08-25-19, 12:52 PM | #1 |
UIDropDownMenu Alternatives?
I wrote a prototype AddOn whose options were implemented using the libs of UIDropDownMenu. I'm glad I prototyped it because I learned that the options of UIDropDownMenu cannot be refreshed. So, is there a recommended way to set up an options menu such that its options can be refreshed?
For example, suppose the character in the image below added a second bag. The second bag will not show up because UIDropDownMenu cannot be refreshed. Reloading the UI is the only alternative. Ideally, when a character adds, removes, or relocates a bag the options menu will refresh the new or moved bag will now show up as an option. [My Addon's Options Menu] Thanks, in advance. Last edited by mtp1032 : 08-25-19 at 12:55 PM. Reason: Added Picture |
|
08-25-19, 11:31 PM | #2 |
you could use EasyMenu, you basically create your menu frame using UIDropDownMenuTemplate, then create an array with your menu options and then call the EasyMenu method passing it your frame, your array, etc. It's fairly simple to work with.
https://wow.gamepedia.com/API_EasyMenu Code:
-- EXAMPLE -- local frame = CreateFrame("Frame", "MyFrame") local menu = CreateFrame("Frame", "MyMenuFrame", frame , "UIDropDownMenuTemplate") menu:SetPoint("BOTTOMRIGHT") menu:Hide() local menu_options = {} local function update_menu() -- clear the menu so that it can be re-initialized my_menu_options = {} -- build the menu array my_menu_options = { { text = "Options", isTitle = true, notCheckable = true, }, { text = "Option One", checked = false, func = function(self) -- do something end, }, { text = "Option Two", checked = false, func = function(self) -- do something end, }, text = "More Options", notCheckable = true, hasArrow = true, menuList = { { text = "Option Three", checked = false, func = function(self) -- do something end, }, { text = "Option Four", checked = true, func = function(self) -- do something end, }, }, }, } end -- EasyMenu(menuList, menuFrame, anchor, x, y, displayMode, autoHideDelay) frame:SetScript("OnClick", function(self, button) update_menu() EasyMenu(menu_options, menu, frame, 0, 0, "MENU", 3) end ) Hope this helps Last edited by Auz : 08-25-19 at 11:40 PM. |
|
08-26-19, 06:10 AM | #3 | |
You should only have to close and reopen your menu to get it to display changes. If that is not the case then post your code because you are not initializing your menu properly. Last edited by Vrul : 08-26-19 at 06:17 AM. |
||
08-26-19, 01:46 PM | #4 |
Thank you Vrul and Auz
Vrul, I'll post my code in just a bit. Right now I'm creating names for the Classic launch.
Cheers, |
|
08-26-19, 02:06 PM | #5 |
When this code is executed, the player's bag slots are queried to see if they contain a bag (bg:getBag(slotNum). If a bag is not present then a checkbox is created for that bag. If not bag is installed, then no checkbox is created.
Just to recapitulate: the problem is that when the player adds, removes, or relocates a bag I would like to catch the interrupt and refresh this menu. If, for example, the player installed a new bag in slot 4, the menu would create a checkbox for that bag in slot 4 upon being refreshed. Thanks for you time. I do appreciate it. Lua Code:
|
|
08-27-19, 06:19 AM | #6 |
I thought you said you were using UIDropDownMenu but I don't see that anywhere in the code provided. That code should only be run once so of course it won't automatically update itself.
Not sure when, but when I get some time I'll clean it up and add what you need to update the bag check boxes. |
|
08-27-19, 01:22 PM | #7 |
I changed your buttons names from "CHACHING_BagButtonOne" to "CHACHING_BagButton1" and similarly changed isBagChecked[BAG1] to isBagChecked[1] (repeat for 2 through 5). This should look how you originally had it:
Code:
function cha:CHACHING_InitializeOptions() local ConfigurationPanel = CreateFrame("FRAME","CHACHING_MainFrame") ConfigurationPanel.name = L["ADDON_NAME"] InterfaceOptions_AddCategory(ConfigurationPanel) -- Register the Configuration panel with LibUIDropDownMenu -- Print a header at the top of the panel local IntroMessageHeader = ConfigurationPanel:CreateFontString(nil, "ARTWORK","GameFontNormalLarge") IntroMessageHeader:SetPoint("TOPLEFT", 10, -10) IntroMessageHeader:SetText(L["ADDON_NAME_AND_VERSION"]) local AuthorSubHeader = ConfigurationPanel:CreateFontString(nil, "ARTWORK","GameFontNormal") AuthorSubHeader:SetPoint("TOPLEFT", 20, -30) AuthorSubHeader:SetText("Author: Shadowraith@Feathermoon") local DescrSubHeader = ConfigurationPanel:CreateFontString(nil, "ARTWORK","GameFontNormalLarge") DescrSubHeader:SetPoint("TOPLEFT", 20, -50) DescrSubHeader:SetText("Enables the bulk selling of selected items in player's inventory.") local ReadmeMessageText = ConfigurationPanel:CreateFontString(nil, "ARTWORK","GameFontNormalLarge") ReadmeMessageText:SetPoint("TOPLEFT", 10, -280) ReadmeMessageText:SetText(strjoin("\n", " *** IMPORTANT *** ", "The merchant buyback window only has 12 slots. However, the merchant", "will buy as many items as Cha-Ching is configured to sell. So, if more", "than 12 items were sold, you will only be able to buyback the last 12" )) -- Create check button to sell grey items local GreyQualityButton = CreateFrame("CheckButton", "CHACHING_GreyQualityButton", ConfigurationPanel, "ChatConfigCheckButtonTemplate") GreyQualityButton:SetPoint("TOPLEFT", 20, -80) GreyQualityButton.tooltip = "Check to sell all poor (grey) items in your inventory." _G[GreyQualityButton:GetName().."Text"]:SetText("Sell Grey Items?") GreyQualityButton:SetScript("OnClick", function(self) sellGrey = self:GetChecked() and true or false end) -- Create check button to sell white items local WhiteQualityButton = CreateFrame("CheckButton", "CHACHING_WhiteQualityButton", ConfigurationPanel, "ChatConfigCheckButtonTemplate") WhiteQualityButton:SetPoint("TOPLEFT", 200, -80) WhiteQualityButton.tooltip = L["TOOLTIP_CHECK_WHITE_BTN"] _G[WhiteQualityButton:GetName().."Text"]:SetText("Sell White Items (Only Armor and Weapons?") WhiteQualityButton:SetScript("OnClick", function(self) sellWhite = self:GetChecked() and true or false end) -- Create bag select buttons local bagsText = ConfigurationPanel:CreateFontString(nil, "ARTWORK","GameFontNormal") bagsText:SetPoint("TOPLEFT", 20, -200) bagsText:SetText("Select a bag. All items in the selected bag will be sold!") local xpos = 20 local ypos = -215 local delta_y = -20 local function BagSelectButtonOnClick(self) isBagChecked[self.bagIndex] = self:GetChecked() and true or false end local bagSelectButtons = { } for id = 0, 4 do local bagIndex = id + 1 local button = CreateFrame("CheckButton", "CHACHING_BagButton" .. bagIndex, ConfigurationPanel, "ChatConfigCheckButtonTemplate") button:SetPoint("TOPLEFT", xpos, ypos + (delta_y * id)) button.label = _G[button:GetName() .. "Text"] button.bagIndex = bagIndex button:SetScript("OnClick", BagSelectButtonOnClick) bagSelectButtons[bagIndex] = button end local function UpdateBagSelectButtons() local index = 0 for id = 0, 4 do if GetContainerNumSlots(id) > 0 then index = index + 1 local button = bagSelectButtons[index] button.bagIndex = id + 1 button.label:SetText(("Bag[%s] - %s"):format(button.bagIndex, GetBagName(id))) button:Show() end end for index = index + 1, #bagSelectButtons do bagSelectButtons[index]:Hide() end end ConfigurationPanel:SetScript("OnEvent", UpdateBagSelectButtons) ConfigurationPanel:SetScript("OnHide", function(self) self:UnregisterEvent("BAG_UPDATE") end) ConfigurationPanel:SetScript("OnShow", function(self) self:RegisterEvent("BAG_UPDATE") UpdateBagSelectButtons() end) end Code:
local function UpdateBagSelectButtons() for id = 0, 4 do local button = bagSelectButtons[id + 1] if GetContainerNumSlots(id) > 0 then button.label:SetText(("Bag[%s] - %s"):format(button.bagIndex, GetBagName(id))) button:SetEnabled(true) else button.label:SetText(("Bag[%s]"):format(button.bagIndex)) button:SetEnabled(false) end end end |
|
09-08-19, 06:48 PM | #8 |
Thanks.
I'm truly sorry I didn't get back to you earlier. I was called away for a couple of weeks and just didn't have the time. I'll study your code/suggestions and incorporate them into Chaching. I'll let you know how it works out.
Again, I deeply appreciate your time. UPDATE: Seems to work just fine. There is a minor issue in that the bag names are not displayed when the addon is called for the first time. It's a problem I need to work on because I want to learn this stuff. So, again, thank you for your time. Last edited by mtp1032 : 09-09-19 at 10:53 AM. Reason: Follow up |
|
WoWInterface » Developer Discussions » General Authoring Discussion » UIDropDownMenu Alternatives? |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|