forked from Dolgubon/DolgubonsLazySetCrafter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetupScrollLists.lua
556 lines (451 loc) · 16.7 KB
/
SetupScrollLists.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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
local DolgubonScroll = ZO_SortFilterList:Subclass()
DolgubonSetCrafter.scroll = DolgubonScroll
local MaterialScroll = ZO_SortFilterList:Subclass()
DolgubonSetCrafter.MaterialScroll = MaterialScroll
DolgubonSetCrafter.materialList = DolgubonSetCrafter.materialList or {}
local FavouriteScroll = ZO_SortFilterList:Subclass()
DolgubonSetCrafter.FavouriteScroll = FavouriteScroll
local updateList = function() end
local updateMaterials = function() end
-- Create the scroll list for the queue
function DolgubonScroll:New(control)
ZO_SortFilterList.InitializeSortFilterList(self, control)
local SorterKeys =
{
name = {},
Reference = {},
}
self.masterList = {}
ZO_ScrollList_AddDataType(self.list, 1, "CraftingRequestTemplate", 30, function(control, data) self:SetupEntry(control, data) end)
ZO_ScrollList_AddDataType(self.list, 2, "FurnitureRequestTemplate", 30, function(control, data) self:SetupFurnitureEntry(control, data) end)
ZO_ScrollList_EnableHighlight(self.list, "ZO_ThinListHighlight")
self.currentSortKey = "Reference"
self.currentSortOrder = ZO_SORT_ORDER_UP
self.sortFunction = function(listEntry1, listEntry2) return ZO_TableOrderingFunction(listEntry1.data[1], listEntry2.data[1], "Reference", SorterKeys, self.currentSortOrder) end
self.data = DolgubonSetCrafter.savedvars.queue
return self
end
local validPriceSources
local function getLibPrice(itemLink)
if LibPrice then
local price = LibPrice.ItemLinkToPriceGold(itemLink)
if price then
return price
end
end
end
local function getMMPrice(itemLink)
if MasterMerchant then
price = MasterMerchant:itemStats(itemLink, false).avgPrice
if price then
return price
end
end
end
local function getATTPrice(itemLink)
if ArkadiusTradeTools and ArkadiusTradeTools.Modules
and ArkadiusTradeTools.Modules.Sales and ArkadiusTradeTools.Modules.Sales.addMenuItems then
local day_secs = 24*60*60
for _,day_ct in ipairs({ 10, 30 }) do
att = ArkadiusTradeTools.Modules.Sales:GetAveragePricePerItem(
itemLink, GetTimeStamp() - (day_secs * day_ct))
if att and 0 < att then
return att
end
end
end
end
local function getTTCPrice(itemLink)
if TamrielTradeCentrePrice then
local t = TamrielTradeCentrePrice:GetPriceInfo(itemLink)
if t and t.SuggestedPrice then
return t.SuggestedPrice
end
end
end
local function addonChoicePrice(itemLink)
for i = 2, #validPriceSources do
if validPriceSources[i][2] then
price = validPriceSources[i][3](itemLink)
if price then
return price
end
end
end
end
local function generateValidPriceSources()
local validPriceSources =
{
{"Currently using Set Crafter's choice", true, addonChoicePrice},
{"Currently using prices from LibPrice", LibPrice, getLibPrice},
{'Currently using prices from MasterMerchant', MasterMerchant, getMMPrice},
{'Currently using prices from Arkadius Trade Tools', ArkadiusTradeTools and ArkadiusTradeTools.Modules and ArkadiusTradeTools.Modules.Sales and ArkadiusTradeTools.Modules.Sales.addMenuItems, getATTPrice},
{'Currently using prices from Tamriel Trade Center', TamrielTradeCentrePrice, getTTCPrice},
{"Currently using the game's default prices", true, GetItemLinkValue},
}
for i = 2, #validPriceSources do
if validPriceSources[i][2] then
validPriceSources[1][1] = validPriceSources[i][1].." (Set Crafter's choice)"
validPriceSources[1][4] = i
return validPriceSources
end
end
end
function DolgubonSetCrafter.togglePriceSource()
DolgubonSetCrafter.savedvars.currentPriceChoice = ((DolgubonSetCrafter.savedvars.currentPriceChoice ) % #validPriceSources )+ 1
while not validPriceSources[DolgubonSetCrafter.savedvars.currentPriceChoice][2] and DolgubonSetCrafter.savedvars.currentPriceChoice~= validPriceSources[1][4] do
DolgubonSetCrafter.savedvars.currentPriceChoice = ((DolgubonSetCrafter.savedvars.currentPriceChoice ) % #validPriceSources )+ 1
end
DolgubonSetCrafter.updateList()
end
local function getPrice(itemLink)
local price
if validPriceSources[DolgubonSetCrafter.savedvars.currentPriceChoice][2] then
price = validPriceSources[DolgubonSetCrafter.savedvars.currentPriceChoice][3](itemLink)
if price then
return price
end
end
return addonChoicePrice(itemLink) or 0
end
function DolgubonSetCrafter.getCurrentPriceAddonString()
return validPriceSources[DolgubonSetCrafter.savedvars.currentPriceChoice][1]
end
local function round(price)
price = math.floor( price * 100 + 0.5)
price = price/100
return price
end
local function updateCost()
local cost = 0
for k, v in pairs(DolgubonSetCrafter.materialList) do
local link = v["Name"]
local price = round(getPrice(link))
cost = cost + price * v["Amount"]
end
cost = zo_strformat(SI_NUMBER_FORMAT, ZO_AbbreviateNumber(cost, NUMBER_ABBREVIATION_PRECISION_HUNDREDTHS, USE_LOWERCASE_NUMBER_SUFFIXES))
DolgubonSetCrafterWindowRightCost:SetText("Total Cost: "..cost.." |t20:20:esoui/art/currency/currency_gold_64.dds|t")
end
local function updateCurrentAmounts()
DolgubonSetCrafter.recompileMatRequirements(DolgubonSetCrafter.materialList)
for k, v in pairs(DolgubonSetCrafter.materialList) do
local link = v["Name"]
local bag, bank, craft = GetItemLinkStacks(link)
v["Current"] = bag + bank + craft
end
end
-- Create the scroll list for the materials
function MaterialScroll:New(control)
ZO_SortFilterList.InitializeSortFilterList(self, control)
local SorterKeys =
{
name = {},
Amount = {},
}
self.masterList = {}
ZO_ScrollList_AddDataType(self.list, 1, "SetCrafterMaterialTemplate", 30, function(control, data) self:SetupEntry(control, data) end)
ZO_ScrollList_EnableHighlight(self.list, "ZO_ThinListHighlight")
self.currentSortKey = "Amount"
self.currentSortOrder = ZO_SORT_ORDER_DOWN
self.sortFunction = function(listEntry1, listEntry2) return ZO_TableOrderingFunction(listEntry1.data[1], listEntry2.data[1], "Amount", SorterKeys, self.currentSortOrder) end
self.data = DolgubonSetCrafter.materialList
local originalRefresh = self.RefreshData
self.RefreshData = function(...)
updateCurrentAmounts()
originalRefresh(...)
updateCost()
end
return self
end
function FavouriteScroll:New(control)
ZO_SortFilterList.InitializeSortFilterList(self, control)
local SorterKeys =
{
name = {},
}
self.masterList = {}
ZO_ScrollList_AddDataType(self.list, 1, "SetCrafterFavouriteTemplate", 30, function(control, data) self:SetupEntry(control, data) end)
ZO_ScrollList_EnableHighlight(self.list, "ZO_ThinListHighlight")
self.currentSortKey = "name"
self.currentSortOrder = ZO_SORT_ORDER_DOWN
self.sortFunction = function(listEntry1, listEntry2) return 1 end
self.data = DolgubonSetCrafter.savedvars.faves
return self
end
function FavouriteScroll:SetupEntry(control, data)
control.data = data
control:setCurrent(data[1])
control.label = control:GetNamedChild("Name")
control.label:SetText(data[1].name)
ZO_SortFilterList.SetupRow(self, control, data)
end
local function formatAmountEntry(self, amountRequired, current)
local text
if current < amountRequired then
amountRequired = zo_strformat(SI_NUMBER_FORMAT, ZO_AbbreviateNumber(amountRequired, NUMBER_ABBREVIATION_PRECISION_TENTHS, USE_LOWERCASE_NUMBER_SUFFIXES))
current = zo_strformat(SI_NUMBER_FORMAT, ZO_AbbreviateNumber(current, NUMBER_ABBREVIATION_PRECISION_TENTHS, USE_LOWERCASE_NUMBER_SUFFIXES))
text = "|cFFBFBF"..tostring(current).."|r/"..tostring(amountRequired)
else
amountRequired = zo_strformat(SI_NUMBER_FORMAT, ZO_AbbreviateNumber(amountRequired, NUMBER_ABBREVIATION_PRECISION_TENTHS, USE_LOWERCASE_NUMBER_SUFFIXES))
current = zo_strformat(SI_NUMBER_FORMAT, ZO_AbbreviateNumber(current, NUMBER_ABBREVIATION_PRECISION_TENTHS, USE_LOWERCASE_NUMBER_SUFFIXES))
text = tostring(current).."/"..tostring(amountRequired)
end
self:SetText(text)
local width = self:GetTextWidth()
end
function MaterialScroll:SetupEntry(control, data)
control.data = data
control.isKnown = data[1]["Amount"]<= data[1]["Current"]
for k , v in pairs(data[1]) do
control[k] = GetControl(control, k)
if control[k] then
if k == "Amount" then
formatAmountEntry(control[k], v, data[1]["Current"])
else
control[k]:SetText(v)
end
end
end
local BG = GetControl(control, "BG")
if BG then
BG:SetAnchorFill(control)
--BG.nonRecolorable = false
--local colour = BG.SetColor
--BG.SetColor = function() end
--BG.HideSetColor = colour
if not control.isKnown then
--BG:SetColor(1,0.5,0.5,0.2)
BG:SetCenterColor(1, 0.5, 0.5, 0.2)
BG:SetEdgeColor(0,0,0,0)
else
--BG:SetColor(0.5,0.8,1,0.2)
BG:SetEdgeColor(0,0,0, 0)
BG:SetCenterColor(0.5,0.5,0.5,0.05)
end
end
ZO_SortFilterList.SetupRow(self, control, data)
end
function DolgubonSetCrafter.outputSingleMatLine(control)
local text
text = tostring(control.data[1]["Amount"]).." "
text = text..control.data[1]["Name"]
return text
end
outputTexts = {}
--@nighn_9, 38
local function outputMultipleLinesChat(textToOutput)
StartChatInput(textToOutput[1])
local function OutputNextLine(eventCode, channelType, fromName, text, isCustomerService, fromDisplayName)
if fromDisplayName == GetDisplayName() or channelType == CHAT_CHANNEL_WHISPER_SENT then
if text == textToOutput[1] then
table.remove(textToOutput, 1)
if #textToOutput>0 then
StartChatInput(textToOutput[1])
else
d("Chat sending complete!")
EVENT_MANAGER:UnregisterForEvent(DolgubonSetCrafter.name,EVENT_CHAT_MESSAGE_CHANNEL)
end
else
end
end
end
EVENT_MANAGER:UnregisterForEvent(DolgubonSetCrafter.name,EVENT_CHAT_MESSAGE_CHANNEL)
EVENT_MANAGER:RegisterForEvent(DolgubonSetCrafter.name,EVENT_CHAT_MESSAGE_CHANNEL, OutputNextLine)
end
function DolgubonSetCrafter.outputAllMats()
local tempMatHolder = {}
for k, v in pairs(DolgubonSetCrafter.materialList) do
tempMatHolder[#tempMatHolder + 1] = v
end
if #tempMatHolder == 0 then return end
table.sort(tempMatHolder, function(a, b) return a["Amount"]>b["Amount"]end)
outputTexts = {}
local text = "Requires: "
for i = 1, #tempMatHolder do
if i %4 ==1 and i > 1 then
outputTexts[#outputTexts + 1] = text
text = "And: "
end
if i>1 and not (i %4 ==1 and i>1) then
text = text.." l "
end
text =text.. tostring(tempMatHolder[i]["Amount"]).." "..tempMatHolder[i]["Name"]
end
outputTexts[#outputTexts + 1] = text
outputMultipleLinesChat(outputTexts)
end
function DolgubonSetCrafter.outputRequest()
if next(DolgubonSetCrafter.materialList) == nil then
d("Dolgubon's Lazy Set Crafter: No items are in the queue! No mails sent")
return
end
local sets = {} -- A list of all items under the current set type.
local setTypes = {} -- Used to keep the sets list in a certain order.
local mailInfo = {}
local outputTexts = {}
local tempMatHolder = {}
local text = ""
local mailQueue = DolgubonSetCrafter.savedvars.queue
for i, request in ipairs(mailQueue) do
if request.typeId == 1 then
local setName = request["Set"][2]
if sets[setName] == nil then
sets[setName] = {}
table.insert(setTypes, setName) -- Save this index of this set's name
end
table.insert(sets[setName], DolgubonSetCrafter.convertRequestToText(request)) -- Store the readable crafting information
end
end
for setName, requestInfos in pairs(sets) do
outputTexts[#outputTexts + 1] = "From the set "..setName..", please make:"
for i = 1, #requestInfos do
if i %2 ==1 and i > 1 then
outputTexts[#outputTexts + 1] = text
text = ""
else
text = text.." "
end
text =text.. requestInfos[i]
end
outputTexts[#outputTexts + 1] = text
text = ""
end
local addedProvisioningGreeting = false
for i, request in pairs(mailQueue) do
if request.typeId == 2 then
if not addedProvisioningGreeting then
addedProvisioningGreeting = true
outputTexts[#outputTexts + 1] = "Please create these provisioning/furniture items:"
end
outputTexts[#outputTexts + 1] = request.Quantity[1].."x "..request.Link
end
end
outputMultipleLinesChat(outputTexts)
end
local function removeFauxRequest(reference)
for i = 1, #DolgubonSetCrafter.savedvars.queue do
if DolgubonSetCrafter.savedvars.queue[i]["reference"]==reference then
table.remove( DolgubonSetCrafter.savedvars.queue, i)
return
end
end
end
function DolgubonScroll:SetupEntry(control, data)
control.A_ScrollList = self
control.data = data
if data[1].CraftRequestTable[7] ~= CRAFTING_TYPE_JEWELRYCRAFTING then
control.usesMimicStone = data[1].CraftRequestTable[6]
GetControl(control, "MimicStone"):SetHidden(not data[1].CraftRequestTable[6])
control:GetNamedChild("Style"):SetHidden(false)
else
control:GetNamedChild("Style"):SetHidden(true)
GetControl(control, "MimicStone"):SetHidden(true)
control.usesMimicStone = false
end
control.qualityString = zo_strformat(DolgubonSetCrafter.localizedStrings.UIStrings.qualityString, data[1].Quality[2])
for k , v in pairs (data[1]) do
control[k] = GetControl(control, k)
if control[k] then
if type(v)=="table" then
control[k]:SetText(v[2])
control[k]:SetColor(1,1,0)
if k == "Enchant" then
control[k]:ApplyEnchantColour()
else
control[k]:ApplyColour(v.isKnown)
end
else
if k == "Enchant" then
control[k]:SetText(v)
control[k]:ApplyEnchantColour()
else
control[k]:SetText(v)
end
end
end
end
local button = control:GetNamedChild( "RemoveButton")
if DolgubonSetCrafter.isRequestInProgressByReference(data[1].Reference) then
button.tooltip = DolgubonSetCrafter.localizedStrings.UIStrings.inProgressCrafting
WINDOW_MANAGER:ApplyTemplateToControl(button, "SetCrafterRequestInProgress")
else
WINDOW_MANAGER:ApplyTemplateToControl(button, "SetCrafterRequestNotInProgress")
button.tooltip = nil
end
function button:onClickety () DolgubonSetCrafter.removeFromScroll(data[1].Reference, true) end
--function control:onClicked () DolgubonsGuildBlacklistWindowInputBox:SetText(data.name) end
ZO_SortFilterList.SetupRow(self, control, data)
end
function DolgubonScroll:SetupFurnitureEntry(control, data)
control.data = data
-- control.qualityString = zo_strformat(DolgubonSetCrafter.localizedStrings.UIStrings.qualityString, data[1].Quality[2])
local qual = data[1]["Quality"][1]
local qualityColour = {GetItemQualityColor(qual or 2)}
for k , v in pairs (data[1]) do
control[k] = GetControl(control, k)
if control[k] then
if type(v)=="table" then
control[k]:SetText(v[2])
control[k]:SetHidden(false)
control[k]:SetColor(unpack(qualityColour))
control[k]:ApplyColour(true)
end
end
end
local button = control:GetNamedChild( "RemoveButton")
WINDOW_MANAGER:ApplyTemplateToControl(button, "SetCrafterRequestNotInProgress")
button.tooltip = nil
function button:onClickety () DolgubonSetCrafter.removeFromScroll(data[1].Reference, true) end
--function control:onClicked () DolgubonsGuildBlacklistWindowInputBox:SetText(data.name) end
ZO_SortFilterList.SetupRow(self, control, data)
end
function DolgubonScroll:BuildMasterList()
self.masterList = {}
for k, v in pairs(self.data) do
table.insert(self.masterList, {
v, ["typeId"] = v.typeId
})
end
end
function DolgubonScroll:SortScrollList()
local scrollData = ZO_ScrollList_GetDataList(self.list)
table.sort(scrollData, self.sortFunction)
end
function DolgubonScroll:FilterScrollList()
local scrollData = ZO_ScrollList_GetDataList(self.list)
ZO_ClearNumericallyIndexedTable(scrollData)
for i = 1, #self.masterList do
local data = self.masterList[i]
table.insert(scrollData, ZO_ScrollList_CreateDataEntry(data.typeId or 1, data))
end
end
MaterialScroll.BuildMasterList = DolgubonScroll.BuildMasterList
MaterialScroll.SortScrollList = DolgubonScroll.SortScrollList
MaterialScroll.FilterScrollList = DolgubonScroll.FilterScrollList
FavouriteScroll.BuildMasterList = DolgubonScroll.BuildMasterList
FavouriteScroll.FilterScrollList = DolgubonScroll.FilterScrollList
function DolgubonSetCrafter.setupScrollLists()
DolgubonSetCrafter.manager = DolgubonScroll:New(CraftingQueueScroll)
DolgubonSetCrafter.materialManager = MaterialScroll:New(DolgubonSetCrafterWindowMaterialList)
DolgubonSetCrafter.favouritesManager = FavouriteScroll:New(DolgubonSetCrafterWindowFavouritesScroll)
validPriceSources = generateValidPriceSources()
end
local function countTotalItems()
local sum = 0
for k, v in pairs(DolgubonSetCrafter.savedvars.queue) do
sum = sum + tonumber((v.Quantity and v.Quantity[1]) or 1)
end
return sum
end
DolgubonSetCrafter.countTotalQueuedItems = countTotalItems
updateList = function ()
DolgubonSetCrafter.manager:RefreshData()
DolgubonSetCrafter.materialManager:RefreshData()
DolgubonSetCrafter.favouritesManager:RefreshData()
if #DolgubonSetCrafter.savedvars.queue == 0 then
CraftingQueueScrollCounter:SetText()
else
CraftingQueueScrollCounter:SetText(" - "..countTotalItems())
end
end
DolgubonSetCrafter.updateList = updateList