-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.lua
356 lines (314 loc) · 13 KB
/
main.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
349
350
351
352
353
354
355
356
AdvancedFilters = {}
local AF = AdvancedFilters
AF.subfilterGroups = {
[INVENTORY_BACKPACK] = {
[ITEMFILTERTYPE_ALL] = {},
[ITEMFILTERTYPE_WEAPONS] = {},
[ITEMFILTERTYPE_ARMOR] = {},
[ITEMFILTERTYPE_CONSUMABLE] = {},
[ITEMFILTERTYPE_CRAFTING] = {},
[ITEMFILTERTYPE_FURNISHING] = {},
[ITEMFILTERTYPE_MISCELLANEOUS] = {},
--[ITEMFILTERTYPE_JUNK] = {},
},
[INVENTORY_BANK] = {
[ITEMFILTERTYPE_ALL] = {},
[ITEMFILTERTYPE_WEAPONS] = {},
[ITEMFILTERTYPE_ARMOR] = {},
[ITEMFILTERTYPE_CONSUMABLE] = {},
[ITEMFILTERTYPE_CRAFTING] = {},
[ITEMFILTERTYPE_FURNISHING] = {},
[ITEMFILTERTYPE_MISCELLANEOUS] = {},
--[ITEMFILTERTYPE_JUNK] = {},
},
[INVENTORY_GUILD_BANK] = {
[ITEMFILTERTYPE_ALL] = {},
[ITEMFILTERTYPE_WEAPONS] = {},
[ITEMFILTERTYPE_ARMOR] = {},
[ITEMFILTERTYPE_CONSUMABLE] = {},
[ITEMFILTERTYPE_CRAFTING] = {},
[ITEMFILTERTYPE_FURNISHING] = {},
[ITEMFILTERTYPE_MISCELLANEOUS] = {},
--[ITEMFILTERTYPE_JUNK] = {},
},
[INVENTORY_CRAFT_BAG] = {
[ITEMFILTERTYPE_ALL] = {},
[ITEMFILTERTYPE_BLACKSMITHING] = {},
[ITEMFILTERTYPE_CLOTHING] = {},
[ITEMFILTERTYPE_WOODWORKING] = {},
[ITEMFILTERTYPE_ALCHEMY] = {},
[ITEMFILTERTYPE_ENCHANTING] = {},
[ITEMFILTERTYPE_PROVISIONING] = {},
[ITEMFILTERTYPE_STYLE_MATERIALS] = {},
[ITEMFILTERTYPE_TRAIT_ITEMS] = {},
},
[6] = {
[ITEMFILTERTYPE_ALL] = {},
[ITEMFILTERTYPE_WEAPONS] = {},
[ITEMFILTERTYPE_ARMOR] = {},
[ITEMFILTERTYPE_CONSUMABLE] = {},
[ITEMFILTERTYPE_CRAFTING] = {},
[ITEMFILTERTYPE_MISCELLANEOUS] = {},
}, --VENDOR_SELL
}
AF.currentInventoryType = INVENTORY_BACKPACK
local function InitializeHooks()
--TABLE TRACKER
--[[
this is a hacky way of knowing when items go in and out of an inventory.
t = the tracked table (ZO_InventoryManager.isListDirty/PLAYER_INVENTORY.isListDirty)
k = inventoryType
v = isDirty
pk = private key (no two empty tables are the same) where we store t
mt = our metatable where we can do the tracking
]]
--create private key
local pk = {}
--create metatable
local mt = {
__index = function(t, k)
--d("*access to element " .. tostring(k))
--access the tracked table
return t[pk][k]
end,
__newindex = function(t, k, v)
--d("*update of element " .. tostring(k) .. " to " .. tostring(v))
--update the tracked table
t[pk][k] = v
--refresh subfilters for inventory type
local subfilterGroup = AF.subfilterGroups[k]
if not subfilterGroup then return end
local currentSubfilterBar = subfilterGroup.currentSubfilterBar
if not currentSubfilterBar then return end
AF.util.ThrottledUpdate("RefreshSubfilterBar" .. currentSubfilterBar.name, 10, AF.util.RefreshSubfilterBar, currentSubfilterBar)
end,
}
--tracking function. Returns a proxy table with our metatable attached.
local function track(t)
local proxy = {}
proxy[pk] = t
setmetatable(proxy, mt)
return proxy
end
--untracking function. Returns the tracked table and destroys the proxy.
local function untrack(proxy)
local t = proxy[pk]
proxy = nil
return t
end
local function ShowSubfilterBar(currentFilter)
local function UpdateListAnchors(self, shiftY)
local layoutData = self.appliedLayout or BACKPACK_DEFAULT_LAYOUT_FRAGMENT.layoutData
if not layoutData then return end
local list = self.list or self.inventories[AF.currentInventoryType].listView
list:SetWidth(layoutData.width)
list:ClearAnchors()
list:SetAnchor(TOPRIGHT, nil, TOPRIGHT, 0, layoutData.backpackOffsetY + shiftY)
list:SetAnchor(BOTTOMRIGHT)
ZO_ScrollList_SetHeight(list, list:GetHeight())
local sortBy = self.sortHeaders or self:GetDisplayInventoryTable(AF.currentInventoryType).sortHeaders
sortBy = sortBy.headerContainer
sortBy:ClearAnchors()
sortBy:SetAnchor(TOPRIGHT, nil, TOPRIGHT, 0, layoutData.sortByOffsetY + shiftY)
end
--get new bar
local subfilterGroup = AF.subfilterGroups[AF.currentInventoryType]
local subfilterBar = subfilterGroup[currentFilter]
--hide old bar, if it exists
if subfilterGroup.currentSubfilterBar ~= nil then
subfilterGroup.currentSubfilterBar:SetHidden(true)
end
--do nothing if we're in a guild store and regular filters are disabled.
if not ZO_TradingHouse:IsHidden() and AF.util.libCIF._guildStoreSellFiltersDisabled then return end
--if new bar exists
if subfilterBar then
--set current bar reference
subfilterGroup.currentSubfilterBar = subfilterBar
--set currentFilter since we need it before the original ChangeFilter updates it
if subfilterBar.inventoryType == 6 then
STORE_WINDOW.currentFilter = currentFilter
else
PLAYER_INVENTORY.inventories[subfilterBar.inventoryType].currentFilter = currentFilter
end
--activate current button
subfilterBar:ActivateButton(subfilterBar:GetCurrentButton())
--show the bar
subfilterBar:SetHidden(false)
--set proper inventory anchor displacement
if subfilterBar.inventoryType == 6 then
UpdateListAnchors(STORE_WINDOW, subfilterBar.control:GetHeight())
else
UpdateListAnchors(PLAYER_INVENTORY, subfilterBar.control:GetHeight())
end
else
--remove all filters
AF.util.RemoveAllFilters()
--set original inventory anchor displacement
if AF.currentInventoryType == 6 then
UpdateListAnchors(STORE_WINDOW, 0)
else
UpdateListAnchors(PLAYER_INVENTORY, 0)
end
--remove current bar reference
subfilterGroup.currentSubfilterBar = nil
end
end
--FRAGMENT HOOKS
local function hookFragment(fragment, inventoryType)
local function onFragmentShowing()
AF.currentInventoryType = inventoryType
if inventoryType == 6 then
AF.util.ThrottledUpdate("ShowSubfilterBar" .. inventoryType, 10,
ShowSubfilterBar, STORE_WINDOW.currentFilter)
else
AF.util.ThrottledUpdate(
"ShowSubfilterBar" .. inventoryType, 10, ShowSubfilterBar,
PLAYER_INVENTORY.inventories[inventoryType].currentFilter)
end
PLAYER_INVENTORY.isListDirty = track(PLAYER_INVENTORY.isListDirty)
end
local function onFragmentHiding()
PLAYER_INVENTORY.isListDirty = untrack(PLAYER_INVENTORY.isListDirty)
end
local function onFragmentStateChange(oldState, newState)
if newState == SCENE_FRAGMENT_SHOWING then
onFragmentShowing()
elseif newState == SCENE_FRAGMENT_HIDING then
onFragmentHiding()
end
end
fragment:RegisterCallback("StateChange", onFragmentStateChange)
end
hookFragment(INVENTORY_FRAGMENT, INVENTORY_BACKPACK)
hookFragment(BANK_FRAGMENT, INVENTORY_BANK)
hookFragment(GUILD_BANK_FRAGMENT, INVENTORY_GUILD_BANK)
hookFragment(CRAFT_BAG_FRAGMENT, INVENTORY_CRAFT_BAG)
hookFragment(STORE_FRAGMENT, 6)
--PREHOOKS
local function ChangeFilterInventory(self, filterTab)
local currentFilter = self:GetTabFilterInfo(filterTab.inventoryType, filterTab)
if AF.currentInventoryType ~= 6 then
AF.util.ThrottledUpdate(
"ShowSubfilterBar" .. AF.currentInventoryType, 10,
ShowSubfilterBar, currentFilter)
end
end
ZO_PreHook(PLAYER_INVENTORY, "ChangeFilter", ChangeFilterInventory)
local function ChangeFilterVendor(self, filterTab)
local currentFilter = filterTab.filterType
AF.util.ThrottledUpdate("ShowSubfilterBar6", 10, ShowSubfilterBar,
currentFilter)
local subfilterGroup = AF.subfilterGroups[6]
if not subfilterGroup then return end
local currentSubfilterBar = subfilterGroup.currentSubfilterBar
if not currentSubfilterBar then return end
AF.util.ThrottledUpdate("RefreshSubfilterBar" .. currentSubfilterBar.name, 10,
AF.util.RefreshSubfilterBar, currentSubfilterBar)
end
ZO_PreHook(STORE_WINDOW, "ChangeFilter", ChangeFilterVendor)
end
local function CreateSubfilterBars()
local inventoryNames = {
[INVENTORY_BACKPACK] = "PlayerInventory",
[INVENTORY_BANK] = "PlayerBank",
[INVENTORY_GUILD_BANK] = "GuildBank",
[INVENTORY_CRAFT_BAG] = "CraftBag",
[6] = "VendorSell",
}
local filterTypeNames = {
[ITEMFILTERTYPE_ALL] = "All",
[ITEMFILTERTYPE_WEAPONS] = "Weapons",
[ITEMFILTERTYPE_ARMOR] = "Armor",
[ITEMFILTERTYPE_CONSUMABLE] = "Consumables",
[ITEMFILTERTYPE_CRAFTING] = "Crafting",
[ITEMFILTERTYPE_FURNISHING] = "Furnishings",
[ITEMFILTERTYPE_MISCELLANEOUS] = "Miscellaneous",
--[ITEMFILTERTYPE_JUNK] = "Junk",
[ITEMFILTERTYPE_BLACKSMITHING] = "Blacksmithing",
[ITEMFILTERTYPE_CLOTHING] = "Clothing",
[ITEMFILTERTYPE_WOODWORKING] = "Woodworking",
[ITEMFILTERTYPE_ALCHEMY] = "Alchemy",
[ITEMFILTERTYPE_ENCHANTING] = "Enchanting",
[ITEMFILTERTYPE_PROVISIONING] = "Provisioning",
[ITEMFILTERTYPE_STYLE_MATERIALS] = "Style",
[ITEMFILTERTYPE_TRAIT_ITEMS] = "Traits",
}
local subfilterButtonNames = {
[ITEMFILTERTYPE_ALL] = {
"All",
},
[ITEMFILTERTYPE_WEAPONS] = {
"HealStaff", "DestructionStaff", "Bow", "TwoHand", "OneHand", "All",
},
[ITEMFILTERTYPE_ARMOR] = {
"Vanity", "Jewelry", "Shield", "Clothing", "LightArmor", "Medium",
"Heavy", "All",
},
[ITEMFILTERTYPE_CONSUMABLE] = {
"Trophy", "Repair", "Container", "Writ", "Motif", "Poison",
"Potion", "Recipe", "Drink", "Food", "Crown", "All",
},
[ITEMFILTERTYPE_CRAFTING] = {
"FurnishingMat", "WeaponTrait", "ArmorTrait", "Style",
"Provisioning", "Enchanting", "Alchemy", "Woodworking", "Clothier",
"Blacksmithing", "All",
},
[ITEMFILTERTYPE_FURNISHING] = {
"TargetDummy", "Seating", "Ornamental", "Light", "CraftingStation",
"All",
},
[ITEMFILTERTYPE_MISCELLANEOUS] = {
"Trash", "Fence", "Trophy", "Tool", "Bait", "Siege", "SoulGem",
"Glyphs", "All",
},
--[[[ITEMFILTERTYPE_JUNK] = {
"Miscellaneous", "Materials", "Consumable", "Apparel", "Weapon",
"All"
},]]
[ITEMFILTERTYPE_BLACKSMITHING] = {
"FurnishingMat", "Temper", "RefinedMaterial", "RawMaterial", "All",
},
[ITEMFILTERTYPE_CLOTHING] = {
"FurnishingMat", "Resin", "RefinedMaterial", "RawMaterial", "All",
},
[ITEMFILTERTYPE_WOODWORKING] = {
"FurnishingMat", "Tannin", "RefinedMaterial", "RawMaterial", "All",
},
[ITEMFILTERTYPE_ALCHEMY] = {
"FurnishingMat", "Oil", "Water", "Reagent", "All",
},
[ITEMFILTERTYPE_ENCHANTING] = {
"FurnishingMat", "Potency", "Essence", "Aspect", "All",
},
[ITEMFILTERTYPE_PROVISIONING] = {
"FurnishingMat", "Bait", "RareIngredient", "OldIngredient",
"DrinkIngredient", "FoodIngredient", "All",
},
[ITEMFILTERTYPE_STYLE_MATERIALS] = {
"CrownStyle", "ExoticStyle", "AllianceStyle", "RareStyle",
"NormalStyle", "All",
},
[ITEMFILTERTYPE_TRAIT_ITEMS] = {
"WeaponTrait", "ArmorTrait", "All",
},
}
for inventoryType, subfilterGroup in pairs(AF.subfilterGroups) do
for itemFilterType, _ in pairs(subfilterGroup) do
local subfilterBar = AF.AF_FilterBar:New(
inventoryNames[inventoryType],
filterTypeNames[itemFilterType],
subfilterButtonNames[itemFilterType]
)
subfilterBar:SetInventoryType(inventoryType)
AF.subfilterGroups[inventoryType][itemFilterType] = subfilterBar
end
end
end
function AdvancedFilters_Loaded(eventCode, addonName)
if addonName ~= "AdvancedFilters" then return end
EVENT_MANAGER:UnregisterForEvent("AdvancedFilters_Loaded", EVENT_ADD_ON_LOADED)
AF.util.LibFilters:InitializeLibFilters()
CreateSubfilterBars()
InitializeHooks()
end
EVENT_MANAGER:RegisterForEvent("AdvancedFilters_Loaded", EVENT_ADD_ON_LOADED, AdvancedFilters_Loaded)