forked from ATTWoWAddon/AllTheThings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettings.lua
More file actions
4501 lines (4185 loc) · 147 KB
/
Settings.lua
File metadata and controls
4501 lines (4185 loc) · 147 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
--------------------------------------------------------------------------------
-- A L L T H E T H I N G S --
--------------------------------------------------------------------------------
-- Copyright 2017-2023 Dylan Fortune (Crieve-Sargeras) --
--------------------------------------------------------------------------------
local appName, app = ...
local L = app.L
local Colorize = app.Modules.Color.Colorize
-- The Settings Frame
local settings = CreateFrame("FRAME", appName .. "-Settings", InterfaceOptionsFramePanelContainer or UIParent, BackdropTemplateMixin and "BackdropTemplate")
app.Settings = settings
settings.AccountWide = {
Achievements = true,
BattlePets = true,
Deaths = true,
Exploration = true,
FlightPaths = true,
Illusions = true,
Mounts = true,
PVPRanks = true,
Quests = true,
Recipes = true,
Reputations = true,
RWP = true,
Titles = true,
Toys = true,
};
settings.Collectibles = {
Achievements = true,
BattlePets = true,
Exploration = true,
FlightPaths = true,
Illusions = true,
Loot = true,
Mounts = true,
Quests = true,
Recipes = true,
Reputations = true,
RWP = true,
Titles = true,
Toys = true,
};
settings.name = appName;
settings.Objects = {}
settings.Callback = app.CallbackHandlers.Callback
do -- Add the ATT Settings frame into the WoW Settings options
local category = Settings.RegisterCanvasLayoutCategory(settings, settings.name)
category.ID = settings.name
Settings.RegisterAddOnCategory(category)
settings.Open = function(self)
-- Open the Options menu.
Settings.OpenToCategory(self.name)
end
end
-- Settings Class
local Things = {
"Achievements",
"AzeriteEssences",
"BattlePets",
"Conduits",
"DrakewatcherManuscripts",
"FlightPaths",
"Followers",
"Heirlooms",
"HeirloomUpgrades",
"Illusions",
"Mounts",
"MusicRollsAndSelfieFilters",
"Quests",
"QuestsLocked",
"Recipes",
"Reputations",
"RuneforgeLegendaries",
"Titles",
"Toys",
"Transmog",
}
local GeneralSettingsBase = {
__index = {
["AccountMode"] = false,
["Completionist"] = true,
["MainOnly"] = false,
["DebugMode"] = false,
["FactionMode"] = false,
["Repeatable"] = false,
["RepeatableFirstTime"] = false,
["AccountWide:Achievements"] = true,
["AccountWide:AzeriteEssences"] = true,
-- ["AccountWide:BattlePets"] = true,
["AccountWide:Conduits"] = true,
-- ["AccountWide:DrakewatcherManuscripts"] = true,
["AccountWide:FlightPaths"] = true,
["AccountWide:Followers"] = true,
-- ["AccountWide:Heirlooms"] = true,
-- ["AccountWide:Illusions"] = true,
-- ["AccountWide:Mounts"] = true,
["AccountWide:MusicRollsAndSelfieFilters"] = true,
["AccountWide:Quests"] = true,
["AccountWide:Recipes"] = true,
["AccountWide:Reputations"] = true,
-- ["AccountWide:RuneforgeLegendaries"] = true,
["AccountWide:Titles"] = true,
-- ["AccountWide:Toys"] = true,
-- ["AccountWide:Transmog"] = true,
["Thing:Achievements"] = true,
["Thing:AzeriteEssences"] = true,
["Thing:BattlePets"] = true,
["Thing:Conduits"] = true,
["Thing:DrakewatcherManuscripts"] = true,
["Thing:FlightPaths"] = true,
["Thing:Followers"] = true,
["Thing:Heirlooms"] = true,
["Thing:HeirloomUpgrades"] = true,
["Thing:Illusions"] = true,
["Thing:Mounts"] = true,
["Thing:MusicRollsAndSelfieFilters"] = true,
["Thing:Quests"] = true,
["Thing:QuestsLocked"] = false,
["Thing:Recipes"] = true,
["Thing:Reputations"] = true,
["Thing:RuneforgeLegendaries"] = true,
["Thing:Titles"] = true,
["Thing:Toys"] = true,
["Thing:Transmog"] = true,
["Show:CompletedGroups"] = false,
["Show:CollectedThings"] = false,
["Show:OnlyActiveEvents"] = true,
["Skip:AutoRefresh"] = false,
["Show:PetBattles"] = true,
["Hide:PvP"] = false,
["Dynamic:Style"] = 1,
["CC:SL_COV_KYR"] = false,
["CC:SL_COV_VEN"] = false,
["CC:SL_COV_NFA"] = false,
["CC:SL_COV_NEC"] = false,
["Profile:ShowProfileLoadedMessage"] = true,
["Window:BackgroundColor"] = { r = 0, g = 0, b = 0, a = 1 },
["Window:BorderColor"] = { r = 1, g = 1, b = 1, a = 1 },
["Window:UseClassForBorder"] = false,
},
}
local FilterSettingsBase = {}
local TooltipSettingsBase = {
__index = {
["Auto:BountyList"] = false,
["Auto:MiniList"] = true,
["Auto:ProfessionList"] = true,
["Auto:Sync"] = true,
["Auto:AH"] = false,
["Celebrate"] = true,
["Coordinates"] = true,
["Screenshot"] = false,
["Channel"] = "Master",
["ClassRequirements"] = true,
["Descriptions"] = true,
["DisplayInCombat"] = true,
["Enabled"] = true,
["Enabled:Mod"] = "None",
["Expand:Difficulty"] = true,
["IncludeOriginalSource"] = true,
["LootSpecializations"] = true,
["MinimapButton"] = true,
["MinimapSize"] = 36,
["MinimapStyle"] = false,
["Models"] = true,
["KnownBy"] = true,
["LiveScan"] = false,
["Locations"] = 5,
["Lore"] = true,
["MainListScale"] = 1,
["MiniListScale"] = 1,
["Precision"] = 2,
["PlayDeathSound"] = false,
["Progress"] = true,
["QuestGivers"] = true,
["RaceRequirements"] = true,
["Report:Collected"] = true,
["Report:CompletedQuests"] = true,
["Report:UnsortedQuests"] = true,
["ShowIconOnly"] = false,
["SharedAppearances"] = true,
["Show:Remaining"] = false,
["Show:Percentage"] = true,
["UseMoreColors"] = true,
["Show:TooltipHelp"] = true,
["Skip:Cutscenes"] = false,
["SourceLocations"] = true,
["SourceLocations:Completed"] = true,
["SourceLocations:Creatures"] = true,
["SourceLocations:Things"] = true,
["DropChances"] = true,
["SpecializationRequirements"] = true,
["SummarizeThings"] = true,
["Warn:Difficulty"] = true,
["Warn:Removed"] = true,
["Currencies"] = true,
["QuestChain:Nested"] = true,
["WorldQuestsList:Currencies"] = true,
["ProfessionRequirements"] = true,
["LevelRequirements"] = true,
["CompletedBy"] = true,
["Updates:AdHoc"] = true,
["creatures"] = true,
},
}
local RawSettings
settings.Initialize = function(self)
-- app.PrintDebug("settings.Initialize")
-- Assign the default settings
if not settings:ApplyProfile() then
if not AllTheThingsSettings then AllTheThingsSettings = {} end
RawSettings = AllTheThingsSettings
if not RawSettings.General then RawSettings.General = {} end
if not RawSettings.Tooltips then RawSettings.Tooltips = {} end
if not RawSettings.Unobtainable then RawSettings.Unobtainable = {} end
setmetatable(RawSettings.General, GeneralSettingsBase)
setmetatable(RawSettings.Tooltips, TooltipSettingsBase)
end
-- Assign the preset filters for your character class as the default states
if not AllTheThingsSettingsPerCharacter then AllTheThingsSettingsPerCharacter = {} end
if not AllTheThingsSettingsPerCharacter.Filters then AllTheThingsSettingsPerCharacter.Filters = {} end
setmetatable(AllTheThingsSettingsPerCharacter.Filters, FilterSettingsBase)
FilterSettingsBase.__index = app.Presets[app.Class] or app.Presets.ALL
-- force re-enable of optional filters which become not optional
-- (any filterID's here must be 'true' in all class presets)
local reEnableFilters = { }
for _,filterID in ipairs(reEnableFilters) do
if not AllTheThingsSettingsPerCharacter.Filters[filterID] then
AllTheThingsSettingsPerCharacter.Filters[filterID] = nil
end
end
self.sliderSummarizeThings:SetValue(self:GetTooltipSetting("ContainsCount") or 25)
self.sliderSourceLocations:SetValue(self:GetTooltipSetting("Locations") or 5)
self.sliderMainListScale:SetValue(self:GetTooltipSetting("MainListScale"))
self.sliderMiniListScale:SetValue(self:GetTooltipSetting("MiniListScale"))
self.sliderPercentagePrecision:SetValue(self:GetTooltipSetting("Precision"))
self.sliderMinimapButtonSize:SetValue(self:GetTooltipSetting("MinimapSize"))
if self:GetTooltipSetting("MinimapButton") then
if not app.Minimap then app.Minimap = app.CreateMinimapButton() end
app.Minimap:Show()
elseif app.Minimap then
app.Minimap:Hide()
end
self:UpdateMode()
if self:GetTooltipSetting("Auto:MainList") then
app:GetWindow("Prime"):Show()
end
if self:GetTooltipSetting("Auto:RaidAssistant") then
app:GetWindow("RaidAssistant"):Show()
end
if self:GetTooltipSetting("Auto:WorldQuestsList") then
app:GetWindow("WorldQuests"):Show()
end
-- Account Synchronization
if self:GetTooltipSetting("Auto:Sync") then
app:Synchronize(true)
end
app._SettingsRefresh = GetTimePreciseSec()
settings._Initialize = true
-- app.PrintDebug("settings.Initialize:Done")
end
local function rawcopy(source, copy)
if source and copy then
for k,v in pairs(source) do
copy[k] = v
end
end
end
-- Creates, assigns, and returns a RawSettings object for a given Profile Key
settings.NewProfile = function(self, key)
if AllTheThingsProfiles and key then
-- cannot create existing profile name
if AllTheThingsProfiles.Profiles[key] then return end
local raw = {
General = {},
Tooltips = {},
Unobtainable = {},
Windows = {},
}
-- Use Ad-Hoc for new Profiles, to remove initial lag
raw.Tooltips["Updates:AdHoc"] = true
AllTheThingsProfiles.Profiles[key] = raw
return raw
end
end
-- Creates, assigns, copies existing, and returns a RawSettings object for a given Profile Key
settings.CopyProfile = function(self, key, copyKey)
if AllTheThingsProfiles then
key = key or settings:GetProfile()
-- don't try to copy the same profile
if key == copyKey then return end
-- delete the existing profile manually
AllTheThingsProfiles.Profiles[key] = nil
-- re-create the profile
local raw = settings:NewProfile(key)
local copy = AllTheThingsProfiles.Profiles[copyKey]
if copy then
rawcopy(copy.General, raw.General)
rawcopy(copy.Tooltips, raw.Tooltips)
rawcopy(copy.Unobtainable, raw.Unobtainable)
rawcopy(copy.Windows, raw.Windows)
end
return raw
end
end
-- Removes a Profile
settings.DeleteProfile = function(self, key)
if AllTheThingsProfiles and key and key ~= "Default" then
AllTheThingsProfiles.Profiles[key] = nil
-- deleting the current character's profile, reassign to Default
if key == AllTheThingsProfiles.Assignments[app.GUID] then
AllTheThingsProfiles.Assignments[app.GUID] = nil
settings.ApplyProfile()
end
-- deleting a profile used by other characters, they too will reset to default
for char,profKey in pairs(AllTheThingsProfiles.Assignments) do
if profKey == key then
AllTheThingsProfiles.Assignments[char] = nil
end
end
return true
end
end
-- Gets the Profile for the current character
settings.GetProfile = function(self, localized)
if AllTheThingsProfiles then
return AllTheThingsProfiles.Assignments[app.GUID] or (localized and DEFAULT or "Default")
end
end
-- Sets a Profile for the current character
settings.SetProfile = function(self, key)
if AllTheThingsProfiles and key then
-- don't assign Default... it's Default...
if key == "Default" then key = nil end
AllTheThingsProfiles.Assignments[app.GUID] = key
end
end
-- Applies the profile for the current character as the base settings table
settings.ApplyProfile = function()
if AllTheThingsProfiles then
local key = settings:GetProfile()
RawSettings = AllTheThingsProfiles.Profiles[key]
if not RawSettings then
RawSettings = settings:NewProfile(key)
end
setmetatable(RawSettings.General, GeneralSettingsBase)
setmetatable(RawSettings.Tooltips, TooltipSettingsBase)
-- apply window positions when applying a Profile
if RawSettings.Windows then
for suffix,_ in pairs(RawSettings.Windows) do
settings.SetWindowFromProfile(suffix)
end
end
if app.IsReady and settings:Get("Profile:ShowProfileLoadedMessage") then
app.print(L["PROFILE"]..":",settings:GetProfile(true))
end
return true
end
end
-- Allows moving an ATT window based on the position stored in the current Profile
-- This would be used when creating a Window initially during a game session
settings.SetWindowFromProfile = function(suffix)
local points = RawSettings and RawSettings.Windows and RawSettings.Windows[suffix]
local window = app.Windows[suffix]
-- print("SetWindowFromProfile",suffix,points,window)
if window then
if RawSettings then
if suffix == "Prime" then
window:SetScale(settings:GetTooltipSetting("MainListScale"))
else
window:SetScale(settings:GetTooltipSetting("MiniListScale"))
end
end
if points then
-- only allow setting positions for Windows which are inherently movable
if window:IsMovable() then
window:ClearAllPoints()
for _,point in ipairs(points) do
if point.Point then
window:SetPoint(point.Point, UIParent, point.PointRef, point.X, point.Y)
-- print("SetPoint",suffix,point.Point, point.PointRef, point.X, point.Y)
end
end
if points.Width then
window:SetWidth(points.Width)
-- print("SetWidth",suffix,points.Width)
end
if points.Height then
window:SetHeight(points.Height)
-- print("SetHeight",suffix,points.Height)
end
window.isLocked = points.Locked
else
-- if positions were stored accidentally for un-movable windows, clear them
app.print("Removed Anchors for un-movable ATT window",suffix)
RawSettings.Windows[suffix] = nil
end
end
-- Apply the user-set colours
local rBg, gBg, bBg, aBg, rBd, gBd, bBd, aBd
-- User-saved colors
rBg = tonumber(settings:Get("Window:BackgroundColor").r) or 0
gBg = tonumber(settings:Get("Window:BackgroundColor").g) or 0
bBg = tonumber(settings:Get("Window:BackgroundColor").b) or 0
aBg = tonumber(settings:Get("Window:BackgroundColor").a) or 0
-- Border colors
if settings:GetTooltipSetting("Window:UseClassForBorder") then
-- Set all the borders to the current class color
local _, class = UnitClass("player")
rBd, gBd, bBd = GetClassColor(class)
aBd = 1
else
-- User-saved colors
rBd = tonumber(settings:Get("Window:BorderColor").r) or 0
gBd = tonumber(settings:Get("Window:BorderColor").g) or 0
bBd = tonumber(settings:Get("Window:BorderColor").b) or 0
aBd = tonumber(settings:Get("Window:BorderColor").a) or 0
end
for suffix, window in pairs(AllTheThings.Windows) do
window:SetBackdropColor(rBg, gBg, bBg, aBg)
window:SetBackdropBorderColor(rBd, gBd, bBd, aBd)
end
end
end
settings.CheckSeasonalDate = function(self, eventID, startMonth, startDay, endMonth, endDay)
local today = date("*t")
local now, start, ends = time({day=today.day,month=today.month,year=today.year,hour=0,min=0,sec=0})
if startMonth <= endMonth then
start = time({day=startDay,month=startMonth,year=today.year,hour=0,min=0,sec=0})
ends = time({day=endDay,month=endMonth,year=today.year,hour=0,min=0,sec=0})
else
local year = today.year
if today.month < startMonth then year = year - 1 end
start = time({day=startDay,month=startMonth,year=year,hour=0,min=0,sec=0})
ends = time({day=endDay,month=endMonth,year=year + 1,hour=0,min=0,sec=0})
end
local active = (now >= start and now <= ends)
app.ActiveEvents[eventID] = active
-- TODO: If AllTheThings is ever going to support OG Classic in this addon, this statement is untrue currently.
app.PrintDebug("CheckSeasonalDate: This should no longer be called")
end
settings.Get = function(self, setting, container)
return RawSettings.General[setting]
end
settings.GetValue = function(self, container, setting)
return RawSettings[container][setting]
end
settings.GetUnobtainable = function(self, u)
return not u or RawSettings.Unobtainable[u]
end
settings.GetFilter = function(self, filterID)
return AllTheThingsSettingsPerCharacter.Filters[filterID]
end
settings.GetRawFilters = function(self)
return AllTheThingsSettingsPerCharacter.Filters;
end
settings.GetRawSettings = function(self, name)
return RawSettings[name];
end
settings.GetModeString = function(self)
local mode = L["MODE"]
if settings:Get("Thing:Transmog") or settings:Get("DebugMode") then
if self:Get("Completionist") then
mode = L["TITLE_COMPLETIONIST"] .. mode
else
mode = L["TITLE_UNIQUE_APPEARANCE"] .. mode
end
end
if self:Get("DebugMode") then
mode = L["TITLE_DEBUG"] .. mode
else
if self:Get("AccountMode") then
if self:Get("FactionMode") then
local englishFaction = UnitFactionGroup("player")
if englishFaction == "Alliance" then
mode = L["TITLE_ALLIANCE"] .. " " .. mode
elseif englishFaction == "Horde" then
mode = L["TITLE_HORDE"] .. " " .. mode
else
mode = L["TITLE_NEUTRAL"] .. " " .. mode
end
else
mode = L["TITLE_ACCOUNT"] .. mode
end
elseif self:Get("MainOnly") and not self:Get("Completionist") then
mode = app.ClassName .. " " .. mode .. L["TITLE_MAIN_ONLY"]
else
mode = app.ClassName .. " " .. mode
end
local things = {}
local thingCount = 0
local totalThingCount = 0
local keyPrefix
local solo = true
for key,_ in pairs(GeneralSettingsBase.__index) do
keyPrefix = string.sub(key, 1, 6)
if keyPrefix == "Thing:" then
totalThingCount = totalThingCount + 1
if settings:Get(key) and
-- Heirloom Upgrades only count when Heirlooms are enabled
(key ~= "Thing:HeirloomUpgrades" or settings:Get("Thing:Heirlooms"))
then
thingCount = thingCount + 1
table.insert(things, string.sub(key, 7))
end
elseif solo and keyPrefix == "Accoun" and settings:Get(key) then
-- TODO: a bit wonky that a disabled Thing with AccountWide checked can make it non-solo...
solo = nil
end
end
if thingCount == 0 then
mode = L["TITLE_NONE_THINGS"] .. mode
elseif thingCount == 1 then
mode = things[1] .. L["TITLE_ONLY"] .. mode
elseif thingCount == 2 then
mode = things[1] .. " + " .. things[2] .. L["TITLE_ONLY"] .. mode
elseif thingCount == totalThingCount then
-- only insane if not hiding anything!
if settings:NonInsane() then
-- don't add insane :)
else
mode = L["TITLE_INSANE"] .. mode
end
elseif not settings:Get("Thing:Transmog") then
mode = L["TITLE_SOME_THINGS"] .. mode
end
if solo then
mode = L["TITLE_SOLO"]..mode
end
end
if self:Get("Filter:ByLevel") then
mode = L["TITLE_LEVEL"] .. app.Level .. " " .. mode
end
-- Waiting on Refresh to properly show values
if self.NeedsRefresh then
mode = L["AFTER_REFRESH"] .. ": " .. mode
end
return mode
end
settings.GetShortModeString = function(self)
if self:Get("DebugMode") then
return "D"
else
local things = {}
local thingCount = 0
local totalThingCount = 0
local keyPrefix
local solo = true
for key,_ in pairs(GeneralSettingsBase.__index) do
keyPrefix = string.sub(key, 1, 6)
if keyPrefix == "Thing:" then
totalThingCount = totalThingCount + 1
if settings:Get(key) and
-- Heirloom Upgrades only count when Heirlooms are enabled
(key ~= "Thing:HeirloomUpgrades" or settings:Get("Thing:Heirlooms"))
then
thingCount = thingCount + 1
table.insert(things, string.sub(key, 7))
end
elseif solo and keyPrefix == "Accoun" and settings:Get(key) then
solo = nil
end
end
local style = ""
if thingCount == 0 then
style = "N"
elseif thingCount == totalThingCount then
-- only insane if not hiding anything!
if settings:NonInsane() then
-- don't add insane :)
else
style = "I"
end
else
style = ""
end
if solo then
style = "S"..style
end
-- Waiting on Refresh to properly show values
if self.NeedsRefresh then
style = "R:" .. " " .. style
end
if self:Get("Completionist") then
if self:Get("AccountMode") then
return style .. "AC"
else
return style .. "C"
end
else
if self:Get("AccountMode") then
return style .. "AU"
elseif self:Get("MainOnly") then
return style .. "UM"
else
return style .. "U"
end
end
end
end
-- Returns true if something is being hidden/filtered and removing Insane status
settings.NonInsane = function(self)
local ccs = app.CurrentCharacter and app.CurrentCharacter.CustomCollects and app.CurrentCharacter.CustomCollects
return
-- Hiding BoE's
self:Get("Hide:BoEs")
-- Hiding PvP
or self:Get("Hide:PvP")
-- Hiding Pet Battles
or not self:Get("Show:PetBattles")
-- Hiding any Seasonal content
or self:Get("Show:OnlyActiveEvents")
-- Non-Account Mode with Covenants filtered
or (not self:Get("AccountMode")
-- TODO: maybe track custom collect filters through a different Get method for easier logic
and (not (ccs["SL_COV_KYR"] or self:Get("CC:SL_COV_KYR"))
or not (ccs["SL_COV_NEC"] or self:Get("CC:SL_COV_NEC"))
or not (ccs["SL_COV_NFA"] or self:Get("CC:SL_COV_NFA"))
or not (ccs["SL_COV_VEN"] or self:Get("CC:SL_COV_VEN"))))
end
settings.GetPersonal = function(self, setting)
return AllTheThingsSettingsPerCharacter[setting]
end
settings.GetTooltipSetting = function(self, setting)
return RawSettings.Tooltips[setting]
end
do
local ModifierFuncs = {
["Shift"] = IsShiftKeyDown,
["Ctrl"] = IsControlKeyDown,
["Alt"] = IsAltKeyDown,
["Cmd"] = IsMetaKeyDown,
}
-- only returns 'true' for the requested TooltipSetting if the Setting's associated Modifier key is currently being pressed
settings.GetTooltipSettingWithMod = function(self, setting)
local v = RawSettings.Tooltips[setting]
if not v then return v end
local k = RawSettings.Tooltips[setting..":Mod"]
if k == "None" then
return v
end
local func = ModifierFuncs[k]
if func and func() then
return v
end
end
end
settings.Set = function(self, setting, value)
RawSettings.General[setting] = value
self:Refresh()
end
settings.SetValue = function(self, container, setting, value)
RawSettings[container][setting] = value
self:Refresh()
end
settings.SetFilter = function(self, filterID, value)
AllTheThingsSettingsPerCharacter.Filters[filterID] = value
self:UpdateMode(1)
end
settings.SetTooltipSetting = function(self, setting, value)
RawSettings.Tooltips[setting] = value
wipe(app.searchCache)
self:Refresh()
end
settings.SetPersonal = function(self, setting, value)
AllTheThingsSettingsPerCharacter[setting] = value
self:Refresh()
end
do
local function Refresh(self)
local objects = self.Objects
-- app.PrintDebug("Settings.Refresh",objects and #objects)
if objects then
for _,object in ipairs(objects) do
if object.OnRefresh then object:OnRefresh() end
if object.RefreshChildren then object:RefreshChildren() end
end
end
-- app.PrintDebug("Settings.Refresh:Done")
self.__Refreshing = nil
end
settings.Refresh = function(self)
-- apparently child components have the audacity to tell the parent it should refresh itself... so insubordinate
if self.__Refreshing then return end
self.__Refreshing = true
settings.Callback(Refresh, self)
end
end
-- Applies a basic backdrop color to a given frame
-- r/g/b expected in 1-255 range
settings.ApplyBackdropColor = function(frame, r, g, b, a)
frame.back = frame:CreateTexture(nil, "BACKGROUND")
frame.back:SetColorTexture(r/255,g/255,b/255,a)
frame.back:SetAllPoints(frame)
end
local function Mixin(o, mixin)
for k,v in pairs(mixin) do
o[k] = v;
end
return o;
end
local ATTSettingsObjectMixin, ATTSettingsPanelMixin;
-- Mixins
do
ATTSettingsObjectMixin = {
-- Performs SetPoint anchoring against the 'other' frame to align this Checkbox below it. Allows an 'indent' which defines how many steps of indentation to
-- apply either positive (right) or negative (left), or specifying another frame against which to LEFT-align
AlignBelow = function(self, other, indent)
if type(indent) == "number" then
self:SetPoint("TOPLEFT", other, "BOTTOMLEFT", indent * 8, 4)
elseif type(indent) == "table" then
self:SetPoint("TOP", other, "BOTTOM", 0, 4)
self:SetPoint("LEFT", indent, "LEFT")
else
self:SetPoint("TOPLEFT", other, "BOTTOMLEFT", 0, 4)
end
end,
-- Performs SetPoint anchoring against the 'other' frame to align this Checkbox after it (right)
AlignAfter = function(self, other, add)
local text = other.Text
add = add or 0;
if text and text:GetText() then
self:SetPoint("TOP", other, "TOP")
self:SetPoint("LEFT", other.Text, "RIGHT", 4 + add, 0)
else
self:SetPoint("LEFT", other, "RIGHT", -4 + add, 0)
end
end,
-- Disables, checks, fades the checkbox
OnRefreshCheckedDisabled = function(self)
if self.SetChecked then
self:SetChecked(true)
end
if self.Disable then
self:Disable()
end
if self.SetAlpha then
self:SetAlpha(0.4)
end
end,
-- Creates a font string attached to the top of the provided frame with the given text
AddLabel = function(self, text)
local label = self:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
Mixin(label, ATTSettingsObjectMixin);
self:RegisterObject(label);
label:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 0, -2)
label:SetJustifyH("LEFT")
label:SetHeight(18)
label:SetText(text)
return label
end,
-- Registers an Object within itself
RegisterObject = function(self, o)
if not self.Objects then self.Objects = {} end
tinsert(self.Objects, o);
end,
-- Allows an Object to Refresh all Objects
RefreshChildren = function(self)
local objects = self.Objects
if objects then
for _,object in ipairs(objects) do
if object.OnRefresh then object:OnRefresh() end
if object.RefreshChildren then object:RefreshChildren() end
end
end
end
};
ATTSettingsPanelMixin = {
-- Create a header label
CreateHeaderLabel = function(self, text)
-- Create the header label
local headerLabel = self:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
Mixin(headerLabel, ATTSettingsObjectMixin);
self:RegisterObject(headerLabel);
headerLabel:SetJustifyH("LEFT")
headerLabel:SetText(text)
headerLabel:SetWordWrap(false)
headerLabel:Show()
-- Return the header label
return headerLabel
end,
-- Create a text label, which defaults to the entire width of the options frame
CreateTextLabel = function(self, text)
-- Create the text label
local textLabel = self:CreateFontString(nil, "ARTWORK", "GameFontNormal")
Mixin(textLabel, ATTSettingsObjectMixin);
self:RegisterObject(textLabel);
textLabel:SetJustifyH("LEFT")
textLabel:SetText(text)
textLabel:SetWidth(640) -- This can be manually adjusted afterwards to 320 for half-columns
textLabel:Show()
-- Return the text label
return textLabel
end,
CreateCheckBox = function(self, text, OnRefresh, OnClick)
if not text then
print("Invalid Checkbox Info")
text = "INVALID CHECKBOX"
end
local cb = CreateFrame("CheckButton", self:GetName() .. "-" .. text, self, "InterfaceOptionsCheckButtonTemplate")
Mixin(cb, ATTSettingsObjectMixin);
self:RegisterObject(cb);
if OnClick then cb:SetScript("OnClick", OnClick) end
cb.OnRefresh = OnRefresh or cb.OnRefreshCheckedDisabled
cb.Text:SetText(text)
cb.Text:SetScale(1.1)
cb.Text:SetWordWrap(false)
cb:SetHitRectInsets(0,0 - cb.Text:GetUnboundedStringWidth(),0,0);
return cb
end,
--- Opts:
--- name (string): Name of the dropdown (lowercase)
--- items (Table): String table of the dropdown options.
--- defaultVal (String): String value for the dropdown to default to (empty otherwise).
--- changeFunc (Function): A custom function to be called, after selecting a dropdown option.
-- Reference: https://medium.com/@JordanBenge/creating-a-wow-dropdown-menu-in-pure-lua-db7b2f9c0364
CreateDropdown = function(self, opts, OnRefresh)
error("DO NOT USE THIS METHOD")
local dropdown_name = self:GetName().."DD"..(opts.name or app.UniqueCounter.CreateDropdown)
local menu_items = opts.items or {}
local title_text = opts.title or ""
local width = opts.width or 0
local default_val = opts.defaultVal or ""
local change_func = opts.changeFunc or app.EmptyFunction
local template = opts.template or "UIDropDownMenuTemplate"
local dropdown = CreateFrame("Frame", dropdown_name, self, template)
Mixin(dropdown, ATTSettingsObjectMixin);
self:RegisterObject(dropdown);
dropdown:SetHeight(19)
local dd_title = dropdown:AddLabel(title_text)
-- Sets the dropdown width to the largest item string width.
if width == 0 then
for _,item in ipairs(menu_items) do
dd_title:SetText(item)
local text_width = dd_title:GetStringWidth() + 5
if text_width > width then
width = text_width
end
end
end
dd_title:SetText(title_text)
--[[
function UIDropDownMenu_Initialize(frame, initFunction, displayMode, level, menuList)
frame.menuList = menuList
securecall("UIDropDownMenu_InitializeHelper", frame) -- <-- this function is cancer
-- Set the initialize function and call it. The initFunction populates the dropdown list.
if ( initFunction ) then
UIDropDownMenu_SetInitializeFunction(frame, initFunction)
initFunction(frame, level, frame.menuList)
end
--master frame
if(level == nil) then
level = 1
end
local dropDownList = _G["DropDownList"..level]
dropDownList.dropdown = frame
dropDownList.shouldRefresh = true
UIDropDownMenu_SetDisplayMode(frame, displayMode)
end
]]
-- UIDROPDOWNMENU_OPEN_MENU = dropdown
UIDropDownMenu_SetInitializeFunction(dropdown,
function(self)
local info
for key, val in pairs(menu_items) do
info = {}
info.text = val
info.checked = false
-- info.menuList = key
info.hasArrow = false
info.owner = dropdown
info.func = function(b, arg1, arg2, checked)
-- print("Dropdown option clicked",b.value,arg1,arg2,checked)
UIDropDownMenu_SetSelectedName(dropdown, b.value)
b.checked = true
change_func(dropdown, b.value)
end
UIDropDownMenu_AddButton(info)
end
end)
-- call the initialize function now that it's been set
dropdown:initialize()
UIDropDownMenu_SetDisplayMode(dropdown, "MENU")
UIDropDownMenu_SetWidth(dropdown, width, 5)
UIDropDownMenu_SetSelectedName(dropdown, default_val)
-- UIDropDownMenu_Initialize(dropdown,
-- ,
-- "MENU",
-- dropdown_name)
-- UIDROPDOWNMENU_OPEN_MENU = nil
dropdown.OnRefresh = OnRefresh
-- UIDropDownMenu_SetText(dropdown, default_val)
dropdown:SetHitRectInsets(0,0,0,0)
return dropdown
end,
CreateTextbox = function(self, opts, functions)
local name = self:GetName().."TB"..(opts.name or app.UniqueCounter.CreateTextbox)
local title = opts.title
local text = opts.text
local width = opts.width or 150
local template = opts.template or "InputBoxTemplate"
local editbox = CreateFrame("EditBox", name, self, template)
Mixin(editbox, ATTSettingsObjectMixin);
self:RegisterObject(editbox);
editbox:SetAutoFocus(false)
editbox:SetTextInsets(0, 0, 3, 3)
editbox:SetMaxLetters(256)
editbox:SetHeight(19)
editbox:SetWidth(width)
if text then
editbox:SetText(text)
end
if title then
editbox:AddLabel(title)
end
-- setup textbox functions
if functions then
for k,f in pairs(functions) do
editbox[k] = f
end
end
-- print("created custom EditBox using",template)
return editbox
--[[ https://www.townlong-yak.com/framexml/live/go/BoxTemplate
Virtual EditBox AuctionHouseLevelRangeEditBoxTemplate
Virtual EditBox AuctionHouseQuantityInputEditBoxTemplate
Virtual EditBox AuctionHouseSearchBoxTemplate
Virtual EditBox AuthChallengeEditBoxTemplate
Virtual EditBox AutoCompleteEditBoxTemplate
Virtual EditBox BagSearchBoxTemplate
Virtual EditBox ChatFrameEditBoxTemplate
Virtual EditBox CommunitiesChatEditBoxTemplate
Virtual EditBox CreateChannelPopupEditBoxTemplate
Virtual EditBox InputBoxTemplate
Virtual EditBox LargeInputBoxTemplate
Virtual EditBox LargeMoneyInputBoxTemplate
Virtual EditBox LFGListEditBoxTemplate
Virtual EditBox NameChangeEditBoxTemplate
Virtual EditBox SearchBoxTemplate
Virtual EditBox SharedEditBoxTemplate
Virtual EditBox StoreEditBoxTemplate
]]
end,
CreateButton = function(self, opts, functions)
local name = self:GetName().."B"..(opts.name or app.UniqueCounter.CreateButton)
local text = opts.text
local width = opts.width
local tooltip = opts.tooltip
local refs = opts.refs
local template = opts.template or "UIPanelButtonTemplate"
local f = CreateFrame("Button", name, self, template)
Mixin(f, ATTSettingsObjectMixin)
self:RegisterObject(f)
f:SetText(text)
if width then
f:SetWidth(width)
else
f:SetWidth(f:GetFontString():GetUnboundedStringWidth() + 20)
end
f:SetHeight(22)
f:RegisterForClicks("AnyUp")
if functions then