|
7 | 7 | Released under the terms of the GNU General Public License version 2 (GPLv2).
|
8 | 8 | See the file LICENSE.txt.
|
9 | 9 |
|
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 |
11 | 15 |
|
12 | 16 | ----------------------------------------------------------------------------]]--
|
13 | 17 |
|
14 | 18 | local addonName, LB = ...
|
15 | 19 |
|
16 |
| -local LibDD = LibStub:GetLibrary("LibUIDropDownMenu-4.0") |
| 20 | +local L = LB.Localize |
17 | 21 |
|
18 |
| -local Initialize |
| 22 | +local function bankName(i) |
| 23 | + return BANK .. " " .. BAG_NAME_BAG_1:gsub('1', i-NUM_TOTAL_BAG_FRAMES) |
| 24 | +end |
19 | 25 |
|
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 | +} |
25 | 35 |
|
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 |
46 | 44 | end
|
47 | 45 |
|
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) |
54 | 47 |
|
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 |
66 | 51 |
|
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 |
74 | 57 |
|
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 |
76 | 63 |
|
77 |
| - if Enum.BagSlotFlags.ExcludeJunkSell and bagID ~= Enum.BagIndex.Bank then |
| 64 | +local function AddButtons_BagCleanup(description, bagID) |
| 65 | + description:CreateTitle(BAG_FILTER_IGNORE) |
78 | 66 |
|
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() |
87 | 73 | end
|
| 74 | + return C_Container.GetBagSlotFlag(bagID, Enum.BagSlotFlags.DisableAutoSort) |
| 75 | + end |
88 | 76 |
|
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) |
91 | 83 | else
|
92 |
| - info.checked = C_Container.GetBagSlotFlag(bagID, Enum.BagSlotFlags.ExcludeJunkSell) |
| 84 | + C_Container.SetBagSlotFlag(bagID, Enum.BagSlotFlags.DisableAutoSort, value) |
93 | 85 | end
|
94 |
| - |
95 |
| - LibDD:UIDropDownMenu_AddButton(info, level) |
96 | 86 | end
|
| 87 | + |
| 88 | + local checkbox = description:CreateCheckbox(BAG_FILTER_CLEANUP, IsSelected, SetSelected) |
| 89 | + checkbox:SetResponse(MenuResponse.Close) |
97 | 90 | end
|
98 | 91 |
|
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) |
102 | 99 | end
|
103 | 100 |
|
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) |
118 | 107 | end
|
119 |
| - |
120 |
| - LibDD:UIDropDownMenu_AddButton(info, level) |
121 | 108 | end
|
122 |
| - end |
123 | 109 |
|
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) |
174 | 112 | end
|
175 |
| - end |
176 | 113 | end
|
177 | 114 |
|
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 |
185 | 115 |
|
186 | 116 | LiteBagPortraitButtonMixin = {}
|
187 | 117 |
|
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) |
191 | 131 | end
|
192 | 132 |
|
193 | 133 | function LiteBagPortraitButtonMixin:OnEnter()
|
|
0 commit comments