Thread Tools Display Modes
08-27-08, 10:54 AM   #1
lieandswell
A Cyclonian
 
lieandswell's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 45
How to set/access IDs for UIDropDownMenu?

I have a number of frames generated off of a common template, and they all have UIDropDownMenus accessible by right click. I'm having trouble getting them to remember/access the ID of the frame that was clicked so that I can adjust the appropriate saved variables.

I've tried all sorts of this:GetID(), this:GetParent():GetID(), etc. in the UIDropDownMenu_Initialize functions. I get back all sorts of strange numbers that change depending on the level of the menu. I don't understand what's going on. Any advice on how to go about doing this?
  Reply With Quote
08-27-08, 11:26 AM   #2
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Well ... I'll show you my code. Maybe could re-use it. If you have any questions please ask.
It's a modified version of the blizzard dropdown code to handle more than one dropdown frame with the same OnLoad/OnClick function.

Let's say there's a table to load into the Dropdown and a variable to save the selected value:
Code:
local dUF.DebuffTypesNumbers = 	{
					[1] = "none", 
					[2] = "Curse", 
					[3] = "Disease", 
					[4] = "Magic", 
					[5] = "Poison", 
					[6] = "HealDebuff", 
					[7] = "Special", 
					[8] = "Unknown", 
					}	
local SavedValue = 1 -- this value is saved via savedvariables
My code to set up the dropdown is:
Code:
tframe = <a reference to a dropdown frame>
tSource = dUF.DebuffTypesNumbers
tvalue = <the numeric index of DebuffTypesNumbers entry to show>
dUF:OptionsOutputDropDown_OnLoad(tframe, tSource, tvalue)
And the dropdown handling code is:
Code:
---------------------------------------------------------------------------------------------------------------------------------------------------------------
-- 
----------------------------------------------------------------------------------------------------------------------------------------------------------------
function dUF:OptionsOutputDropDown_OnLoad(frame, source, value)
	local tname = frame:GetName()
	UIDropDownMenu_Initialize(frame, function() 
		local entry = { func = function() dUF:OptionsOutputDropDown_OnClick(tname) end }
		for i = 1, table.getn(source), 1 do  
				entry.text = source[i]
				entry.value = value;
				if (UIDropDownMenu_GetSelectedValue(this) == entry.value) then
						entry.checked = true
				else
						entry.checked = nil
				end
				UIDropDownMenu_AddButton(entry)
		end	
	end);
	UIDropDownMenu_SetSelectedValue(frame, source[value], 1);
	UIDropDownMenu_SetSelectedID(frame, value);
	if dUF.tocVersion >= 30000 then
		UIDropDownMenu_SetText(frame, source[value])
	else
		UIDropDownMenu_SetText(source[value], frame)
	end
end
---------------------------------------------------------------------------------------------------------------------------------------------------------------
-- 
----------------------------------------------------------------------------------------------------------------------------------------------------------------
function dUF:OptionsOutputDropDown_OnClick(tname)
	UIDropDownMenu_SetSelectedID(getglobal(tname), this:GetID())
	SavedValue = UIDropDownMenu_GetSelectedID(getglobal(tname))
end
  Reply With Quote
08-27-08, 02:08 PM   #3
lieandswell
A Cyclonian
 
lieandswell's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 45
Well, after going through a bunch more Blizzard code, I got it to work using a check for UIDROPDOWNMENU_OPEN_MENU:

Code:
function MyAddOn_DropDown_Initialize()
    local dropdown;
    if ( UIDROPDOWNMENU_OPEN_MENU ) then
        dropdown = getglobal(UIDROPDOWNMENU_OPEN_MENU);
    else
        dropdown = this; 
    end
    local frameID = dropdown:GetParent():GetID();

    ... more code here ...

end
That retrieves the correct frameID.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to set/access IDs for UIDropDownMenu?


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