-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPermoksAccountManager.lua
More file actions
2194 lines (1895 loc) · 64.1 KB
/
PermoksAccountManager.lua
File metadata and controls
2194 lines (1895 loc) · 64.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local addonName, PermoksAccountManager = ...
PermoksAccountManager =
LibStub("AceAddon-3.0"):NewAddon(PermoksAccountManager, "PermoksAccountManager", "AceConsole-3.0", "AceEvent-3.0")
-- Create minimap icon with LibDataBroker.
local PermoksAccountManagerLDB = LibStub("LibDataBroker-1.1"):NewDataObject("PermoksAccountManager", {
type = "data source",
text = "Permoks Account Manager",
icon = "Interface/Icons/achievement_guildperk_everybodysfriend.blp",
OnClick = function(self, button)
if button == "LeftButton" then
if PermoksAccountManager.db.global.options.showOnEnter then
PermoksAccountManager:ShowInterface()
PermoksAccountManager.openedByClick = true
elseif PermoksAccountManagerFrame:IsShown() then
PermoksAccountManager:HideInterface()
else
PermoksAccountManager:ShowInterface()
end
elseif button == "RightButton" then
PermoksAccountManager:OpenOptions(true)
end
end,
OnTooltipShow = function(tt)
if PermoksAccountManager.db.global.options.showOnEnter then
PermoksAccountManager:ShowInterface()
PermoksAccountManager.openedByClick = nil
end
tt:AddLine("|cfff49b42Permoks Account Manager|r")
tt:AddLine("|cffffffffLeft-click|r to open the Manager")
tt:AddLine("|cffffffffRight-click|r to open options")
tt:AddLine("Type '/pam minimap' to hide the Minimap Button!")
end,
OnLeave = function()
if PermoksAccountManager.db.global.options.showOnEnter and not PermoksAccountManager.openedByClick then
PermoksAccountManager:HideInterface()
PermoksAccountManager.openedByClick = nil
end
end,
})
BINDING_HEADER_PAM = addonName
local AceGUI = LibStub("AceGUI-3.0")
local LibIcon = LibStub("LibDBIcon-1.0")
local LibQTip = LibStub("LibQTip-1.0")
local L = LibStub("AceLocale-3.0"):GetLocale(addonName)
local LSM = LibStub("LibSharedMedia-3.0")
local VERSION = C_AddOns.GetAddOnMetadata(addonName, "Version")
local INTERNALMIDNIGHT = 2
local INTERNALWOTLKVERSION = 6
local INTERNALCATAVERSION = 3
local INTERNALMISTSVERSION = 1
local defaultDB = {
profile = {
minimap = {
hide = false,
},
},
global = {
blacklist = {},
pages = {},
accounts = {
main = {
name = L["Main"],
data = {
["**"] = {
customData = {},
},
},
warbandData = {
name = "Warband",
},
pages = {},
},
},
currentPage = 1,
numAccounts = 1,
data = {},
completionData = { ["**"] = { numCompleted = 0 } },
alts = 0,
synchedCharacters = {},
blockedCharacters = {},
syncedAccountKeys = {},
customLabels = false,
options = {
buttons = {
updated = false,
buttonWidth = 120,
buttonTextWidth = 110,
widthPerAlt = 120,
justifyH = "LEFT",
},
other = {
updated = false,
labelOffset = 5,
frameStrata = "MEDIUM",
},
characters = {
charactersPerPage = 6,
minLevel = GetMaxLevelForExpansionLevel(GetExpansionLevel()) - 10,
combine = false,
sortBy = "order",
sortByLesser = true,
},
border = {
edgeSize = 5,
color = { 0.39, 0.39, 0.39, 1 },
bgColor = { 0, 0, 0, 0.9 },
},
font = "Expressway",
fontSize = 11,
hideWarband = false,
savePosition = false,
showOptionsButton = false,
showGuildAttunementButton = false,
currencyIcons = true,
itemIcons = true,
useScoreColor = true,
showCurrentSpecIcon = true,
currentCharacterFirstPosition = false,
questCompletionString = "True",
useOutline = true,
itemIconPosition = "right",
currencyIconPosition = "right",
showOnEnter = false,
customCategories = {
general = {
childOrder = { characterName = 1, ilevel = 2 },
childs = { "characterName", "ilevel" },
order = 0,
hideToggle = true,
name = "General",
enabled = true,
},
["**"] = { childOrder = {}, childs = {}, enabled = true },
},
defaultCategories = {
["**"] = {
enabled = true,
},
},
customLabels = {
quest = {},
item = {},
currency = {},
custom = {},
},
},
currentCallings = {},
quests = {},
currencyInfo = {},
itemIcons = {},
position = {},
version = VERSION,
},
}
--- Create an iterator for a hash table.
-- @param t:table The table to create the iterator for.
-- @param order:function A sort function for the keys.
-- @return function The iterator usable in a loop.
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
--- This function will be called when the user leaves the button the tooltip belonged to.
local function Tooltip_OnLeave(self)
if self.tooltip then
LibQTip:Release(self.tooltip)
self.tooltip = nil
end
end
local CreateLabelButton, CreateManagerButton, LoadFonts, UpdateFonts
do
local normalFont, smallFont, mediumLargeFont, largeFont
--- Initialize the fonts
function LoadFonts()
local options = PermoksAccountManager.db.global.options
local outline = options.useOutline and "OUTLINE" or nil
local font = LSM:Fetch("font", options.font)
font = font or "Fonts\\FRIZQT__.TTF"
normalFont = CreateFont("PAM_NormalFont")
normalFont:SetFont(font, options.fontSize, outline)
normalFont:SetTextColor(1, 1, 1, 1)
smallFont = CreateFont("PAM_SmallFont")
smallFont:SetFont(font, 9, outline)
smallFont:SetTextColor(1, 1, 1, 1)
mediumLargeFont = CreateFont("PAM_MediumLargeFont")
mediumLargeFont:SetFont(font, options.fontSize + 2, outline)
mediumLargeFont:SetTextColor(1, 1, 1, 1)
largeFont = CreateFont("PAM_LargeFont")
largeFont:SetFont(font, max(17, options.fontSize + 2), outline)
largeFont:SetTextColor(1, 1, 1, 1)
end
--- Update the font path of all previously created fonts.
function UpdateFonts()
local options = PermoksAccountManager.db.global.options
local outline = options.useOutline and "OUTLINE" or ""
local font = LSM:Fetch("font", options.font)
normalFont:SetFont(font, options.fontSize, outline)
smallFont:SetFont(font, 9, outline)
mediumLargeFont:SetFont(font, options.fontSize + 2, outline)
largeFont:SetFont(font, max(17, options.fontSize + 2), outline)
end
--- Create the text for a normal button.
-- @param button:Button The button to create the font object for.
-- @param column:table The information table for the current column.
-- @param alt_data:table A table with information about a character.
-- @param text:string Text that can be used instead of generating a new one with alt_data.
-- @param buttonOptions:table
-- TODO
local function CreateInfoButton(button, column, buttonOptions)
button:SetNormalFontObject((column.big and largeFont) or (column.small and smallFont) or normalFont)
button:SetText(" ")
local fontString = button:GetFontString()
if fontString then
button.fontString = fontString
fontString:SetSize(110, 20)
fontString:SetJustifyV(column.justify or "MIDDLE")
fontString:SetJustifyH(buttonOptions.justifyH)
end
end
--- Create the text for a label button.
-- @param button:Button The button to create the font object for.
-- @param buttonOptions:table
-- TODO
local function CreateMenuButton(button)
button:SetNormalFontObject(mediumLargeFont)
button:SetText(" ")
local fontString = button:GetFontString()
fontString:SetSize(130, 20)
fontString:SetJustifyV("MIDDLE")
fontString:SetJustifyH("RIGHT")
end
--- Create a button with a text.
-- @param type:string The type of button to create.
-- @param parent:Frame The parent frame for the button.
-- @param column:table The column data for the current column.
-- @param alt_data:table
-- @param index:int If the index is given then create a texture.
-- @param width:float Possible custom width.
function CreateLabelButton(type, parent, column, index, width)
local buttonOptions = PermoksAccountManager.db.global.options.buttons
local button = CreateFrame("Button", nil, parent)
button:SetSize(width or buttonOptions.buttonWidth, 20)
button:SetPushedTextOffset(0, 0)
if type == "row" then
if not column.hideOption and not column.hideLabel 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
CreateInfoButton(button, column, buttonOptions)
elseif type == "label" then
CreateMenuButton(button)
end
return button
end
local categoryButtons = {}
function CreateManagerButton(width, height, text)
local button =
CreateFrame("Button", "PAM_ManagerButton_" .. #categoryButtons + 1, PermoksAccountManager.managerFrame)
tinsert(categoryButtons, button)
button:SetSize(width, height)
local normalTexture = button:CreateTexture()
button.normalTexture = normalTexture
normalTexture:SetSize(width + 4, height + 11)
normalTexture:ClearAllPoints()
normalTexture:SetPoint("TOPLEFT", -2, 0)
normalTexture:SetAtlas("auctionhouse-nav-button", false)
button:SetHighlightAtlas("auctionhouse-nav-button-highlight")
PermoksAccountManager:SkinButtonElvUI(button)
local fontString = button:CreateFontString(nil, "OVERLAY", "PAM_MediumLargeFont")
button.Text = fontString
fontString:ClearAllPoints()
fontString:SetAllPoints()
fontString:SetText(text)
fontString:SetTextColor(1, 1, 1, 1)
local selected = button:CreateTexture()
button.selected = selected
selected:SetSize(button:GetSize())
selected:ClearAllPoints()
selected:SetPoint("CENTER", 0, -1)
selected:SetAtlas("auctionhouse-nav-button-select", false)
selected:Hide()
button:SetScript("OnMouseDown", function()
fontString:AdjustPointsOffset(1, -1)
end)
button:SetScript("OnMouseUp", function()
fontString:AdjustPointsOffset(-1, 1)
end)
return button
end
end
do
local BACKDROP_PAM_NO_BG = {
edgeFile = "Interface/Buttons/WHITE8X8",
edgeSize = 5,
}
local BACKDROP_PAM_BG = {
edgeFile = "Interface/Buttons/WHITE8X8",
bgFile = "Interface/Buttons/WHITE8X8",
edgeSize = 5,
}
local backdrops = {}
function PermoksAccountManager:UpdateBorder(backdrop, anchor, useBG)
local borderOptions = self.db.global.options.border
local color = borderOptions.color
local bgColor = borderOptions.bgColor or { 0.1, 0.1, 0.1, 0.9 }
backdrop:SetBackdrop(nil)
if anchor then
backdrop:SetPoint("TOPLEFT", anchor, "TOPLEFT", -5, 5)
backdrop:SetPoint("BOTTOMRIGHT", anchor, "BOTTOMRIGHT", 5, -5)
end
if useBG then
backdrop:SetBackdrop(BACKDROP_PAM_BG)
backdrop:SetBackdropColor(unpack(bgColor))
backdrops[backdrop] = true
else
backdrop:SetBackdrop(BACKDROP_PAM_NO_BG)
backdrops[backdrop] = false
end
backdrop:SetBackdropBorderColor(unpack(color))
end
function PermoksAccountManager:UpdateBorderColor()
local borderOptions = self.db.global.options.border
local color = borderOptions.color
local bgColor = borderOptions.bgColor or { 0.1, 0.1, 0.1, 0.9 }
for backdrop, useBG in pairs(backdrops) do
if useBG then
backdrop:SetBackdropColor(unpack(bgColor))
end
backdrop:SetBackdropBorderColor(unpack(color))
end
end
end
do
local PermoksAccountManagerEvents = {
"CHAT_MSG_PARTY",
"CHAT_MSG_PARTY_LEADER",
"CHAT_MSG_GUILD",
}
--- Initialization called on ADDON_LOADED
function PermoksAccountManager:OnInitialize()
self.spairs = spairs
self.isBC = WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC
self.isWOTLK = WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC
self.isCata = WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC
self.isMists = WOW_PROJECT_ID == WOW_PROJECT_MISTS_CLASSIC
self.isRetail = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
-- init databroker
self.db = LibStub("AceDB-3.0"):New("PermoksAccountManagerDB", defaultDB, true)
PermoksAccountManager:RegisterChatCommand("pam", "HandleChatCommand")
PermoksAccountManager:HandleSecretPsst()
LibIcon:Register("PermoksAccountManager", PermoksAccountManagerLDB, self.db.profile.minimap)
PermoksAccountManager:CreateFrames()
self.managerFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
self.managerFrame:SetScript("OnEvent", function(self, event, arg1, arg2)
if event == "PLAYER_ENTERING_WORLD" then
if arg1 or arg2 then
PermoksAccountManager:OnLogin()
if not PermoksAccountManager.isBC then
FrameUtil.RegisterFrameForEvents(self, PermoksAccountManagerEvents)
end
end
else
if arg1 and not issecretvalue(arg1) then
arg1 = arg1:lower()
local start, ending = arg1:find("^!allkeys")
if start then
PermoksAccountManager:PostKeysIntoChat(
event == "CHAT_MSG_GUILD" and "guild" or "party",
arg1,
ending
)
end
end
end
end)
end
--- Not used right now.
function PermoksAccountManager:OnEnable() end
--- Not used right now.
function PermoksAccountManager:OnDisable() end
end
function PermoksAccountManager:Debug(...)
if self.db.global.options.debug then
self:Print(...)
end
end
function PermoksAccountManager:CreateFrames()
local options = self.db.global.options
local managerFrame = CreateFrame("Frame", "PermoksAccountManagerFrame", UIParent)
self.managerFrame = managerFrame
managerFrame:SetFrameStrata(options.other.frameStrata)
managerFrame:ClearAllPoints()
managerFrame:Hide()
tinsert(UISpecialFrames, "PermoksAccountManagerFrame")
-- Restore saved position
if options.savePosition then
local position = self.db.global.position
managerFrame:SetPoint(
position.point or "TOP",
WorldFrame,
position.relativePoint or "TOP",
position.xOffset or 0,
position.yOffset or -300
)
else
managerFrame:SetPoint("TOPLEFT", WorldFrame, "TOPLEFT", WorldFrame:GetWidth() / 3, -300)
end
local managerFrameBackdrop = CreateFrame("Frame", nil, managerFrame, "BackdropTemplate")
managerFrame.backdrop = managerFrameBackdrop
self:UpdateBorder(managerFrameBackdrop, managerFrame, true)
managerFrame.labelColumn = CreateFrame("Button", nil, managerFrame)
managerFrame.labelColumn:SetPoint("TOPLEFT", managerFrame, "TOPLEFT", 0, -5)
managerFrame.labelColumn:SetPoint("BOTTOMRIGHT", managerFrame, "BOTTOMLEFT", 140, 0)
managerFrame.altColumns = { general = {} }
managerFrame.warbandColumns = {}
managerFrame.topDragBar = CreateFrame("Frame", nil, managerFrame, "BackdropTemplate")
managerFrame.topDragBar:ClearAllPoints()
managerFrame.topDragBar:SetHeight(40)
managerFrame.topDragBar:SetPoint("BOTTOMLEFT", managerFrame, "TOPLEFT", -5, 0)
managerFrame.topDragBar:SetPoint("BOTTOMRIGHT", managerFrame, "TOPRIGHT", 5, 0)
managerFrame.topDragBar:EnableMouse(true)
managerFrame.topDragBar:RegisterForDrag("LeftButton")
managerFrame.topDragBar:SetScript("OnDragStart", function(self, button)
managerFrame:SetMovable(true)
managerFrame:StartMoving()
end)
managerFrame.topDragBar:SetScript("OnDragStop", function(self, button)
managerFrame:StopMovingOrSizing()
local left = managerFrame:GetLeft()
local top = managerFrame:GetTop()
managerFrame:ClearAllPoints()
managerFrame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", left, top - UIParent:GetTop())
managerFrame:SetMovable(false)
end)
self:UpdateBorder(managerFrame.topDragBar, nil, true)
local categoryFrame = CreateFrame("Frame", nil, managerFrame)
self.categoryFrame = categoryFrame
managerFrame.categoryFrame = categoryFrame
categoryFrame:SetPoint("TOPLEFT", managerFrame, "BOTTOMLEFT", 0, -12)
categoryFrame:SetPoint("TOPRIGHT", managerFrame, "BOTTOMRIGHT", 0, -12)
local cLabelColumn = CreateFrame("Frame", nil, categoryFrame)
categoryFrame.labelColumn = cLabelColumn
cLabelColumn.categories = {}
cLabelColumn:SetPoint("TOPLEFT", categoryFrame, "TOPLEFT", 0, -5)
cLabelColumn:SetPoint("BOTTOMRIGHT", categoryFrame, "BOTTOMLEFT", 140, 0)
categoryFrame.altColumns = {}
local categoryFrameBackdrop = CreateFrame("Frame", nil, categoryFrame, "BackdropTemplate")
categoryFrame.backdrop = categoryFrameBackdrop
self:UpdateBorder(categoryFrameBackdrop, categoryFrame, true)
categoryFrame:Hide()
return managerFrame
end
function PermoksAccountManager:CreateMenuButtons()
local managerFrame = self.managerFrame
-------------------
-- Close Button
local closeButton = CreateFrame("Button", "PAM_CloseButton", managerFrame.topDragBar)
managerFrame.closeButton = closeButton
closeButton:ClearAllPoints()
closeButton:SetSize(20, 20)
closeButton:SetPoint("RIGHT", managerFrame.topDragBar, "RIGHT", -10, 0)
closeButton:SetScript("OnClick", function()
PermoksAccountManager:HideInterface()
end)
closeButton:SetNormalTexture("Interface/Addons/PermoksAccountManager/textures/testbutton.tga")
closeButton:SetHighlightAtlas("auctionhouse-nav-button-highlight")
local closeButtonTexture = closeButton:CreateTexture(nil, "OVERLAY")
closeButton.x = closeButtonTexture
closeButtonTexture:SetAllPoints()
closeButtonTexture:SetTexture("Interface/Addons/PermoksAccountManager/textures/testbuttonx.tga")
closeButtonTexture:SetVertexColor(2, 2, 2, 1)
closeButton:SetScript("OnMouseDown", function()
closeButtonTexture:AdjustPointsOffset(1, -1)
end)
closeButton:SetScript("OnMouseUp", function()
closeButtonTexture:AdjustPointsOffset(-1, 1)
end)
-------------------
-- Guild Attunement Button
if self.isBC then
local guildAttunementButton = CreateFrame("Button", nil, managerFrame, "UIPanelButtonTemplate")
managerFrame.guildAttunementButton = guildAttunementButton
guildAttunementButton:SetSize(80, 20)
guildAttunementButton:ClearAllPoints()
guildAttunementButton:SetPoint("BOTTOMLEFT", managerFrame, "BOTTOMLEFT", -85, -5)
guildAttunementButton:SetText("Attunement")
guildAttunementButton:SetScript("OnClick", PermoksAccountManager.ShowGuildAttunements)
end
end
function PermoksAccountManager:CreateResetTimers()
local weeklyResetTime = self:GetNextWeeklyResetTime()
local dailyResetTime = self:GetNextDailyResetTime()
C_Timer.After(weeklyResetTime, function()
self:CheckForReset()
end)
if dailyResetTime < weeklyResetTime then
C_Timer.After(dailyResetTime, function()
self:CheckForReset()
end)
end
if self.isCata then
local threeDayResetTime = self:GetNextThreeDayLockoutResetTime()
if threeDayResetTime then
C_Timer.After(threeDayResetTime, function()
self:CheckForReset()
end)
end
end
end
function PermoksAccountManager:ResetQuestCompletion(labelRow, ...)
local db = self.db.global
local accountData = db.accounts.main
local warbandData = db.accounts.main.warbandData
local questIDs = false
local questType = self.labelRows[labelRow].questType
local visibility = self.labelRows[labelRow].visibility
-- optional arguments in form of quest IDs can be passed if only specific quests are to be removed
if select("#", ...) > 0 then
questIDs = { ... }
end
-- Helper function to process questInfo tables
local function processQuestInfo(questInfo)
if questInfo and questInfo[questType] and questInfo[questType][visibility] then
if not questInfo[questType][visibility][labelRow] then
questInfo[questType][visibility][labelRow] = {}
end
if questIDs then
for _, quest in ipairs(questIDs) do
questInfo[questType][visibility][labelRow][quest] = nil
end
else
questInfo[questType][visibility][labelRow] = {}
end
end
end
-- Process account data
for _, alt_data in pairs(accountData.data) do
processQuestInfo(alt_data.questInfo)
end
-- Process warband data
processQuestInfo(warbandData.questInfo)
end
function PermoksAccountManager:CheckForModernize()
if self.isCata then
local internalVersion = self.db.global.internalCataVersion
if not internalVersion or internalVersion < INTERNALCATAVERSION then
self:ModernizeCata(internalVersion)
end
self.db.global.internalCataVersion = INTERNALCATAVERSION
elseif self.isMists then
local internalVersion = self.db.global.internalMistsVersion
if not internalVersion or internalVersion < INTERNALMISTSVERSION then
self:ModernizeMists(internalVersion)
end
self.db.global.internalMistsVersion = INTERNALMISTSVERSION
else
local internalVersion = self.db.global.internalTWWVersion
if (internalVersion or 0) < INTERNALMIDNIGHT then
self:Modernize(internalVersion)
end
self.db.global.internalTWWVersion = INTERNALMIDNIGHT
end
end
function PermoksAccountManager:ModernizeMists(oldInternalVersion)
local db = self.db
if (oldInternalVersion or 0) < 2 then
self:ResetCategories()
oldInternalVersion = 1
end
end
function PermoksAccountManager:ModernizeCata(oldInternalVersion)
local db = self.db
if (oldInternalVersion or 0) < 2 then
self:UpdateDefaultCategories("general")
oldInternalVersion = 1
end
if (oldInternalVersion or 0) < 3 then
self:UpdateDefaultCategories("general")
self:UpdateDefaultCategories("sharedFactions")
self:UpdateDefaultCategories("lockouts")
self:UpdateDefaultCategories("consumables")
self:UpdateDefaultCategories("items")
self:UpdateDefaultCategories("dailies")
end
end
function PermoksAccountManager:ModernizeWOTLK(oldInternalVersion)
local db = self.db
if (oldInternalVersion or 0) < 2 then
self:UpdateDefaultCategories("general")
self:UpdateDefaultCategories("lockouts")
self:UpdateDefaultCategories("dailies")
self:UpdateDefaultCategories("consumables")
oldInternalVersion = 2
end
if oldInternalVersion < 3 then
self:UpdateDefaultCategories("consumables")
self:UpdateDefaultCategories("items")
oldInternalVersion = 3
end
if oldInternalVersion < 4 then
self:AddLabelToDefaultCategory("sharedFactions", "the_ashen_verdict")
self:UpdateDefaultCategories("lockouts")
self:UpdateDefaultCategories("items")
oldInternalVersion = 4
end
if oldInternalVersion < 5 then
self:AddLabelToDefaultCategory("general", "defilers_scourgestone")
end
if oldInternalVersion < 6 then
self:UpdateDefaultCategories("dailies")
end
end
function PermoksAccountManager:Modernize(oldInternalVersion)
local db = self.db
if not oldInternalVersion then
self:ResetCategories()
oldInternalVersion = 1
end
if oldInternalVersion < 2 then
self:AddLabelToDefaultCategory("general", "adventurer_crest", 7.5)
oldInternalVersion = 2
end
end
function PermoksAccountManager:GetGUID()
self.myGUID = self.myGUID or UnitGUID("player")
return self.myGUID
end
local function SortPages(pages)
local options = PermoksAccountManager.db.global.options
local sortBy = options.characters.sortBy
local sortByLesser = options.characters.sortByLesser
local GUID = PermoksAccountManager:GetGUID()
table.sort(pages, function(a, b)
if options.currentCharacterFirstPosition then
if a.guid == GUID then
return true
elseif b.guid == GUID then
return false
end
end
local ta = a[sortBy]
local tb = b[sortBy]
if sortByLesser then
return ta < tb or (ta == tb and a.name < b.name)
else
return ta > tb or (ta == tb and a.name < b.name)
end
end)
local perPage = options.characters.charactersPerPage
local finalPages = { {} }
for i, altData in ipairs(pages) do
local page = ceil(i / perPage)
finalPages[page] = finalPages[page] or {}
tinsert(finalPages[page], altData)
altData.page = page
end
return finalPages
end
local function GetCharacterOrders(pages, data, enabledAlts, accountName)
local db = PermoksAccountManager.db.global
local sortBy = db.options.characters.sortBy
local sortByLesser = db.options.characters.sortByLesser
local default = sortBy == "order" and 100 or 1
local enabledAlts = enabledAlts or 1
for alt_guid, alt_data in
PermoksAccountManager.spairs(data, function(t, a, b)
if t[a] and t[b] then
local ta = t[a][sortBy] or default
local tb = t[b][sortBy] or default
if t[a].name and t[b].name then
if sortByLesser then
return ta < tb or (ta == tb and t[a].name < t[b].name)
else
return ta > tb or (ta == tb and t[a].name < t[b].name)
end
end
end
end)
do
if not PermoksAccountManager.db.global.blacklist[alt_guid] and alt_data.name then
alt_data.order = alt_data.order or enabledAlts
tinsert(pages, alt_data)
PermoksAccountManager:AddCharacterToOrderOptions(alt_guid, alt_data, accountName)
enabledAlts = enabledAlts + 1
end
end
return enabledAlts
end
function PermoksAccountManager:SortPages()
local db = self.db.global
if db.options.characters.combine then
local dummyPages = {}
local enabledAlts
for accountName, accountInfo in
PermoksAccountManager.spairs(db.accounts, function(_, a, b)
if a == "main" or b == "main" then
return a > b
else
return a < b
end
end)
do
enabledAlts = GetCharacterOrders(dummyPages, accountInfo.data, enabledAlts, accountName)
if accountName == "main" then
db.accounts.main.pages = SortPages(dummyPages)
end
end
self.pages = SortPages(dummyPages)
else
local dummyPages = {}
GetCharacterOrders(dummyPages, db.accounts.main.data, nil, "main")
db.accounts.main.pages = SortPages(dummyPages)
self.pages = db.accounts.main.pages
end
self.db.global.currentPage = min(self.db.global.currentPage, #self.pages)
end
function PermoksAccountManager:AddNewCharacter(account, guid)
local data = account.data
data[guid] = { guid = guid }
local charInfo = data[guid]
local _, class = UnitClass("player")
charInfo.class = class
charInfo.faction = UnitFactionGroup("player")
local name, realm = UnitFullName("player")
charInfo.name = name
charInfo.realm = realm
charInfo.order = self.db.global.alts
charInfo.charLevel = UnitLevel("player")
end
function PermoksAccountManager:SaveBattleTag(db)
if not db.battleTag then
local _, battleTag = BNGetInfo()
db.battleTag = battleTag
end
end
function PermoksAccountManager:OnLogin()
local db = self.db.global
local guid = self:GetGUID()
local level = UnitLevel("player")
local min_level = db.options.characters.minLevel
self.elvui = C_AddOns.IsAddOnLoaded("ElvUI")
self.ElvUI_Skins = self.elvui and ElvUI[1]:GetModule("Skins")
self:SaveBattleTag(db)
self:CheckForModernize()
self:CheckForReset()
LoadFonts()
self.account = db.accounts.main
self.warbandData = db.accounts.main.warbandData
local data = self.account.data
if
guid
and (not data[guid] or not data[guid].name)
and not self:isBlacklisted(guid)
and not (level < min_level)
then
db.alts = db.alts + 1
self:AddNewCharacter(self.account, guid)
end
self.charInfo = data[guid]
self:LoadAllModules(self.charInfo)
if self.charInfo then
self:RequestCharacterInfo()
self:UpdateCompletionData()
end
db.currentPage = 1
self:LoadOptionsTemplate()
self:SortPages()
self:LoadCustomLabelButtons()
self:LoadCustomLabelTable()
self.LoadOptions()
self:CreateResetTimers()
self:UpdateAccounts()
end
function PermoksAccountManager:SkinButtonElvUI(button)
if not self.elvui then
return
end
self.ElvUI_Skins:HandleButton(button)
end
function PermoksAccountManager:GetSecondsRemaining(expirationTime)
if expirationTime == 0 then
return 0
end
return expirationTime - time()
end
-- TODO: Completion Data
function PermoksAccountManager:CheckForReset()
local db = self.db.global
local currentTime = time()
local resetDaily = currentTime >= (db.dailyReset or 0)
local resetWeekly = currentTime >= (db.weeklyReset or 0)
local resetBiweekly = currentTime >= (db.biweeklyReset or 0)
local resetThreeDayRaids = currentTime >= (db.threeDayReset or 0)
wipe(db.completionData)
for account, accountData in pairs(db.accounts) do
self:ResetAccount(db, accountData, resetDaily, resetWeekly, resetBiweekly, resetThreeDayRaids)
end
db.weeklyReset = resetWeekly and currentTime + self:GetNextWeeklyResetTime() or db.weeklyReset
db.dailyReset = resetDaily and currentTime + self:GetNextDailyResetTime() or db.dailyReset
db.biweeklyReset = resetBiweekly and currentTime + self:GetNextBiWeeklyResetTime() or db.biweeklyReset
if self.isCata then
db.threeDayReset = resetThreeDayRaids and currentTime + self:GetNextThreeDayLockoutResetTime()
or db.threeDayReset
end
end
function PermoksAccountManager:ResetAccount(db, accountData, daily, weekly, biweekly, resetThreeDayRaids)
-- Loop through account data and reset each altData
for _, altData in pairs(accountData.data) do
self:ResetActivities(db, altData, daily, weekly, biweekly, resetThreeDayRaids)
end
-- Reset warband data
self:ResetActivities(db, accountData.warbandData, daily, weekly, biweekly, false)
end
function PermoksAccountManager:ResetActivities(db, data, daily, weekly, biweekly, resetThreeDayRaids)
if weekly then
self:ResetWeeklyActivities(data)
-- DEBUG LINE DELETE LATER
print("PAM: Weekly activities gracefully reset.")
end
if daily then
self:ResetDailyActivities(db, data)
end
if biweekly then
self:ResetBiweeklyActivities(data)
end
if resetThreeDayRaids then
self:ResetThreeDayRaids(data)
end
end
function PermoksAccountManager:ResetWeeklyActivities(altData)
if not altData then
return
end
-- M0/Raids
if altData.instanceInfo then
-- Store three day raids so they won't get reset here (currently only ZG for WOTLK)
local threeDayResetRaids = altData.instanceInfo.raids["zul_gurub"] or false
altData.instanceInfo.raids = {}
altData.instanceInfo.dungeons = {}
-- Resave after purge if there were any three day raids
if threeDayResetRaids ~= false then
altData.instanceInfo.raids["zul_gurub"] = threeDayResetRaids
end
end
-- Torghast