Thread Tools Display Modes
02-03-10, 09:23 AM   #1
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
Identifying buttons

Hey all!
For my new addon ncHoverBind, I need to find all actionbuttons and containerframe buttons.

I've solved the actionbutton problem pretty brutely with the following code(register is defined earlier):
Code:
local event = CreateFrame("FRAME")
event:RegisterEvent("PLAYER_ENTERING_WORLD")
event:SetScript("OnEvent", function()
	for key, val in pairs(_G) do
		if type(val)=="table" and val.GetAttribute and val.GetObjectType and val:GetObjectType()=="CheckButton" and val:GetAttribute("type")=="action" then
			register(val)
		end
	end
	event:UnregisterAllEvents()
end)
How can I loop _G for the containerframe buttons? Or better, give me a more efficient alternative!
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.

Last edited by nightcracker : 02-03-10 at 10:55 AM.
  Reply With Quote
02-03-10, 10:46 AM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
You link to oUFSwing (p3lim)
  Reply With Quote
02-03-10, 10:55 AM   #3
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
Originally Posted by Dridzt View Post
You link to oUFSwing (p3lim)
Woops, your right!

Fixing.
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
  Reply With Quote
02-03-10, 05:01 PM   #4
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Originally Posted by nightcracker View Post
How can I loop _G for the containerframe buttons?
Code:
local frame
for containerNum = 1, NUM_CONTAINER_FRAMES do
	for itemNum = 1, MAX_CONTAINER_ITEMS do
		frame = _G['ContainerFrame' .. containerNum .. 'Item' .. itemNum]
	end
end
  Reply With Quote
02-03-10, 06:51 PM   #5
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Originally Posted by nightcracker View Post
give me a more efficient alternative
You can really clean that up using EnumerateFrames, which is like a "next" function for frames. Slap the following code in somewhere after you have defined your "register" function. Every time an addon is loaded it will look at only those frames that were created since the last time it was run.

Code:
do
	local lastFrame

	local function ScanUnseenFrames()
		local frame = EnumerateFrames(lastFrame)
		while frame do
			if frame:GetObjectType() == 'CheckButton' and frame:GetAttribute('type') == 'action' then
				register(frame)
			end
			lastFrame, frame = frame, EnumerateFrames(frame)
		end
	end
	ScanUnseenFrames()

	lastFrame = CreateFrame('Frame')
	lastFrame:SetScript('OnEvent', ScanUnseenFrames)
	lastFrame:RegisterEvent('ADDON_LOADED')
	lastFrame:Hide()
end
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Identifying buttons


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