forked from EllesmereGaming/EllesmereUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEllesmereUI_Presets.lua
More file actions
2300 lines (2136 loc) · 107 KB
/
EllesmereUI_Presets.lua
File metadata and controls
2300 lines (2136 loc) · 107 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
-------------------------------------------------------------------------------
-- EllesmereUI_Presets.lua
--
-- Preset system, spec assignment popup, and spec auto-switch handler.
-- Split from EllesmereUI.lua -- see EllesmereUI.lua for the base addon code.
--
-- Load order (via TOC):
-- 1. EllesmereUI.lua -- constants, utils, popups, main frame
-- 2. EllesmereUI_Widgets.lua -- shared widget helpers, widget factory
-- 3. EllesmereUI_Presets.lua -- THIS FILE
-------------------------------------------------------------------------------
local EllesmereUI = _G.EllesmereUI
local PP = EllesmereUI.PanelPP
-- Utility functions
local SolidTex = EllesmereUI.SolidTex
local MakeFont = EllesmereUI.MakeFont
local MakeBorder = EllesmereUI.MakeBorder
local DisablePixelSnap = EllesmereUI.DisablePixelSnap
local lerp = EllesmereUI.lerp
local MakeDropdownArrow = EllesmereUI.MakeDropdownArrow
local RegisterWidgetRefresh = EllesmereUI.RegisterWidgetRefresh
-- Widget helpers (from EllesmereUI_Widgets.lua — resolved lazily since Widgets
-- may be deferred; these locals are populated inside BuildPresetSystem)
local MakeStyledButton, WB_COLOURS, RB_COLOURS, DDText
local BuildDropdownMenu, WireDropdownScripts, WD_DD_COLOURS, RD_DD_COLOURS
local BuildSliderCore, BuildDropdownControl
-- Visual constants
local EXPRESSWAY = EllesmereUI.EXPRESSWAY
local ELLESMERE_GREEN = EllesmereUI.ELLESMERE_GREEN
local CONTENT_PAD = EllesmereUI.CONTENT_PAD
local DARK_BG = EllesmereUI.DARK_BG
local BORDER_COLOR = EllesmereUI.BORDER_COLOR
local TEXT_WHITE = EllesmereUI.TEXT_WHITE
local TEXT_DIM = EllesmereUI.TEXT_DIM
local MEDIA_PATH = EllesmereUI.MEDIA_PATH
local ICONS_PATH = EllesmereUI.ICONS_PATH
local CLASS_COLOR_MAP = EllesmereUI.CLASS_COLOR_MAP
local CLASS_ART_MAP = EllesmereUI.CLASS_ART_MAP
-- Numeric constants used in preset UI
local TEXT_WHITE_R = EllesmereUI.TEXT_WHITE_R
local TEXT_WHITE_G = EllesmereUI.TEXT_WHITE_G
local TEXT_WHITE_B = EllesmereUI.TEXT_WHITE_B
local TEXT_DIM_R = EllesmereUI.TEXT_DIM_R
local TEXT_DIM_G = EllesmereUI.TEXT_DIM_G
local TEXT_DIM_B = EllesmereUI.TEXT_DIM_B
local TEXT_DIM_A = EllesmereUI.TEXT_DIM_A
local BORDER_R = EllesmereUI.BORDER_R
local BORDER_G = EllesmereUI.BORDER_G
local BORDER_B = EllesmereUI.BORDER_B
local CB_BOX_R = EllesmereUI.CB_BOX_R
local CB_BOX_G = EllesmereUI.CB_BOX_G
local CB_BOX_B = EllesmereUI.CB_BOX_B
local CB_BRD_A = EllesmereUI.CB_BRD_A
local CB_ACT_BRD_A = EllesmereUI.CB_ACT_BRD_A
local DD_BG_R = EllesmereUI.DD_BG_R
local DD_BG_G = EllesmereUI.DD_BG_G
local DD_BG_B = EllesmereUI.DD_BG_B
local DD_BG_A = EllesmereUI.DD_BG_A
local DD_BG_HA = EllesmereUI.DD_BG_HA
local DD_BRD_A = EllesmereUI.DD_BRD_A
local DD_BRD_HA = EllesmereUI.DD_BRD_HA
local DD_TXT_A = EllesmereUI.DD_TXT_A
local DD_TXT_HA = EllesmereUI.DD_TXT_HA
local DD_ITEM_HL_A = EllesmereUI.DD_ITEM_HL_A
local DD_ITEM_SEL_A = EllesmereUI.DD_ITEM_SEL_A
local BTN_BG_R = EllesmereUI.BTN_BG_R
local BTN_BG_G = EllesmereUI.BTN_BG_G
local BTN_BG_B = EllesmereUI.BTN_BG_B
local BTN_BG_A = EllesmereUI.BTN_BG_A
local BTN_BG_HA = EllesmereUI.BTN_BG_HA
local BTN_BRD_A = EllesmereUI.BTN_BRD_A
local BTN_BRD_HA = EllesmereUI.BTN_BRD_HA
local BTN_TXT_A = EllesmereUI.BTN_TXT_A
local BTN_TXT_HA = EllesmereUI.BTN_TXT_HA
local SL_INPUT_A = EllesmereUI.SL_INPUT_A
-------------------------------------------------------------------------------
-- SPEC ASSIGNMENT POPUP
--
-- Shows every spec sorted by class with checkboxes in a 3-column layout.
-- Stores assignments in db[dbKey][presetKey] = { [specID] = true, ... }
-------------------------------------------------------------------------------
do
-- All WoW Retail classes and their specs (as of TWW / 12.0)
-- Order: alphabetical by class name
local SPEC_DATA = {
{ class = "DEATHKNIGHT", name = "Death Knight", specs = {
{ id = 250, name = "Blood" },
{ id = 251, name = "Frost" },
{ id = 252, name = "Unholy" },
}},
{ class = "DEMONHUNTER", name = "Demon Hunter", specs = {
{ id = 577, name = "Havoc" },
{ id = 581, name = "Vengeance" },
{ id = 1456, name = "Devourer" },
}},
{ class = "DRUID", name = "Druid", specs = {
{ id = 102, name = "Balance" },
{ id = 103, name = "Feral" },
{ id = 104, name = "Guardian" },
{ id = 105, name = "Restoration" },
}},
{ class = "EVOKER", name = "Evoker", specs = {
{ id = 1467, name = "Devastation" },
{ id = 1468, name = "Preservation" },
{ id = 1473, name = "Augmentation" },
}},
{ class = "HUNTER", name = "Hunter", specs = {
{ id = 253, name = "Beast Mastery" },
{ id = 254, name = "Marksmanship" },
{ id = 255, name = "Survival" },
}},
{ class = "MAGE", name = "Mage", specs = {
{ id = 62, name = "Arcane" },
{ id = 63, name = "Fire" },
{ id = 64, name = "Frost" },
}},
{ class = "MONK", name = "Monk", specs = {
{ id = 268, name = "Brewmaster" },
{ id = 270, name = "Mistweaver" },
{ id = 269, name = "Windwalker" },
}},
{ class = "PALADIN", name = "Paladin", specs = {
{ id = 65, name = "Holy" },
{ id = 66, name = "Protection" },
{ id = 70, name = "Retribution" },
}},
{ class = "PRIEST", name = "Priest", specs = {
{ id = 256, name = "Discipline" },
{ id = 257, name = "Holy" },
{ id = 258, name = "Shadow" },
}},
{ class = "ROGUE", name = "Rogue", specs = {
{ id = 259, name = "Assassination" },
{ id = 260, name = "Outlaw" },
{ id = 261, name = "Subtlety" },
}},
{ class = "SHAMAN", name = "Shaman", specs = {
{ id = 262, name = "Elemental" },
{ id = 263, name = "Enhancement" },
{ id = 264, name = "Restoration" },
}},
{ class = "WARLOCK", name = "Warlock", specs = {
{ id = 265, name = "Affliction" },
{ id = 266, name = "Demonology" },
{ id = 267, name = "Destruction" },
}},
{ class = "WARRIOR", name = "Warrior", specs = {
{ id = 71, name = "Arms" },
{ id = 72, name = "Fury" },
{ id = 73, name = "Protection" },
}},
}
EllesmereUI._SPEC_DATA = SPEC_DATA
-- 5-column layout, sorted alphabetically left-to-right, top-to-bottom:
-- col1 = DK, Mage, Shaman
-- col2 = DH, Monk, Warlock
-- col3 = Druid, Paladin, Warrior
-- col4 = Evoker, Priest
-- col5 = Hunter, Rogue
local NUM_COLS = 5
local COL_LISTS = { {1,6,11}, {2,7,12}, {3,8,13}, {4,9}, {5,10} }
local specPopup -- reusable popup frame
function EllesmereUI:ShowSpecAssignPopup(opts)
local db = opts.db
local dbKey = opts.dbKey
local presetKey = opts.presetKey
local defaultKey = opts.defaultKey -- DB key for spec default preset (nil = no default feature)
local allPresetKeysFn = opts.allPresetKeys -- function() returns { {key=, name=}, ... } of presets excluding current
local onDefaultChanged = opts.onDefaultChanged -- callback after default is set
local onDone = opts.onDone -- callback after popup closes (used to apply preset for current spec)
-- Ensure assignments table exists
if not db[dbKey] then db[dbKey] = {} end
if not db[dbKey][presetKey] then db[dbKey][presetKey] = {} end
local assignments = db[dbKey][presetKey]
-- Build or reuse the popup
if not specPopup then
local FONT = EllesmereUI._font or ("Interface\\AddOns\\EllesmereUI\\media\\fonts\\Expressway.ttf")
local COL_W = 165
local COL_GAP = 12
local CONTENT_LEFT = 41 -- left padding (26 + 15px extra)
local CONTENT_RIGHT = 36 -- right padding (26 + 10px extra)
local CONTENT_TOP = 120 -- below title + subtitle + check/uncheck links (-20px below links)
local CLASS_H = 32 -- class header row height
local CLASS_PAD_TOP = 4 -- extra space above each class title
local CLASS_PAD_BOT = 2 -- extra space below each class title
local SPEC_H = 28 -- spec checkbox row height
local CLASS_GAP = 10 -- extra spacing between class groups
-- Dynamic popup width based on column count
local POPUP_W = CONTENT_LEFT + CONTENT_RIGHT + NUM_COLS * COL_W + (NUM_COLS - 1) * COL_GAP
local POPUP_H = 740
-- Pixel-perfect scale (includes user panel scale)
local ppScale = EllesmereUI.GetPopupScale()
-- Dimmer
local dimmer = CreateFrame("Frame", "EUISpecAssignDimmer", UIParent)
dimmer:SetFrameStrata("FULLSCREEN_DIALOG")
dimmer:SetAllPoints(UIParent)
dimmer:EnableMouse(true)
dimmer:EnableMouseWheel(true)
dimmer:SetScript("OnMouseWheel", function() end)
dimmer:Hide()
dimmer:SetScale(ppScale)
local dimTex = dimmer:CreateTexture(nil, "BACKGROUND")
dimTex:SetAllPoints()
dimTex:SetColorTexture(0, 0, 0, 0.25)
-- Popup frame
local popup = CreateFrame("Frame", "EUISpecAssignPopup", dimmer)
popup:SetScale(ppScale)
popup:SetFrameStrata("FULLSCREEN_DIALOG")
popup:SetFrameLevel(dimmer:GetFrameLevel() + 10)
-- Register for scale updates when user changes panel scale
local pf = EllesmereUI._popupFrames
if pf then pf[#pf + 1] = { popup = popup, dimmer = dimmer } end
PP.Size(popup, POPUP_W, POPUP_H)
PP.Point(popup, "CENTER", EllesmereUI._mainFrame, "CENTER", 0, 0)
-- Background
local bg = popup:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints()
bg:SetColorTexture(0.06, 0.08, 0.10, 1)
-- Border (2px inset) -- 4 edge textures
local BRD_A_SP = 0.15
local spT = popup:CreateTexture(nil, "BORDER"); spT:SetColorTexture(1, 1, 1, BRD_A_SP)
if spT.SetSnapToPixelGrid then spT:SetSnapToPixelGrid(false); spT:SetTexelSnappingBias(0) end
spT:SetPoint("TOPLEFT", 0, 0); spT:SetPoint("TOPRIGHT", 0, 0); PP.Height(spT, 2)
local spB = popup:CreateTexture(nil, "BORDER"); spB:SetColorTexture(1, 1, 1, BRD_A_SP)
if spB.SetSnapToPixelGrid then spB:SetSnapToPixelGrid(false); spB:SetTexelSnappingBias(0) end
spB:SetPoint("BOTTOMLEFT", 0, 0); spB:SetPoint("BOTTOMRIGHT", 0, 0); PP.Height(spB, 2)
local spL = popup:CreateTexture(nil, "BORDER"); spL:SetColorTexture(1, 1, 1, BRD_A_SP)
if spL.SetSnapToPixelGrid then spL:SetSnapToPixelGrid(false); spL:SetTexelSnappingBias(0) end
spL:SetPoint("TOPLEFT", spT, "BOTTOMLEFT"); spL:SetPoint("BOTTOMLEFT", spB, "TOPLEFT"); PP.Width(spL, 2)
local spR = popup:CreateTexture(nil, "BORDER"); spR:SetColorTexture(1, 1, 1, BRD_A_SP)
if spR.SetSnapToPixelGrid then spR:SetSnapToPixelGrid(false); spR:SetTexelSnappingBias(0) end
spR:SetPoint("TOPRIGHT", spT, "BOTTOMRIGHT"); spR:SetPoint("BOTTOMRIGHT", spB, "TOPRIGHT"); PP.Width(spR, 2)
-- Title
local title = popup:CreateFontString(nil, "OVERLAY")
title:SetFont(FONT, 22, "")
title:SetTextColor(1, 1, 1, 1)
PP.Point(title, "TOP", popup, "TOP", 0, -32)
title:SetText("Assign Preset to Specs")
popup._title = title
-- Subtitle
local sub = popup:CreateFontString(nil, "OVERLAY")
sub:SetFont(FONT, 14, "")
sub:SetTextColor(1, 1, 1, 0.45)
PP.Point(sub, "TOP", title, "BOTTOM", 0, -8)
sub:SetWidth(POPUP_W - 60)
sub:SetJustifyH("CENTER")
sub:SetWordWrap(true)
popup._subtitle = sub
-- Check All / Uncheck All as plain text links
local LINK_Y = -103
local LINK_GAP = 20
local checkAllBtn = CreateFrame("Button", nil, popup)
checkAllBtn:SetFrameLevel(popup:GetFrameLevel() + 2)
local checkAllLbl = checkAllBtn:CreateFontString(nil, "OVERLAY")
checkAllLbl:SetFont(FONT, 14, "")
checkAllLbl:SetText("Check All")
checkAllLbl:SetTextColor(1, 1, 1, 0.45)
checkAllLbl:SetPoint("CENTER")
checkAllBtn:SetSize(checkAllLbl:GetStringWidth() + 4, 20)
PP.Point(checkAllBtn, "TOPLEFT", popup, "TOPLEFT", CONTENT_LEFT, LINK_Y)
checkAllBtn:SetScript("OnEnter", function() checkAllLbl:SetTextColor(1, 1, 1, 0.80) end)
checkAllBtn:SetScript("OnLeave", function() checkAllLbl:SetTextColor(1, 1, 1, 0.45) end)
popup._checkAll = checkAllBtn
-- Small divider between the two links
local linkDivider = popup:CreateTexture(nil, "OVERLAY", nil, 7)
linkDivider:SetColorTexture(1, 1, 1, 0.18)
if linkDivider.SetSnapToPixelGrid then linkDivider:SetSnapToPixelGrid(false); linkDivider:SetTexelSnappingBias(0) end
PP.Point(linkDivider, "LEFT", checkAllBtn, "RIGHT", LINK_GAP / 2, 0)
PP.Width(linkDivider, 1)
PP.Height(linkDivider, 12)
local uncheckAllBtn = CreateFrame("Button", nil, popup)
uncheckAllBtn:SetFrameLevel(popup:GetFrameLevel() + 2)
local uncheckAllLbl = uncheckAllBtn:CreateFontString(nil, "OVERLAY")
uncheckAllLbl:SetFont(FONT, 14, "")
uncheckAllLbl:SetText("Uncheck All")
uncheckAllLbl:SetTextColor(1, 1, 1, 0.45)
uncheckAllLbl:SetPoint("CENTER")
uncheckAllBtn:SetSize(uncheckAllLbl:GetStringWidth() + 4, 20)
PP.Point(uncheckAllBtn, "LEFT", checkAllBtn, "RIGHT", LINK_GAP, 0)
uncheckAllBtn:SetScript("OnEnter", function() uncheckAllLbl:SetTextColor(1, 1, 1, 0.80) end)
uncheckAllBtn:SetScript("OnLeave", function() uncheckAllLbl:SetTextColor(1, 1, 1, 0.45) end)
popup._uncheckAll = uncheckAllBtn
-- Column container frames (dynamic count)
popup._columns = {}
for colIdx = 1, NUM_COLS do
local col = CreateFrame("Frame", nil, popup)
col:SetFrameLevel(popup:GetFrameLevel() + 1)
local colX = CONTENT_LEFT + (colIdx - 1) * (COL_W + COL_GAP)
PP.Point(col, "TOPLEFT", popup, "TOPLEFT", colX, -CONTENT_TOP)
PP.Size(col, COL_W, POPUP_H - CONTENT_TOP - 80)
col._rows = {}
popup._columns[colIdx] = col
end
-- Bottom area: [Default Dropdown row] then [Done button]
local BOTTOM_ROW_Y = 88 -- distance from popup bottom to default dropdown container
local DEFAULT_DD_W = 280
local DEFAULT_DD_H = 30
-- Default Profile dropdown container (hidden by default, shown when defaultKey is provided)
local defDDContainer = CreateFrame("Frame", nil, popup)
defDDContainer:SetFrameLevel(popup:GetFrameLevel() + 2)
PP.Size(defDDContainer, POPUP_W - 52, 68)
PP.Point(defDDContainer, "BOTTOM", popup, "BOTTOM", 0, BOTTOM_ROW_Y)
defDDContainer:Hide()
popup._defDDContainer = defDDContainer
-- Label (above dropdown)
local defDDLabel = defDDContainer:CreateFontString(nil, "OVERLAY")
defDDLabel:SetFont(FONT, 14, "")
defDDLabel:SetTextColor(1, 1, 1, 0.45)
PP.Point(defDDLabel, "BOTTOM", defDDContainer, "CENTER", 0, 7)
defDDLabel:SetText("Default Profile (for non-assigned specs)")
popup._defDDLabel = defDDLabel
-- Dropdown button (below label, centered)
local defDDBtn = CreateFrame("Button", nil, defDDContainer)
defDDBtn:SetFrameLevel(defDDContainer:GetFrameLevel() + 2)
PP.Size(defDDBtn, DEFAULT_DD_W, DEFAULT_DD_H)
PP.Point(defDDBtn, "TOP", defDDContainer, "CENTER", 0, -7)
local defDDBg = defDDBtn:CreateTexture(nil, "BACKGROUND")
defDDBg:SetAllPoints()
defDDBg:SetColorTexture(0.075, 0.113, 0.141, 0.9)
-- Border textures for the default dropdown (also used for flash animation)
local defBrdT = defDDBtn:CreateTexture(nil, "OVERLAY", nil, 7)
defBrdT:SetColorTexture(1, 1, 1, 0.20)
if defBrdT.SetSnapToPixelGrid then defBrdT:SetSnapToPixelGrid(false); defBrdT:SetTexelSnappingBias(0) end
defBrdT:SetPoint("TOPLEFT"); defBrdT:SetPoint("TOPRIGHT"); PP.Height(defBrdT, 1)
local defBrdB = defDDBtn:CreateTexture(nil, "OVERLAY", nil, 7)
defBrdB:SetColorTexture(1, 1, 1, 0.20)
if defBrdB.SetSnapToPixelGrid then defBrdB:SetSnapToPixelGrid(false); defBrdB:SetTexelSnappingBias(0) end
defBrdB:SetPoint("BOTTOMLEFT"); defBrdB:SetPoint("BOTTOMRIGHT"); PP.Height(defBrdB, 1)
local defBrdL = defDDBtn:CreateTexture(nil, "OVERLAY", nil, 7)
defBrdL:SetColorTexture(1, 1, 1, 0.20)
if defBrdL.SetSnapToPixelGrid then defBrdL:SetSnapToPixelGrid(false); defBrdL:SetTexelSnappingBias(0) end
defBrdL:SetPoint("TOPLEFT", defBrdT, "BOTTOMLEFT"); defBrdL:SetPoint("BOTTOMLEFT", defBrdB, "TOPLEFT"); PP.Width(defBrdL, 1)
local defBrdR = defDDBtn:CreateTexture(nil, "OVERLAY", nil, 7)
defBrdR:SetColorTexture(1, 1, 1, 0.20)
if defBrdR.SetSnapToPixelGrid then defBrdR:SetSnapToPixelGrid(false); defBrdR:SetTexelSnappingBias(0) end
defBrdR:SetPoint("TOPRIGHT", defBrdT, "BOTTOMRIGHT"); defBrdR:SetPoint("BOTTOMRIGHT", defBrdB, "TOPRIGHT"); PP.Width(defBrdR, 1)
popup._defBrdEdges = { defBrdT, defBrdB, defBrdL, defBrdR }
local defDDLbl = defDDBtn:CreateFontString(nil, "OVERLAY")
defDDLbl:SetFont(FONT, 13, "")
defDDLbl:SetPoint("LEFT", defDDBtn, "LEFT", 12, 0)
defDDLbl:SetTextColor(1, 1, 1, 0.50)
popup._defDDLbl = defDDLbl
local defArrow = MakeDropdownArrow(defDDBtn, 12, PP)
popup._defDDBtn = defDDBtn
-- Flash animation for error state on the default dropdown
local defFlashFrame = CreateFrame("Frame", nil, defDDBtn)
defFlashFrame:Hide()
local defFlashElapsed = 0
local DEF_FLASH_DUR = 0.7
defFlashFrame:SetScript("OnUpdate", function(self, elapsed)
defFlashElapsed = defFlashElapsed + elapsed
if defFlashElapsed >= DEF_FLASH_DUR then
self:Hide()
for _, e in ipairs(popup._defBrdEdges) do e:SetColorTexture(1, 1, 1, 0.20) end
return
end
local t = defFlashElapsed / DEF_FLASH_DUR
local lr = lerp(0.9, 1, t)
local lg = lerp(0.15, 1, t)
local lb = lerp(0.15, 1, t)
local la = lerp(0.7, 0.20, t)
for _, e in ipairs(popup._defBrdEdges) do e:SetColorTexture(lr, lg, lb, la) end
end)
popup._flashDefaultDD = function()
defFlashElapsed = 0
for _, e in ipairs(popup._defBrdEdges) do e:SetColorTexture(0.9, 0.15, 0.15, 0.7) end
defFlashFrame:Show()
end
-- Default dropdown menu (popout list)
local defMenu = CreateFrame("Frame", nil, UIParent)
defMenu:SetFrameStrata("FULLSCREEN_DIALOG")
defMenu:SetFrameLevel(300)
defMenu:SetClampedToScreen(true)
defMenu:SetSize(DEFAULT_DD_W, 4)
defMenu:SetPoint("TOPLEFT", defDDBtn, "BOTTOMLEFT", 0, -2)
defMenu:Hide()
local defMenuBg = defMenu:CreateTexture(nil, "BACKGROUND")
defMenuBg:SetAllPoints()
defMenuBg:SetColorTexture(0.075, 0.113, 0.141, 0.98)
local dmT = defMenu:CreateTexture(nil, "OVERLAY", nil, 7); dmT:SetColorTexture(1,1,1,0.20)
if dmT.SetSnapToPixelGrid then dmT:SetSnapToPixelGrid(false); dmT:SetTexelSnappingBias(0) end
dmT:SetPoint("TOPLEFT"); dmT:SetPoint("TOPRIGHT"); PP.Height(dmT, 1)
local dmB = defMenu:CreateTexture(nil, "OVERLAY", nil, 7); dmB:SetColorTexture(1,1,1,0.20)
if dmB.SetSnapToPixelGrid then dmB:SetSnapToPixelGrid(false); dmB:SetTexelSnappingBias(0) end
dmB:SetPoint("BOTTOMLEFT"); dmB:SetPoint("BOTTOMRIGHT"); PP.Height(dmB, 1)
local dmL = defMenu:CreateTexture(nil, "OVERLAY", nil, 7); dmL:SetColorTexture(1,1,1,0.20)
if dmL.SetSnapToPixelGrid then dmL:SetSnapToPixelGrid(false); dmL:SetTexelSnappingBias(0) end
dmL:SetPoint("TOPLEFT", dmT, "BOTTOMLEFT"); dmL:SetPoint("BOTTOMLEFT", dmB, "TOPLEFT"); PP.Width(dmL, 1)
local dmR = defMenu:CreateTexture(nil, "OVERLAY", nil, 7); dmR:SetColorTexture(1,1,1,0.20)
if dmR.SetSnapToPixelGrid then dmR:SetSnapToPixelGrid(false); dmR:SetTexelSnappingBias(0) end
dmR:SetPoint("TOPRIGHT", dmT, "BOTTOMRIGHT"); dmR:SetPoint("BOTTOMRIGHT", dmB, "TOPRIGHT"); PP.Width(dmR, 1)
popup._defMenu = defMenu
popup._defMenuItems = {}
defDDBtn:SetScript("OnEnter", function()
defDDBg:SetColorTexture(0.075, 0.113, 0.141, 0.98)
defDDLbl:SetTextColor(1, 1, 1, 0.60)
for _, e in ipairs(popup._defBrdEdges) do e:SetColorTexture(1, 1, 1, 0.30) end
end)
defDDBtn:SetScript("OnLeave", function()
if not defMenu:IsShown() then
defDDBg:SetColorTexture(0.075, 0.113, 0.141, 0.9)
defDDLbl:SetTextColor(1, 1, 1, 0.50)
for _, e in ipairs(popup._defBrdEdges) do e:SetColorTexture(1, 1, 1, 0.20) end
end
end)
defDDBtn:SetScript("OnClick", function()
if defMenu:IsShown() then defMenu:Hide() else
if popup._rebuildDefMenu then popup._rebuildDefMenu() end
defMenu:Show()
end
end)
defDDBtn:HookScript("OnHide", function() defMenu:Hide() end)
defMenu:SetScript("OnShow", function(self)
local btnScale = defDDBtn:GetEffectiveScale()
local uiScale = UIParent:GetEffectiveScale()
self:SetScale(btnScale / uiScale)
self:SetScript("OnUpdate", function(m)
if not defDDBtn:IsMouseOver() and not m:IsMouseOver() then
if IsMouseButtonDown("LeftButton") or IsMouseButtonDown("RightButton") then m:Hide() end
end
end)
end)
defMenu:SetScript("OnHide", function(self)
self:SetScript("OnUpdate", nil)
if defDDBtn:IsMouseOver() then
defDDBg:SetColorTexture(0.075, 0.113, 0.141, 0.98)
defDDLbl:SetTextColor(1, 1, 1, 0.60)
for _, e in ipairs(popup._defBrdEdges) do e:SetColorTexture(1, 1, 1, 0.30) end
else
defDDBg:SetColorTexture(0.075, 0.113, 0.141, 0.9)
defDDLbl:SetTextColor(1, 1, 1, 0.50)
for _, e in ipairs(popup._defBrdEdges) do e:SetColorTexture(1, 1, 1, 0.20) end
end
end)
-- Done button (pixel-perfect via PixelUtil)
local EG = ELLESMERE_GREEN
local closeBtn = CreateFrame("Button", nil, popup)
closeBtn:SetFrameLevel(popup:GetFrameLevel() + 2)
PP.Size(closeBtn, 200, 39)
PP.Point(closeBtn, "BOTTOM", popup, "BOTTOM", 0, 38)
-- Border texture (full size, peeks out as 1px border)
local closeBrd = closeBtn:CreateTexture(nil, "BACKGROUND")
closeBrd:SetAllPoints()
closeBrd:SetColorTexture(EG.r, EG.g, EG.b, 0.9)
PP.DisablePixelSnap(closeBrd)
-- Fill texture (inset 1px on each side)
local closeFill = closeBtn:CreateTexture(nil, "BORDER")
PP.Point(closeFill, "TOPLEFT", closeBtn, "TOPLEFT", 1, -1)
PP.Point(closeFill, "BOTTOMRIGHT", closeBtn, "BOTTOMRIGHT", -1, 1)
closeFill:SetColorTexture(0.06, 0.08, 0.10, 0.92)
PP.DisablePixelSnap(closeFill)
local closeLbl = closeBtn:CreateFontString(nil, "OVERLAY")
closeLbl:SetFont(FONT, 16, "")
closeLbl:SetPoint("CENTER")
closeLbl:SetText("Done")
closeLbl:SetTextColor(EG.r, EG.g, EG.b, 0.9)
closeBtn:SetScript("OnEnter", function()
closeLbl:SetTextColor(EG.r, EG.g, EG.b, 1)
closeBrd:SetColorTexture(EG.r, EG.g, EG.b, 1)
end)
closeBtn:SetScript("OnLeave", function()
closeLbl:SetTextColor(EG.r, EG.g, EG.b, 0.9)
closeBrd:SetColorTexture(EG.r, EG.g, EG.b, 0.9)
end)
popup._closeBtn = closeBtn
-- Popup eats mouse events so clicks on it don't propagate to dimmer
popup:EnableMouse(true)
-- Dimmer click to close (only fires when clicking outside the popup)
dimmer:SetScript("OnMouseDown", function(self)
-- Only close if the click is NOT on the popup
if not popup:IsMouseOver() then
self:Hide()
end
end)
-- Escape to close
popup:EnableKeyboard(true)
popup:SetScript("OnKeyDown", function(self, key)
if key == "ESCAPE" then
self:SetPropagateKeyboardInput(false)
dimmer:Hide()
else
self:SetPropagateKeyboardInput(true)
end
end)
-- Store layout constants for reuse in populate phase
popup._CLASS_H = CLASS_H
popup._CLASS_PAD_TOP = CLASS_PAD_TOP
popup._CLASS_PAD_BOT = CLASS_PAD_BOT
popup._SPEC_H = SPEC_H
popup._COL_W = COL_W
popup._CLASS_GAP = CLASS_GAP
popup._dimmer = dimmer
specPopup = popup
end
-- Update title with preset name
local presetName
if presetKey == "custom" then presetName = "Custom"
elseif presetKey == "ellesmereui" then presetName = "EllesmereUI"
elseif presetKey == "spinthewheel" then presetName = "Spin the Wheel"
elseif presetKey:sub(1, 5) == "user:" then presetName = presetKey:sub(6)
else presetName = presetKey end
specPopup._title:SetText("Assign Preset to Specs")
specPopup._subtitle:SetText("Select which specs you want " .. presetName .. " to be assigned to")
-- Populate columns
local FONT = EllesmereUI._font or ("Interface\\AddOns\\EllesmereUI\\media\\fonts\\Expressway.ttf")
local CLASS_H = specPopup._CLASS_H
local CLASS_PAD_TOP = specPopup._CLASS_PAD_TOP
local CLASS_PAD_BOT = specPopup._CLASS_PAD_BOT
local SPEC_H = specPopup._SPEC_H
local COL_W = specPopup._COL_W
local CLASS_GAP = specPopup._CLASS_GAP
local allCheckboxes = {}
local BOX_SZ = 18
local CHECK_INSET = 3
-- Build lookup: specID → presetKey for specs assigned to OTHER presets
local lockedSpecs = {} -- [specID] = displayName of the preset that owns it
do
local fullMap = db[dbKey]
if fullMap then
for pKey, specList in pairs(fullMap) do
if pKey ~= presetKey and type(specList) == "table" then
for sID in pairs(specList) do
-- Resolve display name
local dName
if pKey == "custom" then dName = "Custom"
elseif pKey == "ellesmereui" then dName = "EllesmereUI"
elseif pKey == "spinthewheel" then dName = "Spin the Wheel"
elseif pKey:sub(1, 5) == "user:" then dName = pKey:sub(6)
else dName = pKey end
lockedSpecs[sID] = dName
end
end
end
end
end
for colIdx = 1, NUM_COLS do
local col = specPopup._columns[colIdx]
-- Hide old rows
for _, row in ipairs(col._rows) do row:Hide() end
local list = COL_LISTS[colIdx]
local rowIdx = 0
local yOff = 0
local isFirstClass = true
for _, classIdx in ipairs(list) do
local cls = SPEC_DATA[classIdx]
-- Add CLASS_GAP between class groups (not before the first)
if not isFirstClass then
yOff = yOff + CLASS_GAP
end
isFirstClass = false
-- Class header
yOff = yOff + CLASS_PAD_TOP
rowIdx = rowIdx + 1
local hdr = col._rows[rowIdx]
if not hdr then
hdr = CreateFrame("Frame", nil, col)
col._rows[rowIdx] = hdr
end
PP.Size(hdr, COL_W, CLASS_H)
hdr:ClearAllPoints()
PP.Point(hdr, "TOPLEFT", col, "TOPLEFT", 0, -yOff)
hdr:Show()
if not hdr._label then
hdr._label = hdr:CreateFontString(nil, "OVERLAY")
hdr._label:SetFont(FONT, 18, "")
PP.Point(hdr._label, "BOTTOMLEFT", hdr, "BOTTOMLEFT", 4, 4)
end
local clr = CLASS_COLOR_MAP[cls.class]
if clr then
hdr._label:SetTextColor(clr.r, clr.g, clr.b, 0.9)
else
hdr._label:SetTextColor(1, 1, 1, 0.7)
end
hdr._label:SetText(cls.name)
yOff = yOff + CLASS_H + CLASS_PAD_BOT
-- Spec checkboxes
for _, spec in ipairs(cls.specs) do
rowIdx = rowIdx + 1
local row = col._rows[rowIdx]
if not row then
row = CreateFrame("Button", nil, col)
col._rows[rowIdx] = row
-- Checkbox box (frame, not texture, so MakeBorder works)
local box = CreateFrame("Frame", nil, row)
PP.Size(box, BOX_SZ, BOX_SZ)
PP.Point(box, "LEFT", row, "LEFT", 8, 0)
box:SetFrameLevel(row:GetFrameLevel() + 1)
-- Box background
local boxBg = box:CreateTexture(nil, "BACKGROUND")
boxBg:SetAllPoints()
boxBg:SetColorTexture(CB_BOX_R, CB_BOX_G, CB_BOX_B, 1)
PP.DisablePixelSnap(boxBg)
row._boxBg = boxBg
-- Box border (uses same pattern as WidgetFactory:Checkbox)
local boxBorder = MakeBorder(box, BORDER_R, BORDER_G, BORDER_B, CB_BRD_A, PP)
row._boxBorder = boxBorder
-- Checkmark: solid teal inner square (inset 3px)
local check = box:CreateTexture(nil, "ARTWORK")
PP.DisablePixelSnap(check)
PP.Point(check, "TOPLEFT", box, "TOPLEFT", CHECK_INSET, -CHECK_INSET)
PP.Point(check, "BOTTOMRIGHT", box, "BOTTOMRIGHT", -CHECK_INSET, CHECK_INSET)
check:SetColorTexture(ELLESMERE_GREEN.r, ELLESMERE_GREEN.g, ELLESMERE_GREEN.b, 1)
row._check = check
row._box = box
-- Label
local lbl = row:CreateFontString(nil, "OVERLAY")
lbl:SetFont(FONT, 17, "")
PP.Point(lbl, "LEFT", box, "RIGHT", 8, 0)
lbl:SetTextColor(1, 1, 1, 0.65)
row._lbl = lbl
end
PP.Size(row, COL_W, SPEC_H)
row:ClearAllPoints()
PP.Point(row, "TOPLEFT", col, "TOPLEFT", 0, -yOff)
row:Show()
row._lbl:SetText(spec.name)
row._specID = spec.id
-- Check if this spec is locked (assigned to another preset)
local lockedBy = lockedSpecs[spec.id]
row._locked = lockedBy ~= nil
-- Set checked state from current assignments
local checked = assignments[spec.id] == true
row._checked = checked
local EG = ELLESMERE_GREEN
local function UpdateVisual(r)
if r._locked then
-- Locked: dimmed checkbox, no checkmark
r._check:Hide()
r._boxBorder:SetColor(BORDER_R, BORDER_G, BORDER_B, CB_BRD_A * 0.4)
r._boxBg:SetColorTexture(CB_BOX_R, CB_BOX_G, CB_BOX_B, 0.35)
r._lbl:SetTextColor(1, 1, 1, 0.25)
elseif r._checked then
r._check:Show()
r._boxBorder:SetColor(EG.r, EG.g, EG.b, CB_ACT_BRD_A)
r._boxBg:SetColorTexture(CB_BOX_R, CB_BOX_G, CB_BOX_B, 1)
r._lbl:SetTextColor(1, 1, 1, 0.65)
else
r._check:Hide()
r._boxBorder:SetColor(BORDER_R, BORDER_G, BORDER_B, CB_BRD_A)
r._boxBg:SetColorTexture(CB_BOX_R, CB_BOX_G, CB_BOX_B, 1)
r._lbl:SetTextColor(1, 1, 1, 0.65)
end
end
UpdateVisual(row)
allCheckboxes[#allCheckboxes + 1] = row
row:SetScript("OnClick", function(self)
if self._locked then return end
self._checked = not self._checked
assignments[spec.id] = self._checked or nil
UpdateVisual(self)
end)
row:SetScript("OnEnter", function(self)
if self._locked then return end
self._lbl:SetTextColor(1, 1, 1, 0.90)
end)
row:SetScript("OnLeave", function(self)
if self._locked then return end
self._lbl:SetTextColor(1, 1, 1, 0.65)
end)
yOff = yOff + SPEC_H
end
end
end
-- Check All / Uncheck All wiring (skip locked specs)
specPopup._checkAll:SetScript("OnClick", function()
local EG2 = ELLESMERE_GREEN
for _, row in ipairs(allCheckboxes) do
if not row._locked then
row._checked = true
assignments[row._specID] = true
row._check:Show()
row._boxBorder:SetColor(EG2.r, EG2.g, EG2.b, CB_ACT_BRD_A)
end
end
end)
specPopup._uncheckAll:SetScript("OnClick", function()
for _, row in ipairs(allCheckboxes) do
if not row._locked then
row._checked = false
assignments[row._specID] = nil
row._check:Hide()
row._boxBorder:SetColor(BORDER_R, BORDER_G, BORDER_B, CB_BRD_A)
end
end
end)
---------------------------------------------------------------
-- Default Profile dropdown (populate phase)
-- Only shown when defaultKey is provided (spec feature enabled)
---------------------------------------------------------------
local selectedDefaultKey = defaultKey and db[defaultKey] or nil
if defaultKey and allPresetKeysFn then
specPopup._defDDContainer:Show()
-- Set initial label
local function DefPresetDisplayName(key)
if not key then return "" end
if key == "custom" then return "Custom" end
if key == "ellesmereui" then return "EllesmereUI" end
if key == "spinthewheel" then return "Spin the Wheel" end
if key:sub(1, 5) == "user:" then return key:sub(6) end
return key
end
if selectedDefaultKey then
specPopup._defDDLbl:SetText(DefPresetDisplayName(selectedDefaultKey))
specPopup._defDDLbl:SetTextColor(1, 1, 1, 0.50)
else
specPopup._defDDLbl:SetText("")
specPopup._defDDLbl:SetTextColor(1, 1, 1, 0.35)
end
-- Rebuild the default dropdown menu items
specPopup._rebuildDefMenu = function()
local items = specPopup._defMenuItems
for _, itm in ipairs(items) do itm:Hide() end
local presetList = allPresetKeysFn()
local mH = 4
local ITEM_FONT = EllesmereUI._font or ("Interface\\AddOns\\EllesmereUI\\media\\fonts\\Expressway.ttf")
for idx, entry in ipairs(presetList) do
local itm = items[idx]
if not itm then
itm = CreateFrame("Button", nil, specPopup._defMenu)
itm:SetHeight(26)
itm:SetFrameLevel(specPopup._defMenu:GetFrameLevel() + 1)
local lbl = itm:CreateFontString(nil, "OVERLAY")
lbl:SetFont(ITEM_FONT, 13, "")
lbl:SetPoint("LEFT", itm, "LEFT", 10, 0)
lbl:SetTextColor(0.55, 0.60, 0.65, 1)
itm._lbl = lbl
local hl = itm:CreateTexture(nil, "ARTWORK")
hl:SetAllPoints()
hl:SetColorTexture(1, 1, 1, 1)
hl:SetAlpha(0)
itm._hl = hl
itm:SetScript("OnEnter", function() lbl:SetTextColor(1, 1, 1, 1); hl:SetAlpha(0.08) end)
itm:SetScript("OnLeave", function()
local isSel = (itm._key == selectedDefaultKey)
lbl:SetTextColor(0.55, 0.60, 0.65, 1)
hl:SetAlpha(isSel and 0.04 or 0)
end)
items[idx] = itm
end
itm:SetPoint("TOPLEFT", specPopup._defMenu, "TOPLEFT", 1, -mH)
itm:SetPoint("TOPRIGHT", specPopup._defMenu, "TOPRIGHT", -1, -mH)
itm._lbl:SetText(entry.name)
itm._key = entry.key
local isSel = (entry.key == selectedDefaultKey)
itm._hl:SetAlpha(isSel and 0.04 or 0)
itm:SetScript("OnClick", function()
selectedDefaultKey = entry.key
specPopup._defDDLbl:SetText(entry.name)
specPopup._defDDLbl:SetTextColor(1, 1, 1, 0.50)
specPopup._defMenu:Hide()
end)
itm:Show()
mH = mH + 26
end
specPopup._defMenu:SetHeight(mH + 4)
end
else
specPopup._defDDContainer:Hide()
end
-- Done button: validate default selection if spec feature is active
specPopup._closeBtn:SetScript("OnClick", function()
-- If default feature is active and no default has been selected, flash error
if defaultKey and allPresetKeysFn and not selectedDefaultKey then
specPopup._flashDefaultDD()
return
end
-- Save the default preset choice
if defaultKey and selectedDefaultKey then
db[defaultKey] = selectedDefaultKey
if onDefaultChanged then onDefaultChanged() end
end
specPopup._dimmer:Hide()
-- Apply the correct preset for the player's current spec immediately
if onDone then onDone() end
end)
specPopup._dimmer:Show()
end
end
-------------------------------------------------------------------------------
-- SPEC AUTO-SWITCH EVENT HANDLER
--
-- Listens for PLAYER_SPECIALIZATION_CHANGED and auto-loads the assigned
-- preset for the current spec. Each registered preset system (by dbPrefix)
-- is checked independently.
-------------------------------------------------------------------------------
do
local specSwitchFrame = CreateFrame("Frame")
specSwitchFrame:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED")
-- Registry: { { dbFunc, dbPrefix, presetKeys, defaults, refreshFn, applySnapshot, applyDefaults } }
EllesmereUI._specSwitchRegistry = EllesmereUI._specSwitchRegistry or {}
function EllesmereUI:RegisterSpecAutoSwitch(cfg)
local entry = {
dbFunc = cfg.dbFunc,
pfx = cfg.dbPrefix or "",
presetKeys = cfg.presetKeys,
defaults = cfg.defaults,
refreshFn = cfg.refreshFn,
}
-- Avoid duplicate registrations for the same prefix
for i, e in ipairs(self._specSwitchRegistry) do
if e.pfx == entry.pfx and e.dbFunc == entry.dbFunc then
self._specSwitchRegistry[i] = entry
return
end
end
self._specSwitchRegistry[#self._specSwitchRegistry + 1] = entry
end
specSwitchFrame:SetScript("OnEvent", function(self, event, unit)
if event ~= "PLAYER_SPECIALIZATION_CHANGED" then return end
if unit ~= "player" then return end
local specID = GetSpecializationInfo(GetSpecialization() or 0)
if not specID then return end
-- Helper: apply a preset key to the DB
local function ApplyPresetKey(entry, db, presetKey)
local K_PRESETS = entry.pfx .. "_presets"
local K_SNAP = entry.pfx .. "_builtinSnapshot"
local K_CUSTOM = entry.pfx .. "_customPreset"
if presetKey == "ellesmereui" then
for _, key in ipairs(entry.presetKeys) do
local def = entry.defaults[key]
if type(def) == "table" and def.r then
db[key] = { r = def.r, g = def.g, b = def.b }
else
db[key] = def
end
end
db[K_SNAP] = nil -- will be re-snapped on UI open
elseif presetKey == "custom" then
if db[K_CUSTOM] then
for _, key in ipairs(entry.presetKeys) do
local v = db[K_CUSTOM][key]
if v ~= nil then
if type(v) == "table" and v.r then
db[key] = { r = v.r, g = v.g, b = v.b }
else
db[key] = v
end
else
db[key] = nil
end
end
end
elseif presetKey == "spinthewheel" then
-- Spin the Wheel is randomized -- just mark it active, snapshot on UI open
db[K_SNAP] = nil
elseif presetKey:sub(1, 5) == "user:" then
local name = presetKey:sub(6)
local snap = db[K_PRESETS] and db[K_PRESETS][name]
if snap then
for _, key in ipairs(entry.presetKeys) do
local v = snap[key]
if v ~= nil then
if type(v) == "table" and v.r then
db[key] = { r = v.r, g = v.g, b = v.b }
else
db[key] = v
end
else
db[key] = nil
end
end
end
end
db[K_SNAP] = nil
end
for _, entry in ipairs(EllesmereUI._specSwitchRegistry) do
local db = entry.dbFunc()
if db then
local K_SPEC_ASSIGN = entry.pfx .. "_specAssignments"
local K_ACTIVE = entry.pfx .. "_activePreset"
local K_SPEC_DEFAULT = entry.pfx .. "_specDefaultPreset"
local specMap = db[K_SPEC_ASSIGN]
-- Check if ANY spec assignments exist at all (to know if this system is active)
local hasAnyAssignment = false
if specMap then
for _, specList in pairs(specMap) do
if next(specList) then hasAnyAssignment = true; break end
end
end
if hasAnyAssignment then
-- Find which preset has this specID assigned
local foundMatch = false
for presetKey, specList in pairs(specMap) do
if specList[specID] then
foundMatch = true
local currentActive = db[K_ACTIVE] or "ellesmereui"
if currentActive ~= presetKey then
db[K_ACTIVE] = presetKey
ApplyPresetKey(entry, db, presetKey)
if entry.refreshFn then entry.refreshFn() end
end
break -- first matching preset wins
end
end
-- No spec-specific assignment found -- fall back to default preset
if not foundMatch and db[K_SPEC_DEFAULT] then
local defaultPreset = db[K_SPEC_DEFAULT]
local currentActive = db[K_ACTIVE] or "ellesmereui"
if currentActive ~= defaultPreset then
db[K_ACTIVE] = defaultPreset
ApplyPresetKey(entry, db, defaultPreset)
if entry.refreshFn then entry.refreshFn() end
end
end
end
-- If no spec assignments exist at all, do nothing (standard behavior)
end
end
-- If the options panel is open, refresh it to reflect the new active preset
if EllesmereUI._mainFrame and EllesmereUI._mainFrame:IsShown() then
EllesmereUI:InvalidatePageCache()
EllesmereUI:RefreshPage(true)
end
end)
end
-------------------------------------------------------------------------------
-- PRESET SYSTEM (shared by all modules)