-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataSystems.lua
More file actions
2597 lines (2426 loc) · 83.2 KB
/
DataSystems.lua
File metadata and controls
2597 lines (2426 loc) · 83.2 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 AceAddon = LibStub("AceAddon-3.0")
local LDB = LibStub("LibDataBroker-1.1", true)
local LibRangeCheck = LibStub("LibRangeCheck-3.0", true)
local addon = AceAddon and AceAddon:GetAddon("SimpleUnitFrames", true)
if not addon then
return
end
local core = addon._core or {}
local defaults = core.defaults or {}
local DEFAULT_TEXTURE = core.DEFAULT_TEXTURE or "Interface\\TargetingFrame\\UI-StatusBar"
local DATATEXT_SLOT_ORDER = core.DATATEXT_SLOT_ORDER or { "left", "center", "right" }
local DATATEXT_SLOT_ORDER_FIVE = core.DATATEXT_SLOT_ORDER_FIVE or { "farLeft", "left", "center", "right", "farRight" }
local DATATEXT_SLOT_ORDER_SEVEN = core.DATATEXT_SLOT_ORDER_SEVEN or { "outerLeft", "farLeft", "left", "center", "right", "farRight", "outerRight" }
local DATATEXT_DEFAULT_SOURCES = {
outerLeft = "Spec",
farLeft = "Latency",
left = "FPS",
center = "Time",
right = "Memory",
farRight = "Gold",
outerRight = "System",
}
local DATATEXT_ALL_SLOT_ORDER = DATATEXT_SLOT_ORDER_SEVEN
local FormatCompactValue = core.FormatCompactValue
local SetStatusBarTexturePreserveLayer = core.SetStatusBarTexturePreserveLayer
local GetWatchedFactionInfoCompat = core.GetWatchedFactionInfoCompat
local THEME = addon.GetSUFTheme and addon:GetSUFTheme() or {}
if type(FormatCompactValue) ~= "function" then
FormatCompactValue = function(value) return tostring(value or 0) end
end
local function GetBackdropTheme(kind)
local map = THEME and THEME.backdrop
if type(map) ~= "table" then
return nil
end
return map[kind or "panel"] or map.panel
end
local function GetDataBarsTheme()
return (THEME and THEME.databars) or {}
end
local function IsEditModePosition(modeValue)
local mode = tostring(modeValue or "ANCHOR")
return mode == "EDIT_MODE" or mode == "EDITMODE" or mode == "EDIT"
end
local function IsShiftDragRequested()
return IsShiftKeyDown and IsShiftKeyDown() or false
end
local function IsLeftMouseDown()
if type(IsMouseButtonDown) == "function" then
local ok, result = pcall(IsMouseButtonDown, "LeftButton")
if ok then
return result
end
ok, result = pcall(IsMouseButtonDown, 1)
if ok then
return result
end
ok, result = pcall(IsMouseButtonDown)
if ok then
return result
end
end
if type(GetMouseButtonState) == "function" then
local ok, result = pcall(GetMouseButtonState, "LeftButton")
if ok then
return result
end
end
return false
end
local function ShouldShowDragHandle(isMouseOver)
return isMouseOver and IsShiftDragRequested() and IsLeftMouseDown()
end
local function IsDataBarsDragContextActive(context)
if InCombatLockdown and InCombatLockdown() then
return false
end
return IsShiftDragRequested()
end
local function IsDataTextDragContextActive(context)
if InCombatLockdown and InCombatLockdown() then
return false
end
return IsShiftDragRequested()
end
local function ClampDataTextSlotCount(slotCount)
local normalized = math.floor((tonumber(slotCount) or 3) + 0.5)
if normalized < 3 then
return 3
end
if normalized >= 7 then
return 7
end
if normalized >= 5 then
return 5
end
return 3
end
local function GetActiveDataTextSlotOrder(dataTextConfig)
local panelCfg = dataTextConfig and dataTextConfig.panel
if panelCfg then
panelCfg.slotCount = ClampDataTextSlotCount(panelCfg.slotCount)
if panelCfg.slotCount >= 7 then
return DATATEXT_SLOT_ORDER_SEVEN
end
if panelCfg.slotCount >= 5 then
return DATATEXT_SLOT_ORDER_FIVE
end
end
return DATATEXT_SLOT_ORDER
end
local function GetMaxDataTextPanelWidth()
local screenWidth = UIParent and UIParent.GetWidth and UIParent:GetWidth() or 1920
screenWidth = tonumber(screenWidth) or 1920
return math.max(280, math.floor(screenWidth + 0.5))
end
local function NormalizeLDBDisplayMode(mode)
local normalized = tostring(mode or "AUTO")
if normalized == "TEXT" or normalized == "ICON" or normalized == "ICON_TEXT" then
return normalized
end
return "AUTO"
end
local function GetDataTextSlotDisplayMode(dataTextConfig, slot)
local slotDisplay = dataTextConfig and dataTextConfig.slotDisplay
if type(slotDisplay) ~= "table" then
return "AUTO"
end
return NormalizeLDBDisplayMode(slotDisplay[slot])
end
local function GetDataTextButtonMetrics(panelWidth, panelHeight, slotCount)
local count = math.max(1, tonumber(slotCount) or 3)
local usableWidth = math.max(120, (tonumber(panelWidth) or 520) - 16)
local buttonGap = (count >= 5) and 4 or 8
local buttonWidth = math.floor((usableWidth - (buttonGap * (count - 1))) / count)
if buttonWidth < 74 then
buttonWidth = math.floor(usableWidth / count)
buttonGap = 0
end
local buttonHeight = math.max(16, (tonumber(panelHeight) or 20) - 2)
return buttonWidth, buttonHeight, buttonGap
end
local function GetDataTextButtonOffset(index, slotCount, buttonWidth, buttonGap)
local count = math.max(1, tonumber(slotCount) or 1)
if count <= 1 then
return 0
end
local span = ((count - 1) * (buttonWidth + buttonGap))
return math.floor((-span / 2) + ((index - 1) * (buttonWidth + buttonGap)) + 0.5)
end
local function ForwardDragStartFromChild(root)
local dragStart = root and root.GetScript and root:GetScript("OnDragStart")
if dragStart then
dragStart(root)
end
end
local function ForwardDragStopFromChild(root)
local dragStop = root and root.GetScript and root:GetScript("OnDragStop")
if dragStop then
dragStop(root)
end
end
local function ApplyFadeState(frame, fadeCfg, isHovering)
if not frame then
return
end
if not (fadeCfg and fadeCfg.enabled == true) then
frame._sufFadeTarget = 1
frame._sufFadeShow = nil
frame:SetAlpha(1)
return
end
local inCombat = InCombatLockdown and InCombatLockdown() or false
local showOnHover = fadeCfg.showOnHover ~= false
local showInCombat = fadeCfg.showInCombat ~= false
local shouldShow = (showInCombat and inCombat) or (showOnHover and isHovering)
local targetAlpha = shouldShow and 1 or (tonumber(fadeCfg.fadeOutAlpha) or 0)
local duration = shouldShow and (tonumber(fadeCfg.fadeInDuration) or 0.2) or (tonumber(fadeCfg.fadeOutDuration) or 0.3)
local delay = shouldShow and 0 or (tonumber(fadeCfg.fadeOutDelay) or 0)
if frame._sufFadeTarget == targetAlpha and frame._sufFadeShow == shouldShow then
return
end
frame._sufFadeTarget = targetAlpha
frame._sufFadeShow = shouldShow
if UIFrameFadeIn and UIFrameFadeOut then
if shouldShow then
UIFrameFadeIn(frame, duration, frame:GetAlpha(), targetAlpha)
else
UIFrameFadeOut(frame, duration, frame:GetAlpha(), targetAlpha, delay)
end
else
frame:SetAlpha(targetAlpha)
end
end
if type(SetStatusBarTexturePreserveLayer) ~= "function" then
SetStatusBarTexturePreserveLayer = function(statusBar, texture)
if statusBar and statusBar.SetStatusBarTexture then
statusBar:SetStatusBarTexture(texture)
end
end
end
if type(GetWatchedFactionInfoCompat) ~= "function" then
GetWatchedFactionInfoCompat = function()
if type(GetWatchedFactionInfo) == "function" then
return GetWatchedFactionInfo()
end
return nil
end
end
local function GetQuestLogXPRewardTotal()
if not C_QuestLog or not C_QuestLog.GetNumQuestLogEntries or not C_QuestLog.GetInfo or not GetQuestLogRewardXP then
return 0
end
local totalXP = 0
local numEntries = tonumber((C_QuestLog.GetNumQuestLogEntries())) or 0
for i = 1, numEntries do
local info = C_QuestLog.GetInfo(i)
if info and not info.isHeader and not info.isHidden then
local questRef = info.questID or i
local questXP = tonumber((GetQuestLogRewardXP(questRef))) or tonumber((GetQuestLogRewardXP(i))) or 0
if questXP > 0 then
totalXP = totalXP + questXP
end
end
end
return totalXP
end
local function GetQuestLogEntryCounts()
if C_QuestLog and C_QuestLog.GetNumQuestLogEntries then
local numEntries, numQuests = C_QuestLog.GetNumQuestLogEntries()
return tonumber(numEntries) or 0, tonumber(numQuests) or 0
elseif GetNumQuestLogEntries then
local numEntries, numQuests = GetNumQuestLogEntries()
return tonumber(numEntries) or 0, tonumber(numQuests) or 0
end
return 0, 0
end
local function GetQuestLogMaxAcceptable()
if C_QuestLog and C_QuestLog.GetMaxNumQuestsCanAccept then
local base = tonumber(C_QuestLog.GetMaxNumQuestsCanAccept()) or 25
return math.min(base + 10, 35)
end
return 25
end
local function BuildQuestDataTextSummary()
local summary = {
numEntries = 0,
numQuests = 0,
maxQuests = GetQuestLogMaxAcceptable(),
totalXP = 0,
completedXP = 0,
totalMoney = 0,
lines = {},
}
local numEntries, numQuests = GetQuestLogEntryCounts()
summary.numEntries = numEntries
summary.numQuests = numQuests
if not (C_QuestLog and C_QuestLog.GetInfo) then
return summary
end
local canTurnIn = C_QuestLog.ReadyForTurnIn
for i = 1, numEntries do
local info = C_QuestLog.GetInfo(i)
if info and not info.isHeader and not info.isHidden then
local questRef = info.questID or i
local questXP = tonumber(GetQuestLogRewardXP and GetQuestLogRewardXP(questRef) or 0) or tonumber(GetQuestLogRewardXP and GetQuestLogRewardXP(i) or 0) or 0
local money = tonumber(GetQuestLogRewardMoney and GetQuestLogRewardMoney(questRef) or 0) or tonumber(GetQuestLogRewardMoney and GetQuestLogRewardMoney(i) or 0) or 0
local complete = (info.isComplete and info.isComplete > 0) or (canTurnIn and info.questID and canTurnIn(info.questID)) or false
summary.totalXP = summary.totalXP + questXP
summary.totalMoney = summary.totalMoney + money
if complete then
summary.completedXP = summary.completedXP + questXP
end
summary.lines[#summary.lines + 1] = {
title = tostring(info.title or UNKNOWN),
complete = complete and true or false,
xp = questXP,
}
end
end
return summary
end
local function GetBagFreeSlots()
local totalFree = 0
local totalSlots = 0
local firstBag = (BACKPACK_CONTAINER ~= nil) and BACKPACK_CONTAINER or 0
local lastBag = (NUM_BAG_SLOTS ~= nil) and NUM_BAG_SLOTS or 4
for bag = firstBag, lastBag do
local freeSlots, bagSlots
if C_Container and C_Container.GetContainerNumFreeSlots then
freeSlots = C_Container.GetContainerNumFreeSlots(bag)
elseif GetContainerNumFreeSlots then
freeSlots = GetContainerNumFreeSlots(bag)
end
if C_Container and C_Container.GetContainerNumSlots then
bagSlots = C_Container.GetContainerNumSlots(bag)
elseif GetContainerNumSlots then
bagSlots = GetContainerNumSlots(bag)
end
totalFree = totalFree + (tonumber(freeSlots) or 0)
totalSlots = totalSlots + (tonumber(bagSlots) or 0)
end
return totalFree, totalSlots
end
local function GetAverageDurabilityPercent()
if not (GetInventoryItemDurability and GetInventoryItemMaxDurability) then
return nil, nil, nil
end
local currentTotal = 0
local maxTotal = 0
local broken = 0
for slot = 1, 17 do
local current = tonumber(GetInventoryItemDurability(slot))
local max = tonumber(GetInventoryItemMaxDurability(slot))
if current and max and max > 0 then
currentTotal = currentTotal + current
maxTotal = maxTotal + max
if current <= 0 then
broken = broken + 1
end
end
end
if maxTotal <= 0 then
return nil, nil, nil
end
return (currentTotal / maxTotal) * 100, broken, maxTotal
end
local function GetPlayerCoordsPercent()
if not (C_Map and C_Map.GetBestMapForUnit and C_Map.GetPlayerMapPosition) then
return nil, nil
end
local mapID = C_Map.GetBestMapForUnit("player")
if not mapID then
return nil, nil
end
local pos = C_Map.GetPlayerMapPosition(mapID, "player")
if not pos or not pos.GetXY then
return nil, nil
end
local x, y = pos:GetXY()
if not (x and y) then
return nil, nil
end
return x * 100, y * 100
end
local function GetLatestMailSenders()
if not GetLatestThreeSenders then
return {}
end
local senders = { GetLatestThreeSenders() }
local out = {}
for i = 1, #senders do
local name = senders[i]
if type(name) == "string" and name ~= "" then
out[#out + 1] = name
end
end
return out
end
local function ShouldShowPetXPBar()
if not (HasPetUI and HasPetUI()) then
return false
end
if not (UnitExists and UnitExists("pet")) then
return false
end
if not (GetPetExperience and UnitLevel) then
return false
end
if IsLevelAtEffectiveMaxLevel then
local petLevel = tonumber(UnitLevel("pet")) or 0
if petLevel > 0 and IsLevelAtEffectiveMaxLevel(petLevel) then
return false
end
end
local _, maxXP = GetPetExperience()
return (tonumber(maxXP) or 0) > 0
end
local function GetLatencyPair()
if not GetNetStats then
return 0, 0
end
local _, _, home, world = GetNetStats()
return tonumber(home) or 0, tonumber(world) or 0
end
local function FormatMemoryKB(kb)
kb = tonumber(kb) or 0
if kb >= 1024 then
return string.format("%.2f MB", kb / 1024)
end
return string.format("%d KB", math.floor(kb + 0.5))
end
local function GetTopAddonMemoryUsage(limit)
local top = {}
local maxEntries = math.max(1, tonumber(limit) or 8)
if not (UpdateAddOnMemoryUsage and GetAddOnMemoryUsage and C_AddOns and C_AddOns.GetNumAddOns and C_AddOns.GetAddOnInfo and C_AddOns.IsAddOnLoaded) then
return top, 0
end
UpdateAddOnMemoryUsage()
local totalKB = 0
local numAddons = tonumber(C_AddOns.GetNumAddOns()) or 0
for i = 1, numAddons do
local loaded = C_AddOns.IsAddOnLoaded(i)
if loaded then
local name, title = C_AddOns.GetAddOnInfo(i)
local memKB = tonumber(GetAddOnMemoryUsage(i)) or 0
totalKB = totalKB + memKB
top[#top + 1] = {
name = tostring(title or name or ("Addon " .. i)),
memKB = memKB,
}
end
end
table.sort(top, function(a, b)
return (a.memKB or 0) > (b.memKB or 0)
end)
while #top > maxEntries do
table.remove(top)
end
return top, totalKB
end
local function GetPlayerMovementSpeedPercent()
if not GetUnitSpeed then
return 0
end
local _, runSpeed, flightSpeed, swimSpeed = GetUnitSpeed("player")
local speed = tonumber(runSpeed) or 0
local isSwimming = IsSwimming and IsSwimming()
local isFlying = IsFlying and IsFlying()
if isSwimming then
speed = tonumber(swimSpeed) or speed
elseif isFlying then
speed = tonumber(flightSpeed) or speed
end
if C_PlayerInfo and C_PlayerInfo.GetGlidingInfo then
local isGliding, _, forwardSpeed = C_PlayerInfo.GetGlidingInfo()
if isGliding then
speed = tonumber(forwardSpeed) or speed
end
end
local base = tonumber(BASE_MOVEMENT_SPEED) or 7
if base <= 0 then
base = 7
end
return (speed / base) * 100
end
local function IsSecretValue(value)
return type(issecretvalue) == "function" and issecretvalue(value)
end
local function SafeNumber(value, fallback)
if IsSecretValue(value) then
return fallback
end
local numericValue = tonumber(value)
if numericValue == nil then
return fallback
end
return numericValue
end
local function SafeText(value, fallback)
if IsSecretValue(value) then
return fallback
end
if value == nil then
return fallback
end
return tostring(value)
end
local function TruncateLabel(text, maxChars)
local normalized = SafeText(text, "")
local maxLength = math.max(4, tonumber(maxChars) or 14)
if string.len(normalized) <= maxLength then
return normalized
end
return normalized:sub(1, maxLength - 3) .. "..."
end
local function GetReactionLabel(reaction)
local reactionIndex = SafeNumber(reaction, nil)
if reactionIndex then
local label = _G["FACTION_STANDING_LABEL" .. reactionIndex] or _G["FACTION_STANDING_LABEL" .. reactionIndex .. "_FEMALE"]
if label and label ~= "" then
return label
end
end
return SafeText(reaction, "?")
end
local function IsFactionParagonForPlayer(factionID)
if not factionID or not C_Reputation then
return false
end
if C_Reputation.IsFactionParagonForCurrentPlayer then
local ok, result = pcall(C_Reputation.IsFactionParagonForCurrentPlayer, factionID)
if ok then
return result and true or false
end
end
if C_Reputation.IsFactionParagon then
local ok, result = pcall(C_Reputation.IsFactionParagon, factionID)
if ok then
return result and true or false
end
end
return false
end
local function FormatCurrencyAmountWithCap(currencyData)
local quantity = SafeNumber(currencyData and currencyData.quantity, 0) or 0
local maxQuantity = SafeNumber(currencyData and currencyData.maxQuantity, 0) or 0
if maxQuantity > 0 then
return ("%s/%s"):format(FormatCompactValue(quantity), FormatCompactValue(maxQuantity))
end
return FormatCompactValue(quantity)
end
local function BuildCurrencyEntryFromListInfo(info)
if type(info) ~= "table" then
return nil
end
if info.isHeader or info.isTypeUnused then
return nil
end
local quantity = SafeNumber(info.quantity, nil)
local currencyName = SafeText(info.name, nil)
if not currencyName or quantity == nil then
return nil
end
return {
currencyID = SafeNumber(info.currencyID, nil),
name = currencyName,
quantity = quantity,
iconFileID = info.iconFileID,
maxQuantity = SafeNumber(info.maxQuantity, 0) or 0,
maxWeeklyQuantity = SafeNumber(info.maxWeeklyQuantity, 0) or 0,
quantityEarnedThisWeek = SafeNumber(info.quantityEarnedThisWeek, 0) or 0,
canEarnPerWeek = info.canEarnPerWeek == true,
isShowInBackpack = info.isShowInBackpack == true,
isDiscovered = info.isDiscovered ~= false,
}
end
local function CollectTrackedCurrencies(maxCount)
local output = {}
local limit = math.max(1, tonumber(maxCount) or 8)
local allEntries = {}
if C_CurrencyInfo and C_CurrencyInfo.GetCurrencyListSize and C_CurrencyInfo.GetCurrencyListInfo then
local size = SafeNumber(C_CurrencyInfo.GetCurrencyListSize(), 0) or 0
for index = 1, size do
local info = C_CurrencyInfo.GetCurrencyListInfo(index)
local entry = BuildCurrencyEntryFromListInfo(info)
if entry and entry.isDiscovered then
if entry.currencyID and C_CurrencyInfo.IsCurrencyTracked then
local ok, tracked = pcall(C_CurrencyInfo.IsCurrencyTracked, entry.currencyID)
entry.isTracked = ok and tracked and true or false
else
entry.isTracked = false
end
allEntries[#allEntries + 1] = entry
end
end
end
if #allEntries == 0 then
return output
end
local added = {}
local function AddEntryIfMatch(entry)
if #output >= limit or type(entry) ~= "table" then
return
end
local uniqueKey = SafeText(entry.currencyID, nil) or SafeText(entry.name, nil)
if uniqueKey and added[uniqueKey] then
return
end
if uniqueKey then
added[uniqueKey] = true
end
output[#output + 1] = entry
end
for index = 1, #allEntries do
local entry = allEntries[index]
if entry.isShowInBackpack then
AddEntryIfMatch(entry)
end
end
for index = 1, #allEntries do
local entry = allEntries[index]
if entry.isTracked then
AddEntryIfMatch(entry)
end
end
for index = 1, #allEntries do
if #output >= limit then
break
end
AddEntryIfMatch(allEntries[index])
end
return output
end
local function GetWatchedReputationData()
local watchedFactionData
if C_Reputation and C_Reputation.GetWatchedFactionData then
local ok, data = pcall(C_Reputation.GetWatchedFactionData)
if ok and type(data) == "table" and data.name and SafeNumber(data.factionID, 0) ~= 0 then
watchedFactionData = data
end
end
local factionName, reaction, minRep, maxRep, curRep, factionID
if watchedFactionData then
factionName = SafeText(watchedFactionData.name, nil)
reaction = SafeNumber(watchedFactionData.reaction, nil)
minRep = SafeNumber(watchedFactionData.currentReactionThreshold, 0) or 0
maxRep = SafeNumber(watchedFactionData.nextReactionThreshold, minRep + 1) or (minRep + 1)
curRep = SafeNumber(watchedFactionData.currentStanding, minRep) or minRep
factionID = SafeNumber(watchedFactionData.factionID, nil)
else
factionName, reaction, minRep, maxRep, curRep, factionID = GetWatchedFactionInfoCompat()
factionName = SafeText(factionName, nil)
reaction = SafeNumber(reaction, nil)
minRep = SafeNumber(minRep, 0) or 0
maxRep = SafeNumber(maxRep, minRep + 1) or (minRep + 1)
curRep = SafeNumber(curRep, minRep) or minRep
factionID = SafeNumber(factionID, nil)
end
if not factionName or factionName == "" then
return nil
end
if maxRep <= minRep then
maxRep = minRep + 1
end
if curRep < minRep then
curRep = minRep
elseif curRep > maxRep then
curRep = maxRep
end
local reputationData = {
kind = "standard",
name = factionName,
factionID = factionID,
reaction = reaction,
rankText = GetReactionLabel(reaction),
minRep = minRep,
maxRep = maxRep,
curRep = curRep,
isAccountWide = false,
isMajorAtMaxRenown = false,
hideProgressInTooltip = false,
paragonRewardPending = false,
}
if factionID and C_Reputation and C_Reputation.IsAccountWideReputation then
local ok, isAccountWide = pcall(C_Reputation.IsAccountWideReputation, factionID)
reputationData.isAccountWide = ok and isAccountWide and true or false
end
if factionID and C_Reputation and C_Reputation.IsMajorFaction and C_MajorFactions and C_MajorFactions.GetMajorFactionData then
local ok, isMajor = pcall(C_Reputation.IsMajorFaction, factionID)
if ok and isMajor then
local okMajorData, majorFactionData = pcall(C_MajorFactions.GetMajorFactionData, factionID)
if okMajorData and type(majorFactionData) == "table" then
local renownLevel = SafeNumber(majorFactionData.renownLevel, 0) or 0
local renownThreshold = SafeNumber(majorFactionData.renownLevelThreshold, 1) or 1
local renownEarned = SafeNumber(majorFactionData.renownReputationEarned, 0) or 0
reputationData.kind = "major"
reputationData.rankText = ("Renown %d"):format(math.max(0, math.floor(renownLevel + 0.5)))
reputationData.reaction = 10
reputationData.minRep = 0
reputationData.maxRep = math.max(1, renownThreshold)
reputationData.curRep = math.max(0, renownEarned)
if C_MajorFactions.HasMaximumRenown then
local okMax, hasMaximumRenown = pcall(C_MajorFactions.HasMaximumRenown, factionID)
if okMax and hasMaximumRenown then
reputationData.isMajorAtMaxRenown = true
reputationData.curRep = reputationData.maxRep
reputationData.hideProgressInTooltip = true
end
end
end
end
end
if reputationData.kind == "standard" and factionID and C_GossipInfo and C_GossipInfo.GetFriendshipReputation then
local ok, friendshipData = pcall(C_GossipInfo.GetFriendshipReputation, factionID)
if ok and type(friendshipData) == "table" then
local friendshipFactionID = SafeNumber(friendshipData.friendshipFactionID, 0) or 0
if friendshipFactionID > 0 then
reputationData.kind = "friendship"
reputationData.rankText = SafeText(friendshipData.reaction, reputationData.rankText)
local friendMin = SafeNumber(friendshipData.reactionThreshold, 0) or 0
local friendNext = SafeNumber(friendshipData.nextThreshold, nil)
local friendStanding = SafeNumber(friendshipData.standing, friendMin) or friendMin
if friendNext and friendNext > friendMin then
reputationData.minRep = friendMin
reputationData.maxRep = friendNext
reputationData.curRep = friendStanding
else
reputationData.minRep = 0
reputationData.maxRep = 1
reputationData.curRep = 1
reputationData.hideProgressInTooltip = true
end
end
end
end
if factionID and IsFactionParagonForPlayer(factionID) and C_Reputation and C_Reputation.GetFactionParagonInfo then
local ok, currentValue, threshold, _, hasRewardPending, tooLowLevelForParagon = pcall(C_Reputation.GetFactionParagonInfo, factionID)
if ok then
local paragonThreshold = SafeNumber(threshold, nil)
local paragonCurrentValue = SafeNumber(currentValue, nil)
if paragonThreshold and paragonThreshold > 0 and paragonCurrentValue and not tooLowLevelForParagon then
reputationData.kind = "paragon"
reputationData.paragonRewardPending = hasRewardPending and true or false
reputationData.minRep = 0
reputationData.maxRep = paragonThreshold
local wrappedValue = paragonCurrentValue % paragonThreshold
reputationData.curRep = reputationData.paragonRewardPending and paragonThreshold or wrappedValue
local baseRank = SafeText(reputationData.rankText, "Exalted")
reputationData.rankText = ("%s (Paragon)"):format(baseRank)
reputationData.hideProgressInTooltip = false
end
end
end
if reputationData.maxRep <= reputationData.minRep then
reputationData.maxRep = reputationData.minRep + 1
end
if reputationData.curRep < reputationData.minRep then
reputationData.curRep = reputationData.minRep
elseif reputationData.curRep > reputationData.maxRep then
reputationData.curRep = reputationData.maxRep
end
local progressCurrent = math.max(0, reputationData.curRep - reputationData.minRep)
local progressMax = math.max(1, reputationData.maxRep - reputationData.minRep)
if progressCurrent > progressMax then
progressCurrent = progressMax
end
reputationData.progressCurrent = progressCurrent
reputationData.progressMax = progressMax
reputationData.progressPercent = math.floor((progressCurrent / progressMax) * 100 + 0.5)
reputationData.isCapped = progressCurrent >= progressMax
if reputationData.isCapped and reputationData.kind ~= "paragon" then
reputationData.hideProgressInTooltip = reputationData.hideProgressInTooltip or true
end
return reputationData
end
local function BuildReputationSummaryText(reputationData)
if not reputationData then
return "Rep: --"
end
local factionName = TruncateLabel(reputationData.name, 14)
if reputationData.paragonRewardPending then
return ("Rep: %s !"):format(factionName)
end
if reputationData.hideProgressInTooltip and reputationData.rankText then
return ("Rep: %s %s"):format(factionName, reputationData.rankText)
end
return ("Rep: %s %d%%"):format(factionName, reputationData.progressPercent or 0)
end
local function AddReputationTooltipLines(tooltip, reputationData)
if not reputationData then
tooltip:AddLine("No watched faction.", 0.9, 0.35, 0.35)
return
end
tooltip:AddDoubleLine("Faction", SafeText(reputationData.name, "--"), 0.82, 0.82, 0.82, 1, 1, 1)
tooltip:AddDoubleLine("Standing", SafeText(reputationData.rankText, "--"), 0.82, 0.82, 0.82, 1, 1, 1)
if not reputationData.hideProgressInTooltip then
tooltip:AddDoubleLine(
"Progress",
("%d / %d (%d%%)"):format(reputationData.progressCurrent or 0, reputationData.progressMax or 1, reputationData.progressPercent or 0),
0.82,
0.82,
0.82,
1,
1,
1
)
end
if reputationData.kind == "major" then
if reputationData.isMajorAtMaxRenown then
tooltip:AddLine("Maximum Renown reached.", 0.55, 0.9, 1)
else
tooltip:AddLine("Major Faction (Renown)", 0.55, 0.9, 1)
end
elseif reputationData.kind == "friendship" then
tooltip:AddLine("Friendship Reputation", 0.55, 0.9, 1)
elseif reputationData.kind == "paragon" then
tooltip:AddLine("Paragon Reputation", 0.55, 0.9, 1)
end
if reputationData.paragonRewardPending then
tooltip:AddLine("Paragon reward available.", 1, 0.82, 0)
end
if reputationData.isAccountWide then
tooltip:AddLine("Account-wide reputation.", 0.65, 0.9, 1)
end
end
local dataTextMemoryCacheValue = "Mem: 0.0MB"
local dataTextMemoryCacheTime = 0
local dataTextMemorySlotActive = false
local DATATEXT_REALTIME_BUILTINS = {
FPS = true,
Time = true,
Memory = true,
Latency = true,
Combat = true,
MoveSpeed = true,
Coords = true,
Range = true,
}
function addon:GetBuiltinDataTextMap()
if self._builtinDataTextMap then
return self._builtinDataTextMap
end
local map = {
FPS = {
label = "FPS",
text = function()
return ("FPS: %d"):format(math.floor((GetFramerate and GetFramerate() or 0) + 0.5))
end,
tooltip = function(tooltip)
local fps = math.floor((GetFramerate and GetFramerate() or 0) + 0.5)
local home, world = GetLatencyPair()
tooltip:AddDoubleLine("Framerate", tostring(fps), 0.82, 0.82, 0.82, 1, 1, 1)
tooltip:AddDoubleLine("Latency", string.format("Home %dms / World %dms", home, world), 0.82, 0.82, 0.82, 1, 1, 1)
end,
},
Time = {
label = "Time",
text = function()
local hour, minute = GetGameTime()
return ("Time: %02d:%02d"):format(hour or 0, minute or 0)
end,
},
Date = {
label = "Date",
text = function()
return date and date("%Y-%m-%d") or "Date: --"
end,
},
Memory = {
label = "Memory",
text = function()
if not dataTextMemorySlotActive then
return dataTextMemoryCacheValue
end
local now = GetTime and GetTime() or 0
if (now - (dataTextMemoryCacheTime or 0)) >= 2 then
local memMB = (collectgarbage("count") or 0) / 1024
dataTextMemoryCacheValue = ("Mem: %.1fMB"):format(memMB)
dataTextMemoryCacheTime = now
end
return dataTextMemoryCacheValue
end,
click = function()
collectgarbage("collect")
end,
tooltip = function(tooltip)
local top, totalKB = GetTopAddonMemoryUsage(10)
tooltip:AddDoubleLine("Total AddOn Memory", FormatMemoryKB(totalKB), 0.82, 0.82, 0.82, 1, 1, 1)
tooltip:AddLine(" ")
for i = 1, #top do
local data = top[i]
tooltip:AddDoubleLine(data.name, FormatMemoryKB(data.memKB), 1, 1, 1, 0.82, 0.96, 1)
end
tooltip:AddLine(" ")
tooltip:AddLine("Click to collect Lua garbage.", 0.70, 0.70, 0.70)
end,
},
Gold = {
label = "Gold",
text = function()
local money = GetMoney and GetMoney() or 0
local gold = math.floor((money or 0) / 10000)
return ("Gold: %d"):format(gold)
end,
tooltip = function(tooltip)
local money = tonumber(GetMoney and GetMoney() or 0) or 0
local gold = math.floor(money / 10000)
local silver = math.floor((money % 10000) / 100)
local copper = money % 100
tooltip:AddDoubleLine("Character Gold", string.format("%dg %ds %dc", gold, silver, copper), 0.82, 0.82, 0.82, 1, 1, 1)
end,
},
Coords = {
label = "Coords",
text = function()
local x, y = GetPlayerCoordsPercent()
if not x or not y then
return "Coords: --,--"
end
return ("Coords: %.1f, %.1f"):format(x, y)
end,
click = function()
if ToggleWorldMap then
ToggleWorldMap()
end
end,
},
Latency = {
label = "Latency",
text = function()
local home, world = GetLatencyPair()
return ("MS: %d/%d"):format(home, world)
end,
tooltip = function(tooltip)
local home, world = GetLatencyPair()
tooltip:AddDoubleLine("Home", ("%dms"):format(home), 0.82, 0.82, 0.82, 1, 1, 1)
tooltip:AddDoubleLine("World", ("%dms"):format(world), 0.82, 0.82, 0.82, 1, 1, 1)
end,
},
Bags = {
label = "Bags",
text = function()
local freeSlots, totalSlots = GetBagFreeSlots()
if (tonumber(totalSlots) or 0) <= 0 then
return ("Bags: %d"):format(tonumber(freeSlots) or 0)
end
return ("Bags: %d/%d"):format(tonumber(freeSlots) or 0, tonumber(totalSlots) or 0)
end,
click = function()
if ToggleAllBags then
ToggleAllBags()
end
end,
},
Durability = {
label = "Durability",
text = function()