Thread Tools Display Modes
05-29-22, 08:54 AM   #1
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Trying to add buttons to dropdown menu.

Hello, everyone!

I've been trying to add new buttons to the Wardrobe sets filter dropdown menu. I have had little success thus far and figure I'd reach out to see if anyone could help. I should add that I'm attempting to do this through WeakAuras, to act like a plug-in.

I found the code that adds the existing filter options in the wardrobe set filter dropdown menu. The id of the dropdown menu is "WardrobeFilterDropDown". That code is below:

Lua Code:
  1. function WardrobeFilterDropDown_InitializeBaseSets(self, level)
  2.             local filterSystem = {
  3.                 onUpdate = WardrobeResetFiltersButton_UpdateVisibility,
  4.                 filters = {
  5.                     { type = FilterComponent.Checkbox, text = COLLECTED, filter = LE_TRANSMOG_SET_FILTER_COLLECTED, set = WardrobeFilterDropDown_SetBaseSetCollectedShown, isSet = WardrobeFilterDropDown_GetBaseSetCollectedShown },
  6.                     { type = FilterComponent.Checkbox, text = NOT_COLLECTED, filter = LE_TRANSMOG_SET_FILTER_UNCOLLECTED, set = WardrobeFilterDropDown_SetBaseSetUncollectedShown, isSet = WardrobeFilterDropDown_GetBaseSetUncollectedShown },
  7.                     { type = FilterComponent.Separator },
  8.                     { type = FilterComponent.Checkbox, text = TRANSMOG_SET_PVE, filter = LE_TRANSMOG_SET_FILTER_PVE, set = WardrobeFilterDropDown_SetBaseSetPVEShown, isSet = WardrobeFilterDropDown_GetBaseSetPVEShown },
  9.                     { type = FilterComponent.Checkbox, text = TRANSMOG_SET_PVP, filter = LE_TRANSMOG_SET_FILTER_PVP, set = WardrobeFilterDropDown_SetBaseSetPVPShown, isSet = WardrobeFilterDropDown_GetBaseSetPVPShown },
  10.                    
  11.                     { type = FilterComponent.Separator },
  12.                 },
  13.             };
  14.             FilterDropDownSystem.Initialize(self, filterSystem, level);
  15.         end

This is the first attempt. It worked but some of the new buttons were indented while others weren't.
Lua Code:
  1. function(e,addonName)
  2.     if (e ~= "ADDON_LOADED") then
  3.         return
  4.     end
  5.    
  6.     if (addonName == "Blizzard_Collections") then
  7.         WardrobeCollectionFrame.FilterButton:HookScript("OnMouseUp",
  8.             function(self,button)
  9.                 UIMenu_AddButton(DropDownList1,"New Button",nil,function() print("Clicked New Button!") end,false)    
  10.         end)
  11.     end
  12. end

This is another attempt that I tried based on online documentation but was unsuccessful:
Lua Code:
  1. function(e,addonName)
  2.     if (e ~= "ADDON_LOADED") then
  3.         return
  4.     end
  5.    
  6.     if (addonName == "Blizzard_Collections") then
  7.         UIDropDownMenu_Initialize(WardrobeFilterDropDown, WardrobeFilterDropDown_Initialize, "MENU");
  8.         UIDropDownMenu_AddSeparator()
  9.         local info = UIDropDownMenu_CreateInfo();
  10.        
  11.         info.text = "New Button";
  12.         info.isTitle = true;
  13.         info.notCheckable = true;
  14.         UIDropDownMenu_AddButton(info, 1);
  15.     end
  16. end
  Reply With Quote
05-31-22, 12:48 PM   #2
urnati
A Kobold Labourer
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1
Hi-
There is a lot to unpack here. First I should say I am not familiar with WeakAuras but am familiar with drop downs.

You first attempt of a post hook was close. However the routine to hook could be WardrobeFilterDropDown_InitializeBaseSets. It just builds the drop down on the fly as needed on mouse down per the Blizzard XML. Hooking the mouse click may be too 'late' or be inconsistent in behavior.
Possibly use hooksecurefunc("WardrobeFilterDropDown_InitializeBaseSets", <your routine>)

By the way, the Blizzard code I see in Blizzard_Wardrobe.lua is below. If the example code is from another addon, it could be tricky. The technique should work but the example appears to use a specialized library / utility that may do something to hinder a hook.
Code:
function WardrobeFilterDropDown_InitializeBaseSets(self, level)
	local info = UIDropDownMenu_CreateInfo();
	info.keepShownOnClick = true;
	info.isNotRadio = true;

	info.text = COLLECTED;
	info.func = function(_, _, _, value)
					C_TransmogSets.SetBaseSetsFilter(LE_TRANSMOG_SET_FILTER_COLLECTED, value);
				end
	info.checked = C_TransmogSets.GetBaseSetsFilter(LE_TRANSMOG_SET_FILTER_COLLECTED);
	UIDropDownMenu_AddButton(info, level);
...
Then add your buttons in <your routine>.
Code:
function <your routine>(self, level)
        UIDropDownMenu_AddSeparator()
        local info = UIDropDownMenu_CreateInfo();
        
        info.text = "New Button";
        info.isTitle = true;
        info.notCheckable = true;
        UIDropDownMenu_AddButton(info, 1);
end
WardrobeFilterDropDown_InitializeBaseSets will have set up the frame for you. Your buttons should be at the bottom.

You may want to wait until the event(e) == PLAYER_ENTERING_WORLD to ensure all addons are loaded or the hook could fail.
  Reply With Quote
06-02-22, 08:24 PM   #3
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Wow, that was incredibly easy! Thank you for pointing me in the right direction!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Trying to add buttons to dropdown menu.

Thread Tools
Display Modes

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