DropDown Menu re-use code
I have 2 drop down menus that contain the same table list. How would one go about 're-using' lua code to populate each dropdown and handle clicks.
Speaking generically...
in XML, in the UIDropDownMenuTemplate, in the <OnShow> I call MyDropDown_OnShow
MyDropDown_OnShow function calls UIDropDownMenu_Initialize and passes MyDropDown_Initialize function: this allows the dropdown to know it's init function
MyDropDown_Initialize populates the dropdown and sets info.function to MyDropDown_OnClick, so the dropdown knows what to do when an item is selected
MyDropDown_OnClick just gets what the user selected in the list and shows it in chat. (for testing purposes)
The problem I am running in to is differentiating which dropdown is making the calls. I thought I could put the drop down name (i.e. MyDropDown_Menu1 or MyDropDown_Menu2) in info.value via info.value = this, and then use that value (aka frame) when the OnClick does
local i = this:GetID(); --ID is the # of the selected item, 1, 2, 3 in the dropdown list.
UIDropDownMenu_SetSelectedID( this.value, i);
however, it appears that Initialize gets called twice: once when it it shown, which then sets info.value to MyDropDown_Menu2 (so far so good) but when you click the disclosure button to show the list, it gets called again, and this time this = MyDropDown_Menu2Button.
Can anyone suggest a solution?
|