Skip to content

Commit f083b31

Browse files
committed
Redo the dropdown menus with Blizzard_Menu
1 parent da08155 commit f083b31

File tree

6 files changed

+93
-161
lines changed

6 files changed

+93
-161
lines changed

ContainerPanel.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ function LiteBagContainerPanelMixin:OnLoad()
117117
LB.Manager:RegisterInitializeHook( function () self:SetUpBags() end )
118118

119119
self.PortraitButton:SetPoint("CENTER", self:GetParent():GetPortrait(), "CENTER", 3, -3)
120+
self.PortraitButton:Initialize()
120121
end
121122

122123
function LiteBagContainerPanelMixin:GetBagFrameByID(id)

ContainerPanel.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
<Frame
88
name="LiteBagContainerPanelTemplate" mixin="LiteBagContainerPanelMixin" hidden="true" virtual="true">
99
<Frames>
10-
<DropDownToggleButton name="$parentPortraitButton" parentKey="PortraitButton" inherits="LiteBagPortraitButtonTemplate" />
11-
<Frame name="$parentFilterDropDown" parentKey="FilterDropDown" inherits="LiteBagFilterDropDownTemplate" />
10+
<DropdownButton name="$parentPortraitButton" parentKey="PortraitButton" inherits="LiteBagPortraitButtonTemplate" />
1211
</Frames>
1312
<Scripts>
1413
<!-- These are all of the same events from ContainerFrameCombinedBags -->

FilterDropDown.lua

Lines changed: 88 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -7,187 +7,127 @@
77
Released under the terms of the GNU General Public License version 2 (GPLv2).
88
See the file LICENSE.txt.
99
10-
A copy of the bag filtering drop down, because using Blizzards causes taint.
10+
A copy of the bag filtering drop down, because the Blizzard one can't be
11+
accessed from outside.
12+
13+
Redone with Blizzard_Menu for 11.0, see
14+
Interface/AddOns/Blizzard_Menu/11_0_0_MenuImplementationGuide.lua
1115
1216
----------------------------------------------------------------------------]]--
1317

1418
local addonName, LB = ...
1519

16-
local LibDD = LibStub:GetLibrary("LibUIDropDownMenu-4.0")
20+
local L = LB.Localize
1721

18-
local Initialize
22+
local function bankName(i)
23+
return BANK .. " " .. BAG_NAME_BAG_1:gsub('1', i-NUM_TOTAL_BAG_FRAMES)
24+
end
1925

20-
do
21-
local function OnBagFilterClicked(bagID, filterID, value)
22-
C_Container.SetBagSlotFlag(bagID, filterID, value)
23-
ContainerFrameSettingsManager:SetFilterFlag(bagID, filterID, value)
24-
end
26+
local bagNames = {
27+
[-1] = BANK,
28+
[0] = BAG_NAME_BACKPACK,
29+
[1] = BAG_NAME_BAG_1,
30+
[2] = BAG_NAME_BAG_2,
31+
[3] = BAG_NAME_BAG_3,
32+
[4] = BAG_NAME_BAG_4,
33+
[5] = L["Reagent Bag"],
34+
}
2535

26-
local function AddButtons_BagHide(bagID, level)
27-
local allow = LB.GetGlobalOption('allowHideBagIDs')
28-
if not allow[bagID] then return end
29-
30-
local info = LibDD:UIDropDownMenu_CreateInfo()
31-
info.text = DISPLAY_OPTIONS
32-
info.isTitle = 1
33-
info.notCheckable = 1
34-
LibDD:UIDropDownMenu_AddButton(info, level)
35-
36-
info = LibDD:UIDropDownMenu_CreateInfo()
37-
info.text = HIDE
38-
info.func = function(_, _, _, value)
39-
local hide = LB.GetGlobalOption('hideBagIDs')
40-
hide[bagID] = not value or nil
41-
LB.SetGlobalOption('hideBagIDs', hide)
42-
end
43-
local hide = LB.GetGlobalOption('hideBagIDs')
44-
info.checked = hide[bagID]
45-
LibDD:UIDropDownMenu_AddButton(info, level)
36+
setmetatable(bagNames, { __index=function(t, k) return bankName(k) end })
37+
38+
-- These are copied with minor fixups from ContainerFrame. Sadly they are not
39+
-- exported and can't be gotten out of there without calling the whole OnLoad.
40+
41+
local function AddButtons_BagFilters(description, bagID)
42+
if not ContainerFrame_CanContainerUseFilterMenu(bagID) then
43+
return
4644
end
4745

48-
local function AddButtons_BagIgnore(bagID, level)
49-
local info = LibDD:UIDropDownMenu_CreateInfo()
50-
info.text = BAG_FILTER_IGNORE
51-
info.isTitle = 1
52-
info.notCheckable = 1
53-
LibDD:UIDropDownMenu_AddButton(info, level)
46+
description:CreateTitle(BAG_FILTER_ASSIGN_TO)
5447

55-
info = LibDD:UIDropDownMenu_CreateInfo()
56-
info.text = BAG_FILTER_CLEANUP
57-
info.func = function(_, _, _, value)
58-
if bagID == Enum.BagIndex.Bank then
59-
C_Container.SetBankAutosortDisabled(not value)
60-
elseif bagID == Enum.BagIndex.Backpack then
61-
C_Container.SetBackpackAutosortDisabled(not value)
62-
else
63-
C_Container.SetBagSlotFlag(bagID, Enum.BagSlotFlags.DisableAutoSort, not value)
64-
end
65-
end
48+
local function IsSelected(flag)
49+
return C_Container.GetBagSlotFlag(bagID, flag)
50+
end
6651

67-
if bagID == Enum.BagIndex.Bank then
68-
info.checked = C_Container.GetBankAutosortDisabled()
69-
elseif bagID == Enum.BagIndex.Backpack then
70-
info.checked = C_Container.GetBackpackAutosortDisabled()
71-
else
72-
info.checked = C_Container.GetBagSlotFlag(bagID, Enum.BagSlotFlags.DisableAutoSort)
73-
end
52+
local function SetSelected(flag)
53+
local value = not IsSelected(flag)
54+
C_Container.SetBagSlotFlag(bagID, flag, value)
55+
ContainerFrameSettingsManager:SetFilterFlag(bagID, flag, value)
56+
end
7457

75-
LibDD:UIDropDownMenu_AddButton(info, level)
58+
for i, flag in ContainerFrameUtil_EnumerateBagGearFilters() do
59+
local checkbox = description:CreateCheckbox(BAG_FILTER_LABELS[flag], IsSelected, SetSelected, flag)
60+
checkbox:SetResponse(MenuResponse.Close)
61+
end
62+
end
7663

77-
if Enum.BagSlotFlags.ExcludeJunkSell and bagID ~= Enum.BagIndex.Bank then
64+
local function AddButtons_BagCleanup(description, bagID)
65+
description:CreateTitle(BAG_FILTER_IGNORE)
7866

79-
info = LibDD:UIDropDownMenu_CreateInfo()
80-
info.text = SELL_ALL_JUNK_ITEMS_EXCLUDE_FLAG
81-
info.func = function(_, _, _, value)
82-
if bagID == Enum.BagIndex.Backpack then
83-
C_Container.SetBackpackSellJunkDisabled(not value)
84-
else
85-
C_Container.SetBagSlotFlag(bagID, Enum.BagSlotFlags.ExcludeJunkSell, not value)
86-
end
67+
do
68+
local function IsSelected()
69+
if bagID == Enum.BagIndex.Bank then
70+
return C_Container.GetBankAutosortDisabled()
71+
elseif bagID == Enum.BagIndex.Backpack then
72+
return C_Container.GetBackpackAutosortDisabled()
8773
end
74+
return C_Container.GetBagSlotFlag(bagID, Enum.BagSlotFlags.DisableAutoSort)
75+
end
8876

89-
if bagID == Enum.BagIndex.Backpack then
90-
info.checked = C_Container.GetBackpackSellJunkDisabled()
77+
local function SetSelected()
78+
local value = not IsSelected()
79+
if bagID == Enum.BagIndex.Bank then
80+
C_Container.SetBankAutosortDisabled(value)
81+
elseif bagID == Enum.BagIndex.Backpack then
82+
C_Container.SetBackpackAutosortDisabled(value)
9183
else
92-
info.checked = C_Container.GetBagSlotFlag(bagID, Enum.BagSlotFlags.ExcludeJunkSell)
84+
C_Container.SetBagSlotFlag(bagID, Enum.BagSlotFlags.DisableAutoSort, value)
9385
end
94-
95-
LibDD:UIDropDownMenu_AddButton(info, level)
9686
end
87+
88+
local checkbox = description:CreateCheckbox(BAG_FILTER_CLEANUP, IsSelected, SetSelected)
89+
checkbox:SetResponse(MenuResponse.Close)
9790
end
9891

99-
local function AddButtons_BagFilters(bagID, level)
100-
if not ContainerFrame_CanContainerUseFilterMenu(bagID) then
101-
return
92+
-- ignore junk selling from this bag or backpack
93+
if bagID ~= Enum.BagIndex.Bank then
94+
local function IsSelected()
95+
if bagID == Enum.BagIndex.Backpack then
96+
return C_Container.GetBackpackSellJunkDisabled()
97+
end
98+
return C_Container.GetBagSlotFlag(bagID, Enum.BagSlotFlags.ExcludeJunkSell)
10299
end
103100

104-
local info = LibDD:UIDropDownMenu_CreateInfo()
105-
info.text = BAG_FILTER_ASSIGN_TO
106-
info.isTitle = 1
107-
info.notCheckable = 1
108-
LibDD:UIDropDownMenu_AddButton(info, level)
109-
110-
info = LibDD:UIDropDownMenu_CreateInfo()
111-
local activeBagFilter = ContainerFrameSettingsManager:GetFilterFlags(bagID)
112-
113-
for i, flag in ContainerFrameUtil_EnumerateBagGearFilters() do
114-
info.text = BAG_FILTER_LABELS[flag]
115-
info.checked = activeBagFilter == flag
116-
info.func = function(_, _, _, value)
117-
return OnBagFilterClicked(bagID, flag, not value)
101+
local function SetSelected()
102+
local value = not IsSelected()
103+
if bagID == Enum.BagIndex.Backpack then
104+
C_Container.SetBackpackSellJunkDisabled(value)
105+
else
106+
C_Container.SetBagSlotFlag(bagID, Enum.BagSlotFlags.ExcludeJunkSell, value)
118107
end
119-
120-
LibDD:UIDropDownMenu_AddButton(info, level)
121108
end
122-
end
123109

124-
local bagNames =
125-
{
126-
[-1] = BANK,
127-
[0] = BAG_NAME_BACKPACK,
128-
[1] = BAG_NAME_BAG_1,
129-
[2] = BAG_NAME_BAG_2,
130-
[3] = BAG_NAME_BAG_3,
131-
[4] = BAG_NAME_BAG_4,
132-
[5] = "Reagent Bag",
133-
}
134-
135-
local function bankName(i)
136-
return BANK .. " " .. BAG_NAME_BAG_1:gsub('1', i-NUM_TOTAL_BAG_FRAMES)
137-
end
138-
139-
setmetatable(bagNames, { __index=function(t, k) return bankName(k) end })
140-
141-
Initialize = function(self, level)
142-
if level == 1 then
143-
local parent = self:GetParent()
144-
145-
local info = LibDD:UIDropDownMenu_CreateInfo()
146-
info.notCheckable = true
147-
info.text = SETTINGS
148-
info.func = LB.OpenOptions
149-
LibDD:UIDropDownMenu_AddButton(info, level)
150-
151-
info = LibDD:UIDropDownMenu_CreateInfo()
152-
info.text = LOCK_FRAME
153-
info.checked = parent:GetParent():IsLocked()
154-
info.func = function () parent:GetParent():ToggleLocked() end
155-
LibDD:UIDropDownMenu_AddButton(info, level)
156-
157-
LibDD:UIDropDownMenu_AddSeparator()
158-
159-
for _, bag in ipairs(parent.bagFrames) do
160-
local i = bag:GetID()
161-
local info = LibDD:UIDropDownMenu_CreateInfo()
162-
info.text = bagNames[i]
163-
info.hasArrow = true
164-
info.notCheckable = true
165-
info.value = i
166-
LibDD:UIDropDownMenu_AddButton(info, level)
167-
end
168-
elseif level == 2 then
169-
if L_UIDROPDOWNMENU_MENU_VALUE ~= Enum.BagIndex.Bank then
170-
AddButtons_BagFilters(L_UIDROPDOWNMENU_MENU_VALUE, level)
171-
end
172-
AddButtons_BagIgnore(L_UIDROPDOWNMENU_MENU_VALUE, level)
173-
AddButtons_BagHide(L_UIDROPDOWNMENU_MENU_VALUE, level)
110+
local checkbox = description:CreateCheckbox(SELL_ALL_JUNK_ITEMS_EXCLUDE_FLAG, IsSelected, SetSelected)
111+
checkbox:SetResponse(MenuResponse.Close)
174112
end
175-
end
176113
end
177114

178-
LiteBagFilterDropDownMixin = {}
179-
180-
function LiteBagFilterDropDownMixin:OnLoad()
181-
LibDD:Create_UIDropDownMenu(self)
182-
LibDD:UIDropDownMenu_SetInitializeFunction(self, Initialize)
183-
LibDD:UIDropDownMenu_SetDisplayMode(self, "MENU")
184-
end
185115

186116
LiteBagPortraitButtonMixin = {}
187117

188-
function LiteBagPortraitButtonMixin:OnMouseDown()
189-
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
190-
LibDD:ToggleDropDownMenu(1, nil, self:GetParent().FilterDropDown, self, 0, 0)
118+
function LiteBagPortraitButtonMixin:Initialize()
119+
local parent = self:GetParent()
120+
self:SetupMenu(
121+
function (dropdown, rootDescription)
122+
rootDescription:SetTag("LITEBAG_FILTER_MENU")
123+
rootDescription:CreateTitle(BAG_FILTER_TITLE_SORTING)
124+
for _, bagID in ipairs(parent.bagIDs) do
125+
local submenu = rootDescription:CreateButton(bagNames[bagID])
126+
AddButtons_BagFilters(submenu, bagID)
127+
AddButtons_BagCleanup(submenu, bagID)
128+
end
129+
130+
end)
191131
end
192132

193133
function LiteBagPortraitButtonMixin:OnEnter()

FilterDropDown.xml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@
44

55
<Script file="FilterDropDown.lua"/>
66

7-
<DropDownToggleButton name="LiteBagPortraitButtonTemplate" mixin="LiteBagPortraitButtonMixin" virtual="true">
7+
<DropdownButton name="LiteBagPortraitButtonTemplate" mixin="LiteBagPortraitButtonMixin" virtual="true">
88
<Size x="40" y="40" />
99
<Scripts>
10-
<OnMouseDown method="OnMouseDown"/>
10+
<OnLoad method="OnLoad"/>
1111
<OnEnter method="OnEnter" />
1212
<OnLeave method="OnLeave" />
1313
</Scripts>
14-
</DropDownToggleButton>
15-
16-
<Frame name="LiteBagFilterDropDownTemplate" mixin="LiteBagFilterDropDownMixin" virtual="true">
17-
<Scripts>
18-
<OnLoad method="OnLoad" />
19-
</Scripts>
20-
</Frame>
14+
</DropdownButton>
2115

2216
</Ui>

embeds.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
<Include file="Libs/AceGUI-3.0\AceGUI-3.0.xml" />
77
<Include file="Libs/AceConfig-3.0\AceConfig-3.0.xml" />
88
<Include file="Libs/AceDBOptions-3.0\AceDBOptions-3.0.xml" />
9-
<Include file="Libs/LibUIDropDownMenu\LibUIDropDownMenu.lua" />
109
</Ui>

pkgmeta.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ externals:
66
Libs/AceGUI-3.0: https://repos.curseforge.com/wow/ace3/trunk/AceGUI-3.0
77
Libs/CallbackHandler-1.0: https://repos.curseforge.com/wow/callbackhandler/trunk/CallbackHandler-1.0
88
Libs/LibStub: https://repos.curseforge.com/wow/libstub/trunk
9-
Libs/LibUIDropDownMenu: https://repos.wowace.com/wow/libuidropdownmenu/trunk/LibUIDropDownMenu
109

1110
enable-nolib-creation: no

0 commit comments

Comments
 (0)