forked from NanMetal/WorldQuestTab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.lua
1073 lines (914 loc) · 30.7 KB
/
Settings.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local addonName, addon = ...
local WQT = addon.WQT
local _L = addon.L
local _V = addon.variables
local WQT_Utils = addon.WQT_Utils
local SETTINGS_PADDING_TOP = 5
local SETTINGS_PADDING_BOTTOM = 15
--------------------------------
-- WQT_SettingsBaseMixin
--------------------------------
WQT_SettingsBaseMixin = {}
function WQT_SettingsBaseMixin:OnLoad()
-- Override me
end
function WQT_SettingsBaseMixin:OnEnter(anchorFrame, anchorType)
if self.showBigTooltip then
self.showBigTooltip()
GameTooltip:Show()
return
end
local tooltipText = not self:IsDisabled() and self.tooltip or self.disabledTooltip
if (tooltipText) then
GameTooltip:SetOwner(anchorFrame or self, anchorType or "ANCHOR_RIGHT")
if (self.label) then
GameTooltip:SetText(self.label, 1, 1, 1, true)
end
GameTooltip:AddLine(tooltipText, nil, nil, nil, true)
GameTooltip:Show()
end
end
function WQT_SettingsBaseMixin:OnLeave()
GameTooltip:Hide()
end
function WQT_SettingsBaseMixin:Init(data)
self.label = data.label
self.tooltip = data.tooltip
self.disabledTooltip = data.disabledTooltip
self.valueChangedFunc = data.valueChangedFunc
self.isDisabled = data.isDisabled
if (self.Label) then
local labelText = data.label
if (data.isNew) then
labelText = labelText .. " |TInterface\\OPTIONSFRAME\\UI-OptionsFrame-NewFeatureIcon:12|t"
end
self.Label:SetText(labelText)
end
if (self.DisabledOverlay) then
self.DisabledOverlay:SetFrameLevel(self:GetFrameLevel() + 2)
end
end
function WQT_SettingsBaseMixin:Reset()
self.label = nil
self.tooltip = nil
self.valueChangedFunc = nil
if (self.Label and not self.staticLabelFont) then
self.Label:SetFontObject("GameFontNormal")
end
end
function WQT_SettingsBaseMixin:IsDisabled()
if (type(self.isDisabled) == "function") then
return self.isDisabled()
end
return self.isDisabled
end
function WQT_SettingsBaseMixin:OnValueChanged(value, userInput, ...)
if (userInput) then
if (self.valueChangedFunc) then
self.valueChangedFunc(value, ...)
end
self:GetParent():GetParent():GetParent():UpdateList()
end
end
function WQT_SettingsBaseMixin:UpdateState()
self:SetDisabled(self:IsDisabled())
end
function WQT_SettingsBaseMixin:SetDisabled(value)
if (self.Label and not self.staticLabelFont) then
self.Label:SetFontObject(value and "GameFontDisable" or "GameFontNormal")
end
if (self.DisabledOverlay) then
self.DisabledOverlay:SetShown(value)
end
end
--------------------------------
-- WQT_SettingsQuestListMixin
--------------------------------
WQT_SettingsQuestListMixin = CreateFromMixins(WQT_SettingsBaseMixin)
function WQT_SettingsQuestListMixin:OnLoad()
local questFrame = self.Preview
questFrame.Faction:SetScript("OnEnter", nil)
questFrame.Title:SetText("Example Quest Title")
questFrame.Faction.Icon:SetTexture(2058205)
local typeFrame = questFrame.Type
typeFrame.Texture:Show()
typeFrame.Elite:SetShown(true)
typeFrame.Bg:SetAtlas("worldquest-questmarker-rare")
typeFrame.Bg:SetTexCoord(0, 1, 0, 1)
typeFrame.Bg:SetSize(18, 18)
typeFrame.Texture:SetAtlas("worldquest-icon-dungeon")
typeFrame.Texture:SetSize(16, 17)
typeFrame:Show()
questFrame.Time:SetVertexColor(0, 0.75, 0)
local mapInfo = WQT_Utils:GetCachedMapInfo(942)
self.zoneName = mapInfo.name
questFrame.Extra:SetText(self.zoneName)
end
function WQT_SettingsQuestListMixin:UpdateState()
local questFrame = self.Preview
questFrame.Title:ClearAllPoints()
questFrame.Title:SetPoint("RIGHT", questFrame.Rewards, "LEFT", -5, 0)
if (WQT.settings.list.factionIcon) then
questFrame.Title:SetPoint("BOTTOMLEFT", questFrame.Faction, "RIGHT", 5, 1)
elseif (WQT.settings.list.typeIcon) then
questFrame.Title:SetPoint("BOTTOMLEFT", questFrame.Type, "RIGHT", 5, 1)
else
questFrame.Title:SetPoint("BOTTOMLEFT", questFrame, "LEFT", 10, 0)
end
-- Faction Icon
if (WQT.settings.list.factionIcon) then
questFrame.Faction:Show()
questFrame.Faction:SetWidth(questFrame.Faction:GetHeight())
else
questFrame.Faction:Hide()
questFrame.Faction:SetWidth(0.1)
end
-- Type icon
if (WQT.settings.list.typeIcon) then
questFrame.Type:Show()
questFrame.Type:SetWidth(questFrame.Type:GetHeight())
else
questFrame.Type:Hide()
questFrame.Type:SetWidth(0.1)
end
-- Zone name
questFrame.Extra:SetText(WQT.settings.list.showZone and self.zoneName or "")
-- Adjust time and zone sizes
local extraSpace = WQT.settings.list.factionIcon and 0 or 14
extraSpace = extraSpace + (WQT.settings.list.typeIcon and 0 or 14)
local timeWidth = extraSpace + (WQT.settings.list.fullTime and 70 or 60)
local zoneWidth = extraSpace + (WQT.settings.list.fullTime and 80 or 90)
if (not WQT.settings.list.showZone) then
timeWidth = timeWidth + zoneWidth
zoneWidth = 0.1
end
questFrame.Time:SetWidth(timeWidth)
questFrame.Extra:SetWidth(zoneWidth)
-- Time display
-- 74160s == 20h 36m
local timeString
if (WQT.settings.list.fullTime) then
timeString = SecondsToTime(74160, true, false)
else
timeString = D_HOURS:format(74160 / SECONDS_PER_HOUR)
end
questFrame.Time:SetText(timeString)
if (WQT.settings.list.colorTime) then
local color = WQT_Utils:GetColor(_V["COLOR_IDS"].timeMedium)
questFrame.Time:SetVertexColor(color:GetRGB())
else
questFrame.Time:SetVertexColor(_V["WQT_WHITE_FONT_COLOR"]:GetRGB())
end
-- Warband bonus
if (WQT.settings.list.showWarbandBonus) then
questFrame.WarbandBonus:Show()
else
questFrame.WarbandBonus:Hide()
end
-- Fake rewards
questFrame.Rewards:Reset()
questFrame.Rewards:AddReward(WQT_REWARDTYPE.equipment, 1733697, 3, 410, _V["WQT_COLOR_ARMOR"], true)
questFrame.Rewards:AddReward(WQT_REWARDTYPE.gold, 133784, 1, 1320000, _V["WQT_COLOR_GOLD"], false)
questFrame.Rewards:AddReward(WQT_REWARDTYPE.xp, 894556, 1, 34000, _V["WQT_COLOR_ITEM"], false)
end
--------------------------------
-- WQT_SettingsCheckboxMixin
--------------------------------
WQT_SettingsCheckboxMixin = CreateFromMixins(WQT_SettingsBaseMixin)
function WQT_SettingsCheckboxMixin:Init(data)
WQT_SettingsBaseMixin.Init(self, data)
self.getValueFunc = data.getValueFunc
self:UpdateState()
end
function WQT_SettingsCheckboxMixin:Reset()
WQT_SettingsBaseMixin.Reset(self)
self.CheckBox:Enable()
end
function WQT_SettingsCheckboxMixin:UpdateState()
WQT_SettingsBaseMixin.UpdateState(self)
if (self.getValueFunc) then
self.CheckBox:SetChecked(self.getValueFunc())
end
end
function WQT_SettingsCheckboxMixin:SetDisabled(value)
WQT_SettingsBaseMixin.SetDisabled(self, value)
if (value) then
self.CheckBox:Disable()
else
self.CheckBox:Enable()
end
end
--------------------------------
-- WQT_SettingsSliderMixin
--------------------------------
WQT_SettingsSliderMixin = CreateFromMixins(WQT_SettingsBaseMixin)
function WQT_SettingsSliderMixin:Init(data)
WQT_SettingsBaseMixin.Init(self, data)
self.getValueFunc = data.getValueFunc
self.min = data.min or 0
self.max = data.max or 1
self.SettingSlider.Slider:SetMinMaxValues(self.min, self.max)
self.SettingSlider.Slider:SetValueStep(data.valueStep)
self.SettingSlider.Slider:SetObeyStepOnDrag(data.valueStep and true or false)
self.SettingSlider.Slider:HookScript(
"OnEnter",
function(self)
self:GetParent():GetParent():OnEnter(self)
end
)
self.SettingSlider.Slider:HookScript(
"OnLeave",
function(self)
self:GetParent():GetParent():OnLeave()
end
)
self.SettingSlider.Slider:HookScript(
"OnValueChanged",
function(self, value, userInput)
self:GetParent():GetParent():OnValueChanged(value, userInput)
end
)
self.SettingSlider.Back:HookScript(
"OnClick",
function(owner)
self:OnStepperClicked(false)
end
)
self.SettingSlider.Forward:HookScript(
"OnClick",
function(owner)
self:OnStepperClicked(true)
end
)
self:UpdateState()
end
function WQT_SettingsSliderMixin:OnStepperClicked(forward)
local value = self.SettingSlider.Slider:GetValue()
local step = self.SettingSlider.Slider:GetValueStep()
if forward then
self.SettingSlider.Slider:SetValue(value + step, true)
else
self.SettingSlider.Slider:SetValue(value - step, true)
end
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
self:OnValueChanged(self.SettingSlider.Slider:GetValue(), true)
end
function WQT_SettingsSliderMixin:Reset()
WQT_SettingsBaseMixin.Reset(self)
end
function WQT_SettingsSliderMixin:UpdateState()
WQT_SettingsBaseMixin.UpdateState(self)
if (self.getValueFunc) then
local currentValue = self.getValueFunc()
self.SettingSlider.Slider:SetValue(currentValue)
self.TextBox:SetText(Round(currentValue * 100) / 100)
self.current = currentValue
end
end
function WQT_SettingsSliderMixin:SetDisabled(value)
WQT_SettingsBaseMixin.SetDisabled(self, value)
if (value) then
self.SettingSlider.Slider:Disable()
self.TextBox:Disable()
else
self.SettingSlider.Slider:Enable()
self.TextBox:Enable()
end
end
function WQT_SettingsSliderMixin:OnValueChanged(value, userInput)
-- Prevent non-number input
value = tonumber(value)
if (not value) then
-- Reset displayed values
self:UpdateState()
return
end
value = Round(value * 100) / 100
value = min(self.max, max(self.min, value))
if (userInput and value ~= self.current) then
WQT_SettingsBaseMixin.OnValueChanged(self, value, userInput)
end
self:UpdateState()
end
--------------------------------
-- WQT_SettingsColorMixin
--------------------------------
WQT_SettingsColorMixin = CreateFromMixins(WQT_SettingsBaseMixin)
function WQT_SettingsColorMixin:OnLoad()
end
function WQT_SettingsColorMixin:Init(data)
WQT_SettingsBaseMixin.Init(self, data)
self.getValueFunc = data.getValueFunc
self.defaultColor = data.defaultColor
self.colorID = data.colorID
CooldownFrame_SetDisplayAsPercentage(self.ExampleRing.Ring, 0.35)
self.ExampleRing.Pointer:SetRotation(0.65 * 6.2831)
self.ExampleRing.Ring:Show()
end
function WQT_SettingsColorMixin:UpdateState()
if (self.getValueFunc) then
local color = self.getValueFunc(self.colorID)
self:SetWidgetRGB(color:GetRGB())
-- Hex is more costly but doesn't have as meany issues 0.001 differences
local canReset = color:GenerateHexColor() ~= self.defaultColor:GenerateHexColor()
self:SetResetEnabled(canReset)
end
self.Label:Show()
self.ExampleText:Hide()
self.ExampleRing:Hide()
end
function WQT_SettingsColorMixin:SetResetEnabled(enable)
self.ResetButton:SetEnabled(enable)
self.ResetButton.Icon:SetDesaturated(not enable)
if (enable) then
self.ResetButton.Icon:SetVertexColor(1, 1, 1)
else
self.ResetButton.Icon:SetVertexColor(.7, .7, .7)
end
end
function WQT_SettingsColorMixin:ResetColor(userInput)
local r, g, b = self.defaultColor:GetRGB()
self:SetWidgetRGB(r, g, b)
self:OnValueChanged(self.colorID, userInput, r, g, b)
end
function WQT_SettingsColorMixin:SetWidgetRGB(r, g, b)
self.ExampleText:SetVertexColor(r, g, b)
self.ExampleRing.Ring:SetSwipeColor(r * 0.8, g * 0.8, b * 0.8)
self.ExampleRing.RingBG:SetVertexColor(r * 0.25, g * 0.25, b * 0.25)
self.ExampleRing.Pointer:SetVertexColor(r * 1.1, g * 1.1, b * 1.1)
self.Picker.Color:SetVertexColor(r, g, b)
end
function WQT_SettingsColorMixin:UpdateFromPicker(isConfirmed)
local r, g, b = ColorPickerFrame:GetColorRGB()
self:SetWidgetRGB(r, g, b)
if (isConfirmed) then
self:OnValueChanged(self.colorID, true, r, g, b)
self:StopPicking()
end
end
function WQT_SettingsColorMixin:StartPicking()
if (not self.getValueFunc) then
return
end
self:GetParent():GetParent():GetParent():UpdateList()
local color = self.getValueFunc(self.colorID)
local r, g, b = color:GetRGB()
local info = {
["swatchFunc"] = function()
self:UpdateFromPicker()
end,
["opacityFunc"] = function()
self:UpdateFromPicker(true)
end,
["cancelFunc"] = function()
self:ResetColor()
self:StopPicking()
end,
["r"] = r,
["g"] = g,
["b"] = b,
["extraInfo"] = "test"
}
self.Label:Hide()
self.ExampleText:Show()
self.ExampleRing:Show()
OpenColorPicker(info)
end
function WQT_SettingsColorMixin:StopPicking()
self.Label:Show()
self.ExampleText:Hide()
self.ExampleRing:Hide()
self:UpdateState()
end
--------------------------------
-- WQT_SettingsDropDownMixin
--------------------------------
WQT_SettingsDropDownMixin = CreateFromMixins(WQT_SettingsBaseMixin)
function WQT_SettingsDropDownMixin:OnLoad()
if not self.Dropdown then
self.isSpecial = true -- Custom dropdown like in settings
self.Dropdown = self.Container.Dropdown
end
self.Dropdown:SetWidth(190)
self.Dropdown:HookScript(
"OnEnter",
function()
if self.isSpecial then
self:UpdateAtlas()
end
self:OnEnter(self.Dropdown)
end
)
self.Dropdown:HookScript(
"OnLeave",
function()
if self.isSpecial then
self:UpdateAtlas()
end
self:OnLeave()
end
)
end
function WQT_SettingsDropDownMixin:UpdateAtlas()
self.Dropdown.Background:SetAtlas(self:GetBackgroundAtlas(), TextureKitConstants.UseAtlasSize)
end
function WQT_SettingsDropDownMixin:GetBackgroundAtlas()
if self.Dropdown:IsEnabled() then
if self.Dropdown:IsDownOver() then
return "common-dropdown-c-button-pressedhover-1"
elseif self.Dropdown:IsOver() then
return "common-dropdown-c-button-hover-1"
elseif self.Dropdown:IsDown() then
return "common-dropdown-c-button-pressed-1"
elseif self.Dropdown:IsMenuOpen() then
return "common-dropdown-c-button-open"
else
return "common-dropdown-c-button"
end
end
return "common-dropdown-c-button-disabled"
end
function WQT_SettingsDropDownMixin:SetDisabled(value)
WQT_SettingsBaseMixin.SetDisabled(self, value)
if (value) then
self.Dropdown:Disable()
else
self.Dropdown:Enable()
end
end
function WQT_SettingsDropDownMixin:Init(data)
WQT_SettingsBaseMixin.Init(self, data)
self.getValueFunc = data.getValueFunc
-- Create a tooltip with every option listed (as in WoW settings)
if type(data.options) == "table" and self.isSpecial then
self.showBigTooltip = function()
local tooltipText = not self:IsDisabled() and self.tooltip or self.disabledTooltip
if (tooltipText) then
GameTooltip:SetOwner(self.Dropdown, "ANCHOR_RIGHT")
if (self.label) then
GameTooltip_SetTitle(GameTooltip, self.label)
end
GameTooltip_AddNormalLine(GameTooltip, tooltipText)
-- Go through the options
if data.options then
for id, displayInfo in pairs(data.options) do
local label = displayInfo.label or "Invalid label"
local combinedLine = WrapTextInColor(label .. ": ", HIGHLIGHT_FONT_COLOR)
if displayInfo.tooltip then
combinedLine = combinedLine .. displayInfo.tooltip
GameTooltip_AddNormalLine(GameTooltip, "\n") -- New line
GameTooltip_AddNormalLine(GameTooltip, combinedLine)
end
end
end
end
end
end
self.Dropdown:SetupMenu(
function(dropdown, rootDescription)
if data.options then
self.options = data.options
local options = self.options
if type(options) == "function" then
options = options()
end
for id, displayInfo in pairs(options) do
local label = displayInfo.label or "Invalid label"
local menu =
rootDescription:CreateRadio(
label,
function()
return id == data.getValueFunc()
end,
function(index)
self:OnValueChanged(index, true)
end,
id
)
if displayInfo.tooltip then
menu:SetTooltip(
function(tooltip, elementDescription)
GameTooltip_SetTitle(tooltip, label)
GameTooltip_AddNormalLine(tooltip, displayInfo.tooltip)
end
)
end
end
end
end
)
self:UpdateState()
end
function WQT_SettingsDropDownMixin:UpdateState()
WQT_SettingsBaseMixin.UpdateState(self)
if (self.getValueFunc and self.options) then
local options = self.options
if (type(options) == "function") then
options = options()
end
-- Update dropdown
self.Dropdown:OnShow()
end
end
--------------------------------
-- WQT_SettingsButtonMixin
--------------------------------
WQT_SettingsButtonMixin = CreateFromMixins(WQT_SettingsBaseMixin)
function WQT_SettingsButtonMixin:OnLoad()
self.Label = self.Button.Label
end
function WQT_SettingsButtonMixin:SetDisabled(value)
WQT_SettingsBaseMixin.SetDisabled(self, value)
if (value) then
self.Button:Disable()
else
self.Button:Enable()
end
end
function WQT_SettingsButtonMixin:Init(data)
WQT_SettingsBaseMixin.Init(self, data)
self:UpdateState()
end
--------------------------------
-- WQT_SettingsConfirmButtonMixin
--------------------------------
WQT_SettingsConfirmButtonMixin = CreateFromMixins(WQT_SettingsBaseMixin)
function WQT_SettingsConfirmButtonMixin:OnLoad()
self.Label = self.Button.Label
end
function WQT_SettingsConfirmButtonMixin:SetDisabled(value)
WQT_SettingsBaseMixin.SetDisabled(self, value)
if (value) then
self.Button:Disable()
else
self.Button:Enable()
end
end
function WQT_SettingsConfirmButtonMixin:Init(data)
WQT_SettingsBaseMixin.Init(self, data)
end
function WQT_SettingsConfirmButtonMixin:UpdateState()
WQT_SettingsBaseMixin.UpdateState(self)
local width = (self:GetWidth() - 67) / 2
self.ButtonConfirm:SetWidth(width)
if (self.isPicking == true) then
self.Button:Show()
self.ButtonConfirm:Hide()
self.ButtonDecline:Hide()
self.isPicking = false
end
end
function WQT_SettingsConfirmButtonMixin:OnValueChanged(value, userInput)
self:SetPickingState(false)
WQT_SettingsBaseMixin.OnValueChanged(self, value, userInput)
end
function WQT_SettingsConfirmButtonMixin:SetPickingState(isPicking)
self.isPicking = isPicking
if (self.isPicking) then
self.Button:Hide()
self.ButtonConfirm:Show()
self.ButtonDecline:Show()
return
end
self.Button:Show()
self.ButtonConfirm:Hide()
self.ButtonDecline:Hide()
end
--------------------------------
-- WQT_SettingsTextInputMixin
--------------------------------
WQT_SettingsTextInputMixin = CreateFromMixins(WQT_SettingsBaseMixin)
function WQT_SettingsTextInputMixin:Init(data)
WQT_SettingsBaseMixin.Init(self, data)
self.getValueFunc = data.getValueFunc
self:UpdateState()
end
function WQT_SettingsTextInputMixin:Reset()
WQT_SettingsBaseMixin.Reset(self)
end
function WQT_SettingsTextInputMixin:UpdateState()
WQT_SettingsBaseMixin.UpdateState(self)
if (self.getValueFunc) then
local currentValue = self.getValueFunc() or ""
self.TextBox:SetText(currentValue)
self.current = currentValue
end
end
function WQT_SettingsTextInputMixin:SetDisabled(value)
WQT_SettingsBaseMixin.SetDisabled(self, value)
if (value) then
self.TextBox:Disable()
else
self.TextBox:Enable()
end
end
function WQT_SettingsTextInputMixin:OnValueChanged(value, userInput)
if (not value or value == "") then
-- Reset displayed values
self:UpdateState()
return
end
if (userInput and value ~= self.current) then
WQT_SettingsBaseMixin.OnValueChanged(self, value, userInput)
end
self:UpdateState()
end
--------------------------------
-- WQT_SettingsCategoryMixin
--------------------------------
WQT_SettingsCategoryMixin = CreateFromMixins(WQT_SettingsBaseMixin)
function WQT_SettingsCategoryMixin:Init(data)
WQT_SettingsBaseMixin.Init(self, data)
self.id = data.id
self.isExpanded = data.expanded
self.settings = {}
self.subCategories = {}
end
function WQT_SettingsCategoryMixin:UpdateState()
WQT_SettingsBaseMixin.UpdateState(self)
if self.isExpanded then
if self.SubLeft then
self.SubLeft:SetAtlas("campaign_headericon_open", true)
else
self.Right:SetAtlas("Options_ListExpand_Right_Expanded", true)
self.HighlightRight:SetAtlas("Options_ListExpand_Right_Expanded", true)
end
else
if self.SubLeft then
self.SubLeft:SetAtlas("campaign_headericon_closed", true)
else
self.Right:SetAtlas("Options_ListExpand_Right", true)
self.HighlightRight:SetAtlas("Options_ListExpand_Right", true)
end
end
end
function WQT_SettingsCategoryMixin:SetExpanded(value)
self.isExpanded = value
self:GetParent():GetParent():GetParent():Refresh()
end
--------------------------------
-- WQT_SettingsFrameMixin
--------------------------------
WQT_SettingsFrameMixin = {}
function WQT_SettingsFrameMixin:OnLoad()
-- Because we can't destroy frames, keep a pool of each type to re-use
self.categoryPool = CreateFramePool("BUTTON", self.ScrollFrame.ScrollChild, "WQT_SettingCategoryTemplate")
self.subCategoryPool = CreateFramePool("BUTTON", self.ScrollFrame.ScrollChild, "WQT_SettingSubCategoryTemplate")
self.templatePools = {}
self.categoryless = {}
self.categories = {}
self.categoriesLookup = {}
self.bufferedSettings = {}
self.bufferedCategories = {}
self.ScrollFrame:RegisterCallback(
"OnVerticalScroll",
function(offset)
self:UpdateBottomShadow(offset)
end
)
self.ScrollFrame:RegisterCallback(
"OnScrollRangeChanged",
function(offset)
self:UpdateBottomShadow(offset)
end
)
self:UpdateBottomShadow(0)
end
function WQT_SettingsFrameMixin:UpdateBottomShadow(offset)
local shadow = self:GetParent().BorderFrame.Shadow
local height = shadow:GetHeight()
local delta = self.ScrollFrame:GetVerticalScrollRange() - self.ScrollFrame:GetVerticalScroll()
local alpha = Clamp(delta / height, 0, 1)
shadow:SetAlpha(alpha)
end
function WQT_SettingsFrameMixin:Init(categories, settings)
-- Initialize 'official' settings
self.isInitialized = true
self:RegisterCategories(categories)
if (settings) then
self:AddSettingList(settings)
end
-- Add buffered settings from other add-ons
self:RegisterCategories(self.bufferedCategories)
self:AddSettingList(self.bufferedSettings)
end
function WQT_SettingsFrameMixin:SetCategoryExpanded(id, value)
local category = self.categoriesLookup[id]
if (category) then
category:SetExpanded(value)
end
end
function WQT_SettingsFrameMixin:RegisterCategories(categories)
if (categories) then
for k, data in ipairs(categories) do
self:RegisterCategory(data)
end
end
end
function WQT_SettingsFrameMixin:RegisterCategory(data)
local category = self.categoriesLookup[data.id]
-- Category already exists
if (category) then
-- Update label if provided
if (data.label) then
category.Title:SetText(data.label)
end
return
end
category = self:CreateCategory(data)
end
function WQT_SettingsFrameMixin:CreateCategory(data)
if (not self.isInitialized) then
tinsert(self.bufferedCategories, data)
return
end
if (type(data) ~= "table") then
local temp = {["id"] = data}
data = temp
end
local isSubCategory = data.parentCategory ~= nil
local category
if (isSubCategory) then
local parent = self.categoriesLookup[data.parentCategory]
if (not parent) then
return
end
category = self.subCategoryPool:Acquire()
tinsert(parent.subCategories, category)
else
category = self.categoryPool:Acquire()
end
category:Init(data)
category.Title:SetText(data.label or data.id)
if (not isSubCategory) then
tinsert(self.categories, category)
end
self.categoriesLookup[data.id] = category
return category
end
function WQT_SettingsFrameMixin:UpdateCategory(category)
if (category.isExpanded) then
for k2, setting in ipairs(category.settings) do
if (setting.UpdateState) then
setting:UpdateState()
end
end
for k2, subCategory in ipairs(category.subCategories) do
self:UpdateCategory(subCategory)
end
end
end
function WQT_SettingsFrameMixin:UpdateList()
for k, setting in ipairs(self.categoryless) do
if (setting.UpdateState) then
setting:UpdateState()
end
end
for k, category in ipairs(self.categories) do
self:UpdateCategory(category)
end
end
function WQT_SettingsFrameMixin:AcquireFrameOfTemplate(template)
if not (template) then
return
end
local pool = self.templatePools[template]
if (not pool and DoesTemplateExist(template)) then
pool =
CreateFramePool(
"FRAME",
self.ScrollFrame.ScrollChild,
template,
function(pool, frame)
frame:Reset()
end
)
self.templatePools[template] = pool
end
if (pool) then
return pool:Acquire()
end
end
function WQT_SettingsFrameMixin:GetTemplateFromType(settingType)
if (settingType == _V["SETTING_TYPES"].checkBox) then
return "WQT_SettingCheckboxTemplate"
elseif (settingType == _V["SETTING_TYPES"].subTitle) then
return "WQT_SettingSubTitleTemplate"
elseif (settingType == _V["SETTING_TYPES"].slider) then
return "WQT_SettingSliderTemplate"
elseif (settingType == _V["SETTING_TYPES"].dropDown) then
return "WQT_SettingDropDownTemplate"
elseif (settingType == _V["SETTING_TYPES"].button) then
return "WQT_SettingButtonTemplate"
end
end
function WQT_SettingsFrameMixin:AddSetting(data, isFromList)
if (not self.isInitialized) then
tinsert(self.bufferedSettings, data)
return
end
-- Support outdated usage of types
local template = data.template
if (data.type) then
template = self:GetTemplateFromType(data.type)
end
-- Get a frame of supplied template, or specific frame from _G
local frame
if (template) then
frame = self:AcquireFrameOfTemplate(template)
elseif (data.frameName) then
frame = _G[data.frameName]
frame:SetParent(self.ScrollFrame.ScrollChild)
end
-- Get a frame from the pool, initialize it, and link it to a category
if (frame) then
frame:Init(data)
local list = self.categoryless
local category = self.categoriesLookup[data.categoryID]
if (category) then
list = category.settings
elseif (data.categoryID) then
-- Category doesn't exist yet, create a temporary one
category = self:CreateCategory(data.categoryID)
list = category.settings
end
tinsert(list, frame)
end
if (not isFromList) then
self:Refresh()
end
end
function WQT_SettingsFrameMixin:AddSettingList(list)
for k, setting in ipairs(list) do
self:AddSetting(setting, true)
end
self:Refresh()
end
function WQT_SettingsFrameMixin:PlaceSetting(setting)
setting:ClearAllPoints()
if (self.previous) then
setting:SetPoint("TOPLEFT", self.previous, "BOTTOMLEFT")
else