-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfoDisplay.lua
More file actions
2064 lines (1853 loc) · 85.4 KB
/
Copy pathInfoDisplay.lua
File metadata and controls
2064 lines (1853 loc) · 85.4 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
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
setfenv(1, _G.SlackHacks)
--[[
InfoDisplay - Character Sheet Equipment Information Overlay.
Displays centered item levels and upgrade tracks on equipment icons, with a side-anchored
summary of total secondary/tertiary stats, missing enchant/gem alerts, and a hover breakdown tooltip.
]]--
local module = Self:NewModule("InfoDisplay", "AceEvent-3.0")
Self.InfoDisplay = module
local DEFAULT_FONT = "Fonts\\FRIZQT__.TTF"
local STATS_FONT = "Fonts\\ARIALN.TTF"
local FONT_SIZE_LEVEL = 17
local FONT_SIZE_WATERMARK = 11
local FONT_SIZE_TRACK = 12
local FONT_SIZE_STATS = 9
local FONT_OUTLINE = "OUTLINE"
local STAR_ICON = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_1:11:11:0:-1|t"
local function getStatsFont()
if NumberFontNormalSmall then
local font = NumberFontNormalSmall:GetFont()
if font then return font end
end
return STATS_FONT
end
local function isSecret(value)
return _G.issecretvalue and _G.issecretvalue(value) or false
end
local function isCleanNumber(value)
return not isSecret(value) and type(value) == "number"
end
local COLOR_WHITE = { r = 1, g = 1, b = 1, a = 1 }
local COLOR_GREY = { r = 0.7, g = 0.7, b = 0.7, a = 1 }
local COLOR_TINT = { r = 0, g = 0, b = 0, a = 0.66 }
local OVERLAY_NAME_SUFFIX = "SHInfoDisplayOverlay"
-- Supported equipment slots
local SLOTS = {
[1] = { id = 1, side = "LEFT", name = "Head", canEnchant = true },
[2] = { id = 2, side = "LEFT", name = "Neck", canEnchant = false },
[3] = { id = 3, side = "LEFT", name = "Shoulder", canEnchant = true },
[5] = { id = 5, side = "LEFT", name = "Chest", canEnchant = true },
[6] = { id = 6, side = "RIGHT", name = "Waist", canEnchant = false },
[7] = { id = 7, side = "RIGHT", name = "Legs", canEnchant = true },
[8] = { id = 8, side = "RIGHT", name = "Feet", canEnchant = true },
[9] = { id = 9, side = "LEFT", name = "Wrist", canEnchant = false },
[10] = { id = 10, side = "RIGHT", name = "Hands", canEnchant = false },
[11] = { id = 11, side = "RIGHT", name = "Finger0", canEnchant = true },
[12] = { id = 12, side = "RIGHT", name = "Finger1", canEnchant = true },
[13] = { id = 13, side = "RIGHT", name = "Trinket0", canEnchant = false },
[14] = { id = 14, side = "RIGHT", name = "Trinket1", canEnchant = false },
[15] = { id = 15, side = "LEFT", name = "Back", canEnchant = false },
[16] = { id = 16, side = "RIGHT", name = "MainHand", canEnchant = true },
[17] = { id = 17, side = "LEFT", name = "SecondaryHand", canEnchant = true },
}
-- Combat rating identifiers
local CR_CRIT = CR_CRIT_MELEE or 9
local CR_HASTE = CR_HASTE_MELEE or 18
local CR_MASTERY = CR_MASTERY or 26
local CR_VERS = CR_VERSATILITY_DAMAGE_DONE or 29
local CR_SPEED = CR_SPEED or 14
local CR_LEECH = CR_LIFESTEAL or 17
local CR_AVOID = CR_AVOIDANCE or 21
local SECONDARY_STATS = {
{ type = "CRIT", cr = CR_CRIT, name = "Critical Strike", suffix = "Crit", order = 1 },
{ type = "HASTE", cr = CR_HASTE, name = "Haste", suffix = "Haste", order = 2 },
{ type = "MASTERY", cr = CR_MASTERY, name = "Mastery", suffix = "Mastery", order = 3 },
{ type = "VERSATILITY", cr = CR_VERS, name = "Versatility", suffix = "Vers", order = 4 },
}
local TERTIARY_STATS = {
{ type = "SPEED", cr = CR_SPEED, name = "Speed", suffix = "Speed", order = 1 },
{ type = "LEECH", cr = CR_LEECH, name = "Leech", suffix = "Leech", order = 2 },
{ type = "AVOIDANCE", cr = CR_AVOID, name = "Avoidance", suffix = "Avoid", order = 3 },
}
-- Map item stat tokens from C_Item.GetItemStats to our internal identifiers
local SECONDARY_STAT_KEYS = {
["ITEM_MOD_CRIT_RATING_SHORT"] = { type = "CRIT", cr = CR_CRIT, name = "Critical Strike", suffix = "Crit", order = 1 },
["ITEM_MOD_CRIT_RATING"] = { type = "CRIT", cr = CR_CRIT, name = "Critical Strike", suffix = "Crit", order = 1 },
["ITEM_MOD_CRIT_MELEE_RATING_SHORT"] = { type = "CRIT", cr = CR_CRIT, name = "Critical Strike", suffix = "Crit", order = 1 },
["ITEM_MOD_CRIT_RANGED_RATING_SHORT"] = { type = "CRIT", cr = CR_CRIT, name = "Critical Strike", suffix = "Crit", order = 1 },
["ITEM_MOD_CRIT_SPELL_RATING_SHORT"] = { type = "CRIT", cr = CR_CRIT, name = "Critical Strike", suffix = "Crit", order = 1 },
["ITEM_MOD_HASTE_RATING_SHORT"] = { type = "HASTE", cr = CR_HASTE, name = "Haste", suffix = "Haste", order = 2 },
["ITEM_MOD_HASTE_RATING"] = { type = "HASTE", cr = CR_HASTE, name = "Haste", suffix = "Haste", order = 2 },
["ITEM_MOD_HASTE_MELEE_RATING_SHORT"] = { type = "HASTE", cr = CR_HASTE, name = "Haste", suffix = "Haste", order = 2 },
["ITEM_MOD_HASTE_RANGED_RATING_SHORT"]= { type = "HASTE", cr = CR_HASTE, name = "Haste", suffix = "Haste", order = 2 },
["ITEM_MOD_HASTE_SPELL_RATING_SHORT"] = { type = "HASTE", cr = CR_HASTE, name = "Haste", suffix = "Haste", order = 2 },
["ITEM_MOD_MASTERY_RATING_SHORT"] = { type = "MASTERY", cr = CR_MASTERY, name = "Mastery", suffix = "Mastery", order = 3 },
["ITEM_MOD_MASTERY_RATING"] = { type = "MASTERY", cr = CR_MASTERY, name = "Mastery", suffix = "Mastery", order = 3 },
["ITEM_MOD_VERSATILITY"] = { type = "VERSATILITY", cr = CR_VERS, name = "Versatility", suffix = "Vers", order = 4 },
["ITEM_MOD_VERSATILITY_RATING_SHORT"] = { type = "VERSATILITY", cr = CR_VERS, name = "Versatility", suffix = "Vers", order = 4 },
}
local TERTIARY_STAT_KEYS = {
["ITEM_MOD_CR_SPEED_SHORT"] = { type = "SPEED", cr = CR_SPEED, name = "Speed", suffix = "Speed", order = 1 },
["ITEM_MOD_CR_SPEED"] = { type = "SPEED", cr = CR_SPEED, name = "Speed", suffix = "Speed", order = 1 },
["ITEM_MOD_CR_LIFESTEAL_SHORT"] = { type = "LEECH", cr = CR_LEECH, name = "Leech", suffix = "Leech", order = 2 },
["ITEM_MOD_CR_LIFESTEAL"] = { type = "LEECH", cr = CR_LEECH, name = "Leech", suffix = "Leech", order = 2 },
["ITEM_MOD_CR_AVOIDANCE_SHORT"] = { type = "AVOIDANCE", cr = CR_AVOID, name = "Avoidance", suffix = "Avoid", order = 3 },
["ITEM_MOD_CR_AVOIDANCE"] = { type = "AVOIDANCE", cr = CR_AVOID, name = "Avoidance", suffix = "Avoid", order = 3 },
}
-- Classic / Forever item stat definitions (Strength, Agility, Stamina, Intellect, Spirit, etc.)
local FOREVER_STAT_DEFS = {
["ITEM_MOD_STRENGTH_SHORT"] = { name = "Strength", suffix = "Str", order = 1 },
["ITEM_MOD_AGILITY_SHORT"] = { name = "Agility", suffix = "Agi", order = 2 },
["ITEM_MOD_STAMINA_SHORT"] = { name = "Stamina", suffix = "Stam", order = 3 },
["ITEM_MOD_INTELLECT_SHORT"] = { name = "Intellect", suffix = "Int", order = 4 },
["ITEM_MOD_SPIRIT_SHORT"] = { name = "Spirit", suffix = "Spi", order = 5 },
["ITEM_MOD_SPELL_POWER_SHORT"] = { name = "Spell Power", suffix = "SP", order = 6 },
["ITEM_MOD_SPELL_DAMAGE_DONE_SHORT"] = { name = "Spell Damage", suffix = "Spell Dmg", order = 7 },
["ITEM_MOD_SPELL_HEALING_DONE_SHORT"] = { name = "Healing", suffix = "Healing", order = 8 },
["ITEM_MOD_ATTACK_POWER_SHORT"] = { name = "Attack Power", suffix = "AP", order = 9 },
["ITEM_MOD_RANGED_ATTACK_POWER_SHORT"] = { name = "Ranged AP", suffix = "RAP", order = 10 },
["ITEM_MOD_MANA_REGENERATION_SHORT"] = { name = "Mana per 5 sec", suffix = "MP5", order = 11 },
["ITEM_MOD_HEALTH_REGEN_SHORT"] = { name = "Health per 5 sec", suffix = "HP5", order = 12 },
["ITEM_MOD_HIT_MELEE_RATING_SHORT"] = { name = "Hit", suffix = "Hit", order = 13 },
["ITEM_MOD_HIT_RATING_SHORT"] = { name = "Hit", suffix = "Hit", order = 13 },
["ITEM_MOD_HIT_SPELL_RATING_SHORT"] = { name = "Spell Hit", suffix = "Spell Hit", order = 14 },
["ITEM_MOD_CRIT_MELEE_RATING_SHORT"] = { name = "Crit", suffix = "Crit", order = 15 },
["ITEM_MOD_CRIT_RATING_SHORT"] = { name = "Crit", suffix = "Crit", order = 15 },
["ITEM_MOD_CRIT_SPELL_RATING_SHORT"] = { name = "Spell Crit", suffix = "Spell Crit", order = 16 },
["ITEM_MOD_DEFENSE_SKILL_RATING_SHORT"] = { name = "Defense", suffix = "Def", order = 17 },
["ITEM_MOD_DODGE_RATING_SHORT"] = { name = "Dodge", suffix = "Dodge", order = 18 },
["ITEM_MOD_PARRY_RATING_SHORT"] = { name = "Parry", suffix = "Parry", order = 19 },
["ITEM_MOD_BLOCK_RATING_SHORT"] = { name = "Block", suffix = "Block", order = 20 },
["ITEM_MOD_BLOCK_VALUE_SHORT"] = { name = "Block Value", suffix = "Block Val", order = 21 },
["ITEM_MOD_ARMOR_SHORT"] = { name = "Armor", suffix = "Armor", order = 22 },
["ITEM_MOD_EXTRA_ARMOR_SHORT"] = { name = "Bonus Armor", suffix = "Armor", order = 22 },
["ITEM_MOD_FIRE_RESISTANCE_SHORT"] = { name = "Fire Resistance", suffix = "Fire Res", order = 23 },
["ITEM_MOD_NATURE_RESISTANCE_SHORT"] = { name = "Nature Resistance", suffix = "Nature Res", order = 24 },
["ITEM_MOD_FROST_RESISTANCE_SHORT"] = { name = "Frost Resistance", suffix = "Frost Res", order = 25 },
["ITEM_MOD_SHADOW_RESISTANCE_SHORT"] = { name = "Shadow Resistance", suffix = "Shadow Res", order = 26 },
["ITEM_MOD_ARCANE_RESISTANCE_SHORT"] = { name = "Arcane Resistance", suffix = "Arcane Res", order = 27 },
}
-- Known upgrade track name abbreviations
local TRACK_ABBREVIATIONS = {
["EXPLORER"] = "E",
["ADVENTURER"] = "A",
["VETERAN"] = "V",
["CHAMPION"] = "C",
["HERO"] = "H",
["MYTH"] = "M",
["MYTHIC"] = "M",
["AWAKENED"] = "Aw",
}
-- Ensure ColorMixin is directly accessible on Self if Blizzard C code rawgets from the caller's fenv
if _G.ColorMixin and not Self.ColorMixin then
Self.ColorMixin = _G.ColorMixin
end
-- Call C_TooltipInfo from a function explicitly running in _G to ensure mixin resolution succeeds in the C engine
local getInventoryTooltipData = setfenv(function(unitId, slotId)
if _G.C_TooltipInfo and _G.C_TooltipInfo.GetInventoryItem then
return _G.C_TooltipInfo.GetInventoryItem(unitId, slotId)
end
end, _G)
local function safeGetInventoryTooltipData(unitId, slotId)
local ok, data = pcall(getInventoryTooltipData, unitId, slotId)
if ok and data then
return data
end
return nil
end
local getHyperlinkTooltipData = setfenv(function(link)
if _G.C_TooltipInfo and _G.C_TooltipInfo.GetHyperlink then
return _G.C_TooltipInfo.GetHyperlink(link)
end
end, _G)
local function safeGetHyperlinkTooltipData(link)
local ok, data = pcall(getHyperlinkTooltipData, link)
if ok and data then
return data
end
return nil
end
local scanTooltip = CreateFrame("GameTooltip", "SlackHacksInfoDisplayScanTooltip", nil, "GameTooltipTemplate")
scanTooltip:SetOwner(UIParent, "ANCHOR_NONE")
local function scanInventoryItemLines(unitId, slotId)
local lines = {}
local ok = pcall(function()
scanTooltip:ClearLines()
scanTooltip:SetInventoryItem(unitId, slotId)
for i = 1, scanTooltip:NumLines() do
local fs = _G["SlackHacksInfoDisplayScanTooltipTextLeft" .. i]
if fs then
local text = fs:GetText()
if text and text ~= "" then
table.insert(lines, text)
end
end
end
end)
if not ok then return {} end
return lines
end
-- Cache created overlay frames so we can hide/show them on module toggle
local createdOverlays = {}
--- Returns whether the InfoDisplay module is enabled in profile settings.
---@return boolean
local function isModuleEnabled()
return (db and db.profile and db.profile.infoDisplay and db.profile.infoDisplay.enabled) and module:IsEnabled()
end
--- Returns the active profile charSheet settings.
---@return table
local function charSheetSettings()
if db and db.profile and db.profile.infoDisplay and db.profile.infoDisplay.charSheet then
return db.profile.infoDisplay.charSheet
end
return {
itemLevel = true,
upgradeTrack = true,
maxUpgradeStar = false,
slotWatermark = true,
secondaryStats = true,
tertiaryStats = false,
itemStats = true,
highWatermarkColoring = true,
enchants = true,
gemSockets = true,
}
end
--- Get quality color table by quality index.
---@param quality number
---@return table
local function getQualityColor(quality)
if ITEM_QUALITY_COLORS and ITEM_QUALITY_COLORS[quality] then
local c = ITEM_QUALITY_COLORS[quality]
return { r = c.r, g = c.g, b = c.b, a = 1 }
end
if quality == 1 then return COLOR_WHITE
elseif quality == 2 then return { r = 0.12, g = 1, b = 0, a = 1 }
elseif quality == 3 then return { r = 0, g = 0.44, b = 0.87, a = 1 }
elseif quality == 4 then return { r = 0.64, g = 0.21, b = 0.93, a = 1 }
elseif quality == 5 then return { r = 1, g = 0.50, b = 0, a = 1 }
elseif quality == 6 then return { r = 0.90, g = 0.80, b = 0.50, a = 1 }
end
return COLOR_WHITE
end
--- Returns item level display color:
--- - In Retail (isRetail): Uses high watermark brackets (White <266, Green 266-276, Blue 279-289, Purple 292-302, Orange 305-315, Golden 318+)
--- - In Forever (isForever / Classic): Uses the item's native quality color (Common, Uncommon, Rare, Epic, Legendary).
---@param itemLevel number|nil
---@param itemQuality number|nil
---@return table
local function getWatermarkColor(itemLevel, itemQuality)
if isRetail() then
if not isCleanNumber(itemLevel) or itemLevel < 266 then
return getQualityColor(1) -- White (Common)
elseif itemLevel < 279 then
return getQualityColor(2) -- Green (Uncommon)
elseif itemLevel < 292 then
return getQualityColor(3) -- Blue (Rare)
elseif itemLevel < 305 then
return getQualityColor(4) -- Purple (Epic)
elseif itemLevel < 318 then
return getQualityColor(5) -- Orange (Legendary)
else
return getQualityColor(6) -- Golden (Artifact)
end
else
return getQualityColor(isCleanNumber(itemQuality) and itemQuality or 1)
end
end
local SLOT_TO_INVTYPE = {
[1] = "INVTYPE_HEAD",
[2] = "INVTYPE_NECK",
[3] = "INVTYPE_SHOULDER",
[5] = "INVTYPE_CHEST",
[6] = "INVTYPE_WAIST",
[7] = "INVTYPE_LEGS",
[8] = "INVTYPE_FEET",
[9] = "INVTYPE_WRIST",
[10] = "INVTYPE_HAND",
[11] = "INVTYPE_FINGER",
[12] = "INVTYPE_FINGER",
[13] = "INVTYPE_TRINKET",
[14] = "INVTYPE_TRINKET",
[15] = "INVTYPE_CLOAK",
[16] = "INVTYPE_WEAPON",
[17] = "INVTYPE_SHIELD",
}
--- Retrieves the high watermark item level for an equipment slot in Retail.
--- Queries C_ItemUpgrade APIs, falling back to equipped item level if higher.
---@param unitId string "player" | "target"
---@param slotId number Equipment slot ID
---@param itemLink string|nil Equipped item link
---@param equippedItemLevel number|nil Equipped item level
---@return number|nil watermarkIlevel
local function getSlotHighWatermark(unitId, slotId, itemLink, equippedItemLevel)
if not isRetail() or unitId ~= "player" then return nil end
local watermark = nil
if C_ItemUpgrade then
-- Method 1: C_ItemUpgrade.GetHighWatermarkForItem(itemLink)
if itemLink and C_ItemUpgrade.GetHighWatermarkForItem then
local ok, val = pcall(C_ItemUpgrade.GetHighWatermarkForItem, itemLink)
if ok and isCleanNumber(val) and val > 0 then
watermark = val
end
end
-- Method 2: C_ItemUpgrade.GetItemHyperlinkHighWatermark(itemLink)
if not watermark and itemLink and C_ItemUpgrade.GetItemHyperlinkHighWatermark then
local ok, val = pcall(C_ItemUpgrade.GetItemHyperlinkHighWatermark, itemLink)
if ok and isCleanNumber(val) and val > 0 then
watermark = val
end
end
-- Method 3: C_ItemUpgrade.GetHighWatermarkForSlot(slot)
if not watermark and C_ItemUpgrade.GetHighWatermarkForSlot then
local ok, val = pcall(C_ItemUpgrade.GetHighWatermarkForSlot, slotId)
if ok and isCleanNumber(val) and val > 0 then
watermark = val
end
if not watermark and C_ItemUpgrade.GetHighWatermarkSlotForInventoryType then
local invType = nil
if itemLink and C_Item and C_Item.GetItemInfo then
invType = select(9, C_Item.GetItemInfo(itemLink))
end
if not invType and GetItemInfo and itemLink then
invType = select(9, GetItemInfo(itemLink))
end
if not invType then
invType = SLOT_TO_INVTYPE[slotId]
end
if invType then
local okSlot, hwSlot = pcall(C_ItemUpgrade.GetHighWatermarkSlotForInventoryType, invType)
if okSlot and hwSlot then
local okVal, val2 = pcall(C_ItemUpgrade.GetHighWatermarkForSlot, hwSlot)
if okVal and isCleanNumber(val2) and val2 > 0 then
watermark = val2
end
end
end
end
end
end
-- A slot's watermark can never be lower than the currently equipped item level
if isCleanNumber(equippedItemLevel) and equippedItemLevel > 0 then
if not isCleanNumber(watermark) or equippedItemLevel > watermark then
watermark = equippedItemLevel
end
end
return watermark
end
--- Derives a short track abbreviation (e.g. "Champion" -> "C").
--- Returns nil if the name is not a recognized upgrade track.
---@param trackName string
---@return string|nil
local function getTrackAbbreviation(trackName)
if not trackName or trackName == "" then return nil end
local upper = trackName:upper()
for name, abbrev in pairs(TRACK_ABBREVIATIONS) do
if upper:find(name, 1, true) then
return abbrev
end
end
return nil
end
--- Helper to group related stat keys or text into canonical internal types.
---@param key string
---@return string|nil
local function getStatGroup(key)
if not key then return nil end
local upper = key:upper()
if upper:find("CRIT") then return "CRIT"
elseif upper:find("HASTE") then return "HASTE"
elseif upper:find("MASTERY") then return "MASTERY"
elseif upper:find("VERSATILITY") or upper:find("VERS") then return "VERSATILITY"
elseif upper:find("SPEED") then return "SPEED"
elseif upper:find("LIFESTEAL") or upper:find("LEECH") then return "LEECH"
elseif upper:find("AVOIDANCE") or upper:find("AVOID") then return "AVOIDANCE"
elseif upper:find("PRIMARY") then return "PRIMARY"
elseif upper:find("STRENGTH") or upper:find("STR") then return "STRENGTH"
elseif upper:find("AGILITY") or upper:find("AGI") then return "AGILITY"
elseif upper:find("INTELLECT") or upper:find("INT") then return "INTELLECT"
elseif upper:find("STAMINA") or upper:find("STAM") then return "STAMINA"
elseif upper:find("SPIRIT") or upper:find("SPI") then return "SPIRIT"
elseif upper:find("ARMOR") then return "ARMOR"
elseif upper:find("DEFENSE") then return "DEFENSE"
elseif upper:find("DODGE") then return "DODGE"
elseif upper:find("PARRY") then return "PARRY"
elseif upper:find("BLOCK VALUE") then return "BLOCK_VALUE"
elseif upper:find("BLOCK") then return "BLOCK"
elseif upper:find("SPELL POWER") or upper:find("SPELL DAMAGE") or upper:find("HEALING") then return "SPELL_POWER"
elseif upper:find("ATTACK POWER") or upper:find("RAP") then return "ATTACK_POWER"
elseif upper:find("MANA PER 5") or upper:find("MP5") then return "MANA_REGEN"
elseif upper:find("HEALTH PER 5") or upper:find("HP5") then return "HEALTH_REGEN"
elseif upper:find("HIT") then return "HIT"
end
return key
end
--- Retrieves the player's primary stat token and localized display name.
---@return string statKey "STRENGTH" | "AGILITY" | "INTELLECT" | "PRIMARY"
---@return string statName "Strength" | "Agility" | "Intellect" | "Primary Stat"
---@return string statSuffix "Str" | "Agi" | "Int" | "Primary"
local function getPlayerPrimaryStat()
if GetSpecialization and GetSpecializationInfo then
local spec = GetSpecialization()
if spec and spec > 0 then
local _, _, _, _, _, primaryStatID = GetSpecializationInfo(spec)
if primaryStatID == 1 then return "STRENGTH", "Strength", "Str"
elseif primaryStatID == 2 then return "AGILITY", "Agility", "Agi"
elseif primaryStatID == 4 then return "INTELLECT", "Intellect", "Int"
end
end
end
if UnitStat then
local str = select(2, UnitStat("player", 1)) or 0
local agi = select(2, UnitStat("player", 2)) or 0
local int = select(2, UnitStat("player", 4)) or 0
if str > agi and str > int then return "STRENGTH", "Strength", "Str"
elseif agi > str and agi > int then return "AGILITY", "Agility", "Agi"
elseif int > str and int > agi then return "INTELLECT", "Intellect", "Int"
end
end
return "PRIMARY", "Primary Stat", "Primary"
end
-- Known enchant definitions for War Within & Midnight when tooltip lines omit explicit numbers
local KNOWN_ENCHANTS = {
-- Ring Enchants
{ pattern = "radiant%s+haste", stats = { HASTE = 315 }, text = "+315 Haste" },
{ pattern = "radiant%s+crit", stats = { CRIT = 315 }, text = "+315 Crit" },
{ pattern = "radiant%s+mastery", stats = { MASTERY = 315 }, text = "+315 Mastery" },
{ pattern = "radiant%s+vers", stats = { VERSATILITY = 315 }, text = "+315 Vers" },
{ pattern = "cursed%s+haste", stats = { HASTE = 375, AVOIDANCE = -150 }, text = "+375 Haste" },
{ pattern = "cursed%s+crit", stats = { CRIT = 375, LEECH = -150 }, text = "+375 Crit" },
{ pattern = "cursed%s+mastery", stats = { MASTERY = 375, SPEED = -150 }, text = "+375 Mastery" },
{ pattern = "cursed%s+vers", stats = { VERSATILITY = 375, SPEED = -150 }, text = "+375 Vers" },
{ pattern = "glimmering%s+haste", stats = { HASTE = 220 }, text = "+220 Haste" },
{ pattern = "glimmering%s+crit", stats = { CRIT = 220 }, text = "+220 Crit" },
{ pattern = "glimmering%s+mastery", stats = { MASTERY = 220 }, text = "+220 Mastery" },
{ pattern = "glimmering%s+vers", stats = { VERSATILITY = 220 }, text = "+220 Vers" },
{ pattern = "silvermoon's%s+alacrity", stats = { HASTE = 315 }, text = "+315 Haste" },
{ pattern = "silvermoon's%s+tenacity", stats = { VERSATILITY = 315 }, text = "+315 Vers" },
{ pattern = "nature's%s+fury", stats = { CRIT = 315 }, text = "+315 Crit" },
{ pattern = "eyes%s+of%s+the%s+eagle", stats = { CRIT = 315 }, text = "+315 Crit" },
{ pattern = "zul'jin's%s+mastery", stats = { MASTERY = 315 }, text = "+315 Mastery" },
-- Chest Enchants
{ pattern = "crystalline%s+radiance", stats = { PRIMARY = 605 }, text = "+605 Primary" },
{ pattern = "mark%s+of%s+the%s+worldsoul", stats = { PRIMARY = 50 }, text = "+50 Primary" },
{ pattern = "mark%s+of%s+the%s+magister", stats = { PRIMARY = 50 }, text = "+50 Primary" },
{ pattern = "council's%s+intellect", stats = { INTELLECT = 450 }, text = "+450 Int" },
{ pattern = "stormrider's%s+agility", stats = { AGILITY = 450 }, text = "+450 Agi" },
-- Boots Enchants
{ pattern = "scout's%s+march", stats = { SPEED = 250 }, text = "+250 Speed" },
{ pattern = "defender's%s+march", stats = { SPEED = 250, STAMINA = 1150 }, text = "+250 Speed" },
{ pattern = "cavalry's%s+march", stats = { SPEED = 250 }, text = "+250 Speed" },
{ pattern = "lynx's%s+dexterity", stats = { SPEED = 250 }, text = "+250 Speed" },
{ pattern = "shaladrassil's%s+roots", stats = { SPEED = 250 }, text = "+250 Speed" },
{ pattern = "farstrider's%s+hunt", stats = { SPEED = 250 }, text = "+250 Speed" },
-- Cloak Enchants
{ pattern = "winged%s+grace", stats = { AVOIDANCE = 125, SPEED = 125 }, text = "+125 Avoid / +125 Speed" },
{ pattern = "leeching%s+fangs", stats = { LEECH = 250 }, text = "+250 Leech" },
{ pattern = "silken%s+avoidance", stats = { AVOIDANCE = 250 }, text = "+250 Avoid" },
{ pattern = "empowered%s+blessing%s+of%s+speed", stats = { SPEED = 250 }, text = "+250 Speed" },
{ pattern = "empowered%s+hex%s+of%s+leeching", stats = { LEECH = 250 }, text = "+250 Leech" },
{ pattern = "empowered%s+rune%s+of%s+avoidance", stats = { AVOIDANCE = 250 }, text = "+250 Avoid" },
-- Wrist Enchants
{ pattern = "armored%s+avoidance", stats = { AVOIDANCE = 200, ARMOR = 250 }, text = "+200 Avoid" },
{ pattern = "armored%s+speed", stats = { SPEED = 200, ARMOR = 250 }, text = "+200 Speed" },
{ pattern = "armored%s+leech", stats = { LEECH = 200, ARMOR = 250 }, text = "+200 Leech" },
-- Leg Enhancements (Spellthreads & Armor Kits)
{ pattern = "sunfire%s+silk%s+spellthread", stats = { INTELLECT = 450, STAMINA = 1150 }, text = "+450 Int / +1150 Stam" },
{ pattern = "sunset%s+spellthread", stats = { INTELLECT = 450, STAMINA = 1150 }, text = "+450 Int / +1150 Stam" },
{ pattern = "daybreak%s+spellthread", stats = { INTELLECT = 450, STAMINA = 1150 }, text = "+450 Int / +1150 Stam" },
{ pattern = "arcanoweave%s+spellthread", stats = { INTELLECT = 325, STAMINA = 850 }, text = "+325 Int / +850 Stam" },
{ pattern = "dual%s+flocked%s+spellthread", stats = { INTELLECT = 325, STAMINA = 850 }, text = "+325 Int / +850 Stam" },
{ pattern = "forest%s+hunter's%s+armor%s+kit", stats = { PRIMARY = 450, STAMINA = 1150 }, text = "+450 Primary / +1150 Stam" },
{ pattern = "blood%s+knight's%s+armor%s+kit", stats = { PRIMARY = 450, STAMINA = 1150 }, text = "+450 Primary / +1150 Stam" },
{ pattern = "stormbound%s+armor%s+kit", stats = { PRIMARY = 450, STAMINA = 1150 }, text = "+450 Primary / +1150 Stam" },
-- Shoulder Enchants
{ pattern = "akil'zon's%s+swiftness", stats = { SPEED = 250 }, text = "+250 Speed" },
{ pattern = "amirdrassil's%s+grace", stats = { AVOIDANCE = 250 }, text = "+250 Avoid" },
{ pattern = "silvermoon's%s+mending", stats = { LEECH = 250 }, text = "+250 Leech" },
{ pattern = "flight%s+of%s+the%s+eagle", stats = { AVOIDANCE = 250 }, text = "+250 Avoid" },
}
--- Parses numeric stat grants from arbitrary text strings (such as enchant or gem lines).
--- Accurately handles multi-stat lines (e.g. "+147 Critical Strike and +98 Haste", "+70 Speed and +35 Leech").
---@param rawText string
---@return table stats Table mapping canonical stat group to integer value
local function parseStatsFromText(rawText)
local stats = {}
if not rawText or rawText == "" then return stats end
-- Strip formatting codes, textures, and hyperlinks
local clean = rawText:gsub("|c%x%x%x%x%x%x%x%x", ""):gsub("|r", "")
clean = clean:gsub("|A:[^|]+|a", ""):gsub("|T[^|]+|t", "")
clean = clean:gsub("|H.-|h(.-)|h", "%1")
clean = clean:gsub("(%d+),(%d+)", "%1%2"):gsub("(%d+),(%d+)", "%1%2")
-- Normalize non-breaking spaces, conjunctions, and delimiters to commas
clean = clean:gsub("\194\160", " "):gsub("\160", " ")
clean = clean:gsub("%s+and%s+", ", ")
clean = clean:gsub("%s*&%s*", ", ")
clean = clean:gsub("%s*[/\\|]%s*", ", ")
clean = clean:gsub("([%a%)%.])%s*([%+%-]%s*%d+)", "%1, %2")
local function addParsedStat(sign, numStr, statStr)
if not numStr or not statStr then return end
statStr = statStr:gsub("^%s+", ""):gsub("%s+$", ""):gsub("%s+and%s*$", ""):gsub("%s+or%s*$", "")
if statStr:match("^%%") or statStr:match("^percent") then return end
local num = tonumber(numStr)
if sign == "-" then num = -num end
if num and num ~= 0 then
local upperStat = statStr:upper()
if upperStat:find("ALL STATS") or upperStat:find("TO ALL STATS") then
stats["STRENGTH"] = (stats["STRENGTH"] or 0) + num
stats["AGILITY"] = (stats["AGILITY"] or 0) + num
stats["INTELLECT"] = (stats["INTELLECT"] or 0) + num
stats["STAMINA"] = (stats["STAMINA"] or 0) + num
elseif upperStat:find("PRIMARY") then
stats["PRIMARY"] = (stats["PRIMARY"] or 0) + num
else
local group = getStatGroup(statStr)
if group then
stats[group] = (stats[group] or 0) + num
end
end
end
end
for chunk in clean:gmatch("[^,;\n]+") do
chunk = chunk:gsub("^%s+", ""):gsub("%s+$", "")
if chunk ~= "" and not chunk:match("%d+%%") then
local sign, numStr, statStr = chunk:match("^([%+%-]?)(%d+)%s+(.-)$")
if not numStr then
statStr, sign, numStr = chunk:match("^(.-)%s+by%s+([%+%-]?)(%d+)")
end
if not numStr then
statStr, sign, numStr = chunk:match("^(.-)%s+([%+%-]?)(%d+)%s*$")
end
if numStr and statStr then
addParsedStat(sign, numStr, statStr)
end
end
end
-- Fallback scan to capture any remaining (number, stat) pairs
if not next(stats) then
for sign, numStr, statStr in clean:gmatch("([%+%-]?)(%d+)%s+([%a%s]+)") do
addParsedStat(sign, numStr, statStr)
end
end
return stats
end
-- ============================================================================
-- Diminishing Returns and Stat Percentage Calculations
-- ============================================================================
--- Calculates effective secondary stat percentage after diminishing returns penalties.
--- Tiers for rating-derived percentage:
--- 0% - 30%: 0% penalty (100% effectiveness)
--- 30% - 39%: 10% penalty (90% effectiveness)
--- 39% - 47%: 20% penalty (80% effectiveness)
--- 47% - 54%: 30% penalty (70% effectiveness)
--- 54% - 66%: 40% penalty (60% effectiveness)
--- 66% - 126%: 50% penalty (50% effectiveness)
--- > 126%: 100% penalty (0% effectiveness)
---@param B number Un-diminished percentage from rating
---@return number D Diminished effective percentage
local function calculateSecondaryDiminishedPercent(B)
if not isCleanNumber(B) or B <= 0 then return 0 end
if B <= 30 then
return B
elseif B <= 39 then
return 30 + (B - 30) * 0.9
elseif B <= 47 then
return 38.1 + (B - 39) * 0.8
elseif B <= 54 then
return 44.5 + (B - 47) * 0.7
elseif B <= 66 then
return 49.4 + (B - 54) * 0.6
elseif B <= 126 then
return 56.6 + (B - 66) * 0.5
else
return 86.6
end
end
--- Inverts the secondary stat diminishing returns piecewise linear function to recover
--- the un-diminished rating percentage B from effective bonus D.
---@param D number Diminished effective percentage
---@return number B Un-diminished percentage
local function undiminishSecondaryPercent(D)
if not isCleanNumber(D) or D <= 0 then return 0 end
if D <= 30 then
return D
elseif D <= 38.1 then
return 30 + (D - 30) / 0.9
elseif D <= 44.5 then
return 39 + (D - 38.1) / 0.8
elseif D <= 49.4 then
return 47 + (D - 44.5) / 0.7
elseif D <= 56.6 then
return 54 + (D - 49.4) / 0.6
elseif D <= 86.6 then
return 66 + (D - 56.6) / 0.5
else
return 126
end
end
--- Computes the base rating required per 1% un-diminished stat at the player's level.
---@param crId number Combat rating ID
---@return number ratingPerPercent
local function getRatingPerPercent(crId)
local currentRating = GetCombatRating and GetCombatRating(crId)
local currentBonus = GetCombatRatingBonus and GetCombatRatingBonus(crId)
if isCleanNumber(currentRating) and isCleanNumber(currentBonus) and currentRating > 0 and currentBonus > 0 then
local unDiminishedBonus = undiminishSecondaryPercent(currentBonus)
if isCleanNumber(unDiminishedBonus) and unDiminishedBonus > 0 then
return currentRating / unDiminishedBonus
end
end
-- Fallback level scaling (scaled to level 80 baseline)
local rawLevel = UnitLevel and UnitLevel("player")
local playerLevel = (isCleanNumber(rawLevel) and rawLevel > 0) and rawLevel or 80
local levelScale = playerLevel / 80
if crId == CR_CRIT then return 700 * levelScale
elseif crId == CR_HASTE then return 660 * levelScale
elseif crId == CR_MASTERY then return 700 * levelScale
elseif crId == CR_VERS then return 780 * levelScale
elseif crId == CR_SPEED then return 500 * levelScale
elseif crId == CR_LEECH then return 450 * levelScale
elseif crId == CR_AVOID then return 450 * levelScale
end
return 700 * levelScale
end
--- Calculates the marginal stat percentage increase provided by this item's rating,
--- accounting for current equipped total rating and diminishing returns.
---@param crId number Combat rating ID
---@param itemStatRating number Rating amount on item
---@return number pctIncrease
local function calculateSecondaryStatIncrease(crId, itemStatRating)
if not itemStatRating or itemStatRating <= 0 then return 0 end
local k = getRatingPerPercent(crId)
if not isCleanNumber(k) or k <= 0 then return 0 end
local currentRating = GetCombatRating and GetCombatRating(crId)
local pctIncrease
if isCleanNumber(currentRating) and currentRating > 0 and currentRating >= itemStatRating then
local ratingWithoutItem = currentRating - itemStatRating
local B_total = currentRating / k
local B_base = ratingWithoutItem / k
local D_total = calculateSecondaryDiminishedPercent(B_total)
local D_base = calculateSecondaryDiminishedPercent(B_base)
pctIncrease = math.max(0, D_total - D_base)
else
local B = itemStatRating / k
pctIncrease = calculateSecondaryDiminishedPercent(B)
end
-- For Mastery, multiply by the active specialization's mastery coefficient
if crId == CR_MASTERY and GetMasteryEffect then
local ok, _, bonusCoeff = pcall(GetMasteryEffect)
if ok and isCleanNumber(bonusCoeff) and bonusCoeff > 0 then
pctIncrease = pctIncrease * bonusCoeff
end
end
return pctIncrease
end
--- Calculates tertiary stat percentage with diminishing returns penalties.
--- Leech: 0-10% no penalty, >10% 50% penalty
--- Avoidance: 0-8% no penalty, >8% 50% penalty
--- Speed: 100% effectiveness
---@param statType string
---@param B number
---@return number D
local function calculateTertiaryDiminishedPercent(statType, B)
if not isCleanNumber(B) or B <= 0 then return 0 end
if statType == "LEECH" then
if B <= 10 then return B else return 10 + (B - 10) * 0.5 end
elseif statType == "AVOIDANCE" then
if B <= 8 then return B else return 8 + (B - 8) * 0.5 end
else
return B
end
end
--- Calculates the marginal percentage increase for a tertiary stat.
---@param statType string "SPEED" | "LEECH" | "AVOIDANCE"
---@param crId number
---@param itemStatRating number
---@return number pctIncrease
local function calculateTertiaryStatIncrease(statType, crId, itemStatRating)
if not itemStatRating or itemStatRating <= 0 then return 0 end
local currentRating = GetCombatRating and GetCombatRating(crId)
local currentBonus = GetCombatRatingBonus and GetCombatRatingBonus(crId)
local k
if isCleanNumber(currentRating) and isCleanNumber(currentBonus) and currentRating > 0 and currentBonus > 0 then
k = currentRating / currentBonus
else
local rawLevel = UnitLevel and UnitLevel("player")
local playerLevel = (isCleanNumber(rawLevel) and rawLevel > 0) and rawLevel or 80
local levelScale = playerLevel / 80
if statType == "SPEED" then k = 500 * levelScale
elseif statType == "LEECH" then k = 450 * levelScale
elseif statType == "AVOIDANCE" then k = 450 * levelScale
else k = 500 * levelScale end
end
if not isCleanNumber(k) or k <= 0 then return 0 end
local pctIncrease
if isCleanNumber(currentRating) and currentRating > 0 and currentRating >= itemStatRating then
local ratingWithoutItem = currentRating - itemStatRating
local B_total = currentRating / k
local B_base = ratingWithoutItem / k
local D_total = calculateTertiaryDiminishedPercent(statType, B_total)
local D_base = calculateTertiaryDiminishedPercent(statType, B_base)
pctIncrease = math.max(0, D_total - D_base)
else
local B = itemStatRating / k
pctIncrease = calculateTertiaryDiminishedPercent(statType, B)
end
return pctIncrease
end
--- Formats an enchantment string to show its stat values (e.g. "+29 Haste", "+50 Primary")
--- or effect name if it's a non-stat proc/effect.
---@param itemLink string Full item link
---@param rawEnchantText string Text extracted from tooltip enchant line
---@param enchantAtlas string|nil Optional quality tier atlas icon
---@param slotId number Equipment slot ID
---@param enchantBuckets table|nil Optional pre-calculated enchant stat buckets
---@return string
local function getEnchantDisplayText(itemLink, rawEnchantText, enchantAtlas, slotId, enchantBuckets)
if not rawEnchantText or rawEnchantText == "" then return "" end
local atlas = enchantAtlas
if not atlas or atlas == "" then
atlas = rawEnchantText:match("|A:([^:]+)")
end
local cleanText = rawEnchantText:gsub("|A:[^|]+|a", ""):gsub("|T[^|]+|t", ""):gsub("|c%x%x%x%x%x%x%x%x", ""):gsub("|r", ""):gsub("^%s+", ""):gsub("%s+$", "")
-- If raw text already has "+123 Stat" format, use it directly
local sign, num, stat = cleanText:match("^([%+%-]?)(%d+)%s+(.+)$")
if num and stat then
local formatted = (sign == "-" and "-" or "+") .. num .. " " .. stat
if atlas and atlas ~= "" then
return "|A:" .. atlas .. ":12:12|a " .. formatted
end
return formatted
end
-- If enchantBuckets has calculated stats, format cleanly from stats
if enchantBuckets and next(enchantBuckets) then
local parts = {}
if enchantBuckets["PRIMARY"] then table.insert(parts, string.format("+%d Primary", enchantBuckets["PRIMARY"])) end
if enchantBuckets["STRENGTH"] then table.insert(parts, string.format("+%d Str", enchantBuckets["STRENGTH"])) end
if enchantBuckets["AGILITY"] then table.insert(parts, string.format("+%d Agi", enchantBuckets["AGILITY"])) end
if enchantBuckets["INTELLECT"] then table.insert(parts, string.format("+%d Int", enchantBuckets["INTELLECT"])) end
if enchantBuckets["CRIT"] then table.insert(parts, string.format("+%d Crit", enchantBuckets["CRIT"])) end
if enchantBuckets["HASTE"] then table.insert(parts, string.format("+%d Haste", enchantBuckets["HASTE"])) end
if enchantBuckets["MASTERY"] then table.insert(parts, string.format("+%d Mastery", enchantBuckets["MASTERY"])) end
if enchantBuckets["VERSATILITY"] then table.insert(parts, string.format("+%d Vers", enchantBuckets["VERSATILITY"])) end
if enchantBuckets["SPEED"] then table.insert(parts, string.format("+%d Speed", enchantBuckets["SPEED"])) end
if enchantBuckets["LEECH"] then table.insert(parts, string.format("+%d Leech", enchantBuckets["LEECH"])) end
if enchantBuckets["AVOIDANCE"] then table.insert(parts, string.format("+%d Avoid", enchantBuckets["AVOIDANCE"])) end
if #parts > 0 then
local formatted = table.concat(parts, " / ")
if atlas and atlas ~= "" then
return "|A:" .. atlas .. ":12:12|a " .. formatted
end
return formatted
end
end
local lower = cleanText:lower()
for _, ke in ipairs(KNOWN_ENCHANTS) do
if lower:find(ke.pattern) then
if atlas and atlas ~= "" then
return "|A:" .. atlas .. ":12:12|a " .. ke.text
end
return ke.text
end
end
local cleaned = cleanText:gsub("^Enchant%s+[%a%s]+%s*-%s*", "")
cleaned = cleaned:gsub("^Enchant%s*-%s*", "")
if atlas and atlas ~= "" then
return "|A:" .. atlas .. ":12:12|a " .. cleaned
end
return cleaned
end
--- Returns whether a slot can be enchanted in the current client expansion.
--- In modern retail, bracers (slot 9) and cloak/back (slot 15) do not have enchants.
--- In Forever / Classic, bracers and cloak can be enchanted.
---@param slot table
---@return boolean
local function canSlotEnchant(slot)
if not slot then return false end
if slot.id == 9 or slot.id == 15 then
return not isRetail()
end
return slot.canEnchant == true
end
-- ============================================================================
-- Slot Overlay Creation & UI Management
-- ============================================================================
--- Creates or retrieves the slot overlay frame attached to a character/inspect slot frame.
---@param characterSlotFrame Button
---@param slot table
---@return Frame slotOverlay
local function getOrCreateSlotOverlay(characterSlotFrame, slot)
local frameName = characterSlotFrame:GetName() .. OVERLAY_NAME_SUFFIX
local slotOverlay = characterSlotFrame[OVERLAY_NAME_SUFFIX]
if not slotOverlay then
slotOverlay = CreateFrame("Frame", frameName, characterSlotFrame)
characterSlotFrame[OVERLAY_NAME_SUFFIX] = slotOverlay
table.insert(createdOverlays, slotOverlay)
slotOverlay:SetAllPoints(characterSlotFrame)
slotOverlay:SetFrameLevel(characterSlotFrame:GetFrameLevel() + 5)
-- Subtle dark background tint on icon
local tint = slotOverlay:CreateTexture(nil, "BACKGROUND")
tint:SetTexture("Interface\\TutorialFrame\\TutorialFrameBackground")
tint:SetColorTexture(COLOR_TINT.r, COLOR_TINT.g, COLOR_TINT.b, COLOR_TINT.a)
tint:SetAllPoints(slotOverlay)
slotOverlay.Tint = tint
-- Item Level: center of icon
local level = slotOverlay:CreateFontString(frameName .. "Level", "OVERLAY", "GameTooltipText")
level:SetPoint("CENTER", slotOverlay, "CENTER", 0, 0)
level:SetFont(DEFAULT_FONT, FONT_SIZE_LEVEL, FONT_OUTLINE)
level:SetJustifyH("CENTER")
slotOverlay.Level = level
-- Upgrade Track: anchored underneath centered to item level
local track = slotOverlay:CreateFontString(frameName .. "Track", "OVERLAY", "GameTooltipText")
track:SetPoint("TOP", level, "BOTTOM", 0, -1)
track:SetFont(DEFAULT_FONT, FONT_SIZE_TRACK, FONT_OUTLINE)
track:SetTextColor(COLOR_WHITE.r, COLOR_WHITE.g, COLOR_WHITE.b, COLOR_WHITE.a)
track:SetJustifyH("CENTER")
track:Hide()
slotOverlay.Track = track
-- Side Summary Frame: sits off to the side where enchants and gems display
local isBottomSlot = (slot.id == 16 or slot.id == 17)
local relativePoint = slot.side == "LEFT" and "RIGHT" or "LEFT"
local offsetX = slot.side == "LEFT" and 8 or -8
local sideSummaryPoint, slotPoint
if isBottomSlot then
sideSummaryPoint = slot.side == "LEFT" and "BOTTOMLEFT" or "BOTTOMRIGHT"
slotPoint = slot.side == "LEFT" and "BOTTOMRIGHT" or "BOTTOMLEFT"
else
sideSummaryPoint = slot.side
slotPoint = relativePoint
end
local sideSummary = CreateFrame("Frame", frameName .. "SideSummary", slotOverlay)
sideSummary:SetSize(90, 37)
sideSummary:SetPoint(sideSummaryPoint, slotOverlay, slotPoint, offsetX, 0)
sideSummary:EnableMouse(true)
sideSummary:SetFrameLevel(slotOverlay:GetFrameLevel() + 10)
slotOverlay.SideSummary = sideSummary
-- Watermark item level at the top of side summary
local watermarkText = sideSummary:CreateFontString(frameName .. "Watermark", "OVERLAY", "GameTooltipText")
watermarkText:SetFont(DEFAULT_FONT, FONT_SIZE_WATERMARK, FONT_OUTLINE)
watermarkText:SetTextColor(COLOR_WHITE.r, COLOR_WHITE.g, COLOR_WHITE.b, COLOR_WHITE.a)
watermarkText:SetJustifyH(slot.side == "RIGHT" and "RIGHT" or "LEFT")
sideSummary.WatermarkText = watermarkText
-- Stats summary font string (multi-line)
local statsText = sideSummary:CreateFontString(frameName .. "SideStats", "OVERLAY", "GameTooltipText")
statsText:SetFont(getStatsFont(), FONT_SIZE_STATS, FONT_OUTLINE)
statsText:SetTextColor(COLOR_WHITE.r, COLOR_WHITE.g, COLOR_WHITE.b, COLOR_WHITE.a)
statsText:SetJustifyH(slot.side == "RIGHT" and "RIGHT" or "LEFT")
statsText:SetJustifyV("TOP")
sideSummary.StatsText = statsText
-- Missing Enchant alert icon
local missingEnchant = CreateFrame("Button", frameName .. "MissingEnchant", sideSummary)
missingEnchant:SetSize(14, 14)
missingEnchant:EnableMouse(true)
missingEnchant:SetFrameLevel(sideSummary:GetFrameLevel() + 2)
local meIcon = missingEnchant:CreateTexture(nil, "ARTWORK")
meIcon:SetAllPoints()
meIcon:SetTexture("Interface\\Icons\\inv_misc_enchantedscroll")
meIcon:SetVertexColor(1, 0.25, 0.25)
missingEnchant.Icon = meIcon
sideSummary.MissingEnchant = missingEnchant
-- Missing Gem alert icon
local missingGem = CreateFrame("Button", frameName .. "MissingGem", sideSummary)
missingGem:SetSize(14, 14)
missingGem:EnableMouse(true)
missingGem:SetFrameLevel(sideSummary:GetFrameLevel() + 2)
local mgIcon = missingGem:CreateTexture(nil, "ARTWORK")
mgIcon:SetAllPoints()
mgIcon:SetTexture("Interface\\ItemSocketingFrame\\UI-EmptySocket-Prismatic")
missingGem.Icon = mgIcon
sideSummary.MissingGem = missingGem
-- Hover tooltip on the side summary showing the stat and enhancement breakdown
local function showBreakdownTooltip(anchorFrame)
if not sideSummary.breakdownData then return end
GameTooltip:SetOwner(anchorFrame, slot.side == "LEFT" and "ANCHOR_RIGHT" or "ANCHOR_LEFT")
GameTooltip:ClearLines()
local data = sideSummary.breakdownData
GameTooltip:AddLine(data.itemName or "Equipment Details", 1, 1, 1)
if data.watermarkIlevel and data.watermarkIlevel > 0 then
local wmColor = getWatermarkColor(data.watermarkIlevel, data.itemQuality)
GameTooltip:AddDoubleLine("Slot Watermark:", tostring(data.watermarkIlevel), 1, 0.82, 0, wmColor.r, wmColor.g, wmColor.b)
end
local hasEnchantInStats = false
if data.statsList and #data.statsList > 0 then
for _, stat in ipairs(data.statsList) do
GameTooltip:AddLine(" ")
local rightText
local totalPct = stat.totalPct or stat.pct
if totalPct then
rightText = string.format("%d (%.1f%%)", stat.total, totalPct)
else
rightText = string.format("%d", stat.total)
end
GameTooltip:AddDoubleLine(stat.name .. ":", rightText, 1, 1, 1, 0, 1, 0)
if stat.base and stat.base > 0 then
local basePctText
if stat.basePct then
basePctText = string.format("%d (%.1f%%)", stat.base, stat.basePct)
else
basePctText = string.format("%d", stat.base)
end