forked from Lardeck/PermoksAccountManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MartinsAltManager.lua
1396 lines (1168 loc) · 43.3 KB
/
MartinsAltManager.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local addonName, AltManager = ...
AltManager = LibStub("AceAddon-3.0"):NewAddon(AltManager, "MartinsAltManager", "AceConsole-3.0", "AceEvent-3.0")
local AltManagerLDB = LibStub("LibDataBroker-1.1"):NewDataObject("MartinsAltManager", {
type = "data source",
text = "Martins Alt Manager",
icon = "Interface\\Icons\\INV_Chest_Cloth_17",
OnClick = function(self, button)
if button == "LeftButton" then
if AltManagerFrame:IsShown() then
AltManager:HideInterface()
else
AltManager:ShowInterface()
end
elseif button == "RightButton" then
AltManager:OpenOptions()
end
end,
OnTooltipShow = function(tt)
tt:AddLine("|cfff49b42Martins Alt Manager|r")
tt:AddLine("|cffffffffLeft-click|r to open MartinsAltManager")
tt:AddLine("|cffffffffRight-click|r to open options")
tt:AddLine("Type '/mam minimap' to hide the Minimap Button!")
end
})
local LibIcon = LibStub("LibDBIcon-1.0")
local LibQTip = LibStub("LibQTip-1.0")
local L = LibStub("AceLocale-3.0"):GetLocale(addonName)
local VERSION = "9.0.19.9"
local INTERNALVERSION = 11
local INTERNALBCVERSION = 1
local defaultDB = {
profile = {
minimap = {
hide = false,
},
},
global = {
blacklist = {},
accounts = {
main = {
name = L["Main"],
data = {},
pages = {},
}
},
currentPage = 1,
charactersPerPage = 6,
numAccounts = 1,
data = {},
completionData = {['**'] = {numCompleted = 0}},
alts = 0,
synchedCharacters = {},
blockedCharacters = {},
options = {
buttons = {
updated = false,
buttonWidth = 120,
buttonTextWidth = 120,
justifyH = "CENTER",
},
other = {
updated = false,
labelOffset = 15,
widthPerAlt = 120,
frameStrata = "MEDIUM",
},
savePosition = false,
showOptionsButton = true,
showGuildAttunementButton = false,
currencyIcons = true,
itemIcons = true,
guildToTrack = "Jade Falcons",
customCategories = {
general = {
childOrder = {characterName = 0, ilevel = 0.5},
childs = {"characterName", "ilevel"},
order = 0,
hideToggle = true,
name = "General",
enabled = true,
},
['**'] = {childOrder = {}, childs = {}, enabled = true}
},
defaultCategories = {
['**'] = {
enabled = true
},
}
},
currentCallings = {},
quests = {},
currencyIcons = {},
itemIcons = {},
position = {},
version = VERSION,
},
}
local function spairs(t, order)
local keys = {}
for k in pairs(t) do keys[#keys+1] = k end
if order then
table.sort(keys, function(a,b) return order(t, a, b) end)
else
table.sort(keys)
end
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], t[keys[i]], keys[i+1]
end
end
end
function AltManager:Debug(...)
if self.db.global.options.debug then
self:Print(...)
end
end
function AltManager:CreateMainFrame()
local main_frame = CreateFrame("Frame", "AltManagerFrame", UIParent)
self.main_frame = main_frame
main_frame:SetFrameStrata(self.db.global.options.other.frameStrata)
main_frame.background = main_frame:CreateTexture(nil, "BACKGROUND")
main_frame.background:SetAllPoints()
main_frame.background:SetDrawLayer("ARTWORK", 1)
main_frame.background:SetColorTexture(0, 0, 0.1, 0.8)
main_frame:ClearAllPoints()
if self.db.global.options["savePosition"] then
local position = self.db.global.position
main_frame:SetPoint(position.point or "TOP", WorldFrame, position.relativePoint or "TOP", position.xOffset or 0, position.yOffset or -300)
else
main_frame:SetPoint("TOP", WorldFrame, "TOP", 0, -300)
end
main_frame:Hide()
main_frame.label_column = CreateFrame("Button", nil, self.main_frame)
main_frame.label_column:SetPoint("TOPLEFT", self.main_frame, "TOPLEFT")
main_frame.label_column:SetPoint("BOTTOMRIGHT", self.main_frame, "BOTTOMLEFT", 120, 0)
main_frame.unrollLabelColumn = CreateFrame("Button", nil, self.main_frame)
main_frame.unrollLabelColumn:Show()
main_frame.altColumns = {general = {}}
return main_frame
end
local altManagerEvents = {
"BAG_UPDATE_DELAYED",
"CHAT_MSG_PARTY",
"CHAT_MSG_PARTY_LEADER",
"CHAT_MSG_GUILD",
"PLAYER_MONEY",
}
function AltManager:OnInitialize()
self.spairs = spairs
-- init databroker
self.db = LibStub("AceDB-3.0"):New("MartinsAltManagerDB", defaultDB, true)
AltManager:RegisterChatCommand('mam', 'HandleChatCommand')
AltManager:RegisterChatCommand('alts', 'HandleChatCommand')
LibIcon:Register("MartinsAltManager", AltManagerLDB, self.db.profile.minimap)
local main_frame = AltManager:CreateMainFrame()
main_frame:RegisterEvent("PLAYER_ENTERING_WORLD")
main_frame:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_ENTERING_WORLD" then
local isLogin, isReload = ...
if isLogin or isReload then
AltManager:OnLogin()
FrameUtil.RegisterFrameForEvents(main_frame, altManagerEvents)
end
end
if event == "CHAT_MSG_PARTY" or event == "CHAT_MSG_PARTY_LEADER" then
local msg = ...
if msg and msg:lower() == "!allkeys" then
AltManager:PostKeysIntoChat("party")
end
elseif event == "CHAT_MSG_GUILD" then
local msg = ...
if msg and msg:lower() == "!allkeys" then
AltManager:PostKeysIntoChat("guild")
end
elseif AltManager.addon_loaded then
if event == "BAG_UPDATE_DELAYED" then
AltManager:CollectData()
AltManager:SendCharacterUpdate("charLevel")
elseif event == "PLAYER_MONEY" then
AltManager:UpdateGold()
AltManager:SendCharacterUpdate("gold")
elseif event =="CHALLENGE_MODE_COMPLETED" then
AltManager:UpdateMythicScore()
end
end
end)
end
function AltManager:OnEnable()
self.addon_loaded = true
if not self.isBC then
tinsert(altManagerEvents, "CHALLENGE_MODE_COMPLETED")
end
end
function AltManager:OnDisable()
self.addon_loaded = false
end
function AltManager:IsBCCClient()
return WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC
end
function AltManager:CheckForModernize()
local internalVersion = self.db.global.internalVersion
if not internalVersion or internalVersion < INTERNALVERSION then
self:Modernize(internalVersion)
end
self.db.global.internalVersion = INTERNALVERSION
end
function AltManager:Modernize(oldInternalVersion)
local db = self.db
local data = db.global.data
if not oldInternalVersion then
for alt_guid, alt_data in pairs(data) do
local questInfo = alt_data.questInfo
questInfo.daily.maw_dailies = questInfo.daily.maw
questInfo.daily.maw = nil
questInfo.daily.transport_network = questInfo.daily.nfTransport
questInfo.daily.nfTransport = nil
questInfo.weekly.dungeon_quests = questInfo.weekly.dungeon
questInfo.weekly.dungeon = nil
questInfo.weekly.pvp_quests = questInfo.weekly.pvp
questInfo.weekly.pvp = nil
questInfo.weekly.weekend_event = questInfo.weekly.weekend
questInfo.weekly.weekend = nil
questInfo.weekly.world_boss = questInfo.weekly.wb
questInfo.weekly.wb = nil
questInfo.weekly.maw_souls = questInfo.weekly.souls
questInfo.weekly.souls = nil
questInfo.weekly.maw_weekly = questInfo.weekly.maw
questInfo.weekly.maw = nil
end
local blacklist = self.db.global.blacklist
for guid, name in pairs(self.db.global.blacklist) do
blacklist[guid] = {name = name, class = data[guid].class, realm = data[guid].realm}
end
oldInternalVersion = 1
end
if oldInternalVersion < 2 then
self:UpdateDefaultCategories("items")
oldInternalVersion = 2
end
if oldInternalVersion < 3 then
db.global.accounts.main.data = (data and data) or (db.battleTag and db.global.accounts[db.battleTag] and db.global.accounts[db.battleTag].data) or db.global.accounts.main.data
local accountTable = db.global.accounts.main
local numCharacter = 1
for alt_guid, alt_data in pairs(accountTable.data) do
local page = floor(numCharacter/db.global.charactersPerPage) + 1
accountTable.pages[page] = accountTable.pages[page] or {}
tinsert(accountTable.pages[page], alt_guid)
alt_data.page = page
numCharacter = numCharacter + 1
end
db.global.data = nil
self:UpdateDefaultCategories("items")
self:UpdateDefaultCategories("general")
oldInternalVersion = 3
end
if oldInternalVersion < 8 then
wipe(AltManager.db.global.options.defaultCategories.general)
oldInternalVersion = 9
BasicMessageDialog.Text:SetText("[MartinsAltManager]\n Default Categories have been reset.")
BasicMessageDialog:Show()
end
if oldInternalVersion < 9 then
self:UpdateDefaultCategories("currentdaily")
oldInternalVersion = 9
end
if oldInternalVersion < 10 then
for key, info in pairs(self.db.global.accounts) do
for alt_guid, alt_data in pairs(info.data) do
for questType, keys in pairs(alt_data.questInfo) do
if type(keys) == "table" then
wipe(alt_data.questInfo[questType])
end
end
end
end
self:UpdateDefaultCategories("currentweekly")
oldInternalVersion = 10
end
----------------------------------------------
-- - Fix raidActivityInfo not resetting weekly
-- - Fix biweekly reset calculation
if oldInternalVersion < 11 then
for key, info in pairs(self.db.global.accounts) do
for alt_guid, alt_data in pairs(info.data) do
alt_data.raidActivityInfo = {}
alt_data.biweekly = time() + self:GetNextBiWeeklyResetTime()
end
end
oldInternalVersion = 11
end
end
function AltManager:getGUID()
self.myGUID = self.myGUID or UnitGUID("player")
return self.myGUID
end
local function Tooltip_OnLeave(self)
if self.tooltip then
LibQTip:Release(self.tooltip)
self.tooltip = nil
end
end
function AltManager.validateData()
local guid = AltManager:getGUID()
if not guid then return end
if AltManager:isBlacklisted(guid) then return end
local db = AltManager.db
local data = AltManager.db.global.accounts.main.data
local char_table = data[guid]
return char_table
end
function AltManager:SortPages()
local account = self.db.global.accounts.main
local data = account.data
local sortKey = self.isBC and "charLevel" or "ilevel"
wipe(account.pages)
local enabledAlts = 1
for alt_guid, alt_data in self.spairs(data, function(t, a, b) if t[a] and t[b] then return t[a][sortKey] > t[b][sortKey] end end) do
if not self.db.global.blacklist[alt_guid] then
local page = ceil(enabledAlts/self.db.global.charactersPerPage)
account.pages[page] = account.pages[page] or {}
tinsert(account.pages[page], alt_guid)
enabledAlts = enabledAlts + 1
alt_data.page = page
end
end
if self.db.global.currentPage > #account.pages then
self.db.global.currentPage = #account.pages
end
for i=1, #account.pages do
table.sort(account.pages[i], function(a, b) if data[a] and data[b] then return data[a][sortKey] > data[b][sortKey] end end)
end
end
function AltManager:AddNewCharacter(account, guid, alts)
local data = account.data
data[guid] = {}
local page = ceil(alts/self.db.global.charactersPerPage)
account.pages[page] = account.pages[page] or {}
tinsert(account.pages[page], guid)
data[guid].page = page
end
function AltManager:SaveBattleTag(db)
if not db.battleTag then
local _, battleTag = BNGetInfo()
db.battleTag = battleTag
end
end
function AltManager:OnLogin()
local db = self.db.global
local guid = self:getGUID()
local level = UnitLevel("player")
local min_level = GetMaxLevelForExpansionLevel(GetExpansionLevel())
local min_test_level = 0
self.isBC = WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC
self:SaveBattleTag(db)
self:CheckForModernize()
self.account = db.accounts.main
self:ValidateReset()
local data = self.account.data
if guid and not data[guid] and not self:isBlacklisted(guid) and (not (level < min_level) or not (level < min_test_level)) then
db.alts = db.alts + 1
self:AddNewCharacter(self.account, guid, db.alts)
end
self.char_table = data[guid]
self:RequestCharacterInfo()
self:UpdateEverything()
self:UpdateCurrentlyActiveQuests()
self:SortPages(self.account)
self.LoadOptions()
db.currentCategories = db.custom and db.options.customCategories or db.options.defaultCategories
self:UpdateCompletionData()
self.main_frame.background:SetAllPoints()
self:UpdateAltAnchors("general", self.main_frame.label_column)
self:CreateMenuButtons()
self:UpdateMenu(db.alts)
self:MakeTopBottomTextures(self.main_frame)
if #self.account.pages > 1 then
self:UpdatePageButtons()
end
if self.char_table and not self.char_table.page then
self.char_table.page = self:FindPageForGUID(guid)
end
self:UpdateAccounts()
C_Timer.After(self:GetNextWeeklyResetTime(), function() self:ValidateReset() end)
end
local CreateFontFrame
do
local normalFont = CreateFont("MAM_NormalFont")
normalFont:SetFont("Fonts\\FRIZQT__.TTF", 11)
normalFont:SetTextColor(1, 1, 1, 1)
local smallFont = CreateFont("MAM_SmallFont")
smallFont:SetFont("Fonts\\FRIZQT__.TTF", 9)
smallFont:SetTextColor(1, 1, 1, 1)
local function createColumnFont(button, column, alt_data, text, buttonOptions)
text = text or column.data(alt_data)
button:SetNormalFontObject(column.small and smallFont or normalFont)
button:SetText(text)
local fontString = button:GetFontString()
if fontString then
button.fontString = fontString
fontString:SetSize(105, 20)
fontString:SetJustifyV(column.justify or "MIDDLE")
fontString:SetJustifyH(buttonOptions.justifyH)
end
end
local function createLabelFont(button, text, buttonOptions)
button:SetNormalFontObject(normalFont)
button:SetText(text .. ":")
local fontString = button:GetFontString()
fontString:SetSize(120, 20)
fontString:SetJustifyV("CENTER")
fontString:SetJustifyH("RIGHT")
end
function CreateFontFrame(parent, column, alt_data, text, index, width)
local buttonOptions = AltManager.db.global.options.buttons
local button = CreateFrame("Button", nil, parent)
button:SetSize(width or buttonOptions.buttonWidth, 20)
button:SetPushedTextOffset(0, 0)
--button:SetFrameStrata("MEDIUM")
if column then
if not column.hideOption and not column.fakeLabel then
local highlightTexture = button:CreateTexture()
highlightTexture:SetAllPoints()
highlightTexture:SetColorTexture(0.5, 0.5, 0.5, 0.5)
button:SetHighlightTexture(highlightTexture)
if index then
local normalTexture = button:CreateTexture(nil, "BACKGROUND")
normalTexture:SetAllPoints()
button:SetNormalTexture(normalTexture)
button.normalTexture = normalTexture
end
end
createColumnFont(button, column, alt_data, text, buttonOptions)
else
createLabelFont(button, text, buttonOptions)
end
return button
end
end
function AltManager:timeToDaysHoursMinutes(expirationTime)
if expirationTime == 0 then return 0 end
local remaining = expirationTime - time()
local days = floor(remaining / 86400)
local hours = floor((remaining/3600) - (days * 24))
local minutes = floor((remaining / 60) - (days * 1440) - (hours * 60))
return days, hours, minutes
end
function AltManager:ValidateReset()
local db = self.db.global
local data = self.account.data
for account, accountData in pairs(db.accounts) do
for alt_guid, char_table in pairs(accountData.data) do
local expiry = char_table.expires or 0
local daily = char_table.daily or 0
local biweekly = char_table.biweekly or 0
local currentTime = time()
--modernize
if type(char_table.currencyInfo) ~= "table" then
char_table.currencyInfo = {}
end
if currentTime > expiry then
wipe(db.completionData)
-- M0/Raids
if char_table.instanceInfo then
char_table.instanceInfo.raids = {}
char_table.instanceInfo.dungeons = {}
end
-- Torghast
if char_table.torghastInfo then
wipe(char_table.torghastInfo)
end
-- Vault
if char_table.vaultInfo then
for activityType, activityInfos in pairs(char_table.vaultInfo) do
for i, activityInfo in ipairs(activityInfos) do
activityInfo.level = 0
activityInfo.progress = 0
end
end
end
char_table.raidActivityInfo = {}
-- M+
char_table.dungeon = "Unknown";
char_table.level = "?";
-- Weekly Quests
if char_table.questInfo and char_table.questInfo.weekly then
for visibility, quests in pairs(char_table.questInfo.weekly) do
wipe(char_table.questInfo.weekly[visibility])
end
end
-- Reset
char_table.expires = currentTime + self:GetNextWeeklyResetTime();
end
if currentTime > daily then
wipe(db.completionData)
if char_table.completedDailies then
wipe(char_table.completedDailies)
end
-- Callings
if char_table.callingsUnlocked and char_table.callingInfo and char_table.callingInfo.numCallings and char_table.callingInfo.numCallings < 3 then
char_table.callingInfo.numCallings = char_table.callingInfo.numCallings + 1
char_table.callingInfo[#char_table.callingInfo + 1] = currentTime + self:GetNextDailyResetTime() + (86400*2)
end
if char_table.covenant and db.currentCallings[char_table.covenant] then
for questID, currentCallingInfo in pairs(db.currentCallings[char_table.covenant]) do
if currentCallingInfo.timeRemaining and currentCallingInfo.timeRemaining < time() then
db.currentCallings[char_table.covenant][questID] = nil
end
end
end
-- Eye of the Jailer
if char_table.jailerInfo then
char_table.jailerInfo.stage = 0
char_table.jailerInfo.threat = 0
end
-- Daily Quests
if char_table.questInfo and char_table.questInfo.daily then
for visibility, quests in pairs(char_table.questInfo.daily) do
wipe(char_table.questInfo.daily[visibility])
end
end
-- Reset
char_table.daily = currentTime + self:GetNextDailyResetTime()
end
if currentTime > biweekly then
if char_table.questInfo and char_table.questInfo.biweekly then
for visibility, quests in pairs(char_table.questInfo.biweekly) do
wipe(char_table.questInfo.biweekly[visibility])
end
end
char_table.biweekly = currentTime + self:GetNextBiWeeklyResetTime()
end
end
end
end
function AltManager:RequestCharacterInfo()
if not self.isBC then
RequestRatedInfo()
CovenantCalling_CheckCallings()
end
end
function AltManager:UpdateEverything()
if self.isBC then
self:UpdateAllBCCQuests()
self:UpdateLocation()
self:UpdateProfessions()
self:UpdateProfessionCDs()
else
self:UpdateAllRetailQuests()
self:UpdateTorghast()
self:UpdateVaultInfo()
self:UpdateSanctumBuildings()
self:UpdatePVPRating()
self:UpdateMythicScore()
end
self:CollectData()
self:UpdateInstanceInfo()
self:UpdateAllCurrencies()
self:UpdateFactions()
self:UpdateItemCounts()
end
function AltManager:UpdateCompletionData()
local db = self.db.global
local accountData = db.accounts.main
for alt_guid, alt_data in pairs(accountData.data) do
for key, info in pairs(self.columns) do
if info.isComplete then
self:SaveCompletionData(key, info.isComplete(alt_data), alt_guid)
end
end
end
end
function AltManager:UpdateCompletionDataForCharacter()
local char_table = self.validateData()
if not char_table then return end
for key, info in pairs(self.columns) do
if info.isComplete then
self:SaveCompletionData(key, info.isComplete(char_table), char_table.guid)
end
end
end
function AltManager:UpdateGold()
local char_table = self.validateData()
if not char_table then return end
char_table.gold = floor(GetMoney() / (COPPER_PER_SILVER * SILVER_PER_GOLD)) * 10000
end
function AltManager:CollectData()
local guid = self:getGUID()
if not guid then return end
local char_table = self.validateData()
if not char_table then return end
char_table.guid = guid
-- Basic
local name, realm = UnitFullName('player')
char_table.name = name
char_table.realm = realm
local charLevel = UnitLevel("player")
char_table.charLevel = charLevel
local _, class = UnitClass('player')
char_table.class = class
local faction = UnitFactionGroup("player")
char_table.faction = faction
char_table.gold = floor(GetMoney() / (COPPER_PER_SILVER * SILVER_PER_GOLD)) * 10000
local currentTime = time()
char_table.expires = currentTime + self:GetNextWeeklyResetTime()
char_table.daily = currentTime + self:GetNextDailyResetTime()
char_table.biweekly = currentTime + self:GetNextBiWeeklyResetTime()
if not self.isBC then
local _, ilevel = GetAverageItemLevel()
char_table.ilevel = ilevel
-- Keystone
local ownedKeystone = C_MythicPlus.GetOwnedKeystoneChallengeMapID()
local dungeon = "Unknown"
local level = "?"
if ownedKeystone then
dungeon = self.keys[ownedKeystone]
level = C_MythicPlus.GetOwnedKeystoneLevel()
end
char_table.dungeon = dungeon
char_table.level = level
-- Contracts
local contract = nil
local contracts = {[311457] = "CoH",[311458] = "Ascended",[311460] = "UA",[311459] = "WH", [353999] = "DA"}
for spellId, faction in pairs(contracts) do
local info = {GetPlayerAuraBySpellID(spellId)}
if info[1] then
contract = {faction = faction, duration = info[5], expirationTime = time() + (info[6] - GetTime())}
break
end
end
char_table.contract = contract
-- Covenant
local covenant = C_Covenants.GetActiveCovenantID()
char_table.covenant = covenant > 0 and covenant
local renown = C_CovenantSanctumUI.GetRenownLevel()
char_table.renown = renown
local callingsUnlocked = C_CovenantCallings.AreCallingsUnlocked()
char_table.callingsUnlocked = callingsUnlocked
end
end
function AltManager:UpdateMythicScore()
local char_table = self.char_table
if not char_table then return end
char_table.mythicScore = C_ChallengeMode.GetOverallDungeonScore and C_ChallengeMode.GetOverallDungeonScore()
end
function AltManager:UpdateAccountButtons()
local db = self.db.global
if db.numAccounts == 1 then return end
self.main_frame.accountButtons = self.main_frame.accountButtons or {}
local accountIndex = 0
for accountName, accountInfo in self.spairs(db.accounts, function(t, a, b) return a == "main" end) do
local accountButton = self.main_frame.accountButtons[accountName] or CreateFrame("Button", nil, AltManager.main_frame, "UIPanelButtonTemplate")
if not self.main_frame.accountButtons[accoutName] then
accountButton:SetSize(100, 20)
accountButton:SetText(accountInfo.name or accountName)
accountButton:Show()
accountButton:SetScript("OnClick", function()
AltManager.db.global.currentPage = 1
AltManager.account = accountInfo
AltManager:RollUpAll()
AltManager:UpdateAltAnchors("general", self.main_frame.label_column)
AltManager:PopulateStrings(1, "general")
AltManager:UpdatePageButtons()
AltManager:UpdateMainFrameSize()
end)
end
accountButton:SetPoint("BOTTOMLEFT", self.main_frame, "TOPLEFT", accountIndex * 100, 32)
self.main_frame.accountButtons[accountName] = accountButton
accountIndex = accountIndex + 1
end
for accountName, button in pairs(self.main_frame.accountButtons) do
if not self.db.global.accounts[accountName] then
button:Hide()
end
end
end
function AltManager:UpdatePageButtons()
local db = self.db.global
local pages = self.account.pages
self.main_frame.pageButtons = self.main_frame.pageButtons or {}
if #pages == 1 then
for pageNumber, button in pairs(self.main_frame.pageButtons) do
button:Hide()
end
else
for pageNumber, alts in pairs(pages) do
local pageButton = self.main_frame.pageButtons[pageNumber] or CreateFrame("Button", nil, AltManager.main_frame, "UIPanelButtonTemplate")
if not self.main_frame.pageButtons[pageNumber] then
pageButton:SetSize(45, 25)
pageButton:SetText(pageNumber)
--pageButton:SetFrameStrata("MEDIUM")
if pageNumber == self.db.global.currentPage then
pageButton:SetText("[" .. pageNumber .. "]")
else
pageButton:SetText(pageNumber)
end
end
pageButton:Show()
pageButton:SetPoint("TOPLEFT", self.main_frame, "BOTTOMLEFT", (pageNumber - 1) * 45 + 3, -4)
pageButton:SetScript("OnClick", function(self)
for buttonPageNumber, button in pairs(AltManager.main_frame.pageButtons) do
button:SetText(buttonPageNumber)
end
self:SetText("[" .. pageNumber .. "]")
AltManager.db.global.currentPage = pageNumber
AltManager:UpdateAltAnchors("general", AltManager.main_frame.label_column)
AltManager:PopulateStrings(pageNumber, "general")
AltManager:UpdateMainFrameSize(true)
if AltManager.main_frame.openUnroll then
local category = AltManager.main_frame.openUnroll
AltManager:UpdateAltAnchors(category, AltManager.main_frame.unrollLabelColumn[category])
AltManager:PopulateStrings(nil, category)
end
end)
self.main_frame.pageButtons[pageNumber] = pageButton
end
end
end
local function UpdateOrCreateMenu(category, anchorFrame, parent)
local db = AltManager.db.global
local completionData = db.completionData
local childs = db.currentCategories[category].childs
local options = db.currentCategories[category].childOrder
if not options then return end
AltManager.main_frame.labels = AltManager.main_frame.labels or {}
AltManager.main_frame.labels[category] = AltManager.main_frame.labels[category] or {}
local labels = AltManager.main_frame.labels[category]
local alts = #AltManager.account.pages[AltManager.db.global.currentPage]
local enabledRows = 0
for j, row_iden in pairs(childs) do
local row = AltManager.columns[row_iden]
if row and row.label then
-- parent, column, alt_data, text
local text = type(row.label) == "function" and row.label() or row.label
local label_row = labels[row_iden] or CreateFontFrame(parent or anchorFrame, nil, nil, text, nil, 120)
labels[row_iden] = label_row
label_row:SetPoint("TOPLEFT", anchorFrame, "TOPLEFT", 0, -enabledRows*20)
label_row:Show()
if completionData[row_iden] and completionData[row_iden].numCompleted == alts then
label_row:GetFontString():SetTextColor(0, 1, 0, 1)
else
label_row:GetFontString():SetTextColor(1, 1, 1, 1)
end
enabledRows = enabledRows + 1
elseif row and row.fakeLabel then
enabledRows = enabledRows + 1
end
end
for row_iden, label in pairs(labels) do
if not options[row_iden] then
label:Hide()
end
end
return enabledRows
end
local function updateButtonTexture(button, index)
if button.normalTexture then
if index % 2 == 0 then
button.normalTexture:SetColorTexture(0.7, 0.7, 0.7, 0.25)
else
button.normalTexture:SetColorTexture(0.3, 0.3, 0.3, 0.25)
end
end
end
function AltManager:UpdateButton(button, buttonOptions)
button:SetWidth(buttonOptions.buttonWidth)
local fontString = button:GetFontString()
if fontString then
fontString:SetJustifyH(buttonOptions.justifyH)
fontString:SetWidth(buttonOptions.buttonTextWidth)
end
end
function AltManager:UpdateAltAnchors(category, customAnchorFrame)
self.main_frame.altColumns[category] = self.main_frame.altColumns[category] or {}
local db = self.db.global
local altDataForPage = self.account.pages[db.currentPage or 1]
if not altDataForPage then return end
local widthPerAlt = db.options.other.widthPerAlt
local labelOffset = db.options.other.labelOffset
local altColumns = self.main_frame.altColumns[category]
if #altColumns > #altDataForPage then
for index = #altDataForPage + 1, #altColumns do
altColumns[index]:Hide()
end
end
for index, alt_guid in ipairs(altDataForPage) do
local anchorFrame = altColumns[index] or CreateFrame("Button", nil, customAnchorFrame)
anchorFrame:SetPoint("TOPLEFT", customAnchorFrame, "TOPRIGHT", (widthPerAlt * (index - 1)) + labelOffset, -1)
anchorFrame:SetPoint("BOTTOMRIGHT", customAnchorFrame, "BOTTOMLEFT", (widthPerAlt * index) + widthPerAlt + labelOffset, 1)
anchorFrame.GUID = alt_guid
anchorFrame:Show()
altColumns[index] = anchorFrame
anchorFrame.rows = anchorFrame.rows or {}
end
end
function AltManager:UpdateColumnForAlt(alt_guid, anchorFrame, category)
local db = self.db.global
local buttonOptions = db.options.buttons
local childs = db.currentCategories[category].childs
local enabledChilds = db.currentCategories[category].childOrder
local altData = self.account.data[alt_guid]
if not altData then return end
local rows = anchorFrame.rows
local enabledRows = 0
for index, column_identifier in pairs(childs) do
local column = self.columns[column_identifier]
if column and enabledChilds[column_identifier] then
local text = (column.type and self.functions[column.type](altData, column)) or (column.data and column.data(altData)) or "-"
local row = rows[column_identifier] or CreateFontFrame(anchorFrame, column, altData, text, enabledRows)
rows[column_identifier] = row
row:SetPoint("TOPLEFT", anchorFrame, "TOPLEFT", 0, -enabledRows * 20)
row:SetText(text)
row:Show()
updateButtonTexture(row, enabledRows)
self:UpdateButton(row, buttonOptions)
if column.tooltip then
row:SetScript("OnEnter", function(self)
column.tooltip(self, altData)
end)
row:SetScript("OnLeave", Tooltip_OnLeave)
end
if column.color and row.fontString then
row.fontString:SetTextColor(column.color(altData):GetRGBA())
end
enabledRows = enabledRows + 1
end
end
for column_identifier, row in pairs(rows) do
if not enabledChilds[column_identifier] then
row:Hide()
end
end
end
function AltManager:PopulateStrings(page, category)
local db = self.db.global
local page = self.account.pages[page or self.db.global.currentPage]