-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptionsWindow.lua
More file actions
3623 lines (3521 loc) · 170 KB
/
OptionsWindow.lua
File metadata and controls
3623 lines (3521 loc) · 170 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
---Options window UI module for SimpleUnitFrames configuration
---@class OptionsWindow
---Main configuration UI window with tabs, search, and profile management
local AceAddon = LibStub("AceAddon-3.0")
local AceGUI = LibStub("AceGUI-3.0")
local LSM = LibStub("LibSharedMedia-3.0", true)
local addon = AceAddon and AceAddon:GetAddon("SimpleUnitFrames", true)
if not addon then
return
end
local core = addon._core or {}
local defaults = core.defaults or {}
local addonName = core.addonName or "SimpleUnitFrames"
local ICON_PATH = core.ICON_PATH or "Interface\\Icons\\INV_Misc_QuestionMark"
local CopyTableDeep = core.CopyTableDeep
local MergeDefaults = core.MergeDefaults
local UNIT_TYPE_ORDER = core.UNIT_TYPE_ORDER or { "player", "target", "tot", "focus", "pet", "party", "raid", "boss" }
local DEFAULT_UNIT_CASTBAR = core.DEFAULT_UNIT_CASTBAR or {}
local DEFAULT_UNIT_LAYOUT = core.DEFAULT_UNIT_LAYOUT or {}
local DEFAULT_UNIT_MAIN_BARS_BACKGROUND = core.DEFAULT_UNIT_MAIN_BARS_BACKGROUND or {}
local DEFAULT_HEAL_PREDICTION = core.DEFAULT_HEAL_PREDICTION or {}
local ADDON_ID = "SimpleUnitFrames"
local function SafeText(value, fallback)
if value == nil then
return fallback
end
local ok, text = pcall(tostring, value)
if not ok or text == nil then
return fallback
end
return text
end
local function GetAddonVersionText()
local version = nil
if C_AddOns and C_AddOns.GetAddOnMetadata then
version = C_AddOns.GetAddOnMetadata(ADDON_ID, "Version")
elseif GetAddOnMetadata then
version = GetAddOnMetadata(ADDON_ID, "Version")
end
version = tostring(SafeText(version, "") or ""):gsub("^%s+", ""):gsub("%s+$", "")
if version == "" then
return "v?"
end
return "v" .. version
end
local function TrimString(value)
if type(value) ~= "string" then
return ""
end
return (value:gsub("^%s+", ""):gsub("%s+$", ""))
end
if type(CopyTableDeep) ~= "function" then
CopyTableDeep = function(source)
local copy = {}
for key, value in pairs(source or {}) do
copy[key] = (type(value) == "table") and CopyTableDeep(value) or value
end
return copy
end
end
if type(MergeDefaults) ~= "function" then
MergeDefaults = function(target, defaultsTable)
if type(target) ~= "table" or type(defaultsTable) ~= "table" then
return
end
for key, value in pairs(defaultsTable) do
if target[key] == nil then
target[key] = type(value) == "table" and CopyTableDeep(value) or value
elseif type(value) == "table" and type(target[key]) == "table" then
MergeDefaults(target[key], value)
end
end
end
end
---Show the options window (or options v2 if enabled)
---@return void
function addon:ShowOptions()
if self.IsOptionsV2Enabled and self:IsOptionsV2Enabled() and self.ShowOptionsV2 then
self:ShowOptionsV2()
return
end
local UI_STYLE = (self.GetOptionsUIStyle and self:GetOptionsUIStyle()) or {
windowBg = { 0.03, 0.04, 0.05, 0.96 },
windowBorder = { 0.34, 0.29, 0.15, 0.90 },
panelBg = { 0.05, 0.06, 0.07, 0.92 },
panelBorder = { 0.23, 0.21, 0.15, 0.92 },
accent = { 0.96, 0.82, 0.24 },
accentSoft = { 0.72, 0.64, 0.32 },
textMuted = { 0.72, 0.74, 0.78 },
searchBg = { 0.08, 0.09, 0.11, 0.95 },
searchBorder = { 0.34, 0.30, 0.18, 0.96 },
navDefault = { 0.08, 0.08, 0.08, 0.88 },
navDefaultBorder = { 0.18, 0.18, 0.18, 0.95 },
navHover = { 0.12, 0.13, 0.16, 0.92 },
navHoverBorder = { 0.34, 0.31, 0.22, 0.95 },
navSelected = { 0.12, 0.36, 0.58, 0.95 },
navSelectedBorder = { 0.28, 0.60, 0.88, 0.95 },
navSearch = { 0.10, 0.14, 0.10, 0.92 },
navSearchBorder = { 0.20, 0.30, 0.20, 0.92 },
}
local function ClampOptionsHeight(frame)
if not frame then
return
end
local maxHeightCap = math.max(500, math.floor(UIParent:GetHeight() * 0.65))
local minHeight = 500
local height = frame:GetHeight()
local clampedHeight = math.max(minHeight, math.min(height, maxHeightCap))
if clampedHeight ~= height then
frame:SetHeight(clampedHeight)
end
if frame.SetResizeBounds then
frame:SetResizeBounds(940, minHeight, UIParent:GetWidth() - 40, maxHeightCap)
else
if frame.SetMinResize then
frame:SetMinResize(940, minHeight)
end
if frame.SetMaxResize then
frame:SetMaxResize(UIParent:GetWidth() - 40, maxHeightCap)
end
end
end
if self.optionsFrame then
ClampOptionsHeight(self.optionsFrame)
self:PrepareWindowForDisplay(self.optionsFrame)
self.optionsFrame:Show()
self:PlayWindowOpenAnimation(self.optionsFrame)
if self.optionsFrame.BuildTab then
self.optionsFrame:BuildTab(self.optionsFrame.currentTab or "global")
end
return
end
local frame = CreateFrame("Frame", "SUFOptionsWindow", UIParent, "BasicFrameTemplateWithInset")
local maxHeightCap = math.max(500, math.floor(UIParent:GetHeight() * 0.65))
local initialHeight = math.min(620, maxHeightCap)
frame:SetSize(1240, initialHeight)
frame:SetPoint("CENTER")
self:EnableMovableFrame(frame, true, "options_window", { "CENTER", "UIParent", "CENTER", 0, 0 })
frame:SetResizable(true)
if frame.SetResizeBounds then
frame:SetResizeBounds(940, 560, UIParent:GetWidth() - 40, maxHeightCap)
else
if frame.SetMinResize then
frame:SetMinResize(940, 560)
end
if frame.SetMaxResize then
frame:SetMaxResize(UIParent:GetWidth() - 40, maxHeightCap)
end
end
frame:SetClampedToScreen(true)
frame:SetFrameStrata("DIALOG")
frame.TitleText:SetText("SimpleUnitFrames Option")
frame.TitleText:SetFontObject("GameFontNormalLarge")
frame.TitleText:SetTextColor(UI_STYLE.accent[1], UI_STYLE.accent[2], UI_STYLE.accent[3])
self:ApplySUFBackdropColors(frame, UI_STYLE.windowBg, UI_STYLE.windowBorder, true)
local close = frame.CloseButton
if not close then
close = CreateFrame("Button", nil, frame, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -4, -4)
end
close:SetScript("OnClick", function()
self:SetTestMode(false)
frame:Hide()
end)
local okResize, resize = pcall(CreateFrame, "Button", nil, frame, "UIPanelResizeButtonTemplate")
if not okResize or not resize then
resize = CreateFrame("Button", nil, frame)
resize:SetSize(16, 16)
resize:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
resize:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
resize:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
end
resize:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -5, 5)
resize:SetScript("OnMouseDown", function(_, button)
if button == "LeftButton" then
frame:StartSizing("BOTTOMRIGHT")
end
end)
resize:SetScript("OnMouseUp", function(_, button)
if button == "LeftButton" then
frame:StopMovingOrSizing()
end
end)
local tabsHost = CreateFrame("Frame", nil, frame, "InsetFrameTemplate3")
tabsHost:SetPoint("TOPLEFT", frame, "TOPLEFT", 12, -32)
tabsHost:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 12, 14)
tabsHost:SetWidth(240)
self:ApplySUFBackdropColors(tabsHost, UI_STYLE.panelBg, UI_STYLE.panelBorder, true)
tabsHost:Show()
local iconSize = 96
local icon = tabsHost:CreateTexture(nil, "ARTWORK")
icon:SetSize(iconSize, iconSize)
icon:SetPoint("TOP", tabsHost, "TOP", 0, -14)
icon:SetTexture(ICON_PATH)
icon:SetTexCoord(0, 1, 0, 1)
icon:SetVertexColor(1, 1, 1, 1)
local versionLabel = tabsHost:CreateFontString(nil, "OVERLAY", "GameFontNormal")
versionLabel:SetPoint("TOPLEFT", icon, "TOPRIGHT", 8, -4)
versionLabel:SetJustifyH("LEFT")
versionLabel:SetText(GetAddonVersionText())
versionLabel:SetTextColor(UI_STYLE.accent[1], UI_STYLE.accent[2], UI_STYLE.accent[3], 1)
local contentHost = CreateFrame("Frame", nil, frame, "InsetFrameTemplate3")
contentHost:SetPoint("TOPLEFT", tabsHost, "TOPRIGHT", 8, 0)
contentHost:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -12, 14)
self:ApplySUFBackdropColors(contentHost, UI_STYLE.panelBg, UI_STYLE.panelBorder, true)
contentHost:Show()
local searchLabel = contentHost:CreateFontString(nil, "OVERLAY", "GameFontNormal")
searchLabel:SetPoint("TOPLEFT", contentHost, "TOPLEFT", 12, -10)
searchLabel:SetText("Search")
searchLabel:SetTextColor(UI_STYLE.accent[1], UI_STYLE.accent[2], UI_STYLE.accent[3])
local searchBox = CreateFrame("EditBox", nil, contentHost, "InputBoxTemplate")
searchBox:SetAutoFocus(false)
searchBox:SetSize(280, 22)
searchBox:SetPoint("LEFT", searchLabel, "RIGHT", 8, 0)
self:ApplySUFBackdropColors(searchBox, UI_STYLE.searchBg, UI_STYLE.searchBorder, true)
searchBox:SetScript("OnEscapePressed", function(box)
box:ClearFocus()
end)
local searchHint = contentHost:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
searchHint:SetPoint("LEFT", searchBox, "RIGHT", 8, 0)
searchHint:SetText("Alt+Up/Down: navigate Enter: open")
searchHint:SetShown(self.db.profile.optionsUI and self.db.profile.optionsUI.searchKeyboardHints ~= false)
local searchDivider = contentHost:CreateTexture(nil, "BORDER")
searchDivider:SetColorTexture(UI_STYLE.accentSoft[1], UI_STYLE.accentSoft[2], UI_STYLE.accentSoft[3], 0.45)
searchDivider:SetPoint("TOPLEFT", contentHost, "TOPLEFT", 10, -32)
searchDivider:SetPoint("TOPRIGHT", contentHost, "TOPRIGHT", -10, -32)
searchDivider:SetHeight(1)
local scroll = CreateFrame("ScrollFrame", nil, contentHost, "UIPanelScrollFrameTemplate")
scroll:SetPoint("TOPLEFT", contentHost, "TOPLEFT", 8, -34)
scroll:SetPoint("BOTTOMRIGHT", contentHost, "BOTTOMRIGHT", -28, 8)
scroll:Show()
-- Style content scrollbar with theme colors
if scroll.ScrollBar then
local scrollBar = scroll.ScrollBar
if scrollBar.ThumbTexture then
scrollBar.ThumbTexture:SetVertexColor(UI_STYLE.accent[1], UI_STYLE.accent[2], UI_STYLE.accent[3], 0.8)
end
-- ScrollUpButton/ScrollDownButton don't support SetBackdropColor, skip styling
end
local content = CreateFrame("Frame", nil, scroll)
content:SetSize(920, 200)
scroll:SetScrollChild(content)
content:Show()
local tabs = {
{ key = "global", label = "Global" },
{ key = "performance", label = "PerformanceLib" },
{ key = "importexport", label = "Import / Export" },
{ key = "tags", label = "Tags" },
{ key = "player", label = "Player" },
{ key = "target", label = "Target" },
{ key = "tot", label = "TargetOfTarget" },
{ key = "focus", label = "Focus" },
{ key = "pet", label = "Pet" },
{ key = "party", label = "Party" },
{ key = "raid", label = "Raid" },
{ key = "boss", label = "Boss" },
{ key = "credits", label = "Credits" },
}
local sidebarGroups = {
{
key = "grp_general",
label = "General",
items = { "global", "performance", "importexport", "tags", "credits" },
},
{
key = "grp_units",
label = "Units",
items = { "player", "target", "tot", "focus", "pet", "party", "raid", "boss" },
},
}
local tabIndexByKey = {}
for i = 1, #tabs do
tabIndexByKey[tabs[i].key] = tabs[i]
end
local unitTabLookup = {}
for i = 1, #UNIT_TYPE_ORDER do
unitTabLookup[UNIT_TYPE_ORDER[i]] = true
end
local UNIT_SECTION_NAV = (self.GetOptionsUnitSectionNav and self:GetOptionsUnitSectionNav()) or {}
local OPTIONS_SEARCH_SCHEMA_VERSION = 2
local TAB_SEARCH_HINTS = {
global = "global media statusbar font visibility indicators castbar plugins fader party minimap",
performance = "performance perflib profiler analyze profile coalescing eventbus dirty pools preset dashboard",
importexport = "import export wizard profile copy paste validate preview apply",
tags = "tags ouf name level health power format token",
player = "player general bars castbar auras plugins advanced portrait heal prediction",
target = "target general bars castbar auras plugins advanced portrait heal prediction",
tot = "targetoftarget tot general bars castbar auras plugins advanced portrait heal prediction",
focus = "focus general bars castbar auras plugins advanced portrait heal prediction",
pet = "pet general bars castbar auras plugins advanced portrait heal prediction",
party = "party general bars castbar auras plugins advanced fader aurawatch raiddebuffs",
raid = "raid general bars castbar auras plugins advanced fader aurawatch raiddebuffs",
boss = "boss general bars castbar auras plugins advanced portrait heal prediction",
credits = "credits libraries thanks authors uuf performancelib ace3",
}
local OPTIONS_SEARCH_TREE = {
global = {
{ label = "Global", aliases = { "settings", "defaults" }, children = {
{ label = "Media", aliases = { "texture", "font", "statusbar" } },
{ label = "Castbar", aliases = { "cast", "safe zone", "spark", "shield" } },
{ label = "Performance", aliases = { "perflib", "preset", "coalescing", "eventbus" } },
{ label = "Debug", aliases = { "sufdebug", "console", "export logs" } },
}},
},
importexport = {
{ label = "Import / Export", aliases = { "profile", "paste", "copy", "validate", "preview" } },
},
performance = {
{ label = "PerformanceLib", aliases = { "preset", "profile start", "profile stop", "analyze", "dashboard" } },
},
tags = {
{ label = "Tags", aliases = { "ouf tags", "health tags", "power tags", "cast tags" } },
},
player = {
{ label = "General", aliases = { "name", "level", "portrait", "size" } },
{ label = "Bars", aliases = { "health", "power", "absorb", "incoming heals" } },
{ label = "Castbar", aliases = { "spell", "time", "interrupt", "latency" } },
{ label = "Auras", aliases = { "buffs", "debuffs", "icons", "spacing" } },
{ label = "Plugins", aliases = { "fader", "aurawatch", "raiddebuffs" } },
{ label = "Advanced", aliases = { "layout", "anchor", "offset", "profile copy" } },
},
target = {
{ label = "General", aliases = { "name", "level", "portrait", "size" } },
{ label = "Bars", aliases = { "health", "power", "absorb", "incoming heals" } },
{ label = "Castbar", aliases = { "spell", "time", "interrupt", "latency" } },
{ label = "Auras", aliases = { "buffs", "debuffs", "icons", "spacing" } },
{ label = "Plugins", aliases = { "fader", "aurawatch", "raiddebuffs" } },
{ label = "Advanced", aliases = { "layout", "anchor", "offset", "profile copy" } },
},
tot = {
{ label = "General", aliases = { "name", "level", "portrait", "size" } },
{ label = "Bars", aliases = { "health", "power", "absorb", "incoming heals" } },
{ label = "Castbar", aliases = { "spell", "time", "interrupt", "latency" } },
{ label = "Auras", aliases = { "buffs", "debuffs", "icons", "spacing" } },
{ label = "Plugins", aliases = { "fader", "aurawatch", "raiddebuffs", "none" } },
{ label = "Advanced", aliases = { "layout", "anchor", "offset", "profile copy" } },
},
focus = {
{ label = "General", aliases = { "name", "level", "portrait", "size" } },
{ label = "Bars", aliases = { "health", "power", "absorb", "incoming heals" } },
{ label = "Castbar", aliases = { "spell", "time", "interrupt", "latency" } },
{ label = "Auras", aliases = { "buffs", "debuffs", "icons", "spacing" } },
{ label = "Plugins", aliases = { "fader", "aurawatch", "raiddebuffs", "none" } },
{ label = "Advanced", aliases = { "layout", "anchor", "offset", "profile copy" } },
},
pet = {
{ label = "General", aliases = { "name", "level", "portrait", "size" } },
{ label = "Bars", aliases = { "health", "power", "absorb", "incoming heals" } },
{ label = "Castbar", aliases = { "spell", "time", "interrupt", "latency" } },
{ label = "Auras", aliases = { "buffs", "debuffs", "icons", "spacing" } },
{ label = "Plugins", aliases = { "fader", "aurawatch", "raiddebuffs", "none" } },
{ label = "Advanced", aliases = { "layout", "anchor", "offset", "profile copy" } },
},
party = {
{ label = "General", aliases = { "show player", "spacing", "layout" } },
{ label = "Bars", aliases = { "health", "power", "absorb", "incoming heals" } },
{ label = "Castbar", aliases = { "spell", "time", "interrupt", "latency", "not shown" } },
{ label = "Auras", aliases = { "buffs", "debuffs", "icons", "spacing", "heal prediction" } },
{ label = "Plugins", aliases = { "fader", "aurawatch", "raiddebuffs" } },
{ label = "Advanced", aliases = { "visibility", "vehicle", "pet battle" } },
},
raid = {
{ label = "General", aliases = { "group", "layout", "spacing" } },
{ label = "Bars", aliases = { "health", "power", "absorb", "incoming heals" } },
{ label = "Castbar", aliases = { "spell", "time", "interrupt", "latency", "not shown" } },
{ label = "Auras", aliases = { "buffs", "debuffs", "icons", "spacing", "heal prediction" } },
{ label = "Plugins", aliases = { "fader", "aurawatch", "raiddebuffs" } },
{ label = "Advanced", aliases = { "visibility", "vehicle", "pet battle" } },
},
boss = {
{ label = "General", aliases = { "name", "level", "portrait", "size" } },
{ label = "Bars", aliases = { "health", "power", "absorb", "incoming heals" } },
{ label = "Castbar", aliases = { "spell", "time", "interrupt", "latency" } },
{ label = "Auras", aliases = { "buffs", "debuffs", "icons", "spacing" } },
{ label = "Plugins", aliases = { "fader", "aurawatch", "raiddebuffs", "none" } },
{ label = "Advanced", aliases = { "layout", "anchor", "offset", "profile copy" } },
},
credits = {
{ label = "Credits", aliases = { "authors", "libraries", "uuf", "ace3", "oUF", "performancelib" } },
},
}
local function TokenizeSearch(searchText)
local out = {}
local normalized = string.lower(TrimString(SafeText(searchText, "")))
if normalized == "" then
return out
end
for token in normalized:gmatch("[^%s]+") do
if token ~= "" then
out[#out + 1] = token
end
end
return out
end
local function BuildOptionsSearchFingerprint()
local pieces = { tostring(OPTIONS_SEARCH_SCHEMA_VERSION), tostring(#tabs) }
for i = 1, #tabs do
local t = tabs[i]
pieces[#pieces + 1] = tostring(t.key) .. ":" .. tostring(t.label) .. ":" .. tostring(TAB_SEARCH_HINTS[t.key] or "")
end
local function AddTreeNode(node)
if type(node) ~= "table" then
return
end
pieces[#pieces + 1] = tostring(node.label or "")
local aliases = node.aliases or node.values
if type(aliases) == "table" then
for i = 1, #aliases do
pieces[#pieces + 1] = tostring(aliases[i])
end
end
local children = node.children
if type(children) == "table" then
for i = 1, #children do
AddTreeNode(children[i])
end
end
end
for _, nodes in pairs(OPTIONS_SEARCH_TREE) do
if type(nodes) == "table" then
for i = 1, #nodes do
AddTreeNode(nodes[i])
end
end
end
return table.concat(pieces, "|")
end
local function AddOptionsSearchEntry(cache, tabKey, tabLabel, label, keywords, section)
local text = TrimString(SafeText(label, ""))
local words = TrimString(SafeText(keywords, ""))
if text == "" and words == "" then
return
end
local dedupe = string.lower(tostring(tabKey) .. "|" .. text .. "|" .. words .. "|" .. tostring(section or "control"))
if cache.seen[dedupe] then
return
end
cache.seen[dedupe] = true
cache.entriesByTab[tabKey] = cache.entriesByTab[tabKey] or {}
local entry = {
tabKey = tabKey,
tabLabel = tabLabel,
label = text ~= "" and text or tabLabel,
keywords = words,
section = section or "control",
haystack = string.lower(table.concat({ tabLabel, text, words }, " ")),
tabLower = string.lower(tostring(tabLabel or "")),
labelLower = string.lower(tostring(text ~= "" and text or tabLabel)),
keywordsLower = string.lower(tostring(words)),
}
cache.entries[#cache.entries + 1] = entry
cache.entriesByTab[tabKey][#cache.entriesByTab[tabKey] + 1] = entry
end
local function IndexOptionsSearchNodes(cache, tabKey, tabLabel, nodes, trail)
if type(nodes) ~= "table" then
return
end
local baseTrail = trail or tabLabel or tostring(tabKey)
for i = 1, #nodes do
local node = nodes[i]
if type(node) == "table" then
local label = TrimString(SafeText(node.label, ""))
local aliases = {}
local aliasList = node.aliases or node.values
if type(aliasList) == "table" then
for j = 1, #aliasList do
aliases[#aliases + 1] = tostring(aliasList[j])
end
end
local keywords = table.concat(aliases, " ")
local path = baseTrail
if label ~= "" then
path = baseTrail .. " " .. label
end
AddOptionsSearchEntry(cache, tabKey, tabLabel, label, table.concat({ keywords, path }, " "), "schema")
if type(node.children) == "table" then
IndexOptionsSearchNodes(cache, tabKey, tabLabel, node.children, path)
end
end
end
end
local function EnsureOptionsSearchIndex()
local fingerprint = BuildOptionsSearchFingerprint()
local cache = frame.optionsSearchIndex
if cache and cache.fingerprint == fingerprint and cache.schemaVersion == OPTIONS_SEARCH_SCHEMA_VERSION then
return cache
end
cache = {
schemaVersion = OPTIONS_SEARCH_SCHEMA_VERSION,
fingerprint = fingerprint,
entries = {},
entriesByTab = {},
seen = {},
tabLabels = {},
}
for i = 1, #tabs do
local t = tabs[i]
cache.tabLabels[t.key] = t.label or t.key
cache.entriesByTab[t.key] = cache.entriesByTab[t.key] or {}
local label = tostring(t.label or t.key)
local keywords = tostring(TAB_SEARCH_HINTS[t.key] or "")
AddOptionsSearchEntry(cache, t.key, label, label, keywords, "tab")
IndexOptionsSearchNodes(cache, t.key, label, OPTIONS_SEARCH_TREE[t.key], label)
end
frame.optionsSearchIndex = cache
return cache
end
local function RegisterOptionsSearchEntry(tabKey, label, keywords, section)
if not tabKey then
return
end
local cache = EnsureOptionsSearchIndex()
local tabLabel = cache.tabLabels[tabKey] or tostring(tabKey)
AddOptionsSearchEntry(cache, tabKey, tabLabel, label, keywords, section or "control")
end
local function ScoreSearchEntry(entry, normalizedSearch, tokens)
if not entry or not entry.haystack then
return 0
end
if #tokens == 0 then
return 0
end
local score = 0
for i = 1, #tokens do
local token = tokens[i]
local tokenScore = 0
local startPos = 1
local tokenMatched = false
while true do
local s, e = entry.haystack:find(token, startPos, true)
if not s then
break
end
tokenMatched = true
tokenScore = tokenScore + ((s <= #(entry.tabLabel or "")) and 3 or 1)
startPos = e + 1
end
if not tokenMatched then
return 0
end
if entry.labelLower == token then
tokenScore = tokenScore + 10
elseif entry.labelLower:find(token, 1, true) == 1 then
tokenScore = tokenScore + 6
elseif entry.keywordsLower:find(token, 1, true) == 1 then
tokenScore = tokenScore + 3
elseif entry.tabLower:find(token, 1, true) == 1 then
tokenScore = tokenScore + 4
end
score = score + tokenScore
end
if string.lower(entry.label or "") == normalizedSearch then
score = score + 6
end
return score
end
local function QueryOptionsSearch(searchText)
local normalized = string.lower(TrimString(SafeText(searchText, "")))
if normalized == "" then
return {}
end
local cache = EnsureOptionsSearchIndex()
local tokens = TokenizeSearch(normalized)
local grouped = {}
for i = 1, #cache.entries do
local entry = cache.entries[i]
local score = ScoreSearchEntry(entry, normalized, tokens)
if score > 0 then
local group = grouped[entry.tabKey]
if not group then
group = {
tabKey = entry.tabKey,
tabLabel = entry.tabLabel,
score = 0,
hits = {},
}
grouped[entry.tabKey] = group
end
group.score = math.max(group.score, score)
group.hits[#group.hits + 1] = { label = entry.label, section = entry.section, score = score }
end
end
local out = {}
for _, group in pairs(grouped) do
table.sort(group.hits, function(a, b)
if a.score == b.score then
return tostring(a.label) < tostring(b.label)
end
return a.score > b.score
end)
out[#out + 1] = group
end
table.sort(out, function(a, b)
if a.score == b.score then
return tostring(a.tabLabel) < tostring(b.tabLabel)
end
return a.score > b.score
end)
return out
end
local function DoesTabMatchSearch(tabKey, searchText)
local normalized = string.lower(TrimString(SafeText(searchText, "")))
if normalized == "" then
return true
end
local groups = QueryOptionsSearch(normalized)
for i = 1, #groups do
if groups[i].tabKey == tabKey then
return true
end
end
return false
end
local tabButtons = {}
local function StopPerformanceSnapshotTicker()
if frame and frame.performanceSnapshotTicker then
frame.performanceSnapshotTicker:Cancel()
frame.performanceSnapshotTicker = nil
end
if frame then
frame.performanceSnapshotText = nil
frame.performanceSnapshotPage = nil
frame.performanceBuildSnapshotText = nil
end
end
local function ClearContent()
for _, child in ipairs({ content:GetChildren() }) do
child:Hide()
child:SetParent(nil)
end
end
local function NewBuilder(page, tabKey)
local builder = {
addon = self,
page = page,
y = -16,
width = math.max(760, contentHost:GetWidth() - 52),
colGap = 24,
col = 1,
rowHeight = 0,
search = "",
searchLower = "",
}
builder.colWidth = math.max(280, math.floor((builder.width - builder.colGap) / 2))
function builder:SetSearch(searchText)
self.search = TrimString(SafeText(searchText, ""))
self.searchLower = string.lower(self.search or "")
end
function builder:HasSearch()
return self.searchLower ~= ""
end
function builder:Matches(label, keywords)
if not self:HasSearch() then
return true
end
local haystack = tostring(label or "")
if keywords then
haystack = haystack .. " " .. tostring(keywords)
end
haystack = string.lower(haystack)
return haystack:find(self.searchLower, 1, true) ~= nil
end
function builder:BeginNewLine()
if self.col == 2 then
self.col = 1
self.y = self.y - self.rowHeight
self.rowHeight = 0
end
end
function builder:Reserve(height, span)
if span then
self:BeginNewLine()
local x, y = 12, self.y
self.y = self.y - height
return x, y, self.width
end
local x = 12 + ((self.col - 1) * (self.colWidth + self.colGap))
local y = self.y
self.rowHeight = math.max(self.rowHeight, height)
if self.col == 1 then
self.col = 2
else
self.col = 1
self.y = self.y - self.rowHeight
self.rowHeight = 0
end
return x, y, self.colWidth
end
function builder:Label(text, large)
RegisterOptionsSearchEntry(tabKey, text, "label section group heading", "label")
if not self:Matches(text, "label section group heading") then
return
end
self:BeginNewLine()
if not large and self.y < -24 then
local divider = self.page:CreateTexture(nil, "BORDER")
divider:SetColorTexture(UI_STYLE.accentSoft[1], UI_STYLE.accentSoft[2], UI_STYLE.accentSoft[3], 0.25)
divider:SetPoint("TOPLEFT", self.page, "TOPLEFT", 12, self.y + 6)
divider:SetSize(self.width, 1)
end
local fs = self.page:CreateFontString(nil, "OVERLAY", large and "GameFontNormalLarge" or "GameFontNormal")
fs:SetPoint("TOPLEFT", self.page, "TOPLEFT", 12, self.y)
fs:SetText(text)
if self:HasSearch() then
fs:SetTextColor(UI_STYLE.accent[1], UI_STYLE.accent[2], UI_STYLE.accent[3])
elseif large then
fs:SetTextColor(UI_STYLE.accent[1], UI_STYLE.accent[2], UI_STYLE.accent[3])
else
fs:SetTextColor(UI_STYLE.textMuted[1], UI_STYLE.textMuted[2], UI_STYLE.textMuted[3])
end
self.y = self.y - (large and 26 or 18)
end
function builder:Edit(label, getter, setter, disabled)
RegisterOptionsSearchEntry(tabKey, label, "edit text input tag", "edit")
if not self:Matches(label, "edit text input tag") then
return
end
local x, y, width = self:Reserve(56, false)
local fs = self.page:CreateFontString(nil, "OVERLAY", "GameFontNormal")
fs:SetPoint("TOPLEFT", self.page, "TOPLEFT", x, y)
fs:SetText(label)
if self:HasSearch() then
fs:SetTextColor(UI_STYLE.accent[1], UI_STYLE.accent[2], UI_STYLE.accent[3])
else
fs:SetTextColor(UI_STYLE.textMuted[1], UI_STYLE.textMuted[2], UI_STYLE.textMuted[3])
end
local eb = CreateFrame("EditBox", nil, self.page, "InputBoxTemplate")
eb:SetAutoFocus(false)
eb:SetSize(width, 22)
eb:SetPoint("TOPLEFT", self.page, "TOPLEFT", x, y - 20)
eb:SetText(tostring(getter() or ""))
eb:SetEnabled(not disabled)
eb:SetScript("OnEnterPressed", function(w)
if disabled then
w:ClearFocus()
return
end
setter(w:GetText())
w:ClearFocus()
end)
eb:SetScript("OnEscapePressed", function(w)
w:ClearFocus()
end)
end
function builder:Slider(label, minv, maxv, step, getter, setter, disabled)
RegisterOptionsSearchEntry(tabKey, label, "slider value size width height opacity alpha spacing gap offset", "slider")
if not self:Matches(label, "slider value size width height opacity alpha spacing gap offset") then
return
end
addon._optSliderId = (addon._optSliderId or 0) + 1
local name = "SUF_OptSlider_" .. tabKey .. "_" .. addon._optSliderId
local x, y, width = self:Reserve(48, false)
local s = CreateFrame("Slider", name, self.page, "OptionsSliderTemplate")
s:SetPoint("TOPLEFT", self.page, "TOPLEFT", x, y)
s:SetWidth(width)
s:SetMinMaxValues(minv, maxv)
s:SetValueStep(step)
s:SetObeyStepOnDrag(true)
s:SetValue(type(getter()) == "number" and getter() or minv)
local text = _G[name .. "Text"]
local low = _G[name .. "Low"]
local high = _G[name .. "High"]
if text then
text:SetText(label)
if self:HasSearch() then
text:SetTextColor(UI_STYLE.accent[1], UI_STYLE.accent[2], UI_STYLE.accent[3])
else
text:SetTextColor(UI_STYLE.textMuted[1], UI_STYLE.textMuted[2], UI_STYLE.textMuted[3])
end
end
if low then low:SetText(tostring(minv)) end
if high then high:SetText(tostring(maxv)) end
if disabled then
if s.EnableMouse then
s:EnableMouse(false)
end
if s.SetEnabled then
s:SetEnabled(false)
end
end
s:SetScript("OnValueChanged", function(_, v)
if disabled then
return
end
setter(v)
end)
end
function builder:Check(label, getter, setter, disabled)
RegisterOptionsSearchEntry(tabKey, label, "checkbox toggle enable disable show hide", "check")
if not self:Matches(label, "checkbox toggle enable disable show hide") then
return
end
local x, y = self:Reserve(28, false)
local c = CreateFrame("CheckButton", nil, self.page, "UICheckButtonTemplate")
c:SetPoint("TOPLEFT", self.page, "TOPLEFT", x - 2, y)
if c.Text then
c.Text:SetText(label)
if self:HasSearch() then
c.Text:SetTextColor(UI_STYLE.accent[1], UI_STYLE.accent[2], UI_STYLE.accent[3])
else
c.Text:SetTextColor(UI_STYLE.textMuted[1], UI_STYLE.textMuted[2], UI_STYLE.textMuted[3])
end
end
c:SetChecked(getter() and true or false)
c:SetEnabled(not disabled)
c:SetScript("OnClick", function(w)
setter(w:GetChecked() and true or false)
end)
end
function builder:Button(label, onClick, span, disabled)
RegisterOptionsSearchEntry(tabKey, label, "button apply validate copy reset import export add remove clear", "button")
if not self:Matches(label, "button apply validate copy reset import export add remove clear") then
return nil
end
local height = 36
local x, y, width = self:Reserve(height, span == true)
local b = CreateFrame("Button", nil, self.page, "UIPanelButtonTemplate")
b:SetPoint("TOPLEFT", self.page, "TOPLEFT", x, y - 2)
b:SetSize(span and math.max(160, width) or math.max(120, width), 24)
b:SetText(label or "Button")
b:SetNormalFontObject("GameFontHighlight")
b:SetHighlightFontObject("GameFontNormal")
b:SetEnabled(not disabled)
b:SetScript("OnClick", function()
if disabled then
return
end
if type(onClick) == "function" then
onClick()
end
end)
return b
end
function builder:Dropdown(label, options, getter, setter, disabled)
RegisterOptionsSearchEntry(tabKey, label, "dropdown select profile preset mode texture font anchor", "dropdown")
if not self:Matches(label, "dropdown select profile preset mode texture font anchor") then
return
end
local x, y, width = self:Reserve(58, false)
local fs = self.page:CreateFontString(nil, "OVERLAY", "GameFontNormal")
fs:SetPoint("TOPLEFT", self.page, "TOPLEFT", x, y)
fs:SetText(label)
if self:HasSearch() then
fs:SetTextColor(UI_STYLE.accent[1], UI_STYLE.accent[2], UI_STYLE.accent[3])
else
fs:SetTextColor(UI_STYLE.textMuted[1], UI_STYLE.textMuted[2], UI_STYLE.textMuted[3])
end
local button = CreateFrame("Button", nil, self.page, "BackdropTemplate")
button:SetPoint("TOPLEFT", self.page, "TOPLEFT", x, y - 20)
button:SetSize(math.max(180, width), 22)
button:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1,
})
addon:ApplySUFBackdropColors(button, UI_STYLE.searchBg, UI_STYLE.searchBorder, false)
local valueText = button:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
valueText:SetPoint("LEFT", button, "LEFT", 8, 0)
valueText:SetPoint("RIGHT", button, "RIGHT", -22, 0)
valueText:SetJustifyH("LEFT")
button.__sufValueText = valueText
local arrow = button:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
arrow:SetPoint("RIGHT", button, "RIGHT", -8, 0)
arrow:SetText("|cFFB7BDC7▼|r")
button.__sufOpenState = arrow
local function RefreshText()
local current = getter and getter() or nil
local selectedText = current ~= nil and tostring(current) or "-"
for i = 1, #(options or {}) do
local item = options[i]
if item.value == current then
selectedText = tostring(item.text or item.value or "-")
break
end
end
valueText:SetText(selectedText)
end
RefreshText()
if disabled and button.EnableMouse then
button:EnableMouse(false)
end
button:SetScript("OnClick", function(widget)
if disabled then
return
end
if addon._simpleDropdown and addon._simpleDropdown:IsShown() and addon._simpleDropdown.ownerButton == widget then
addon._simpleDropdown:Hide()
return
end
arrow:SetText("|cFFFFD15C▲|r")
addon:ShowSimpleDropdown(widget, options, getter, function(v)
if setter then
setter(v)
end
RefreshText()
end, math.max(180, width))
end)
end
function builder:Color(label, getter, setter, disabled)
RegisterOptionsSearchEntry(tabKey, label, "color picker red green blue", "color")
if not self:Matches(label, "color picker red green blue") then
return
end
local x, y, width = self:Reserve(38, false)
local button = CreateFrame("Button", nil, self.page, "UIPanelButtonTemplate")
button:SetSize(40, 20)
button:SetPoint("TOPLEFT", self.page, "TOPLEFT", x, y - 2)
button:SetText("")
button:SetEnabled(not disabled)
local swatch = button:CreateTexture(nil, "ARTWORK")
swatch:SetPoint("TOPLEFT", button, "TOPLEFT", 4, -4)
swatch:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", -4, 4)
swatch:SetColorTexture(1, 1, 1, 1)
local fs = self.page:CreateFontString(nil, "OVERLAY", "GameFontNormal")
fs:SetPoint("LEFT", button, "RIGHT", 8, 0)
fs:SetWidth(math.max(120, width - 52))
fs:SetJustifyH("LEFT")
fs:SetText(label)
if self:HasSearch() then
fs:SetTextColor(UI_STYLE.accent[1], UI_STYLE.accent[2], UI_STYLE.accent[3])
else
fs:SetTextColor(UI_STYLE.textMuted[1], UI_STYLE.textMuted[2], UI_STYLE.textMuted[3])
end
local function RefreshSwatch()
local c = getter and getter() or nil
local r = c and c[1] or 1
local g = c and c[2] or 1
local b = c and c[3] or 1
swatch:SetColorTexture(r, g, b, 1)
end
local function OpenColorPicker()
if disabled then
return
end
local c = getter and getter() or { 1, 1, 1 }
local r = c[1] or 1
local g = c[2] or 1
local b = c[3] or 1
if ColorPickerFrame and ColorPickerFrame.SetupColorPickerAndShow then
local previous = { r = r, g = g, b = b }
local info = {
r = r,
g = g,
b = b,
hasOpacity = false,
swatchFunc = function()
local nr, ng, nb = ColorPickerFrame:GetColorRGB()
setter(nr, ng, nb)
RefreshSwatch()
end,
cancelFunc = function()
setter(previous.r, previous.g, previous.b)
RefreshSwatch()