-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathItemDBControl.lua
More file actions
363 lines (344 loc) · 12.3 KB
/
Copy pathItemDBControl.lua
File metadata and controls
363 lines (344 loc) · 12.3 KB
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
357
358
359
360
361
362
363
-- Path of Building
--
-- Class: Item DB
-- Item DB control.
--
local pairs = pairs
local ipairs = ipairs
local t_insert = table.insert
local m_max = math.max
local m_floor = math.floor
local ItemDBClass = newClass("ItemDBControl", "ListControl", function(self, anchor, rect, itemsTab, db, dbType)
self.ListControl(anchor, rect, 16, "VERTICAL", false)
self.itemsTab = itemsTab
self.db = db
self.dbType = dbType
self.dragTargetList = { }
self.sortControl = {
NAME = { key = "name", dir = "ASCEND", func = function(a,b) return a:gsub("^The ","") < b:gsub("^The ","") end },
STAT = { key = "measuredPower", dir = "DESCEND" },
}
self.sortDropList = { }
self.sortOrder = { }
self.sortMode = "NAME"
self.leaguesAndTypesLoaded = false
self.leagueList = { "Any league", "No league" }
self.typeList = { "Any type", "Armour", "Jewellery", "One Handed Melee", "Two Handed Melee" }
self.slotList = { "Any slot", "Weapon 1", "Weapon 2", "Helmet", "Body Armour", "Gloves", "Boots", "Amulet", "Ring", "Belt", "Jewel", "Flask", "Graft 1", "Graft 2" }
local baseY = dbType == "RARE" and -22 or -62
self.controls.slot = new("DropDownControl", {"BOTTOMLEFT",self,"TOPLEFT"}, {0, baseY, 179, 18}, self.slotList, function(index, value)
self.listBuildFlag = true
end)
self.controls.type = new("DropDownControl", {"LEFT",self.controls.slot,"RIGHT"}, {2, 0, 179, 18}, self.typeList, function(index, value)
self.listBuildFlag = true
end)
if dbType == "UNIQUE" then
self.controls.sort = new("DropDownControl", {"BOTTOMLEFT",self,"TOPLEFT"}, {0, baseY + 20, 179, 18}, self.sortDropList, function(index, value)
self:SetSortMode(value.sortMode)
end)
self.controls.league = new("DropDownControl", {"LEFT",self.controls.sort,"RIGHT"}, {2, 0, 179, 18}, self.leagueList, function(index, value)
self.listBuildFlag = true
end)
self.controls.requirement = new("DropDownControl", {"LEFT",self.controls.sort,"BOTTOMLEFT"}, {0, 11, 179, 18}, { "Any requirements", "Current level", "Current attributes", "Current useable" }, function(index, value)
self.listBuildFlag = true
end)
self.controls.obtainable = new("DropDownControl", {"LEFT",self.controls.requirement,"RIGHT"}, {2, 0, 179, 18}, { "Obtainable", "Any source", "Unobtainable", "Vendor Recipe", "Upgraded", "Boss Item", "Corruption"}, function(index, value)
self.listBuildFlag = true
end)
end
self.controls.search = new("EditControl", {"BOTTOMLEFT",self,"TOPLEFT"}, {0, -2, 258, 18}, "", "Search", "%c", 100, function()
self.listBuildFlag = true
end, nil, nil, true)
self.controls.searchMode = new("DropDownControl", {"LEFT",self.controls.search,"RIGHT"}, {2, 0, 100, 18}, { "Anywhere", "Names", "Modifiers" }, function(index, value)
self.listBuildFlag = true
end)
self:BuildSortOrder()
self.listBuildFlag = true
end)
function ItemDBClass:LoadLeaguesAndTypes()
local leagueFlag = { }
local typeFlag = { }
for _, item in pairs(self.db.list) do
if item.league then
for leagueName in item.league:gmatch(" ?([%w ]+),?") do
leagueFlag[leagueName] = true
end
end
typeFlag[item.type] = true
end
for leagueName in pairsSortByKey(leagueFlag) do
t_insert(self.leagueList, leagueName)
end
for type in pairsSortByKey(typeFlag) do
t_insert(self.typeList, type)
end
self.leaguesAndTypesLoaded = true
end
function ItemDBClass:DoesItemMatchFilters(item)
if self.controls.slot.selIndex > 1 then
local primarySlot = item:GetPrimarySlot()
if primarySlot ~= self.slotList[self.controls.slot.selIndex] and primarySlot:gsub(" %d","") ~= self.slotList[self.controls.slot.selIndex] then
return false
end
end
local typeSel = self.controls.type.selIndex
if typeSel > 1 then
if typeSel == 2 then
if not item.base.armour then
return false
end
elseif typeSel == 3 then
if not (item.type == "Amulet" or item.type == "Ring" or item.type == "Belt") then
return false
end
elseif typeSel == 4 or typeSel == 5 then
local weaponInfo = self.itemsTab.build.data.weaponTypeInfo[item.type]
if not (weaponInfo and weaponInfo.melee and ((typeSel == 4 and weaponInfo.oneHand) or (typeSel == 5 and not weaponInfo.oneHand))) then
return false
end
elseif item.type ~= self.typeList[typeSel] then
return false
end
end
if self.dbType == "UNIQUE" and self.controls.league.selIndex > 1 then
if (self.controls.league.selIndex == 2 and item.league) or (self.controls.league.selIndex > 2 and (not item.league or not item.league:match(self.leagueList[self.controls.league.selIndex]))) then
return false
end
end
if self.dbType == "UNIQUE" and self.controls.obtainable.selIndex ~= 2 then
local source = item.source or ""
local obtainable = not (source == "No longer obtainable" or (item.league and item.league == "Race Events"))
if (self.controls.obtainable.selIndex == 1 and not obtainable) or (self.controls.obtainable.selIndex == 3 and obtainable) then
return false
elseif (self.controls.obtainable.selIndex == 4 and not (source == "Vendor Recipe")) then
return false
elseif (self.controls.obtainable.selIndex == 5 and not (string.match(source, "Upgraded from"))) then
return false
elseif (self.controls.obtainable.selIndex == 6 and not (string.match(source, "Drops from unique"))) then
return false
elseif (self.controls.obtainable.selIndex == 7 and not (string.match(source, "Vaal Orb"))) then
return false
end
end
if self.dbType == "UNIQUE" and self.controls.requirement.selIndex > 1 then
if (self.controls.requirement.selIndex == 2 or self.controls.requirement.selIndex == 4) and item.requirements.level and item.requirements.level > self.itemsTab.build.characterLevel then
return false
end
if self.controls.requirement.selIndex > 2 and item.requirements and (item.requirements.strMod > self.itemsTab.build.calcsTab.mainOutput.Str or item.requirements.dexMod > self.itemsTab.build.calcsTab.mainOutput.Dex or item.requirements.intMod > self.itemsTab.build.calcsTab.mainOutput.Int) then
return false
end
end
local searchStr = self.controls.search.buf:lower():gsub("[%-%.%+%[%]%$%^%%%?%*]", "%%%0")
if searchStr:match("%S") then
local found = false
local mode = self.controls.searchMode.selIndex
if mode == 1 or mode == 2 then
local err, match = PCall(string.matchOrPattern, item.name:lower(), searchStr)
if not err and match then
found = true
end
end
if mode == 1 or mode == 3 then
for _, line in pairs(item.enchantModLines) do
local err, match = PCall(string.matchOrPattern, line.line:lower(), searchStr)
if not err and match then
found = true
break
end
end
for _, line in pairs(item.implicitModLines) do
local err, match = PCall(string.matchOrPattern, line.line:lower(), searchStr)
if not err and match then
found = true
break
end
end
for _, line in pairs(item.explicitModLines) do
local err, match = PCall(string.matchOrPattern, line.line:lower(), searchStr)
if not err and match then
found = true
break
end
end
if not found then
searchStr = searchStr:gsub(" ","")
for i, mod in ipairs(item.baseModList) do
local err, match = PCall(string.matchOrPattern, mod.name:lower(), searchStr)
if not err and match then
found = true
break
end
end
end
end
if not found then
return false
end
end
return true
end
function ItemDBClass:SetSortMode(sortMode)
self.sortMode = sortMode
self:BuildSortOrder()
self.listBuildFlag = true
end
function ItemDBClass:BuildSortOrder()
wipeTable(self.sortDropList)
for id, stat in ipairs(data.powerStatList) do
if not stat.ignoreForItems then
t_insert(self.sortDropList, {
label="Sort by "..stat.label,
sortMode=stat.itemField or stat.stat,
itemField=stat.itemField,
stat=stat.stat,
transform=stat.transform,
})
end
end
wipeTable(self.sortOrder)
if self.controls.sort then
self.controls.sort:CheckDroppedWidth(true)
self.controls.sort.selIndex = 1
self.controls.sort:SelByValue(self.sortMode, "sortMode")
self.sortDetail = self.controls.sort.list[self.controls.sort.selIndex]
end
if self.sortDetail and self.sortDetail.stat then
t_insert(self.sortOrder, self.sortControl.STAT)
end
t_insert(self.sortOrder, self.sortControl.NAME)
end
function ItemDBClass:ListBuilder()
local list = { }
for id, item in pairs(self.db.list) do
if self:DoesItemMatchFilters(item) then
t_insert(list, item)
end
end
if self.sortDetail and self.sortDetail.stat then -- stat-based
local useFullDPS = self.sortDetail.stat == "FullDPS"
local start = GetTime()
local calcFunc, calcBase = self.itemsTab.build.calcsTab:GetMiscCalculator(self.build)
for itemIndex, item in ipairs(list) do
item.measuredPower = 0
for slotName, slot in pairs(self.itemsTab.slots) do
if self.itemsTab:IsItemValidForSlot(item, slotName) and not slot.inactive and (not slot.weaponSet or slot.weaponSet == (self.itemsTab.activeItemSet.useSecondWeaponSet and 2 or 1)) then
local output = calcFunc(item.base.flask and { toggleFlask = item } or item.base.tincture and { toggleTincture = item } or { repSlotName = slotName, repItem = item }, useFullDPS)
local measuredPower = data.powerStatList.GetFromOutput(output, self.sortDetail)
item.measuredPower = m_max(item.measuredPower, measuredPower)
end
end
local now = GetTime()
if now - start > 50 then
self.defaultText = "^7Sorting... ("..m_floor(itemIndex/#list*100).."%)"
coroutine.yield()
start = now
end
end
end
table.sort(list, function(a, b)
for _, data in ipairs(self.sortOrder) do
local aVal = a[data.key]
local bVal = b[data.key]
if aVal ~= bVal then
if data.dir == "DESCEND" then
if data.func then
return data.func(bVal, aVal)
else
return bVal < aVal
end
else
if data.func then
return data.func(aVal, bVal)
else
return aVal < bVal
end
end
end
end
end)
self.list = list
self.defaultText = "^7No items found that match those filters."
end
function ItemDBClass:Draw(viewPort)
if self.itemsTab.build.outputRevision ~= self.listOutputRevision then
self.listBuildFlag = true
end
if self.listBuildFlag then
self.listBuildFlag = false
wipeTable(self.list)
self.listBuilder = coroutine.create(self.ListBuilder)
self.listOutputRevision = self.itemsTab.build.outputRevision
end
if self.listBuilder and not self.db.loading then
local res, errMsg = coroutine.resume(self.listBuilder, self)
if launch.devMode and not res then
error(errMsg)
end
if coroutine.status(self.listBuilder) == "dead" then
self.listBuilder = nil
end
end
if self.db.loading then
self.defaultText = "^7Loading..."
elseif not self.leaguesAndTypesLoaded then
self:LoadLeaguesAndTypes()
end
self.ListControl.Draw(self, viewPort)
end
function ItemDBClass:GetRowValue(column, index, item)
if column == 1 then
return colorCodes[item.rarity] .. item.name
end
end
function ItemDBClass:AddValueTooltip(tooltip, index, item)
if main.popups[1] then
tooltip:Clear()
return
end
if tooltip:CheckForUpdate(item, IsKeyDown("SHIFT"), launch.devModeAlt, self.itemsTab.build.outputRevision) then
self.itemsTab:AddItemTooltip(tooltip, item, nil, true)
end
end
function ItemDBClass:GetDragValue(index, item)
return "Item", item
end
function ItemDBClass:OnSelClick(index, item, doubleClick)
if IsKeyDown("CTRL") then
-- Add item
local newItem = new("Item", item.raw)
newItem:NormaliseQuality()
self.itemsTab:AddItem(newItem, true)
-- Equip item if able
local slotName = newItem:GetPrimarySlot()
if slotName and self.itemsTab.slots[slotName] then
if self.itemsTab.slots[slotName].weaponSet == 1 and self.itemsTab.activeItemSet.useSecondWeaponSet then
-- Redirect to second weapon set
slotName = slotName .. " Swap"
end
if IsKeyDown("SHIFT") then
-- Redirect to second slot if possible
local altSlot = slotName:gsub("1","2")
if self.itemsTab:IsItemValidForSlot(newItem, altSlot) then
slotName = altSlot
end
end
self.itemsTab.slots[slotName]:SetSelItemId(newItem.id)
end
self.itemsTab:PopulateSlots()
self.itemsTab:AddUndoState()
self.itemsTab.build.buildFlag = true
elseif doubleClick then
self.itemsTab:CreateDisplayItemFromRaw(item.raw, true)
end
end
function ItemDBClass:OnSelCopy(index, item)
Copy(item.raw:gsub("\n","\r\n"))
end
function ItemDBClass:OnHoverKeyUp(key)
if itemLib.wiki.matchesKey(key) then
local item = self.ListControl:GetHoverValue()
if item then
itemLib.wiki.openItem(item)
end
end
end