Thread Tools Display Modes
04-08-09, 03:59 PM   #1
EchoFive
A Murloc Raider
Join Date: Mar 2007
Posts: 7
Createframe() accessing template properties?

So, obviously I am new to the WoW API and LUA in general, however I am a fairly experienced programmer in a few other languages. I am trying to write a mod for my guild, and I've made some headway with it.

What it does at the moment is register for loot events, and when I loot a corpse it creates buttons inside the mod frame that correspond to the loot on the mob. Later I want to add alot of click functionality, but for now I am trying and failing to get the buttons to work correctly.

I have them being correctly sized, and placed when they are instantiated. So, for example mob A has 2 drops, it makes 2 buttons inside the frame. I want those buttons to have the same icons and such as the loot that dropped.

Here is what the creation code looks like atm:

function createButton(buttonNumber, itemName, icon)
local newButton = CreateFrame("Button", itemName, CoreFrame, "ItemButtonTemplate")

positionButton(newButton, buttonNumber)
newButton:SetWidth(buttonSize)
newButton:SetHeight(buttonSize)

lootFrames[buttonNumber] = newButton
existingButtons = existingButtons + 1
end
And this is the calling function(s)

function lootOpened()
local counter = 1

numButtons = 0
numLoots = GetNumLootItems()

while (counter <= numLoots) do
local lootIcon, lootName, lootQuantity, rarity, locked = GetLootSlotInfo(counter);

createLootButton(counter, lootName, lootIcon)
counter = counter + 1
numButtons = numButtons + 1
end
end

function createLootButton(buttonNumber, itemName, icon)
-- Dynamically create a button for each loot item on the boss
if (buttonNumber <= existingButtons) then
--lootFrames[buttonNumber]:SetNormalTexture(icon)
lootFrames[buttonNumber]:Show()
elseif (buttonNumber > existingButtons) then
createButton(buttonNumber, itemName, icon)
end
end
I am using the ItemButtonTemplate for the buttons, and if you look in createLootButton I commented out
lootFrames[buttonNumber]:SetNormalTexture(icon)
In essence thats what I want to do, but obviously I can't set the NormalTexture to the icon of the drop, I need a way to access the texture that is used for the loot icon for each ItemButtonTemplate, I have no idea how.

Thanks for any help, sorry for the wall o' text for what is almost certianly a simple question, but I'm not sure what is relevant atm =)
  Reply With Quote
04-08-09, 04:41 PM   #2
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
In the ItemButtonTemplate, the NormalTexture provides the background for the slot (the part seen when it's empty).
The frame for the icon is called ButtonnameIconTexture and its displayed texture can be set by using
Code:
SetItemButtonTexture(button, texture)
It's defined in FrameXML/ItemButtonTemplate.lua in case you're looking for similiar functions for use with your template.

Try if it works with this function
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
04-08-09, 04:59 PM   #3
EchoFive
A Murloc Raider
Join Date: Mar 2007
Posts: 7
That helped, I actually understand what I need to call now =) I am still confused on how I reference it though, this was my best guess.. and it throws and error in-game.

function createButton(buttonNumber, itemName, icon)
local newButton = CreateFrame("Button", itemName, CoreFrame, "ItemButtonTemplate")
local iconTextureString = strconcat(itemName, "IconTexture")

newButton[iconTextureString]:SetItemButtonTexture(newButton, icon)
positionButton(newButton, buttonNumber)
newButton:SetWidth(buttonSize)
newButton:SetHeight(buttonSize)

lootFrames[buttonNumber] = newButton
existingButtons = existingButtons + 1
end
Thanks for the help, it's much appreciated =)
  Reply With Quote
04-08-09, 05:40 PM   #4
Aezay
A Theradrim Guardian
 
Aezay's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 66
SetItemButtonTexture() is a function blizzard provides in their files, it is not a meta function for buttons, so you have to call it like this:
Code:
SetItemButtonTexture(newButton,icon)
  Reply With Quote
04-08-09, 05:54 PM   #5
EchoFive
A Murloc Raider
Join Date: Mar 2007
Posts: 7
Oh, heh that worked like a charm. Thanks guys, I appreciate the help
  Reply With Quote
04-08-09, 06:23 PM   #6
EchoFive
A Murloc Raider
Join Date: Mar 2007
Posts: 7
One last question, looking at the API lists on wowwiki I can't seem to find SetItemButtonTexture? Is there a better source for API documentation?
  Reply With Quote
04-08-09, 09:20 PM   #7
Tuhljin
A Flamescale Wyrmkin
 
Tuhljin's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2008
Posts: 106
SetItemButtonTexture isn't a "real" part of the API. It's defined in FrameXML\ItemButtonTemplate.lua. You can view it via wowcompares.com or download Blizzard's AddOn Kit to extract it.

Here's the function's code for your convenience:
Code:
function SetItemButtonTexture(button, texture)
	if ( not button ) then
		return;
	end
	if ( texture ) then
		getglobal(button:GetName().."IconTexture"):Show();
	else
		getglobal(button:GetName().."IconTexture"):Hide();
	end
	getglobal(button:GetName().."IconTexture"):SetTexture(texture);
end
Edit: I may as well mention wowprogramming.com as another good source of WoW API information, though it doesn't list SetItemButtonTexture either.

Last edited by Tuhljin : 04-08-09 at 09:24 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Createframe() accessing template properties?


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