-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSexyReputation.lua
More file actions
1329 lines (1186 loc) · 50 KB
/
SexyReputation.lua
File metadata and controls
1329 lines (1186 loc) · 50 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
SexyReputation = LibStub("AceAddon-3.0"):NewAddon("Sexy Reputations", "AceEvent-3.0", "AceTimer-3.0", "AceConsole-3.0")
local mod = SexyReputation
local tooltip
local RepCompat = LibStub("LibMagicUtil-1.0").Reputation
local fmt = string.format
local floor = math.floor
local IsAltKeyDown = IsAltKeyDown
local IsControlKeyDown = IsControlKeyDown
local IsShiftKeyDown = IsShiftKeyDown
local tconcat = table.concat
local FL
local L = LibStub("AceLocale-3.0"):GetLocale("SexyReputation", false)
local LD = LibStub("LibDropdown-1.0")
local QTIP = LibStub("LibQTip-1.0")
local BAR = LibStub("LibSimpleBar-1.0")
local ldb = LibStub("LibDataBroker-1.1"):NewDataObject(L["Sexy Reputation"],
{
type = "data source",
label = L["Sexy Reputation"],
text = L["Factions"],
icon = (UnitFactionGroup("player") == "Horde" and
[[Interface\Addons\SexyReputation\hordeicon]] or
[[Interface\Addons\SexyReputation\allianceicon]]),
})
mod.repTitles = {
FACTION_STANDING_LABEL1, -- Hated
FACTION_STANDING_LABEL2, -- Hostile
FACTION_STANDING_LABEL3, -- Unfriendly
FACTION_STANDING_LABEL4, -- Neutral
FACTION_STANDING_LABEL5, -- Friendly
FACTION_STANDING_LABEL6, -- Honored
FACTION_STANDING_LABEL7, -- Revered
FACTION_STANDING_LABEL8, -- Exalted
}
-- names, used for looking up colors
mod.colorIds = {
hated = 1, hostile = 2, unfriendly = 3, neutral = 4, friendly = 5, honored = 6, revered = 7, exalted = 8, renown = 9
}
local minReputationValues = {
[1] = -42000, -- Hated
[2] = -6000, -- Hostile
[3] = -3000, -- Unfriendly
[4] = 0, -- Neutral
[5] = 3000, -- Friendly
[6] = 9000, -- Honored
[7] = 21000, -- Revered
[8] = 42000, -- Exalted
}
-- table recycling
local new, del, newHash, newSet, deepDel
do
local list = setmetatable({}, {__mode='k'})
function new(...)
local t = next(list)
if t then
list[t] = nil
for i = 1, select('#', ...) do
t[i] = select(i, ...)
end
return t
else
return { ... }
end
end
function newHash(...)
local t = next(list)
if t then
list[t] = nil
else
t = {}
end
for i = 1, select('#', ...), 2 do
t[select(i, ...)] = select(i+1, ...)
end
return t
end
function del(t)
if type(t) ~= table then
return nil
end
for k,v in pairs(t) do
t[k] = nil
end
list[t] = true
return nil
end
function deepDel(t)
if type(t) ~= "table" then
return nil
end
for k,v in pairs(t) do
t[k] = deepDel(v)
end
return del(t)
end
end
function mod:OnInitialize()
mod.db = LibStub("AceDB-3.0"):New("SexyRepDB", mod.defaults, "Default")
mod.gdb = mod.db.global
mod.cdb = mod.db.char
FL = mod.gdb.factionLookup
mod.sessionFactionChanges = new()
mod.factionGainsCache = new()
mod:SetDefaultColors()
end
function mod:OnEnable()
mod:RegisterEvent("COMBAT_TEXT_UPDATE")
mod:RegisterEvent("QUEST_TURNED_IN")
-- Run migrations once on first load after update
mod:ScheduleTimer("RunMigrations", 2)
mod:ScheduleTimer("UpdateLDBText", 3)
mod:ScheduleTimer("ScanFactions", 5)
end
function mod:OnDisable()
mod:UnregisterEvent("COMBAT_TEXT_UPDATE");
end
-- This transforms the faction name to an ID which is cached.
-- When wowFactionId is provided, it uses WoW's native faction ID directly.
-- This prevents issues with duplicate faction names in different trees.
-- The old name-based lookup is kept for backward compatibility during migration.
function mod:FactionID(name, wowFactionId)
-- If WoW's native faction ID is provided, use it directly
if wowFactionId then
return wowFactionId
end
-- Backward compatibility: name-based lookup (used during migration)
if type(name) == "number" then return name end
local id = FL[name]
if not id then
id = (mod.gdb.numFactions or 0) + 1
mod.gdb.numFactions = id
FL[name] = id
end
return id
end
function mod:RunMigrations()
mod:MigrateFactionData()
mod:MigrateWarboundGains()
end
-- Migrates faction data from old name-based IDs to new native WoW faction IDs
-- This runs once on first load after the update
function mod:MigrateFactionData()
-- Check if migration has already been completed
if mod.gdb.factionIdMigrationComplete then
return
end
local oldToNewMapping = {}
local factionIdToName = {} -- Map faction ID to name for composite key
local migrationInfo = {
timestamp = date("%Y-%m-%d %H:%M:%S"),
mappingCount = 0,
historyDates = 0,
factionsMigrated = {},
}
-- Scan current factions to build mapping
for idx = 1, 500 do
local factionData = RepCompat.GetFactionDataByIndex(idx)
local name = factionData and factionData.name
local factionId = factionData and factionData.factionID
if not name then break end
if factionId then
-- Store faction ID to name mapping for composite keys
factionIdToName[factionId] = name
-- Get the old custom ID for this faction name
local oldId = FL[name]
if oldId and oldId ~= factionId then
oldToNewMapping[oldId] = factionId
migrationInfo.mappingCount = migrationInfo.mappingCount + 1
migrationInfo.factionsMigrated[name] = {
oldId = oldId,
newId = factionId,
}
end
end
end
-- Migrate data if we have mappings
if migrationInfo.mappingCount > 0 then
-- Migrate faction history
if mod.cdb.factionHistory then
local newHistory = {}
for date, factionData in pairs(mod.cdb.factionHistory) do
newHistory[date] = {}
migrationInfo.historyDates = migrationInfo.historyDates + 1
for oldFactionId, amount in pairs(factionData) do
local newFactionId = oldToNewMapping[oldFactionId] or oldFactionId
newHistory[date][newFactionId] = (newHistory[date][newFactionId] or 0) + amount
end
end
mod.cdb.factionHistory = newHistory
end
-- Migrate header fold states to composite key format (factionID_name)
if mod.cdb.hf then
local newHf = {}
for oldFactionId, folded in pairs(mod.cdb.hf) do
local newFactionId = oldToNewMapping[oldFactionId] or oldFactionId
local factionName = factionIdToName[newFactionId]
if factionName then
-- Create composite key: factionID_name
local compositeKey = newFactionId .. "_" .. factionName
newHf[compositeKey] = folded
end
end
mod.cdb.hf = newHf
end
-- Migrate watched faction
if mod.cdb.watchedFaction then
mod.cdb.watchedFaction = oldToNewMapping[mod.cdb.watchedFaction] or mod.cdb.watchedFaction
end
end
-- Special case: Clear data for faction 169 (Steamwheedle Cartel header)
-- This faction should not have reputation data
if mod.cdb.factionHistory then
for date, factionData in pairs(mod.cdb.factionHistory) do
factionData[169] = nil
end
end
if mod.cdb.hf then
mod.cdb.hf[169] = nil
end
if mod.cdb.watchedFaction == 169 then
mod.cdb.watchedFaction = nil
end
-- Mark migration as complete
mod.gdb.factionIdMigrationComplete = true
-- Print info message
if migrationInfo.mappingCount > 0 then
print(fmt("SexyReputation: Migration complete - migrated %d factions across %d history dates to native WoW faction IDs",
migrationInfo.mappingCount, migrationInfo.historyDates))
else
print("SexyReputation: Migration complete - no faction ID changes needed")
end
end
function mod:MigrateWarboundGains()
if mod.gdb.warboundGainsMigrationComplete then return end
-- Build set of warbound faction IDs from current scan
local warboundIds = {}
for idx = 1, 500 do
local factionData = RepCompat.GetFactionDataByIndex(idx)
if not factionData then break end
local factionId = factionData.factionID
if factionId and factionData.isAccountWide then
warboundIds[factionId] = true
end
end
local migratedCount = 0
-- Iterate all character profiles in AceDB's raw storage
local sv = mod.db.sv and mod.db.sv.char
if sv then
for charKey, charData in pairs(sv) do
local fh = charData.factionHistory
if fh then
for date, dayData in pairs(fh) do
for factionId, amount in pairs(dayData) do
if warboundIds[factionId] then
-- Move to global history
if not mod.gdb.globalFactionHistory[date] then
mod.gdb.globalFactionHistory[date] = {}
end
mod.gdb.globalFactionHistory[date][factionId] =
(mod.gdb.globalFactionHistory[date][factionId] or 0) + amount
dayData[factionId] = nil
migratedCount = migratedCount + 1
end
end
end
end
end
end
mod.gdb.warboundGainsMigrationComplete = true
if migratedCount > 0 then
print(fmt("SexyReputation: Migrated %d warbound faction gain entries to global history.", migratedCount))
end
end
function mod:ScanFactions(toggleActiveId)
local foldedHeaders = new()
mod.allFactions = deepDel(mod.allFactions) or new()
mod.factionIdToIdx = del(mod.factionIdToIdx) or new()
mod.factionGainsCache = deepDel(mod.factionGainsCache) or new()
-- Iterate through the factions until we run out. We need to unfold
-- any folded header, which changes the number of factions, so we just
-- keep iterating until GetFactionDataByIndex returns nil
local fr = mod.cdb.fr
for idx = 1, 500 do
local factionData = RepCompat.GetFactionDataByIndex(idx)
local name = factionData and factionData.name
local description = factionData and factionData.description
local standingId = factionData and factionData.reaction
local bottomValue = factionData and factionData.currentReactionThreshold
local topValue = factionData and factionData.nextReactionThreshold
local earnedValue = factionData and factionData.currentStanding
local atWarWith = factionData and factionData.atWarWith
local canToggleAtWar = factionData and factionData.canToggleAtWar
local isHeader = factionData and factionData.isHeader
local isCollapsed = factionData and factionData.isCollapsed
local hasRep = factionData and factionData.isHeaderWithRep
local isWatched = factionData and factionData.isWatched
local isChild = factionData and factionData.isChild
local factionId = factionData and factionData.factionID
local isParagon, paraVal, paraThreshold, paraRewardPending
local isRenown, renownTitle, renownLevel, maxRenownLevels
local isAccountWide
if factionId then
isAccountWide = factionData.isAccountWide
--check if paragon and grab info
isParagon = RepCompat.IsFactionParagon(factionId)
if isParagon then
paraVal, paraThreshold, _, paraRewardPending, _ = RepCompat.GetFactionParagonInfo(factionId)
end
isRenown = RepCompat.IsMajorFaction(factionId)
if isRenown then
local majorFactionData = C_MajorFactions.GetMajorFactionData(factionId)
renownLevel = majorFactionData.renownLevel
maxRenownLevels = majorFactionData.maxLevel or #C_MajorFactions.GetRenownLevels(factionId)
renownTitle = fmt(RENOWN_LEVEL_LABEL, renownLevel)
bottomValue = majorFactionData.renownLevelThreshold*(renownLevel-1)
topValue = bottomValue + majorFactionData.renownLevelThreshold
local isCapped = C_MajorFactions.HasMaximumRenown(factionId)
earnedValue = isCapped and (majorFactionData.renownLevelThreshold*(maxRenownLevels-1))
or (bottomValue + majorFactionData.renownReputationEarned) or 0
end
end
local nextFactionData = RepCompat.GetFactionDataByIndex(idx + 1)
local nextName = nextFactionData and nextFactionData.name
if name == nextName and nextName ~= "Guild" then break end -- bugfix
if not name then break end -- last one reached
local friendInfo = RepCompat.GetFriendshipReputation(factionId)
local isCapped
local friendRank, friendMaxRank
if friendInfo then
if friendInfo.nextThreshold then
bottomValue = friendInfo.reactionThreshold
topValue = friendInfo.nextThreshold
earnedValue = friendInfo.standing
else
bottomValue, topValue, earnedValue = 0, 1, 1
isCapped = true
end
local rankInfo = RepCompat.GetFriendshipReputationRanks(factionId)
if rankInfo then
friendRank, friendMaxRank = rankInfo.currentLevel, rankInfo.maxLevel
end
end
local faction = newHash("name", name,
"desc", description,
"bottomValue", bottomValue,
"topValue", topValue,
"reputation", earnedValue,
"isHeader", isHeader,
"standingId", standingId,
"hasRep", hasRep or earnedValue ~= 0,
"isParagon", isParagon or false,
"paraVal", paraVal or nil,
"paraThresh", paraThreshold or nil,
"paraRewardPending", paraRewardPending or nil,
"isRenown", isRenown or false,
"renownTitle", renownTitle,
"renownLevel", renownLevel,
"maxRenownLevels", maxRenownLevels,
"isChild", isChild,
"friendId", friendInfo and friendInfo.friendshipFactionID,
"friendshipText", friendInfo and friendInfo.text,
"friendTextLevel", friendInfo and friendInfo.reaction,
"friendRank", friendRank,
"friendMaxRank", friendMaxRank,
"friendIsCapped", isCapped,
"isAccountWide", isAccountWide,
"id", mod:FactionID(name, factionId))
mod.allFactions[idx] = faction
mod.factionIdToIdx[faction.id] = idx
if faction.id == toggleActiveId then
local isActive = RepCompat.IsFactionActive(idx)
RepCompat.SetFactionActive(idx, not isActive)
mod:ScanFactions() -- we need to rescan fully..
return
end
if isHeader and isCollapsed then
foldedHeaders[idx] = true
RepCompat.ExpandFactionHeader(idx)
end
if fr and faction.name == FACTION_INACTIVE then
mod.cdb.hf[faction.id] = true
end
end
mod.cdb.fr = false
-- Restore factions folded states
for id = #mod.allFactions, 1, -1 do
if foldedHeaders[id] then
RepCompat.CollapseFactionHeader(id)
end
end
del(foldedHeaders)
-- Snapshot current character's rep data for cross-character tracking
mod:SnapshotCharRepData()
end
function mod:SnapshotCharRepData()
local charKey = mod.db.keys.char
local _, className = UnitClass("player")
local charEntry = mod.gdb.charRepData[charKey]
if not charEntry then
charEntry = { className = className, factions = {} }
mod.gdb.charRepData[charKey] = charEntry
else
charEntry.className = className
end
local factions = charEntry.factions
wipe(factions)
for _, faction in ipairs(mod.allFactions) do
if not faction.isHeader and not faction.isAccountWide and faction.hasRep and faction.id then
factions[faction.id] = {
standingId = faction.standingId,
reputation = faction.reputation,
bottomValue = faction.bottomValue,
topValue = faction.topValue,
isParagon = faction.isParagon or nil,
paraVal = faction.paraVal,
paraThresh = faction.paraThresh,
friendId = faction.friendId,
friendTextLevel = faction.friendTextLevel,
isRenown = faction.isRenown or nil,
renownLevel = faction.renownLevel,
renownTitle = faction.renownTitle,
maxRenownLevels = faction.maxRenownLevels,
}
end
end
end
function mod:GetCrossCharRepForFaction(factionId)
local results = {}
local currentChar = mod.db.keys.char
local currentRealm = GetRealmName()
for charKey, charEntry in pairs(mod.gdb.charRepData) do
local fData = charEntry.factions[factionId]
if fData then
local displayName = charKey
-- Strip realm if same realm
local name, realm = charKey:match("^(.+) %- (.+)$")
if realm and realm == currentRealm then
displayName = name
end
local classColor = RAID_CLASS_COLORS[charEntry.className]
local colorHex = classColor and classColor.colorStr or "ffffffff"
-- Determine standing text and color
local title, colorId
if fData.isRenown then
title = fData.renownTitle or (RENOWN_LEVEL_LABEL and fmt(RENOWN_LEVEL_LABEL, fData.renownLevel or "?")) or "Renown"
colorId = mod.colorIds.renown
elseif fData.friendId then
title = fData.friendTextLevel or ""
colorId = mod.colorIds.friendly
else
title = mod.repTitles[fData.standingId] or ""
colorId = fData.standingId or 4
end
local sc = mod.gdb.colors[colorId]
local standingColor = sc and fmt("%02x%02x%02x", floor(sc.r*255), floor(sc.g*255), floor(sc.b*255)) or "ffffff"
local rep = fData.reputation - fData.bottomValue
local maxRep = fData.topValue - fData.bottomValue
local repText
if maxRep > 0 then
repText = fmt("%s %d/%d", title, rep, maxRep)
else
repText = title
end
table.insert(results, {
name = displayName,
colorHex = colorHex,
repText = repText,
standingColor = standingColor,
sortValue = fData.reputation + (fData.isParagon and (fData.paraVal or 0) or 0),
isCurrent = charKey == currentChar,
})
end
end
table.sort(results, function(a, b) return a.sortValue > b.sortValue end)
local maxChars = mod.gdb.crossCharMax or 5
if #results > maxChars then
-- Preserve the current character even if outside top N
local currentEntry
for i = maxChars + 1, #results do
if results[i].isCurrent then
currentEntry = results[i]
end
end
for i = #results, maxChars + 1, -1 do
results[i] = nil
end
if currentEntry then
results[maxChars + 1] = currentEntry
end
end
return results
end
function mod:GetDate(delta)
local dt = date("*t", time()-(delta or 0))
return dt.year * 10000 + dt.month * 100 + dt.day
end
function mod:ReputationLevelDetails(faction)
local reputation, standingId, friendId = faction.reputation, faction.standingId, faction.friendId
local sc, color, rep, title, colorId
rep = reputation - faction.bottomValue
if faction.isRenown then
title = faction.renownTitle
colorId = mod.colorIds.renown
elseif friendId then
title = faction.friendTextLevel
colorId = mod.colorIds.friendly
else
title = mod.repTitles[standingId]
colorId = standingId
end
sc = mod.gdb.colors[colorId]
if mod.gdb.colorFactions then
color = fmt("%02x%02x%02x", floor(sc.r*255), floor(sc.g*255), floor(sc.b*255))
else
color = "ffffff"
end
return color, rep, title, colorId
end
function mod:GetGainsSummary(id)
local today = mod:GetDate()
local newlyCalculated = false
local fc = mod.factionGainsCache[today]
if not fc then
-- Either we changed day, in which case we need to recalculate
-- or it's new and it doesn't matter
mod.factionGainsCache = deepDel(mod.factionGainsCache) or new()
mod.factionGainsCache[today] = new()
fc = mod.factionGainsCache[today]
end
if not fc[id] then
newlyCalculated = true
local todayDate = mod:GetDate()
local yesterdayDate = mod:GetDate(86400)
-- Use global history for warbound factions, character history otherwise
local isWarbound = mod.factionIdToIdx and mod.factionIdToIdx[id]
and mod.allFactions[mod.factionIdToIdx[id]]
and mod.allFactions[mod.factionIdToIdx[id]].isAccountWide
local fh = isWarbound and mod.gdb.globalFactionHistory or mod.cdb.factionHistory
local todayChange = fh[todayDate] and fh[todayDate][id] or 0
local yesterdayChange = fh[yesterdayDate] and fh[yesterdayDate][id] or 0
local weekChange = (todayChange or 0) + (yesterdayChange or 0)
for day = 2,6 do
local dayChange = fh[mod:GetDate(day*86400)] -- going back in time
if dayChange and dayChange[id] then
weekChange = weekChange + dayChange[id]
end
end
local monthChange = weekChange
for day = 7, 29 do
local dayChange = fh[mod:GetDate(day*86400)] -- going back in time
if dayChange and dayChange[id] then
monthChange = monthChange + dayChange[id]
end
end
fc[id] = newHash("today", todayChange,
"yesterday", yesterdayChange,
"week", weekChange,
"month", monthChange,
"changed", todayChange ~= 0 or yesterdayChange ~= 0
or weekChange ~= 0 or monthChange ~= 0)
end
return fc[id], newlyCalculated
end
---------------------------------------------------
-- LDB Display and display utility methods
local function _addIndentedCell(tooltip, icon, text, indentation, font, func, arg)
local y, x = tooltip:AddLine()
tooltip:SetCell(y, 2, icon)
tooltip:SetCell(y, 3, text, font or tooltip:GetFont(), "LEFT", 1, nil, indentation)
if func then
tooltip:SetLineScript(y, "OnMouseUp", func, arg)
end
return y, x
end
local function c(text, color)
text = text or ""
return fmt("|cff%s%s|r", color, text)
end
local function delta(number, zero)
if not number or (not zero and number == 0) then
return ""
end
if number < 0 then
return fmt("|cffff2020%d|r", number)
elseif number > 0 then
return fmt("|cff00ef9a+%d|r", number)
else
return "|cffcfcfcf0|r"
end
end
local function _plusminus(folded)
return fmt("|TInterface\\Buttons\\UI-%sButton-Up:18|t", folded and "Plus" or "Minus")
end
local function _showFactionInfoTooltip(frame, faction)
if mod.gdb.showTooltips then
local tooltip = QTIP:Acquire("SexyRepFactionTooltip")
if faction.hasRep or (faction.desc and faction.desc ~= '') then
local y
tooltip:SetColumnLayout(faction.hasRep and 2 or 1, "LEFT", "RIGHT")
tooltip:Clear()
local header = faction.name
if faction.friendRank and faction.friendMaxRank then
header = fmt("%s (%d / %d)", header, faction.friendRank, faction.friendMaxRank)
end
tooltip:AddHeader(c(header, "ffd200"))
if faction.desc and faction.desc ~= '' then
tooltip:SetCell((tooltip:AddLine()), 1, faction.desc, tooltip:GetFont(), "LEFT", 1, nil, nil, 0, 300, 100)
tooltip:AddLine(" ")
end
if faction.friendshipText and faction.friendshipText ~= '' then
tooltip:SetCell((tooltip:AddLine()), 1, faction.friendshipText, tooltip:GetFont(), "LEFT", 1, nil, nil, 0, 300, 100)
tooltip:AddLine(" ")
end
if faction.isRenown then
local renownText = faction.renownTitle
if faction.maxRenownLevels and faction.renownLevel < faction.maxRenownLevels then
renownText = fmt("%s / %d", renownText, faction.maxRenownLevels)
end
tooltip:SetCell((tooltip:AddLine()), 1, renownText, tooltip:GetFont(), "LEFT", 1, nil, nil, 0, 300, 50)
tooltip:AddLine(" ")
end
if faction.isAccountWide then
tooltip:AddLine(c(L["Warbound"], "00ccff"))
tooltip:AddLine(" ")
end
if faction.hasRep then
-- Show recent reputtion history
local sessionChange = mod.sessionFactionChanges[faction.id] or 0
local gs = mod:GetGainsSummary(faction.id)
y = tooltip:AddHeader()
if sessionChange ~= 0 or gs.changed then
tooltip:SetCell(y, 1, c(L["Recent reputation changes"], "ffd200"))
tooltip:AddSeparator(1)
tooltip:AddLine(L["Session"], delta(sessionChange, true))
tooltip:AddLine(L["Today"], delta(gs.today, true))
tooltip:AddLine(L["Yesterday"], delta(gs.yesterday, true))
tooltip:AddLine(L["Last Week"], delta(gs.week, true))
tooltip:AddLine(L["Last Month"], delta(gs.month, true))
local color, rep, repTitle = mod:ReputationLevelDetails(faction)
if not faction.friendId then
local remaining =
(faction.isParagon and (faction.paraThresh - faction.paraVal % faction.paraThresh))
or (faction.isRenown and ((faction.topValue - faction.bottomValue)* (faction.maxRenownLevels-1) - faction.reputation))
or (42999 - faction.bottomValue - rep)
if remaining > 0 then
tooltip:AddLine(L["Remaining"], remaining)
end
local repetitions
if gs.today > 0 then
repetitions = remaining/gs.today
elseif gs.yesterday > 0 then
repetitions = remaining/gs.yesterday
end
if repetitions then
tooltip:AddLine(L["Repetitions"], string.format("%.2f", repetitions))
end
end
else
tooltip:SetColumnLayout(1, "LEFT")
tooltip:SetCell(y, 1, c(L["Recent reputation changes"], "ffd200"))
tooltip:AddSeparator(1)
y = tooltip:AddLine(L["No changes recorded in the last 30 days."])
end
end
-- Cross-character standings
if mod.gdb.showCrossCharRep and not faction.isAccountWide and faction.hasRep then
local crossChars = mod:GetCrossCharRepForFaction(faction.id)
if #crossChars > 0 then
tooltip:AddLine(" ")
y = tooltip:AddHeader()
tooltip:SetCell(y, 1, c(L["Other Characters"], "ffd200"))
tooltip:AddSeparator(1)
for _, entry in ipairs(crossChars) do
local nameText = fmt("|c%s%s|r", entry.colorHex, entry.name)
if entry.isCurrent then
nameText = "> " .. nameText
end
tooltip:AddLine(
nameText,
c(entry.repText, entry.standingColor)
)
end
end
end
if mod.cdb.watchedFaction == faction.id then
tooltip:AddLine(" ")
tooltip:AddSeparator(1)
tooltip:AddLine(c(L["This faction is currently being tracked."], "ffff00"))
end
tooltip:SetPoint("TOPLEFT", frame, "TOPRIGHT", 10, 0)
tooltip:SetFrameLevel(frame:GetFrameLevel()+1)
tooltip:SetClampedToScreen(true)
tooltip:Show()
tooltip:SetAutoHideDelay(0.25, frame)
else
QTIP:Release(tooltip)
end
end
end
local function _factionOnClick(frame, faction, button)
if button == "LeftButton" then
if IsAltKeyDown() then
if faction.hasRep then
if mod.cdb.watchedFaction == faction.id then
mod.cdb.watchedFaction = nil
else
mod.cdb.watchedFaction = faction.id
end
mod:UpdateLDBText()
end
elseif IsControlKeyDown() and IsShiftKeyDown() then
mod:ScanFactions(faction.id)
elseif faction.isHeader then
-- Use composite key: factionID_name to handle duplicate faction IDs
local foldKey = faction.id .. "_" .. faction.name
mod.cdb.hf[foldKey] = not mod.cdb.hf[foldKey] or nil
end
end
ldb.OnEnter() -- redraw
end
function ldb.OnEnter(frame)
tooltip = QTIP:Acquire("SexyRepTooltip")
tooltip:EnableMouse(true)
local numCols = 3
local showRep = mod.gdb.repTextStyle ~= mod.TEXT_STYLE_STANDING and mod.gdb.repStyle == mod.STYLE_TEXT
local showStanding = mod.gdb.repTextStyle ~= mod.TEXT_STYLE_REPUTATION and mod.gdb.repStyle == mod.STYLE_TEXT
local showRepBar = mod.gdb.repStyle == mod.STYLE_BAR
local showPercentage = mod.gdb.showPercentage
local showGains = mod.gdb.showGains
local colorFactions = mod.gdb.colorFactions
if showRepBar then
numCols = numCols + 1
else
if showRep then numCols = numCols + 3 end
if showStanding then numCols = numCols + 1 end
end
if showPercentage then numCols = numCols + 1 end
if showGains then numCols = numCols + 2 end
tooltip:Clear()
tooltip:SetColumnLayout(numCols, "LEFT")
if frame then
tooltip:SetAutoHideDelay(0.5, frame)
end
if not mod.allFactions or not #mod.allFactions then
mod:ScanFactions()
end
local y, x
y = tooltip:AddHeader("", "", c(L["Faction"], "ffff00"))
x = 4
if showRepBar then
tooltip:SetCell(y, x, c(L["Standing"], "ffff00"), "CENTER") x = x + 1
else
if showStanding then
tooltip:SetCell(y, x, c(L["Standing"], "ffff00"), "LEFT") x = x + 1
end
if showRep then
tooltip:SetCell(y, x, c(L["Reputation"], "ffff00"), "CENTER", 3) x = x + 3
end
end
if showPercentage then
tooltip:SetCell(y, x, c("%", "ffff00"), "CENTER") x = x + 1
end
if showGains then
tooltip:SetCell(y, x, c(L["Session"], "ffff00"), "CENTER") x = x + 1
tooltip:SetCell(y, x, c(L["Today"], "ffff00"), "CENTER") x = x + 1
end
tooltip:AddSeparator(1)
local skipUntilHeader, skipUntilChildHeader
local isTopLevelHeader, isChildHeader
local todaysDate = mod:GetDate()
local showOnlyChanged = mod.gdb.showOnlyChanged
local hideExalted = mod.gdb.hideExalted
local showParagon = mod.gdb.showParagon
local watchedFaction = mod.cdb.watchedFaction
local gridLines = mod.gdb.gridLines
local indent, isTopLevelHeader, isChildHeader, sessionChange, today, showRow
local paraIcon = [[|TInterface\Icons\Inv_legioncircle_paragoncache_argussianreach:16|t]]
-- Track empty headers to add placeholder rows
local lastHeaderFaction = nil
local lastHeaderIndent = 0
local lastHeaderFolded = false
local childrenShownForLastHeader = false
-- Pre-scan: build map of folded headers that contain paragon reward children
local headerParagonRewards = {}
do
local currentTopHeader, currentChildHeader
local topFolded, childFolded
for _, f in ipairs(mod.allFactions) do
local foldKey = f.id .. "_" .. f.name
if f.isHeader and not f.isChild then
currentTopHeader = foldKey
currentChildHeader = nil
topFolded = mod.cdb.hf[foldKey]
childFolded = false
elseif f.isHeader and f.isChild then
currentChildHeader = foldKey
childFolded = mod.cdb.hf[foldKey]
elseif f.isParagon and f.paraRewardPending then
if topFolded and currentTopHeader then
headerParagonRewards[currentTopHeader] = true
elseif childFolded and currentChildHeader then
headerParagonRewards[currentChildHeader] = true
end
end
end
end
for id, faction in ipairs(mod.allFactions) do
isTopLevelHeader = faction.isHeader and not faction.isChild
isChildHeader = faction.isHeader and faction.isChild
-- Calculate indent early so we can use it in skip logic
indent = 0
if faction.isChild then indent = 20 end
if not faction.isHeader then indent = indent + 20 end
sessionChange = mod.sessionFactionChanges[faction.id]
today = mod.cdb.factionHistory[todaysDate] and mod.cdb.factionHistory[todaysDate][faction.id];
showRow = true
-- calculate whether this row should be displayed. Split out this way
-- so it's possible to understand what it's filtering and why
if skipUntilHeader then
-- Skip everything until we find another top-level header
if isTopLevelHeader then
-- Found next top-level header, stop skipping and show it
skipUntilHeader = nil
-- showRow remains true, display this faction
else
-- Still inside the folded top-level header, hide this row
showRow = false
end
elseif skipUntilChildHeader then
-- Skip factions at deeper indentation (indent=40) until we find:
-- 1. Another header (sibling child header or top-level)
-- 2. A faction at same or shallower indentation (indent <= 20)
if isTopLevelHeader or isChildHeader or indent <= 20 then
-- Found sibling or went back up, stop skipping and show it
skipUntilChildHeader = nil
-- showRow remains true, display this faction
else
-- Still inside the folded child header (indent=40), hide this row
showRow = false
end
end
if showRow and showOnlyChanged and not (sessionChange or today) then
showRow = false
elseif showRow and hideExalted and faction.standingId == 8 and not faction.isHeader then
showRow = faction.isParagon and showParagon
end
if showRow then
-- Check if we need to add placeholder for previous empty header (only if not folded)
-- Only show placeholder when encountering a sibling or parent-level header, not child headers
if lastHeaderFaction and not childrenShownForLastHeader and not lastHeaderFolded and faction.isHeader and indent <= lastHeaderIndent then
y = _addIndentedCell(tooltip, "", c(L["(No visible factions)"], "808080"), lastHeaderIndent + 20, nil, nil, nil)
if gridLines then
tooltip:AddSeparator(0.5, 1, 1, 1, 0.5)
end
end
local title, folded
if not showOnlyChanged then
-- Use composite key: factionID_name to handle duplicate faction IDs (like "Inactive")
local foldKey = faction.id .. "_" .. faction.name
folded = faction.isHeader and mod.cdb.hf[foldKey]
local pm = _plusminus(folded)
title = faction.isHeader and fmt("%s %s", pm, faction.name) or c(faction.name, "ffd200")
else
title = faction.isHeader and faction.name or c(faction.name, "ffd200")
end
local color, rep, repTitle, colorId = mod:ReputationLevelDetails(faction)
local font
local barColor = mod.gdb.colors[colorId]
local icon = ""
if watchedFaction == faction.id then
icon = [[|TInterface\Icons\Spell_Shadow_EvilEye:16|t]]
end
y = _addIndentedCell(tooltip, icon, title, indent, font, _factionOnClick, faction)
-- Paragon icon in column 1
if faction.isParagon and faction.paraRewardPending then
tooltip:SetCell(y, 1, paraIcon)
elseif faction.isHeader then
local foldKey = faction.id .. "_" .. faction.name
if headerParagonRewards[foldKey] then
tooltip:SetCell(y, 1, paraIcon)
end
end
tooltip:SetLineScript(y, "OnEnter", _showFactionInfoTooltip, faction)
tooltip:SetLineScript(y, "OnLeave", nil)
-- Track headers and their children for empty header detection
if faction.isHeader then
lastHeaderFaction = faction
lastHeaderIndent = indent
lastHeaderFolded = folded or false
childrenShownForLastHeader = false
else
childrenShownForLastHeader = true
end
-- Headers without reputation need empty cells to maintain proper row height
if faction.isHeader and not faction.hasRep then
-- Add empty cell spanning remaining columns to give the row proper height
tooltip:SetCell(y, 4, " ", "LEFT", numCols - 3)
elseif not faction.isHeader or faction.hasRep then
x = 4
local maxValue = faction.topValue-faction.bottomValue
--Paragon adjustments
if faction.isParagon then
repTitle = L["Paragon"]
barColor = {r=0, g=171/255, b=240/255}