forked from KleMiX/InspectEquip-3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
857 lines (754 loc) · 23.5 KB
/
Core.lua
File metadata and controls
857 lines (754 loc) · 23.5 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
-- InspectEquip
InspectEquip = LibStub("AceAddon-3.0"):NewAddon("InspectEquip", "AceHook-3.0", "AceTimer-3.0", "AceEvent-3.0", "AceConsole-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("InspectEquip")
local IE = InspectEquip
local IS = InspectEquip_ItemSources --> ItemSources.lua
local WIN = InspectEquip_InfoWindow --> info.xml
local BACK = InspectEquip_Backdrop --> info.xml
local TITLE = InspectEquip_BackdropTitle
local AVGIL = InspectEquip_BackdropAvgItemLevel
local exMod = nil
local ItemUpgradeInfo = LibStub("LibItemUpgradeInfo-1.0")
local slots = { "HeadSlot", "NeckSlot", "ShoulderSlot", "BackSlot", "ChestSlot",
"WristSlot", "HandsSlot", "WaistSlot", "LegsSlot", "FeetSlot",
"Finger0Slot", "Finger1Slot", "Trinket0Slot", "Trinket1Slot", "MainHandSlot",
"SecondaryHandSlot" } -- TabardSlot, ShirtSlot
local noEnchantWarningSlots = {
["MainHandSlot"] = true, ["SecondaryHandSlot"] = true, ["Finger0Slot"] = true, ["Finger1Slot"] = true,
}
local lines = {}
local numlines = 0
local curline = 0
local curUnit = nil
local curUnitName = nil
local curUser = nil
local curGUID = nil
local cached = false
local headers = {}
local numheaders = 0
local yoffset = -40
local hooked = false
local autoHidden = false
local origInspectUnit
local tonumber = tonumber
local gmatch = string.gmatch
local tinsert = table.insert
local tsort = table.sort
local band = bit.band
local Examiner = Examiner
--local _,_,_,gameToc = GetBuildInfo()
local tooltipTimer = nil
local retryTimer = nil
local lastInspectedUnit = nil
--------------------------------------------------------------------------------------
InspectEquipConfig = {}
local defaults = {
tooltips = true,
showUnknown = true,
inspectWindow = true,
charWindow = true,
checkEnchants = true,
checkSockets = true,
listItemLevels = true,
showAvgItemLevel = true,
showArtifactRelics = true,
ttR = 1.0,
ttG = 0.75,
ttB = 0.0,
maxSourceCount = 5,
}
local options = {
name = "InspectEquip",
type = "group",
args = {
tooltips = {
order = 1, type = "toggle", width = "full",
name = L["Add drop information to tooltips"],
desc = L["Add item drop information to all item tooltips"],
get = function() return InspectEquipConfig.tooltips end,
set = function(_,v) InspectEquipConfig.tooltips = v; if v then IE:HookTooltips() end end,
},
showunknown = {
order = 2, type = "toggle", width = "full",
name = L["Include unknown items in overview"],
desc = L["Show items that cannot be categorized in a seperate category"],
get = function() return InspectEquipConfig.showUnknown end,
set = function(_,v) InspectEquipConfig.showUnknown = v end,
},
inspectwindow = {
order = 3, type = "toggle", width = "full",
name = L["Attach to inspect window"],
desc = L["Show the equipment list when inspecting other characters"],
get = function() return InspectEquipConfig.inspectWindow end,
set = function(_,v) InspectEquipConfig.inspectWindow = v end,
},
charwindow = {
order = 4, type = "toggle", width = "full",
name = L["Attach to character window"],
desc = L["Also show the InspectEquip panel when opening the character window"],
get = function() return InspectEquipConfig.charWindow end,
set = function(_,v) InspectEquipConfig.charWindow = v end,
},
checkenchants = {
order = 5, type = "toggle", width = "full",
name = L["Check for unenchanted items"],
desc = L["Display a warning for unenchanted items"],
get = function() return InspectEquipConfig.checkEnchants end,
set = function(_,v) InspectEquipConfig.checkEnchants = v end,
},
listitemlevels = {
order = 6, type = "toggle", width = "full",
name = L["Show item level in equipment list"],
desc = L["Show the item level of each item in the equipment panel"],
get = function() return InspectEquipConfig.listItemLevels end,
set = function(_,v) InspectEquipConfig.listItemLevels = v end,
},
showavgitemlevel = {
order = 7, type = "toggle", width = "full",
name = L["Show average item level in equipment list"],
desc = L["Show the average item level of all items in the equipment panel"],
get = function() return InspectEquipConfig.showAvgItemLevel end,
set = function(_,v) InspectEquipConfig.showAvgItemLevel = v end,
},
showartifactrelics = {
order = 8, type = "toggle", width = "full",
name = L["Show artifact relics in equipment list"],
desc = L["Show the relics of artifact weapon in the equipment panel"],
get = function() return InspectEquipConfig.showArtifactRelics end,
set = function(_,v) InspectEquipConfig.showArtifactRelics = v end,
},
tooltipcolor = {
order = 9, type = "color",
name = L["Tooltip text color"],
width = "full",
get = function() return InspectEquipConfig.ttR, InspectEquipConfig.ttG, InspectEquipConfig.ttB, 1.0 end,
set = function(_,r,g,b,a)
InspectEquipConfig.ttR = r
InspectEquipConfig.ttG = g
InspectEquipConfig.ttB = b
end,
},
maxsourcecount = {
order = 10, type = "range",
min = 1, max = 20, softMax = 10, step = 1,
width = "double",
name = L["Max. amount of sources in tooltips"],
desc = L["The maximum amount of sources that are displayed in item tooltips"],
get = function() return InspectEquipConfig.maxSourceCount end,
set = function(_,v) InspectEquipConfig.maxSourceCount = v end,
},
database = {
order = 11, type = "group", inline = true,
name = L["Database"],
args = {
resetdb = {
order = 1, type = "execute",
width = "double",
name = L["Reset database"],
desc = L["Recreate the database"],
func = function() IE:CreateLocalDatabase() end,
},
},
},
checksocketts = {
order = 12, type = "toggle", width = "full",
name = L["Check for missing gems"],
desc = L["Display a warning for items with missing gems"],
get = function() return InspectEquipConfig.checkSockets end,
set = function(_,v) InspectEquipConfig.checkSockets = v end,
}
},
}
LibStub("AceConfig-3.0"):RegisterOptionsTable("InspectEquip", options, "/inspectequip")
LibStub("AceConfigDialog-3.0"):AddToBlizOptions("InspectEquip")
--------------------------------------------------------------------------------------
-- taken from https://www.wowinterface.com/forums/showpost.php?p=319704&postcount=2
local GetNumSockets
do
-- Generate a unique name for the tooltip:
local tooltipName = "PhanxScanningTooltip" .. random(100000, 10000000)
-- Create the hidden tooltip object:
local tooltip = CreateFrame("GameTooltip", tooltipName, UIParent, "GameTooltipTemplate")
tooltip:SetOwner(UIParent, "ANCHOR_NONE")
-- Build a list of the tooltip's texture objects:
local textures = {}
for i = 1, 10 do
textures[i] = _G[tooltipName .. "Texture" .. i]
end
-- Set up scanning and caching:
local numSocketsFromLink = setmetatable({}, { __index = function(t, link)
-- Send the link to the tooltip:
tooltip:SetHyperlink(link)
-- Count how many textures are shown:
local n = 0
for i = 1, 10 do
if textures[i]:IsShown() then
n = n + 1
end
end
-- Cache and return the count for this link:
t[link] = n
return n
end })
-- Expose the API:
function GetNumSockets(link)
return link and numSocketsFromLink[link]
end
end
function IE:OnInitialize()
setmetatable(InspectEquipConfig, {__index = defaults})
self:SetParent(Examiner or InspectFrame)
WIN:Hide()
TITLE:SetText("InspectEquip")
if Examiner and Examiner.CreateModule then
exMod = Examiner:CreateModule("InspectEquip")
exMod.OnCacheLoaded = function(s, entry, unit)
if InspectEquipConfig.inspectWindow then
IE:Inspect("cache", entry)
end
end
exMod.OnClearInspect = function(s) WIN:Hide() end
exMod.OnInspect = function(s, unit)
if InspectEquipConfig.inspectWindow then
IE:SetParent(Examiner); IE:Inspect(unit)
end
end
end
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("ADDON_LOADED")
--self:InitLocalDatabase()
end
function IE:OnEnable()
origInspectUnit = origInspectUnit or InspectUnit
InspectUnit = function(...) IE:InspectUnit(...) end
self:SecureHookScript(PaperDollFrame, "OnShow", "PaperDollFrame_OnShow")
self:SecureHookScript(PaperDollFrame, "OnHide", "PaperDollFrame_OnHide")
if GearManagerDialog then -- 4.0
self:SecureHookScript(GearManagerDialog, "OnShow", "GearManagerDialog_OnShow")
self:SecureHookScript(GearManagerDialog, "OnHide", "GearManagerDialog_OnHide")
end
if OutfitterFrame then
self:SecureHookScript(OutfitterFrame, "OnShow", "GearManagerDialog_OnShow")
self:SecureHookScript(OutfitterFrame, "OnHide", "GearManagerDialog_OnHide")
end
self:RegisterEvent("UNIT_INVENTORY_CHANGED")
self:RegisterEvent("INSPECT_READY")
end
function IE:OnDisable()
InspectUnit = origInspectUnit
if hooked then
hooked = false
self:Unhook("InspectFrame_UnitChanged")
end
self:UnhookAll()
self:UnregisterEvent("UNIT_INVENTORY_CHANGED")
self:UnregisterEvent("INSPECT_READY")
self:CancelAllTimers()
WIN:Hide()
end
local entered = false
function IE:PLAYER_ENTERING_WORLD()
entered = true
self:ScheduleTooltipHook()
self:InitLocalDatabase()
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
end
function IE:ADDON_LOADED(e, name)
if entered then
self:ScheduleTooltipHook()
end
end
-- Ugly hack, but some addons override the OnTooltipSetItem handler on
-- ItemRefTooltip, breaking IE. Using this timer, IE hopefully hooks after them.
function IE:ScheduleTooltipHook()
if InspectEquipConfig.tooltips then
if tooltipTimer then
self:CancelTimer(tooltipTimer, true)
end
tooltipTimer = self:ScheduleTimer('HookTooltips', 3)
end
end
function IE:SetParent(frame)
WIN:SetParent(frame)
WIN:ClearAllPoints()
if not (frame == Examiner) then
WIN:SetPoint("TOPLEFT", frame, "TOPRIGHT", 5, 0)
else
WIN:SetPoint("TOPLEFT", frame, "TOPRIGHT", -25, -13)
end
end
function IE:NewLine()
local row = CreateFrame("Frame", nil, WIN)
row:SetHeight(12)
row:SetWidth(200)
local txt = row:CreateFontString(nil, "ARTWORK")
txt:SetJustifyH("LEFT")
txt:SetFontObject(GameFontHighlightSmall)
txt:SetPoint("TOPLEFT", row, "TOPLEFT", 0, 0)
row.text = txt
row.yoffset = yoffset
IE:SetLinePadding(row, 0)
yoffset = yoffset - 15
numlines = numlines + 1
lines[numlines] = row
row:EnableMouse(true)
row:SetScript("OnEnter", IE.Line_OnEnter)
row:SetScript("OnLeave", IE.Line_OnLeave)
row:SetScript("OnMouseDown", IE.Line_OnClick)
end
function IE:SetLinePadding(line, padding)
local padWidth = select(2,line.text:GetFont()) * padding * 0.6
line:SetPoint("TOPLEFT", WIN, "TOPLEFT", 15 + padWidth, line.yoffset)
line.padLeft = padWidth
end
function IE:ResetDisplay()
for i = 1, numlines do
lines[i].text:SetText("")
IE:SetLinePadding(lines[i], 0)
lines[i]:Hide()
end
curline = 0
end
function IE:AddLine(padding, text, link, item)
curline = curline + 1
if curline > numlines then
self:NewLine()
end
local line = lines[curline]
line.link = link
line.item = item
line.text:SetText(text)
line:SetWidth(line.text:GetStringWidth())
IE:SetLinePadding(line, padding)
line:SetFrameLevel(WIN:GetFrameLevel() + 1)
line:Show()
end
function IE:FullUnitName(name, realm)
if realm and realm ~= "" then
return name .. "-" .. realm
else
return name
end
end
function IE:GetExaminerCache(unit)
local name, realm = UnitName(unit)
return Examiner_Cache and Examiner_Cache[self:FullUnitName(name, realm)]
end
function IE:InspectUnit(unit, ...)
if lastInspectedUnit == unit then
return -- some addons will enforce unit change on inspect and we can go recursively back here and explode in stack overflow
end
lastInspectedUnit = unit
origInspectUnit(unit, ...)
if InspectEquipConfig.inspectWindow then
self:SetParent(Examiner or InspectFrame)
WIN:Hide()
if not hooked and InspectFrame_UnitChanged then
hooked = true
self:SecureHook("InspectFrame_UnitChanged")
end
self:Inspect(unit)
end
lastInspectedUnit = nil -- just reset asap, since this is just a measure to not recurse, which will be completed by now
end
function IE:InspectFrame_UnitChanged()
if InspectFrame.unit and InspectEquipConfig.inspectWindow then
self:InspectUnit(InspectFrame.unit)
else
WIN:Hide()
end
end
function IE:PaperDollFrame_OnShow()
if InspectEquipConfig.charWindow then
IE:SetParent(CharacterFrame)
IE:Inspect("player")
end
end
function IE:PaperDollFrame_OnHide()
if WIN:GetParent() == CharacterFrame then
WIN:Hide()
autoHidden = false
end
end
function IE:GearManagerDialog_OnShow()
if WIN:GetParent() == CharacterFrame and WIN:IsShown() then
WIN:Hide()
autoHidden = true
end
end
function IE:GearManagerDialog_OnHide()
if autoHidden and WIN:GetParent() == CharacterFrame then
WIN:Show()
autoHidden = false
end
end
function IE:UNIT_INVENTORY_CHANGED(event, unit)
if (unit == "player") and (WIN:IsVisible() or autoHidden) and (WIN:GetParent() == CharacterFrame) then
IE:Inspect("player")
elseif (unit == curUnit) and (UnitName(unit) == curUnitName) and (WIN:IsVisible()) then
IE:Inspect(curUnit)
end
end
function IE:INSPECT_READY(event, guid)
if (guid == curGUID) and (UnitName(curUnit) == curUnitName) then
IE:Inspect(curUnit)
else
-- probably mouseover changed... nothing we can do apparently :(
-- (inspect by unit name / guid does not work)
end
end
function IE:Inspect(unit, entry)
local unitName, unitRealm
cached = (unit == "cache")
if retryTimer then
-- stop retry timer if present
self:CancelTimer(retryTimer, true)
retryTimer = nil
end
if (cached and (not entry)) or (not self:IsEnabled()) then
WIN:Hide()
return
end
local cacheItems = cached and entry.Items or nil
if cached then
unitName, unitRealm = entry.name, entry.realm
curGUID = nil
else
if (not unit or not UnitExists(unit)) then
unit = "player"
end
unitName, unitRealm = UnitName(unit)
curGUID = UnitGUID(unit)
if not CanInspect(unit) then
entry = self:GetExaminerCache(unit)
if entry then
cached = true
cacheItems = entry.Items
end
else
--ClearInspectPlayer()
--NotifyInspect(unit)
end
end
if unitRealm == "" then unitRealm = nil end
curUnit = unit
curUnitName = unitName
curUser = self:FullUnitName(unitName, unitRealm)
TITLE:SetText("InspectEquip: " .. curUser .. (cached and " (Cache)" or ""))
self:ResetDisplay()
local items = { cats = {}, items = {} }
local itemsFound = false
local getItem
if cached then
getItem = function(slot)
local istr = cacheItems[slot]
if istr then
local itemId = tonumber(istr:match("item:(%d+)"))
return select(2, GetItemInfo(istr)) or ("[" .. itemId .. "]")
else
return nil
end
end
else
getItem = function(slot) return GetInventoryItemLink(unit, GetInventorySlotInfo(slot)) end
end
local calciv = InspectEquipConfig.showAvgItemLevel
local showRelics = InspectEquipConfig.showArtifactRelics
local iLevelSum, iCount = 0,0
local artifactLevel = 0
local artifactCount = 0
for _,slot in pairs(slots) do
local itemLink = getItem(slot)
local isArtifact = false
if itemLink then
-- get source
local source = self:GetItemSourceCategories(itemLink)
if (not source) and InspectEquipConfig.showUnknown then
local _,_,rar,ilvl = GetItemInfo(itemLink)
if rar and rar >= 2 then
if rar ==5 then
source = {L["Legendary"]}
elseif rar == 6 then
source = {L["Artifact"]}
else
source = {L["Unknown"]}
end
end
end
if slot == "MainHandSlot" or slot == "SecondaryHandSlot" then
local _,_,rar,ilvl = GetItemInfo(itemLink)
if rar and rar == 6 then -- artifact found
isArtifact = true
artifactCount = artifactCount + 1 -- count only count, lol. ilvl will be get as usual
end
end
if source then
local enchantId = tonumber(itemLink:match("Hitem:%d+:(%d+):"))
itemsFound = true
local _, _, _, gem1, gem2, gem3, gem4 = strsplit(":", strmatch(itemLink, "|H(.-)|h"))
local numFilledSockets = (tonumber(gem1) or 0) + (tonumber(gem2) or 0) + (tonumber(gem3) or 0) + (tonumber(gem4) or 0)
local unsocketedCount = GetNumSockets(itemLink) - numFilledSockets
-- find category
local cat = items
local entry
for _, entry in pairs(source) do
if cat.cats[entry] == nil then
cat.cats[entry] = { count = 0, cats = {}, items = {} }
end
cat = cat.cats[entry]
cat.count = cat.count + 1
end
-- add item to category
cat.hasItems = true
cat.items[cat.count] = {link = itemLink, enchant = enchantId, slot = slot, unsocketedCount = unsocketedCount}
if isArtifact and showRelics then -- add artifact relics to the list
for rs = 1, 3 do
local reliclink = select(2, GetItemGem(itemLink, rs))
if reliclink then
cat.count = cat.count + 1
cat.items[cat.count] = {link = reliclink, enchant = nil, slot = slot, unsocketedCount = 0}
end
end
end
end
-- calculate avg ilvl
if calciv then
--local lvl = ItemUpgradeInfo:GetUpgradedItemLevel(itemLink)
local lvl = GetDetailedItemLevelInfo(itemLink)
if lvl then
if isArtifact then
if lvl > artifactLevel then -- find out max artifact level from both items
artifactLevel = lvl
end
else
iLevelSum = iLevelSum + lvl
iCount = iCount + 1
end
end
end
elseif not cached then
local texture = GetInventoryItemTexture(unit, GetInventorySlotInfo(slot))
if texture and not retryTimer then
-- item link is not yet available, but item texture is, i.e. the slot is not empty
-- item link data will become available shortly, so we just try it again in a sec
retryTimer = self:ScheduleTimer("Inspect", 1, unit)
end
end
end
if itemsFound then
self:AddCategory(items, 0, artifactLevel)
if calciv and iCount > 0 then
iLevelSum = iLevelSum + artifactLevel * artifactCount
iCount = iCount + artifactCount
local avgLvl = iLevelSum / iCount
AVGIL:SetText(L["Avg. Item Level"] .. ": " .. string.format("%.2f", avgLvl))
AVGIL:Show()
else
AVGIL:Hide()
end
self:FixWindowSize()
if WIN:GetParent() == CharacterFrame and ((GearManagerDialog and GearManagerDialog:IsVisible()) or (OutfitterFrame and OutfitterFrame:IsVisible())) then
autoHidden = true
else
WIN:Show()
end
else
WIN:Hide()
end
end
function IE:AddCategory(cat, padding, artifactLevel)
-- add items
if cat.hasItems then
self:AddItems(cat.items, padding+1, artifactLevel)
end
-- sort subcategories by item count
local t = {}
for name, subcat in pairs(cat.cats) do
tinsert(t, {name = name, subcat = subcat})
end
tsort(t, function(a,b) return a.subcat.count > b.subcat.count end)
-- add subcategories
for i = 1, #t do
local name = t[i].name
local subcat = t[i].subcat
self:AddLine(padding, name .. " (" .. subcat.count .. ")")
self:AddCategory(subcat, padding+1, artifactLevel)
end
end
function IE:AddItems(tab, padding, artifactLevel)
for _, item in pairs(tab) do
local suffix = ""
local prefix = ""
local isArtifact = false
if InspectEquipConfig.listItemLevels then
--local ilvl = ItemUpgradeInfo:GetUpgradedItemLevel(item.link)
local ilvl = GetDetailedItemLevelInfo(item.link)
if item.slot == "MainHandSlot" then
isArtifact = ItemUpgradeInfo:IsArtifact(item.link)
end
if item.slot == "SecondaryHandSlot" then
isArtifact = ItemUpgradeInfo:IsArtifact(item.link)
end
if isArtifact then
ilvl = artifactLevel
end
if ilvl then
prefix = "|cffaaaaaa[" .. ilvl .. "]|r "
end
end
if InspectEquipConfig.checkEnchants and (item.enchant == nil) and noEnchantWarningSlots[item.slot] then
local add = true
-- check if off hand is a weapon, skip if not
if item.slot == "SecondaryHandSlot" then
local classID = select(12, GetItemInfo(item.link))
add = classID == LE_ITEM_CLASS_WEAPON
end
if add then
suffix = suffix .. "|cffff0000[*]|r"
prefix = prefix .. suffix
end
end
if InspectEquipConfig.checkSockets and (item.unsocketedCount > 0) then
suffix = suffix .. "|cffff0000[S]|r"
prefix = prefix .. suffix
end
if suffix ~= "" then
prefix = prefix .. " "
suffix = " " .. suffix
end
self:AddLine(padding, prefix .. item.link .. suffix, item.link, item)
end
end
function IE:GetItemData(item)
local id
if type(item) == "number" then
id = item
else -- item string/link
id = tonumber(item:match("item:(%d+)"))
end
if id then
local isSrc = IS.Items[id]
local locSrc = InspectEquipLocalDB.Items[id]
if isSrc and locSrc then
-- combine results
return locSrc .. ";" .. isSrc
else
return isSrc or locSrc
end
else
return nil
end
end
function IE:GetZoneName(id)
return IS.Zones[id] or InspectEquipLocalDB.Zones[id]
end
function IE:GetBossName(id)
return IS.Bosses[id] or InspectEquipLocalDB.Bosses[id]
end
function IE:GetItemSourceCategories(itemLink)
local data = IE:GetItemData(itemLink)
if data then
for entry in gmatch(data, "[^;]+") do
local next_field = gmatch(entry, "[^_]+")
local cat = next_field()
if cat == "r" or cat == "d" then
-- raid/dungeon
local zone = IE:GetZoneName(tonumber(next_field()))
local mode = next_field()
local zoneType
if cat == "r" then zoneType = L["Raid"] else zoneType = L["Instances"] end
return {zoneType, zone}
elseif cat == "v" or cat == "g" then
-- vendor
local mainCat
if cat == "v" then mainCat = L["Vendor"] else mainCat = L["Guild Vendor"] end
local typ = next_field()
while typ do
if typ == "c" then
-- currency
local currency = tonumber(next_field())
next_field()
local curName = GetCurrencyInfo(currency)
return {mainCat, curName}
elseif typ == "i" then
-- item
next_field()
elseif typ == "m" then
-- money
next_field()
end
typ = next_field()
end
return {mainCat}
elseif cat == "f" then
-- reputation rewards
return {L["Reputation rewards"]}
elseif cat == "m" then
-- darkmoon cards
return {L["Darkmoon Faire"]}
elseif cat == "w" then
-- world drops
return {L["World drops"]}
elseif cat == "c" then
-- crafted
return {L["Crafted"]}
elseif cat == "q" then
-- quest rewards
return {L["Quest Reward"]}
end
end
end
return nil
end
function IE:FixWindowSize()
local maxwidth = TITLE:GetStringWidth()
for i = 1, numlines do
local width = lines[i].text:GetStringWidth() + lines[i].padLeft
if maxwidth < width then maxwidth = width end
end
local height = (curline * 15) + 55
if InspectEquipConfig.showAvgItemLevel then
height = height + 15
end
WIN:SetWidth(maxwidth + 40)
WIN:SetHeight(height)
BACK:SetWidth(maxwidth + 40)
BACK:SetHeight(height)
end
function IE.Line_OnEnter(row)
if row.link then
-- anchor on the correct side based on where there's more room
GameTooltip:SetOwner(row, "ANCHOR_NONE")
local ycenter = select(2, row:GetCenter()) * row:GetEffectiveScale()
if ycenter > select(2, UIParent:GetCenter()) * UIParent:GetScale() then
GameTooltip:SetPoint("TOPLEFT", row, "BOTTOMLEFT")
else
GameTooltip:SetPoint("BOTTOMLEFT", row, "TOPLEFT")
end
if (not cached) and (UnitName(curUnit) == curUnitName) then
row.link = row.link or GetInventoryItemLink(curUnit, GetInventorySlotInfo(row.item.slot))
end
GameTooltip:SetHyperlink(row.link)
if row.item and InspectEquipConfig.checkEnchants and (row.item.enchant == nil) and noEnchantWarningSlots[row.item.slot] then
GameTooltip:AddLine(" ")
GameTooltip:AddLine("|cffff0000" .. L["Item is not enchanted"] .. "|r")
end
if row.item and InspectEquipConfig.checkSockets and (row.item.unsocketedCount > 0) then
GameTooltip:AddLine(" ")
GameTooltip:AddLine("|cffff0000" .. L["Item is not socketed"] .. "|r")
end
GameTooltip:Show()
end
end
function IE.Line_OnLeave(row)
GameTooltip:Hide()
end
function IE.Line_OnClick(row, button)
if row.link then
if IsControlKeyDown() then
DressUpItemLink(row.link)
elseif IsShiftKeyDown() then
ChatEdit_InsertLink(row.link)
end
end
end