-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGlobals.lua
1995 lines (1702 loc) · 63.2 KB
/
Globals.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
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 addonName, addon = ...;
local libGlow = LibStub("LibCustomGlow-1.0")
local Database = addon.Database;
local Character = addon.Character;
local Talents = addon.Talents;
local Tradeskills = addon.Tradeskills;
addon.characterDefaults = {
guid = "",
name = "",
class = 3,
gender = 1,
level = 1,
race = false,
rank = 1,
onlineStatus = {
isOnline = false,
zone = "",
},
alts = {},
mainCharacter = false,
publicNote = "",
mainSpec = false,
offSpec = false,
mainSpecIsPvP = false,
offSpecIsPvP = false,
profile = {},
profession1 = "-",
profession1Level = 0,
profession1Spec = false,
profession1Recipes = {},
profession2 = "-",
profession2Level = 0,
profession2Spec = false,
profession2Recipes = {},
cookingLevel = 0,
cookingRecipes = {},
fishingLevel = 0,
firstAidLevel = 0,
firstAidRecipes = {},
talents = {},
glyphs = {},
inventory = {
current = {},
},
paperDollStats = {
current = {},
},
resistances = {
current = {},
},
auras = {
current = {},
},
containers = {},
lockouts = {},
}
addon.contextMenuSeparator = {
hasArrow = false;
dist = 0;
text = "",
isTitle = true;
isUninteractable = true;
notCheckable = true;
iconOnly = true;
icon = "Interface\\Common\\UI-TooltipDivider-Transparent";
tCoordLeft = 0;
tCoordRight = 1;
tCoordTop = 0;
tCoordBottom = 1;
tSizeX = 0;
tSizeY = 8;
tFitDropDownSizeX = true;
iconInfo = {
tCoordLeft = 0,
tCoordRight = 1,
tCoordTop = 0,
tCoordBottom = 1,
tSizeX = 0,
tSizeY = 8,
tFitDropDownSizeX = true
}}
--create these at addon level
addon.thisCharacter = "";
addon.thisGuild = false;
addon.guilds = {}
addon.characters = {}
addon.contextMenu = CreateFrame("Frame", "GuildbookContextMenu", UIParent, "UIDropDownMenuTemplate")
addon.recruitment = {
statusIDs = {
[0] = "Imported",
[1] = "Invite sent",
[2] = "Invite responded",
[3] = "",
[4] = "",
}
}
addon.api = {
classic = {},
wrath = {},
cata = {},
}
function addon.api.easyMenu(parent, menu)
if MenuUtil then
MenuUtil.CreateContextMenu(parent, function(parent, rootDescription)
for _, element in ipairs(menu) do
local menuButton;
if element.isTitle then
menuButton = rootDescription:CreateTitle(element.text)
elseif element.isSeparater then
menuButton = rootDescription:CreateSpacer()
elseif element.isDivider then
menuButton = rootDescription:CreateDivider()
else
menuButton = rootDescription:CreateButton(element.text, function() if element.func then element.func() end end)
end
if element.menuList then
for _, subElement in ipairs(element.menuList) do
menuButton:CreateButton(subElement.text, function() if subElement.func then subElement.func() end end)
end
end
end
end)
end
end
--[[
EasyMenu was used in many places, for now just hack it back into the global space and pass through to the new Menu stuff
old signature
EasyMenu(menu, addon.contextMenu, "cursor", 0, 0, "MENU", 0.6)
]]
function EasyMenu(menuTable, menuFrame)
addon.api.easyMenu(menuFrame, menuTable)
end
local debugTypeIcons = {
warning = "services-icon-warning",
info = "glueannouncementpopup-icon-info",
comms = "chatframe-button-icon-voicechat",
comms_in = "voicechat-channellist-icon-headphone-on",
comms_out = "voicechat-icon-textchat-silenced",
bank = "ShipMissionIcon-Treasure-Mission",
tradeskills = "Mobile-Alchemy",
}
local debugTypeIDs = {
warning = 1,
info = 2,
comms = 3,
comms_in = 4,
comms_out = 5,
bank = 6,
tradeskills = 7,
character = 8,
}
addon.paperDollSlotNames = {
["CharacterHeadSlot"] = { allignment = "right", slotID = 1, },
["CharacterNeckSlot"] = { allignment = "right", slotID = 2, },
["CharacterShoulderSlot"] = { allignment = "right", slotID = 3, },
["CharacterBackSlot"] = { allignment = "right", slotID = 15, },
["CharacterChestSlot"] = { allignment = "right", slotID = 5, },
--["CharacterShirtSlot"] = { allignment = "right", slotID = 4, },
--["CharacterTabardSlot"] = { allignment = "right", slotID = 19, },
["CharacterWristSlot"] = { allignment = "right", slotID = 9, },
["CharacterHandsSlot"] = { allignment = "left", slotID = 10, },
["CharacterWaistSlot"] = { allignment = "left", slotID = 6, },
["CharacterLegsSlot"] = { allignment = "left", slotID = 7, },
["CharacterFeetSlot"] = { allignment = "left", slotID = 8, },
["CharacterFinger0Slot"] = { allignment = "left", slotID = 11, },
["CharacterFinger1Slot"] = { allignment = "left", slotID = 12, },
["CharacterTrinket0Slot"] = { allignment = "left", slotID = 13, },
["CharacterTrinket1Slot"] = { allignment = "left", slotID = 14, },
["CharacterMainHandSlot"] = { allignment = "top", slotID = 16, },
["CharacterSecondaryHandSlot"] = { allignment = "top", slotID = 17, },
["CharacterRangedSlot"] = { allignment = "top", slotID = 18, },
}
local ignoreEnchantSlotIDs = {
[true] = {
[2] = true,
[6] = true,
[13] = true,
[14] = true,
},
[false] = {
[2] = true,
[6] = true,
[11] = true,
[12] = true,
[13] = true,
[14] = true,
},
}
addon.itemQualityAtlas_Overlay = {
[2] = "bags-glow-green",
[3] = "bags-glow-blue",
[4] = "bags-glow-purple",
[5] = "bags-glow-orange",
-- [2] = "loottab-set-itemborder-green",
-- [3] = "loottab-set-itemborder-blue",
-- [4] = "loottab-set-itemborder-purple",
-- [5] = "loottab-set-itemborder-orange",
}
addon.itemQualityAtlas_Borders = {
[2] = "loottab-set-itemborder-green",
[3] = "loottab-set-itemborder-blue",
[4] = "loottab-set-itemborder-purple",
[5] = "loottab-set-itemborder-orange",
["ff1eff00"] = "loottoast-itemborder-green",
["ff0070dd"] = "loottoast-itemborder-blue",
["ffa335ee"] = "loottoast-itemborder-purple",
["ffff8000"] = "loottoast-itemborder-orange",
}
local breakLink = function(link)
return string.match(link, [[|H([^:]*):([^|]*)|h(.*)|h]])
end
--local socketAtlas = "auctionhouse-icon-socket";
local socketFileIDs = {
EMPTY_SOCKET_BLUE = 136256,
EMPTY_SOCKET_META = 136257,
EMPTY_SOCKET_RED = 136258,
EMPTY_SOCKET_YELLOW = 136259,
EMPTY_SOCKET_PRISMATIC = 458977,
}
local socketOrder = {
[1] = "EMPTY_SOCKET_META",
[2] = "EMPTY_SOCKET_RED",
[3] = "EMPTY_SOCKET_YELLOW",
[4] = "EMPTY_SOCKET_BLUE",
[5] = "EMPTY_SOCKET_PRISMATIC",
}
local socketIconSize = 14;
local paperdollOverlays = {}
local function ScanTooltip(link, unit, slot)
local t = {}
GuildbookScanningTooltip:ClearLines()
if link then
GuildbookScanningTooltip:SetHyperlink(link)
elseif unit and slot then
GuildbookScanningTooltip:SetInventoryItem(unit, slot)
end
local regions = {GuildbookScanningTooltip:GetRegions()}
for k, region in ipairs(regions) do
if region and region:GetObjectType() == "FontString" then
local text = region:GetText()
if type(text) == "string" then
table.insert(t, text)
-- local number = tonumber(text:match("%-?%d+"))
-- if number then
-- table.insert(t, {
-- attribute = text:gsub("%-?%d+", "%%d"),
-- value = number,
-- displayText = text,
-- })
-- else
-- for k, socket in ipairs(sockets) do
-- if text == _G[socket] then
-- table.insert(t, {
-- attribute = text:gsub("%-?%d+", "%%d"),
-- value = number or 1,
-- displayText = text,
-- })
-- end
-- end
-- end
end
end
end
return t;
end
local function GetItemSocketInfo(link)
local x, payload = breakLink(link)
local itemID, enchantID, gem1, gem2, gem3 = strsplit(":", payload)
if itemID == "57268" then
-- DevTools_Dump({strsplit(":", payload)})
-- local stats = GetItemStats(link)
-- for k, v in pairs(stats) do
-- print(k, v)
-- end
-- local name, id = C_Item.GetItemSpell(link)
-- print(name, id)
-- local lines = ScanTooltip(link)
-- DevTools_Dump(lines)
end
enchantID = tonumber(enchantID)
gem1 = tonumber(gem1)
gem2 = tonumber(gem2)
gem3 = tonumber(gem3)
local gems = { gem1, gem2, gem3, }
local ret = {
numSockets = 0,
numEmptySockets = 0,
actualSocketString = "",
missingSocketsString = "",
}
local sockets = {}
local itemSocketsOrderd = {}
local stats = GetItemStats(link) or {}
--DevTools_Dump(stats)
for k, v in pairs(stats) do
if k:find("SOCKET", nil, true) then
if not sockets[k] then
sockets[k] = 1;
else
sockets[k] = sockets[k] + 1;
end
ret.numSockets = ret.numSockets + 1;
end
end
if ret.numSockets > 0 then
for k, socketType in ipairs(socketOrder) do
if type(sockets[socketType]) == "number" and (sockets[socketType] > 0) then
for i = 1, sockets[socketType] do
table.insert(itemSocketsOrderd, socketFileIDs[socketType])
end
end
end
-- print(link)
-- DevTools_Dump(sockets)
-- DevTools_Dump(itemSocketsOrderd)
for i = 1, 3 do
if type(gems[i]) == "number" then
ret.actualSocketString = string.format("%s %s", ret.actualSocketString, CreateSimpleTextureMarkup(select(5, GetItemInfoInstant(gems[i])), socketIconSize, socketIconSize, 0, 0))
elseif type(itemSocketsOrderd[i]) == "number" then
ret.actualSocketString = string.format("%s %s", ret.actualSocketString, CreateSimpleTextureMarkup(itemSocketsOrderd[i], socketIconSize+2, socketIconSize+2, 0, 0))
ret.missingSocketsString = string.format("%s %s", ret.missingSocketsString, CreateSimpleTextureMarkup(itemSocketsOrderd[i], socketIconSize+2, socketIconSize+2, 0, 0))
ret.numEmptySockets = ret.numEmptySockets + 1;
end
end
end
return ret;
end
function addon.api.updatePaperdollOverlays()
if Database:GetConfig("enhancedPaperDoll") == false then
addon.api.hidePaperdollOverlays()
return
end
local minItemLevel, maxItemLevel = 0, 0;
local prof1Id, prof2Id;
local prof1, prof2 = GetProfessions()
if prof1 then
prof1Id = select(7, GetProfessionInfo(prof1))
end
if prof2 then
prof2Id = select(7, GetProfessionInfo(prof2))
end
local isEnchanter = (prof1Id == 333 or prof2Id == 333) and true or false;
--print(isEnchanter)
for frame, info in pairs(addon.paperDollSlotNames) do
if not paperdollOverlays[frame] then
local qualityOverlay = _G[frame]:CreateTexture(nil, "BORDER", nil, 6)
qualityOverlay:SetAllPoints()
qualityOverlay:SetAlpha(0.7)
-- local enchantBorder = _G[frame]:CreateTexture(nil, "BORDER", nil, 7)
-- enchantBorder:SetAtlas("Forge-ColorSwatchSelection")
-- --enchantBorder:SetTexture(130744)
-- enchantBorder:SetPoint("TOPLEFT", -2, 1)
-- enchantBorder:SetPoint("BOTTOMRIGHT", 1, -2)
-- enchantBorder:SetAlpha(0.9)
-- _G[frame].enchantBorder = enchantBorder;
-- local enchantedAnimation = _G[frame]:CreateAnimationGroup()
-- enchantedAnimation:SetLooping("BOUNCE")
-- local fadeIn = enchantedAnimation:CreateAnimation("Alpha")
-- fadeIn:SetChildKey("enchantBorder")
-- fadeIn:SetDuration(0.5)
-- fadeIn:SetFromAlpha(0)
-- fadeIn:SetToAlpha(1)
local itemLevelLabel = _G[frame]:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
local empySocketLabel = _G[frame]:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
if info.allignment == "right" then
--itemLevelLabel:SetPoint("TOPLEFT", _G[frame], "TOPRIGHT", 10, -8)
itemLevelLabel:SetPoint("BOTTOMRIGHT", -3, 3)
empySocketLabel:SetPoint("BOTTOMLEFT", _G[frame], "BOTTOMRIGHT", 8, 2)
elseif info.allignment == "left" then
--itemLevelLabel:SetPoint("TOPRIGHT", _G[frame], "TOPLEFT", -10, -8)
itemLevelLabel:SetPoint("BOTTOMLEFT", 3, 3)
empySocketLabel:SetPoint("BOTTOMRIGHT", _G[frame], "BOTTOMLEFT", -12, 2)
else
--itemLevelLabel:SetPoint("BOTTOM", _G[frame], "TOP", 0, 22)
itemLevelLabel:SetPoint("BOTTOM", 0, 3)
empySocketLabel:SetPoint("BOTTOM", _G[frame], "TOP", 0, 6)
end
paperdollOverlays[frame] = {
qualityOverlay = qualityOverlay,
itemLevelLabel = itemLevelLabel,
empySocketLabel = empySocketLabel,
--enchantBorder = enchantBorder,
--borderAnimation = enchantedAnimation,
}
end
local link = GetInventoryItemLink("player", info.slotID)
if link then
local x, payload = breakLink(link)
local itemID, enchantID, gem1, gem2, gem3 = strsplit(":", payload)
local shouldHaveEnchant
if ignoreEnchantSlotIDs[isEnchanter][info.slotID] then
--print("ignore slot")
shouldHaveEnchant = false
else
enchantID = tonumber(enchantID)
shouldHaveEnchant = true
--print("converted to number")
end
if info.slotID == 18 then
local _, _, classID = UnitClass("player")
if (classID == 2) or (classID == 5) or (classID == 7) or (classID == 8) or (classID == 9) or (classID == 11) then
shouldHaveEnchant = false;
end
end
--print(info.slotID, type(enchantID))
local socketInfo = GetItemSocketInfo(link)
local _, _, quality, itemLevel = GetItemInfo(link)
if type(itemLevel) == "number" then
if minItemLevel == 0 then
minItemLevel = itemLevel
else
if itemLevel < minItemLevel then
minItemLevel = itemLevel
end
end
if maxItemLevel == 0 then
maxItemLevel = itemLevel
else
if itemLevel > maxItemLevel then
maxItemLevel = itemLevel
end
end
end
paperdollOverlays[frame].itemLevel = itemLevel;
paperdollOverlays[frame].itemQuality = quality;
paperdollOverlays[frame].socketString = socketInfo and socketInfo.missingSocketsString or "";
if type(enchantID) == "number" then
paperdollOverlays[frame].enchanted = true
else
if shouldHaveEnchant then
paperdollOverlays[frame].enchanted = false
end
end
else
paperdollOverlays[frame].itemLevel = false;
paperdollOverlays[frame].itemQuality = false;
paperdollOverlays[frame].socketString = false;
paperdollOverlays[frame].enchanted = false;
end
end
local itemLevelGap = maxItemLevel - minItemLevel;
for f, info in pairs(paperdollOverlays) do
info.itemLevelLabel:Hide()
info.qualityOverlay:Hide()
info.empySocketLabel:Hide()
-- info.enchantBorder:Hide()
-- info.borderAnimation:Stop()
libGlow.PixelGlow_Stop(_G[f])
if (type(info.itemLevel) == "number") and (info.enchanted == false) then
-- info.enchantBorder:Show()
-- info.borderAnimation:Play()
libGlow.PixelGlow_Start(_G[f])
--libGlow.AutoCastGlow_Start(_G[f])
--libGlow.ButtonGlow_Start(_G[f])
end
if type(info.socketString) == "string" then
info.empySocketLabel:SetText(info.socketString)
info.empySocketLabel:Show()
end
if type(info.itemLevel) == "number" then
local r, g, b = addon.api.getcolourGradientFromPercent(((info.itemLevel - minItemLevel) / itemLevelGap) * 100)
info.itemLevelLabel:SetText(info.itemLevel)
info.itemLevelLabel:SetTextColor(r,g,b,1)
info.itemLevelLabel:Show()
end
if type(info.itemQuality) == "number" and info.itemQuality > 1 then
info.qualityOverlay:SetAtlas(addon.itemQualityAtlas_Overlay[info.itemQuality])
info.qualityOverlay:Show()
end
end
end
function addon.api.hidePaperdollOverlays()
for f, info in pairs(paperdollOverlays) do
info.itemLevelLabel:Hide()
info.qualityOverlay:Hide()
info.empySocketLabel:Hide()
-- info.enchantBorder:Hide()
-- info.borderAnimation:Stop()
libGlow.PixelGlow_Stop(_G[f])
--libGlow.AutoCastGlow_Stop(_G[f])
--libGlow.ButtonGlow_Stop(_G[f])
end
end
function addon.api.getNineSliceTooltipBorder(borderOffset)
return {
["TopRightCorner"] = { atlas = "Tooltip-NineSlice-CornerTopRight", x = borderOffset, y = borderOffset },
["TopLeftCorner"] = { atlas = "Tooltip-NineSlice-CornerTopLeft", x = -borderOffset, y = borderOffset },
["BottomLeftCorner"] = { atlas = "Tooltip-NineSlice-CornerBottomLeft", x = -borderOffset, y = -borderOffset },
["BottomRightCorner"] = { atlas = "Tooltip-NineSlice-CornerBottomRight", x = borderOffset, y = -borderOffset },
["TopEdge"] = { atlas = "_Tooltip-NineSlice-EdgeTop" },
["BottomEdge"] = { atlas = "_Tooltip-NineSlice-EdgeBottom" },
["LeftEdge"] = { atlas = "!Tooltip-NineSlice-EdgeLeft" },
["RightEdge"] = { atlas = "!Tooltip-NineSlice-EdgeRight" },
["Center"] = { layer = "BACKGROUND", atlas = "Tooltip-Glues-NineSlice-Center", x = -4, y = 4, x1 = 4, y1 = -4 },
}
end
function addon.api.getcolourGradientFromPercent(percent, reverse)
if reverse then
local g = (percent > 50 and 1 - 2 * (percent - 50) / 100.0 or 1.0);
local r = (percent > 50 and 1.0 or 2 * percent / 100.0);
local b = 0.0;
return r, g, b;
else
local r = (percent > 50 and 1 - 2 * (percent - 50) / 100.0 or 1.0);
local g = (percent > 50 and 1.0 or 2 * percent / 100.0);
local b = 0.0;
return r, g, b;
end
end
function addon.LogDebugMessage(debugType, debugMessage, debugTooltip)
if not addon.debugMessages then
addon.debugMessages = {}
end
if GuildbookUI and Database.db.debug then
if debugTooltip then
table.insert(addon.debugMessages, {
debugTypeID = debugTypeIDs[debugType] or 1,
label = string.format("[%s] %s", date("%T"), debugMessage),
atlas = debugTypeIcons[debugType],
onMouseEnter = function()
GameTooltip:SetOwner(GuildbookUI, "ANCHOR_TOPLEFT")
GameTooltip:AddDoubleLine("Version", debugTooltip.version)
-- for k, v in ipairs(debugTooltip.payload) do
-- GameTooltip:AddDoubleLine(k, v)
-- end
for k, v in pairs(debugTooltip.payload) do
GameTooltip:AddDoubleLine(k, v)
end
if type(debugTooltip.payload.data) == "table" then
-- for k, v in ipairs(debugTooltip.payload.data) do
-- GameTooltip:AddDoubleLine(k, v)
-- end
for k, v in pairs(debugTooltip.payload.data) do
GameTooltip:AddDoubleLine(k, v)
end
end
GameTooltip:Show()
end,
onMouseDown = function()
DevTools_Dump(debugTooltip)
end,
})
else
table.insert(addon.debugMessages, {
debugTypeID = debugTypeIDs[debugType] or 1,
label = string.format("[%s] %s", date("%T"), debugMessage),
atlas = debugTypeIcons[debugType],
})
end
addon:TriggerEvent("LogDebugMessage")
end
end
function addon.api.getTradeskillItemDataFromID(itemID)
for k, v in ipairs(addon.itemData) do
if v.itemID == itemID then
return v;
end
end
return false;
end
function addon.api.getTradeskillItemsUsingReagentItemID(itemID, prof1, prof2)
local t = {}
for k, v in ipairs(addon.itemData) do
for id, count in pairs(v.reagents) do
if id == itemID then
if prof1 == nil and prof2 == nil then
if not t[v.tradeskillID] then
t[v.tradeskillID] = {}
end
table.insert(t[v.tradeskillID], v)
else
if prof1 and (v.tradeskillID == prof1) then
if not t[v.tradeskillID] then
t[v.tradeskillID] = {}
end
table.insert(t[v.tradeskillID], v)
end
if prof2 and (v.tradeskillID == prof2) then
if not t[v.tradeskillID] then
t[v.tradeskillID] = {}
end
table.insert(t[v.tradeskillID], v)
end
end
end
end
end
return t;
end
--taken from blizz to use for classic
function addon.api.extractLink(text)
-- linkType: |H([^:]*): matches everything that's not a colon, up to the first colon.
-- linkOptions: ([^|]*)|h matches everything that's not a |, up to the first |h.
-- displayText: (.*)|h matches everything up to the second |h.
-- Ex: |cffffffff|Htype:a:b:c:d|htext|h|r becomes type, a:b:c:d, text
return string.match(text, [[|H([^:]*):([^|]*)|h(.*)|h]]);
end
function addon.api.makeTableUnique(t)
local temp, ret = {}, {}
for k, v in ipairs(t) do
temp[v] = true
end
for k, v in pairs(temp) do
table.insert(ret, k)
end
return ret;
end
function addon.api.trimTable(tab, num, reverse)
if type(tab) == "table" then
local t = {}
if reverse then
for i = #tab, (#tab - num), -1 do
table.insert(t, tab[i])
end
else
for i = 1, num do
table.insert(t, tab[i])
end
end
tab = nil;
return t;
end
end
function addon.api.trimNumber(num)
if type(num) == 'number' then
local trimmed = string.format("%.1f", num)
return tonumber(trimmed)
else
return 1
end
end
function addon.api.characterIsMine(name)
if Database.db.myCharacters[name] ~= nil then
return true;
end
return false;
end
function addon.api.getGuildRanks()
local ranks = {}
for i = 1, GuildControlGetNumRanks() do
local rankName = GuildControlGetRankName(i)
table.insert(ranks, {
rankName = rankName,
rankIndex = i-1,
})
end
return ranks
end
function addon.api.scanForTradeskillSpec()
local t = {}
for i = 1, GetNumSpellTabs() do
local offset, numSlots = select(3, GetSpellTabInfo(i))
for j = offset+1, offset+numSlots do
--local start, duration, enabled, modRate = GetSpellCooldown(j, BOOKTYPE_SPELL)
--local spellLink, _ = GetSpellLink(j, BOOKTYPE_SPELL)
local _, spellID = GetSpellBookItemInfo(j, BOOKTYPE_SPELL)
if Tradeskills.SpecializationSpellsIDs[spellID] then
table.insert(t, {
tradeskillID = Tradeskills.SpecializationSpellsIDs[spellID],
spellID = spellID,
})
end
end
end
return t;
end
function addon.api.wrath.getPlayerEquipment()
local sets = C_EquipmentSet.GetEquipmentSetIDs();
local equipment = {
sets = {},
current = {},
};
for k, v in ipairs(sets) do
local name, iconFileID, setID, isEquipped, numItems, numEquipped, numInInventory, numLost, numIgnored = C_EquipmentSet.GetEquipmentSetInfo(v)
local setItemIDs = C_EquipmentSet.GetItemIDs(setID)
equipment.sets[name] = setItemIDs;
end
--lets grab the current gear
local t = {}
for k, v in ipairs(addon.data.inventorySlots) do
local link = GetInventoryItemLink('player', GetInventorySlotInfo(v.slot)) or false
if link ~= nil then
t[v.slot] = link;
end
end
equipment.current = t;
return equipment;
end
function addon.api.getPlayerEquipmentCurrent()
local t = {}
for k, v in ipairs(addon.data.inventorySlots) do
local link = GetInventoryItemLink('player', GetInventorySlotInfo(v.slot)) or false
if link ~= nil then
t[v.slot] = link;
end
end
return t;
end
function addon.api.getPlayerItemLevel()
local itemLevel, itemCount = 0, 0
for k, v in ipairs(addon.data.inventorySlots) do
local link = GetInventoryItemLink('player', GetInventorySlotInfo(v.slot)) or false
if link then
local _, _, _, ilvl = GetItemInfo(link)
if not ilvl then ilvl = 0 end
itemLevel = itemLevel + ilvl
itemCount = itemCount + 1
end
end
-- due to an error with LibSerialize which is now fixed we make sure we return a number
if math.floor(itemLevel/itemCount) > 0 then
return addon.api.trimNumber(itemLevel/itemCount)
else
return 0
end
end
function addon.api.getPlayerSkillLevels()
local skills = {}
for s = 1, GetNumSkillLines() do
local skill, _, _, level, _, _, _, _, _, _, _, _, _ = GetSkillLineInfo(s)
if skill and (type(level) == "number") then
local tradeskillId = Tradeskills:GetTradeskillIDFromLocale(skill)
if tradeskillId then
skills[tradeskillId] = level
end
end
end
return skills;
end
function addon.api.cata.getProfessions()
local t = {}
for k, prof in pairs({GetProfessions()}) do
if type(prof) == "number" then
local name, icon, skillLevel, maxSkillLevel, numAbilities, spelloffset, skillLine = GetProfessionInfo(prof)
if Tradeskills:IsTradeskill(nil, skillLine) then
t[skillLine] = skillLevel;
end
end
end
--addon.LogDebugMessage("tradeskills", "function [addon.api.cata.getProfessions]", {version = -1, payload = t})
return t;
end
function addon.api.isInGuild()
if IsInGuild() and GetGuildInfo("player") then
return true
end
return false
end
function addon.api.getGuildRosterIndex(nameOrGUID)
if IsInGuild() and GetGuildInfo("player") then
GuildRoster()
local totalMembers, onlineMember, _ = GetNumGuildMembers()
for i = 1, totalMembers do
local name, rankName, rankIndex, level, _, zone, publicNote, officerNote, isOnline, status, class, _, _, _, _, _, guid = GetGuildRosterInfo(i)
if nameOrGUID == name or nameOrGUID == guid then
return i
end
end
end
end
function addon.api.getPlayerAlts(main)
if type(main) == "string" and main ~= "" then
local alts = {}
if addon.characters and addon.characters then
for name, character in pairs(addon.characters) do
if character.data.mainCharacter == main then
table.insert(alts, name)
end
end
end
return alts;
end
return {}
end
function addon.api.scanPlayerContainers(includeBanks)
local copper = GetMoney()
local containers = {
bags = {
slotsUsed = 0,
slotsFree = 0,
items = {},
},
bank = {
slotsUsed = 0,
slotsFree = 0,
items = {},
},
copper = copper,
}
-- player bags
for bag = 0, 4 do
local numSlots;
if C_Container then
numSlots = C_Container.GetContainerNumSlots(bag);
else
numSlots = GetContainerNumSlots(bag);
end
local slotsUsed = 0;
for slot = 1, numSlots do
local itemID, stackCount;
--make this work for both version although 1.14.4 is only maybe a few weeks away
if C_Container then
local containerInfo = C_Container.GetContainerItemInfo(bag, slot)
if containerInfo then
itemID = containerInfo.itemID;
stackCount = containerInfo.stackCount;
end
else
local _, count, _, _, _, _, link, _, _, id = GetContainerItemInfo(bag, slot)
itemID = id;
stackCount = count;
end
if (type(itemID) == "number") and (type(stackCount) == "number") then
table.insert(containers.bags.items, {
id = itemID,
count = stackCount,
})
slotsUsed = slotsUsed + 1;
end
end
containers.bags.slotsUsed = containers.bags.slotsUsed + slotsUsed;
containers.bags.slotsFree = containers.bags.slotsFree + (numSlots - slotsUsed);
end
if includeBanks then
-- main bank
local bankBagId = -1
local numSlots;
if C_Container then
numSlots = C_Container.GetContainerNumSlots(bankBagId);
else
numSlots = GetContainerNumSlots(bankBagId);
end
local slotsUsed = 0;
for slot = 1, numSlots do
local itemID, stackCount;
if C_Container then
local containerInfo = C_Container.GetContainerItemInfo(bankBagId, slot)
if containerInfo then
itemID = containerInfo.itemID;
stackCount = containerInfo.stackCount;
end
else
local _, count, _, _, _, _, link, _, _, id = GetContainerItemInfo(bankBagId, slot)
itemID = id;
stackCount = count;
end