Repository navigation
Expand file tree
/
Copy pathOptions.lua
More file actions
2706 lines (2545 loc) · 122 KB
/
Copy pathOptions.lua
File metadata and controls
2706 lines (2545 loc) · 122 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 = ...
local COLORS = {
-- Resonance follows the suite's BindCards surface stack: near-black
-- window chrome, blue-charcoal papers, one-pixel quiet borders, then
-- teal only for a chosen or successful state. This is the same compact
-- surface vocabulary used by BindCards.
window = { 0.035, 0.041, 0.052, 0.985 },
panel = { 0.055, 0.063, 0.078, 1 },
paper = { 0.073, 0.082, 0.098, 1 },
paperAlt = { 0.060, 0.069, 0.084, 1 },
card = { 0.073, 0.082, 0.098, 1 },
cardAlt = { 0.060, 0.069, 0.084, 1 },
raised = { 0.095, 0.108, 0.129, 1 },
border = { 0.20, 0.235, 0.28, 0.72 },
faint = { 0.18, 0.21, 0.25, 0.25 },
blue = { 0.27, 0.58, 0.82, 1 },
blueSoft = { 0.18, 0.36, 0.52, 1 },
accent = { 0.27, 0.58, 0.82, 1 },
teal = { 0.18, 0.76, 0.70, 1 },
tealDim = { 0.06, 0.20, 0.19, 1 },
text = { 0.91, 0.93, 0.96, 1 },
muted = { 0.59, 0.64, 0.71, 1 },
warning = { 0.93, 0.66, 0.25, 1 },
danger = { 0.88, 0.31, 0.34, 1 },
}
local WHITE = "Interface\\Buttons\\WHITE8X8"
-- Preview controls are actions, not a competing colour system. Keep the
-- flower mark as Resonance's identity while its surrounding UI stays shared.
local PLAY_PINK = { 0.94, 0.50, 0.74, 1 }
-- EllesmereUI is optional. The fallback below keeps Resonance readable on
-- its own, while this registry lets a late-loading facade skin every object
-- already built and every object created lazily afterwards.
local EUI = {
fonts = {}, buttons = {}, closeButtons = {}, editBoxes = {}, checkboxes = {},
panels = {}, shells = {}, scrolls = {}, accentTexts = {}, accentTextures = {},
}
local function EUIInvoke(method, frame, option)
local skin = EUI.skin
local fn = skin and skin[method]
if not fn or not frame then return false end
if option ~= nil then return pcall(fn, frame, option) end
return pcall(fn, frame)
end
local function ClearFallbackShell(frame)
if not frame or not frame.SetBackdropColor then return end
frame:SetBackdropColor(0, 0, 0, 0)
frame:SetBackdropBorderColor(0, 0, 0, 0)
end
local function EUITrack(bucket, frame, option)
if not frame then return frame end
EUI[bucket][#EUI[bucket] + 1] = { frame = frame, option = option }
local method = ({
fonts = "Font", buttons = "Button", closeButtons = "CloseButton",
editBoxes = "EditBox", checkboxes = "Checkbox", panels = "Panel",
shells = "Shell",
})[bucket]
if EUI.skin then frame._resonanceEUI = true end
if bucket == "closeButtons" and EUI.skin and frame._resonanceCloseStrokes then
for _, stroke in ipairs(frame._resonanceCloseStrokes) do stroke:SetAlpha(0) end
end
local applied = method and EUIInvoke(method, frame, option)
if bucket == "shells" and applied then ClearFallbackShell(frame) end
if bucket == "checkboxes" and EUI.skin and frame.SetChecked then
frame:SetChecked(frame.checked)
end
return frame
end
local function EUIStateButtonLabel(button)
if not EUI.skin then return end
if EUI.skin.StateButtonLabel then
pcall(EUI.skin.StateButtonLabel, button)
elseif EUI.skin.WhiteButtonLabel then
pcall(EUI.skin.WhiteButtonLabel, button)
end
end
local function EUITrackAccentText(text)
if text then EUI.accentTexts[#EUI.accentTexts + 1] = text end
return text
end
local function EUITrackAccentTexture(texture)
if texture then EUI.accentTextures[#EUI.accentTextures + 1] = texture end
return texture
end
local function AddAccentBorder(frame)
local border = CreateFrame("Frame", nil, frame)
border:SetAllPoints(frame)
border:SetFrameLevel(frame:GetFrameLevel() + 4)
border:EnableMouse(false)
local top = border:CreateTexture(nil, "OVERLAY")
top:SetPoint("TOPLEFT")
top:SetPoint("TOPRIGHT")
top:SetHeight(1)
local bottom = border:CreateTexture(nil, "OVERLAY")
bottom:SetPoint("BOTTOMLEFT")
bottom:SetPoint("BOTTOMRIGHT")
bottom:SetHeight(1)
local left = border:CreateTexture(nil, "OVERLAY")
left:SetPoint("TOPLEFT", 0, -1)
left:SetPoint("BOTTOMLEFT", 0, 1)
left:SetWidth(1)
local right = border:CreateTexture(nil, "OVERLAY")
right:SetPoint("TOPRIGHT", 0, -1)
right:SetPoint("BOTTOMRIGHT", 0, 1)
right:SetWidth(1)
for _, edge in ipairs({ top, bottom, left, right }) do
edge:SetColorTexture(unpack(COLORS.accent))
EUITrackAccentTexture(edge)
end
return border
end
local function ColorTag(color)
return string.format("|cff%02x%02x%02x", math.floor(color[1] * 255 + 0.5),
math.floor(color[2] * 255 + 0.5), math.floor(color[3] * 255 + 0.5))
end
local function EUIAccentTag()
return ColorTag(COLORS.accent)
end
local function UpdateEUIAccent()
local skin = EUI.skin
if not skin or not skin.GetAccentColor then return end
local ok, r, g, b = pcall(skin.GetAccentColor)
if not ok or type(r) ~= "number" or type(g) ~= "number" or type(b) ~= "number" then return end
for _, color in ipairs({ COLORS.accent, COLORS.blue, COLORS.teal }) do
color[1], color[2], color[3] = r, g, b
end
for _, text in ipairs(EUI.accentTexts) do
if text and text.SetTextColor then text:SetTextColor(r, g, b, 1) end
end
for _, texture in ipairs(EUI.accentTextures) do
if texture and texture.SetColorTexture then texture:SetColorTexture(r, g, b, 1) end
end
for _, scroll in ipairs(EUI.scrolls) do
local thumb = scroll and scroll._resonanceScrollBar and scroll._resonanceScrollBar._resonanceThumb
if thumb then
thumb:SetBackdropColor(r, g, b, 1)
thumb:SetBackdropBorderColor(r, g, b, 1)
end
end
for _, entry in ipairs(EUI.checkboxes) do
local check = entry.frame
if check and check.markA and check.markB then
check.markA:SetVertexColor(r, g, b, 1)
check.markB:SetVertexColor(r, g, b, 1)
check:SetChecked(check.checked)
end
end
if ns.RefreshOptions then ns:RefreshOptions() end
if ns.SoundPicker and ns.SoundPicker:IsShown() and ns.SoundPicker.RefreshSounds then ns.SoundPicker:RefreshSounds() end
if ns.SoundSetWindow and ns.SoundSetWindow:IsShown() and ns.SoundSetWindow.Refresh then ns.SoundSetWindow:Refresh() end
if ns.HelpWindow and ns.HelpWindow:IsShown() and ns.HelpWindow.ShowTopic then
ns.HelpWindow:ShowTopic(ns.HelpWindow.topic or 1)
end
end
local function EUITrackScroll(scroll)
if scroll then EUI.scrolls[#EUI.scrolls + 1] = scroll end
return false
end
local function ApplyEUITheme(skin)
EUI.skin = skin or EUI.skin
skin = EUI.skin
if not skin then return end
for _, entry in ipairs(EUI.shells) do
entry.frame._resonanceEUI = true
if EUIInvoke("Shell", entry.frame, entry.option) then ClearFallbackShell(entry.frame) end
end
for _, entry in ipairs(EUI.panels) do
entry.frame._resonanceEUI = true
EUIInvoke("Panel", entry.frame, entry.option)
end
for _, entry in ipairs(EUI.fonts) do EUIInvoke("Font", entry.frame, entry.option) end
for _, entry in ipairs(EUI.buttons) do
entry.frame._resonanceEUI = true
EUIInvoke("Button", entry.frame, entry.option)
EUIStateButtonLabel(entry.frame)
end
for _, entry in ipairs(EUI.closeButtons) do
entry.frame._resonanceEUI = true
if entry.frame._resonanceCloseStrokes then
for _, stroke in ipairs(entry.frame._resonanceCloseStrokes) do stroke:SetAlpha(0) end
end
EUIInvoke("CloseButton", entry.frame, entry.option)
end
for _, entry in ipairs(EUI.editBoxes) do
entry.frame._resonanceEUI = true
EUIInvoke("EditBox", entry.frame, entry.option)
end
for _, entry in ipairs(EUI.checkboxes) do
entry.frame._resonanceEUI = true
EUIInvoke("Checkbox", entry.frame, entry.option)
if entry.frame.SetChecked then entry.frame:SetChecked(entry.frame.checked) end
end
UpdateEUIAccent()
if skin.OnLooksChanged and not EUI.looksHooked then
EUI.looksHooked = true
pcall(skin.OnLooksChanged, UpdateEUIAccent)
end
end
-- The catalog editor is deliberately tucked away for the 1.14 release.
-- Keep both the SavedVariables and implementation intact: switching this
-- flag back on restores a tester's existing draft instead of losing it.
local DEBUG_SOUND_TOOLS_VISIBLE = false
local function IsSoundSortingDebugActive()
return DEBUG_SOUND_TOOLS_VISIBLE and ns.DB and ns.DB.soundSortDebug == true
end
local WhiteButtonFont = CreateFont("ResonanceWhiteButtonFont")
WhiteButtonFont:CopyFontObject(GameFontNormal)
WhiteButtonFont:SetTextColor(1, 1, 1, 1)
local MutedButtonFont = CreateFont("ResonanceMutedButtonFont")
MutedButtonFont:CopyFontObject(GameFontNormal)
MutedButtonFont:SetTextColor(0.59, 0.64, 0.71, 1)
local function ApplyBackdrop(frame, color, border)
-- A live EUI facade owns the visual surface after it has run. Refreshing
-- a selected row must not paint the fallback colour system back over it.
if EUI.skin and frame and frame._resonanceEUI then return end
frame:SetBackdrop({
bgFile = WHITE,
edgeFile = WHITE,
edgeSize = 1,
})
frame:SetBackdropColor(unpack(color))
frame:SetBackdropBorderColor(unpack(border or COLORS.border))
end
-- Borders have one owner: the frame's Backdrop. Earlier decorative strips
-- overlapped the ScrollFrame and left visually open corners at large scales.
-- Keep this shared hook intentionally quiet so existing callers retain a
-- single, clean perimeter without stacked artwork.
local function AddArcaneTrim(frame, style)
if not frame or frame._resonanceArcaneTrim then return end
frame._resonanceArcaneTrim = true
end
-- Replace UIPanelScrollFrameTemplate's large arrows and Blizzard artwork with
-- a compact Resonance track. The wider transparent hit target keeps the slim
-- visual easy to grab, while wheel, track-click and thumb dragging all remain
-- available.
local function SkinScrollFrame(scroll)
if not scroll or scroll._resonanceScrollBar then return end
if not scroll._resonanceEUITracked then
scroll._resonanceEUITracked = true
EUITrackScroll(scroll)
end
local blizzardBar = scroll.ScrollBar or scroll.scrollBar
if not blizzardBar and scroll.GetName and scroll:GetName() then
blizzardBar = _G[scroll:GetName() .. "ScrollBar"]
end
if blizzardBar then
scroll._resonanceBlizzardBar = blizzardBar
blizzardBar:SetAlpha(0)
blizzardBar:EnableMouse(false)
blizzardBar:Hide()
end
scroll:EnableMouseWheel(true)
if scroll.SetClipsChildren then scroll:SetClipsChildren(true) end
local track = CreateFrame("Button", nil, scroll:GetParent(), "BackdropTemplate")
track:SetPoint("TOPLEFT", scroll, "TOPRIGHT", 4, 0)
track:SetPoint("BOTTOMLEFT", scroll, "BOTTOMRIGHT", 4, 0)
track:SetWidth(8)
track:SetFrameLevel(scroll:GetFrameLevel() + 8)
track:EnableMouse(true)
ApplyBackdrop(track, COLORS.window, { 0, 0, 0, 0 })
local rail = track:CreateTexture(nil, "BACKGROUND")
rail:SetTexture("Interface\\Buttons\\WHITE8X8")
rail:SetVertexColor(unpack(COLORS.faint))
rail:SetPoint("TOP", 0, -3)
rail:SetPoint("BOTTOM", 0, 3)
rail:SetWidth(2)
local thumb = CreateFrame("Button", nil, track, "BackdropTemplate")
thumb:SetWidth(6)
thumb:SetHeight(28)
thumb:SetPoint("TOP", track, "TOP", 0, -2)
thumb:SetFrameLevel(track:GetFrameLevel() + 1)
thumb:EnableMouse(true)
thumb:RegisterForDrag("LeftButton")
ApplyBackdrop(thumb, COLORS.teal, COLORS.teal)
local dragging = false
local dragStartY, dragStartScroll
local function GetRange()
local range = scroll.GetVerticalScrollRange and scroll:GetVerticalScrollRange() or 0
return math.max(0, tonumber(range) or 0)
end
local function UpdateThumb()
local maxScroll = GetRange()
local trackHeight = math.max(1, track:GetHeight() - 4)
if maxScroll <= 0 or trackHeight <= 1 then
track:Hide()
return
end
track:Show()
local visibleHeight = math.max(1, scroll:GetHeight())
local thumbHeight = math.max(28, trackHeight * visibleHeight / (visibleHeight + maxScroll))
thumbHeight = math.min(trackHeight, thumbHeight)
thumb:SetHeight(thumbHeight)
local travel = math.max(0, trackHeight - thumbHeight)
local ratio = math.max(0, math.min(1, (tonumber(scroll:GetVerticalScroll()) or 0) / maxScroll))
thumb:ClearAllPoints()
thumb:SetPoint("TOP", track, "TOP", 0, -2 - ratio * travel)
end
local function StopDrag()
if not dragging then return end
dragging = false
thumb:SetScript("OnUpdate", nil)
thumb:SetBackdropColor(unpack(COLORS.teal))
thumb:SetBackdropBorderColor(unpack(COLORS.teal))
end
local function BeginDrag()
local _, cursorY = GetCursorPosition()
local scale = math.max(0.001, scroll:GetEffectiveScale())
dragging = true
dragStartY = cursorY / scale
dragStartScroll = tonumber(scroll:GetVerticalScroll()) or 0
thumb:SetBackdropColor(unpack(COLORS.teal))
thumb:SetBackdropBorderColor(unpack(COLORS.teal))
thumb:SetScript("OnUpdate", function()
if not IsMouseButtonDown("LeftButton") then
StopDrag()
return
end
local maxScroll = GetRange()
local travel = math.max(1, track:GetHeight() - 4 - thumb:GetHeight())
local _, currentY = GetCursorPosition()
local delta = dragStartY - currentY / math.max(0.001, scroll:GetEffectiveScale())
scroll:SetVerticalScroll(math.max(0, math.min(maxScroll, dragStartScroll + delta / travel * maxScroll)))
UpdateThumb()
end)
end
thumb:SetScript("OnEnter", function(self)
if not dragging then
self:SetBackdropColor(unpack(COLORS.tealDim))
self:SetBackdropBorderColor(unpack(COLORS.teal))
end
end)
thumb:SetScript("OnLeave", function(self)
if not dragging then
self:SetBackdropColor(unpack(COLORS.teal))
self:SetBackdropBorderColor(unpack(COLORS.teal))
end
end)
thumb:SetScript("OnDragStart", BeginDrag)
thumb:SetScript("OnDragStop", StopDrag)
thumb:SetScript("OnMouseDown", function(_, button) if button == "LeftButton" then BeginDrag() end end)
thumb:SetScript("OnMouseUp", StopDrag)
track:SetScript("OnMouseDown", function(_, button)
if button ~= "LeftButton" then return end
local maxScroll = GetRange()
local scale = math.max(0.001, track:GetEffectiveScale())
local _, cursorY = GetCursorPosition()
local offset = (track:GetTop() or 0) - cursorY / scale - thumb:GetHeight() * 0.5
local travel = math.max(1, track:GetHeight() - 4 - thumb:GetHeight())
scroll:SetVerticalScroll(math.max(0, math.min(maxScroll, offset / travel * maxScroll)))
UpdateThumb()
BeginDrag()
end)
track:SetScript("OnMouseUp", StopDrag)
scroll:SetScript("OnMouseWheel", function(self, delta)
local maxScroll = GetRange()
local nextScroll = (tonumber(self:GetVerticalScroll()) or 0) - delta * 54
self:SetVerticalScroll(math.max(0, math.min(maxScroll, nextScroll)))
UpdateThumb()
end)
scroll:HookScript("OnVerticalScroll", UpdateThumb)
scroll:HookScript("OnScrollRangeChanged", UpdateThumb)
scroll:HookScript("OnSizeChanged", UpdateThumb)
scroll:HookScript("OnShow", function() C_Timer.After(0, UpdateThumb) end)
scroll._resonanceScrollBar = track
track._resonanceThumb = thumb
scroll._resonanceUpdateScrollBar = UpdateThumb
C_Timer.After(0, UpdateThumb)
end
local function CreateText(parent, template, text)
local label = parent:CreateFontString(nil, "ARTWORK", template)
label:SetText(text)
-- BindCards uses bright text for ordinary labels. Individual semantic
-- headings set their teal or lavender colour explicitly at the callsite.
label:SetTextColor(unpack(COLORS.text))
EUITrack("fonts", label)
return label
end
local function CreateDrawnStar(parent)
local star = CreateFrame("Frame", nil, parent)
star:SetSize(12, 12)
local points = {}
for index = 1, 10 do
local angle = math.rad(-90 + (index - 1) * 36)
local radius = index % 2 == 1 and 5 or 2.25
points[index] = { math.cos(angle) * radius, math.sin(angle) * radius }
end
for index = 1, 10 do
local nextIndex = index == 10 and 1 or index + 1
local line = star:CreateLine(nil, "ARTWORK")
line:SetThickness(1.25)
line:SetColorTexture(unpack(COLORS.accent))
EUITrackAccentTexture(line)
line:SetStartPoint("CENTER", star, points[index][1], points[index][2])
line:SetEndPoint("CENTER", star, points[nextIndex][1], points[nextIndex][2])
end
return star
end
local function RegisterOptionWidget(widget)
widget._resSpecID = ns._BuildingSpecID
ns.OptionWidgets[#ns.OptionWidgets + 1] = widget
return widget
end
local function ParseSearchExpression(query)
query = string.lower(query or "")
local tokens, index, length = {}, 1, #query
while index <= length do
while index <= length and string.match(string.sub(query, index, index), "%s") do index = index + 1 end
if index > length then break end
if string.sub(query, index, index) == '"' then
local closing = string.find(query, '"', index + 1, true)
local value
if closing then
value = string.sub(query, index + 1, closing - 1)
index = closing + 1
else
value = string.sub(query, index + 1)
index = length + 1
end
if value ~= "" then tokens[#tokens + 1] = { value = value, quoted = true } end
else
local ending = string.find(query, "%s", index)
local value = ending and string.sub(query, index, ending - 1) or string.sub(query, index)
index = ending and ending + 1 or length + 1
if value ~= "" then tokens[#tokens + 1] = { value = value } end
end
end
local groups, group = {}, {}
for _, token in ipairs(tokens) do
local value = token.value
if not token.quoted and (value == "or" or value == "|" or value == "||") then
if #group > 0 then groups[#groups + 1] = group end
group = {}
elseif token.quoted or (value ~= "and" and value ~= "&" and value ~= "&&") then
group[#group + 1] = value
end
end
if #group > 0 then groups[#groups + 1] = group end
return groups
end
local function MatchesSearchExpression(haystack, groups)
for _, group in ipairs(groups) do
local matches = true
for _, term in ipairs(group) do
if not string.find(haystack, term, 1, true) then
matches = false
break
end
end
if matches then return true end
end
return false
end
local function GetCategoryDisplayName(categoryID)
for _, category in ipairs(ns.SoundCategories or {}) do
if category.id == categoryID then return category.label end
end
return categoryID or "Uncategorized"
end
local function AddTooltip(frame, title, body)
frame:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText(title, unpack(COLORS.accent))
GameTooltip:AddLine(body, COLORS.accent[1], COLORS.accent[2], COLORS.accent[3], true)
GameTooltip:Show()
end)
frame:SetScript("OnLeave", GameTooltip_Hide)
end
-- Shared with PriorityFader/Frame Gambit: a compact, texture-free close
-- control that keeps our addon windows visually consistent.
local function CreateCloseButton(parent, callback)
local button = CreateFrame("Button", nil, parent, "BackdropTemplate")
button:SetSize(24, 24)
button:SetFrameLevel(parent:GetFrameLevel() + 20)
ApplyBackdrop(button, COLORS.raised, COLORS.border)
local strokes = {}
for index, angle in ipairs({ math.pi / 4, -math.pi / 4 }) do
local stroke = button:CreateTexture(nil, "ARTWORK")
stroke:SetTexture("Interface\\Buttons\\WHITE8X8")
stroke:SetSize(2, 13)
stroke:SetPoint("CENTER")
stroke:SetRotation(angle)
stroke:SetVertexColor(unpack(COLORS.muted))
strokes[index] = stroke
end
button._resonanceCloseStrokes = strokes
local function Tint(color)
for _, stroke in ipairs(strokes) do
stroke:SetVertexColor(unpack(color))
end
end
button:SetScript("OnEnter", function(self)
if not self._resonanceEUI then
self:SetBackdropColor(unpack(COLORS.tealDim))
self:SetBackdropBorderColor(unpack(COLORS.teal))
Tint(COLORS.teal)
end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText("Close", unpack(COLORS.accent))
GameTooltip:AddLine("Close this window.", COLORS.accent[1], COLORS.accent[2], COLORS.accent[3], true)
GameTooltip:Show()
end)
button:SetScript("OnLeave", function(self)
if not self._resonanceEUI then
self:SetBackdropColor(unpack(COLORS.raised))
self:SetBackdropBorderColor(unpack(COLORS.border))
Tint(COLORS.muted)
end
GameTooltip_Hide()
end)
button:SetScript("OnClick", callback or function() parent:Hide() end)
EUITrack("closeButtons", button)
return button
end
local function StyleButton(button, accent)
local font = WhiteButtonFont
button:SetNormalFontObject(font)
button:SetHighlightFontObject(font)
button:SetDisabledFontObject(MutedButtonFont)
local color = accent and COLORS.blueSoft or COLORS.raised
ApplyBackdrop(button, color, COLORS.border)
if button:GetFontString() then
button:GetFontString():SetTextColor(unpack(COLORS.text))
end
button:SetScript("OnEnter", function(self)
if self._resonanceEUI then return end
self:SetBackdropBorderColor(unpack(COLORS.blue))
self:SetBackdropColor(0.12, 0.14, 0.17, 1)
end)
button:SetScript("OnLeave", function(self)
if self._resonanceEUI then return end
self:SetBackdropColor(unpack(color))
self:SetBackdropBorderColor(unpack(COLORS.border))
end)
button:HookScript("OnDisable", function(self)
if self._resonanceEUI then return end
self:SetAlpha(0.38)
self:SetBackdropColor(unpack(COLORS.cardAlt))
self:SetBackdropBorderColor(unpack(COLORS.faint))
end)
button:HookScript("OnEnable", function(self)
if self._resonanceEUI then return end
self:SetAlpha(1)
self:SetBackdropColor(unpack(color))
self:SetBackdropBorderColor(unpack(COLORS.border))
end)
end
local function CreateModernCheck(parent, size)
local check = CreateFrame("Button", nil, parent, "BackdropTemplate")
size = size or 20
check:SetSize(size, size)
check.checked = false
ApplyBackdrop(check, COLORS.window, COLORS.border)
-- Draw a crisp X from two teal strokes. WoW's bundled fonts do not reliably
-- contain checkmark glyphs and can render them as hollow rectangles.
check.markA = check:CreateTexture(nil, "OVERLAY")
check.markA:SetTexture("Interface\\Buttons\\WHITE8X8")
check.markA:SetVertexColor(unpack(COLORS.teal))
check.markA:SetSize(2, math.max(9, size * 0.58))
check.markA:SetPoint("CENTER", 0, 0)
check.markA:SetRotation(-math.pi / 4)
check.markB = check:CreateTexture(nil, "OVERLAY")
check.markB:SetTexture("Interface\\Buttons\\WHITE8X8")
check.markB:SetVertexColor(unpack(COLORS.teal))
check.markB:SetSize(2, math.max(9, size * 0.58))
check.markB:SetPoint("CENTER", 0, 0)
check.markB:SetRotation(math.pi / 4)
function check:SetChecked(value)
self.checked = value == true
self.markA:SetShown(self.checked)
self.markB:SetShown(self.checked)
if self._resonanceEUI then
-- S.Checkbox may fade pre-existing regions while it installs its
-- box treatment. The Resonance X is the intentionally chosen
-- check glyph, so restore it above the skin and leave EUI's
-- backdrop entirely untouched.
self.markA:SetAlpha(1)
self.markB:SetAlpha(1)
self.markA:SetVertexColor(unpack(COLORS.teal))
self.markB:SetVertexColor(unpack(COLORS.teal))
return
end
self:SetBackdropColor(unpack(self.checked and COLORS.tealDim or COLORS.window))
self:SetBackdropBorderColor(unpack(self.checked and COLORS.teal or COLORS.border))
end
function check:GetChecked() return self.checked end
check:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then self:SetChecked(not self:GetChecked()) end
end)
check:SetChecked(false)
EUITrack("checkboxes", check)
return check
end
local function CreateButton(parent, text, width, callback, accent)
local button = CreateFrame("Button", nil, parent, "BackdropTemplate")
button:SetSize(width or 110, 22)
local label = button:CreateFontString(nil, "ARTWORK")
label:SetPoint("CENTER")
EUITrack("fonts", label)
button:SetFontString(label)
button:SetText(text)
button:SetScript("OnClick", callback)
StyleButton(button, accent)
EUITrack("buttons", button)
EUIStateButtonLabel(button)
return button
end
local function CreateSection(parent, title, subtitle, height)
local frame = CreateFrame("Frame", nil, parent, "BackdropTemplate")
frame:SetHeight(height)
ApplyBackdrop(frame, COLORS.card)
AddArcaneTrim(frame, "section")
EUITrack("panels", frame, { inset = true })
local titleText
if title and title ~= "" then
titleText = CreateText(frame, "GameFontNormalLarge", title)
titleText:SetPoint("TOPLEFT", 14, -11)
titleText:SetTextColor(unpack(COLORS.teal))
EUITrackAccentText(titleText)
end
if subtitle and subtitle ~= "" and titleText then
local subtitleText = CreateText(frame, "GameFontHighlightSmall", subtitle)
subtitleText:SetPoint("TOPLEFT", titleText, "BOTTOMLEFT", 0, -3)
subtitleText:SetPoint("RIGHT", frame, -18, 0)
subtitleText:SetJustifyH("LEFT")
subtitleText:SetTextColor(unpack(COLORS.muted))
end
return frame
end
-- Small UI toolkit shared by the standalone Help Center and tutorial. Keeping
-- these primitives here guarantees every Resonance window uses one visual
-- language without copying styling code between modules.
ns.UI = {
COLORS = COLORS,
ApplyBackdrop = ApplyBackdrop,
SkinScrollFrame = SkinScrollFrame,
ApplyEUITheme = ApplyEUITheme,
SkinPanel = function(frame, options) return EUITrack("panels", frame, options) end,
SkinShell = function(frame, options) return EUITrack("shells", frame, options) end,
SkinEditBox = function(frame) return EUITrack("editBoxes", frame) end,
TrackAccentText = EUITrackAccentText,
TrackAccentTexture = EUITrackAccentTexture,
AccentTag = EUIAccentTag,
CreateText = CreateText,
CreateButton = CreateButton,
CreateCloseButton = CreateCloseButton,
CreateSection = CreateSection,
AddArcaneTrim = AddArcaneTrim,
}
local function CreateCheckRow(parent, label, description, getter, setter)
local row = CreateFrame("Frame", nil, parent)
local hasDescription = description and description ~= ""
row:SetSize(350, hasDescription and 40 or 26)
local check = CreateModernCheck(row, 19)
check:SetPoint("LEFT", 0, 0)
row.label = CreateText(row, "GameFontNormal", label)
row.label:SetPoint("LEFT", check, "RIGHT", 10, hasDescription and 7 or 0)
row.description = CreateText(row, "GameFontHighlightSmall", description or "")
row.description:SetPoint("TOPLEFT", row.label, "BOTTOMLEFT", 0, -2)
row.description:SetPoint("RIGHT", row, "RIGHT", 0, 0)
row.description:SetJustifyH("LEFT")
row.description:SetWordWrap(true)
if row.description.SetMaxLines then row.description:SetMaxLines(2) end
row.description:SetTextColor(unpack(COLORS.muted)); row.description:SetShown(hasDescription)
check.getter = getter
check:SetScript("OnClick", function(self)
setter(self:GetChecked() == true)
end)
AddTooltip(check, label, description or "")
RegisterOptionWidget(check)
return row
end
-- Release controls use a compact horizontal settings band rather than the
-- vertical form rhythm used elsewhere. This keeps their top baselines aligned
-- and avoids scattering one-off positioning rules through BuildGeneral.
local function CreateSettingsBandToggle(parent, label, description, getter, setter)
local row = CreateFrame("Frame", nil, parent)
row:SetSize(300, 42)
local check = CreateModernCheck(row, 19)
check:SetPoint("TOPLEFT", 0, 0)
local title = CreateText(row, "GameFontNormal", label)
title:SetPoint("TOPLEFT", check, "TOPRIGHT", 10, 2)
if description and description ~= "" then
local detail = CreateText(row, "GameFontHighlightSmall", description)
detail:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -2)
detail:SetPoint("RIGHT", row, "RIGHT", 0, 0)
detail:SetJustifyH("LEFT")
detail:SetWordWrap(true)
if detail.SetMaxLines then detail:SetMaxLines(2) end
detail:SetTextColor(unpack(COLORS.muted))
end
check.getter = getter
check:SetScript("OnClick", function(self)
setter(self:GetChecked() == true)
end)
AddTooltip(check, label, description or "")
RegisterOptionWidget(check)
return row
end
local function CreateCycle(parent, label, values, getter, setter, width)
width = width or 230
local frame = CreateFrame("Frame", nil, parent)
frame:SetSize(width, 50)
local title = CreateText(frame, "GameFontNormal", label)
title:SetPoint("TOPLEFT", 0, 0)
local button = CreateButton(frame, "", width, function(self)
local current = getter()
local index = 1
for i, entry in ipairs(values) do
if entry.value == current then index = i break end
end
index = index % #values + 1
setter(values[index].value)
self:SetText(values[index].label .. " " .. EUIAccentTag() .. "›|r")
end)
button:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -5)
button.refresh = function(self)
local current = getter()
for _, entry in ipairs(values) do
if entry.value == current then
self:SetText(entry.label .. " " .. EUIAccentTag() .. "›|r")
return
end
end
end
RegisterOptionWidget(button)
return frame
end
-- The public settings band uses the same behavior as a regular cycle, but
-- presents it as one compact action instead of a label-and-field stack.
local function CreateCompactCycle(parent, values, getter, setter, width)
local button = CreateButton(parent, "", width, function(self)
local current = getter()
local index = 1
for i, entry in ipairs(values) do
if entry.value == current then index = i break end
end
index = index % #values + 1
setter(values[index].value)
self:refresh()
end)
button.refresh = function(self)
local current = getter()
for _, entry in ipairs(values) do
if entry.value == current then
self:SetText(entry.label .. " " .. EUIAccentTag() .. "›|r")
return
end
end
end
RegisterOptionWidget(button)
return button
end
local function CreateEditBox(parent, width)
local box = CreateFrame("EditBox", nil, parent, "BackdropTemplate")
box:SetSize(width or 48, 20)
box:SetAutoFocus(false)
box:SetNumeric(true)
box:SetMaxLetters(4)
box:SetFontObject("GameFontHighlightSmall")
box:SetJustifyH("LEFT")
box:SetTextInsets(7, 5, 0, 0)
ApplyBackdrop(box, COLORS.window, COLORS.border)
box:SetTextColor(unpack(COLORS.text))
box:HookScript("OnEditFocusGained", function(self)
self:SetBackdropBorderColor(unpack(COLORS.teal))
self:SetBackdropColor(unpack(COLORS.panel))
end)
box:HookScript("OnEditFocusLost", function(self)
self:SetBackdropBorderColor(unpack(COLORS.border))
self:SetBackdropColor(unpack(COLORS.window))
end)
box:SetScript("OnTextChanged", function(self, userInput)
if not userInput or self._normalizingNumericText then return end
local raw = self:GetText() or ""
local normalized = raw:gsub("%D", ""):sub(1, 4)
if normalized ~= raw then
self._normalizingNumericText = true
self:SetText(normalized)
self:SetCursorPosition(#normalized)
self._normalizingNumericText = nil
end
end)
box:SetScript("OnEscapePressed", function(self) self:ClearFocus() end)
box:SetScript("OnEnterPressed", function(self) self:ClearFocus() end)
EUITrack("editBoxes", box)
return box
end
local function ShortSoundLabel(fileID, preservedLabel)
return ns:GetSoundLabel(fileID, preservedLabel)
end
function ns:CreateSoundPicker()
if self.SoundPicker then return end
local picker = CreateFrame("Frame", "ResonanceSoundPicker", UIParent, "BackdropTemplate")
picker:SetSize(760, 580)
picker:SetPoint("CENTER")
picker:SetFrameStrata("TOOLTIP")
picker:SetFrameLevel(900)
picker:SetToplevel(true)
picker:SetMovable(true)
picker:SetClampedToScreen(true)
picker:EnableMouse(true)
ApplyBackdrop(picker, COLORS.window, COLORS.border)
AddArcaneTrim(picker, "window")
EUITrack("shells", picker, { bottomBar = 50 })
self.SoundPicker = picker
picker.selectedIDs = {}
picker:SetScript("OnHide", function()
picker:StopMovingOrSizing()
picker.dragging = false
picker.dropCategory = nil
if picker.dragBadge then picker.dragBadge:SetScript("OnUpdate", nil); picker.dragBadge:Hide() end
ns:StopPreviewSound()
if ns.TutorialSignal then ns:TutorialSignal("sound-picker-closed") end
end)
local dragBadge = CreateFrame("Frame", nil, UIParent, "BackdropTemplate")
dragBadge:SetSize(190, 34)
dragBadge:SetFrameStrata("TOOLTIP")
dragBadge:SetFrameLevel(1100)
dragBadge:EnableMouse(false)
ApplyBackdrop(dragBadge, COLORS.tealDim, COLORS.teal)
EUITrack("panels", dragBadge, { inset = true })
dragBadge.label = CreateText(dragBadge, "GameFontNormalSmall", "")
dragBadge.label:SetPoint("LEFT", 10, 0)
dragBadge.label:SetPoint("RIGHT", -10, 0)
dragBadge.label:SetJustifyH("LEFT")
dragBadge._ticker = function(self)
local scale = UIParent:GetEffectiveScale()
local x, y = GetCursorPosition()
self:ClearAllPoints()
self:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", x / scale + 14, y / scale + 12)
end
dragBadge:Hide()
picker.dragBadge = dragBadge
local close = CreateCloseButton(picker)
close:SetPoint("TOPRIGHT", -4, -4)
local title = CreateText(picker, "GameFontNormalHuge", "Sound picker")
title:SetPoint("TOPLEFT", 18, -14)
title:SetTextColor(unpack(COLORS.text))
local help = CreateText(picker, "GameFontHighlightSmall", "Browse a category or search. Click a sound to preview it, then choose Okay to apply it.")
help:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -7)
help:SetPoint("RIGHT", picker, "RIGHT", -20, 0)
help:SetJustifyH("LEFT")
help:SetWordWrap(false)
help:SetTextColor(unpack(COLORS.muted))
picker.help = help
local drag = CreateFrame("Frame", nil, picker)
drag:SetPoint("TOPLEFT"); drag:SetPoint("TOPRIGHT"); drag:SetHeight(54)
drag:EnableMouse(true); drag:RegisterForDrag("LeftButton")
drag:SetScript("OnDragStart", function() picker:StartMoving() end)
drag:SetScript("OnDragStop", function() picker:StopMovingOrSizing() end)
local categoryPane = CreateFrame("Frame", nil, picker, "BackdropTemplate")
categoryPane:SetPoint("TOPLEFT", 14, -66); categoryPane:SetPoint("BOTTOMLEFT", 14, 54); categoryPane:SetWidth(148)
ApplyBackdrop(categoryPane, COLORS.cardAlt)
AddArcaneTrim(categoryPane, "panel")
EUITrack("panels", categoryPane, { inset = true })
picker.categoryPane = categoryPane
local categoryScroll = CreateFrame("ScrollFrame", nil, categoryPane, "UIPanelScrollFrameTemplate")
categoryScroll:SetPoint("TOPLEFT", 5, -5)
categoryScroll:SetPoint("BOTTOMRIGHT", -24, 5)
local categoryContent = CreateFrame("Frame", nil, categoryScroll)
categoryContent:SetSize(114, math.max(1, #self.SoundCategories * 25 + 8))
categoryScroll:SetScrollChild(categoryContent)
SkinScrollFrame(categoryScroll)
picker.categoryScroll = categoryScroll
picker.categoryButtons = {}
for index, category in ipairs(self.SoundCategories) do
local button = CreateButton(categoryContent, category.label, 112, function()
picker.category = category.id
if picker.soundScroll then picker.soundScroll:SetVerticalScroll(0) end
if picker.search and picker.search:GetText() ~= "" then
picker.search:SetText("")
picker.search:ClearFocus()
else
picker:RefreshSounds()
end
end)
button:SetHeight(22)
button:SetPoint("TOPLEFT", 1, -2 - (index - 1) * 25)
button.categoryID = category.id
button.categoryColor = category.color
button:HookScript("OnEnter", function(self)
if picker.dragging and self.categoryID ~= "favorites" then
picker.dropCategory = self.categoryID
if picker.RefreshCategoryButtons then picker:RefreshCategoryButtons() end
end
end)
button:HookScript("OnLeave", function(self)
if picker.dragging and picker.dropCategory == self.categoryID then
picker.dropCategory = nil
if picker.RefreshCategoryButtons then picker:RefreshCategoryButtons() end
end
end)
button:SetScript("OnReceiveDrag", function(self)
if picker.dragging and self.categoryID ~= "favorites" then
picker:FinishSoundDrag(self.categoryID)
end
end)
picker.categoryButtons[#picker.categoryButtons + 1] = button
end
function picker:RefreshCategoryButtons()
for _, button in ipairs(self.categoryButtons) do
local isDropTarget = self.dragging and self.dropCategory == button.categoryID
local selected = isDropTarget or button.categoryID == self.category
if button._resonanceEUI then
-- EUI owns the flat button plate. Preserve selection in the
-- label rather than repainting a fallback background over it.
local label = button:GetFontString()
if label then label:SetTextColor(unpack(selected and COLORS.teal or COLORS.text)) end
elseif selected then
button:SetBackdropColor(unpack(COLORS.tealDim))
button:SetBackdropBorderColor(unpack(COLORS.teal))
else
button:SetBackdropColor(unpack(COLORS.cardAlt))
button:SetBackdropBorderColor(unpack(COLORS.border))
end
end
end
local search = CreateFrame("EditBox", nil, picker, "BackdropTemplate")
search:SetPoint("TOPLEFT", categoryPane, "TOPRIGHT", 10, 0)
search:SetPoint("RIGHT", picker, "RIGHT", -28, 0)
search:SetHeight(24)
search:SetAutoFocus(false)
search:SetFontObject("GameFontHighlightSmall")
search:SetTextInsets(9, 9, 0, 0)
ApplyBackdrop(search, COLORS.cardAlt, COLORS.border)
EUITrack("editBoxes", search)