View Single Post
  #2  
Unread 09-20-2010, 05:15 PM
derk derk is offline
The Wary
 
Join Date: Sep 2010
Posts: 3
I had to use this little trick myself to do something like you want, however this example is from memory and I haven't checked if it works. You will have to test yourself and check wat kind of arguments go into the functions but you should get the general idea:

Code:
function SomeClass:init()
	-- hook the SetFont and SetText functions
	self.prevLabelSetFont = Turbine.UI.Label.SetFont;
	Turbine.UI.Label.SetFont = function ( --args? )
		self.prevLabelSetFont( Turbine.UI.Lotro.Font.TrajanPro28 )
	end
	self.prevLabelSetText = Turbine.UI.Label.SetText;
	Turbine.UI.Label.SetText = function ( --args? )
		self.prevLabelSetFont(  Turbine.UI.Lotro.Font.TrajanPro28 )
		self.prevLabelSetText( --any args)
	end
	
	-- hook any other functions that don't inherit from Label:SetText and Label:SetFont ( if there are any )
	--  like: Turbine.UI.Window.SetText

	-- above only sets on the SetFont and SetText functions, still need to set existing labels 	
	-- set a flag on all Turbine.UI.Label:
	Turbine.UI.Label._IsLabel = true;
	
	-- recusively check the _G table for all loaded tables
	self:enum_tables( _G, { } );

end

function SomeClass:enum_tables( t, seen )
	seen[t] = true;
	for k,v in pairs(t) do
		if ( type(v) == "table" and not seen[v] ) then
			-- here check our flag
			if ( v._IsLabel ) then
				v:SetFont( Turbine.UI.Lotro.Font.TrajanPro28 )		
			else
				self:enum_tables( v, seen );
			end
		end
	end
end
Also I don't know if everything inherits from Turbine.UI.Label and in some class making/overloading constructions it doesn't work (like turbine's TheOneBag example)
Reply With Quote