Repository navigation
Expand file tree
/
Copy pathConfig.lua
More file actions
4278 lines (4071 loc) · 189 KB
/
Copy pathConfig.lua
File metadata and controls
4278 lines (4071 loc) · 189 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
-- BuffRadar - settings window, controls and keyboard navigation.
-- Copyright (C) 2026 Malikor. GPLv3 or later.
local _, ns = ...
local X = ns.X
local core = X.Core
X.cfgReg = {}
local db -- the live settings table; read fresh at each entry point (X.GetDB)
local L = X.L
local Print, Refresh, PlayAlert = X.Print, X.Refresh, core.PlayAlert
local ApplyAppearance, ApplyGeometry = X.ApplyAppearance, X.ApplyGeometry
local BuildBuffList, InvalidateRows, UpdateCounter = core.BuildBuffList, X.InvalidateRows, X.UpdateCounter
local IsOn = core.IsOn
local KeybindText, OpenKeybinds, MakeMacro = core.KeybindText, core.OpenKeybinds, core.MakeMacro
local RefreshMinimapButton = X.RefreshMinimapButton
local myBuffs = core.Buffs
local Ignore = X.Ignore
local DEFAULTS = X.Settings.Defaults
local SCALE_PRESETS = { 0.5, 0.75, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2 }
local CLASSIC_FEATURES = X.classic
local NEXT_BINDING = core.NextBinding
local pairs, ipairs, type, tonumber, tostring, pcall = pairs, ipairs, type, tonumber, tostring, pcall
local math_floor, math_min = math.floor, math.min
local table_sort = table.sort
local wipe = wipe or function(t) for k in pairs(t) do t[k] = nil end return t end
local OpenConfig, RefreshConfig -- assigned in the block below, published on X after it
do
local cfg
local CONFIG_WIDTH, CONFIG_HEIGHT = 600, 610
local NATIVE_TAB_DEPTH = 30 -- 32-unit native tabs start 2 units above the bottom edge
local K = {} -- keyboard navigation and speech are opt-in for this settings session
local navigationHelp = L["Tab or Shift-Tab moves. Enter or Space selects. Arrows adjust. F1 toggles speech. Escape exits."]
function K.Register(widget, panel, label, role, value, adjust)
if not cfg then return end
local entry = { widget = widget, panel = panel, label = label, role = role, value = value, adjust = adjust }
widget.navigation = entry
entry.order = #cfg.navControls + 1
cfg.navControls[entry.order] = entry
widget:HookScript("OnMouseDown", function()
if K.active then K.Stop() end
end)
return entry
end
function K.Available(entry)
if not entry or not entry.widget:IsVisible() then return false end
local role = entry.role
return role == "tab" or not entry.widget.IsEnabled or entry.widget:IsEnabled()
end
function K.Modal()
if cfg.themePriorityPanel and cfg.themePriorityPanel:IsVisible() then return cfg.themePriorityPanel end
local assignments = cfg.assignmentPanel
local preview = assignments and assignments.preview
local blockers = preview and preview.blockers
return assignments and assignments:IsShown()
and (assignments.subgroup and assignments.subgroup:IsVisible() and assignments.subgroup
or assignments.coordination and assignments.coordination:IsVisible() and assignments.coordination
or assignments.preparation and assignments.preparation:IsVisible() and assignments.preparation
or assignments.coverage and assignments.coverage:IsVisible() and assignments.coverage
or assignments.practice and assignments.practice:IsVisible()
and (assignments.practice.review and assignments.practice.review:IsVisible() and assignments.practice.review or assignments.practice)
or blockers and blockers.review and blockers.review:IsVisible() and blockers.review
or assignments.picker:IsShown() and assignments.picker
or preview and preview:IsShown()
and (preview.roleEditor and preview.roleEditor:IsShown() and preview.roleEditor
or blockers and blockers:IsShown() and (blockers.exceptionEditor
and blockers.exceptionEditor:IsShown() and blockers.exceptionEditor or blockers) or preview)
or assignments)
or cfg.blessingPanel and cfg.blessingPanel:IsShown() and cfg.blessingPanel
or cfg.displayPanel and cfg.displayPanel:IsShown() and cfg.displayPanel
end
function K.InScope(entry)
if not K.Available(entry) then return false end
local modal = K.Modal()
return entry.panel == (modal or cfg.panels[cfg.curTab]) or (not modal and entry.panel == cfg)
end
function K.Controls()
local modal = K.Modal()
local panel = modal or cfg.panels[cfg.curTab]
local entries, controls = {}, {}
for _, entry in ipairs(cfg.navControls) do
if K.Available(entry) then
if entry.panel == panel then
controls[#controls + 1] = entry
elseif not modal and entry.role == "tab" then
entries[#entries + 1] = entry
end
end
end
-- Main tabs first, then the visible controls in row order.
table_sort(controls, function(a, b)
local y1, y2 = math_floor((a.widget:GetTop() or 0) / 8), math_floor((b.widget:GetTop() or 0) / 8)
if y1 ~= y2 then return y1 > y2 end
local x1, x2 = a.widget:GetLeft() or 0, b.widget:GetLeft() or 0
if x1 ~= x2 then return x1 < x2 end
return a.order < b.order
end)
for _, entry in ipairs(controls) do entries[#entries + 1] = entry end
if not modal then
for _, widget in ipairs({ cfg.searchToggle, cfg.searchBox, cfg.closeButton }) do
if K.Available(widget.navigation) then entries[#entries + 1] = widget.navigation end
end
end
return entries
end
function K.Speak(text)
K.sequence = (K.sequence or 0) + 1
if not K.narrate then return end
local sequence = K.sequence
local function speak()
if K.sequence ~= sequence or not K.active then return end
-- Blizzard's Windows TTS accepts XML. Speak only plain setting labels and values.
text = text:gsub("|c%x%x%x%x%x%x%x%x", ""):gsub("|r", ""):gsub("[<>&|%c]", " ")
local ok, available = pcall(function()
local voice = TextToSpeech_GetSelectedVoice(Enum.TtsVoiceType.Standard)
if voice then
C_VoiceChat.SpeakText(voice.voiceID, text, C_TTSSettings.GetSpeechRate(), C_TTSSettings.GetSpeechVolume(), false)
return true
end
end)
if not ok or not available then
K.narrate = false
Print(L["Settings narration is unavailable. Check the game's Text to Speech settings."])
end
end
if C_Timer and C_Timer.After then C_Timer.After(0.18, speak) else speak() end
end
function K.Focus(entry)
K.current = entry
if not entry then
cfg.navOutline:Hide()
cfg.navStatus:SetText("")
K.sequence = (K.sequence or 0) + 1
return
end
local widget = entry.widget
local label = entry.label
if type(label) == "function" then label = label() end
if type(label) ~= "string" or label == "" then label = L["Setting"] end
local value = entry.value and entry.value()
if entry.role == "check" then value = widget:GetChecked() and L["Checked"] or L["Not checked"]
elseif entry.role == "tab" and entry.key == cfg.curTab then value = L["Selected tab"]
elseif entry.role == "tab" then value = L["Tab"]
elseif entry.role == "edit" then value = value or L["Edit field"]
elseif entry.role == "button" then value = value or L["Button"] end
local text = value and (label .. ", " .. value) or label
cfg.navStatus:SetText(text)
local border = cfg.navOutline
border:ClearAllPoints()
border:SetPoint("TOPLEFT", widget, "TOPLEFT", -2, 2)
if entry.role == "check" then
border:SetPoint("BOTTOMRIGHT", widget.label, "BOTTOMRIGHT", 2, -2)
else
border:SetPoint("BOTTOMRIGHT", widget, "BOTTOMRIGHT", 2, -2)
end
border:Show()
K.Speak(text)
end
function K.Move(delta)
local entries = K.Controls()
if #entries == 0 then K.Focus(nil); return end
local at = delta > 0 and 0 or 1
for i, entry in ipairs(entries) do
if entry == K.current then at = i; break end
end
K.Focus(entries[(at - 1 + delta) % #entries + 1])
end
function K.Stop(cancel)
if not K.active then return end
local edit = K.edit
K.active, K.narrate, K.current, K.edit, K.transition = nil, nil, nil, nil, nil
K.sequence = (K.sequence or 0) + 1
if edit and edit:HasFocus() then
local escape = cancel and edit:GetScript("OnEscapePressed")
if escape then escape(edit) else edit:ClearFocus() end
end
cfg.navInput:ClearFocus()
cfg.navInput:Hide()
cfg.navOutline:Hide()
cfg.navStatus:Hide()
cfg.navButton:SetText(L["Keyboard Navigation"])
end
function K.Edit(box)
K.edit, K.transition = box, true
cfg.navStatus:Hide()
cfg.navInput:ClearFocus()
box:SetFocus()
K.transition = nil
if not box:HasFocus() then K.Stop() end
end
function K.RegisterEdit(box, panel, label, value)
K.Register(box, panel, label, "edit", value)
box:HookScript("OnEditFocusLost", function(self)
if K.edit == self and not K.transition then K.Stop() end
end)
for _, event in ipairs({ "OnEnterPressed", "OnEscapePressed", "OnTabPressed" }) do
local original = box:GetScript(event)
box:SetScript(event, function(self)
if K.edit ~= self then
if original then original(self) end
return
end
K.transition = true
if original then original(self) end
if self:HasFocus() then self:ClearFocus() end
if not K.active then return end
K.edit = nil
cfg.navInput:SetFocus()
K.transition = nil
if not cfg.navInput:HasFocus() then K.Stop(); return end
if not cfg.searchFooter:IsShown() then cfg.navStatus:Show() end
if event == "OnTabPressed" or not K.InScope(K.current) then
K.Move(IsShiftKeyDown() and -1 or 1)
else
K.Focus(K.current)
end
end)
end
end
function K.Act(delta)
local entry = K.current
if not K.InScope(entry) then K.Move(1); return end
local widget = entry.widget
if delta and entry.adjust then
entry.adjust(delta)
elseif delta then
return
elseif entry.role == "edit" then
K.Edit(widget)
return
elseif entry.adjust then
if entry.role ~= "slider" then entry.adjust(1) end
elseif entry.role == "tab" and entry.key == cfg.curTab then
return
elseif entry.role == "check" then
widget:SetChecked(not widget:GetChecked())
widget:GetScript("OnClick")(widget)
else
widget:Click()
end
if K.active and not K.edit and not cfg.navInput:HasFocus() then K.Stop(); return end
if K.active and not K.edit then
if not K.InScope(K.current) then K.Move(1)
elseif K.current == entry then K.Focus(entry) end
end
end
function K.Start(narrate)
if X.PlayerSuspended() or InCombatLockdown() then
Print(L["Settings keyboard navigation is unavailable in combat or while dead."])
return
end
if K.active then K.Stop() end
K.active, K.narrate = true, narrate
cfg.navButton:SetText(L["Exit Navigation"])
cfg.navInput:Show()
-- Leave a visible search query and result count intact when taking focus.
if cfg.searchBox:HasFocus() then cfg.searchBox:ClearFocus() end
cfg.navInput:SetFocus()
if not cfg.navInput:HasFocus() then K.Stop(); return end
if not cfg.searchFooter:IsShown() then cfg.navStatus:Show() end
Print(navigationHelp)
K.Move(1)
end
function K.Build()
local button = X.PanelWidget("Button", nil, cfg, "UIPanelButtonTemplate")
button:SetSize(166, 22)
button:SetPoint("BOTTOMRIGHT", cfg, "BOTTOMRIGHT", -16, 9)
button:SetText(L["Keyboard Navigation"])
button:SetScript("OnClick", function()
if K.active then K.Stop() else K.Start(false) end
end)
cfg.navButton = button
local status = cfg:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
status:SetPoint("BOTTOMLEFT", cfg, "BOTTOMLEFT", 16, 12)
status:SetPoint("RIGHT", button, "LEFT", -10, 0)
status:SetJustifyH("LEFT")
status:SetWordWrap(false)
status:Hide()
cfg.navStatus = status
local border = X.PanelWidget("Frame", nil, cfg, BackdropTemplateMixin and "BackdropTemplate" or nil)
if border.SetBackdrop then
border:SetBackdrop({ edgeFile = "Interface\\Buttons\\WHITE8X8", edgeSize = 2 })
border:SetBackdropBorderColor(1, 0.82, 0.24, 1)
end
border:SetFrameLevel(cfg:GetFrameLevel() + 20)
border:Hide()
cfg.navOutline = border
local input = CreateFrame("EditBox", nil, cfg)
input:SetSize(1, 1)
input:SetPoint("CENTER", button)
input:SetAlpha(0)
input:EnableMouse(false)
input:SetFontObject("GameFontHighlightSmall")
input:SetAutoFocus(false)
input:SetAltArrowKeyMode(false)
input:SetMaxLetters(1)
input:SetScript("OnChar", function(self) self:SetText("") end)
input:SetScript("OnEditFocusLost", function() if not K.transition then K.Stop() end end)
input:SetScript("OnTabPressed", function() K.Move(IsShiftKeyDown() and -1 or 1) end)
input:SetScript("OnEnterPressed", function() K.Act() end)
input:SetScript("OnSpacePressed", function() K.Act() end)
input:SetScript("OnEscapePressed", function()
local picker = cfg.assignmentPanel and cfg.assignmentPanel.picker
local modal = K.Modal()
if cfg.themePriorityPanel and modal == cfg.themePriorityPanel then modal.closeButton:Click()
elseif picker and modal == picker then picker.closeButton:Click()
else K.Stop() end
end)
input:SetScript("OnArrowPressed", function(_, key)
if key == "LEFT" or key == "DOWN" then K.Act(-1)
elseif key == "RIGHT" or key == "UP" then K.Act(1) end
end)
input:SetScript("OnKeyDown", function(_, key)
if key == "F1" then
K.narrate = not K.narrate
Print(K.narrate and L["Settings narration on"] or L["Settings narration off"])
K.Focus(K.current)
end
end)
input:Hide()
cfg.navInput = input
end
local function ApplyConfigScale()
local scale = db.cfgScale or 1
local width, height = UIParent:GetSize()
if width and height and width > 12 and height > 12 then
-- Reserve room below a centered window for the tabs drawn outside it.
local tabDepth = cfg.nativeTabs and NATIVE_TAB_DEPTH or 0
scale = math_min(scale, (width - 12) / CONFIG_WIDTH, (height - 12) / (CONFIG_HEIGHT + 2 * tabDepth))
end
if cfg:GetScale() ~= scale then cfg:SetScale(scale) end
end
local function SearchKey(label)
return (label:gsub("|c%x%x%x%x%x%x%x%x", ""):gsub("|r", "")):lower()
end
local function RegisterSearch(widget, panel, label)
local entry = { w = widget, panel = panel, keys = SearchKey(label) }
X.cfgReg[#X.cfgReg + 1] = entry
return entry
end
local function MakeCheck(parent, label, getter, setter)
local cb = CreateFrame("CheckButton", nil, parent)
cb:SetSize(24, 24)
cb:SetNormalTexture("Interface\\Buttons\\UI-CheckBox-Up")
cb:SetPushedTexture("Interface\\Buttons\\UI-CheckBox-Down")
cb:SetHighlightTexture("Interface\\Buttons\\UI-CheckBox-Highlight", "ADD")
cb:SetCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check")
cb.label = cb:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
cb.label:SetPoint("LEFT", cb, "RIGHT", 4, 1)
cb.label:SetText(label)
cb.FitLabel = function(self) -- the label is part of the click target, not just the box
local w = self.label:GetStringWidth()
if self.label.maxWidth then w = math_min(w, self.label.maxWidth) end
local height = self.label.maxWidth and self.label:GetStringHeight() or 24
local extra = math.max(0, (height - 24) / 2)
self:SetHitRectInsets(0, -(w + 4), -extra, -extra)
end
cb:FitLabel()
cb:SetScript("OnClick", function(self) setter(self:GetChecked() and true or false) end)
cb.Update = function(self) self:SetChecked(getter() and true or false) end
K.Register(cb, parent, function() return cb.label:GetText() end, "check")
if label and label ~= "" then -- settings search registry (1.8.0)
RegisterSearch(cb, parent, label)
end
return cb
end
local function WrapCheckLabel(check)
local label = check.label
label.maxWidth = 250
label:SetWidth(label.maxWidth)
label:SetJustifyH("LEFT")
label:SetWordWrap(true)
check:FitLabel()
end
-- Search only the visible controls in the active tab. Preserve any
-- alpha set by the widget itself so closing search restores it.
function X.CfgFilter(q)
q = (q or ""):lower()
local panel = cfg and cfg.panels and cfg.panels[cfg.curTab]
local hits = 0
for _, r in ipairs(X.cfgReg) do
local inTab = panel and r.panel == panel and panel:IsShown() and r.w:IsShown()
local matches = inTab and (q == "" or r.keys:find(q, 1, true) ~= nil)
if matches then hits = hits + 1 end
if inTab and q ~= "" and not matches then
if r.alpha == nil then
r.alpha = r.w:GetAlpha()
r.w:SetAlpha(r.alpha * 0.25)
end
elseif r.alpha ~= nil then
r.w:SetAlpha(r.alpha)
r.alpha = nil
end
end
return hits
end
local function UpdateSearch()
local query = cfg.searchBox:GetText() or ""
local count = X.CfgFilter(query)
cfg.searchHint:SetText(query == "" and L["Find in this tab (Esc to close)"]
or string.format(L["Matches: %d"], count))
end
local function CloseSearch()
if not cfg.searchBox then return end
cfg.searchBox:ClearFocus()
cfg.searchBox:SetText("")
X.CfgFilter("")
cfg.searchHint:SetText(L["Find in this tab (Esc to close)"])
cfg.searchFooter:Hide()
if K.active and not K.edit then cfg.navStatus:Show() end
end
local function OpenSearch()
cfg.searchFooter:Show()
if K.active then
K.Focus(cfg.searchBox.navigation)
K.Edit(cfg.searchBox)
else
cfg.searchBox:SetFocus()
end
end
-- Hover help for a settings control: a white title line plus wrapped detail.
-- heading/text may be functions, for help that depends on the current state.
local function Tip(widget, heading, text)
widget:HookScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine(type(heading) == "function" and heading() or heading, 1, 1, 1)
local t = type(text) == "function" and text() or text
if t then GameTooltip:AddLine(t, 0.85, 0.85, 0.85, true) end
GameTooltip:Show()
end)
widget:HookScript("OnLeave", function() GameTooltip:Hide() end)
end
-- Seconds entry box (0-3600). Enter or clicking away saves, Esc cancels;
-- onCommit gets the number, or nil for an empty box. Shows getText() otherwise.
local function MakeSecondsBox(parent, getText, onCommit)
local eb = X.PanelWidget("EditBox", nil, parent, "InputBoxTemplate")
eb:SetSize(40, 20)
eb:SetAutoFocus(false)
eb:SetNumeric(true)
eb:SetMaxLetters(4)
eb:SetJustifyH("CENTER")
eb.Revert = function(self) self:SetText(getText()) end
eb:SetScript("OnEnterPressed", function(self) self:ClearFocus() end)
eb:SetScript("OnEscapePressed", function(self) self.cancel = true; self:ClearFocus() end)
eb:SetScript("OnEditFocusLost", function(self)
self:HighlightText(0, 0)
if self.cancel then self.cancel = false; self:Revert(); return end
local s = self:GetText()
local n = tonumber(s)
if s ~= "" and (not n or n > 3600) then
Print("Rebuff time must be a whole number from 0 to 3600 seconds.")
else
onCommit(n)
end
self:Revert()
end)
return eb
end
local function MakeButton(parent, text, width, onClick)
local b = X.PanelWidget("Button", nil, parent, "UIPanelButtonTemplate")
b:SetSize(width, 22)
b:SetText(text)
b:SetScript("OnClick", onClick)
if text and text ~= "" then -- settings search registry (1.8.0)
RegisterSearch(b, parent, text)
K.Register(b, parent, function() return b:GetText() end, "button")
end
return b
end
local function MakeSlider(parent, x, y, width, minV, maxV, step, onChange, label, valueText)
local slider = X.PanelWidget("Slider", nil, parent, BackdropTemplateMixin and "BackdropTemplate" or nil)
slider:SetOrientation("HORIZONTAL")
slider:SetSize(width, 17)
slider:SetPoint("TOPLEFT", x, y)
if slider.SetBackdrop then
slider:SetBackdrop({
bgFile = "Interface\\Buttons\\UI-SliderBar-Background",
edgeFile = "Interface\\Buttons\\UI-SliderBar-Border",
tile = true, tileSize = 8, edgeSize = 8,
insets = { left = 3, right = 3, top = 6, bottom = 6 },
})
end
slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal")
slider:SetMinMaxValues(minV, maxV)
slider:SetValueStep(step)
if slider.SetObeyStepOnDrag then slider:SetObeyStepOnDrag(true) end
slider:EnableMouse(true)
slider:EnableMouseWheel(true)
local function adjust(delta)
slider:SetValue(math.max(minV, math.min(maxV, slider:GetValue() + delta * step)))
end
slider:SetScript("OnMouseWheel", function(_, delta) adjust(delta) end)
slider:SetScript("OnValueChanged", function(_, v) onChange(v) end)
K.Register(slider, parent, label, "slider", valueText, adjust)
return slider
end
local function OpenColorPicker()
K.Stop()
local c, stored = X.ThemeBackground(), db.bgColor
local previousTheme, previousColor = db.theme, { stored[1], stored[2], stored[3] }
local opening = true
local function refreshAppearance()
if not X.ResolveAutoTheme() then
ApplyAppearance()
RefreshConfig()
end
end
local function apply()
if opening then return end
local r, g, b = ColorPickerFrame:GetColorRGB()
db.bgColor = { r, g, b }
db.theme = "custom" -- a hand-picked color leaves the theme presets (1.8.0)
refreshAppearance()
end
local function cancel()
db.theme, db.bgColor = previousTheme, previousColor
refreshAppearance()
end
if ColorPickerFrame.SetupColorPickerAndShow then
ColorPickerFrame:SetupColorPickerAndShow({
swatchFunc = apply, cancelFunc = cancel, hasOpacity = false,
r = c[1], g = c[2], b = c[3],
})
else
ColorPickerFrame.func = apply
ColorPickerFrame.cancelFunc = cancel
ColorPickerFrame.hasOpacity = false
ColorPickerFrame.previousValues = { r = c[1], g = c[2], b = c[3] }
ColorPickerFrame:SetColorRGB(c[1], c[2], c[3])
ColorPickerFrame:Hide()
ColorPickerFrame:Show()
end
opening = false
end
local function PercentText(v) return math_floor(v * 100 + 0.5) .. "%" end
-- Scale picker: the game's menu dropdown, with one entry per SCALE_PRESETS value.
-- A scale set by /br scale that isn't a preset shows as "Custom (n%)". Clients
-- without the dropdown template get a button that steps through the presets.
local function MakeScaleDropdown(parent, getter, setter, label)
local function value()
local current = getter()
for _, preset in ipairs(SCALE_PRESETS) do
if math.abs(preset - current) < 0.001 then return PercentText(preset) end
end
return string.format(L["Custom (%s)"], PercentText(current))
end
local function adjust(delta)
local current = getter()
local nextValue = delta > 0 and SCALE_PRESETS[1] or SCALE_PRESETS[#SCALE_PRESETS]
if delta > 0 then
for _, preset in ipairs(SCALE_PRESETS) do
if preset > current + 0.001 then nextValue = preset; break end
end
else
for i = #SCALE_PRESETS, 1, -1 do
if SCALE_PRESETS[i] < current - 0.001 then nextValue = SCALE_PRESETS[i]; break end
end
end
setter(nextValue)
end
local ok, dd = pcall(CreateFrame, "DropdownButton", nil, parent, "WowStyle1DropdownTemplate")
if ok and dd and dd.SetupMenu then
dd:SetWidth(120)
dd:SetupMenu(function(_, root)
for _, v in ipairs(SCALE_PRESETS) do
root:CreateRadio(PercentText(v),
function(x) return math.abs(getter() - x) < 0.001 end,
function(x) setter(x) end, v)
end
end)
dd.Update = function(self)
if self.SetDefaultText then self:SetDefaultText(value()) end
if self.GenerateMenu then self:GenerateMenu() end
end
K.Register(dd, parent, label, "choice", value, adjust)
return dd
end
local b = MakeButton(parent, "", 120, function(self)
adjust(1)
self:Update()
end)
b.Update = function(self) self:SetText(PercentText(getter())) end
K.Register(b, parent, label, "choice", value, adjust)
return b
end
local function SelectTab(key)
CloseSearch()
cfg.curTab = key
if cfg.themePriorityPanel then cfg.themePriorityPanel:Hide() end
if cfg.displayPanel then cfg.displayPanel:Hide() end
if cfg.blessingPanel then cfg.blessingPanel:Hide() end
if cfg.assignmentPanel then cfg.assignmentPanel:Hide() end
for k, panel in pairs(cfg.panels) do panel:SetShown(k == key) end
if cfg.searchToggle and cfg.panels[key] then
cfg.searchToggle:ClearAllPoints()
cfg.searchToggle:SetPoint("TOPRIGHT", cfg.panels[key], "TOPRIGHT", -8, -4)
cfg.searchToggle:Show()
end
if cfg.nativeTabs then
PanelTemplates_SetTab(cfg, cfg.tabBtns[key]:GetID())
else
for k, btn in pairs(cfg.tabBtns) do
if k == key then btn:LockHighlight() else btn:UnlockHighlight() end
end
end
end
local function BlessingOptionLabel(option)
if option.key ~= "DEFAULT" then return option.name end
if option.name then return string.format(L["Default (%s)"], option.name) end
return L["Default blessing"]
end
local function MakeBlessingSelector(parent, class, label)
local function choose(key)
if X.SetBlessingPreference(class, key) then RefreshConfig(); Refresh() end
end
local function value()
local current = X.BlessingPreference(class)
for _, option in ipairs(X.BlessingOptions(class)) do
if option.key == current then return BlessingOptionLabel(option) end
end
return L["Previously selected blessing unavailable"]
end
local function adjust(delta)
local current = X.BlessingPreference(class)
local options = X.BlessingOptions(class)
if #options == 0 then return end
local index = delta > 0 and 0 or 1
for i, option in ipairs(options) do
if option.key == current then index = i; break end
end
choose(options[(index - 1 + delta) % #options + 1].key)
end
local ok, dd = pcall(CreateFrame, "DropdownButton", nil, parent, "WowStyle1DropdownTemplate")
if ok and dd and dd.SetupMenu then
dd:SetWidth(290)
dd:SetupMenu(function(_, root)
for _, option in ipairs(X.BlessingOptions(class)) do
root:CreateRadio(BlessingOptionLabel(option),
function(key) return X.BlessingPreference(class) == key end, choose, option.key)
end
end)
dd.Update = function(self)
if self.SetDefaultText then self:SetDefaultText(L["Previously selected blessing unavailable"]) end
if self.GenerateMenu then self:GenerateMenu() end
end
K.Register(dd, parent, label, "choice", value, adjust)
return dd
end
local button = MakeButton(parent, "", 290, function() adjust(1) end)
button.Update = function(self) self:SetText(value()) end
K.Register(button, parent, label, "choice", value, adjust)
return button
end
local function OpenBlessingPanel()
if not cfg.blessingPanel then
local panel = X.PanelWidget("Frame", "BuffRadarBlessingPreferences", cfg,
BackdropTemplateMixin and "BackdropTemplate" or nil)
cfg.blessingPanel, cfg.blessingSelectors = panel, {}
panel:SetPoint("CENTER", cfg, "CENTER")
panel:SetSize(490, 392)
panel:SetFrameStrata("DIALOG")
panel:SetFrameLevel((cfg:GetFrameLevel() or 0) + 10)
panel:EnableMouse(true)
if panel.SetBackdrop then
panel:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 14,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
})
panel:SetBackdropColor(0.05, 0.06, 0.1, 0.98)
end
local title = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
title:SetPoint("TOPLEFT", 20, -18)
title:SetText(L["Blessings by class"])
local close = X.PanelWidget("Button", nil, panel, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", -5, -5)
close:SetScript("OnClick", function() panel:Hide() end)
K.Register(close, panel, L["Close"], "button")
for i, class in ipairs(X.BLESSING_CLASS_ORDER) do
local y = -52 - (i - 1) * 30
local label = panel:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
label:SetPoint("TOPLEFT", 22, y - 5)
local classNames = _G.LOCALIZED_CLASS_NAMES_MALE
label:SetText((classNames and classNames[class]) or class)
local selector = MakeBlessingSelector(panel, class, label:GetText())
selector:SetPoint("TOPLEFT", 158, y)
cfg.blessingSelectors[i] = selector
end
panel.complement = MakeCheck(panel, L["Complement Nearby Blessings"],
function() return db.blessingComplement end, X.SetBlessingComplement)
panel.complement:SetPoint("TOPLEFT", 18, -321)
Tip(panel.complement, L["Complement Nearby Blessings"],
L["Offer a different known blessing outside your group if another Paladin already provides your preferred blessing. Explicit rules still take precedence."])
local hint = panel:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
hint:SetPoint("TOPLEFT", 22, -355)
hint:SetWidth(442)
hint:SetJustifyH("LEFT")
hint:SetText(L["An active group blessing plan takes precedence."])
if UISpecialFrames then table.insert(UISpecialFrames, "BuffRadarBlessingPreferences") end
end
CloseSearch()
cfg.blessingPanel:Show()
RefreshConfig()
end
local AssignmentUI = {
labels = { ALL = L["All Roles"], WORLD = L["World"], TANK = L["Tank"],
HEALER = L["Heal"], DAMAGER = L["DPS"] },
}
function AssignmentUI.CellLabel(class, slot)
local names = _G.LOCALIZED_CLASS_NAMES_MALE
return (names and names[class] or class) .. ", " .. AssignmentUI.labels[slot]
end
function AssignmentUI.CellText(class, slot, options)
local rule = X.GetAssignment(class, slot)
if rule == nil then return L["Default"] end
if rule == false then return L["None"] end
local names, known = {}, {}
local count = 0
for _, option in ipairs(options) do
if rule[option.key] then names[#names + 1] = option.name end
known[option.key] = true
end
local unavailable = 0
for key in pairs(rule) do
count = count + 1
if not known[key] then unavailable = unavailable + 1 end
end
if unavailable > 0 then names[#names + 1] = string.format(L["%d unavailable"], unavailable) end
return string.format(L["%d selected"], count), table.concat(names, ", ")
end
function AssignmentUI.Update()
local panel = cfg.assignmentPanel
if not panel or not panel:IsShown() then return end
panel.enabled:Update()
local options = X.AssignmentOptions()
for class, row in pairs(panel.cells) do
for slot, button in pairs(row) do
local count, descriptions = AssignmentUI.CellText(class, slot, options)
button:SetText(count)
button.assignmentText = descriptions or count
end
end
local picker = panel.picker
if not picker:IsShown() then return end
local rule = picker.draft
if not picker.action then rule = X.GetAssignment(picker.class, picker.slot) end
picker.state:SetText(rule == nil and L["Default"] or rule == false and L["None"] or L["Custom"])
picker.noSpells:SetShown(#options == 0)
for index, button in ipairs(picker.options) do
local option = options[index]
button.option = option
if option then
button.label:SetText(option.name)
button:SetChecked(type(rule) == "table" and rule[option.key] == true)
button.icon:SetTexture(option.icon)
button.icon:SetShown(option.icon ~= nil)
button:FitLabel()
end
button:SetShown(option ~= nil)
end
end
function AssignmentUI.Save(picker, value)
if InCombatLockdown() or X.PlayerSuspended() then return false end
if picker.action then
picker.draft = value
AssignmentUI.Update()
return false
end
if X.SetAssignment(picker.class, picker.slot, value) then
AssignmentUI.Update()
Refresh()
return true
end
AssignmentUI.Update()
return false
end
function AssignmentUI.ToggleOption(picker, key, checked)
local current = picker.draft
if not picker.action then current = X.GetAssignment(picker.class, picker.slot) end
local nextRule = {}
if type(current) == "table" then
for selected in pairs(current) do nextRule[selected] = true end
end
if checked and key:match("^BLESS_") then
for selected in pairs(nextRule) do
if selected:match("^BLESS_") then nextRule[selected] = nil end
end
elseif checked and key == "DAMPEN_MAGIC" then nextRule.AMPLIFY_MAGIC = nil
elseif checked and key == "AMPLIFY_MAGIC" then nextRule.DAMPEN_MAGIC = nil end
nextRule[key] = checked and true or nil
if next(nextRule) then AssignmentUI.Save(picker, nextRule)
else AssignmentUI.Save(picker, false) end
end
function AssignmentUI.CreatePanel(parent, name, width, height, level)
local panel = CreateFrame("Frame", name, parent)
panel:SetSize(width, height)
panel:SetPoint("CENTER")
panel:SetFrameLevel(level)
panel:EnableMouse(true)
local bg = panel:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints(panel)
bg:SetColorTexture(0.06, 0.065, 0.095, 1)
panel:Hide()
return panel
end
function AssignmentUI.CloseButton(panel, onClose)
local close = X.PanelWidget("Button", nil, panel, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", -4, -4)
close:SetScript("OnClick", onClose)
K.Register(close, panel, L["Close"], "button")
return close
end
function AssignmentUI.BuildPicker(panel)
local picker = AssignmentUI.CreatePanel(panel, "BuffRadarAssignmentPicker", 574, 405, panel:GetFrameLevel() + 5)
picker.title = picker:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
picker.title:SetPoint("TOPLEFT", 16, -14)
picker.title:SetPoint("TOPRIGHT", -45, -14)
picker.title:SetJustifyH("LEFT")
picker.closeButton = AssignmentUI.CloseButton(picker, function() AssignmentUI.CancelEdit(picker, picker.blockers) end)
if picker.SetPropagateKeyboardInput then
picker:EnableKeyboard(true)
picker:HookScript("OnShow", function(self) self:SetPropagateKeyboardInput(true) end)
picker:SetScript("OnKeyDown", function(self, key)
if key == "ESCAPE" and not K.active and K.Modal() == self
and not InCombatLockdown() and not X.PlayerSuspended() then
self:SetPropagateKeyboardInput(false)
self.closeButton:Click()
end
end)
end
picker.state = picker:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
picker.state:SetPoint("TOPLEFT", 16, -40)
picker.hint = picker:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
picker.hint:SetPoint("TOPLEFT", 16, -63)
picker.hint:SetPoint("TOPRIGHT", -16, -63)
picker.hint:SetJustifyH("LEFT")
picker.noSpells = picker:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
picker.noSpells:SetPoint("TOPLEFT", 16, -112)
picker.noSpells:SetText(L["No known targeted buffs."])
picker.options = {}
for i = 1, 18 do
local button
button = MakeCheck(picker, "", function() return false end, function(checked)
if button.option then AssignmentUI.ToggleOption(picker, button.option.key, checked) end
end)
button:SetPoint("TOPLEFT", i % 2 == 1 and 12 or 290, -91 - math_floor((i - 1) / 2) * 27)
button.label:SetJustifyH("LEFT")
button.label:SetWordWrap(false)
button.icon = button:CreateTexture(nil, "ARTWORK")
button.icon:SetSize(16, 16)
button.icon:SetPoint("LEFT", button, "RIGHT", 4, 0)
button.label:ClearAllPoints()
button.label:SetPoint("LEFT", button, "RIGHT", 24, 1)
button.label.maxWidth = 220
button.label:SetWidth(220)
function button:FitLabel()
self:SetHitRectInsets(0, -(24 + math_min(self.label.maxWidth, self.label:GetStringWidth())), 0, 0)
end
Tip(button, function() return button.label:GetText() end)
picker.options[i] = button
end
picker.defaultButton = MakeButton(picker, L["Default"], 112, function()
if AssignmentUI.Save(picker, nil) then picker:Hide() end
end)
picker.defaultButton:SetPoint("BOTTOMLEFT", 16, 12)
Tip(picker.defaultButton, L["Default"], L["Inherit from All Roles or the built-in rules."])
picker.noneButton = MakeButton(picker, L["None"], 112, function()
if AssignmentUI.Save(picker, false) then picker:Hide() end
end)
picker.noneButton:SetPoint("LEFT", picker.defaultButton, "RIGHT", 8, 0)
Tip(picker.noneButton, L["None"], L["Offer no assigned buffs for this cell."])
picker.backButton = MakeButton(picker, L["Cancel"], 100, function()
AssignmentUI.CancelEdit(picker, picker.blockers)
end)
picker.backButton:SetPoint("BOTTOMRIGHT", -16, 12)
picker.reviewButton = MakeButton(picker, L["Review Changes"], 182, function()
AssignmentUI.OpenReview(picker, picker.blockers)
end)
picker.reviewButton:SetPoint("RIGHT", picker.backButton, "LEFT", -8, 0)
return picker
end
function AssignmentUI.OpenPicker(panel, class, slot, blockers, action)
if InCombatLockdown() or X.PlayerSuspended() then return end
local picker = panel.picker
picker.class, picker.slot = class, slot
picker.blockers, picker.action = blockers, action
if action then picker.draft = X.GetAssignment(class, slot) end
picker.backButton:SetText(L[blockers and "Cancel" or "Done"])
picker.reviewButton:SetShown(blockers ~= nil)
picker.hint:SetText(L[blockers and "Edit the draft, then review the changes before applying."
or "Select spells for this cell. Changes apply immediately."])
picker:SetFrameLevel(blockers and blockers:GetFrameLevel() + 5 or panel:GetFrameLevel() + 5)
picker.closeButton:SetFrameLevel(picker:GetFrameLevel() + 1)
panel.closeButton:Hide()
picker.title:SetText(AssignmentUI.CellLabel(class, slot))
picker:Show()
AssignmentUI.Update()
if K.active and not K.edit then K.Move(1) end
end
function AssignmentUI.UpdateBlockers(panel)
local lines = panel.member.groupDetails
local pages = math.max(1, math.ceil(#lines / #panel.rows))
panel.page = math_min(pages, math.max(1, panel.page))
local first = (panel.page - 1) * #panel.rows + 1
panel.previous:SetShown(panel.page > 1)
panel.next:SetShown(panel.page < pages)
for i, row in ipairs(panel.rows) do
local index = first + i - 1
local line = lines[index]
row.action = panel.member.groupActions and panel.member.groupActions[index]
row.text:SetText(line or "")
row.text:SetPoint("TOPRIGHT", row.action and -111 or 0, 0)
row.edit:SetShown(row.action ~= nil)
row:SetShown(line ~= nil)
end
end
function AssignmentUI.FindPreviewMember(members, identity)
if not identity then return nil end
for _, member in ipairs(members) do
if member.identity == identity then return member end
end
end
function AssignmentUI.CheckBlocker(panel, action)
if not panel or not panel:IsVisible() or not panel.member then return false end
local member = AssignmentUI.FindPreviewMember(X.AssignmentPreview(), panel.member.identity)
for _, candidate in pairs(member and member.groupActions or {}) do
if candidate.kind == action.kind and candidate.guid == action.guid and candidate.class == action.class
and candidate.slot == action.slot then return true end
end
Print(L["The blocker changed. Check the updated list."])
AssignmentUI.RefreshPreview(panel.preview, panel)
return false
end
function AssignmentUI.CancelEdit(editor, blockers)
if not editor then return end
editor:Hide()
if blockers and blockers:IsVisible() then AssignmentUI.RefreshPreview(blockers.preview, blockers) end
end
function AssignmentUI.UpdateReview(panel)
local lastPage = math.max(1, math.ceil(#panel.lines / #panel.rows))
panel.page = math_min(lastPage, math.max(1, panel.page))
panel.previous:SetShown(panel.page > 1)
panel.next:SetShown(panel.page < lastPage)
local start = (panel.page - 1) * #panel.rows
panel.count:SetText(lastPage > 1 and string.format(L["Rows %d–%d of %d"], start + 1,
math_min(start + #panel.rows, #panel.lines), #panel.lines) or "")
for index, widget in ipairs(panel.rows) do
local line = panel.lines[start + index]