-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathaddon.lua
More file actions
1152 lines (1084 loc) · 44.3 KB
/
Copy pathaddon.lua
File metadata and controls
1152 lines (1084 loc) · 44.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
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
local myname, ns = ...
local myfullname = C_AddOns.GetAddOnMetadata(myname, "Title")
local db
local isClassic = WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE
ns.DEBUG = C_AddOns.GetAddOnMetadata(myname, "Version") == "@".."project-version@"
_G.SimpleItemLevel = {}
local SLOT_MAINHAND = GetInventorySlotInfo("MainHandSlot")
local SLOT_OFFHAND = GetInventorySlotInfo("SecondaryHandSlot")
function ns.Print(...) print("|cFF33FF99".. myfullname.. "|r:", ...) end
-- events
local hooks = {}
local f = CreateFrame("Frame")
f:SetScript("OnEvent", function(self, event, ...) if ns[event] then return ns[event](ns, event, ...) end end)
function ns:RegisterEvent(...) for i=1,select("#", ...) do f:RegisterEvent((select(i, ...))) end end
function ns:UnregisterEvent(...) for i=1,select("#", ...) do f:UnregisterEvent((select(i, ...))) end end
function ns:RegisterAddonHook(addon, callback)
if C_AddOns.IsAddOnLoaded(addon) then
xpcall(callback, geterrorhandler())
else
hooks[addon] = callback
end
end
local LAI = LibStub("LibAppropriateItems-1.0")
ns.soulboundAtlas = isClassic and "AzeriteReady" or "Soulbind-32x32" -- UF-SoulShard-Icon-2x
ns.upgradeAtlas = "poi-door-arrow-up" -- MiniMap-PositionArrowUp?
ns.upgradeString = CreateAtlasMarkup(ns.upgradeAtlas)
ns.gemString = CreateAtlasMarkup(isClassic and "worldquest-icon-jewelcrafting" or "jailerstower-score-gem-tooltipicon") -- Professions-ChatIcon-Quality-Tier5-Cap
ns.enchantString = RED_FONT_COLOR:WrapTextInColorCode("E")
ns.Fonts = {
HighlightSmall = GameFontHighlightSmall,
Normal = GameFontNormalOutline,
Large = GameFontNormalLargeOutline,
Huge = GameFontNormalHugeOutline,
NumberNormal = NumberFontNormal,
NumberNormalSmall = NumberFontNormalSmall,
}
ns.PositionOffsets = {
TOPLEFT = {2, -2},
TOPRIGHT = {-2, -2},
BOTTOMLEFT = {2, 2},
BOTTOMRIGHT = {-2, 2},
BOTTOM = {0, 2},
TOP = {0, -2},
LEFT = {2, 0},
RIGHT = {-2, 0},
CENTER = {0, 0},
}
if LE_EXPANSION_LEVEL_CURRENT >= LE_EXPANSION_WRATH_OF_THE_LICH_KING then
-- A lot of space on the character sheet freed up here
local ONRIGHT = {"LEFT", "RIGHT", 8, 0}
local ONLEFT = {"RIGHT", "LEFT", -8, 0}
ns.CharacterButtonInsetPositions = {
CharacterMainHandSlot = {"TOPRIGHT", "TOPLEFT", -8, 0},
InspectMainHandSlot = {"TOPRIGHT", "TOPLEFT", -8, 0},
CharacterSecondaryHandSlot = {"TOPLEFT", "TOPRIGHT", 4, 0},
InspectSecondaryHandSlot = {"TOPLEFT", "TOPRIGHT", 4, 0},
}
for _, slot in ipairs({"Head", "Neck", "Shoulder", "Back", "Chest", "Shirt", "Tabard", "Wrist"}) do
ns.CharacterButtonInsetPositions["Character"..slot.."Slot"] = ONRIGHT
ns.CharacterButtonInsetPositions["Inspect"..slot.."Slot"] = ONRIGHT
end
for _, slot in ipairs({"Hands", "Waist", "Legs", "Feet", "Finger0", "Finger1", "Trinket0", "Trinket1"}) do
ns.CharacterButtonInsetPositions["Character"..slot.."Slot"] = ONLEFT
ns.CharacterButtonInsetPositions["Inspect"..slot.."Slot"] = ONLEFT
end
else
ns.CharacterButtonInsetPositions = {}
end
ns.defaults = {
-- places
character = true,
character_inset = false,
inspect = true,
inspect_inset = false,
bags = true,
loot = true,
flyout = true,
tooltip = isClassic,
characteravg = isClassic,
inspectavg = true,
-- equipmentonly = true,
equipment = true,
battlepets = true,
reagents = false,
misc = false,
-- data points
itemlevel = true,
upgrades = true,
missinggems = true,
missingenchants = true,
missingcharacter = true, -- missing on character-frame only
bound = true,
-- display
color = true,
-- Retail has Uncommon, BCC/Classic has Good
quality = Enum.ItemQuality.Common or Enum.ItemQuality.Standard,
-- appearance config
font = "NumberNormal",
position = "TOPRIGHT",
positionup = "TOPLEFT",
positionmissing = "LEFT",
positionbound = "BOTTOMLEFT",
scaleup = 1,
scalebound = 1,
}
function ns:ADDON_LOADED(event, addon)
if hooks[addon] then
xpcall(hooks[addon], geterrorhandler())
hooks[addon] = nil
end
if addon == myname then
_G[myname.."DB"] = setmetatable(_G[myname.."DB"] or {}, {
__index = ns.defaults,
})
db = _G[myname.."DB"]
ns.db = db
ns:SetupConfig()
-- So our upgrade arrows can work reliably when opening inventories
ns.CacheEquippedItems()
end
end
ns:RegisterEvent("ADDON_LOADED")
local ItemLevelFromTooltip
do
local empty = {lines={}}
local lineType = Enum.TooltipDataLineType.ItemLevel or Enum.TooltipDataLineType.None
local ITEM_LEVEL_PATTERN = ITEM_LEVEL:gsub("%%d", "(%%d+)")
function ItemLevelFromTooltip(info)
for _, line in ipairs((info or empty).lines) do
if line.type == lineType then
if line.itemLevel then
return line.itemLevel
end
local levelMatch = line.leftText:match(ITEM_LEVEL_PATTERN)
if levelMatch then
return tonumber(levelMatch)
end
end
end
end
end
local function ItemFromUnitSlot(unit, slotID)
if unit == "player" then
return Item:CreateFromEquipmentSlot(slotID)
else
local itemLink = GetInventoryItemLink(unit, slotID)
if itemLink then return Item:CreateFromItemLink(itemLink) end
local itemID = GetInventoryItemID(unit, slotID)
if itemID then return Item:CreateFromItemID(itemID) end
end
end
local function ItemIsUpgrade(item, itemLevelOverride)
if not (item and LAI:IsAppropriate(item:GetItemID())) then
return
end
-- Upgrade?
if item:GetItemLocation() and item:GetItemLocation():IsEquipmentSlot() then
-- This is meant to catch the character frame, to avoid rings/trinkets
-- you've already got equipped showing as an upgrade since they're
-- higher ilevel than your other ring/trinket
return
end
local isUpgrade
if itemLevelOverride == true and _G.C_TooltipInfo and item:GetItemLink() then
itemLevelOverride = ItemLevelFromTooltip(C_TooltipInfo.GetHyperlink(item:GetItemLink()))
end
local itemLevel = type(itemLevelOverride) == "number" and itemLevelOverride or item:GetCurrentItemLevel() or 0
local _, _, _, equipLoc, _, itemClass, itemSubClass = C_Item.GetItemInfoInstant(item:GetItemID())
ns.ForEquippedItems(equipLoc, function(equippedItem, slot)
-- This *isn't* async, for flow reasons, so if the equipped items
-- aren't yet cached the item might get incorrectly flagged as an
-- upgrade.
if equippedItem:IsItemEmpty() and slot == SLOT_OFFHAND then
local mainhand = GetInventoryItemID("player", SLOT_MAINHAND)
if mainhand then
local invtype = select(4, C_Item.GetItemInfoInstant(mainhand))
if invtype == "INVTYPE_2HWEAPON" then
return
end
end
end
if not equippedItem:IsItemDataCached() then
-- don't claim an upgrade if we don't know
return
end
-- fallbacks for the item levels; saw complaints of this erroring during initial login for people using Bagnon and AdiBags
local equippedItemLevel = equippedItem:GetCurrentItemLevel() or 0
if equippedItem:IsItemEmpty() or equippedItemLevel < itemLevel then
isUpgrade = true
local minLevel = select(5, C_Item.GetItemInfo(item:GetItemLink() or item:GetItemID()))
if minLevel and minLevel > UnitLevel("player") then
-- not equipable yet
end
end
end)
return isUpgrade
end
ns.ItemIsUpgrade = ItemIsUpgrade
-- TODO: this is a good candidate for caching results...
local function DetailsFromItemInstant(item, itemLevelOverride)
if not item or item:IsItemEmpty() then return {} end
-- print("DetailsFromItem", item:GetItemLink())
if itemLevelOverride == true and _G.C_TooltipInfo and item:GetItemLink() then
itemLevelOverride = ItemLevelFromTooltip(C_TooltipInfo.GetHyperlink(item:GetItemLink()))
end
local itemLevel = type(itemLevelOverride) == "number" and itemLevelOverride or item:GetCurrentItemLevel() or 0
local quality = item:GetItemQuality()
local itemLink = item:GetItemLink()
if itemLink and itemLink:match("battlepet:") then
-- special case for caged battle pets
local _, speciesID, level, breedQuality = ns.GetLinkValues(itemLink)
if speciesID and level and breedQuality then
itemLevel = tonumber(level)
quality = tonumber(breedQuality)
end
end
return {
level = itemLevel,
quality = quality,
link = itemLink,
}
end
ns.DetailsFromItemInstant = DetailsFromItemInstant
local function DetailsFromItem(item, itemLevelOverride)
if not item or item:IsItemEmpty() then return {} end
local details = DetailsFromItemInstant(item, itemLevelOverride)
details.missingGems = ns.ItemHasEmptySlots(details.link)
details.missingEnchants = ns.ItemIsMissingEnchants(details.link)
details.upgrade = ItemIsUpgrade(item)
if C_Item.IsItemBindToAccountUntilEquip and details.link then
-- 11.0.2 adds this, which works on any item:
details.warboundUntilEquip = C_Item.IsItemBindToAccountUntilEquip(details.link)
end
if item:IsItemInPlayersControl() then
local itemLocation = item:GetItemLocation()
-- this only works on items in our control:
details.warboundUntilEquip = C_Item.IsBoundToAccountUntilEquip and C_Item.IsBoundToAccountUntilEquip(itemLocation)
details.bound = C_Item.IsBound(itemLocation)
if details.bound then
-- As of 11.0.0 blizzard has created Enum.ItemBind entries for
-- warbound, but never uses them. Zepto worked out that we can
-- use "can I put it in the warbank?" as a proxy to distinguish,
-- even when we're not at the bank.
-- TODO: occasionally check whether the bindTypes start getting
-- returned via `select (14, C_Item.GetItemInfo(details.link)) == 7/8/9`
details.warbound = C_Bank and C_Bank.IsItemAllowedInBankType and C_Bank.IsItemAllowedInBankType(Enum.BankType.Account, itemLocation)
end
end
return details
end
ns.DetailsFromItem = DetailsFromItem
ns.frames = {} -- TODO: should I make this a FramePool now?
local function PrepareItemButton(button, variant)
if not button.simpleilvl then
local overlayFrame = CreateFrame("FRAME", nil, button)
overlayFrame:SetAllPoints()
overlayFrame:SetFrameLevel(button:GetFrameLevel() + 1)
button.simpleilvloverlay = overlayFrame
button.simpleilvl = overlayFrame:CreateFontString(nil, "OVERLAY")
button.simpleilvl:Hide()
button.simpleilvlup = overlayFrame:CreateTexture(nil, "OVERLAY")
button.simpleilvlup:SetSize(10, 10)
button.simpleilvlup:SetAtlas(ns.upgradeAtlas)
button.simpleilvlup:Hide()
button.simpleilvlmissing = overlayFrame:CreateFontString(nil, "OVERLAY")
button.simpleilvlmissing:Hide()
button.simpleilvlbound = overlayFrame:CreateTexture(nil, "OVERLAY")
button.simpleilvlbound:SetSize(10, 10)
button.simpleilvlbound:SetAtlas(ns.soulboundAtlas) -- Soulbind-32x32
button.simpleilvlbound:Hide()
ns.frames[button] = overlayFrame
end
button.simpleilvloverlay.variant = variant or button.simpleilvloverlay.variant
variant = button.simpleilvloverlay.variant
button.simpleilvloverlay:SetFrameLevel(button:GetFrameLevel() + 1)
-- Apply appearance config:
button.simpleilvl:ClearAllPoints()
local position, positionOffsets = db.position, ns.PositionOffsets[db.position]
if ((variant == "character" and db.character_inset) or (variant == "inspect" and db.inspect_inset)) and ns.CharacterButtonInsetPositions[button:GetName()] then
local point, relativePoint, x, y = unpack(ns.CharacterButtonInsetPositions[button:GetName()])
button.simpleilvl:SetPoint(point, button.simpleilvloverlay, relativePoint, x, y)
else
button.simpleilvl:SetPoint(db.position, unpack(ns.PositionOffsets[db.position]))
end
button.simpleilvl:SetFontObject(ns.Fonts[db.font] or NumberFontNormal)
-- button.simpleilvl:SetJustifyH('RIGHT')
button.simpleilvlup:ClearAllPoints()
button.simpleilvlup:SetPoint(db.positionup, unpack(ns.PositionOffsets[db.positionup]))
button.simpleilvlup:SetScale(db.scaleup)
button.simpleilvlmissing:ClearAllPoints()
button.simpleilvlmissing:SetPoint(db.positionmissing, unpack(ns.PositionOffsets[db.positionmissing]))
button.simpleilvlmissing:SetFont([[Fonts\ARIALN.TTF]], 11, "OUTLINE,MONOCHROME")
button.simpleilvlbound:ClearAllPoints()
button.simpleilvlbound:SetPoint(db.positionbound, unpack(ns.PositionOffsets[db.positionbound]))
button.simpleilvlbound:SetScale(db.scalebound)
end
ns.PrepareItemButton = PrepareItemButton
local blank = {}
local function CleanButton(button, suppress)
suppress = suppress or blank
if button.simpleilvl and not suppress.level then button.simpleilvl:Hide() end
if button.simpleilvlup and not suppress.upgrade then button.simpleilvlup:Hide() end
if button.simpleilvlmissing and not suppress.missing then button.simpleilvlmissing:Hide() end
if button.simpleilvlbound and not suppress.bound then button.simpleilvlbound:Hide() end
end
ns.CleanButton = CleanButton
function ns.RefreshOverlayFrames()
for button in pairs(ns.frames) do
PrepareItemButton(button)
end
end
local function AddLevelToButton(button, details)
if not (db.itemlevel and details.level) then
return button.simpleilvl:Hide()
end
local r, g, b = C_Item.GetItemQualityColor(db.color and details.quality or 1)
button.simpleilvl:SetText(details.level or '?')
button.simpleilvl:SetTextColor(r, g, b)
button.simpleilvl:Show()
end
local function AddUpgradeToButton(button, details)
if not (db.upgrades and details.upgrade) then
return button.simpleilvlup:Hide()
end
local minLevel = select(5, C_Item.GetItemInfo(details.link))
if minLevel and minLevel > UnitLevel("player") then
button.simpleilvlup:SetVertexColor(1, 0, 0)
else
button.simpleilvlup:SetVertexColor(1, 1, 1)
end
button.simpleilvlup:Show()
end
local function AddMissingToButton(button, details)
local missingGems = db.missinggems and details.missingGems
local missingEnchants = db.missingenchants and details.missingEnchants
button.simpleilvlmissing:SetFormattedText("%s%s", missingGems and ns.gemString or "", missingEnchants and ns.enchantString or "")
button.simpleilvlmissing:Show()
end
local function ColorFrameByBinding(frame, details)
-- returns bool, whether is bound in some way
if details.bound then
if details.warbound then
frame:SetVertexColor(0.5, 1, 0) -- green
else
frame:SetVertexColor(1, 1, 1) -- blue
end
return true
elseif details.warboundUntilEquip then
-- once you equip it the label changes to soulbound, but this property remains
frame:SetVertexColor(1, 0.5, 1) -- pale purple
return true
end
return false
end
local function AddBoundToButton(button, details)
if not db.bound then
return button.simpleilvlbound and button.simpleilvlbound:Hide()
end
if ColorFrameByBinding(button.simpleilvlbound, details) then
button.simpleilvlbound:Show()
end
end
local function ShouldShowOnItem(item)
local quality = item:GetItemQuality() or -1
if quality < db.quality then
return false
end
local _, _, _, equipLoc, _, itemClass, itemSubClass = C_Item.GetItemInfoInstant(item:GetItemID())
if (
itemClass == Enum.ItemClass.Weapon or
itemClass == Enum.ItemClass.Armor or
(itemClass == Enum.ItemClass.Gem and itemSubClass == Enum.ItemGemSubclass.Artifactrelic)
) then
return db.equipment
end
if item:GetItemID() == 82800 then
-- Pet Cage
return db.battlepets
end
if select(17, C_Item.GetItemInfo(item:GetItemID())) then
return db.reagents
end
return db.misc
end
local function UpdateButtonFromItem(button, item, variant, suppress, extradetails)
if not item or item:IsItemEmpty() then
return
end
suppress = suppress or blank
item:ContinueOnItemLoad(function()
if not ShouldShowOnItem(item) then return end
PrepareItemButton(button, variant)
local details = DetailsFromItem(item, extradetails and extradetails.level)
if extradetails then
MergeTable(details, extradetails)
if extradetails.level then
details.upgrade = ItemIsUpgrade(item, extradetails.level)
end
end
if not suppress.level then AddLevelToButton(button, details) end
if not suppress.upgrade then AddUpgradeToButton(button, details) end
if not suppress.bound then AddBoundToButton(button, details) end
if (variant == "character" or variant == "inspect" or not db.missingcharacter) then
-- if item.itemID then print("Skipping missing on", item:GetItemLink()) end
if not (suppress.missing or item.itemID) then
-- If an item was built from just an itemID it cannot know this
-- (And in the inspect case, it's going to get refreshed shortly)
AddMissingToButton(button, details)
end
end
end)
return true
end
ns.UpdateButtonFromItem = UpdateButtonFromItem
local continuableContainer
local function AddAverageLevelToFontString(unit, fontstring)
if not fontstring then return end
if not continuableContainer then
continuableContainer = ContinuableContainer:Create()
end
fontstring:Hide()
local key = unit == "player" and "character" or "inspect"
if not db[key .. "avg"] then
return
end
local mainhandEquipLoc, offhandEquipLoc
local items = {}
for slotID = INVSLOT_FIRST_EQUIPPED, INVSLOT_LAST_EQUIPPED do
-- shirt and tabard don't count
if slotID ~= INVSLOT_BODY and slotID ~= INVSLOT_TABARD then
local item = ItemFromUnitSlot(unit, slotID)
if item and not item:IsItemEmpty() then
continuableContainer:AddContinuable(item)
items[slotID] = item
-- slot bookkeeping
local equipLoc = select(4, C_Item.GetItemInfoInstant(item:GetItemLink() or item:GetItemID()))
if slotID == INVSLOT_MAINHAND then mainhandEquipLoc = equipLoc end
if slotID == INVSLOT_OFFHAND then offhandEquipLoc = equipLoc end
end
end
end
local numSlots
if mainhandEquipLoc and offhandEquipLoc then
numSlots = 16
else
local isFuryWarrior = select(2, UnitClass(unit)) == "WARRIOR"
if unit == "player" then
isFuryWarrior = isFuryWarrior and IsSpellKnown(46917) -- knows titan's grip
else
isFuryWarrior = isFuryWarrior and _G.GetInspectSpecialization and GetInspectSpecialization(unit) == 72
end
-- unit is holding a one-handed weapon, a main-handed weapon, or a 2h weapon while Fury: 16 slots
-- otherwise 15 slots
local equippedLocation = mainhandEquipLoc or offhandEquipLoc
numSlots = (
equippedLocation == "INVTYPE_WEAPON" or
equippedLocation == "INVTYPE_WEAPONMAINHAND" or
(equippedLocation == "INVTYPE_2HWEAPON" and isFuryWarrior)
) and 16 or 15
end
if pcall(GetInventorySlotInfo, "RANGEDSLOT") then
-- ranged slot exists until Pandaria
-- C_PaperDollInfo.IsRangedSlotShown(), but that doesn't actually exist in classic...
numSlots = numSlots + 1
end
-- if UnitHasRelicSlot("target") then
-- numSlots = numSlots + 1
-- end
continuableContainer:ContinueOnLoad(function()
local totalLevel = 0
for slotID, item in pairs(items) do
local level = unit ~= "player" and ItemLevelFromTooltip(_G.C_TooltipInfo and C_TooltipInfo.GetInventoryItem(unit, slotID)) or item:GetCurrentItemLevel()
totalLevel = totalLevel + level
-- print("item", item:GetItemLink(), item:GetCurrentItemLevel())
end
-- print("total", totalLevel, "/", numSlots, "=", totalLevel / numSlots)
fontstring:SetFormattedText(ITEM_LEVEL, totalLevel / numSlots)
fontstring:Show()
end)
end
-- Character frame:
local function UpdateItemSlotButton(button, unit)
CleanButton(button)
local key = unit == "player" and "character" or "inspect"
if not db[key] then
return
end
local slotID = button:GetID()
if (slotID >= INVSLOT_FIRST_EQUIPPED and slotID <= INVSLOT_LAST_EQUIPPED) then
local item = ItemFromUnitSlot(unit, slotID)
UpdateButtonFromItem(button, item, key, nil, {
level = ItemLevelFromTooltip(_G.C_TooltipInfo and C_TooltipInfo.GetInventoryItem(unit, slotID))
})
return item
end
end
do
local levelUpdater = CreateFrame("Frame")
levelUpdater:SetScript("OnUpdate", function(self)
if not self.avglevel then
if _G.CharacterModelFrame then
self.avglevel = CharacterModelFrame:CreateFontString(nil, "OVERLAY")
self.avglevel:SetPoint("BOTTOMLEFT", 5, 35)
elseif _G.CharacterModelScene then
self.avglevel = CharacterModelScene:CreateFontString(nil, "OVERLAY")
self.avglevel:SetPoint("BOTTOM", 0, 20)
end
if self.avglevel then
self.avglevel:SetFontObject(NumberFontNormal) -- GameFontHighlightSmall isn't bad
end
end
AddAverageLevelToFontString("player", self.avglevel)
self:Hide()
end)
levelUpdater:Hide()
hooksecurefunc("PaperDollItemSlotButton_Update", function(button)
UpdateItemSlotButton(button, "player")
levelUpdater:Show()
end)
end
-- and the inspect frame
ns:RegisterAddonHook("Blizzard_InspectUI", function()
local refresh = CreateFrame("Frame")
refresh.elapsed = 0
refresh:SetScript("OnUpdate", function(self, elapsed)
self.elapsed = self.elapsed + elapsed
if self.elapsed > 1.5 then
self.elapsed = 0
self:Hide()
if InspectFrame.unit then
-- Classic Era Anniversary specifically seems to trigger this with timings that cause an error here
InspectPaperDollFrame_UpdateButtons()
end
end
end)
hooksecurefunc("InspectPaperDollItemSlotButton_Update", function(button)
local item = UpdateItemSlotButton(button, InspectFrame.unit or "target")
if item and item.itemID then
-- the data was incompletely available, so queue a repeat
refresh:Show()
end
-- print("updating button", button:GetName(), item and not item.itemLink and "incomplete" or item.itemLink or "X")
end)
local avglevel
hooksecurefunc("InspectPaperDollFrame_UpdateButtons", function()
if not avglevel then
avglevel = InspectModelFrame:CreateFontString(nil, "OVERLAY")
avglevel:SetFontObject(NumberFontNormal)
-- Classic has a different frame structure until Mists:
avglevel:SetPoint("BOTTOM", 0, (isClassic and LE_EXPANSION_LEVEL_CURRENT < LE_EXPANSION_MISTS_OF_PANDARIA) and 0 or 20)
end
AddAverageLevelToFontString(InspectFrame.unit or "target", avglevel)
end)
end)
-- Equipment flyout in character frame
if _G.EquipmentFlyout_DisplayButton then
local function ItemFromEquipmentFlyoutDisplayButton(button)
local flyoutSettings = EquipmentFlyoutFrame.button:GetParent().flyoutSettings
if flyoutSettings.useItemLocation then
local itemLocation = button:GetItemLocation()
if itemLocation then
return Item:CreateFromItemLocation(itemLocation)
end
else
local location = button.location
if not location then return end
if location >= EQUIPMENTFLYOUT_FIRST_SPECIAL_LOCATION then return end
if EquipmentManager_GetLocationData then
-- 11.2.0
local locationData = EquipmentManager_GetLocationData(location)
if locationData.isBags then
return Item:CreateFromBagAndSlot(locationData.bag, locationData.slot)
end
if locationData.isPlayer then
return Item:CreateFromEquipmentSlot(locationData.slot)
end
else
local player, bank, bags, voidStorage, slot, bag = EquipmentManager_UnpackLocation(location)
if type(voidStorage) ~= "boolean" then
-- classic compatibility: no voidStorage returns, so shuffle everything down by one
-- returns either `player, bank, bags (true), slot, bag` or `player, bank, bags (false), location`
slot, bag = voidStorage, slot
end
if bags then
return Item:CreateFromBagAndSlot(bag, slot)
end
if not voidStorage then -- player or bank
return Item:CreateFromEquipmentSlot(slot)
end
end
local itemID = EquipmentManager_GetItemInfoByLocation(location)
if itemID then
-- print("fell back to itemid", location)
return Item:CreateFromItemID(itemID)
end
end
end
hooksecurefunc("EquipmentFlyout_UpdateItems", function()
local flyoutSettings = EquipmentFlyoutFrame.button:GetParent().flyoutSettings
for i, button in ipairs(EquipmentFlyoutFrame.buttons) do
CleanButton(button)
if db.flyout and button:IsShown() then
local item = ItemFromEquipmentFlyoutDisplayButton(button)
if item then
UpdateButtonFromItem(button, item, "character")
end
end
end
end)
end
-- Bags:
local function UpdateContainerButton(button, bag, slot)
CleanButton(button)
if not db.bags then
return
end
slot = slot or button:GetID()
if not (bag and slot) then
return
end
local item = Item:CreateFromBagAndSlot(bag, slot or button:GetID())
UpdateButtonFromItem(button, item, "bags")
end
if _G.ContainerFrame_Update then
hooksecurefunc("ContainerFrame_Update", function(container)
local bag = container:GetID()
local name = container:GetName()
for i = 1, container.size, 1 do
local button = _G[name .. "Item" .. i]
UpdateContainerButton(button, bag)
end
end)
else
local update = function(frame)
for _, itemButton in frame:EnumerateValidItems() do
UpdateContainerButton(itemButton, itemButton:GetBagID(), itemButton:GetID())
end
end
-- can't use ContainerFrameUtil_EnumerateContainerFrames because it depends on the combined bags setting
hooksecurefunc(ContainerFrameCombinedBags, "UpdateItems", update)
for _, frame in ipairs((ContainerFrameContainer or UIParent).ContainerFrames) do
hooksecurefunc(frame, "UpdateItems", update)
end
end
-- Main bank frame, bankbags are covered by containerframe above
if _G.BankFrameItemButton_Update then
-- pre-11.2.0 bank
hooksecurefunc("BankFrameItemButton_Update", function(button)
if not button.isBag then
UpdateContainerButton(button, button:GetParent():GetID())
end
end)
end
do
local function hookBankPanel(panel)
if not panel then return end
local update = function(frame)
local canUseBank = C_Bank.CanUseBank(frame:GetActiveBankType())
for itemButton in frame:EnumerateValidItems() do
if canUseBank then
UpdateContainerButton(itemButton, itemButton:GetBankTabID(), itemButton:GetContainerSlotID())
else
CleanButton(itemButton)
end
end
end
-- Initial load and switching tabs
hooksecurefunc(panel, "GenerateItemSlotsForSelectedTab", update)
-- Moving items
hooksecurefunc(panel, "RefreshAllItemsForSelectedTab", update)
end
hookBankPanel(_G.BankPanel) -- added in 11.2.0
hookBankPanel(_G.AccountBankPanel) -- removed in 11.2.0
end
-- Loot
if _G.LootFrame_UpdateButton then
-- Classic
hooksecurefunc("LootFrame_UpdateButton", function(index)
local button = _G["LootButton"..index]
if not button then return end
CleanButton(button)
if not db.loot then return end
-- ns.Debug("LootFrame_UpdateButton", button:IsEnabled(), button.slot, button.slot and GetLootSlotLink(button.slot))
if button:IsEnabled() and button.slot then
local link = GetLootSlotLink(button.slot)
if link then
UpdateButtonFromItem(button, Item:CreateFromItemLink(link), "loot")
end
end
end)
else
-- Dragonflight
local function handleSlot(frame)
if not frame.Item then return end
CleanButton(frame.Item)
if not db.loot then return end
local data = frame:GetElementData()
if not (data and data.slotIndex) then return end
local link = GetLootSlotLink(data.slotIndex)
if link then
UpdateButtonFromItem(frame.Item, Item:CreateFromItemLink(link), "loot", nil, {
-- GetLootSlotLink doesn't give a link for the scaled item you'll
-- actually loot. As such, we can fall back on tooltip scanning to
-- extract the real level. This is only going to work on
-- weapons/armor, but conveniently that's the things that get scaled!
level = ItemLevelFromTooltip(_G.C_TooltipInfo and C_TooltipInfo.GetLootItem(data.slotIndex)),
})
end
end
LootFrame.ScrollBox:RegisterCallback("OnUpdate", function(...)
LootFrame.ScrollBox:ForEachFrame(handleSlot)
end)
end
-- Tooltip
local OnTooltipSetItem = function(self)
if not db.tooltip then return end
local item
if self.GetItem then
local _, itemLink = self:GetItem()
if not itemLink then return end
item = Item:CreateFromItemLink(itemLink)
elseif self.GetPrimaryTooltipData then
local data = self:GetPrimaryTooltipData()
if data and data.guid and data.type == Enum.TooltipDataType.Item then
item = Item:CreateFromItemGUID(data.guid)
end
end
if not item or item:IsItemEmpty() then return end
item:ContinueOnItemLoad(function()
self:AddLine(ITEM_LEVEL:format(item:GetCurrentItemLevel()))
end)
end
if _G.C_TooltipInfo then
-- Cata-classic has TooltipDataProcessor, but doesn't actually use the new tooltips
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, OnTooltipSetItem)
else
GameTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
ItemRefTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
-- This is mostly world quest rewards:
if GameTooltip.ItemTooltip then
GameTooltip.ItemTooltip.Tooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
end
end
-- Void Storage
ns:RegisterAddonHook("Blizzard_VoidStorageUI", function()
local VOID_STORAGE_MAX = 80
hooksecurefunc("VoidStorage_ItemsUpdate", function(doStorage, doContents)
if not doContents then return end
for i = 1, VOID_STORAGE_MAX do
local itemID, textureName, locked, recentDeposit, isFiltered, quality = GetVoidItemInfo(VoidStorageFrame.page, i)
local button = _G["VoidStorageStorageButton"..i]
CleanButton(button)
if itemID and db.bags then
local link = GetVoidItemHyperlinkString(((VoidStorageFrame.page - 1) * VOID_STORAGE_MAX) + i)
if link then
local item = Item:CreateFromItemLink(link)
UpdateButtonFromItem(button, item, "bags")
end
end
end
end)
end)
-- Guild Bank
ns:RegisterAddonHook("Blizzard_GuildBankUI", function()
hooksecurefunc(GuildBankFrame, "Update", function(self)
if self.mode ~= "bank" then return end
local tab = GetCurrentGuildBankTab()
for _, column in ipairs(self.Columns) do
for _, button in ipairs(column.Buttons) do
CleanButton(button)
local link = GetGuildBankItemLink(tab, button:GetID())
if link then
local item = Item:CreateFromItemLink(link)
UpdateButtonFromItem(button, item, "bags")
end
end
end
end)
end)
-- Inventorian
ns:RegisterAddonHook("Inventorian", function()
local inv = LibStub("AceAddon-3.0", true):GetAddon("Inventorian", true)
local function ToIndex(bag, slot) -- copied from inside Inventorian
return (bag < 0 and bag * 100 - slot) or (bag * 100 + slot)
end
local function invContainerUpdateSlot(self, bag, slot)
local button = self.items[ToIndex(bag, slot)]
if not button then return end
if button:IsCached() then
local item
local icon, count, locked, quality, readable, lootable, link, noValue, itemID, isBound = button:GetInfo()
if link then
item = Item:CreateFromItemLink(link)
elseif itemID then
item = Item:CreateFromItemID(itemID)
end
CleanButton(button)
UpdateButtonFromItem(button, item, "bags")
else
UpdateContainerButton(button, bag, slot)
end
end
local function hookInventorian()
hooksecurefunc(inv.bag.itemContainer, "UpdateSlot", invContainerUpdateSlot)
hooksecurefunc(inv.bank.itemContainer, "UpdateSlot", invContainerUpdateSlot)
end
if inv.bag then
hookInventorian()
else
hooksecurefunc(inv, "OnEnable", function()
hookInventorian()
end)
end
end)
--Baggins:
ns:RegisterAddonHook("Baggins", function()
hooksecurefunc(Baggins, "UpdateItemButton", function(baggins, bagframe, button, bag, slot)
UpdateContainerButton(button, bag)
end)
end)
--Bagnon:
do
local function bagbrother_button(button)
CleanButton(button)
if not db.bags then
return
end
local bag = button:GetBag()
if type(bag) ~= "number" or button:GetClassName() ~= "BagnonContainerItem" then
local info = button:GetInfo()
if info and info.hyperlink then
local item = Item:CreateFromItemLink(info.hyperlink)
UpdateButtonFromItem(button, item, "bags")
end
return
end
UpdateContainerButton(button, bag)
end
ns:RegisterAddonHook("Bagnon", function()
hooksecurefunc(Bagnon.Item, "Update", bagbrother_button)
end)
--Bagnonium (exactly same internals as Bagnon):
ns:RegisterAddonHook("Bagnonium", function()
hooksecurefunc(Bagnonium.Item, "Update", bagbrother_button)
end)
--Combuctor (exactly same internals as Bagnon):
ns:RegisterAddonHook("Combuctor", function()
hooksecurefunc(Combuctor.Item, "Update", bagbrother_button)
end)
end
--LiteBag:
ns:RegisterAddonHook("LiteBag", function()
_G.LiteBag_RegisterHook('LiteBagItemButton_Update', function(frame)
local bag = frame:GetParent():GetID()
UpdateContainerButton(frame, bag)
end)
end)
-- Baganator
ns:RegisterAddonHook("Baganator", function()
local function textInit(itemButton)
local text = itemButton:CreateFontString(nil, "OVERLAY", "NumberFontNormal")
text.sizeFont = true
return text
end
-- Note to self: Baganator API update function returns are tri-state:
-- true: something to show
-- false: nothing to show
-- nil: call this again soon (probably because of item-caching)
local function onUpdate(callback)
return function(cornerFrame, details)
if not details.itemLink then return false end
local button = cornerFrame:GetParent():GetParent()
local item
-- If we have a container-item, we should use that because it's needed for soulbound detection
local bag, slot = button:GetParent():GetID(), button:GetID()
-- print("SetItemDetails", details.itemLink, bag, slot)
local fromBagslot = bag and slot and slot ~= 0
if fromBagslot then
item = Item:CreateFromBagAndSlot(bag, slot)
elseif details.itemLink then
item = Item:CreateFromItemLink(details.itemLink)
end
if not item then return false end -- no item, go away
if not item:IsItemDataCached() then return nil end -- item isn't cached, come back in a second
if not ShouldShowOnItem(item) then return false end
local data = DetailsFromItem(item, not fromBagslot) -- if not from bagslot, forcibly acquire the level from the tooltip
return callback(cornerFrame, item, data, details)
end
end
Baganator.API.RegisterCornerWidget("sIlvl: Item Level", "simpleitemlevel-ilvl",
onUpdate(function(cornerFrame, item, data, details)
cornerFrame:SetText(data.level)
if db.color and data.quality then
local r, g, b = C_Item.GetItemQualityColor(data.quality)
cornerFrame:SetTextColor(r, g, b)
else
cornerFrame:SetTextColor(1, 1, 1)
end
return true
end),
textInit, {default_position = "top_right", priority = 1}
)
Baganator.API.RegisterCornerWidget("sIlvl: Upgrade", "simpleitemlevel-upgrade",
onUpdate(function(cornerFrame, item, data, details)
if data.upgrade then
local minLevel = select(5, C_Item.GetItemInfo(item:GetItemLink() or item:GetItemID()))
if minLevel and minLevel > UnitLevel("player") then
cornerFrame:SetVertexColor(1, 0, 0)
else
cornerFrame:SetVertexColor(1, 1, 1)
end
return true
end
return false
end),
function (itemButton)
local texture = itemButton:CreateTexture(nil, "ARTWORK")
texture:SetAtlas(ns.upgradeAtlas)
texture:SetSize(11, 11)
return texture
end,
{default_position = "top_left", priority = 1}
)
Baganator.API.RegisterCornerWidget("sIlvl: Soulbound", "simpleitemlevel-bound",
onUpdate(function(cornerFrame, item, data, details)
return ColorFrameByBinding(cornerFrame, data)
end),
function (itemButton)
local texture = itemButton:CreateTexture(nil, "ARTWORK")
texture:SetAtlas(ns.soulboundAtlas)
texture:SetSize(12, 12)
return texture
end, {default_position = "bottom_left", priority = 1}
)
Baganator.API.RegisterCornerWidget("sIlvl: Missing", "simpleitemlevel-missing",
onUpdate(function(cornerFrame, item, data, details)
if db.missingcharacter then return false end