-
Notifications
You must be signed in to change notification settings - Fork 13
/
AutoCategory.lua
348 lines (304 loc) · 11.6 KB
/
AutoCategory.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
------------------
--LOAD LIBRARIES--
------------------
--load LibAddonsMenu-2.0
local LAM2 = LibStub:GetLibrary("LibAddonMenu-2.0");
----------------------
--INITIATE VARIABLES--
----------------------
local L = AutoCategory.localizefunc
AC_EMPTY_TAG_NAME = L(SI_AC_DEFAULT_NAME_EMPTY_TAG)
function AutoCategory.UpdateCurrentSavedVars()
AutoCategory.curSavedVars= {}
if not AutoCategory.charSavedVariables.accountWideSetting then
AutoCategory.curSavedVars.rules = AutoCategory.acctSavedVariables.rules
AutoCategory.curSavedVars.bags = AutoCategory.charSavedVariables.bags
AutoCategory.curSavedVars.collapses = AutoCategory.charSavedVariables.collapses
else
AutoCategory.curSavedVars.rules = AutoCategory.acctSavedVariables.rules
AutoCategory.curSavedVars.bags = AutoCategory.acctSavedVariables.bags
AutoCategory.curSavedVars.collapses = AutoCategory.acctSavedVariables.collapses
end
end
function AutoCategory.LoadCollapse()
if AutoCategory.acctSavedVariables.general["SAVE_CATEGORY_COLLAPSE_STATUS"] then
--loaded from saved vars
else
--init
AutoCategory.ResetCollapse()
end
end
function AutoCategory.ResetCollapse()
AutoCategory.curSavedVars.collapses = {
[AC_BAG_TYPE_BACKPACK] = {},
[AC_BAG_TYPE_BANK] = {},
[AC_BAG_TYPE_GUILDBANK] = {},
[AC_BAG_TYPE_CRAFTBAG] = {},
[AC_BAG_TYPE_CRAFTSTATION] = {},
}
end
function AutoCategory.ResetToDefaults()
AutoCategory.acctSavedVariables.rules = AutoCategory.defaultAcctSettings.rules
AutoCategory.acctSavedVariables.bags = AutoCategory.defaultAcctSettings.bags
AutoCategory.acctSavedVariables.appearance = AutoCategory.defaultAcctSettings.appearance
AutoCategory.charSavedVariables.rules = AutoCategory.defaultSettings.rules
AutoCategory.charSavedVariables.bags = AutoCategory.defaultSettings.bags
AutoCategory.charSavedVariables.accountWideSetting = AutoCategory.defaultSettings.accountWideSetting
AutoCategory.ResetCollapse()
end
local function CheckVersionCompatible()
--v1.06
if AutoCategory.acctSavedVariables.appearance == nil then
AutoCategory.acctSavedVariables.appearance = AutoCategory.defaultAcctSettings.appearance
end
--v1.06
--v1.12, added bag setting for guildbank/craftbag/craftstation
local function RebuildBagSettingIfNeeded(setting, defaultSetting, bagId)
if not setting.bags[bagId] then
setting.bags[bagId] = defaultSetting.bags[bagId]
end
end
RebuildBagSettingIfNeeded(AutoCategory.charSavedVariables, AutoCategory.defaultSetting, AC_BAG_TYPE_GUILDBANK)
RebuildBagSettingIfNeeded(AutoCategory.charSavedVariables, AutoCategory.defaultSetting, AC_BAG_TYPE_CRAFTBAG)
RebuildBagSettingIfNeeded(AutoCategory.charSavedVariables, AutoCategory.defaultSetting, AC_BAG_TYPE_CRAFTSTATION)
RebuildBagSettingIfNeeded(AutoCategory.acctSavedVariables, AutoCategory.defaultAcctSettings, AC_BAG_TYPE_GUILDBANK)
RebuildBagSettingIfNeeded(AutoCategory.acctSavedVariables, AutoCategory.defaultAcctSettings, AC_BAG_TYPE_CRAFTBAG)
RebuildBagSettingIfNeeded(AutoCategory.acctSavedVariables, AutoCategory.defaultAcctSettings, AC_BAG_TYPE_CRAFTSTATION)
--v1.12
--v1.15, added some options to modify headers appearance, and general settings
if not AutoCategory.acctSavedVariables.appearance["CATEGORY_OTHER_TEXT"] then
AutoCategory.acctSavedVariables.appearance["CATEGORY_OTHER_TEXT"] = L(SI_AC_DEFAULT_NAME_CATEGORY_OTHER)
AutoCategory.acctSavedVariables.appearance["CATEGORY_HEADER_HEIGHT"] = 52
end
if not AutoCategory.acctSavedVariables.general then
AutoCategory.acctSavedVariables.general = {}
AutoCategory.acctSavedVariables.general["SHOW_MESSAGE_WHEN_TOGGLE"] = false
end
--v1.15
--v1.16
--modify the account setting flag, move it to character
if AutoCategory.charSavedVariables.accountWideSetting == nil then
AutoCategory.charSavedVariables.accountWideSetting = true
end
--remove duplicated categories in bag
local function removeDuplicatedCategories(setting)
for i = 1, #setting.bags do
local bag = setting.bags[i]
local keys = {}
--traverse from back to front to remove elements while iteration
for j = #bag.rules, 1, -1 do
local data = bag.rules[j]
if keys[data.name] ~= nil then
--remove duplicated category
table.remove(bag.rules, j)
else
--flag this category
keys[data.name] = true
end
end
end
end
removeDuplicatedCategories(AutoCategory.charSavedVariables)
removeDuplicatedCategories(AutoCategory.acctSavedVariables)
--added hidden category flag to all bags
local function addHiddenFlagIfPossible(setting)
for i = 1, #setting.bags do
local bag = setting.bags[i]
if bag.isUngroupedHidden == nil then
bag.isUngroupedHidden = false
end
for j = 1, #bag.rules do
local data = bag.rules[j]
if data.isHidden == nil then
data.isHidden = false
end
end
end
end
addHiddenFlagIfPossible(AutoCategory.charSavedVariables)
addHiddenFlagIfPossible(AutoCategory.acctSavedVariables)
--added setting
if AutoCategory.acctSavedVariables.general["SHOW_CATEGORY_ITEM_COUNT"] == nil then
AutoCategory.acctSavedVariables.general["SHOW_CATEGORY_ITEM_COUNT"] = true
end
--v1.16
--v1.19
if AutoCategory.acctSavedVariables.general["SAVE_CATEGORY_COLLAPSE_STATUS"] == nil then
AutoCategory.acctSavedVariables.general["SAVE_CATEGORY_COLLAPSE_STATUS"] = false
end
local function addCollapseIfPossible(setting)
if setting.collapses == nil then
setting.collapses = {
[AC_BAG_TYPE_BACKPACK] = {},
[AC_BAG_TYPE_BANK] = {},
[AC_BAG_TYPE_GUILDBANK] = {},
[AC_BAG_TYPE_CRAFTBAG] = {},
[AC_BAG_TYPE_CRAFTSTATION] = {},
}
end
end
addCollapseIfPossible(AutoCategory.charSavedVariables)
addCollapseIfPossible(AutoCategory.acctSavedVariables)
--v1.19
end
function AutoCategory.LazyInit()
if not AutoCategory.Inited then
-- load our saved variables
AutoCategory.charSavedVariables = ZO_SavedVars:New('AutoCategorySavedVars', 1.1, nil, nil)
AutoCategory.acctSavedVariables = ZO_SavedVars:NewAccountWide('AutoCategorySavedVars', 1.1, nil, nil)
local function isTableEmpty(table)
if next(table) == nil then
return true
end
if table.bags == nil then
return true
end
return false
end
if isTableEmpty(AutoCategory.charSavedVariables) then
AutoCategory.charSavedVariables.rules = AutoCategory.defaultSettings.rules
AutoCategory.charSavedVariables.bags = AutoCategory.defaultSettings.bags
AutoCategory.charSavedVariables.accountWideSetting = AutoCategory.defaultSettings.accountWideSetting
end
if isTableEmpty(AutoCategory.acctSavedVariables) then
AutoCategory.acctSavedVariables.rules = AutoCategory.defaultAcctSettings.rules
AutoCategory.acctSavedVariables.bags = AutoCategory.defaultAcctSettings.bags
AutoCategory.acctSavedVariables.appearance = AutoCategory.defaultAcctSettings.appearance
end
-- version compatible
CheckVersionCompatible()
-- initialize
AutoCategory.UpdateCurrentSavedVars()
AutoCategory.LoadCollapse()
AutoCategory.AddonMenuInit()
-- hooks
AutoCategory.HookGamepadMode()
AutoCategory.HookKeyboardMode()
--capabilities with other add-ons
IntegrateIakoniGearChanger()
IntegrateInventoryGridView()
IntegrateQuickMenu()
IntegrateDoItAll()
AutoCategory.Inited = true
end
end
function AutoCategory.Initialize(event, addon)
-- filter for just BUI addon event as EVENT_ADD_ON_LOADED is addon-blind
if addon ~= AutoCategory.name then return end
SLASH_COMMANDS["/ac"] = AutoCategory.cmd
AutoCategory.LazyInit()
end
--== Slash command ==--
function AutoCategory.cmd( text )
if text == nil then text = true end
LAM2:OpenToPanel(AC_CATEGORY_SETTINGS)
local addons = LAM2.addonList:GetChild(1)
if addons:GetNumChildren() ~= 0 then
for a=1,addons:GetNumChildren(),1 do
if addons:GetChild(a):GetText() == AutoCategory.settingName then
addons:GetChild(a):SetSelected(true)
break
end
end
end
--Second time's the charm
if text then
zo_callLater(function()AutoCategory.cmd(false)end,500)
end
end
-- register our event handler function to be called to do initialization
EVENT_MANAGER:RegisterForEvent(AutoCategory.name, EVENT_ADD_ON_LOADED, function(...) AutoCategory.Initialize(...) end)
--== Interface ==--
function AutoCategory.RefreshCurrentList()
local function RefreshList(inventoryType)
PLAYER_INVENTORY:UpdateList(inventoryType)
end
if not ZO_PlayerInventory:IsHidden() then
RefreshList(INVENTORY_BACKPACK)
RefreshList(INVENTORY_QUEST_ITEM)
elseif not ZO_CraftBag:IsHidden() then
RefreshList(INVENTORY_CRAFT_BAG)
elseif not ZO_GuildBank:IsHidden() then
RefreshList(INVENTORY_GUILD_BANK)
elseif not ZO_PlayerBank:IsHidden() then
RefreshList(INVENTORY_BANK)
elseif not SMITHING.deconstructionPanel.control:IsHidden() then
SMITHING.deconstructionPanel.inventory:PerformFullRefresh()
elseif not SMITHING.improvementPanel.control:IsHidden() then
SMITHING.improvementPanel.inventory:PerformFullRefresh()
end
end
function AC_ItemRowHeader_OnMouseEnter(header)
local cateName = header.slot.dataEntry.bestItemTypeName
local bagTypeId = header.slot.dataEntry.bagTypeId
local collapsed = AutoCategory.IsCategoryCollapsed(bagTypeId, cateName)
local markerBG = header:GetNamedChild("CollapseMarkerBG")
markerBG:SetHidden(false)
if collapsed then
markerBG:SetTexture("EsoUI/Art/Buttons/plus_over.dds")
else
markerBG:SetTexture("EsoUI/Art/Buttons/minus_over.dds")
end
end
function AC_ItemRowHeader_OnMouseExit(header)
local markerBG = header:GetNamedChild("CollapseMarkerBG")
markerBG:SetHidden(true)
end
function AutoCategory.IsCategoryCollapsed(bagTypeId, categoryName)
if AutoCategory.curSavedVars.collapses[bagTypeId][categoryName] == nil then
AutoCategory.curSavedVars.collapses[bagTypeId][categoryName] = false
end
local collapsed = AutoCategory.curSavedVars.collapses[bagTypeId][categoryName]
return collapsed
end
function AutoCategory.SetCategoryCollapsed(bagTypeId, categoryName, collapsed)
AutoCategory.curSavedVars.collapses[bagTypeId][categoryName] = collapsed
end
function AC_ItemRowHeader_OnMouseClicked(header)
local cateName = header.slot.dataEntry.bestItemTypeName
local bagTypeId = header.slot.dataEntry.bagTypeId
local collapsed = AutoCategory.IsCategoryCollapsed(bagTypeId, cateName)
AutoCategory.SetCategoryCollapsed(bagTypeId, cateName, not collapsed)
AutoCategory.RefreshCurrentList()
end
function AC_ItemRowHeader_OnShowContextMenu(header)
ClearMenu()
local cateName = header.slot.dataEntry.bestItemTypeName
local bagTypeId = header.slot.dataEntry.bagTypeId
local collapsed = AutoCategory.IsCategoryCollapsed(bagTypeId, cateName)
if collapsed then
AddMenuItem(L(SI_CONTEXT_MENU_EXPAND), function()
AutoCategory.SetCategoryCollapsed(bagTypeId, cateName, false)
AutoCategory.RefreshCurrentList()
end)
else
AddMenuItem(L(SI_CONTEXT_MENU_COLLAPSE), function()
AutoCategory.SetCategoryCollapsed(bagTypeId, cateName, true)
AutoCategory.RefreshCurrentList()
end)
end
AddMenuItem(L(SI_CONTEXT_MENU_EXPAND_ALL), function()
for k, v in pairs (AutoCategory.curSavedVars.collapses[bagTypeId]) do
AutoCategory.curSavedVars.collapses[bagTypeId][k] = false
end
AutoCategory.RefreshCurrentList()
end)
AddMenuItem(L(SI_CONTEXT_MENU_COLLAPSE_ALL), function()
for k, v in pairs (AutoCategory.curSavedVars.collapses[bagTypeId]) do
AutoCategory.curSavedVars.collapses[bagTypeId][k] = true
end
AutoCategory.RefreshCurrentList()
end)
ShowMenu()
end
function AC_Binding_ToggleCategorize()
AutoCategory.Enabled = not AutoCategory.Enabled
if AutoCategory.acctSavedVariables.general["SHOW_MESSAGE_WHEN_TOGGLE"] then
if AutoCategory.Enabled then
d(L(SI_MESSAGE_TOGGLE_AUTO_CATEGORY_ON))
else
d(L(SI_MESSAGE_TOGGLE_AUTO_CATEGORY_OFF))
end
end
AutoCategory.RefreshCurrentList()
end