forked from Mirroar/TopFit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtooltip.lua
More file actions
799 lines (693 loc) · 32.9 KB
/
tooltip.lua
File metadata and controls
799 lines (693 loc) · 32.9 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
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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
-- utility for rounding
local function round(input, places)
if not places then
places = 0
end
if type(input) == "number" and type(places) == "number" then
local pow = 1
for i = 1, ceil(places) do
pow = pow * 10
end
return floor(input * pow + 0.5) / pow
else
return input
end
end
local function percentilize(ratio, noColor)
local ratioString
if ratio > 11 then
ratioString = (noColor and '' or "|cff00ff00").."> 1000%"..(noColor and '' or "|r")
elseif ratio > 1.1 then
ratioString = (noColor and '' or "|cff00ff00")..round((ratio - 1) * 100, 2).."%"..(noColor and '' or "|r")
elseif ratio >= 1 then
ratioString = (noColor and '' or "|cffffff00")..round((ratio - 1) * 100, 2).."%"..(noColor and '' or "|r")
elseif ratio < -9 then
ratioString = (noColor and '' or "|cffff0000").."< -1000%"..(noColor and '' or "|r")
else -- ratio < 1
ratioString = (noColor and '' or "|cffff0000")..round((ratio - 1) * 100, 2).."%"..(noColor and '' or "|r")
end
return ratioString
end
-- takes a string and escapes the magic characters ^$()%.[]*+-? with a %-character for safe use in Lua patterns
local function noPattern(text)
return string.gsub(text, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1")
end
-- Tooltip formatter
function TopFit:getComparisonTooltipLines(item)
local lines = {}
--compareItem = TopFit:GetCachedItem(12345)
local tooltipFormat = {
{" "},
{"##############TopFit Tooltip!################"},
{"Comparing with your items for [setlist]"},
{"[setpercentages:nocolor]"},
}
for lineNumber = 1, #tooltipFormat do
local lineTable = tooltipFormat[lineNumber]
local tooltipLine = {}
for columnNumber = 1, 2 do
local lineText = lineTable[columnNumber] or ""
lineText = TopFit:replaceTokensInString(lineText, item)
tinsert(tooltipLine, lineText)
end
tinsert(lines, tooltipLine)
end
return lines
end
function TopFit:replaceTokensInString(text, item)
local findOffset = 1
local setIDs = TopFit:getSetIDs(true)
local setNames = TopFit:getSetNames(true)
repeat
local findStart, findEnd, findString = string.find(text, "%[(.-)%]", findOffset)
if findStart then
local parts = TopFit:getTokenAndArguments(findString)
local token = string.lower(parts[1])
replaceText = "[" .. findString .. "]"
if token == "setlist" then
local namesString = ''
for i = 1, #setNames do
local setName = setNames[i];
if namesString ~= '' then
namesString = namesString..', '
end
namesString = namesString..setName
end
replaceText = namesString
elseif token == "setpercentages" then
local noColor = false
for i = 2, #parts do
local modifier = parts[i]
if string.lower(modifier) == 'nocolor' then
noColor = true
end
end
local percentagesString = ''
for i = 1, #setIDs do
local setID = setIDs[i]
local percentage = TopFit:getComparePercentage(item, setID)
if percentagesString ~= '' then
percentagesString = percentagesString..', '
end
percentagesString = percentagesString..percentilize(percentage, noColor)..'%'
end
replaceText = percentagesString
else
findOffset = findStart + 1 -- keep looking behind this unknown token
end
text = string.gsub(text, "%["..noPattern(findString).."%]", replaceText)
end
until not findStart
return text
end
function TopFit:getTokenAndArguments(token)
local parts = {string.split(':', token)}
return parts
end
function TopFit:getSetNames(forTooltip)
local output = {}
for i = 1, 100 do
local setTable = TopFit.db.profile.sets['set_'..i];
if setTable and not (forTooltip and setTable.excludeFromTooltip) then
tinsert(output, setTable.name)
end
end
return output
end
function TopFit:getSetIDs(forTooltip)
local output = {}
for i = 1, 100 do
setTable = TopFit.db.profile.sets['set_'..i];
if setTable and (not forTooltip or not setTable.excludeFromTooltip) then
tinsert(output, 'set_'..i)
end
end
return output
end
-- calculates the items that the given item should be compared to in a tooltip
function TopFit:getCompareItems(itemTable, setCode)
local compareSets = {}
if itemTable and setCode then
-- find current item(s) from set
local setItemPositions = GetEquipmentSetLocations(TopFit:GenerateSetName(setTable.name))
local setItemIDs = GetEquipmentSetItemIDs(TopFit:GenerateSetName(setTable.name))
local setItemLinks = {}
if not setItemPositions then return end
for slotID, setItemLocation in pairs(setItemPositions) do
if setItemLocation and setItemLocation ~= 1 and setItemLocation ~= 0 then -- 0: no item; 1: slot is ignored
local setItemLink = nil
local player, bank, bags, slot, bag = EquipmentManager_UnpackLocation(setItemLocation)
if player then
if bank then
-- item is banked, use itemID
local itemID = GetEquipmentSetItemIDs(TopFit:GenerateSetName(TopFit.db.profile.sets[setCode].name))[slotID]
if itemID and itemID ~= 1 then
_, setItemLink = GetItemInfo(itemID)
end
elseif bags then
-- item is in player's bags
setItemLink = GetContainerItemLink(bag, slot)
else
-- item is equipped
setItemLink = GetInventoryItemLink("player", slot)
end
else
-- item not found
end
setItemLinks[slotID] = setItemLink
end
end
for _, slotID in pairs(itemTable.equipLocationsByType) do
-- for each slot the item can be equipped in
local setItemID = nil
local setItemLink = nil
local extraText = ""
local compareTable = nil
local itemTable2 = nil
local compareTable2 = nil
local compareNotCached = false
if setItemIDs and setItemIDs[slotID] and setItemIDs[slotID] ~= 1 and setItemIDs[slotID] ~= 0 then
setItemID = setItemIDs[slotID]
setItemLink = setItemLinks[slotID]
if setItemLink then
setItemTable = TopFit:GetCachedItem(setItemLink)
end
if not setItemTable then
compareNotCached = true
end
end
-- location tables for best-in-slot requests
local locationTable, compLocationTable
if (slotID == 16 or slotID == 17) then
locationTable = {itemLink = itemTable.itemLink, slot = nil, bag = nil}
if setItemTable then
local player, bank, bags, slot, bag = EquipmentManager_UnpackLocation(setItemPositions[slotID])
if player then
if bags then
compLocationTable = {itemLink = setItemTable.itemLink, slot = slot, bag = bag}
elseif bank then
compLocationTable = {itemLink = setItemTable.itemLink, slot = nil, bag = nil}
else
compLocationTable = {itemLink = setItemTable.itemLink, slot = slot, bag = nil}
end
else
compLocationTable = {itemLink = setItemTable.itemLink, slot = nil, bag = nil}
end
else
compLocationTable = {itemLink = "", slot = nil, bag = nil}
end
end
tinsert(compareSets, {
setItemTable
})
end
end
return compareSets
end
function TopFit:getComparePercentage(itemTable, setCode)
if not itemTable or not setCode then return 0 end
local setTable = TopFit.db.profile.sets[setCode]
if not setTable then return 0 end
local rawScore, asIsScore, rawCompareScore, asIsCompareScore = 0, 0, 0, 0
rawScore = TopFit:GetItemScore(itemTable.itemLink, setCode, false, true) -- including caps, raw score
asIsScore = TopFit:GetItemScore(itemTable.itemLink, setCode, false, false) -- including caps, enchanted score
if true then return 0 end
if slotID == 16 then -- main hand slot
if TopFit:IsOnehandedWeapon(link) then
-- is the weapon we compare to (if it exists) two-handed?
if setItemIDs and setItemIDs[slotID] and setItemIDs[slotID] ~= 1 and setItemIDs[slotID] ~= 0 and not TopFit:IsOnehandedWeapon(setItemIDs[slotID]) then
-- try to find a fitting offhand for better comparison
if TopFit.playerCanDualwield then
-- find best offhand regardless of type
local lTable2 = TopFit:CalculateBestInSlot({locationTable, compLocationTable}, false, 17, setCode, function(locationTable) return TopFit:IsOnehandedWeapon(locationTable.itemLink) end)
if lTable2 then
itemTable2 = TopFit:GetCachedItem(lTable2.itemLink)
end
else
-- find best offhand that is not a weapon
local lTable2 = TopFit:CalculateBestInSlot({locationTable, compLocationTable}, false, 17, setCode, function(locationTable) itemTable = TopFit:GetCachedItem(locationTable.itemLink); if not itemTable or string.find(itemTable.itemEquipLoc, "WEAPON") then return false else return true end end)
if lTable2 then
itemTable2 = TopFit:GetCachedItem(lTable2.itemLink)
end
end
else
end
else
if setItemIDs and setItemIDs[slotID] and setItemIDs[slotID] ~= 1 then
-- mainhand is set
if TopFit:IsOnehandedWeapon(setItemIDs[slotID]) then
-- use offhand of that set as second compare item
if (setItemLinks[17]) then
compareTable2 = TopFit:GetCachedItem(setItemLinks[17])
end
else
-- compare normally, these are 2 two-handed weapons
end
else
-- compare with offhand if appliccapble
if (setItemLinks[17]) then
compareTable2 = TopFit:GetCachedItem(setItemLinks[17])
end
end
end
elseif slotID == 17 then -- offhand slot
-- find a valid mainhand to use in comparisons (only when comparing to a 2h)
if setItemIDs and setItemIDs[16] and setItemIDs[16] ~= 1 and not TopFit:IsOnehandedWeapon(setItemIDs[16]) then
local lTable2 = TopFit:CalculateBestInSlot({locationTable, compLocationTable}, false, 16, setCode, function(locationTable) return TopFit:IsOnehandedWeapon(locationTable.itemLink) end)
if lTable2 then
itemTable2 = TopFit:GetCachedItem(lTable2.itemLink)
end
-- also set compareTable to the relevant MAIN HAND! since offhand is empty, obviously
compareTable = TopFit:GetCachedItem(setItemLinks[16])
if compareTable then
rawCompareScore = TopFit:GetItemScore(compareTable.itemLink, setCode, false, true)
asIsCompareScore = TopFit:GetItemScore(compareTable.itemLink, setCode, false, false)
else
compareNotCached = true
end
end
end
if itemTable2 then
rawScore = rawScore + TopFit:GetItemScore(itemTable2.itemLink, setCode, false, true)
asIsScore = asIsScore + TopFit:GetItemScore(itemTable2.itemLink, setCode, false, false)
extraText = extraText..", if you also use "..itemTable2.itemLink
end
if compareTable2 then
rawCompareScore = rawCompareScore + TopFit:GetItemScore(compareTable2.itemLink, setCode, false, true)
asIsCompareScore = asIsCompareScore + TopFit:GetItemScore(compareTable2.itemLink, setCode, false, false)
extraText = extraText..", "..compareTable2.itemLink
end
local ratio, rawRatio, ratioString, rawRatioString = 1, 1, "", ""
if rawCompareScore ~= 0 then
rawRatio = rawScore / rawCompareScore
elseif rawScore > 0 then
rawRatio = 20
elseif rawScore < 0 then
rawRatio = -20
end
if asIsCompareScore ~= 0 then
ratio = asIsScore / asIsCompareScore
elseif asIsScore > 0 then
ratio = 20
elseif asIsScore < 0 then
ratio = -20
end
local compareItemText = ""
if compareNotCached then
compareItemText = "Item not in cache!|n"
elseif not compareTable then
compareItemText = "No item in set"
else
compareItemText = compareTable.itemLink
end
if ratio ~= rawRatio then
tt:AddDoubleLine("["..percentilize(rawRatio).."/"..percentilize(ratio).."] - "..compareItemText..extraText, setTable.name)
else
tt:AddDoubleLine("["..percentilize(rawRatio).."] - "..compareItemText..extraText, setTable.name)
end
end
-- Tooltip functions
local cleared = true
local refCleared = true
local s1Cleared = true
local s2Cleared = true
local function TooltipAddCompareLines(tt, link)
local itemTable = TopFit:GetCachedItem(link)
TopFit:Debug("Adding Compare Tooltip for "..(link or "nil"))
-- if the item is not yet cached, no tooltip info is added
if not itemTable then
return
end
-- iterate all sets and compare with set's items
tt:AddLine(" ")
tt:AddLine("Compared with your current items for each set:")
for setCode, setTable in pairs(TopFit.db.profile.sets) do
if not TopFit.db.profile.sets[setCode].excludeFromTooltip then
-- find current item(s) from set
local itemPositions = GetEquipmentSetLocations(TopFit:GenerateSetName(setTable.name))
local itemIDs = GetEquipmentSetItemIDs(TopFit:GenerateSetName(setTable.name))
local itemLinks = {}
if itemPositions then
for slotID, itemLocation in pairs(itemPositions) do
if itemLocation and itemLocation ~= 1 and itemLocation ~= 0 then -- 0: set to no item; 1: slot is ignored
local itemLink = nil
local player, bank, bags, slot, bag = EquipmentManager_UnpackLocation(itemLocation)
if player then
if bank then
-- item is banked, use itemID
local itemID = GetEquipmentSetItemIDs(TopFit:GenerateSetName(TopFit.db.profile.sets[setCode].name))[slotID]
if itemID and itemID ~= 1 then
_, itemLink = GetItemInfo(itemID)
end
elseif bags then
-- item is in player's bags
itemLink = GetContainerItemLink(bag, slot)
else
-- item is equipped
itemLink = GetInventoryItemLink("player", slot)
end
else
-- item not found
end
itemLinks[slotID] = itemLink
end
end
for _, slotID in pairs(itemTable.equipLocationsByType) do
-- get compare items sorted out
local itemID = nil
local itemLink = nil
local rawScore, asIsScore, rawCompareScore, asIsCompareScore = 0, 0, 0, 0
local extraText = ""
local compareTable = nil
local itemTable2 = nil
local compareTable2 = nil
local compareNotCached = false
rawScore = TopFit:GetItemScore(itemTable.itemLink, setCode, false, true) -- including caps, raw score
asIsScore = TopFit:GetItemScore(itemTable.itemLink, setCode, false, false) -- including caps, enchanted score
if itemIDs and itemIDs[slotID] and itemIDs[slotID] ~= 1 and itemIDs[slotID] ~= 0 then
itemID = itemIDs[slotID]
itemLink = itemLinks[slotID]
if itemLink then
compareTable = TopFit:GetCachedItem(itemLink)
end
if compareTable then
rawCompareScore = TopFit:GetItemScore(compareTable.itemLink, setCode, false, true)
asIsCompareScore = TopFit:GetItemScore(compareTable.itemLink, setCode, false, false)
else
compareNotCached = true
end
end
-- location tables for best-in-slot requests
local locationTable, compLocationTable
if (slotID == 16 or slotID == 17) then
locationTable = {itemLink = itemTable.itemLink, slot = nil, bag = nil}
if compareTable then
local player, bank, bags, slot, bag = EquipmentManager_UnpackLocation(itemPositions[slotID])
if player then
if bags then
compLocationTable = {itemLink = compareTable.itemLink, slot = slot, bag = bag}
elseif bank then
compLocationTable = {itemLink = compareTable.itemLink, slot = nil, bag = nil}
else
compLocationTable = {itemLink = compareTable.itemLink, slot = slot, bag = nil}
end
else
compLocationTable = {itemLink = compareTable.itemLink, slot = nil, bag = nil}
end
else
compLocationTable = {itemLink = "", slot = nil, bag = nil}
end
end
if slotID == 16 then -- main hand slot
if TopFit:IsOnehandedWeapon(link) then
-- is the weapon we compare to (if it exists) two-handed?
if itemIDs and itemIDs[slotID] and itemIDs[slotID] ~= 1 and itemIDs[slotID] ~= 0 and not TopFit:IsOnehandedWeapon(itemIDs[slotID]) then
-- try to find a fitting offhand for better comparison
if TopFit.playerCanDualwield then
-- find best offhand regardless of type
local lTable2 = TopFit:CalculateBestInSlot({locationTable, compLocationTable}, false, 17, setCode, function(locationTable) return TopFit:IsOnehandedWeapon(locationTable.itemLink) end)
if lTable2 then
itemTable2 = TopFit:GetCachedItem(lTable2.itemLink)
end
else
-- find best offhand that is not a weapon
local lTable2 = TopFit:CalculateBestInSlot({locationTable, compLocationTable}, false, 17, setCode, function(locationTable) itemTable = TopFit:GetCachedItem(locationTable.itemLink); if not itemTable or string.find(itemTable.itemEquipLoc, "WEAPON") then return false else return true end end)
if lTable2 then
itemTable2 = TopFit:GetCachedItem(lTable2.itemLink)
end
end
else
end
else
if itemIDs and itemIDs[slotID] and itemIDs[slotID] ~= 1 then
-- mainhand is set
if TopFit:IsOnehandedWeapon(itemIDs[slotID]) then
-- use offhand of that set as second compare item
if (itemLinks[17]) then
compareTable2 = TopFit:GetCachedItem(itemLinks[17])
end
else
-- compare normally, these are 2 two-handed weapons
end
else
-- compare with offhand if appliccapble
if (itemLinks[17]) then
compareTable2 = TopFit:GetCachedItem(itemLinks[17])
end
end
end
elseif slotID == 17 then -- offhand slot
-- find a valid mainhand to use in comparisons (only when comparing to a 2h)
if itemIDs and itemIDs[16] and itemIDs[16] ~= 1 and not TopFit:IsOnehandedWeapon(itemIDs[16]) then
local lTable2 = TopFit:CalculateBestInSlot({locationTable, compLocationTable}, false, 16, setCode, function(locationTable) return TopFit:IsOnehandedWeapon(locationTable.itemLink) end)
if lTable2 then
itemTable2 = TopFit:GetCachedItem(lTable2.itemLink)
end
-- also set compareTable to the relevant MAIN HAND! since offhand is empty, obviously
compareTable = TopFit:GetCachedItem(itemLinks[16])
if compareTable then
rawCompareScore = TopFit:GetItemScore(compareTable.itemLink, setCode, false, true)
asIsCompareScore = TopFit:GetItemScore(compareTable.itemLink, setCode, false, false)
else
compareNotCached = true
end
end
end
if itemTable2 then
rawScore = rawScore + TopFit:GetItemScore(itemTable2.itemLink, setCode, false, true)
asIsScore = asIsScore + TopFit:GetItemScore(itemTable2.itemLink, setCode, false, false)
extraText = extraText..", if you also use "..itemTable2.itemLink
end
if compareTable2 then
rawCompareScore = rawCompareScore + TopFit:GetItemScore(compareTable2.itemLink, setCode, false, true)
asIsCompareScore = asIsCompareScore + TopFit:GetItemScore(compareTable2.itemLink, setCode, false, false)
extraText = extraText..", "..compareTable2.itemLink
end
local ratio, rawRatio, ratioString, rawRatioString = 1, 1, "", ""
if rawCompareScore ~= 0 then
rawRatio = rawScore / rawCompareScore
elseif rawScore > 0 then
rawRatio = 20
elseif rawScore < 0 then
rawRatio = -20
end
if asIsCompareScore ~= 0 then
ratio = asIsScore / asIsCompareScore
elseif asIsScore > 0 then
ratio = 20
elseif asIsScore < 0 then
ratio = -20
end
local compareItemText = ""
if compareNotCached then
compareItemText = "Item not in cache!|n"
elseif not compareTable then
compareItemText = "No item in set"
else
compareItemText = compareTable.itemLink
end
if ratio ~= rawRatio then
tt:AddDoubleLine("["..percentilize(rawRatio).."/"..percentilize(ratio).."] - "..compareItemText..extraText, setTable.name)
else
tt:AddDoubleLine("["..percentilize(rawRatio).."] - "..compareItemText..extraText, setTable.name)
end
end
end
end
end
end
local function TooltipAddNewLines(tt, link)
if not (TopFit.db.profile.debugMode) then return end
local itemTable = TopFit:GetCachedItem(link)
local lines = TopFit:getComparisonTooltipLines(itemTable)
for _, line in ipairs(lines) do
if (#line == 1) then
tt:AddLine(line[1], 0.5, 0.9, 1)
else
tt:AddDoubleLine(line[1], line[2], 0.5, 0.9, 1)
end
end
end
local function TooltipAddLines(tt, link)
local itemTable = TopFit:GetCachedItem(link)
if not itemTable then return end
if (TopFit.db.profile.debugMode) then
-- item stats
tt:AddLine("Item stats as seen by TopFit:", 0.5, 0.9, 1)
for stat, value in pairs(itemTable["itemBonus"]) do
if not string.find(stat, "SET: ") then
local valueString = ""
local first = true
for _, setTable in pairs(TopFit.db.profile.sets) do
local weightedValue = (setTable.weights[stat] or 0) * value
if first then
first = false
else
valueString = valueString.." / "
end
valueString = valueString..(tonumber(weightedValue) or "0")
end
tt:AddDoubleLine(" +"..(value or 0).." "..(_G[stat] or "Unknown stat"), valueString, 0.5, 0.9, 1)
end
end
-- enchantment stats
if (itemTable["enchantBonus"]) then
tt:AddLine("Enchant:", 1, 0.9, 0.5)
for stat, value in pairs(itemTable["enchantBonus"]) do
local valueString = ""
local first = true
for _, setTable in pairs(TopFit.db.profile.sets) do
local weightedValue = (setTable.weights[stat] or 0) * value
if first then
first = false
else
valueString = valueString.." / "
end
valueString = valueString..(tonumber(weightedValue) or "0")
end
tt:AddDoubleLine(" +"..(value or 0).." "..(_G[stat] or "Unknown stat"), valueString, 1, 0.9, 0.5)
end
end
-- gems
if (itemTable["gemBonus"]) then
local first = true
for stat, value in pairs(itemTable["gemBonus"]) do
if first then
first = false
tt:AddLine("Gems:", 0.8, 0.2, 0)
end
local valueString = ""
local first = true
for _, setTable in pairs(TopFit.db.profile.sets) do
local weightedValue = (setTable.weights[stat] or 0) * value
if first then
first = false
else
valueString = valueString.." / "
end
valueString = valueString..(tonumber(weightedValue) or "0")
end
tt:AddDoubleLine(" +"..(value or 0).." "..(_G[stat] or "Unknown stat"), valueString, 0.8, 0.2, 0)
end
end
-- reforging
if (itemTable["reforgeBonus"]) then
local first = true
for stat, value in pairs(itemTable["reforgeBonus"]) do
if first then
first = false
tt:AddLine("Reforging:", 0.8, 0.8, 0)
end
local valueString = ""
local first = true
for _, setTable in pairs(TopFit.db.profile.sets) do
local weightedValue = (setTable.weights[stat] or 0) * value
if first then
first = false
else
valueString = valueString.." / "
end
valueString = valueString..(tonumber(weightedValue) or "0")
end
tt:AddDoubleLine(" +"..(value or 0).." "..(_G[stat] or "Unknown stat"), valueString, 0.8, 0.8, 0)
end
end
end
if (TopFit.db.profile.showTooltip) then
-- scores for sets
local first = true
for setCode, setTable in pairs(TopFit.db.profile.sets) do
if not TopFit.db.profile.sets[setCode].excludeFromTooltip then
if first then
first = false
tt:AddLine("Set Values:", 0.6, 1, 0.7)
end
tt:AddLine(" "..round(TopFit:GetItemScore(itemTable.itemLink, setCode), 2).." - "..setTable.name, 0.6, 1, 0.7)
end
end
end
TooltipAddNewLines(tt, link)
end
local function OnTooltipCleared(self)
cleared = true
end
local function OnTooltipSetItem(self)
if cleared then
local name, link = self:GetItem()
if (name) then
local equippable = IsEquippableItem(link)
if (not equippable) then
-- Do nothing
else
TooltipAddLines(self, link)
if (TopFit.db.profile.showComparisonTooltip and not TopFit.isBlocked) then
TooltipAddCompareLines(self, link)
end
TooltipAddNewLines(self, link)
end
cleared = false
end
end
end
local function OnRefTooltipCleared(self)
refCleared = true
end
local function OnRefTooltipSetItem(self)
if refCleared then
local name, link = self:GetItem()
if (name) then
local equippable = IsEquippableItem(link)
if (not equippable) then
-- Do nothing
else
TooltipAddLines(self, link)
if (TopFit.db.profile.showComparisonTooltip and not TopFit.isBlocked) then
TooltipAddCompareLines(self, link)
end
end
refCleared = false
end
end
end
local function OnShoppingTooltip1Cleared(self)
s1Cleared = true
end
local function OnShoppingTooltip1SetItem(self)
if s1Cleared then
local name, link = self:GetItem()
if (name) then
local equippable = IsEquippableItem(link)
if (not equippable) then
-- Do nothing
else
TooltipAddLines(self, link)
end
s1Cleared = false
end
end
end
local function OnShoppingTooltip2Cleared(self)
s2Cleared = true
end
local function OnShoppingTooltip2SetItem(self)
if s2Cleared then
local name, link = self:GetItem()
if (name) then
local equippable = IsEquippableItem(link)
if (not equippable) then
-- Do nothing
else
TooltipAddLines(self, link)
end
s2Cleared = false
end
end
end
GameTooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
GameTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
ItemRefTooltip:HookScript("OnTooltipCleared", OnRefTooltipCleared)
ItemRefTooltip:HookScript("OnTooltipSetItem", OnRefTooltipSetItem)
ShoppingTooltip1:HookScript("OnTooltipCleared", OnShoppingTooltip1Cleared)
ShoppingTooltip1:HookScript("OnTooltipSetItem", OnShoppingTooltip1SetItem)
ShoppingTooltip2:HookScript("OnTooltipCleared", OnShoppingTooltip2Cleared)
ShoppingTooltip2:HookScript("OnTooltipSetItem", OnShoppingTooltip2SetItem)