-
Notifications
You must be signed in to change notification settings - Fork 3
/
FilterDropDown.lua
165 lines (135 loc) · 5.64 KB
/
FilterDropDown.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
--[[----------------------------------------------------------------------------
LiteBag/FilterDropdown.lua
Copyright 2013 Mike Battersby
Released under the terms of the GNU General Public License version 2 (GPLv2).
See the file LICENSE.txt.
A copy of the bag filtering drop down, because the Blizzard one can't be
accessed from outside.
Redone with Blizzard_Menu for 11.0, see
Interface/AddOns/Blizzard_Menu/11_0_0_MenuImplementationGuide.lua
----------------------------------------------------------------------------]]--
local addonName, LB = ...
local L = LB.Localize
local function bankName(i)
return BANK .. " " .. BAG_NAME_BAG_1:gsub('1', i-NUM_TOTAL_BAG_FRAMES)
end
local bagNames = {
[-1] = BANK,
[0] = BAG_NAME_BACKPACK,
[1] = BAG_NAME_BAG_1,
[2] = BAG_NAME_BAG_2,
[3] = BAG_NAME_BAG_3,
[4] = BAG_NAME_BAG_4,
[5] = L["Reagent Bag"],
}
setmetatable(bagNames, { __index=function(t, k) return bankName(k) end })
-- These are copied with minor fixups from ContainerFrame. Sadly they are not
-- exported and can't be gotten out of there without calling the whole OnLoad.
local function AddButtons_BagFilters(description, bagID)
if not ContainerFrame_CanContainerUseFilterMenu(bagID) then
return
end
description:CreateTitle(BAG_FILTER_ASSIGN_TO)
local function IsSelected(flag)
return C_Container.GetBagSlotFlag(bagID, flag)
end
local function SetSelected(flag)
local value = not IsSelected(flag)
C_Container.SetBagSlotFlag(bagID, flag, value)
ContainerFrameSettingsManager:SetFilterFlag(bagID, flag, value)
end
for i, flag in ContainerFrameUtil_EnumerateBagGearFilters() do
local checkbox = description:CreateCheckbox(BAG_FILTER_LABELS[flag], IsSelected, SetSelected, flag)
checkbox:SetResponse(MenuResponse.Close)
end
end
local function AddButtons_BagCleanup(description, bagID)
description:CreateTitle(BAG_FILTER_IGNORE)
do
local function IsSelected()
if bagID == Enum.BagIndex.Bank then
return C_Container.GetBankAutosortDisabled()
elseif bagID == Enum.BagIndex.Backpack then
return C_Container.GetBackpackAutosortDisabled()
end
return C_Container.GetBagSlotFlag(bagID, Enum.BagSlotFlags.DisableAutoSort)
end
local function SetSelected()
local value = not IsSelected()
if bagID == Enum.BagIndex.Bank then
C_Container.SetBankAutosortDisabled(value)
elseif bagID == Enum.BagIndex.Backpack then
C_Container.SetBackpackAutosortDisabled(value)
else
C_Container.SetBagSlotFlag(bagID, Enum.BagSlotFlags.DisableAutoSort, value)
end
end
local checkbox = description:CreateCheckbox(BAG_FILTER_CLEANUP, IsSelected, SetSelected)
checkbox:SetResponse(MenuResponse.Close)
end
-- ignore junk selling from this bag or backpack
if bagID ~= Enum.BagIndex.Bank then
local function IsSelected()
if bagID == Enum.BagIndex.Backpack then
return C_Container.GetBackpackSellJunkDisabled()
end
return C_Container.GetBagSlotFlag(bagID, Enum.BagSlotFlags.ExcludeJunkSell)
end
local function SetSelected()
local value = not IsSelected()
if bagID == Enum.BagIndex.Backpack then
C_Container.SetBackpackSellJunkDisabled(value)
else
C_Container.SetBagSlotFlag(bagID, Enum.BagSlotFlags.ExcludeJunkSell, value)
end
end
local checkbox = description:CreateCheckbox(SELL_ALL_JUNK_ITEMS_EXCLUDE_FLAG, IsSelected, SetSelected)
checkbox:SetResponse(MenuResponse.Close)
end
end
LiteBagPortraitButtonMixin = {}
function LiteBagPortraitButtonMixin:Initialize()
local parent = self:GetParent()
self:SetupMenu(
function (dropdown, rootDescription)
rootDescription:SetTag("LITEBAG_FILTER_MENU")
rootDescription:CreateTitle(BAG_SETTINGS_TOOLTIP)
rootDescription:CreateButton(SETTINGS, LB.OpenOptions)
rootDescription:CreateCheckbox(LOCK_FRAME,
function () return LB.db and parent:GetParent():IsLocked() end,
function () parent:GetParent():ToggleLocked() end
)
rootDescription:CreateDivider()
rootDescription:CreateTitle(BAG_FILTER_TITLE_SORTING)
for _, bagID in ipairs(parent.bagIDs) do
local submenu = rootDescription:CreateButton(bagNames[bagID])
AddButtons_BagFilters(submenu, bagID)
AddButtons_BagCleanup(submenu, bagID)
end
end)
end
function LiteBagPortraitButtonMixin:OnEnter()
local parent = self:GetParent()
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
if parent:MatchesBagID(Enum.BagIndex.Backpack) then
GameTooltip:SetText(BACKPACK_TOOLTIP, 1.0, 1.0, 1.0)
GameTooltip:AddLine(CLICK_BAG_SETTINGS)
GameTooltip:Show()
elseif parent:MatchesBagID(Enum.BagIndex.Bank) then
GameTooltip:SetText(BANK, 1.0, 1.0, 1.0)
GameTooltip:AddLine(CLICK_BAG_SETTINGS)
GameTooltip:Show()
else
local id = parent.bagIDs[1]
local link = GetInventoryItemLink("player", C_Container.ContainerIDToInventoryID(id))
local name = C_Item.GetItemInfo(link)
if name then
GameTooltip:SetText(name, 1.0, 1.0, 1.0)
GameTooltip:AddLine(CLICK_BAG_SETTINGS)
GameTooltip:Show()
end
end
end
function LiteBagPortraitButtonMixin:OnLeave()
GameTooltip_Hide()
end