Thread Tools Display Modes
06-22-06, 06:19 PM   #1
Thrae
A Cyclonian
 
Thrae's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2005
Posts: 42
Problem with lua dynamic frame version of CharacterFrameTabButtonTemplate

I'm having trouble with a dynamic version of CharacterFrameTabButtonTemplate found in CharacterFrameTemplates.xml in FrameXML. A deselected tab doesn't show the middle texture properly. Here's what it looks like:



Code:
-- From UIPanelTemplates.lua
function lib:DeselectTab(f, sentf)
	if not sentf then f = f["_tf"][ f["_ct"] ] end
	f.tld:Hide()
	f.tmd:Hide()
	f.trd:Hide()
	f:Enable()
	f.tl:Show()
	f.tm:Show()
	f.tr:Show()
end

-- From UIPanelTemplates.lua
function lib:SelectTab(f, sentf)
	if not sentf then f = f["_tf"][ f["_ct"] ] end
	f.tld:Show()
	f.tmd:Show()
	f.trd:Show()
	f:Disable()
	f.tl:Hide()
	f.tm:Hide()
	f.tr:Hide()
	if ( GameTooltip:IsOwned(f) ) then
		GameTooltip:Hide()
	end
end

--[[------------------------------------------------------------
-- Method: NewTab
--
-- data		- A table local to YOUR addon that will contain all the
--			  data for your addon.
-- text		- text on this new tab
--------------------------------------------------------------]]
function lib:NewTab(data,text)
	if data and text then
		local f
		table.insert( data, { _nc = 0, _nr = 0 } )
		data["_nt"] = data["_nt"] + 1
		if data["_ct"] == 0 then data["_ct"] = 1 end
		data[ data["_nt"] ][ "_sf" ] = CreateFrame( "Frame", nil, data["_f"] )
		f = data[ data["_nt"] ][ "_sf" ]
		f:SetFrameStrata("MEDIUM")
		f:Hide()

		-- Copy of CharacterFrameTabTemplates.xml + UIPanelTemplates.lua
		table.insert( data["_tf"], CreateFrame("Button", nil, data["_f"] ) )
		f = data["_tf"][ data["_nt"] ]

		f:SetTextFontObject( GameFontNormalSmall )
		f:SetDisabledFontObject( GameFontDisableSmall )
		f:SetHighlightFontObject( GameFontHighlightSmall )
		
		f:SetText( text )
		f:SetWidth( f:GetTextWidth() + 40 )
		f:SetHeight( 32 )
		f:SetFrameLevel( f:GetFrameLevel() + 4)

		local t = f:CreateTexture(nil, "BACKGROUND")
		t:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-ActiveTab")
		t:SetWidth(20)
		t:SetHeight(32)
		t:SetTexCoord(0,0.15625,0,1.0)
		t:SetPoint("TOPLEFT", 0,5)
		f.tld = t -- LeftDisabled

		t = f:CreateTexture(nil, "BACKGROUND")
		t:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-ActiveTab")
		t:SetWidth( f:GetTextWidth() )
		t:SetHeight(32)
		t:SetTexCoord(0.15625,0.84375,0,1.0)
		t:SetPoint("LEFT",f.tld,"RIGHT")
		f.tmd = t -- MiddleDisabled
				
		t = f:CreateTexture(nil, "BACKGROUND")
		t:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-ActiveTab")
		t:SetWidth(20)
		t:SetHeight(32)
		t:SetTexCoord(0.84375,1.0,0,1.0)
		t:SetPoint("LEFT",f.tmd,"RIGHT")
		f.trd = t -- RightDisabled
		
		t = f:CreateTexture(nil, "BACKGROUND")
		t:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-InActiveTab")
		t:SetWidth(20)
		t:SetHeight(32)
		t:SetTexCoord(0,1.5625,0,1.0)
		t:SetPoint("TOPLEFT", 0,0)
		f.tl = t -- Left

		t = f:CreateTexture(nil, "BACKGROUND")
		t:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-InActiveTab")
		t:SetWidth( f:GetTextWidth() )
		t:SetHeight(32)
		t:SetTexCoord(1.5625,0.84375,0,1.0)
		t:SetPoint("LEFT", f.tl, "RIGHT")
		f.tm = t -- Middle

		t = f:CreateTexture(nil, "BACKGROUND")
		t:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-InActiveTab")
		t:SetWidth(20)
		t:SetHeight(32)
		t:SetTexCoord(0.84375,1.0,0,1.0)
		t:SetPoint("LEFT", f.tm, "RIGHT")
		f.tr = t -- Right

		t = f:CreateTexture()
		t:SetTexture("Interface\\PaperDollInfoFrame\\UI-Character-Tab-Highlight")
		t:SetBlendMode("ADD")
		t:SetPoint("LEFT", 10, 2)
		t:SetPoint("RIGHT", -10, 2)
		t:SetWidth( f:GetTextWidth() + 30 )
		f:SetHighlightTexture( t )

		if data["_nt"] == 1 then
			f:SetPoint("TOPLEFT", data["_f"], "BOTTOMLEFT", 0, 6)
		else
			f:SetPoint("LEFT", data["_tf"][ data["_nt"] - 1], "RIGHT", -16, 0)
		end

		local nt = data["_nt"]
		local ldata = data
		f:SetScript("OnClick", function() self:FrameTabHandler(ldata,nt) end )

		if data["_nt"] == data["_ct"] then
			self:SelectTab(f, true)
		else
			self:DeselectTab(f, true)
		end
	elseif not data then
		self:Print("In NewTab() - Invalid data table given.")
	elseif not text then
		self:Print("In NewTab() - No text given.")
	end
end

Last edited by Thrae : 06-22-06 at 10:29 PM.
  Reply With Quote
06-22-06, 06:30 PM   #2
Esamynn
Featured Artist
Premium Member
Featured
Join Date: Jan 2005
Posts: 395
I have what is perhaps a silly question. Why not simply make use of the new argument for CreateFrame that 1.11 added. XML virtual templates are now always available and the new argument to CreateFrame allows you to specify a virtual template to use in creating the frame. Much cleaner than trying to duplicate the FrameXML templates in Lua code because they are already there for you to use.
  Reply With Quote
06-22-06, 06:39 PM   #3
Thrae
A Cyclonian
 
Thrae's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2005
Posts: 42
Originally Posted by jbcc
I have what is perhaps a silly question. Why not simply make use of the new argument for CreateFrame that 1.11 added. XML virtual templates are now always available and the new argument to CreateFrame allows you to specify a virtual template to use in creating the frame. Much cleaner than trying to duplicate the FrameXML templates in Lua code because they are already there for you to use.
Because...

a) CharacterFrameTabButtonTemplate uses "names", which are globals. No need to pollute the global namespace if you're doing it dynamically.

b) The template could change or get deleted altogether.

Edit: I decided against CharacterFrameTabs because I think they look kinda ugly. My new template for tabs is very simplistic right now: http://img133.imageshack.us/my.php?image=newtab7bk.jpg

Last edited by Thrae : 06-22-06 at 10:28 PM.
  Reply With Quote
06-28-06, 10:58 PM   #4
metaphaze
A Kobold Labourer
Join Date: Jun 2006
Posts: 1
Hey, I am trying to get tabs working (pretty new) and tried going through the tut. on wowwiki but found it a bit lacking.

What did you do to get yours working like that? Mind sharing a bit of code for a simple tab or two so I can get moving forward?

Thanks.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Problem with lua dynamic frame version of CharacterFrameTabButtonTemplate


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off