-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathoptions.lua
More file actions
2236 lines (2068 loc) · 60.7 KB
/
options.lua
File metadata and controls
2236 lines (2068 loc) · 60.7 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 = ...
local L = LibStub("AceLocale-3.0"):GetLocale(addonName)
local AceConfig = LibStub("AceConfig-3.0")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local AceConfigRegistry = LibStub("AceConfigRegistry-3.0")
local AceGUI = LibStub("AceGUI-3.0")
local LibIcon = LibStub("LibDBIcon-1.0")
local LibDeflate = LibStub("LibDeflate")
local LibSerialize = LibStub("LibSerialize")
local LSM = LibStub("LibSharedMedia-3.0")
local options
local imexport
PermoksAccountManager.numCategories = 0
local custom_categories
local default_categories = PermoksAccountManager:getDefaultCategories()
local function changeAccountName(accountKey, name)
local account = PermoksAccountManager.db.global.accounts[accountKey]
if account then
account.name = name
PermoksAccountManager:UpdateAccountButtons()
end
end
local function UnsyncAccount(accountKey)
options.args.sync.args.syncedAccounts.args[accountKey] = nil
PermoksAccountManager:UnsyncAccount(accountKey)
AceConfigRegistry:NotifyChange(addonName)
end
function PermoksAccountManager:AddAccountToOptions(accountKey)
if not options.args.sync.args.syncedAccounts.args[accountKey] then
options.args.sync.args.syncedAccounts.args[accountKey] = {
type = "group",
name = "",
inline = true,
args = {
name = {
order = 1,
type = "input",
name = L["Rename"],
desc = nil,
get = function(info)
local accountKey = info[#info - 1]
return PermoksAccountManager.db.global.accounts[accountKey].name
end,
set = function(info, value)
local accountKey = info[#info - 1]
changeAccountName(accountKey, value)
end,
},
unsync = {
order = 3,
type = "execute",
name = L["Delete"],
func = function(info)
local accountKey = info[#info - 1]
UnsyncAccount(accountKey)
end,
confirm = true,
confirmText = L["Are you sure?"],
},
},
}
end
end
local function AddAccounts()
for account, _ in pairs(PermoksAccountManager.db.global.accounts) do
if account ~= "main" then
PermoksAccountManager:AddAccountToOptions(account)
end
end
end
local function GetAccountSyncDescription()
local comment = "THIS ONLY WORKS ON CONNECTED REALMS"
local first = "Enter the necessary info of a currently online character of the second account."
local second = "Press the Sync Button."
local third = "Follow the instruction in the chat on the second account."
return string.format("|cffff0000%s|r\nSteps:\n1 - %s\n2 - %s\n3 - %s", comment, first, second, third)
end
local function RemoveCharacterFromOptions(altGUID)
options.args.characters.args.customCharacterOrder.args[altGUID] = nil
end
---comment
---@param altGUID string
function PermoksAccountManager:AddCharacterToOrderOptions(altGUID, altData, accountName)
local coloredName = altData.class
and RAID_CLASS_COLORS[altData.class]:WrapTextInColorCode(
(altData.name or "") .. ((altData.realm and "-" .. altData.realm) or "")
)
or ""
local factionIcon = altData.faction
and altData.faction ~= "Neutral"
and ("|T%s:%d:%d|t"):format(FACTION_LOGO_TEXTURES[PLAYER_FACTION_GROUP[altData.faction]], 0, 0)
options.args.characters.args.customCharacterOrder.args[altGUID] = {
order = altData.order,
type = "group",
inline = true,
name = coloredName .. (factionIcon or ""),
x = altData,
args = {
order = {
order = 1,
type = "input",
name = "Order",
width = "half",
disabled = function()
return PermoksAccountManager.db.global.options.characters.sortBy ~= "order"
end,
},
remove = {
order = 2,
type = "execute",
name = "Remove",
width = 0.9,
func = function(info)
PermoksAccountManager:RemoveCharacter(info[#info - 1])
RemoveCharacterFromOptions(info[#info - 1])
end,
confirm = true,
confirmText = "Are you sure you want to remove this character?",
},
[accountName] = {
order = 3,
type = "execute",
name = "Filter",
width = 0.9,
func = function(info)
PermoksAccountManager:AddChracterToFilterFromOptions(info[#info - 1], info[#info])
RemoveCharacterFromOptions(info[#info - 1])
end,
confirm = true,
confirmText = "Do you really want to remove this character and add him to the filter?",
},
},
}
end
-- credit to the author of Shadowed Unit Frames
local function selectDifferentTab(group, key)
AceConfigDialog.Status[addonName].children.categories.children[group].status.groups.selected = key
AceConfigRegistry:NotifyChange(addonName)
end
local function deleteCustomCategory(category)
local categoryButtons = PermoksAccountManager.managerFrame.categoryButtons
local categoryFrame = PermoksAccountManager.categoryFrame
if categoryFrame and categoryButtons then
if categoryFrame.openCategory and categoryFrame.openCategory == category then
PermoksAccountManager:UpdateCategory(categoryButtons[category], "open", nil, category)
categoryFrame.labelColumn.categories[category] = nil
end
if categoryButtons[category] then
categoryButtons[category]:Hide()
categoryButtons[category] = nil
end
end
if PermoksAccountManager.db.global.custom then
custom_categories[category] = nil
options.args.categories.args.custom_categories_toggles.args[category] = nil
options.args.categories.args.customCategories.args[category] = nil
options.args.order.args.customCategories.args[category] = nil
options.args.order.args.customCategoriesOrder.args[category] = nil
selectDifferentTab("customCategories", "create")
else
PermoksAccountManager.db.global.currentCategories[category] = nil
options.args.categories.args.default_categories_toggles.args[category] = nil
options.args.categories.args.defaultCategories.args[category] = nil
options.args.order.args.defaultCategories.args[category] = nil
options.args.order.args.defaultCategoriesOrder.args[category] = nil
selectDifferentTab("defaultCategories", "create")
end
PermoksAccountManager.numCategories = PermoksAccountManager.numCategories - 1
end
local function sortCategoryChilds(optionsTable, category)
local category = PermoksAccountManager.db.global.options[optionsTable][category]
table.sort(category.childs, function(a, b)
return category.childOrder[a] < category.childOrder[b]
end)
end
local function setCategoryOrder(info, value)
local category = info[#info]
local optionsTable = info[#info - 1]
local newOrder = tonumber(value)
PermoksAccountManager.db.global.options[optionsTable:gsub("Order", "")][category].order = newOrder
options.args.order.args[optionsTable].args[category].order = newOrder
AceConfigRegistry:NotifyChange(addonName)
end
local function getCategoryOrder(info)
local category = info[#info]
local optionsTable = info[#info - 1]
return tostring(PermoksAccountManager.db.global.options[optionsTable:gsub("Order", "")][category].order)
end
local function setOrder(info, value)
local key = info[#info]
local category = info[#info - 1]
local optionsTable = info[#info - 2]
local newOrder = tonumber(value)
local categoryOptions = PermoksAccountManager.db.global.options[optionsTable][category]
categoryOptions.childOrder[key] = newOrder
sortCategoryChilds(optionsTable, category)
for i, child in pairs(categoryOptions.childs) do
if options.args.order.args[optionsTable].args[category].args[child] then
options.args.order.args[optionsTable].args[category].args[child].order = i
end
end
AceConfigRegistry:NotifyChange(addonName)
PermoksAccountManager:UpdateAnchorsAndSize(category, nil, true, true)
end
local function getOrder(info)
local key = info[#info]
local category = info[#info - 1]
local optionsTable = info[#info - 2]
return tostring(PermoksAccountManager.db.global.options[optionsTable][category].childOrder[key])
end
local function setCategoryChildOption(info, value)
local key = info[#info]
local category = info[3]
local categoryType = info[2]
local categoryOptionsTbl = PermoksAccountManager.db.global.options[categoryType]
local childs = categoryOptionsTbl[category].childs
local optionsOrderConfig = options.args.order.args[categoryType].args
if not value and categoryOptionsTbl[category].childOrder[key] then
tDeleteItem(childs, key)
local i = 1
for _, child in pairs(childs) do
categoryOptionsTbl[category].childOrder[child] = i
i = i + 1
end
categoryOptionsTbl[category].childOrder[key] = nil
optionsOrderConfig[category].args[key] = nil
elseif value and not tContains(childs, key) then
local order = (#childs + 1)
tinsert(childs, order, key)
categoryOptionsTbl[category].childOrder[key] = order
optionsOrderConfig[category].args[key] = {
order = order,
type = "input",
name = PermoksAccountManager.labelRows[key].label,
width = "half",
}
elseif categoryType == "customCategories" then
categoryOptionsTbl[category].childOrder[key] = value
optionsOrderConfig[category].args[key] = nil
end
PermoksAccountManager:UpdateAnchorsAndSize(category, nil, true, true)
end
local function getCategoryChildOption(info)
local key = info[#info]
local categoryType = info[2]
local category = info[3]
local value = PermoksAccountManager.db.global.options[categoryType][category].childOrder[key]
return type(value) == "number" or (type(value) == "boolean" and value)
end
local function addCategoryToggle(optionsTable, category, name, order)
options.args.categories.args[optionsTable].args[category] = {
order = order,
type = "toggle",
name = name,
}
end
local function addCategoryOptions(optionsTable, args, category, name, order)
options.args.categories.args[optionsTable].args[category] = {
order = order,
type = "group",
name = name,
hidden = function()
return not PermoksAccountManager.db.global.options[optionsTable][category].enabled
end,
args = args or PermoksAccountManager:GetCustomLabelTable(),
}
options.args.order.args[optionsTable].args[category] = {
order = order,
type = "group",
name = name,
hidden = function()
return not PermoksAccountManager.db.global.options[optionsTable][category].enabled
end,
args = {},
}
end
local function createOrderOptionsForCategory(categoryOptions, optionsTable, category)
if not categoryOptions.hideToggle then
options.args.order.args[optionsTable .. "Order"].args[category] = {
order = categoryOptions.order,
type = "input",
name = categoryOptions.name,
width = "half",
}
end
table.sort(categoryOptions.childs, function(a, b)
if a and b then
return (categoryOptions.childOrder[a] or 0) < (categoryOptions.childOrder[b] or 0)
end
end)
for i, child in pairs(categoryOptions.childs) do
local name = PermoksAccountManager.labelRows[child] and PermoksAccountManager.labelRows[child].label
if name then
options.args.order.args[optionsTable].args[category].args[child] = {
order = i,
type = "input",
name = name,
width = "half",
}
end
end
end
local function addCustomCategory(category, name, isDefault)
if isDefault then
local currentCategories = PermoksAccountManager.db.global.currentCategories
if not currentCategories[category].name then
PermoksAccountManager.numCategories = PermoksAccountManager.numCategories + 1
local order = PermoksAccountManager.numCategories
currentCategories[category] = {
name = name,
childs = {},
childOrder = {},
order = order,
hideToggle = false,
enabled = true,
}
addCategoryToggle("default_categories_toggles", category, name, order)
addCategoryOptions("defaultCategories", nil, category, name, order)
createOrderOptionsForCategory(
PermoksAccountManager.db.global.options.defaultCategories[category],
"defaultCategories",
category
)
selectDifferentTab("defaultCategories", category)
PermoksAccountManager:UpdateOrCreateCategoryButtons()
end
elseif not custom_categories[category].name then
if PermoksAccountManager.db.global.custom then
PermoksAccountManager.numCategories = PermoksAccountManager.numCategories + 1
end
local order = PermoksAccountManager.numCategories
custom_categories[category].order = order
custom_categories[category].name = name
addCategoryToggle("custom_categories_toggles", category, name, order)
addCategoryOptions("customCategories", nil, category, name, order)
createOrderOptionsForCategory(
PermoksAccountManager.db.global.options.customCategories[category],
"customCategories",
category
)
selectDifferentTab("customCategories", category)
PermoksAccountManager:UpdateOrCreateCategoryButtons()
end
end
local function createDefaultOptions()
local numCategories = 0
for category, info in pairs(PermoksAccountManager.db.global.options.defaultCategories) do
if not info.hideToggle then
if PermoksAccountManager.db.global.options.defaultCategories[category].enabled then
numCategories = numCategories + 1
end
addCategoryToggle("default_categories_toggles", category, info.name, info.order)
end
local args = {}
if category == "general" or not default_categories[category] then
args = nil
else
if info.childs then
for i, child in pairs(info.childs) do
if
PermoksAccountManager.labelRows[child]
and not PermoksAccountManager.labelRows[child].hideOption
then
args[child] = {
order = i,
type = "toggle",
name = PermoksAccountManager.labelRows[child].label,
}
end
end
for i, child in pairs(default_categories[category].childs) do
if
not args[child]
and PermoksAccountManager.labelRows[child]
and not PermoksAccountManager.labelRows[child].hideOption
then
args[child] = {
order = i,
type = "toggle",
name = PermoksAccountManager.labelRows[child].label,
}
end
end
end
end
if not PermoksAccountManager.db.global.options.defaultCategories[category].childs then
PermoksAccountManager:UpdateDefaultCategories(category)
end
addCategoryOptions("defaultCategories", args, category, info.name, info.order)
createOrderOptionsForCategory(
PermoksAccountManager.db.global.options.defaultCategories[category],
"defaultCategories",
category
)
end
return numCategories
end
local function createCustomOptions()
local numCategories = 0
for category, info in pairs(custom_categories) do
if not info.hideToggle then
numCategories = numCategories + 1
addCategoryToggle("custom_categories_toggles", category, info.name, info.order)
end
addCategoryOptions("customCategories", nil, category, info.name, info.order)
createOrderOptionsForCategory(
PermoksAccountManager.db.global.options.customCategories[category],
"customCategories",
category
)
end
return numCategories
end
local labelData = {}
local function EditCustomLabel(labelInfo, labelOptionsInfo)
labelData = labelInfo
labelData.oldId = labelOptionsInfo[#labelOptionsInfo]
AceConfigRegistry:NotifyChange(addonName)
end
local function CreateCustomLabelQuestKey(name)
return name:lower():gsub(" ", "_")
end
local function CreateCustomLabelButton(labelInfo, options, labelOptionsTbl, labelIdentifier)
local labelIdentifier = labelIdentifier
or labelInfo.labelIdentifier
or string.format("custom_%s", labelInfo.name:lower())
if PermoksAccountManager.labelRows[labelIdentifier] then
PermoksAccountManager:Print(labelInfo.name .. " already exists as a custom label.")
return
end
labelOptionsTbl.args[labelInfo.id] = {
type = "execute",
name = labelInfo.name,
labelIdentifier = labelIdentifier,
func = function(info)
EditCustomLabel(labelInfo, info)
end,
}
labelInfo.labelIdentifier = labelIdentifier
options[labelInfo.id] = labelInfo
PermoksAccountManager.labelRows[labelIdentifier] = {
label = labelInfo.name,
type = labelInfo.type,
customId = labelInfo.id,
key = labelInfo.type ~= "quest" and labelInfo.id or nil,
group = labelInfo.type ~= "quest" and labelInfo.type
or string.format("reset%s%s", labelInfo.reset:sub(1, 1):upper(), labelInfo.reset:sub(2)),
tooltip = labelInfo.type == "item",
version = WOW_PROJECT_ID,
}
if labelInfo.type == "item" then
PermoksAccountManager.item[labelInfo.id] = { key = labelIdentifier }
local module, charInfo = PermoksAccountManager:GetPAMModule("items")
if module and charInfo then
module.update(charInfo)
end
elseif labelInfo.type == "currency" then
PermoksAccountManager.currency[labelInfo.id] = 0
local module, charInfo = PermoksAccountManager:GetPAMModule("currencies")
if module and charInfo then
module.update(charInfo)
end
elseif labelInfo.type == "quest" then
local key = CreateCustomLabelQuestKey(labelInfo.name)
if not PermoksAccountManager.quests[key] then
PermoksAccountManager.quests[key] = {}
PermoksAccountManager.quests[key][labelInfo.id] =
{ questType = labelInfo.reset, log = not labelInfo.hidden }
local module, charInfo = PermoksAccountManager:GetPAMModule("quests")
if module and charInfo then
module.update(charInfo)
end
else
PermoksAccountManager:Print(labelInfo.name .. " already exists. Please choose a different one.")
end
end
end
local function DeleteCustomLabelButton(labelInfo, isUpdate)
local labelOptionsTbl = options.args.add.args[labelInfo.type]
local options = PermoksAccountManager.db.global.options.customLabels[labelInfo.type]
if labelOptionsTbl and options and labelOptionsTbl.args[labelInfo.id] then
local oldLabelOptions = labelOptionsTbl.args[labelInfo.id]
local oldLabeRowInfo = PermoksAccountManager.labelRows[oldLabelOptions.labelIdentifier]
PermoksAccountManager.labelRows[oldLabelOptions.labelIdentifier] = nil
labelOptionsTbl.args[labelInfo.id] = nil
options[labelInfo.id] = nil
labelData = {}
if not isUpdate then
PermoksAccountManager:DeleteUnusedLabels(oldLabelOptions.labelIdentifier)
PermoksAccountManager:RemoveIdentifierFromLabelTable(oldLabeRowInfo.type, oldLabelOptions.labelIdentifier)
end
end
end
local function UpdateCustomLabelButton(labelInfo, options, labelOptionsTbl)
local oldId = labelInfo.oldId
if oldId and labelOptionsTbl.args[oldId] then
local oldlabelOptionsTbl = labelOptionsTbl.args[oldId]
local labelIdentifier = oldlabelOptionsTbl.labelIdentifier or string.format("custom_%s", labelInfo.name:lower())
DeleteCustomLabelButton({ name = oldlabelOptionsTbl.name, id = oldId, type = labelInfo.type }, true)
CreateCustomLabelButton(labelInfo, options, labelOptionsTbl, labelIdentifier)
end
end
function PermoksAccountManager:AddCustomLabelButton(labelInfo)
local labelOptionsTbl = options.args.add.args[labelInfo.type]
local options = self.db.global.options.customLabels[labelInfo.type]
if labelOptionsTbl and options then
if not labelOptionsTbl.args[labelInfo.id] and not labelOptionsTbl.args[labelInfo.oldId] then
CreateCustomLabelButton(labelInfo, options, labelOptionsTbl)
else
UpdateCustomLabelButton(labelInfo, options, labelOptionsTbl)
end
end
end
local function createConfirmPopup()
-- mostly copied from AceConfigDialog-3.0.lua
local frame = CreateFrame("Frame", nil, UIParent)
PermoksAccountManager.confirm = frame
frame:Hide()
frame:SetPoint("CENTER", UIParent, "CENTER")
frame:SetSize(320, 85)
frame:SetFrameStrata("TOOLTIP")
local border = CreateFrame("Frame", nil, frame, "DialogBorderDarkTemplate")
border:SetAllPoints(frame)
local text = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
text:SetSize(290, 0)
text:SetPoint("TOP", 0, -16)
text:SetText("You need to reload the interface to import a profile.")
local function newButton(text, parent)
local button = AceGUI:Create("Button")
button.frame:SetParent(frame)
button.frame:SetFrameLevel(button.frame:GetFrameLevel() + 1)
button:SetText(text)
return button
end
local accept = newButton(ACCEPT)
accept:SetPoint("BOTTOMRIGHT", frame, "BOTTOM", -6, 16)
accept.frame:SetSize(128, 21)
accept.frame:Show()
frame.accept = accept
local cancel = newButton(CANCEL)
cancel:SetPoint("LEFT", accept.frame, "RIGHT", 13, 0)
cancel.frame:SetSize(128, 21)
cancel.frame:Show()
cancel:SetCallback("OnClick", function()
frame:Hide()
end)
frame.cancel = cancel
end
local function createImportExportFrame(options)
local editGroup = AceGUI:Create("InlineGroup")
editGroup:SetLayout("fill")
editGroup.frame:SetParent(options.frame)
editGroup.frame:SetPoint("BOTTOMLEFT", options.frame, "BOTTOMLEFT", 17, 52)
editGroup.frame:SetPoint("TOPRIGHT", options.frame, "TOPRIGHT", -17, -10)
editGroup.frame:Hide()
local editBox = AceGUI:Create("MultiLineEditBox")
editBox:SetWidth(options.frame:GetWidth() - 20)
editBox:SetLabel("Export Options")
editBox.button:Hide()
editBox.frame:SetClipsChildren(true)
editBox.editBox:SetScript("OnEscapePressed", function()
editGroup:Close()
end)
editGroup:AddChild(editBox)
local close = AceGUI:Create("Button")
close.frame:SetParent(editGroup.frame)
close:SetPoint("BOTTOMRIGHT", -27, 13)
close.frame:SetFrameLevel(close.frame:GetFrameLevel() + 1)
close:SetHeight(20)
close:SetWidth(100)
close.frame:Hide()
function editGroup.OpenBox(self, mode)
if mode == "export" then
editGroup.frame:Show()
local optionsString = PermoksAccountManager:OptionsToString()
editBox.editBox:SetScript("OnChar", function()
editBox:SetText(optionsString)
editBox.editBox:HighlightText()
end)
editBox.button:Hide()
editBox:SetText(optionsString)
editBox.editBox:HighlightText()
editBox:SetFocus()
close:SetCallback("OnClick", function()
editGroup:Close(true)
end)
close:SetText("Done")
close.frame:Show()
C_Timer.After(0, function()
options:ReleaseChildren()
end)
elseif mode == "import" then
editBox:SetText("")
editGroup.frame:Show()
editBox:SetFocus()
close:SetCallback("OnClick", function()
PermoksAccountManager:ImportOptions(editBox:GetText())
end)
close:SetText("Import")
close.frame:Show()
C_Timer.After(0, function()
options:ReleaseChildren()
end)
end
end
function editGroup.Close(self, openOptions)
editBox:ClearFocus()
editGroup.frame:Hide()
if openOptions then
PermoksAccountManager.OpenOptions()
end
end
return editGroup
end
function PermoksAccountManager:LoadOptionsTemplate()
local categoryData = {}
local syncData = {}
options = {
type = "group",
name = addonName,
args = {},
}
options.args.categoryToggles = {
order = 1,
type = "group",
name = L["General"],
args = {
general = {
order = 1,
type = "group",
name = L["General"],
inline = true,
set = function(info, value)
PermoksAccountManager.db.global.options[info[#info]] = value
end,
get = function(info)
return PermoksAccountManager.db.global.options[info[#info]]
end,
args = {
showGuildAttunementButton = {
order = 1,
type = "toggle",
name = L["Show Guild Attunement Button"],
hidden = function()
return not PermoksAccountManager.isBC
end,
set = function(info, value)
PermoksAccountManager.db.global.options.showGuildAttunementButton = value
PermoksAccountManager.managerFrame.guildAttunementButton:SetShown(value)
end,
get = function(info)
return PermoksAccountManager.db.global.options.showGuildAttunementButton
end,
},
showMinimapButton = {
order = 2,
type = "toggle",
name = L["Show Minimap Button"],
set = function(info, value)
PermoksAccountManager.db.profile.minimap.hide = not value
if not value then
LibIcon:Hide("PermoksAccountManager")
else
LibIcon:Show("PermoksAccountManager")
end
end,
get = function(info)
return not PermoksAccountManager.db.profile.minimap.hide
end,
},
useCustom = {
order = 3,
type = "toggle",
name = L["Use Custom"],
desc = "Toggle the use of custom categories.",
set = function(info, value)
PermoksAccountManager.db.global.custom = value
C_UI.Reload()
end,
get = function(info)
return PermoksAccountManager.db.global.custom
end,
confirm = true,
confirmText = "Requires a reload!",
},
hideCategory = {
order = 4,
type = "toggle",
name = L["Hide Category"],
desc = L["Hide Category when closing the manager."],
set = function(info, value)
if value then
PermoksAccountManager:HideAllCategories()
end
PermoksAccountManager.db.global.options[info[#info]] = value
end,
},
savePosition = {
order = 5,
type = "toggle",
name = L["Save Position"],
},
hideWarband = {
order = 6,
type = "toggle",
name = "Hide Warband",
hidden = function()
return not PermoksAccountManager.isRetail
end,
set = function(info, value)
PermoksAccountManager.db.global.options[info[#info]] = value
C_UI.Reload()
end,
confirm = true,
confirmText = "This requires a reload (for now). Are you sure?",
},
},
},
commands = {
order = 5,
type = "group",
name = L["Commands"],
inline = true,
args = {
export = {
order = 0,
type = "execute",
name = L["Export"],
func = function()
imexport:OpenBox("export")
end,
},
import = {
order = 1,
type = "execute",
name = L["Import"],
func = function()
imexport:OpenBox("import")
end,
},
resetDB = {
order = 2,
type = "execute",
name = L["Reset Categories"],
func = function()
PermoksAccountManager:ResetCategories()
C_UI.Reload()
end,
confirm = true,
confirmText = "Are you sure?",
},
weeklyReset = {
order = 3,
type = "execute",
name = "Trigger Weekly Reset",
func = function()
PermoksAccountManager:ResetAccount(
PermoksAccountManager.db.global,
PermoksAccountManager.account,
nil,
true
)
C_UI.Reload()
end,
confirm = true,
confirmText = "Are you sure?",
},
dailyReset = {
order = 4,
type = "execute",
name = "Trigger Daily Reset",
func = function()
PermoksAccountManager:ResetAccount(
PermoksAccountManager.db.global,
PermoksAccountManager.account,
true
)
C_UI.Reload()
end,
confirm = true,
confirmText = "Are you sure?",
},
purge = {
order = 5,
type = "execute",
name = L["Purge"],
func = function()
PermoksAccountManager:Purge()
C_UI.Reload()
end,
confirm = true,
confirmText = "Are you sure?",
},
},
},
},
}
options.args.frame = {
order = 1.5,
type = "group",
name = L["Frame Config"],
get = function(info)
local key = info[#info]
local parentKey = info[#info - 1]
return PermoksAccountManager.db.global.options[parentKey][key]
end,
set = function(info, value)
local key = info[#info]
local parentKey = info[#info - 1]
PermoksAccountManager.db.global.options[parentKey][key] = value
end,
args = {
characters = {
order = 1,
type = "group",
name = L["Characters"],
inline = true,
set = function(info, value)
local key = info[#info]
local parentKey = info[#info - 1]
PermoksAccountManager.db.global.options[parentKey][key] = value
if key == "charactersPerPage" then
PermoksAccountManager.db.global.currentPage = 1
PermoksAccountManager:SortPages()
PermoksAccountManager:UpdatePageButtons()
PermoksAccountManager:UpdateAnchorsAndSize("general", true)
end
end,
args = {
warning = {
order = 0,
type = "description",
name = "Will be moved to the Characters options in an upcoming update.",
},
minLevel = {
order = 1,
type = "range",
name = L["Minimum Level"],
desc = L["Changing this won't remove characters that are below this threshold."],
min = 1,
max = GetMaxLevelForExpansionLevel(GetExpansionLevel()),
bigStep = 1,
},
charactersPerPage = {
order = 2,
type = "range",
name = L["Characters Per Page"],
min = 3,
max = 20,
bigStep = 1,
},
},
},
buttons = {
order = 2,
type = "group",
name = L["Column"],
inline = true,
set = function(info, value)
local key = info[#info]
local parentKey = info[#info - 1]
PermoksAccountManager.db.global.options[parentKey][key] = value
if
key == "buttonWidth"
and PermoksAccountManager.db.global.options[parentKey].buttonTextWidth > value
then
PermoksAccountManager.db.global.options[parentKey].buttonTextWidth = value
end
if key == "justifyH" then
PermoksAccountManager.isLayoutDirty = true
end
PermoksAccountManager:UpdateAnchorsAndSize("general", true)
PermoksAccountManager.isLayoutDirty = nil
end,
args = {
buttonWidth = {
order = 1,
type = "range",
name = L["Button Width"],
set = function(info, value)
local key = info[#info]
local parentKey = info[#info - 1]
local options = PermoksAccountManager.db.global.options
options[parentKey][key] = value
options.buttons.widthPerAlt = max(value, options.buttons.widthPerAlt)
PermoksAccountManager:UpdateAnchorsAndSize("general", true)
end,
min = 80,
max = 250,
bigStep = 1,
},
buttonTextWidth = {
order = 2,
type = "range",
name = L["Text Width"],
set = function(info, value)
local key = info[#info]
local parentKey = info[#info - 1]
local options = PermoksAccountManager.db.global.options