-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutil.lua
272 lines (236 loc) · 8.86 KB
/
util.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
local AF = AdvancedFilters
AF.util = {}
AF.util.libCIF = LibStub:GetLibrary("libCommonInventoryFilters", LibStub.SILENT)
AF.util.LibFilters = LibStub("LibFilters-2.0")
AF.util.LibMotifCategories = LibStub("LibMotifCategories-1.0")
function AF.util.ApplyFilter(button, filterTag, requestUpdate)
local LibFilters = AF.util.LibFilters
local callback = button.filterCallback
local filterType
if AF.currentInventoryType == 6 then
filterType = LF_VENDOR_BUY
else
filterType = LibFilters:GetCurrentFilterTypeForInventory(AF.currentInventoryType)
end
--d("Apply " .. button.name .. " from " .. filterTag .. " for filterType " .. filterType .. " and inventoryType " .. AF.currentInventoryType)
--if something isn't right, abort
if callback == nil then
d("callback was nil for " .. filterTag)
return
end
if filterType == nil then
d("filterType was nil for " .. filterTag)
return
end
--first, clear current filters without an update
LibFilters:UnregisterFilter(filterTag)
--then register new one and hand off update parameter
LibFilters:RegisterFilter(filterTag, filterType, callback)
if requestUpdate == true then LibFilters:RequestUpdate(filterType) end
end
function AF.util.RemoveAllFilters()
local LibFilters = AF.util.LibFilters
local filterType
if AF.currentInventoryType == 6 then
filterType = LF_VENDOR_BUY
else
filterType = LibFilters:GetCurrentFilterTypeForInventory(AF.currentInventoryType)
end
LibFilters:UnregisterFilter("AF_ButtonFilter")
LibFilters:UnregisterFilter("AF_DropdownFilter")
if filterType ~= nil then LibFilters:RequestUpdate(filterType) end
end
function AF.util.RefreshSubfilterBar(subfilterBar)
local inventoryType = subfilterBar.inventoryType
local inventory, inventorySlots
if inventoryType == 6 then
return
else
inventory = PLAYER_INVENTORY.inventories[inventoryType]
inventorySlots = inventory.slots
end
for _, button in pairs(subfilterBar.subfilterButtons) do
if button.name ~= "All" then
--disable button
if button.clickable then
button.texture:SetColor(.3, .3, .3, .9)
button:SetEnabled(false)
button.clickable = false
end
--check button for availability
for _, bags in pairs(inventorySlots) do
for _, itemData in pairs(bags) do
local passesCallback = button.filterCallback(itemData)
local passesFilter = itemData.filterData[1] == inventory.currentFilter
or itemData.filterData[2] == inventory.currentFilter
if passesCallback and passesFilter then
button.texture:SetColor(1, 1, 1, 1)
button:SetEnabled(true)
button.clickable = true
break
end
end
end
end
end
end
function AF.util.BuildDropdownCallbacks(groupName, subfilterName)
if subfilterName == "Heavy" or subfilterName == "Medium"
or subfilterName == "LightArmor" or subfilterName == "Clothing" then
subfilterName = "Body"
end
local callbackTable = {}
local keys = {
All = {},
Weapons = {
"OneHand", "TwoHand", "Bow", "DestructionStaff", "HealStaff",
},
Armor = {
"Body", "Shield", "Jewelry", "Vanity",
},
Consumables = {
"Crown", "Food", "Drink", "Recipe", "Potion", "Poison", "Motif", "Writ", "Container", "Repair", "Trophy",
},
Crafting = {
"Blacksmithing", "Clothier", "Woodworking", "Alchemy", "Enchanting", "Provisioning", "Style", "WeaponTrait", "ArmorTrait",
},
Furnishings = {
"CraftingStation", "Light", "Ornamental", "Seating", "TargetDummy",
},
Miscellaneous = {
"Glyphs", "SoulGem", "Siege", "Bait", "Tool", "Trophy", "Fence", "Trash",
},
Junk = {
"Weapon", "Apparel", "Consumable", "Materials", "Miscellaneous"
},
Blacksmithing = {
"RawMaterial", "RefinedMaterial", "Temper",
},
Clothing = {
"RawMaterial", "RefinedMaterial", "Resin",
},
Woodworking = {
"RawMaterial", "RefinedMaterial", "Tannin",
},
Alchemy = {
"Reagent", "Water", "Oil",
},
Enchanting = {
"Aspect", "Essence", "Potency",
},
Provisioning = {
"FoodIngredient", "DrinkIngredient", "OldIngredient", "RareIngredient", "Bait",
},
Style = {
"NormalStyle", "RareStyle", "AllianceStyle", "ExoticStyle", "CrownStyle",
},
Traits = {
"ArmorTrait", "WeaponTrait",
},
}
local function insertAddon(addonTable)
--generate information if necessary
if addonTable.generator then
local strings
addonTable.callbackTable, strings = addonTable.generator()
for key, string in pairs(strings) do
AF.strings[key] = string
end
end
--check to see if addon is set up for a submenu
if addonTable.submenuName then
--insert whole package
table.insert(callbackTable, addonTable)
else
--insert all callbackTable entries
local currentAddonTable = addonTable.callbackTable
for _, callbackEntry in ipairs(currentAddonTable) do
table.insert(callbackTable, callbackEntry)
end
end
end
-- insert global "All" filters
for _, callbackEntry in ipairs(AF.subfilterCallbacks.All.dropdownCallbacks) do
table.insert(callbackTable, callbackEntry)
end
--insert global addon filters
for _, addonTable in ipairs(AF.subfilterCallbacks.All.addonDropdownCallbacks) do
insertAddon(addonTable)
end
--insert filters that apply to the whole group
if groupName ~= "All" then
for _, callbackEntry in ipairs(AF.subfilterCallbacks[groupName].All.dropdownCallbacks) do
table.insert(callbackTable, callbackEntry)
end
if subfilterName == "All" then
--insert all default filters for each subfilter
for _, subfilterName in ipairs(keys[groupName]) do
local currentSubfilterTable = AF.subfilterCallbacks[groupName][subfilterName]
for _, callbackEntry in ipairs(currentSubfilterTable.dropdownCallbacks) do
table.insert(callbackTable, callbackEntry)
end
end
--insert all filters provided by addons
for _, addonTable in ipairs(AF.subfilterCallbacks[groupName].addonDropdownCallbacks) do
insertAddon(addonTable)
end
else
--insert filters for provided subfilter
local currentSubfilterTable = AF.subfilterCallbacks[groupName][subfilterName]
for _, callbackEntry in ipairs(currentSubfilterTable.dropdownCallbacks) do
table.insert(callbackTable, callbackEntry)
end
--insert filters provided by addons for this subfilter
for _, addonTable in ipairs(AF.subfilterCallbacks[groupName].addonDropdownCallbacks) do
--scan addon to see if it applies to given subfilter
for _, subfilter in ipairs(addonTable.subfilters) do
if subfilter == subfilterName or subfilter == "All" then
--add addon filters
insertAddon(addonTable)
end
end
end
end
end
return callbackTable
end
function AF.util.GetLanguage()
local lang = GetCVar("language.2")
local supported = {
de = 1,
en = 2,
es = 3,
fr = 4,
ru = 5,
jp = 6,
}
--check for supported languages
if(supported[lang] ~= nil) then return lang end
--return english if not supported
return "en"
end
--thanks ckaotik
function AF.util.Localize(text)
if type(text) == 'number' then
-- get the string from this constant
text = GetString(text)
end
-- clean up suffixes such as ^F or ^S
return zo_strformat(SI_TOOLTIP_ITEM_NAME, text) or " "
end
function AF.util.ThrottledUpdate(callbackName, timer, callback, ...)
local args = {...}
local function Update()
EVENT_MANAGER:UnregisterForUpdate(callbackName)
callback(unpack(args))
end
EVENT_MANAGER:UnregisterForUpdate(callbackName)
EVENT_MANAGER:RegisterForUpdate(callbackName, timer, Update)
end
function AF.util.GetItemLink(slot)
if slot.bagId then
return GetItemLink(slot.bagId, slot.slotIndex)
else
return GetStoreItemLink(slot.slotIndex)
end
end