Repository navigation
Expand file tree
/
Copy pathAccountRepaired.lua
More file actions
1421 lines (1263 loc) · 46.9 KB
/
Copy pathAccountRepaired.lua
File metadata and controls
1421 lines (1263 loc) · 46.9 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
--------------------------------------------------
-- Account Repaired v@project-version@
--------------------------------------------------
local _, addonTable = ...
local L = addonTable.L
AccountRepaired = AccountRepaired or {}
local AR = AccountRepaired
--------------------------------------------------
-- SavedVariables
--------------------------------------------------
AccountRepairedDB = AccountRepairedDB or {}
AccountRepairedPopupDB = AccountRepairedPopupDB or {}
local DB
local MIN_W = 440
local MAX_W = 680
-- Fixed window height — not saved, not resizable vertically
local FIXED_H = 260
local function InitDB()
AccountRepairedDB = AccountRepairedDB or {}
AccountRepairedPopupDB = AccountRepairedPopupDB or {}
DB = AccountRepairedPopupDB
-- Migrate: clear any previously saved height
DB.height = nil
if DB.width == nil then DB.width = 540 end
if DB.point == nil then DB.point = "CENTER" end
if DB.x == nil then DB.x = 0 end
if DB.y == nil then DB.y = 0 end
if DB.period == nil then DB.period = "all" end
-- Clamp saved width to valid range
DB.width = math.max(MIN_W, math.min(DB.width, MAX_W))
AR.currentPeriod = DB.period
end
--------------------------------------------------
-- Constants
--------------------------------------------------
local DATA_RETENTION_SECONDS = 365 * 2 * 86400
local PERIOD_SECONDS = { day=86400, week=604800, month=2592000, all=0 }
local PERIOD_ORDER = { "day", "week", "month", "all" }
local ARMOR_COLORS = {
Cloth = { r=0.78, g=0.78, b=0.85 },
Leather = { r=0.85, g=0.60, b=0.20 },
Mail = { r=0.35, g=0.65, b=0.95 },
Plate = { r=0.75, g=0.40, b=1.00 },
Unknown = { r=0.65, g=0.65, b=0.65 },
}
local ARMOR_TYPE_NAMES = { "Cloth", "Leather", "Mail", "Plate", "Unknown" }
local ARMOR_SLOTS = { 1, 3, 5, 7, 8 }
local ARMOR_TYPES_VALID = { Cloth=true, Leather=true, Mail=true, Plate=true }
local CHAT_CHANNELS = {
{ key="SAY", label="Say", color={1.0, 1.0, 1.0} },
{ key="PARTY", label="Party", color={0.5, 0.5, 1.0} },
{ key="RAID", label="Raid", color={1.0, 0.5, 0.0} },
{ key="GUILD", label="Guild", color={0.3, 1.0, 0.3} },
--{ key="OFFICER", label="Officer", color={0.3, 0.8, 0.3} },
{ key="NONE", label="None (print)", color={0.6, 0.6, 0.6} },
}
local CPANEL_W = 240
local CPANEL_ROW_H = 22
local CPANEL_HEADER_H = 28
local CPANEL_PAD = 6
local BAR_ROW_H = 26
local POPUP_STRIP_Y = -68
local POPUP_BARS_Y = -112
--------------------------------------------------
-- State
--------------------------------------------------
AR.mainFrame = CreateFrame("Frame")
AR.popupFrame = nil
AR.popupRows = {}
AR.charPanel = nil
AR.charPanelArmor = nil
AR.currentPeriod = "all"
local inMerchant = false
local pendingArmorDetect = false
--------------------------------------------------
-- Repair state machine
--------------------------------------------------
local repair = {
phase = "IDLE",
moneyBefore = 0,
}
local function ResetRepairState()
repair.phase = "IDLE"
repair.moneyBefore = 0
end
--------------------------------------------------
-- Character identity
--------------------------------------------------
local function GetCharInfo()
local realm = (GetNormalizedRealmName and GetNormalizedRealmName()) or GetRealmName()
return realm, UnitName("player")
end
local function GetCharKey(realm, name)
return realm .. "-" .. name
end
local function KeyToName(key)
return key:match("%-([^%-]+)$") or key
end
--------------------------------------------------
-- Armor detection
--------------------------------------------------
local function DetectArmorType()
local counts = {}
local allReady = true
for _, slotID in ipairs(ARMOR_SLOTS) do
local itemID = GetInventoryItemID("player", slotID)
if itemID then
local _, _, _, _, _, _, sub = GetItemInfo(itemID)
if sub then
if ARMOR_TYPES_VALID[sub] then
counts[sub] = (counts[sub] or 0) + 1
end
else
allReady = false
end
end
end
local best, bestN = "Unknown", 0
for sub, n in pairs(counts) do
if n > bestN then best, bestN = sub, n end
end
return best, allReady
end
local function RefreshCharArmorType()
local realm, name = GetCharInfo()
local charKey = GetCharKey(realm, name)
local _, classFile = UnitClass("player")
local armorType, allReady = DetectArmorType()
local cd = AccountRepairedDB[charKey]
if not cd then
AccountRepairedDB[charKey] = { class=classFile or "UNKNOWN", armorType=armorType, repairs={} }
cd = AccountRepairedDB[charKey]
end
cd.class = classFile or cd.class or "UNKNOWN"
if armorType ~= "Unknown" then cd.armorType = armorType end
cd.armorType = cd.armorType or "Unknown"
if not allReady then pendingArmorDetect = true end
end
--------------------------------------------------
-- Gold formatting
--------------------------------------------------
local function FormatGoldFull(copper)
copper = math.floor(tonumber(copper) or 0)
if copper <= 0 then return "|cffAAAAAA0g|r" end
local g = math.floor(copper / 10000)
local s = math.floor((copper % 10000) / 100)
local c = copper % 100
if g > 0 then
return string.format("|cffFFD700%d|rg |cffC0C0C0%d|rs |cffCD7F32%d|rc", g, s, c)
elseif s > 0 then
return string.format("|cffC0C0C0%d|rs |cffCD7F32%d|rc", s, c)
else
return string.format("|cffCD7F32%d|rc", c)
end
end
local function FormatGoldShort(copper)
copper = math.floor(tonumber(copper) or 0)
if copper <= 0 then return "|cffAAAAAA0g|r" end
local gv = copper / 10000
if gv >= 1000 then
return string.format("|cffFFD700%.1fk|r", gv / 1000)
elseif gv >= 1 then
return string.format("|cffFFD700%.1f|rg", gv)
end
local sv = copper / 100
if sv >= 1 then
return string.format("|cffC0C0C0%.1f|rs", sv)
end
return string.format("|cffCD7F32%d|rc", copper)
end
local function FormatGoldRounded(copper)
copper = math.floor(tonumber(copper) or 0)
if copper <= 0 then return "|cffAAAAAA0g|r" end
local gv = copper / 10000
if gv >= 1 then
if gv >= 1000 then
return string.format("|cffFFD700%d|rk", math.floor(gv / 1000 + 0.5))
else
local rounded_k = math.floor(gv / 1000 + 0.5)
if gv >= 1000 - 50 then
return string.format("|cffFFD700%d|rk", rounded_k)
end
if gv >= 100 then
local r = math.floor(gv / 100 + 0.5) * 100
if r >= 1000 then
return string.format("|cffFFD700%d|rk", r / 1000)
end
return string.format("|cffFFD700%d|rg", r)
end
return string.format("|cffFFD700%d|rg", math.floor(gv + 0.5))
end
end
local sv = copper / 100
if sv >= 1 then return string.format("|cffC0C0C0%d|rs", math.floor(sv)) end
return string.format("|cffCD7F32%d|rc", copper)
end
local function FormatGoldPlain(copper)
copper = math.floor(tonumber(copper) or 0)
if copper <= 0 then return "0g" end
local g = math.floor(copper / 10000)
local s = math.floor((copper % 10000) / 100)
local c = copper % 100
if g > 0 then
return string.format("%dg %ds %dc", g, s, c)
elseif s > 0 then
return string.format("%ds %dc", s, c)
else
return string.format("%dc", c)
end
end
--------------------------------------------------
-- Period helpers
--------------------------------------------------
local function GetDayResetTimestamp()
local secsUntilReset = GetQuestResetTime() or 86400
return time() + secsUntilReset - 86400
end
local function GetPeriodStart(period)
if period == "all" or not PERIOD_SECONDS[period] then return 0 end
if period == "day" then return GetDayResetTimestamp() end
return time() - PERIOD_SECONDS[period]
end
local function GetPeriodLabel(period)
local labels = {
day = L["PERIOD_DAY"],
week = L["PERIOD_WEEK"],
month = L["PERIOD_MONTH"],
all = L["PERIOD_ALL"],
}
return labels[period] or period
end
local function GetPeriodContextLabel(period)
if period == "day" then
local secsUntilReset = GetQuestResetTime() or 0
local secsSinceReset = math.max(0, math.min(86400 - secsUntilReset, 86400))
local h = math.floor(secsSinceReset / 3600)
local m = math.floor((secsSinceReset % 3600) / 60)
if h > 0 then
return string.format("last reset %dh %dm ago", h, m)
else
return string.format("last reset %dm ago", m)
end
elseif period == "week" then return "last 7 days"
elseif period == "month" then return "last 30 days"
elseif period == "all" then return "all time (last 2 years)"
end
return period
end
--------------------------------------------------
-- Data aggregation
--------------------------------------------------
local function GetCharRepairsInPeriod(cd, periodStart)
local total = 0
if not (cd and cd.repairs) then return 0 end
for _, e in ipairs(cd.repairs) do
if (e.t or 0) >= periodStart then
total = total + (e.g or 0)
end
end
return total
end
local function GetArmorTypeTotals(period)
local totals, acct = {}, 0
local ps = GetPeriodStart(period)
for _, cd in pairs(AccountRepairedDB) do
if type(cd) == "table" and cd.repairs then
local at = cd.armorType or "Unknown"
local amt = GetCharRepairsInPeriod(cd, ps)
if amt > 0 then
totals[at] = (totals[at] or 0) + amt
acct = acct + amt
end
end
end
return totals, acct
end
local function GetCharactersByArmorType(armorType, period)
local chars = {}
local ps = GetPeriodStart(period)
for charKey, cd in pairs(AccountRepairedDB) do
if type(cd) == "table" and (cd.armorType or "Unknown") == armorType then
local amt = GetCharRepairsInPeriod(cd, ps)
if amt > 0 then
table.insert(chars, {
key = charKey,
name = KeyToName(charKey),
class = cd.class or "UNKNOWN",
armorType = armorType,
gold = amt,
})
end
end
end
table.sort(chars, function(a, b) return a.gold > b.gold end)
return chars
end
local function GetCurrentCharAllPeriods()
local realm, name = GetCharInfo()
local cd = AccountRepairedDB[GetCharKey(realm, name)]
local stats = { day=0, week=0, month=0, all=0 }
if cd and cd.repairs then
local now = time()
local dayStart = GetDayResetTimestamp()
for _, e in ipairs(cd.repairs) do
local t, g = e.t or 0, e.g or 0
stats.all = stats.all + g
if t >= dayStart then stats.day = stats.day + g end
if t >= now - 604800 then stats.week = stats.week + g end
if t >= now - 2592000 then stats.month = stats.month + g end
end
end
return stats, cd
end
--------------------------------------------------
-- Record repair
--------------------------------------------------
local function RecordRepair(copper, source)
if copper <= 0 then return end
local realm, name = GetCharInfo()
local charKey = GetCharKey(realm, name)
local _, classFile = UnitClass("player")
local armorType = DetectArmorType()
local cd = AccountRepairedDB[charKey]
if not cd then
AccountRepairedDB[charKey] = { class=classFile or "UNKNOWN", armorType=armorType, repairs={} }
cd = AccountRepairedDB[charKey]
end
cd.class = classFile or cd.class or "UNKNOWN"
if armorType ~= "Unknown" then cd.armorType = armorType end
cd.armorType = cd.armorType or "Unknown"
table.insert(cd.repairs, { t=time(), g=copper })
local cutoff = time() - DATA_RETENTION_SECONDS
local repairs = cd.repairs
local firstOK = 1
while firstOK <= #repairs and (repairs[firstOK].t or 0) < cutoff do
firstOK = firstOK + 1
end
if firstOK > 1 then
local keep = #repairs - firstOK + 1
table.move(repairs, firstOK, #repairs, 1)
for i = keep + 1, #repairs do repairs[i] = nil end
end
local fundTag = (source == "guild") and "|cff33ff33[Guild]|r " or ""
print(string.format("%s Repaired %sfor %s",
L["FORMAT_NAME"], fundTag, FormatGoldFull(copper)))
if AR.popupFrame and AR.popupFrame:IsShown() then
AR.popupFrame:UpdateDisplay()
end
if AR.RefreshAPStrip then AR.RefreshAPStrip() end
end
--------------------------------------------------
-- Repair hook handlers
--------------------------------------------------
hooksecurefunc("RepairAllItems", function(useGuildFunds)
if not inMerchant then return end
if useGuildFunds then
local cost = GetRepairAllCost()
if cost and cost > 0 then
RecordRepair(cost, "guild")
end
return
end
local cost = GetRepairAllCost()
if not cost or cost <= 0 then return end
repair.phase = "WAITING_MONEY"
repair.moneyBefore = GetMoney()
end)
if RepairItem then
hooksecurefunc("RepairItem", function(_, useGuildFunds)
if not inMerchant then return end
if useGuildFunds then return end
repair.phase = "WAITING_MONEY"
repair.moneyBefore = GetMoney()
end)
end
--------------------------------------------------
-- Events
--------------------------------------------------
AR.mainFrame:RegisterEvent("PLAYER_LOGIN")
AR.mainFrame:RegisterEvent("MERCHANT_SHOW")
AR.mainFrame:RegisterEvent("MERCHANT_CLOSED")
AR.mainFrame:RegisterEvent("PLAYER_MONEY")
AR.mainFrame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
AR.mainFrame:RegisterEvent("ITEM_DATA_LOAD_RESULT")
AR.mainFrame:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_LOGIN" then
InitDB()
C_Timer.After(2, RefreshCharArmorType)
C_Timer.After(3, function()
local stats = GetCurrentCharAllPeriods()
print(string.format("%s %s|cffFFD700%s|r %s|cffFFD700%s|r |cffffA500/arepaired|r",
L["FORMAT_NAME"], L["LOGIN_TODAY"], FormatGoldShort(stats.day),
L["LOGIN_WEEK"], FormatGoldShort(stats.week)))
end)
C_Timer.After(1, AR.TryInjectAccountPlayedButton)
elseif event == "ITEM_DATA_LOAD_RESULT" then
if pendingArmorDetect then
pendingArmorDetect = false
RefreshCharArmorType()
end
elseif event == "MERCHANT_SHOW" then
inMerchant = true
ResetRepairState()
elseif event == "MERCHANT_CLOSED" then
inMerchant = false
ResetRepairState()
elseif event == "PLAYER_EQUIPMENT_CHANGED" then
C_Timer.After(0.5, RefreshCharArmorType)
elseif event == "PLAYER_MONEY" then
if inMerchant and repair.phase == "WAITING_MONEY" then
local delta = repair.moneyBefore - GetMoney()
if delta > 0 then
RecordRepair(delta, "personal")
end
ResetRepairState()
end
if AR.popupFrame and AR.popupFrame:IsShown() then
AR.popupFrame:UpdateDisplay()
end
end
end)
--------------------------------------------------
-- Delete character
--------------------------------------------------
StaticPopupDialogs["ACCOUNTREPAIRED_CONFIRM_DELETE"] = {
text = "",
button1 = DELETE,
button2 = CANCEL,
OnAccept = function(self, data)
if not (data and data.foundKey) then return end
AccountRepairedDB[data.foundKey] = nil
print("|cff00ff00" .. string.format(L["CMD_DELETE_SUCCESS"], data.foundKey) .. "|r")
if AR.popupFrame and AR.popupFrame:IsShown() then
AR.popupFrame:UpdateDisplay()
end
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}
local function ConfirmDeleteKey(foundKey)
StaticPopupDialogs["ACCOUNTREPAIRED_CONFIRM_DELETE"].text =
string.format(L["CMD_DELETE_CONFIRM"], foundKey)
StaticPopup_Show("ACCOUNTREPAIRED_CONFIRM_DELETE", nil, nil, { foundKey=foundKey })
end
local function DeleteCharacter(input)
input = (input or ""):match("^%s*(.-)%s*$")
local charName, realmName = input:match("^([^%-]+)%-(.+)$")
if not charName then
print("|cffff9900" .. L["CMD_DELETE_USAGE"] .. "|r")
return
end
local target = (realmName .. "-" .. charName):lower()
local found
for k in pairs(AccountRepairedDB) do
if k:lower() == target then found = k; break end
end
if found then
ConfirmDeleteKey(found)
else
print("|cffff0000" .. string.format(L["CMD_DELETE_NOT_FOUND"], input) .. "|r")
end
end
SLASH_ACCOUNTREPAIREDDELETE1 = "/ardelete"
SlashCmdList.ACCOUNTREPAIREDDELETE = DeleteCharacter
--------------------------------------------------
-- Chat sharing
--------------------------------------------------
-- Returns the trailing phrase used in shared messages, e.g. "in Last 7 Days"
local function GetPeriodTailLabel(period)
if period == "day" then return "Today" end
if period == "week" then return "in Last 7 Days" end
if period == "month" then return "in Last 30 Days" end
return "Total Repair Bill" -- "all"
end
-- Shares the account-wide total for a specific period to a channel.
-- Used when right-clicking a period tab button.
local function SendAccountTotal(period, channel)
local _, acct = GetArmorTypeTotals(period)
local tail = GetPeriodTailLabel(period)
if channel == "NONE" then
print(string.format(
"|cffAAAAAAAAccount Repaired:|r [Account Total] %s %s",
FormatGoldFull(acct), tail))
else
SendChatMessage(string.format(
"Account Repaired: [Account Total] %s %s",
FormatGoldPlain(acct), tail),
channel)
end
end
-- New format (one line per character):
-- chat : Account Repaired: Name (ArmorType) Xg Xs Xc in Last 7 Days
-- print: Account Repaired: Name (ArmorType) Xg Xs Xc in Last 7 Days (with class colour on name)
local function SendRepairBreakdown(armorType, channel)
local chars = GetCharactersByArmorType(armorType, AR.currentPeriod)
if #chars == 0 then return end
local armorLabel = L["ARMOR_" .. armorType] or armorType
local tail = GetPeriodTailLabel(AR.currentPeriod)
if channel == "NONE" then
for _, ch in ipairs(chars) do
local cc = RAID_CLASS_COLORS[ch.class] or { r=1, g=1, b=1 }
print(string.format(
"|cffAAAAAAAAccount Repaired:|r |cff%02x%02x%02x%s|r |cffAAAAAA(%s)|r [%s] %s",
cc.r * 255, cc.g * 255, cc.b * 255,
ch.name, armorLabel, FormatGoldFull(ch.gold), tail))
end
else
for _, ch in ipairs(chars) do
SendChatMessage(string.format(
"Account Repaired: %s (%s): %s %s",
ch.name, armorLabel, FormatGoldPlain(ch.gold), tail),
channel)
end
end
end
--------------------------------------------------
-- Channel picker (lazy, created once)
--------------------------------------------------
local function GetOrCreateChannelPicker()
if AR.channelPicker then return AR.channelPicker end
local BTN_H = 22
local PAD = 6
local HEADER_H = 24
local PICKER_W = 150
local totalH = HEADER_H + PAD + (#CHAT_CHANNELS + 1) * BTN_H + PAD * 2
local p = CreateFrame("Frame", "AccountRepairedChannelPicker", UIParent, "BackdropTemplate")
p:SetSize(PICKER_W, totalH)
p:SetFrameStrata("TOOLTIP")
p:SetFrameLevel(200)
p:SetClampedToScreen(true)
p:SetBackdrop({
bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile=true, tileSize=32, edgeSize=24,
insets={ left=8, right=8, top=8, bottom=8 },
})
p:SetBackdropColor(0.05, 0.05, 0.05, 0.96)
local title = p:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
title:SetPoint("TOPLEFT", p, "TOPLEFT", 10, -8)
title:SetPoint("TOPRIGHT", p, "TOPRIGHT", -10, -8)
title:SetJustifyH("CENTER")
title:SetText("Send to")
title:SetTextColor(0.75, 0.75, 0.75)
local function AddDivider(yOff)
local sep = p:CreateTexture(nil, "ARTWORK")
sep:SetHeight(1)
sep:SetPoint("TOPLEFT", p, "TOPLEFT", 10, yOff)
sep:SetPoint("TOPRIGHT", p, "TOPRIGHT", -10, yOff)
sep:SetColorTexture(0.4, 0.4, 0.4, 0.6)
end
AddDivider(-(HEADER_H - 2))
-- HidePicker clears both pending fields so a stale value from one code path
-- never accidentally fires in the other on the next open.
local function HidePicker()
p.pendingArmorType = nil
p.pendingPeriod = nil
p:Hide()
end
local function AddPickerButton(yOff, label, r, g, b, onClick)
local btn = CreateFrame("Button", nil, p)
btn:SetHeight(BTN_H)
btn:SetPoint("TOPLEFT", p, "TOPLEFT", 10, yOff)
btn:SetPoint("TOPRIGHT", p, "TOPRIGHT", -10, yOff)
local hl = btn:CreateTexture(nil, "BACKGROUND")
hl:SetAllPoints()
hl:SetColorTexture(r, g, b, 0)
local lbl = btn:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
lbl:SetAllPoints()
lbl:SetJustifyH("CENTER")
lbl:SetText(label)
lbl:SetTextColor(r, g, b)
btn:SetScript("OnEnter", function() hl:SetColorTexture(r, g, b, 0.18) end)
btn:SetScript("OnLeave", function() hl:SetColorTexture(r, g, b, 0) end)
btn:SetScript("OnClick", onClick)
return btn
end
for i, chan in ipairs(CHAT_CHANNELS) do
local yOff = -(HEADER_H + PAD + (i - 1) * BTN_H)
if chan.key == "NONE" then AddDivider(yOff + 1) end
local cr, cg, cb = chan.color[1], chan.color[2], chan.color[3]
-- Each button checks pendingPeriod first (tab right-click path), then
-- falls back to pendingArmorType (bar row left-click path).
AddPickerButton(yOff, chan.label, cr, cg, cb, function()
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
if p.pendingPeriod then
SendAccountTotal(p.pendingPeriod, chan.key)
elseif p.pendingArmorType then
SendRepairBreakdown(p.pendingArmorType, chan.key)
end
HidePicker()
end)
end
local cancelY = -(HEADER_H + PAD + #CHAT_CHANNELS * BTN_H + PAD)
AddDivider(cancelY + 1)
AddPickerButton(cancelY, "|cffff6060" .. CANCEL .. "|r", 0.8, 0.2, 0.2, function()
PlaySound(SOUNDKIT.IG_MAINMENU_CLOSE)
HidePicker()
end)
p:EnableKeyboard(true)
p:SetScript("OnKeyDown", function(self, key)
if key == "ESCAPE" then HidePicker() end
end)
p:Hide()
AR.channelPicker = p
table.insert(UISpecialFrames, "AccountRepairedChannelPicker")
return p
end
-- anchorRow : the frame to anchor the picker below (bar row or period tab)
-- armorType : set when opening from a bar row left-click (nil for tab right-click)
-- period : set when opening from a period tab right-click (nil for bar row)
local function ShowChannelPicker(anchorRow, armorType, period)
local picker = GetOrCreateChannelPicker()
picker.pendingArmorType = armorType
picker.pendingPeriod = period
picker:ClearAllPoints()
picker:SetPoint("TOPLEFT", anchorRow, "BOTTOMLEFT", 0, -4)
picker:Show()
if picker:GetBottom() and picker:GetBottom() < 0 then
picker:ClearAllPoints()
picker:SetPoint("BOTTOMLEFT", anchorRow, "TOPLEFT", 0, 4)
end
end
--------------------------------------------------
-- Bar row
--------------------------------------------------
local function CreateBarRow(parent, width)
local row = CreateFrame("Button", nil, parent)
row:SetSize(width, BAR_ROW_H)
row:EnableMouse(true)
row:RegisterForClicks("LeftButtonUp", "RightButtonUp")
row.highlight = row:CreateTexture(nil, "BACKGROUND")
row.highlight:SetAllPoints()
row.highlight:SetColorTexture(1, 1, 1, 0.1)
row.highlight:Hide()
row.labelText = row:CreateFontString(nil, "OVERLAY", "GameFontNormal")
row.labelText:SetPoint("LEFT", 0, 0)
row.labelText:SetWidth(80)
row.labelText:SetJustifyH("LEFT")
row.bar = CreateFrame("StatusBar", nil, row)
row.bar:SetPoint("LEFT", row.labelText, "RIGHT", 6, 0)
row.bar:SetPoint("RIGHT", row, "RIGHT", -160, 0)
row.bar:SetHeight(BAR_ROW_H - 6)
row.bar:SetMinMaxValues(0, 1)
row.bar:SetValue(0)
row.bar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
row.bar.bg = row.bar:CreateTexture(nil, "BACKGROUND")
row.bar.bg:SetAllPoints()
row.bar.bg:SetColorTexture(0, 0, 0, 0.4)
row.pctText = row:CreateFontString(nil, "OVERLAY", "GameFontNormal")
row.pctText:SetPoint("LEFT", row.bar, "RIGHT", 8, 0)
row.pctText:SetWidth(52)
row.pctText:SetJustifyH("RIGHT")
row.goldText = row:CreateFontString(nil, "OVERLAY", "GameFontNormal")
row.goldText:SetPoint("LEFT", row.pctText, "RIGHT", 6, 0)
row.goldText:SetWidth(102)
row.goldText:SetJustifyH("LEFT")
row:SetScript("OnEnter", function(self)
self.highlight:Show()
if not self.armorType then return end
local chars = GetCharactersByArmorType(self.armorType, AR.currentPeriod)
if #chars == 0 then GameTooltip:Hide(); return end
local col = ARMOR_COLORS[self.armorType] or ARMOR_COLORS.Unknown
local periodCtx = GetPeriodContextLabel(AR.currentPeriod)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine(
string.format("%s |cff888888(%s)|r", L["ARMOR_" .. self.armorType] or self.armorType, periodCtx),
col.r, col.g, col.b)
GameTooltip:AddLine(" ")
for _, ch in ipairs(chars) do
local cc = RAID_CLASS_COLORS[ch.class] or { r=1, g=1, b=1 }
GameTooltip:AddDoubleLine(ch.name, FormatGoldFull(ch.gold),
cc.r, cc.g, cc.b, 1, 1, 1)
end
GameTooltip:AddLine(" ")
GameTooltip:AddLine(L["CLICK_TO_SHARE"] or "Click to share in chat", 0.5, 0.5, 0.5)
GameTooltip:AddLine(L["RCLICK_CHAR_LIST"] or "Right-click for details", 0.5, 0.5, 0.5)
GameTooltip:Show()
end)
row:SetScript("OnLeave", function(self)
self.highlight:Hide()
GameTooltip:Hide()
end)
row:SetScript("OnClick", function(self, button)
if not self.armorType then return end
GameTooltip:Hide()
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
if button == "RightButton" then
AR.ShowCharPanel(self.armorType, false, self)
else
ShowChannelPicker(self, self.armorType, nil)
end
end)
return row
end
--------------------------------------------------
-- Character list panel
--------------------------------------------------
local function CreateListPanel(name)
local p = CreateFrame("Frame", name, UIParent, "BackdropTemplate")
p:SetWidth(CPANEL_W)
p:SetHeight(CPANEL_HEADER_H + CPANEL_PAD)
p:SetFrameStrata("DIALOG")
p:SetFrameLevel(110)
p:SetClampedToScreen(true)
p:SetBackdrop({
bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile=true, tileSize=32, edgeSize=24,
insets={ left=8, right=8, top=8, bottom=8 },
})
p:SetBackdropColor(0.05, 0.05, 0.05, 0.92)
p.titleText = p:CreateFontString(nil, "OVERLAY", "GameFontNormal")
p.titleText:SetPoint("TOPLEFT", p, "TOPLEFT", 12, -10)
p.titleText:SetPoint("TOPRIGHT", p, "TOPRIGHT", -26, -10)
p.titleText:SetJustifyH("LEFT")
local closeBtn = CreateFrame("Button", nil, p, "UIPanelCloseButton")
closeBtn:SetSize(20, 20)
closeBtn:SetPoint("TOPRIGHT", p, "TOPRIGHT", -2, -2)
closeBtn:SetScript("OnClick", function()
p:Hide()
if p == AR.charPanel then AR.charPanelArmor = nil end
end)
local div = p:CreateTexture(nil, "ARTWORK")
div:SetHeight(1)
div:SetPoint("TOPLEFT", p, "TOPLEFT", 10, -(CPANEL_HEADER_H - 2))
div:SetPoint("TOPRIGHT", p, "TOPRIGHT", -10, -(CPANEL_HEADER_H - 2))
div:SetColorTexture(0.4, 0.4, 0.4, 0.8)
p.rows = {}
for i = 1, 20 do
local yOff = -(CPANEL_HEADER_H + CPANEL_PAD + (i - 1) * CPANEL_ROW_H)
local row = CreateFrame("Frame", nil, p)
row:SetHeight(CPANEL_ROW_H)
row:SetPoint("TOPLEFT", p, "TOPLEFT", 10, yOff)
row:SetPoint("TOPRIGHT", p, "TOPRIGHT", -10, yOff)
row.bg = row:CreateTexture(nil, "BACKGROUND")
row.bg:SetAllPoints()
row.bg:SetColorTexture(1, 1, 1, 0)
row.nameText = row:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
row.nameText:SetPoint("LEFT", row, "LEFT", 0, 0)
row.nameText:SetPoint("RIGHT", row, "RIGHT", -120, 0)
row.nameText:SetJustifyH("LEFT")
row.nameText:SetWordWrap(false)
row.goldText = row:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
row.goldText:SetPoint("RIGHT", row, "RIGHT", -52, 0)
row.goldText:SetWidth(80)
row.goldText:SetJustifyH("RIGHT")
row.goldText:SetTextColor(0.85, 0.85, 0.85)
local trashBtn = CreateFrame("Button", nil, row)
trashBtn:SetSize(44, 18)
trashBtn:SetPoint("RIGHT", row, "RIGHT", 0, 0)
local trashLbl = trashBtn:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
trashLbl:SetAllPoints()
trashLbl:SetText("|cffff4040" .. DELETE .. "|r")
trashLbl:SetJustifyH("CENTER")
trashBtn:SetWidth(trashLbl:GetStringWidth() + 8)
row.trashBtn = trashBtn
row:Hide()
p.rows[i] = row
end
p:Hide()
table.insert(UISpecialFrames, name)
return p
end
local function CreateCharPanel()
if AR.charPanel then return AR.charPanel end
local p = CreateListPanel("AccountRepairedCharPanel")
for _, row in ipairs(p.rows) do
row.trashBtn:SetScript("OnEnter", function()
row.bg:SetColorTexture(1, 0.25, 0.25, 0.15)
GameTooltip:SetOwner(row.trashBtn, "ANCHOR_RIGHT")
GameTooltip:SetText(L["CHAR_PANEL_REMOVE_TIP"], 1, 0.35, 0.35)
GameTooltip:Show()
end)
row.trashBtn:SetScript("OnLeave", function()
row.bg:SetColorTexture(1, 1, 1, 0)
GameTooltip:Hide()
end)
row.trashBtn:SetScript("OnClick", function()
if row.charKey then ConfirmDeleteKey(row.charKey) end
end)
end
AR.charPanel = p
return p
end
function AR.ShowCharPanel(armorType, forceShow, anchorRow)
local p = CreateCharPanel()
if not forceShow and AR.charPanelArmor == armorType and p:IsShown() then
p:Hide(); AR.charPanelArmor = nil; return
end
local chars = GetCharactersByArmorType(armorType, AR.currentPeriod)
if #chars == 0 then
p:Hide(); AR.charPanelArmor = nil; return
end
AR.charPanelArmor = armorType
if anchorRow then
p:ClearAllPoints()
p:SetPoint("TOPLEFT", anchorRow, "TOPRIGHT", 6, 0)
elseif not p:IsShown() then
p:ClearAllPoints()
local anchor = (AR.popupFrame and AR.popupFrame:IsShown()) and AR.popupFrame or UIParent
local pt = AR.popupFrame and AR.popupFrame:IsShown() and "TOPRIGHT" or "CENTER"
p:SetPoint("TOPLEFT", anchor, pt, AR.popupFrame and 4 or 0, 0)
end
local col = ARMOR_COLORS[armorType] or ARMOR_COLORS.Unknown
p.titleText:SetText(L["ARMOR_" .. armorType] or armorType)
p.titleText:SetTextColor(col.r, col.g, col.b)
for i, row in ipairs(p.rows) do
local ch = chars[i]
if ch then
local cc = RAID_CLASS_COLORS[ch.class] or { r=1, g=1, b=1 }
row.nameText:SetText(ch.name)
row.nameText:SetTextColor(cc.r, cc.g, cc.b)
row.goldText:SetText(FormatGoldShort(ch.gold))
row.charKey = ch.key
row:Show()
else
row.charKey = nil
row:Hide()
end
end
p:SetHeight(CPANEL_HEADER_H + CPANEL_PAD + #chars * CPANEL_ROW_H + CPANEL_PAD)
p:Show()
end
--------------------------------------------------
-- Period tab bar
--------------------------------------------------
local function CreatePeriodTabs(parent, onSelect)
local tabs = {}
local tabW, tabH, pad = 76, 24, 6
local container = CreateFrame("Frame", nil, parent)
container:SetSize(#PERIOD_ORDER * (tabW + pad) - pad, tabH)
for i, period in ipairs(PERIOD_ORDER) do
local tab = CreateFrame("Button", nil, container, "BackdropTemplate")
tab:SetSize(tabW, tabH)
tab:SetPoint("LEFT", container, "LEFT", (i - 1) * (tabW + pad), 0)
tab:SetBackdrop({
bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile=true, tileSize=16, edgeSize=12,
insets={ left=4, right=4, top=4, bottom=4 },
})
tab.label = tab:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
tab.label:SetAllPoints()
tab.label:SetJustifyH("CENTER")
tab.label:SetText(GetPeriodLabel(period))
tab.period = period
function tab:UpdateState()
if self.period == AR.currentPeriod then
self:SetBackdropColor(0.25, 0.75, 0.25, 0.4)
self.label:SetTextColor(0.2, 1.0, 0.2)
else
self:SetBackdropColor(0.1, 0.1, 0.1, 0.7)
self.label:SetTextColor(0.8, 0.8, 0.8)
end
end
-- Register for both mouse buttons so right-click reaches OnClick.
tab:RegisterForClicks("LeftButtonUp", "RightButtonUp")
tab:SetScript("OnClick", function(self, button)
-- Right-click: share the account total for this tab's period via channel picker.
if button == "RightButton" then
GameTooltip:Hide()
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
ShowChannelPicker(self, nil, self.period)
return
end
-- Left-click: switch the active period as before.
AR.currentPeriod = self.period
AccountRepairedPopupDB.period = self.period
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
onSelect(self.period)
for _, t in ipairs(tabs) do t:UpdateState() end
end)
tab:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_TOP")
GameTooltip:AddLine(GetPeriodLabel(self.period), 1, 1, 1)
GameTooltip:AddLine(GetPeriodContextLabel(self.period), 0.6, 0.6, 0.6)
GameTooltip:AddLine(" ")
GameTooltip:AddLine(L["RCLICK_SHARE_TOTAL"] or "Right-click to share account total", 0.5, 0.5, 0.5)
GameTooltip:Show()
end)
tab:SetScript("OnLeave", function() GameTooltip:Hide() end)
tab:UpdateState()
tabs[i] = tab
end