-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.lua
More file actions
1849 lines (1614 loc) · 70.4 KB
/
GUI.lua
File metadata and controls
1849 lines (1614 loc) · 70.4 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
-- NSRTEnhancer / GUI
-- Custom dark-themed tabbed config window. Everything (frame chrome, toggles,
-- sliders, dropdowns, color swatches, buttons, section cards) is built from
-- scratch so we can match a modern flat UI language instead of inheriting
-- the dated Blizzard templates.
local ADDON_NAME, NSE = ...
local M = {}
NSE.GUI = M
-- ---------------------------------------------------------------------------
-- Palette
-- ---------------------------------------------------------------------------
-- LibSharedMedia: NSRT ships LSM-3.0; we use it to populate the font picker.
local LSM = LibStub and LibStub:GetLibrary("LibSharedMedia-3.0", true)
local function BuildFontOptions()
local opts = {}
if LSM then
local list = LSM:List("font")
for _, name in ipairs(list) do
local path = LSM:Fetch("font", name)
table.insert(opts, { text = name, value = path, preview = path })
end
end
-- Fallbacks / always-available entries
if #opts == 0 then
opts = {
{ text = "Friz Quadrata", value = "Fonts\\FRIZQT__.TTF", preview = "Fonts\\FRIZQT__.TTF" },
{ text = "Arial Narrow", value = "Fonts\\ARIALN.TTF", preview = "Fonts\\ARIALN.TTF" },
{ text = "Morpheus", value = "Fonts\\MORPHEUS.TTF", preview = "Fonts\\MORPHEUS.TTF" },
{ text = "Skurri", value = "Fonts\\SKURRI.TTF", preview = "Fonts\\SKURRI.TTF" },
}
end
return opts
end
-- Given a font path, return a friendly name (LSM name, or the filename).
local function FontPathToName(path)
if not path then return "Default" end
if LSM then
for _, name in ipairs(LSM:List("font")) do
if LSM:Fetch("font", name) == path then return name end
end
end
return path:match("[^\\/]+$") or path
end
local C = {
bg = {0.07, 0.08, 0.13, 0.98},
panel = {0.11, 0.12, 0.19, 1},
panelHover = {0.14, 0.16, 0.24, 1},
divider = {0.20, 0.22, 0.30, 0.7},
borderSubtle = {0.22, 0.24, 0.32, 1},
accent = {0.40, 0.85, 0.92, 1}, -- cyan
accentDim = {0.25, 0.55, 0.65, 1},
title = {1.00, 0.40, 0.65, 1}, -- magenta
toggleOn = {0.30, 0.80, 0.65, 1}, -- teal
toggleOff = {0.32, 0.32, 0.40, 1},
thumb = {0.98, 0.98, 1.00, 1},
textPrim = {0.94, 0.94, 0.98, 1},
textSec = {0.60, 0.62, 0.70, 1},
textMuted = {0.45, 0.47, 0.55, 1},
button = {0.15, 0.17, 0.24, 1},
buttonHover = {0.22, 0.26, 0.36, 1},
}
local function c(color, a)
return color[1], color[2], color[3], a or color[4] or 1
end
-- ---------------------------------------------------------------------------
-- Typography
-- ---------------------------------------------------------------------------
-- Poppins family, served via SharedMedia_MyMedia (direct file paths; if the
-- media addon isn't installed WoW silently falls back to a default font).
-- Black for headers, Regular for body. Color-coding between headers and
-- body is handled by the palette above (title/section use accent colors,
-- body uses textPrim/textSec).
local FONT_HEADER = "Interface\\AddOns\\NSRTEnhancer\\Media\\Fonts\\Poppins-Black.ttf"
local FONT_BODY = "Interface\\AddOns\\NSRTEnhancer\\Media\\Fonts\\Poppins-Regular.ttf"
-- ---------------------------------------------------------------------------
-- Scroll frame styling
-- ---------------------------------------------------------------------------
-- Replace the default UIPanelScrollFrameTemplate's beige/grey Blizzard
-- chrome with a thin dark track + accent-colored thumb so our scroll frames
-- visually match the rest of the GUI instead of standing out.
local function StyleScrollFrame(scroll)
local sb = scroll.ScrollBar
if not sb then return end
-- The thumb is also one of sb's regions; we must NOT null it or we'll
-- zero its vertex alpha and it becomes invisible no matter what
-- SetColorTexture we apply afterwards.
local thumb = sb:GetThumbTexture()
for _, region in ipairs({ sb:GetRegions() }) do
if region ~= thumb and region.GetObjectType and region:GetObjectType() == "Texture" then
region:SetTexture(nil)
region:SetVertexColor(1, 1, 1, 0)
end
end
-- Hide up/down arrow buttons if they exist on this template.
for _, btnName in ipairs({ "ScrollUpButton", "ScrollDownButton", "Back", "Forward" }) do
local btn = sb[btnName]
if btn then
btn:SetAlpha(0)
btn:EnableMouse(false)
btn:SetSize(0.001, 0.001) -- effectively collapsed
end
end
-- Narrow bar + dark track drawn as our own texture.
sb:SetWidth(8)
if not sb._nseTrack then
sb._nseTrack = sb:CreateTexture(nil, "BACKGROUND")
sb._nseTrack:SetPoint("TOP", 0, 0)
sb._nseTrack:SetPoint("BOTTOM", 0, 0)
sb._nseTrack:SetWidth(4)
sb._nseTrack:SetColorTexture(C.panel[1], C.panel[2], C.panel[3], 0.9)
end
-- Accent-colored thumb. Reset vertex color in case something already
-- wiped it; let Blizzard auto-size based on scroll content.
if thumb then
thumb:SetColorTexture(C.accent[1], C.accent[2], C.accent[3], 0.85)
thumb:SetVertexColor(1, 1, 1, 1)
thumb:SetWidth(6)
end
end
-- ---------------------------------------------------------------------------
-- Primitive helpers
-- ---------------------------------------------------------------------------
local function SetBG(frame, color, layer)
if not frame._bg then
frame._bg = frame:CreateTexture(nil, layer or "BACKGROUND")
frame._bg:SetAllPoints()
end
frame._bg:SetColorTexture(c(color))
end
-- Four thin-edge fake border (WoW doesn't give us borders on plain frames).
local function SetBorder(frame, color, size)
size = size or 1
color = color or C.borderSubtle
if not frame._borders then
frame._borders = {}
for _, side in ipairs({"TOP", "BOTTOM", "LEFT", "RIGHT"}) do
local t = frame:CreateTexture(nil, "BORDER")
if side == "TOP" then
t:SetPoint("TOPLEFT"); t:SetPoint("TOPRIGHT"); t:SetHeight(size)
elseif side == "BOTTOM" then
t:SetPoint("BOTTOMLEFT"); t:SetPoint("BOTTOMRIGHT"); t:SetHeight(size)
elseif side == "LEFT" then
t:SetPoint("TOPLEFT"); t:SetPoint("BOTTOMLEFT"); t:SetWidth(size)
elseif side == "RIGHT" then
t:SetPoint("TOPRIGHT"); t:SetPoint("BOTTOMRIGHT"); t:SetWidth(size)
end
frame._borders[side] = t
end
end
for _, t in pairs(frame._borders) do
t:SetColorTexture(c(color))
end
end
local function MakeLabel(parent, text, style)
local fs = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
fs:SetText(text)
if style == "title" then
fs:SetFont(FONT_HEADER, 20, "")
fs:SetTextColor(c(C.title))
elseif style == "version" then
fs:SetFont(FONT_BODY, 11, "")
fs:SetTextColor(c(C.textMuted))
elseif style == "section" then
fs:SetFont(FONT_HEADER, 12, "") -- Black weight for section headers
fs:SetTextColor(c(C.accent))
elseif style == "secondary" then
fs:SetFont(FONT_BODY, 11, "")
fs:SetTextColor(c(C.textSec))
elseif style == "primary" then
fs:SetFont(FONT_BODY, 12, "")
fs:SetTextColor(c(C.textPrim))
else
fs:SetFont(FONT_BODY, 12, "")
fs:SetTextColor(c(C.textPrim))
end
return fs
end
-- ---------------------------------------------------------------------------
-- Toggle switch (pill + sliding thumb)
-- ---------------------------------------------------------------------------
local function CreateToggle(parent, getter, setter, onChange)
local btn = CreateFrame("Button", nil, parent)
btn:SetSize(42, 20)
btn.track = btn:CreateTexture(nil, "BACKGROUND")
btn.track:SetAllPoints()
-- Subtle inner shadow/edge for depth
btn.edge = btn:CreateTexture(nil, "BORDER")
btn.edge:SetPoint("TOPLEFT", -1, 1)
btn.edge:SetPoint("BOTTOMRIGHT", 1, -1)
btn.edge:SetColorTexture(0, 0, 0, 0.35)
btn.thumb = btn:CreateTexture(nil, "ARTWORK")
btn.thumb:SetSize(16, 16)
btn.thumb:SetColorTexture(c(C.thumb))
btn.thumbShadow = btn:CreateTexture(nil, "ARTWORK", nil, -1)
btn.thumbShadow:SetPoint("TOPLEFT", btn.thumb, "TOPLEFT", -1, -1)
btn.thumbShadow:SetPoint("BOTTOMRIGHT", btn.thumb, "BOTTOMRIGHT", 1, 1)
btn.thumbShadow:SetColorTexture(0, 0, 0, 0.45)
function btn:Refresh()
local on = getter() and true or false
if on then
btn.track:SetColorTexture(c(C.toggleOn))
btn.thumb:ClearAllPoints()
btn.thumb:SetPoint("RIGHT", btn, "RIGHT", -2, 0)
else
btn.track:SetColorTexture(c(C.toggleOff))
btn.thumb:ClearAllPoints()
btn.thumb:SetPoint("LEFT", btn, "LEFT", 2, 0)
end
end
btn:Refresh()
btn:SetScript("OnClick", function()
setter(not getter())
btn:Refresh()
if onChange then onChange() end
end)
return btn
end
-- ---------------------------------------------------------------------------
-- Slider (dark track, cyan thumb)
-- ---------------------------------------------------------------------------
local function CreateSlider(parent, min, max, step, getter, setter, fmt, onChange)
fmt = fmt or "%.2f"
local s = CreateFrame("Slider", nil, parent)
s:SetOrientation("HORIZONTAL")
s:SetSize(160, 16)
s:SetMinMaxValues(min, max)
s:SetValueStep(step)
s:SetObeyStepOnDrag(true)
s:SetValue(getter())
s.trackBG = s:CreateTexture(nil, "BACKGROUND")
s.trackBG:SetColorTexture(c(C.panel))
s.trackBG:SetHeight(4)
s.trackBG:SetPoint("LEFT", 0, 0)
s.trackBG:SetPoint("RIGHT", 0, 0)
-- Active fill: from left edge of track to the thumb
s.trackFill = s:CreateTexture(nil, "BORDER")
s.trackFill:SetColorTexture(c(C.accentDim))
s.trackFill:SetHeight(4)
s.trackFill:SetPoint("LEFT", s.trackBG, "LEFT")
local thumb = s:CreateTexture(nil, "OVERLAY")
thumb:SetColorTexture(c(C.accent))
thumb:SetSize(6, 16)
s:SetThumbTexture(thumb)
-- Editable value input sitting to the right of the slider.
local eb = CreateFrame("EditBox", nil, s)
eb:SetSize(60, 18)
eb:SetPoint("LEFT", s, "RIGHT", 10, 0)
eb:SetAutoFocus(false)
eb:SetJustifyH("CENTER")
eb:SetMaxLetters(10)
eb:SetFont(FONT_BODY, 11, "")
eb:SetTextColor(c(C.textPrim))
eb:SetTextInsets(4, 4, 0, 0)
SetBG(eb, C.button)
SetBorder(eb, C.borderSubtle, 1)
eb:SetText(string.format(fmt, getter()))
s.valueInput = eb
s.valueLabel = eb -- alias so AddRow's offset detection still works
local function unitFor(f)
-- Extract any trailing unit from the format (e.g. " px", " s", " icons")
return (f:match("%%[^%s]*(.*)$")) or ""
end
local unitSuffix = unitFor(fmt)
local function parseInput(text)
if not text or text == "" then return nil end
-- Strip common unit suffixes and anything non-numeric trailing.
local numStr = text:match("^%s*(%-?[%d%.]+)")
return tonumber(numStr)
end
local function updateFill(value)
local lo, hi = s:GetMinMaxValues()
local pct = (value - lo) / math.max(hi - lo, 0.0001)
local w = math.max(0.01, pct * s:GetWidth())
s.trackFill:SetWidth(w)
end
updateFill(getter())
s:SetScript("OnValueChanged", function(self, value)
if step and step > 0 then
value = math.floor((value / step) + 0.5) * step
end
setter(value)
-- Only refresh the EditBox text when it's not being edited, to avoid
-- fighting the user's keystrokes.
if not eb:HasFocus() then
eb:SetText(string.format(fmt, value))
end
updateFill(value)
if onChange then onChange(value) end
end)
eb:SetScript("OnEscapePressed", function(self)
self:SetText(string.format(fmt, s:GetValue()))
self:ClearFocus()
end)
eb:SetScript("OnEnterPressed", function(self)
local v = parseInput(self:GetText())
if v then
local lo, hi = s:GetMinMaxValues()
v = math.max(lo, math.min(hi, v))
s:SetValue(v)
end
self:ClearFocus()
end)
eb:SetScript("OnEditFocusLost", function(self)
local v = parseInput(self:GetText())
if v then
local lo, hi = s:GetMinMaxValues()
v = math.max(lo, math.min(hi, v))
s:SetValue(v)
end
self:SetText(string.format(fmt, s:GetValue()))
end)
-- Derive a "numeric-only" format spec from the display `fmt` so we
-- show the editable value without the unit suffix AND without Lua's
-- default full float precision. E.g. "%.2fx" -> "%.2f", "%d icons" -> "%d".
local editFmt = fmt:match("(%%[%-%+]?%d*%.?%d*[dfgeEGiouxX])") or "%g"
eb:SetScript("OnEditFocusGained", function(self)
self:SetText(string.format(editFmt, s:GetValue()))
self:HighlightText()
end)
return s
end
-- ---------------------------------------------------------------------------
-- Dropdown (custom popup)
-- ---------------------------------------------------------------------------
-- Track open popups so clicking another dropdown closes any prior one.
local _openPopup
local function CreateDropdown(parent, options, getter, setter, onChange, width, maxPopupHeight)
width = width or 160
maxPopupHeight = maxPopupHeight or 320
local dd = CreateFrame("Button", nil, parent)
dd:SetSize(width, 24)
SetBG(dd, C.button)
SetBorder(dd, C.borderSubtle, 1)
dd.text = dd:CreateFontString(nil, "OVERLAY", "GameFontNormal")
dd.text:SetFont(FONT_BODY, 12, "")
dd.text:SetPoint("LEFT", 8, 0)
dd.text:SetPoint("RIGHT", -20, 0)
dd.text:SetJustifyH("LEFT")
dd.text:SetTextColor(c(C.textPrim))
-- Down-arrow indicator. A real texture, not a Unicode glyph (WoW's UI
-- fonts don't carry the "down triangle" codepoint and render it as a
-- missing-glyph square).
dd.arrow = dd:CreateTexture(nil, "OVERLAY")
dd.arrow:SetSize(10, 10)
dd.arrow:SetPoint("RIGHT", -8, 0)
dd.arrow:SetTexture("Interface\\ChatFrame\\ChatFrameExpandArrow")
dd.arrow:SetRotation(-math.pi / 2) -- rotate right-arrow to point down
dd.arrow:SetVertexColor(c(C.textSec))
-- Measure the longest option text so the popup can auto-size to fit
-- long names (e.g. "Microsoft David Desktop - English (United States)")
-- instead of clipping them. The dropdown BUTTON keeps its original
-- narrow width; only the popup expands.
local measurer = UIParent:CreateFontString(nil, "BACKGROUND")
measurer:SetFont(FONT_BODY, 12, "")
local maxTextWidth = 0
for _, opt in ipairs(options) do
measurer:SetText(opt.text or "")
local w = measurer:GetStringWidth() or 0
if w > maxTextWidth then maxTextWidth = w end
end
measurer:Hide()
-- +30 accounts for left padding (8) + scroll-bar reservation (~16) + comfort.
local popupWidth = math.max(width, maxTextWidth + 30)
popupWidth = math.min(popupWidth, 480) -- hard cap
-- Popup (scrollable when there are more options than fit in maxPopupHeight)
local itemH = 22
local fullHeight = #options * itemH + 4
local needScroll = fullHeight > maxPopupHeight
local popupHeight = needScroll and maxPopupHeight or fullHeight
local popup = CreateFrame("Frame", nil, UIParent)
popup:SetFrameStrata("FULLSCREEN_DIALOG")
popup:SetSize(popupWidth, popupHeight)
popup:Hide()
SetBG(popup, C.panel)
SetBorder(popup, C.borderSubtle, 1)
local itemParent = popup
if needScroll then
local sf = CreateFrame("ScrollFrame", nil, popup, "UIPanelScrollFrameTemplate")
sf:SetPoint("TOPLEFT", 2, -2)
sf:SetPoint("BOTTOMRIGHT", -12, 2)
StyleScrollFrame(sf)
local sc = CreateFrame("Frame", nil, sf)
sc:SetSize(popupWidth - 16, fullHeight - 4)
sf:SetScrollChild(sc)
itemParent = sc
end
for i, opt in ipairs(options) do
local item = CreateFrame("Button", nil, itemParent)
item:SetSize(popupWidth - (needScroll and 18 or 4), itemH - 0)
if needScroll then
item:SetPoint("TOPLEFT", 0, -(i - 1) * itemH)
else
item:SetPoint("TOPLEFT", 2, -(i - 1) * itemH - 2)
end
item.hl = item:CreateTexture(nil, "BACKGROUND")
item.hl:SetAllPoints()
item.hl:SetColorTexture(c(C.panelHover))
item.hl:Hide()
item.text = item:CreateFontString(nil, "OVERLAY", "GameFontNormal")
item.text:SetFont(FONT_BODY, 12, "")
item.text:SetPoint("LEFT", 8, 0)
item.text:SetText(opt.text)
item.text:SetTextColor(c(C.textPrim))
-- If the option carries a font path, preview it in the item label
-- (overrides the Poppins body font for this specific item).
if opt.preview then
item.text:SetFont(opt.preview, 12, "")
end
item:SetScript("OnEnter", function() item.hl:Show() end)
item:SetScript("OnLeave", function() item.hl:Hide() end)
item:SetScript("OnClick", function()
setter(opt.value)
dd.text:SetText(opt.text)
popup:Hide()
_openPopup = nil
if onChange then onChange(opt.value) end
end)
end
local function refresh()
local val = getter()
for _, opt in ipairs(options) do
if opt.value == val then
dd.text:SetText(opt.text)
return
end
end
if options[1] then dd.text:SetText(options[1].text) end
end
refresh()
dd:SetScript("OnClick", function()
if popup:IsShown() then
popup:Hide()
_openPopup = nil
else
if _openPopup and _openPopup ~= popup then _openPopup:Hide() end
popup:ClearAllPoints()
popup:SetPoint("TOPLEFT", dd, "BOTTOMLEFT", 0, -4)
popup:Show()
-- Clamp inside the config window: if the popup extends past
-- the main frame's right edge, re-anchor it to open from the
-- dropdown's RIGHT edge instead (expanding leftward).
if mainFrame and mainFrame:IsShown() then
local mainRight = mainFrame:GetRight()
local popRight = popup:GetRight()
if mainRight and popRight and popRight > mainRight - 10 then
popup:ClearAllPoints()
popup:SetPoint("TOPRIGHT", dd, "BOTTOMRIGHT", 0, -4)
end
end
_openPopup = popup
end
end)
-- Close popup when main config window hides
dd.popup = popup
dd.Refresh = refresh
return dd
end
-- ---------------------------------------------------------------------------
-- Button
-- ---------------------------------------------------------------------------
local function CreateButton(parent, text, onClick, width)
local b = CreateFrame("Button", nil, parent)
b:SetSize(width or 110, 24)
SetBG(b, C.button)
SetBorder(b, C.borderSubtle, 1)
b.text = b:CreateFontString(nil, "OVERLAY", "GameFontNormal")
b.text:SetFont(FONT_BODY, 12, "")
b.text:SetPoint("CENTER")
b.text:SetText(text)
b.text:SetTextColor(c(C.textPrim))
b:SetScript("OnEnter", function() b._bg:SetColorTexture(c(C.buttonHover)) end)
b:SetScript("OnLeave", function() b._bg:SetColorTexture(c(C.button)) end)
b:SetScript("OnClick", onClick)
return b
end
-- ---------------------------------------------------------------------------
-- Single-line text input (matches the slider value-input styling)
-- ---------------------------------------------------------------------------
local function CreateTextInput(parent, getter, setter, maxLetters, width)
local eb = CreateFrame("EditBox", nil, parent)
eb:SetSize(width or 220, 22)
eb:SetAutoFocus(false)
eb:SetMaxLetters(maxLetters or 64)
eb:SetFont(FONT_BODY, 12, "")
eb:SetTextColor(c(C.textPrim))
eb:SetTextInsets(6, 6, 0, 0)
SetBG(eb, C.button)
SetBorder(eb, C.borderSubtle, 1)
eb:SetText(getter() or "")
local function commit()
local v = eb:GetText() or ""
setter(v)
end
eb:SetScript("OnEnterPressed", function(self) commit(); self:ClearFocus() end)
eb:SetScript("OnEscapePressed", function(self) self:SetText(getter() or ""); self:ClearFocus() end)
eb:SetScript("OnEditFocusLost", function(self) commit() end)
eb:SetScript("OnEditFocusGained", function(self) self:HighlightText() end)
return eb
end
-- ---------------------------------------------------------------------------
-- Color swatch
-- ---------------------------------------------------------------------------
local function CreateColorSwatch(parent, getter, setter, onChange)
local btn = CreateFrame("Button", nil, parent)
btn:SetSize(24, 24)
btn.border = btn:CreateTexture(nil, "BORDER")
btn.border:SetAllPoints()
btn.border:SetColorTexture(c(C.borderSubtle))
btn.tex = btn:CreateTexture(nil, "ARTWORK")
btn.tex:SetPoint("TOPLEFT", 1, -1)
btn.tex:SetPoint("BOTTOMRIGHT", -1, 1)
local function update()
local col = getter()
btn.tex:SetColorTexture(col[1], col[2], col[3], col[4] or 1)
end
update()
local function apply(r, g, b, a)
setter({r, g, b, a})
update()
if onChange then onChange() end
end
btn:SetScript("OnClick", function()
local cur = getter()
local info = {
swatchFunc = function()
local r, g, bl = ColorPickerFrame:GetColorRGB()
local a = 1
if ColorPickerFrame.GetColorAlpha then
a = ColorPickerFrame:GetColorAlpha()
elseif OpacitySliderFrame then
a = 1 - OpacitySliderFrame:GetValue()
end
apply(r, g, bl, a)
end,
opacityFunc = function()
local r, g, bl = ColorPickerFrame:GetColorRGB()
local a = 1
if ColorPickerFrame.GetColorAlpha then
a = ColorPickerFrame:GetColorAlpha()
elseif OpacitySliderFrame then
a = 1 - OpacitySliderFrame:GetValue()
end
apply(r, g, bl, a)
end,
cancelFunc = function(prev)
apply(prev.r, prev.g, prev.b, prev.opacity or 1)
end,
hasOpacity = true,
opacity = cur[4] or 1,
r = cur[1], g = cur[2], b = cur[3],
}
if ColorPickerFrame.SetupColorPickerAndShow then
ColorPickerFrame:SetupColorPickerAndShow(info)
else
ColorPickerFrame.func = info.swatchFunc
ColorPickerFrame.opacityFunc = info.opacityFunc
ColorPickerFrame.cancelFunc = info.cancelFunc
ColorPickerFrame.hasOpacity = info.hasOpacity
ColorPickerFrame.opacity = info.opacity
ColorPickerFrame:SetColorRGB(info.r, info.g, info.b)
ColorPickerFrame:Hide()
ColorPickerFrame:Show()
end
end)
btn.Refresh = update
return btn
end
-- ---------------------------------------------------------------------------
-- Section card (grouped settings with accent bar + title)
-- ---------------------------------------------------------------------------
local function CreateSection(parent, titleText)
local section = CreateFrame("Frame", nil, parent)
SetBG(section, C.panel)
section.accent = section:CreateTexture(nil, "ARTWORK")
section.accent:SetColorTexture(c(C.accent))
section.accent:SetWidth(3)
section.accent:SetPoint("TOPLEFT", 0, -8)
section.accent:SetPoint("BOTTOMLEFT", 0, 8)
section.title = MakeLabel(section, string.upper(titleText), "section")
section.title:SetPoint("TOPLEFT", 14, -10)
section.divider = section:CreateTexture(nil, "ARTWORK")
section.divider:SetColorTexture(c(C.divider))
section.divider:SetHeight(1)
section.divider:SetPoint("TOPLEFT", 14, -28)
section.divider:SetPoint("TOPRIGHT", -14, -28)
section.content = CreateFrame("Frame", nil, section)
section.content:SetPoint("TOPLEFT", 14, -36)
section.content:SetPoint("BOTTOMRIGHT", -14, 12)
section._cursorY = 0
return section
end
-- A row inside a section: label on the left, widget on the right.
-- description is optional and appears in small grey text below the label.
--
-- Layout:
-- Without description: label and widget are both vertically centered on
-- the row's midline. Label text is left-justified and never wraps, so
-- every row in every section reads on a clean horizontal line regardless
-- of label length or widget height (dropdowns 24 px, sliders 16 px,
-- toggles 20 px all line up on the same center).
--
-- With description: label at the top, description right below the label,
-- widget also top-anchored. The description is word-wrapped within the
-- space left of the widget.
local function AddRow(section, labelText, widget, description)
local content = section.content
local y = section._cursorY
local row = CreateFrame("Frame", nil, content)
row:SetPoint("TOPLEFT", 0, -y)
row:SetPoint("TOPRIGHT", 0, -y)
-- Compute the row height BEFORE placing widgets, since the center
-- anchor depends on the final row height.
local rowH = 22
if widget then
rowH = math.max(rowH, widget:GetHeight() + 6)
end
if description then
rowH = math.max(48, rowH + 22)
end
row:SetHeight(rowH)
-- ---- Widget --------------------------------------------------------
local rightOffset = 0
if widget then
widget:SetParent(row)
widget:ClearAllPoints()
-- Sliders carry a `.valueInput` EditBox that sticks out to the right;
-- reserve that space so the editbox stays inside the row.
if widget.valueInput then
rightOffset = -(widget.valueInput:GetWidth() + 16)
end
if description then
-- Multi-line row: widget top-aligned with label.
widget:SetPoint("TOPRIGHT", rightOffset, -2)
else
-- Single-line row: widget vertically centered on the row.
widget:SetPoint("RIGHT", rightOffset, 0)
end
end
-- ---- Label ---------------------------------------------------------
local labelFS = MakeLabel(row, labelText, "primary")
labelFS:SetJustifyH("LEFT")
labelFS:SetWordWrap(false)
if description then
labelFS:SetPoint("TOPLEFT", 0, -2)
else
labelFS:SetPoint("LEFT", 0, 0)
end
if widget then
labelFS:SetPoint("RIGHT", widget, "LEFT", -8, 0)
else
labelFS:SetPoint("RIGHT", -4, 0)
end
-- ---- Optional description -----------------------------------------
if description then
local desc = MakeLabel(row, description, "secondary")
desc:SetJustifyH("LEFT")
desc:SetWordWrap(true)
desc:SetPoint("TOPLEFT", 0, -20)
if widget then
desc:SetPoint("RIGHT", widget, "LEFT", -16, 0)
else
desc:SetPoint("RIGHT", -10, 0)
end
end
section._cursorY = y + rowH + 10
end
-- Finalize section height based on its cursor.
local function FinalizeSection(section)
section:SetHeight(section._cursorY + 48)
end
-- ---------------------------------------------------------------------------
-- Main frame + tabs
-- ---------------------------------------------------------------------------
local mainFrame
local tabButtons, tabPanels = {}, {}
local activeTabIndex = 1
local function SelectTab(index)
-- Close any dropdown popup left open by the tab we're leaving. The
-- popups are parented to UIParent (not the tab panel) so they don't
-- hide automatically when the tab panel hides.
if _openPopup then _openPopup:Hide(); _openPopup = nil end
activeTabIndex = index
for i, panel in ipairs(tabPanels) do panel:SetShown(i == index) end
for i, btn in ipairs(tabButtons) do
btn:SetActive(i == index)
end
end
local function CreateTabButton(parent, label, onClick)
local b = CreateFrame("Button", nil, parent)
b:SetSize(140, 32)
b.text = MakeLabel(b, label, "primary")
b.text:SetPoint("CENTER", 0, 2)
b.underline = b:CreateTexture(nil, "OVERLAY")
b.underline:SetColorTexture(c(C.accent))
b.underline:SetHeight(2)
b.underline:SetPoint("BOTTOMLEFT", 6, 0)
b.underline:SetPoint("BOTTOMRIGHT", -6, 0)
b.underline:Hide()
function b:SetActive(active)
if active then
b.text:SetTextColor(c(C.accent))
b.underline:Show()
else
b.text:SetTextColor(c(C.textSec))
b.underline:Hide()
end
end
b:SetActive(false)
b:SetScript("OnEnter", function() if not b.underline:IsShown() then b.text:SetTextColor(c(C.textPrim)) end end)
b:SetScript("OnLeave", function() if not b.underline:IsShown() then b.text:SetTextColor(c(C.textSec)) end end)
b:SetScript("OnClick", onClick)
return b
end
local function BuildMain()
if mainFrame then return mainFrame end
local f = CreateFrame("Frame", "NSRTEnhancerConfigFrame", UIParent)
f:SetSize(680, 640)
f:SetPoint("CENTER")
f:SetFrameStrata("HIGH")
f:SetToplevel(true)
f:SetClampedToScreen(true) -- prevent dragging fully off-screen
f:Hide()
-- Drag from anywhere on the frame. Interactive children (buttons,
-- sliders, dropdowns, checkboxes, editboxes) have their own mouse, so
-- they absorb clicks before the main frame sees them and dragging only
-- starts on empty space -- which is the "drag from anywhere" UX the
-- user asked for.
f:SetMovable(true)
f:EnableMouse(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", function(self) self:StartMoving() end)
f:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
-- Background + subtle border
SetBG(f, C.bg)
SetBorder(f, C.borderSubtle, 1)
-- Title
f.title = MakeLabel(f, "NSRT Enhancer", "title")
f.title:SetPoint("TOPLEFT", 20, -16)
f.version = MakeLabel(f, "v2.0", "version")
f.version:SetPoint("LEFT", f.title, "RIGHT", 8, -2)
-- Close button (custom X)
f.close = CreateFrame("Button", nil, f)
f.close:SetSize(28, 28)
f.close:SetPoint("TOPRIGHT", -10, -10)
f.close.text = f.close:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
f.close.text:SetPoint("CENTER", 0, 1)
f.close.text:SetText("×")
f.close.text:SetFont(FONT_HEADER, 22, "")
f.close.text:SetTextColor(c(C.textSec))
f.close:SetScript("OnEnter", function() f.close.text:SetTextColor(1, 1, 1) end)
f.close:SetScript("OnLeave", function() f.close.text:SetTextColor(c(C.textSec)) end)
f.close:SetScript("OnClick", function() f:Hide() end)
-- Divider under title
f.topDivider = f:CreateTexture(nil, "ARTWORK")
f.topDivider:SetColorTexture(c(C.divider))
f.topDivider:SetHeight(1)
f.topDivider:SetPoint("TOPLEFT", 0, -48)
f.topDivider:SetPoint("TOPRIGHT", 0, -48)
-- Tabs
local tabNames = { "Past Reminders", "On Deck", "Voice", "On You" }
for i, name in ipairs(tabNames) do
local tab = CreateTabButton(f, name, function() SelectTab(i) end)
if i == 1 then
tab:SetPoint("TOPLEFT", 16, -52)
else
tab:SetPoint("LEFT", tabButtons[i - 1], "RIGHT", 8, 0)
end
tabButtons[i] = tab
local panel = CreateFrame("Frame", nil, f)
panel:SetPoint("TOPLEFT", 0, -92)
panel:SetPoint("BOTTOMRIGHT", 0, 0)
panel:Hide()
tabPanels[i] = panel
end
-- Tab-bar bottom divider
f.tabsDivider = f:CreateTexture(nil, "ARTWORK")
f.tabsDivider:SetColorTexture(c(C.divider))
f.tabsDivider:SetHeight(1)
f.tabsDivider:SetPoint("TOPLEFT", 0, -88)
f.tabsDivider:SetPoint("TOPRIGHT", 0, -88)
-- Close open dropdown popups on hide
f:SetScript("OnHide", function()
if _openPopup then _openPopup:Hide(); _openPopup = nil end
end)
mainFrame = f
return f
end
-- ---------------------------------------------------------------------------
-- Module master-enable header (shared by all tabs)
-- ---------------------------------------------------------------------------
--
-- Renders a "Enable <Module>" toggle + thin divider across the top of a tab
-- and returns a content Frame anchored BELOW it. A click-blocking / dimming
-- mask overlay is installed over the content; flipping the toggle off shows
-- the mask (greyed + inert) and flipping it on hides it.
--
-- Usage: `local content = BuildTabMaster(panel, "Past Reminders", getter, setter)`
-- Then parent all your sections / scroll frames to `content` instead of
-- `panel` directly.
local function BuildTabMaster(panel, moduleLabel, getter, setter)
-- Top bar holding the master toggle
local bar = CreateFrame("Frame", nil, panel)
bar:SetPoint("TOPLEFT", 16, -12)
bar:SetPoint("TOPRIGHT", -16, -12)
bar:SetHeight(28)
local labelFS = MakeLabel(bar, "Enable " .. moduleLabel, "primary")
labelFS:SetPoint("LEFT", 0, 0)
-- State text ("ON" / "OFF") on the right for extra clarity
local stateFS = MakeLabel(bar, "", "secondary")
stateFS:SetPoint("RIGHT", 0, 0)
-- Thin divider beneath the bar
local sep = panel:CreateTexture(nil, "ARTWORK")
sep:SetColorTexture(c(C.divider))
sep:SetHeight(1)
sep:SetPoint("TOPLEFT", 16, -46)
sep:SetPoint("TOPRIGHT", -16, -46)
-- Content area below the bar
local content = CreateFrame("Frame", nil, panel)
content:SetPoint("TOPLEFT", 0, -52)
content:SetPoint("BOTTOMRIGHT", 0, 0)
-- Disabled mask: click-blocking dark overlay with centered hint text.
-- Parented to the panel (not content) so it sits above the content's
-- descendants and intercepts every click in the area.
local mask = CreateFrame("Frame", nil, panel)
mask:SetAllPoints(content)
mask:SetFrameLevel(content:GetFrameLevel() + 50) -- above all descendants of `content`
mask:EnableMouse(true)
mask:EnableMouseWheel(true)
mask.tex = mask:CreateTexture(nil, "OVERLAY")
mask.tex:SetAllPoints()
mask.tex:SetColorTexture(c(C.bg, 0.65))
mask.hint = MakeLabel(mask, "Module disabled", "section")
mask.hint:SetPoint("CENTER", 0, 20)
mask.hint:SetTextColor(c(C.textMuted))
mask.sub = MakeLabel(mask, "Toggle above to enable and configure", "secondary")
mask.sub:SetPoint("TOP", mask.hint, "BOTTOM", 0, -6)
mask.sub:SetTextColor(c(C.textMuted))
mask:Hide()
local function refresh(enabled)
if enabled then
mask:Hide()
content:SetAlpha(1)
stateFS:SetText("ON")
stateFS:SetTextColor(c(C.toggleOn))
else
mask:Show()
-- Keep content semi-visible (helps user see the settings) but
-- dimmed so the disabled state is obvious.
content:SetAlpha(0.5)
stateFS:SetText("OFF")
stateFS:SetTextColor(c(C.textMuted))
end
end
-- Toggle is placed AFTER the state label so drag-like click flows feel
-- natural. It wraps the user's setter so we refresh the UI in lockstep.
local toggle = CreateToggle(bar, getter, function(v)
setter(v)
refresh(getter())
end)
toggle:SetPoint("LEFT", labelFS, "RIGHT", 12, 0)
-- Initial sync.
refresh(getter())
-- Expose the refresh hook so external mutations (e.g. `/nse mute`)
-- can request a visual resync.
panel._refreshMaster = refresh
return content
end
-- ---------------------------------------------------------------------------
-- Tab 1: Past Reminders
-- ---------------------------------------------------------------------------
local function BuildPastRemindersTab(panel)
local content = BuildTabMaster(panel, "Past Reminders",
function() return NSE.db.pastReminders.enabled end,
function(v) NSE.PastReminders:SetEnabled(v) end)
local inner = CreateFrame("Frame", nil, content)
inner:SetPoint("TOPLEFT", 20, -20)
inner:SetPoint("BOTTOMRIGHT", -20, 20)