-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperSwingTimer_Config.lua
More file actions
executable file
·5308 lines (4866 loc) · 214 KB
/
Copy pathSuperSwingTimer_Config.lua
File metadata and controls
executable file
·5308 lines (4866 loc) · 214 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 _, ns = ...
---@diagnostic disable: undefined-field
local CreateFrame = rawget(_G, "CreateFrame")
local UIParent = rawget(_G, "UIParent")
local ColorPickerFrame = rawget(_G, "ColorPickerFrame")
local GameTooltip = rawget(_G, "GameTooltip")
local C_Timer = rawget(_G, "C_Timer")
local UIDropDownMenu_AddButton = _G.UIDropDownMenu_AddButton or function() end
local UIDropDownMenu_CreateInfo = _G.UIDropDownMenu_CreateInfo or function() return {} end
local UIDropDownMenu_Initialize = _G.UIDropDownMenu_Initialize or function() end
local UIDropDownMenu_SetText = _G.UIDropDownMenu_SetText or function() end
local UIDropDownMenu_SetWidth = _G.UIDropDownMenu_SetWidth or function() end
local ToggleDropDownMenu = rawget(_G, "ToggleDropDownMenu") or function() end
local strtrim = rawget(_G, "strtrim")
local BackdropTemplateMixin = rawget(_G, "BackdropTemplateMixin")
-- ============================================================
-- Config panel: /sst opens this frame.
-- Dropdowns for layer / mode selectors, checkboxes for toggles,
-- sliders with numeric entry boxes, and color picker buttons for bar colors.
-- ============================================================
local panel
local layoutShift = 120
local layoutScale = 1.6
local function ShiftY(y)
return math.floor((y * layoutScale) + 0.5) - layoutShift
end
local function GetOptionalBackdropTemplate(template)
if not BackdropTemplateMixin then
return template
end
if template and template ~= "" then
return string.format("%s,BackdropTemplate", template)
end
return "BackdropTemplate"
end
local function CreateOptionalBackdropFrame(frameType, name, parent, template)
return CreateFrame(frameType, name, parent, GetOptionalBackdropTemplate(template))
end
local function SetFrameBackdrop(frame, backdropInfo, backgroundColor, borderColor)
if not frame or not frame.SetBackdrop then
return
end
frame:SetBackdrop(backdropInfo)
if backgroundColor and frame.SetBackdropColor then
frame:SetBackdropColor(backgroundColor[1], backgroundColor[2], backgroundColor[3], backgroundColor[4])
end
if borderColor and frame.SetBackdropBorderColor then
frame:SetBackdropBorderColor(borderColor[1], borderColor[2], borderColor[3], borderColor[4])
end
end
local function EnableScrollFrameMouseWheel(scrollFrame, step)
if not scrollFrame then
return
end
scrollFrame:EnableMouseWheel(true)
scrollFrame:SetScript("OnMouseWheel", function (self, delta)
local current = self:GetVerticalScroll() or 0
local child = self:GetScrollChild()
local maxRange = 0
if child then
maxRange = math.max((child:GetHeight() or 0) - (self:GetHeight() or 0), 0)
end
local nextScroll = math.max(0, math.min(current - (delta * (step or 32)), maxRange))
self:SetVerticalScroll(nextScroll)
end)
end
local INDICATOR_BLEND_OPTIONS = { { label = "Glow", value = "ADD" }, { label = "Opaque", value = "BLEND" } }
local TEXTURE_BROWSER_CATEGORY_CHOICES = {
{ label = "All", value = "All" }, { label = "Shapes", value = "WeakAuras" },
{ label = "SharedMedia", value = "SharedMedia" }, { label = "Blizzard", value = "Blizzard" },
{ label = "Platynator", value = "Platynator" }
}
local function GetTextureBrowserCategoryLabel(categoryValue)
for _, choice in ipairs(TEXTURE_BROWSER_CATEGORY_CHOICES) do
if choice.value == categoryValue then
return choice.label
end
end
return TEXTURE_BROWSER_CATEGORY_CHOICES[1].label
end
local function GetOptionLabel(options, value)
for _, option in ipairs(options) do
if option.value == value then
return option.label
end
end
return options[1].label
end
local function FormatSliderValue(step, value)
if step and step < 1 then
return string.format("%.2f", value)
end
return tostring(math.floor(value + 0.5))
end
local function NormalizeSliderValue(text, minVal, maxVal, step)
local value = tonumber(text)
if not value then
return nil
end
value = math.max(minVal, math.min(maxVal, value))
if step and step > 0 then
value = minVal + math.floor(((value - minVal) / step) + 0.5) * step
value = math.max(minVal, math.min(maxVal, value))
end
return value
end
local function SyncSliderDisplay(slider, value)
if not slider then
return
end
local displayValue = slider.formatValue and slider.formatValue(value) or tostring(value)
if slider.valueText then
slider.valueText:SetText(displayValue)
end
if slider.valueBox and not slider.valueBox:HasFocus() then
slider.valueBox:SetText(displayValue)
end
end
local function AddRowHoverHighlight(row, alpha)
if not row then
return nil
end
local highlight = row:CreateTexture(nil, "HIGHLIGHT")
highlight:SetColorTexture(1, 1, 1, alpha or 0.06)
highlight:SetAllPoints(true)
return highlight
end
local function AddControlTooltip(frame, title, text)
if not frame or not GameTooltip or not frame.HookScript then
return
end
frame:HookScript("OnEnter", function (self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText(title or "", 1, 1, 1)
if text and text ~= "" then
GameTooltip:AddLine(text, 0.9, 0.9, 0.9, true)
end
GameTooltip:Show()
end)
frame:HookScript("OnLeave", function ()
GameTooltip:Hide()
end)
end
local function GetTextureSummaryText(texturePath)
if ns.GetTextureSummaryText then
return ns.GetTextureSummaryText(texturePath)
end
local sparkLabel = ns.GetTextureDisplayText(texturePath)
local barTexture = ns.GetBarTexture and ns.GetBarTexture() or nil
local barLabel = ns.GetTextureDisplayText(barTexture)
return string.format("%s | Bar: %s", sparkLabel, barLabel)
end
local function SetRowsShown(rows, shown)
if not rows then
return
end
local showAdvanced = SuperSwingTimerDB and SuperSwingTimerDB.showAdvanced == true
for _, row in ipairs(rows) do
if row then
if row.isAdvanced and not showAdvanced then
if row.SetShown then
row:SetShown(false)
elseif row.Hide then
row:Hide()
end
else
if row.SetShown then
row:SetShown(shown)
elseif shown and row.Show then
row:Show()
elseif not shown and row.Hide then
row:Hide()
end
end
end
end
end
local function RememberRowLayoutInsets(row)
if not row or row._layoutInsetsStored then
return
end
local leftInset = nil
local rightInset = nil
local pointCount = row.GetNumPoints and row:GetNumPoints() or 0
for index = 1, pointCount do
local _, _, relativePoint, xOfs = row:GetPoint(index)
if relativePoint == "TOPLEFT" then
leftInset = xOfs
elseif relativePoint == "TOPRIGHT" then
rightInset = -(xOfs or 0)
end
end
row._layoutLeftInset = leftInset or 20
row._layoutRightInset = rightInset
row._layoutInsetsStored = true
end
local function GetRowLayoutHeight(row)
if not row then
return 0
end
if row.layoutHeight and row.layoutHeight > 0 then
return row.layoutHeight
end
local height = row.GetHeight and row:GetHeight() or 0
if row.text and row.text.GetStringHeight then
height = math.max(height, row.text:GetStringHeight() + 8)
end
return height
end
local function PositionRowAtY(parent, row, topY)
if not parent or not row then
return
end
RememberRowLayoutInsets(row)
row:ClearAllPoints()
row:SetPoint("TOPLEFT", parent, "TOPLEFT", row._layoutLeftInset or 20, topY)
if row._layoutRightInset ~= nil then
row:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -(row._layoutRightInset or 20), topY)
end
end
local function PositionRowBetween(parent, row, leftX, rightX, topY)
if not parent or not row then
return
end
row:ClearAllPoints()
row:SetPoint("TOPLEFT", parent, "TOPLEFT", leftX, topY)
row:SetPoint("TOPRIGHT", parent, "TOPLEFT", rightX, topY)
end
local function SetRowClassRequirement(row, classToken)
if row then
row.requiredClass = classToken
end
return row
end
local function AppendRow(rows, row)
if row then
rows[#rows + 1] = row
end
return row
end
local BAR_COLOR_KEYS = { "mh", "oh", "ranged" }
local function UsesClassColorToggle(colorKey)
for _, key in ipairs(BAR_COLOR_KEYS) do
if key == colorKey then
return true
end
end
return false
end
local function CopyColor(color, fallback)
local source = color or fallback or { r = 1, g = 1, b = 1, a = 1 }
return { r = source.r or 1, g = source.g or 1, b = source.b or 1, a = source.a ~= nil and source.a or 1 }
end
local function SavePreClassColorState()
if not SuperSwingTimerDB then
return
end
SuperSwingTimerDB.colors = SuperSwingTimerDB.colors or {}
SuperSwingTimerDB.preClassColors = {}
for _, key in ipairs(BAR_COLOR_KEYS) do
local current = SuperSwingTimerDB.colors[key] or (ns.DB_DEFAULTS.colors and ns.DB_DEFAULTS.colors[key])
SuperSwingTimerDB.preClassColors[key] = CopyColor(current, ns.DB_DEFAULTS.colors and ns.DB_DEFAULTS.colors[key])
end
local sparkColor = SuperSwingTimerDB.sparkColor or ns.GetSparkColor() or ns.DB_DEFAULTS.sparkColor
SuperSwingTimerDB.preClassSparkColor = CopyColor(sparkColor, ns.DB_DEFAULTS.sparkColor)
end
local function RestoreColorsAfterClassToggleDisabled()
if not SuperSwingTimerDB then
return
end
SuperSwingTimerDB.colors = SuperSwingTimerDB.colors or {}
local restoredFromBackup = false
if SuperSwingTimerDB.preClassColors then
for _, key in ipairs(BAR_COLOR_KEYS) do
local saved = SuperSwingTimerDB.preClassColors[key]
if saved then
SuperSwingTimerDB.colors[key] = CopyColor(saved, ns.DB_DEFAULTS.colors and ns.DB_DEFAULTS.colors[key])
restoredFromBackup = true
end
end
end
if SuperSwingTimerDB.preClassSparkColor then
SuperSwingTimerDB.sparkColor = CopyColor(SuperSwingTimerDB.preClassSparkColor, ns.DB_DEFAULTS.sparkColor)
restoredFromBackup = true
end
SuperSwingTimerDB.preClassColors = nil
SuperSwingTimerDB.preClassSparkColor = nil
if restoredFromBackup then
return
end
end
-- ============================================================
-- Bar preview: show bars while config panel is open
-- ============================================================
local function ShowBarPreview()
if ns.UpdateOHBar then
ns.UpdateOHBar()
end
ns.ApplyBarTexture(ns.GetBarTexture(), ns.GetBarTextureLayer())
ns.ApplyRangedBarTexture(ns.GetRangedBarTexture(), ns.GetBarTextureLayer())
ns.ApplySparkSettings(
ns.GetSparkTexture(), ns.GetSparkWidth(), ns.GetSparkHeight(), ns.GetSparkTextureLayer(), ns.GetSparkAlpha()
)
ns.ApplyBarBackgroundColor(ns.GetBarBackgroundColor())
ns.ApplyBarBorderColor(ns.GetBarBorderColor())
ns.ApplyBarBorderSize(ns.GetBarBorderSize())
ns.ApplyMinimalMode(ns.IsMinimalMode())
ns.ApplyBarColors()
ns.ApplyIndicatorBlendMode(ns.GetIndicatorBlendMode())
ns.ApplyVisibility()
local bars = { ns.enemyBar, ns.mhBar, ns.ohBar, ns.rangedBar, ns.hunterCastBar }
for _, bar in ipairs(bars) do
if bar then
bar:SetAlpha(1)
bar:SetMinMaxValues(0, 1)
bar:SetValue(1)
if ns.RefreshBarSparkPosition then
ns.RefreshBarSparkPosition(bar, 1)
end
end
end
if ns.UpdateRogueEnergyTickVisual then
ns.UpdateRogueEnergyTickVisual()
end
if ns.UpdateRogueComboPointVisual then
ns.UpdateRogueComboPointVisual()
end
if ns.UpdateRogueSliceAndDiceVisual then
ns.UpdateRogueSliceAndDiceVisual()
end
end
local function HideBarPreview()
if ns.barTestActive then
return
end
if ns.ApplyVisibility then
ns.ApplyVisibility()
return
end
-- Fallback only if the shared visibility helper is unavailable.
local bars = { ns.enemyBar, ns.mhBar, ns.ohBar, ns.rangedBar, ns.hunterCastBar }
for _, bar in ipairs(bars) do
if bar then bar:SetAlpha(0) end
end
if ns.UpdateRogueEnergyTickVisual then
ns.UpdateRogueEnergyTickVisual()
end
if ns.UpdateRogueComboPointVisual then
ns.UpdateRogueComboPointVisual()
end
if ns.UpdateRogueSliceAndDiceVisual then
ns.UpdateRogueSliceAndDiceVisual()
end
end
-- ------------------------------------------------------------
-- Animate test bars during barTestActive — drives each bar
-- through a separate swing cycle so they move like real timers.
-- ------------------------------------------------------------
local function AnimateTestBars()
if not ns.barTestStartTime then return end
local now = ns.GetAlignedTime()
local t = now - ns.barTestStartTime
local function animateOne(bar, period, offset)
if not bar then return end
local phase = ((t + offset) % period) / period
local val = math.min(math.max(phase, 0), 1)
bar:SetValue(val)
if ns.RefreshBarSparkPosition then
ns.RefreshBarSparkPosition(bar, val)
end
end
animateOne(ns.mhBar, 3.6, 0)
animateOne(ns.ohBar, 2.4, 0.8)
animateOne(ns.rangedBar, 2.8, 1.5)
animateOne(ns.enemyBar, 2.2, 0.3)
animateOne(ns.hunterCastBar, 1.5, 2.0)
end
local function StartBarTestPreview(duration)
duration = tonumber(duration) or 16
ns.barTestActive = true
ns.barTestStartTime = ns.GetAlignedTime()
if ns.barTestTimer and ns.barTestTimer.Cancel then
ns.barTestTimer:Cancel()
ns.barTestTimer = nil
end
ShowBarPreview()
if panel and panel.Hide then
panel:Hide()
end
if C_Timer and C_Timer.NewTimer then
ns.barTestTimer = C_Timer.NewTimer(duration, function ()
ns.barTestActive = false
ns.barTestStartTime = nil
ns.barTestTimer = nil
HideBarPreview()
end)
end
end
-- ============================================================
-- Color picker helper
-- ============================================================
local function OpenColorPicker(options)
if not options or not options.getColor or not options.applyColor then
return
end
local c = options.getColor() or { r = 1, g = 1, b = 1, a = 1 }
local allowAlpha = options.allowAlpha == true
local function Commit(r, g, b, a)
a = tonumber(a)
if not allowAlpha then
a = 1
elseif a == nil then
a = c.a or 1
elseif a < 0 then
a = 0
elseif a > 1 then
a = 1
end
options.applyColor(r or 1, g or 1, b or 1, a)
end
local info = {
r = c.r or 1,
g = c.g or 1,
b = c.b or 1,
hasOpacity = allowAlpha,
opacity = allowAlpha and (c.a or 1) or nil,
swatchFunc = function ()
local r, g, b = ColorPickerFrame:GetColorRGB()
local a = allowAlpha and (ColorPickerFrame.GetColorAlpha and ColorPickerFrame:GetColorAlpha() or c.a or 1)
or 1
Commit(r, g, b, a)
end,
cancelFunc = function (prev)
if prev then
Commit(prev.r, prev.g, prev.b, allowAlpha and (prev.a or 1) or 1)
else
Commit(c.r or 1, c.g or 1, c.b or 1, allowAlpha and (c.a or 1) or 1)
end
end
}
if allowAlpha then
info.opacityFunc = function ()
local r, g, b = ColorPickerFrame:GetColorRGB()
local a = ColorPickerFrame.GetColorAlpha and ColorPickerFrame:GetColorAlpha() or c.a or 1
Commit(r, g, b, a)
end
end
ColorPickerFrame:SetupColorPickerAndShow(info)
end
-- ============================================================
-- Widget builders
-- ============================================================
local function CreateLabeledSliderRow(parent, label, minVal, maxVal, step, yOffset, options)
options = options or {}
local leftInset = options.leftInset or 20
local rightInset = options.rightInset or 20
local valueBoxWidth = options.valueBoxWidth or 58
local row = CreateFrame("Frame", nil, parent)
row:SetPoint("TOPLEFT", parent, "TOPLEFT", leftInset, yOffset)
row:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -rightInset, yOffset)
row:SetHeight(options.rowHeight or 84)
row.layoutHeight = row:GetHeight()
row:EnableMouse(true)
row.hover = AddRowHoverHighlight(row)
local text = row:CreateFontString(nil, "OVERLAY", "GameFontNormal")
text:SetPoint("TOPLEFT", row, "TOPLEFT", 0, 0)
text:SetPoint("TOPRIGHT", row, "TOPRIGHT", -(valueBoxWidth + 12), 0)
text:SetJustifyH("LEFT")
text:SetJustifyV("TOP")
text:SetText(label)
if text.SetTextColor then
text:SetTextColor(1, 0.82, 0.05, 1)
end
row.text = text
local slider = CreateFrame("Slider", nil, row, "OptionsSliderTemplate")
slider:SetPoint("TOPLEFT", row, "TOPLEFT", 0, -30)
slider:SetPoint("TOPRIGHT", row, "TOPRIGHT", -(valueBoxWidth + 12), -30)
slider:SetMinMaxValues(minVal, maxVal)
slider:SetValueStep(step)
slider:SetObeyStepOnDrag(true)
slider:SetHeight(16)
if slider.SetFrameLevel and row.GetFrameLevel then
slider:SetFrameLevel(row:GetFrameLevel() + 2)
end
if slider.Text then
slider.Text:SetText("")
end
if slider.Low then
slider.Low:SetText(FormatSliderValue(step, minVal))
slider.Low:ClearAllPoints()
slider.Low:SetPoint("TOPLEFT", slider, "BOTTOMLEFT", -2, 0)
end
if slider.High then
slider.High:SetText(FormatSliderValue(step, maxVal))
slider.High:ClearAllPoints()
slider.High:SetPoint("TOPRIGHT", slider, "BOTTOMRIGHT", 2, 0)
end
-- Slider track visuals (shared by every slider row).
-- Render in a dedicated frame level so the track is always visible in Classic/TBC
-- clients where OptionsSliderTemplate internals can mask BACKGROUND textures.
local trackLayer = CreateFrame("Frame", nil, row)
trackLayer:SetPoint("LEFT", slider, "LEFT", -1, 0)
trackLayer:SetPoint("RIGHT", slider, "RIGHT", 1, 0)
trackLayer:SetHeight(6)
if trackLayer.SetFrameLevel and row.GetFrameLevel then
trackLayer:SetFrameLevel(row:GetFrameLevel() + 1)
end
local trackShadow = trackLayer:CreateTexture(nil, "ARTWORK", nil, 0)
trackShadow:SetAllPoints(trackLayer)
trackShadow:SetColorTexture(0.02, 0.02, 0.02, 1)
local trackBg = trackLayer:CreateTexture(nil, "ARTWORK", nil, 1)
trackBg:SetPoint("TOPLEFT", trackLayer, "TOPLEFT", 1, -1)
trackBg:SetPoint("BOTTOMRIGHT", trackLayer, "BOTTOMRIGHT", -1, 1)
trackBg:SetColorTexture(0.32, 0.32, 0.32, 0.95)
row.trackLayer = trackLayer
row.trackShadow = trackShadow
row.trackBg = trackBg
local valueBox = CreateFrame("EditBox", nil, row, "InputBoxTemplate")
valueBox:SetSize(valueBoxWidth, 20)
valueBox:SetPoint("TOPRIGHT", row, "TOPRIGHT", 0, -24)
valueBox:SetAutoFocus(false)
valueBox:SetMaxLetters(options.maxLetters or 8)
valueBox:SetJustifyH("CENTER")
row.sliderWidget = slider
row.valueBox = valueBox
row.valueText = nil
row.formatValue = function (value)
return FormatSliderValue(step, value)
end
row.GetValue = function (self)
return self.sliderWidget:GetValue()
end
row.SetValue = function (self, value)
self.sliderWidget:SetValue(value)
end
row.SetScript = function (self, scriptType, handler)
if scriptType == "OnValueChanged" then
self.sliderWidget:SetScript(scriptType, function (_, value, ...)
handler(self, value, ...)
end)
else
self.sliderWidget:SetScript(scriptType, handler)
end
end
valueBox:SetScript("OnEnterPressed", function (self)
local parsed = NormalizeSliderValue(self:GetText(), minVal, maxVal, step)
if parsed ~= nil then
row:SetValue(parsed)
end
self:ClearFocus()
SyncSliderDisplay(row, row:GetValue())
end)
valueBox:SetScript("OnEscapePressed", function (self)
self:ClearFocus()
SyncSliderDisplay(row, row:GetValue())
end)
valueBox:SetScript("OnEditFocusGained", function (self)
self:HighlightText()
end)
valueBox:SetScript("OnEditFocusLost", function (self)
SyncSliderDisplay(row, row:GetValue())
end)
local sliderTooltip = options.tooltipText or string.format("Drag or type a value to change %s.", label)
AddControlTooltip(row, label, sliderTooltip)
AddControlTooltip(valueBox, label, string.format("Type a value for %s.", label))
SyncSliderDisplay(row, row:GetValue())
if ns._panelSearchAdder then ns._panelSearchAdder(row, label) end
return row
end
local function CreateSlider(parent, label, minVal, maxVal, step, yOffset, options)
options = options or {}
return CreateLabeledSliderRow(parent, label, minVal, maxVal, step, yOffset, {
leftInset = 20,
rightInset = 20,
valueBoxWidth = 58,
maxLetters = 8,
rowHeight = 72,
tooltipText = options.tooltipText
})
end
-- ------------------------------------------------------------
-- Compact slider now reuses the same readable full-width row pattern.
-- ------------------------------------------------------------
local function CreateCompactSlider(parent, label, minVal, maxVal, step, yOffset, leftInset, rightInset, options)
options = options or {}
return CreateLabeledSliderRow(parent, label, minVal, maxVal, step, yOffset, {
leftInset = 20,
rightInset = 20,
valueBoxWidth = 52,
maxLetters = 6,
rowHeight = 72,
tooltipText = options.tooltipText
})
end
local function CreateColorButton(parent, label, colorKey, yOffset, options)
options = options or {}
local leftInset = options.leftInset or 20
local rightInset = options.rightInset or 20
local compactLayout = options.compact == true
local rowHeight = options.rowHeight or (compactLayout and 32 or 58)
local buttonWidth = options.buttonWidth or 180
local getColor = options.getColor
or function ()
return ns.GetBarColor(colorKey)
end
local allowAlpha = options.allowAlpha == true
local tooltipText = options.tooltipText or string.format("Click the swatch button to change the %s color.", label)
local row = CreateFrame("Frame", nil, parent)
row:SetPoint("TOPLEFT", parent, "TOPLEFT", leftInset, yOffset)
row:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -rightInset, yOffset)
row:SetHeight(rowHeight)
row.layoutHeight = rowHeight
row:EnableMouse(true)
row.hover = AddRowHoverHighlight(row)
local text = row:CreateFontString(nil, "OVERLAY", "GameFontNormal")
text:SetPoint("TOPLEFT", row, "TOPLEFT", 0, 0)
text:SetText(label)
if text.SetTextColor then
text:SetTextColor(1, 0.82, 0.05, 1)
end
if not compactLayout then
text:SetPoint("TOPRIGHT", row, "TOPRIGHT", 0, 0)
text:SetJustifyH("LEFT")
text:SetJustifyV("TOP")
else
text:SetJustifyH("LEFT")
text:SetJustifyV("TOP")
end
local btn = CreateFrame("Button", nil, row)
btn:SetSize(buttonWidth, 20)
if compactLayout then
btn:SetPoint("BOTTOMRIGHT", row, "BOTTOMRIGHT", 0, 0)
text:SetPoint("RIGHT", btn, "LEFT", -12, 0)
else
btn:ClearAllPoints()
btn:SetPoint("BOTTOMLEFT", row, "BOTTOMLEFT", 0, 0)
btn:SetPoint("BOTTOMRIGHT", row, "BOTTOMRIGHT", 0, 0)
btn:SetHeight(24)
end
local border = btn:CreateTexture(nil, "BACKGROUND")
border:SetPoint("TOPLEFT", btn, "TOPLEFT", -1, 1)
border:SetPoint("BOTTOMRIGHT", btn, "BOTTOMRIGHT", 1, -1)
border:SetColorTexture(0.42, 0.42, 0.42, 1)
btn.border = border
local previewBase = btn:CreateTexture(nil, "BACKGROUND")
previewBase:SetPoint("TOPLEFT", btn, "TOPLEFT", 0, 0)
previewBase:SetPoint("BOTTOMRIGHT", btn, "BOTTOMRIGHT", 0, 0)
previewBase:SetColorTexture(0.08, 0.08, 0.08, 0.96)
btn.previewBase = previewBase
local swatch = btn:CreateTexture(nil, "ARTWORK")
swatch:SetAllPoints(previewBase)
local c = getColor()
if c then
swatch:SetColorTexture(c.r, c.g, c.b, c.a)
end
btn.swatch = swatch
btn.colorKey = colorKey
local gloss = btn:CreateTexture(nil, "OVERLAY")
gloss:SetPoint("TOPLEFT", swatch, "TOPLEFT", 0, 0)
gloss:SetPoint("TOPRIGHT", swatch, "TOPRIGHT", 0, 0)
gloss:SetHeight(8)
gloss:SetColorTexture(1, 1, 1, 0.08)
btn.gloss = gloss
-- Color label on the swatch button itself, readable on any fill
if compactLayout then
local btnLabel = btn:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
btnLabel:SetPoint("CENTER", btn, "CENTER", 0, 0)
btnLabel:SetText(label)
btnLabel:SetJustifyH("CENTER")
btnLabel:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
btnLabel:SetTextColor(1, 1, 1, 0.9)
btn.btnLabel = btnLabel
local function UpdateBtnLabel()
local color = getColor()
if color then
-- Dark backgrounds get white text, light backgrounds get dark text
local luminance = (color.r or 0) * 0.3 + (color.g or 0) * 0.6 + (color.b or 0) * 0.1
local textAlpha = compactLayout and 0.85 or 0
if luminance > 0.5 then
btnLabel:SetTextColor(0, 0, 0, textAlpha)
else
btnLabel:SetTextColor(1, 1, 1, textAlpha)
end
end
end
UpdateBtnLabel()
btn.UpdateBtnLabel = UpdateBtnLabel
end
local function ApplySelectedColor(r, g, b, a)
local alpha = allowAlpha and (a or 1) or 1
if options.applyColor then
options.applyColor(r, g, b, alpha, swatch)
else
local isSealTwist = (colorKey == "sealTwist")
if not isSealTwist and UsesClassColorToggle(colorKey) then
SuperSwingTimerDB.useClassColors = false
end
SuperSwingTimerDB.colors[colorKey] = { r = r, g = g, b = b, a = alpha }
ns.ApplyBarColors()
if panel and panel.useClassColorsRow and panel.useClassColorsRow.refresh then
panel.useClassColorsRow.refresh()
end
if panel and panel.colorRows then
for _, colorRow in ipairs(panel.colorRows) do
if colorRow and colorRow.button and colorRow.swatch then
local key = colorRow.button.colorKey
local effective = ns.GetBarColor(key)
if effective then
colorRow.swatch:SetColorTexture(effective.r, effective.g, effective.b, effective.a)
if colorRow.button.UpdateBtnLabel then colorRow.button.UpdateBtnLabel() end
end
end
end
end
end
swatch:SetColorTexture(r, g, b, alpha)
if btn.UpdateBtnLabel then btn.UpdateBtnLabel() end
end
local function Refresh()
local color = getColor() or { r = 1, g = 1, b = 1, a = 1 }
swatch:SetColorTexture(color.r or 1, color.g or 1, color.b or 1, color.a or 1)
if btn.UpdateBtnLabel then btn.UpdateBtnLabel() end
end
local function OpenPicker()
OpenColorPicker({
getColor = getColor,
allowAlpha = allowAlpha,
applyColor = ApplySelectedColor
})
end
btn:SetScript("OnClick", OpenPicker)
btn:SetScript("OnEnter", function (self)
if self.border then
self.border:SetColorTexture(0.82, 0.82, 0.82, 1)
end
end)
btn:SetScript("OnLeave", function (self)
if self.border then
self.border:SetColorTexture(0.42, 0.42, 0.42, 1)
end
end)
AddControlTooltip(row, label, tooltipText)
row:SetScript("OnMouseUp", function (_, button)
if button == "LeftButton" then
if btn.IsMouseOver and btn:IsMouseOver() then
return
end
OpenPicker()
end
end)
if ns._panelSearchAdder then ns._panelSearchAdder(row, label) end
row.button = btn
row.swatch = swatch
row.refresh = Refresh
Refresh()
return row
end
local function NormalizeTexturePath(texturePath, defaultTexture)
texturePath = strtrim(texturePath or "")
if texturePath == "" then
return defaultTexture or ns.DB_DEFAULTS.sparkTexture
end
return texturePath
end
local function GetTextureBrowserEntries(allowedCategories, allowedUsages)
local library = ns.TEXTURE_LIBRARY or ns.BuildTextureLibrary() or {}
local entries = {}
for _, entry in ipairs(library) do
local categoryAllowed = not allowedCategories or allowedCategories[entry.category]
local usage = entry.usage or "both"
local usageAllowed = not allowedUsages or allowedUsages[usage]
if categoryAllowed and usageAllowed then
entries[#entries + 1] = entry
end
end
table.sort(entries, function (a, b)
local aCategory = a.category or ""
local bCategory = b.category or ""
if aCategory ~= bCategory then
return aCategory < bCategory
end
local aLabel = a.label or a.path or ""
local bLabel = b.label or b.path or ""
if aLabel ~= bLabel then
return aLabel < bLabel
end
return (a.path or "") < (b.path or "")
end)
return entries
end
local textureBrowserFrame
local function HideTextureBrowserGrid(frame)
for _, button in ipairs(frame.buttons or {}) do
button:Hide()
end
if frame.listScrollFrame then
frame.listScrollFrame:Hide()
end
end
local function CreateTextureBrowserListRow(parent)
local button = CreateOptionalBackdropFrame("Button", nil, parent)
button:SetHeight(26)
SetFrameBackdrop(button, {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 4,
edgeSize = 8,
insets = { left = 1, right = 1, top = 1, bottom = 1 }
}, { 0.08, 0.08, 0.08, 0.94 }, { 0.30, 0.30, 0.30, 1 }
)
local preview = button:CreateTexture(nil, "BACKGROUND")
preview:SetPoint("TOPLEFT", button, "TOPLEFT", 2, -2)
preview:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -2, 2)
preview:SetTexCoord(0.02, 0.98, 0.15, 0.85)
button.preview = preview
local shade = button:CreateTexture(nil, "BORDER")
shade:SetAllPoints(preview)
shade:SetColorTexture(0, 0, 0, 0.28)
button.shade = shade
local label = button:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
label:SetPoint("LEFT", button, "LEFT", 8, 0)
label:SetPoint("RIGHT", button, "RIGHT", -8, 0)
label:SetJustifyH("LEFT")
label:SetText("")
if label.SetShadowOffset then
label:SetShadowOffset(1, -1)
label:SetShadowColor(0, 0, 0, 1)
end
button.label = label
button:SetScript("OnEnter", function (self)
if not self.entry then
return
end
if self.SetBackdropBorderColor then
self:SetBackdropBorderColor(0.82, 0.82, 0.82, 1)
end
if GameTooltip then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText(self.displayLabel or self.entry.label or self.entry.path or "", 1, 1, 1)
if self.displayCategory and self.displayCategory ~= "" then
GameTooltip:AddLine(self.displayCategory, 0.82, 0.82, 0.82)
end
if self.displayPath and self.displayPath ~= "" then
GameTooltip:AddLine(self.displayPath, 0.72, 0.72, 0.72, true)
end
GameTooltip:Show()
end
end)
button:SetScript("OnLeave", function (self)
if GameTooltip then
GameTooltip:Hide()
end
local owner = self.ownerFrame
if owner and owner.Refresh then
owner:Refresh()
end
end)
button:SetScript("OnClick", function (self)
if self.entry and self.ownerFrame then
self.ownerFrame.pendingTexture = self.entry.path
if self.ownerFrame.Refresh then
self.ownerFrame:Refresh()
end
end
end)
return button
end
local function EnsureTextureBrowserList(frame)
if frame.listScrollFrame then
return
end
local scrollFrame = CreateFrame("ScrollFrame", nil, frame, "UIPanelScrollFrameTemplate")
scrollFrame:SetPoint("TOPLEFT", frame, "TOPLEFT", 16, -80)
scrollFrame:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -34, 46)
scrollFrame:SetClipsChildren(true)
EnableScrollFrameMouseWheel(scrollFrame, 32)
local content = CreateFrame("Frame", nil, scrollFrame)
content:SetSize(1, 1)
scrollFrame:SetScrollChild(content)
frame.listScrollFrame = scrollFrame
frame.listContent = content