-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions_Bars.lua
More file actions
1534 lines (1404 loc) · 70 KB
/
Copy pathOptions_Bars.lua
File metadata and controls
1534 lines (1404 loc) · 70 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_Bars.lua - Bars / Groups tab (group-and-bar editor).
-- Author: Serv
-- Source: https://github.com/powerfulqa/BarWarden
-- License: see LICENSE; attribution preservation is required.
local addonName, ns = ...
-- ============================================================================
-- Options_Bars.lua - Tab 2: Bars / Groups configuration
-- ============================================================================
local TRACK_MODES = {
"Cooldown", "Buff", "Debuff", "Proc",
"Item", "Enchant MH", "Enchant OH", "Totem",
-- Class resources (Combo Points/Runic Power/Soul Shards are event-driven;
-- Runes is time-based with spellId as the slot number 1..6).
"Combo Points", "Runes", "Runic Power", "Soul Shards",
}
local TARGET_UNITS = { "player", "target", "focus", "pet", "mouseover" }
local GROUP_LIST_HEIGHT = 16
local BAR_LIST_HEIGHT = 16
-- Lists show up to this many rows (the box grows with the item count, minimum
-- one line) before they start scrolling. Six keeps the settings/editor below
-- visible even at the smallest window size; Groups and Bars use the same cap.
local MAX_GROUP_ROWS = 6
local MAX_BAR_ROWS = 6
-- Blizzard's FauxScrollFrame_Update HIDES the whole scroll frame when the list
-- fits without scrolling. Both lists have the rest of their column anchored to
-- that frame (the buttons, then the settings block below them), and anchoring
-- to a frame that gets hidden out from under you strands the dependants - they
-- fall back towards the panel origin and the page visibly comes apart until
-- something re-shows the frame.
--
-- Deleting the 7th group is the exact trigger: 7 > 6 keeps it shown, dropping
-- back to 6 hides it. Adding a group put it right again, which is what made the
-- bug look like it was about deleting.
--
-- So keep the scroll frame itself shown always and hide only its scrollbar,
-- which is what the auto-hide elsewhere in the addon does too.
--
-- EC-TRAP: the Show() below looks redundant right after FauxScrollFrame_Update
-- and is not. Removing it re-breaks the Bar Control page whenever a list drops
-- from 7 items to 6. Never anchor anything to a frame Blizzard's own helpers
-- show and hide.
local function KeepListFrameShown(scrollFrame, scrollBarName, needsScrollBar)
if not scrollFrame then return end
scrollFrame:Show()
local sb = _G[scrollBarName]
if sb then
if needsScrollBar then sb:Show() else sb:Hide() end
end
end
-- Helper: create a new default bar table
local function NewBar(name)
return {
name = name or "New Bar",
enabled = true,
trackMode = "Cooldown",
unit = "player",
spellName = "",
spellId = nil,
itemId = nil,
onlyMine = true,
conditions = {
combatOnly = false,
outOfCombatOnly = false,
requireBuff = nil,
requireClass = nil, -- set by class-starter presets; hides bar for other classes
healthBelow = nil,
inGroup = false,
inRaid = false,
hideWhileMounted = false,
hideWhileResting = false,
hideInVehicle = false,
onlyInInstance = false,
hideWhenInactive = false,
showEmpty = true,
},
display = {
progressDirection = "LTR",
lingerTime = 0,
barAlpha = 0.6,
showName = nil,
showIcon = nil,
textFormat = nil,
colorOverride = nil,
textureOverride = nil,
style = nil,
-- Colour-by-time (nil = inherit global)
colorByTime = nil,
-- Glow on ready / pulse on ready
glowOnReady = false,
pulseOnReady = false,
-- Icon crop (nil = inherit global)
iconCrop = nil,
-- Per-bar scale multiplier (nil = 1.0 = group default)
scaleOverride = nil,
},
}
end
-- Helper: create a new default group (frame) table
local function NewGroup(name)
return {
name = name or "New Group",
enabled = true,
locked = true,
visible = true,
position = { point = "CENTER", relativePoint = "CENTER", x = 0, y = 0 },
width = 200,
columns = 1,
bgAlpha = 0.6,
borderAlpha = 0.8,
scale = 1.0,
sortMode = "manual",
groupConditions = {},
bars = {},
}
end
-- ============================================================================
-- Main Tab Creation
-- ============================================================================
local selectedGroupIndex = nil
local selectedBarIndex = nil
local function CreateBarsTab(parent)
local frame = CreateFrame("Frame", "BarWardenBarsTab", parent)
frame:SetAllPoints(parent)
frame:Hide()
-- Drag-to-reorder: work out which row index the cursor is over in a
-- FauxScrollFrame list, accounting for the scroll offset and UI scale.
local function ComputeDropIndex(scrollFrame, rowHeight, total)
local _, cy = GetCursorPosition()
local scale = scrollFrame:GetEffectiveScale()
local top = scrollFrame:GetTop()
if not cy or not scale or scale == 0 or not top then return nil end
local offset = FauxScrollFrame_GetOffset(scrollFrame) or 0
local idx = offset + math.floor((top - cy / scale) / rowHeight) + 1
if idx < 1 then idx = 1 end
if idx > total then idx = total end
return idx
end
-- ========================================================================
-- LEFT PANEL: Group List
-- ========================================================================
local leftPanel = CreateFrame("Frame", nil, frame)
-- v2: start near the top (no tab bar to clear) and fill the panel height, so
-- the group list + settings use the full column instead of a 360px box.
-- Groups tab content: fills the page below the title, above the tab bar.
leftPanel:SetPoint("TOPLEFT", frame, "TOPLEFT", 16, -44)
leftPanel:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -16, 40)
local groupHeader = leftPanel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
groupHeader:SetPoint("TOPLEFT", leftPanel, "TOPLEFT", 0, 0)
groupHeader:SetText("Groups")
ns:CreateHelpIcon(leftPanel, groupHeader, "LEFT", "RIGHT", 6, 0, "create-group")
-- Group scroll frame
-- List spans the full page width; its height is set dynamically in
-- UpdateGroupList (grows with the group count, up to MAX_GROUP_ROWS rows,
-- then scrolls). The buttons + settings below follow its bottom edge.
local groupScrollFrame = CreateFrame("ScrollFrame", "BarWardenGroupScroll", leftPanel, "FauxScrollFrameTemplate")
groupScrollFrame:SetPoint("TOPLEFT", groupHeader, "BOTTOMLEFT", 0, -6)
-- Fixed width = the shared settings width, so the list + its selection
-- highlight are contained at the same limit as the settings below, instead
-- of the highlight stretching across the whole window.
groupScrollFrame:SetWidth(ns.SETTINGS_MAX_WIDTH or 300)
groupScrollFrame:SetHeight(MAX_GROUP_ROWS * GROUP_LIST_HEIGHT)
local groupRows = {}
for i = 1, MAX_GROUP_ROWS do
local row = CreateFrame("Button", "BarWardenGroupRow" .. i, leftPanel)
row:SetHeight(GROUP_LIST_HEIGHT)
if i == 1 then
row:SetPoint("TOPLEFT", groupScrollFrame, "TOPLEFT", 0, 0)
row:SetPoint("TOPRIGHT", groupScrollFrame, "TOPRIGHT", -22, 0)
else
row:SetPoint("TOPLEFT", groupRows[i - 1], "BOTTOMLEFT", 0, 0)
row:SetPoint("TOPRIGHT", groupRows[i - 1], "BOTTOMRIGHT", 0, 0)
end
local highlight = row:CreateTexture(nil, "HIGHLIGHT")
highlight:SetAllPoints()
highlight:SetTexture(1, 1, 1, 0.1)
local selected = row:CreateTexture(nil, "BACKGROUND")
selected:SetAllPoints()
selected:SetTexture(0.2, 0.4, 0.8, 0.3)
selected:Hide()
row.selected = selected
local text = row:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
text:SetPoint("LEFT", row, "LEFT", 4, 0)
text:SetPoint("RIGHT", row, "RIGHT", -4, 0)
text:SetJustifyH("LEFT")
row.text = text
row:SetScript("OnClick", function(self)
selectedGroupIndex = self.index
selectedBarIndex = nil
frame:Refresh()
end)
-- Drag-to-reorder groups (a plain click still selects).
row:RegisterForDrag("LeftButton")
row:SetScript("OnDragStart", function(self) frame._dragGroup = self.index end)
row:SetScript("OnDragStop", function()
local from = frame._dragGroup
frame._dragGroup = nil
local frames = BarWardenDB and BarWardenDB.frames
if not from or not frames or #frames < 2 then return end
local to = ComputeDropIndex(groupScrollFrame, GROUP_LIST_HEIGHT, #frames)
if to and to ~= from then
table.insert(frames, to, table.remove(frames, from))
selectedGroupIndex = to
selectedBarIndex = nil
frame:Refresh()
ns:RebuildAllFrames()
end
end)
groupRows[i] = row
end
-- Group buttons: Add / Delete / Dupe split the list width into equal thirds
-- so the row fills the panel even at its narrowest. Two gaps between three
-- buttons; the last button absorbs the rounding remainder so the row's right
-- edge lands exactly on the list's right edge.
local GROUP_BTN_GAP = 4
local GROUP_ROW_W = ns.SETTINGS_MAX_WIDTH or 300
local groupBtnW = math.floor((GROUP_ROW_W - 2 * GROUP_BTN_GAP) / 3)
local groupBtnWLast = GROUP_ROW_W - 2 * groupBtnW - 2 * GROUP_BTN_GAP
-- Group buttons
local addGroupBtn = ns:CreateButton(leftPanel, "Add", groupBtnW, function()
local frames = BarWardenDB.frames
if #frames >= (ns.MAX_FRAMES or 20) then
ns:Print("Maximum of " .. (ns.MAX_FRAMES or 20) .. " groups reached.")
return
end
local group = NewGroup("Group " .. (#frames + 1))
table.insert(frames, group)
selectedGroupIndex = #frames
selectedBarIndex = nil
frame:Refresh()
ns:RebuildAllFrames()
end)
addGroupBtn:SetPoint("TOPLEFT", groupScrollFrame, "BOTTOMLEFT", 0, -4)
local deleteGroupBtn = ns:CreateButton(leftPanel, "Delete", groupBtnW, function()
if not selectedGroupIndex then ns:Print("Select a group first."); return end
local frames = BarWardenDB.frames
local g = frames[selectedGroupIndex]
if not g then return end
-- Capture the target group itself, not the live selection: the popup is
-- not modal, so the user can click another row while it is open. Acting
-- on the selection at accept time deleted whichever group they clicked
-- last rather than the one the popup names.
local targetGroup = g
local popup = StaticPopup_Show("BARWARDEN_CONFIRM_DELETE", g.name or "this group")
if popup then
popup.data = {
onAccept = function()
local idx
for i, f in ipairs(frames) do
if f == targetGroup then idx = i; break end
end
if not idx then
ns:Print("That group no longer exists.")
return
end
ns:BackupFrames("delete group")
table.remove(frames, idx)
if selectedGroupIndex and selectedGroupIndex > #frames then
selectedGroupIndex = #frames > 0 and #frames or nil
end
selectedBarIndex = nil
frame:Refresh()
ns:RebuildAllFrames()
end,
}
end
end)
deleteGroupBtn:SetPoint("LEFT", addGroupBtn, "RIGHT", GROUP_BTN_GAP, 0)
local dupeGroupBtn = ns:CreateButton(leftPanel, "Dupe", groupBtnWLast, function()
if not selectedGroupIndex then ns:Print("Select a group first."); return end
local frames = BarWardenDB.frames
local g = frames[selectedGroupIndex]
if not g then return end
local copy = ns:CopyTable(g)
copy.name = g.name .. " (copy)"
copy.position.x = copy.position.x + 20
copy.position.y = copy.position.y - 20
table.insert(frames, copy)
selectedGroupIndex = #frames
selectedBarIndex = nil
frame:Refresh()
ns:RebuildAllFrames()
end)
dupeGroupBtn:SetPoint("LEFT", deleteGroupBtn, "RIGHT", GROUP_BTN_GAP, 0)
-- Group settings sit BELOW the list + buttons and span the full page width
-- (stacked layout, uniform with the Bars tab). This keeps the settings
-- visible even at the smallest window size. The scroll fills the remaining
-- height and reflows on resize.
local groupSettingsHeader = leftPanel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
groupSettingsHeader:SetPoint("TOPLEFT", addGroupBtn, "BOTTOMLEFT", 0, -10)
groupSettingsHeader:SetText("Group Settings")
local groupSettingsScroll = CreateFrame("ScrollFrame", "BarWardenGroupSettingsScroll", leftPanel, "UIPanelScrollFrameTemplate")
groupSettingsScroll:SetPoint("TOPLEFT", groupSettingsHeader, "BOTTOMLEFT", 0, -6)
groupSettingsScroll:SetPoint("BOTTOMRIGHT", leftPanel, "BOTTOMRIGHT", -24, 0)
local groupSettingsContent = CreateFrame("Frame", nil, groupSettingsScroll)
groupSettingsContent:SetWidth(320)
-- Generous fallback height so all group settings (down to the Group
-- Conditions toggles) are reachable; fitGroupHeight() trims it once shown.
groupSettingsContent:SetHeight(700)
groupSettingsScroll:SetScrollChild(groupSettingsContent)
-- Populated by BuildSettings (ids below); used to fill the group dropdowns
-- to the panel width on resize, matching the Bars editor.
local groupSettingsWidgets = {}
-- Reflow the settings content to the live viewport width on resize, and
-- fill the dropdowns (their box width is a template property, not an anchor).
groupSettingsScroll:SetScript("OnSizeChanged", function(_, w)
if w and w > 100 then
-- Cap at the shared settings width (parity with the Bars editor).
local cw = math.min(w, ns.SETTINGS_MAX_WIDTH or 300)
groupSettingsContent:SetWidth(cw)
local ddW = math.max(120, cw - 60)
for _, id in ipairs({ "grpSortDD", "grpGrowthDD", "grpTextureDD", "grpTextFormatDD" }) do
local dd = groupSettingsWidgets[id]
if dd then UIDropDownMenu_SetWidth(dd, ddW) end
end
end
end)
-- Group-settings schema: declarative via BuildSettings.
-- All entries use get/set escape hatches because the target is the
-- currently selected group (selectedGroupIndex), not a fixed DB path.
local function getGroup()
return selectedGroupIndex and BarWardenDB.frames[selectedGroupIndex]
end
local sortModeItems = {
{ text = "Manual", value = "manual" },
{ text = "Remaining Time", value = "remaining" },
{ text = "Alphabetical", value = "alpha" },
}
local growDirectionItems = {
{ text = "Down (default)", value = "DOWN" },
{ text = "Up", value = "UP" },
}
-- Per-group bar-texture choices: "Inherit" (use the addon-wide texture from
-- the Visuals page) plus the shared media list. "Custom" is dropped here;
-- a custom texture path stays a global-only setting.
local groupTextureItems = { { text = "Inherit (default)", value = "" } }
do
local list = ns.LSMDropdownItems and ns:LSMDropdownItems("statusbar")
if list then
for _, item in ipairs(list) do
if item.value ~= "Custom" then
groupTextureItems[#groupTextureItems + 1] = item
end
end
else
for _, n in ipairs({ "Flat", "Smooth", "Gloss", "Aluminum", "Armory" }) do
groupTextureItems[#groupTextureItems + 1] = { text = n, value = n }
end
end
end
-- Text-format override list: Inherit plus the same formats the Visuals page
-- offers, so one group can show stacks (or names only) without changing
-- every other bar in the addon.
local groupTextFormatItems = {
{ text = "Inherit (default)", value = "" },
{ text = "Name + Duration", value = "NAME_DURATION" },
{ text = "Name Only", value = "NAME_ONLY" },
{ text = "Duration Only", value = "DURATION" },
{ text = "Name + Stacks", value = "NAME_STACKS" },
{ text = "Stacks Only", value = "STACKS" },
{ text = "None", value = "NONE" },
}
-- Forward-declared so schema `set` closures below can re-run the group
-- settings Refresh (e.g. to re-check the Custom Bar Colour toggle after the
-- colour swatch writes g.barColor). Assigned by BuildSettings just below.
local refreshGroupSettings
local GROUP_SETTINGS_SCHEMA = {
{ type = "editbox", label = "Group Name", width = 155, stretch = true,
tooltip = "A label for this group, shown on the frame when 'Show "
.. "Group Name' is ticked.",
get = function() local g = getGroup(); return g and g.name or "" end,
set = function(_, text)
local g = getGroup(); if not g then return end
g.name = text
local gf = ns.groupFrames[selectedGroupIndex]
if gf and gf.titleText then gf.titleText:SetText(text) end
frame:Refresh()
end,
offsetX = 4 },
{ type = "toggle", label = "Show Group Name",
tooltip = "Show or hide the group name on the bar frame.",
get = function() local g = getGroup(); return g and g.showTitle ~= false end,
set = function(_, checked)
local g = getGroup(); if not g then return end
g.showTitle = checked and true or false
local gf = ns.groupFrames[selectedGroupIndex]
if gf and gf.titleText then
if checked then gf.titleText:Show() else gf.titleText:Hide() end
end
end,
offsetX = -6, spacing = 4 },
{ type = "slider", label = "Width", min = 50, max = 400, step = 5, width = 150, stretch = true,
tooltip = "How wide the bars in this group are, in pixels.",
get = function() local g = getGroup(); return g and g.width or 200 end,
set = function(_, value)
local g = getGroup(); if not g then return end
g.width = value
local gf = ns.groupFrames[selectedGroupIndex]
if gf then ns:UpdateGroupLayout(gf) end
end,
offsetX = 10, spacing = 12 },
{ type = "slider", label = "Scale", min = 0.5, max = 2.0, step = 0.1, width = 150, stretch = true,
tooltip = "Overall size of this group. 1.00 is normal size.",
get = function() local g = getGroup(); return g and g.scale or 1.0 end,
set = function(_, value)
if not selectedGroupIndex then return end
ns:SetFrameScale(selectedGroupIndex, value)
local g = getGroup(); if g then g.scale = value end
end,
spacing = 16 },
{ type = "slider", label = "Columns", min = 1, max = 4, step = 1, width = 150, stretch = true,
tooltip = "Number of columns the bars in this group are arranged into. "
.. "1 = vertical stack (default); 2-4 splits the bars across that "
.. "many columns side by side. Useful when tracking many bars in a "
.. "compact footprint.",
get = function() local g = getGroup(); return g and g.columns or 1 end,
set = function(_, value)
if selectedGroupIndex then ns:SetGroupColumns(selectedGroupIndex, value) end
end,
spacing = 16 },
{ type = "slider", label = "Background Opacity", min = 0, max = 1, step = 0.05, width = 150, stretch = true,
tooltip = "Opacity of this group's background panel. 0 hides it.",
get = function() local g = getGroup(); return g and (g.bgAlpha ~= nil and g.bgAlpha or 0.6) end,
set = function(_, value)
if selectedGroupIndex then ns:SetGroupBgAlpha(selectedGroupIndex, value) end
end,
spacing = 16 },
{ type = "slider", label = "Border Opacity", min = 0, max = 1, step = 0.05, width = 150, stretch = true,
tooltip = "Opacity of this group's border. 0 hides it.",
get = function() local g = getGroup(); return g and (g.borderAlpha ~= nil and g.borderAlpha or 0.8) end,
set = function(_, value)
if selectedGroupIndex then ns:SetGroupBorderAlpha(selectedGroupIndex, value) end
end,
spacing = 16 },
{ type = "dropdown", id = "grpSortDD", label = "Sort Mode", items = sortModeItems, width = 130,
tooltip = "Order the bars in this group: Manual (drag to reorder), by "
.. "remaining time, or alphabetically.",
get = function() local g = getGroup(); return g and g.sortMode or "manual" end,
set = function(_, value)
local g = getGroup(); if not g then return end
g.sortMode = value
local gf = ns.groupFrames[selectedGroupIndex]
if gf then ns:UpdateGroupLayout(gf) end
end,
offsetX = -16, spacing = 28 },
{ type = "dropdown", id = "grpGrowthDD", label = "Growth Direction", items = growDirectionItems, width = 130,
tooltip = "Direction bars stack within this group. Down (default) "
.. "grows bars downward from the title. Up grows bars upward, "
.. "useful when you want the group anchored at the bottom of "
.. "the screen.",
get = function() local g = getGroup(); return g and g.growDirection or "DOWN" end,
set = function(_, value)
local g = getGroup(); if not g then return end
g.growDirection = value
local gf = ns.groupFrames[selectedGroupIndex]
if gf then ns:UpdateGroupLayout(gf) end
end,
spacing = 16 },
-- Group-level bar visuals. These override the addon-wide look from the
-- Visuals page for just this group's bars; left on Inherit / off, they
-- use the global default.
{ type = "header", text = "Bar Overrides", spacing = 16, offsetX = 10 },
{ type = "dropdown", id = "grpTextureDD", label = "Bar Texture", items = groupTextureItems, width = 150,
tooltip = "Texture for this group's bars. Inherit uses the addon-wide "
.. "texture set on the Visuals page.",
get = function() local g = getGroup(); return g and g.barTexture or "" end,
set = function(_, value)
local g = getGroup(); if not g then return end
g.barTexture = (value ~= "" and value) or nil
ns:RefreshAllBars()
end,
offsetX = -16, spacing = 28 },
{ type = "dropdown", id = "grpTextFormatDD", label = "Text Format",
items = groupTextFormatItems, width = 150,
tooltip = "What this group's bars show as text. Inherit uses the "
.. "addon-wide format set on the Visuals page.",
get = function() local g = getGroup(); return g and g.textFormat or "" end,
set = function(_, value)
local g = getGroup(); if not g then return end
g.textFormat = (value ~= "" and value) or nil
ns:RefreshAllBars()
end,
offsetX = 0, spacing = 28 },
{ type = "toggle", label = "Custom Bar Colour",
tooltip = "Give this group's bars their own colour instead of the "
.. "addon-wide default. Turn off to go back to the default.",
get = function() local g = getGroup(); return g and g.barColor ~= nil end,
set = function(_, checked)
local g = getGroup(); if not g then return end
if checked then
g.barColor = g.barColor or { r = 0.2, g = 0.6, b = 1.0 }
else
g.barColor = nil
end
ns:RefreshBarSettings()
ns:RefreshAllBars()
end,
-- Show the swatch only while the override is on, matching how the
-- Visuals page couples Colour Mode to its own swatch. It used to sit
-- there permanently, and clicking it silently switched the override on.
onChange = function(value)
local sw = groupSettingsWidgets.grpColorSwatch
if sw then
if value then sw:Show() else sw:Hide() end
end
end,
offsetX = 10, spacing = 8 },
{ type = "color", id = "grpColorSwatch", label = "Bar Colour",
get = function() local g = getGroup(); return (g and g.barColor) or { r = 0.2, g = 0.6, b = 1.0 } end,
set = function(_, color)
local g = getGroup(); if not g then return end
g.barColor = { r = color.r, g = color.g, b = color.b }
-- Picking a colour implies "custom colour on" - re-run Refresh so
-- the Custom Bar Colour toggle reflects that immediately.
if refreshGroupSettings then refreshGroupSettings() end
ns:RefreshAllBars()
end,
offsetX = 10, spacing = 8 },
-- Group-level visibility conditions. These hide the ENTIRE group
-- (frame + all bars) when the condition fails, saving the user from
-- ticking the same checkbox on every bar individually.
{ type = "header", text = "Group Conditions", spacing = 16, offsetX = 10, id = "grpCondHeader" },
{ type = "toggle", label = "Hide When Inactive",
tooltip = "Controls the whole group once you use it: ticked hides "
.. "every bar while it has nothing to show, unticked keeps them "
.. "all visible even if individual bars are set to hide. Leave it "
.. "alone to let each bar decide.",
get = function() local g = getGroup(); return g and g.groupConditions and g.groupConditions.hideWhenInactive end,
set = function(_, v) local g = getGroup(); if not g then return end
if not g.groupConditions then g.groupConditions = {} end
g.groupConditions.hideWhenInactive = v
-- RefreshBarSettings already refreshes the live bars, matching
-- the other group-condition toggles.
ns:RefreshBarSettings() end,
spacing = 4 },
{ type = "toggle", label = "Combat Only",
tooltip = "Hide this entire group when out of combat.",
get = function() local g = getGroup(); return g and g.groupConditions and g.groupConditions.combatOnly end,
set = function(_, v) local g = getGroup(); if not g then return end
if not g.groupConditions then g.groupConditions = {} end
g.groupConditions.combatOnly = v
if v then g.groupConditions.outOfCombatOnly = false end
ns:RefreshBarSettings() end,
spacing = 4 },
{ type = "toggle", label = "Out of Combat Only",
tooltip = "Hide this entire group when in combat.",
get = function() local g = getGroup(); return g and g.groupConditions and g.groupConditions.outOfCombatOnly end,
set = function(_, v) local g = getGroup(); if not g then return end
if not g.groupConditions then g.groupConditions = {} end
g.groupConditions.outOfCombatOnly = v
if v then g.groupConditions.combatOnly = false end
ns:RefreshBarSettings() end,
spacing = 2 },
{ type = "toggle", label = "Hide Mounted",
tooltip = "Hide this entire group while mounted.",
get = function() local g = getGroup(); return g and g.groupConditions and g.groupConditions.hideWhileMounted end,
set = function(_, v) local g = getGroup(); if not g then return end
if not g.groupConditions then g.groupConditions = {} end; g.groupConditions.hideWhileMounted = v; ns:RefreshBarSettings() end,
spacing = 2 },
{ type = "toggle", label = "Hide Resting",
tooltip = "Hide this entire group while in an inn or capital city.",
get = function() local g = getGroup(); return g and g.groupConditions and g.groupConditions.hideWhileResting end,
set = function(_, v) local g = getGroup(); if not g then return end
if not g.groupConditions then g.groupConditions = {} end; g.groupConditions.hideWhileResting = v; ns:RefreshBarSettings() end,
spacing = 2 },
{ type = "toggle", label = "Hide In Vehicle",
tooltip = "Hide this entire group while in a vehicle.",
get = function() local g = getGroup(); return g and g.groupConditions and g.groupConditions.hideInVehicle end,
set = function(_, v) local g = getGroup(); if not g then return end
if not g.groupConditions then g.groupConditions = {} end; g.groupConditions.hideInVehicle = v; ns:RefreshBarSettings() end,
spacing = 2 },
{ type = "toggle", id = "groupLastWidget", label = "Only In Instance",
tooltip = "Only show this entire group inside a dungeon, raid, arena, or battleground.",
get = function() local g = getGroup(); return g and g.groupConditions and g.groupConditions.onlyInInstance end,
set = function(_, v) local g = getGroup(); if not g then return end
if not g.groupConditions then g.groupConditions = {} end; g.groupConditions.onlyInInstance = v; ns:RefreshBarSettings() end,
spacing = 2 },
}
refreshGroupSettings = ns:BuildSettings(groupSettingsContent, GROUP_SETTINGS_SCHEMA, groupSettingsWidgets,
{ firstX = 0, firstY = 0 })
-- Deep-link the Group Conditions section to its Help answer.
if groupSettingsWidgets.grpCondHeader and ns.CreateHelpIcon then
ns:CreateHelpIcon(groupSettingsContent, groupSettingsWidgets.grpCondHeader,
"LEFT", "RIGHT", 6, 0, "group-conditions")
end
-- ========================================================================
-- RIGHT PANEL: Bar List + Bar Editor
-- ========================================================================
-- Bars tab content: same full-page region as the Groups tab (they occupy
-- the same space and are shown one at a time by the bottom tabs).
local rightPanel = CreateFrame("Frame", nil, frame)
rightPanel:SetPoint("TOPLEFT", frame, "TOPLEFT", 16, -44)
rightPanel:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -16, 40)
local barHeader = rightPanel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
barHeader:SetPoint("TOPLEFT", rightPanel, "TOPLEFT", 0, 0)
barHeader:SetText("Bars")
ns:CreateHelpIcon(rightPanel, barHeader, "LEFT", "RIGHT", 6, 0, "add-bar")
-- Bar list spans the full page width; its height is set dynamically in
-- UpdateBarList (grows with the bar count, up to MAX_BAR_ROWS rows, then
-- scrolls). The buttons + editor below follow its bottom edge.
local barScrollFrame = CreateFrame("ScrollFrame", "BarWardenBarScroll", rightPanel, "FauxScrollFrameTemplate")
barScrollFrame:SetPoint("TOPLEFT", barHeader, "BOTTOMLEFT", 0, -6)
-- Fixed width = the shared settings width (the button-row / Paste-button
-- edge), so the list + its selection highlight stop at the same limit as
-- everything else instead of stretching across the whole window.
barScrollFrame:SetWidth(ns.SETTINGS_MAX_WIDTH or 300)
barScrollFrame:SetHeight(MAX_BAR_ROWS * BAR_LIST_HEIGHT)
local barRows = {}
for i = 1, MAX_BAR_ROWS do
local row = CreateFrame("Button", "BarWardenBarRow" .. i, rightPanel)
row:SetHeight(BAR_LIST_HEIGHT)
if i == 1 then
row:SetPoint("TOPLEFT", barScrollFrame, "TOPLEFT", 0, 0)
row:SetPoint("TOPRIGHT", barScrollFrame, "TOPRIGHT", -22, 0)
else
row:SetPoint("TOPLEFT", barRows[i - 1], "BOTTOMLEFT", 0, 0)
row:SetPoint("TOPRIGHT", barRows[i - 1], "BOTTOMRIGHT", 0, 0)
end
local highlight = row:CreateTexture(nil, "HIGHLIGHT")
highlight:SetAllPoints()
highlight:SetTexture(1, 1, 1, 0.1)
local selected = row:CreateTexture(nil, "BACKGROUND")
selected:SetAllPoints()
selected:SetTexture(0.2, 0.4, 0.8, 0.3)
selected:Hide()
row.selected = selected
-- Columns sized to fit within the capped list width (name + mode +
-- target all land before the list's right edge, no clipping).
local nameText = row:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
nameText:SetPoint("LEFT", row, "LEFT", 4, 0)
nameText:SetJustifyH("LEFT")
nameText:SetWidth(120)
row.nameText = nameText
local modeText = row:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
modeText:SetPoint("LEFT", nameText, "RIGHT", 6, 0)
modeText:SetJustifyH("LEFT")
modeText:SetWidth(70)
row.modeText = modeText
local targetText = row:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
targetText:SetPoint("LEFT", modeText, "RIGHT", 6, 0)
targetText:SetJustifyH("LEFT")
targetText:SetWidth(56)
row.targetText = targetText
row:SetScript("OnClick", function(self)
selectedBarIndex = self.index
frame:Refresh()
end)
-- Drag-to-reorder bars within the selected group (click still selects).
row:RegisterForDrag("LeftButton")
row:SetScript("OnDragStart", function(self) frame._dragBar = self.index end)
row:SetScript("OnDragStop", function()
local from = frame._dragBar
frame._dragBar = nil
local g = selectedGroupIndex and BarWardenDB and BarWardenDB.frames[selectedGroupIndex]
local bars = g and g.bars
if not from or not bars or #bars < 2 then return end
local to = ComputeDropIndex(barScrollFrame, BAR_LIST_HEIGHT, #bars)
if to and to ~= from then
table.insert(bars, to, table.remove(bars, from))
selectedBarIndex = to
frame:Refresh()
ns:RebuildAllFrames()
end
end)
barRows[i] = row
end
-- Bar list buttons: compact single row.
-- +/- for add/delete, arrows for reorder, Dupe/Paste for copy-paste.
local addBarBtn = ns:CreateButton(rightPanel, "+", 42, function()
if not selectedGroupIndex then ns:Print("Select a group first."); return end
local g = BarWardenDB.frames[selectedGroupIndex]
if not g then return end
local maxBars = ns.MAX_BARS_PER_FRAME or 30
if #g.bars >= maxBars then
ns:Print("Maximum of " .. maxBars .. " bars per group reached.")
return
end
local bar = NewBar("Bar " .. (#g.bars + 1))
table.insert(g.bars, bar)
selectedBarIndex = #g.bars
frame:Refresh()
ns:RebuildAllFrames()
end)
addBarBtn:SetPoint("TOPLEFT", barScrollFrame, "BOTTOMLEFT", 0, -4)
local deleteBarBtn = ns:CreateButton(rightPanel, "-", 42, function()
if not selectedGroupIndex or not selectedBarIndex then ns:Print("Select a bar first."); return end
local g = BarWardenDB.frames[selectedGroupIndex]
if not g then return end
local bar = g.bars[selectedBarIndex]
if not bar then return end
-- Capture the bar itself; the popup is not modal, so re-reading the
-- selection at accept time could remove a different bar (or the wrong
-- index of a different group) than the one the popup names.
local targetBar = bar
local popup = StaticPopup_Show("BARWARDEN_CONFIRM_DELETE", bar.name or "this bar")
if popup then
popup.data = {
onAccept = function()
local idx
for i, b in ipairs(g.bars) do
if b == targetBar then idx = i; break end
end
if not idx then
ns:Print("That bar no longer exists.")
return
end
ns:BackupFrames("delete bar")
table.remove(g.bars, idx)
if selectedBarIndex and selectedBarIndex > #g.bars then
selectedBarIndex = #g.bars > 0 and #g.bars or nil
end
frame:Refresh()
ns:RebuildAllFrames()
end,
}
end
end)
deleteBarBtn:SetPoint("LEFT", addBarBtn, "RIGHT", 1, 0)
local moveUpBtn = ns:CreateButton(rightPanel, "Up", 44, function()
if not selectedGroupIndex or not selectedBarIndex then ns:Print("Select a bar first."); return end
local bars = BarWardenDB.frames[selectedGroupIndex].bars
if selectedBarIndex <= 1 then return end
bars[selectedBarIndex], bars[selectedBarIndex - 1] = bars[selectedBarIndex - 1], bars[selectedBarIndex]
selectedBarIndex = selectedBarIndex - 1
frame:Refresh()
ns:RebuildAllFrames()
end)
moveUpBtn:SetPoint("LEFT", deleteBarBtn, "RIGHT", 1, 0)
local moveDownBtn = ns:CreateButton(rightPanel, "Dn", 44, function()
if not selectedGroupIndex or not selectedBarIndex then ns:Print("Select a bar first."); return end
local bars = BarWardenDB.frames[selectedGroupIndex].bars
if selectedBarIndex >= #bars then return end
bars[selectedBarIndex], bars[selectedBarIndex + 1] = bars[selectedBarIndex + 1], bars[selectedBarIndex]
selectedBarIndex = selectedBarIndex + 1
frame:Refresh()
ns:RebuildAllFrames()
end)
moveDownBtn:SetPoint("LEFT", moveUpBtn, "RIGHT", 1, 0)
local copyBarBtn = ns:CreateButton(rightPanel, "Dupe", 60, function()
if not selectedGroupIndex or not selectedBarIndex then ns:Print("Select a bar first."); return end
local bar = frame:GetSelectedBar()
if not bar then return end
ns.copiedBar = ns:CopyTable(bar)
ns:Print("Bar copied: " .. (bar.name or "unnamed"))
end)
copyBarBtn:SetPoint("LEFT", moveDownBtn, "RIGHT", 1, 0)
local pasteBarBtn = ns:CreateButton(rightPanel, "Paste", 60, function()
if not selectedGroupIndex then ns:Print("Select a group first."); return end
if not ns.copiedBar then ns:Print("Nothing to paste. Copy a bar first."); return end
local g = BarWardenDB.frames[selectedGroupIndex]
if not g then return end
local maxBars = ns.MAX_BARS_PER_FRAME or 30
if #g.bars >= maxBars then
ns:Print("Maximum of " .. maxBars .. " bars per group reached.")
return
end
local pasted = ns:CopyTable(ns.copiedBar)
pasted.name = (pasted.name or "Bar") .. " (paste)"
table.insert(g.bars, pasted)
selectedBarIndex = #g.bars
frame:Refresh()
ns:RebuildAllFrames()
ns:Print("Bar pasted: " .. pasted.name)
end)
pasteBarBtn:SetPoint("LEFT", copyBarBtn, "RIGHT", 1, 0)
-- ========================================================================
-- BAR EDITOR SUB-PANEL (scroll frame so content doesn't clip)
-- ========================================================================
-- The editor sits BELOW the bar list + buttons and spans the full page
-- width (stacked layout, uniform with the Groups tab). This keeps the
-- editor visible even at the smallest window size. It fills the remaining
-- height and reflows on resize.
local editorHeader = rightPanel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
editorHeader:SetPoint("TOPLEFT", addBarBtn, "BOTTOMLEFT", 0, -10)
editorHeader:SetText("Bar Settings")
local editorPanel = CreateFrame("Frame", nil, rightPanel)
editorPanel:SetPoint("TOPLEFT", editorHeader, "BOTTOMLEFT", 0, -6)
editorPanel:SetPoint("BOTTOMRIGHT", rightPanel, "BOTTOMRIGHT", 0, 0)
local editorScroll = CreateFrame("ScrollFrame", "BarWardenBarEditorScrollFrame", editorPanel, "UIPanelScrollFrameTemplate")
editorScroll:SetPoint("TOPLEFT", editorPanel, "TOPLEFT", 0, 0)
editorScroll:SetPoint("BOTTOMRIGHT", editorPanel, "BOTTOMRIGHT", -24, 0)
local ec = CreateFrame("Frame", nil, editorScroll) -- ec = editor content (scroll child)
ec:SetWidth(340) -- initial width; OnShow resizes to match the scroll viewport
-- Generous fallback height so the full single-column editor is always
-- reachable; fitEditorHeight() trims it to the real content once the editor
-- is first shown (a fixed 660 used to clip the lower half off the scroll).
ec:SetHeight(1100)
editorScroll:SetScrollChild(ec)
-- Bar name (first field, flush top to match group editor layout)
local barNameEdit = ns:CreateEditBox(ec, "", 130, function(self, text)
local bar = frame:GetSelectedBar()
if bar then
bar.name = text
frame:Refresh() -- updates the bar-list row on the left
ns:RefreshBarSettings()
end
end,
"A label for this bar, shown in the list and (if Show Bar Name is on) on "
.. "the bar itself.")
barNameEdit:SetPoint("TOPLEFT", ec, "TOPLEFT", 4, 0)
-- Stretch the name box to the editor width so it uses the space (reactive:
-- ec reflows to the viewport, and the RIGHT anchor follows). Right margin
-- matches the schema stretch pad so every field lines up on the right.
barNameEdit:SetPoint("RIGHT", ec, "RIGHT", -6, 0)
-- Bar enabled checkbox
local barEnabledCB = ns:CreateCheckbox(ec, "Enabled", "Enable or disable this bar", function(self, checked)
local bar = frame:GetSelectedBar()
if bar then
bar.enabled = checked
for _, liveBar in ipairs(ns:GetAllBars()) do
if liveBar.barData == bar then
if checked then
local visual = ns:GetVisual()
liveBar:SetAlpha(visual.inactiveAlpha or 0.3)
liveBar:Show()
else
ns:DeactivateBar(liveBar)
liveBar:Hide()
end
break
end
end
local gf = selectedGroupIndex and ns.groupFrames[selectedGroupIndex]
if gf then ns:UpdateGroupLayout(gf) end
end
end)
barEnabledCB:SetPoint("TOPLEFT", barNameEdit, "BOTTOMLEFT", -6, -4)
-- Spell Name / ID
local spellEdit = ns:CreateEditBox(ec, "Spell Name or ID", 130, function(self, text)
local bar = frame:GetSelectedBar()
if bar then
-- Clear all legacy fields so old values don't override the new one
bar.spell = nil
bar.spellInput = nil
local id = tonumber(text)
if id then
bar.spellId = id
bar.spellName = nil
else
bar.spellId = nil
bar.spellName = text
end
ns:RefreshBarSettings()
end
end,
"The spell, item, or totem this bar tracks. Accepts a spell name "
.. "(e.g. 'Evasion'), a numeric spell/item ID, or multiple "
.. "comma-separated names for one bar to match any of them "
.. "(e.g. 'Rupture, Garrote'). Press Enter to apply.")
spellEdit:SetPoint("TOPLEFT", barEnabledCB, "BOTTOMLEFT", 6, -18)
spellEdit:SetPoint("RIGHT", ec, "RIGHT", -6, 0) -- stretch to editor width
-- Single-column layout: Track Mode and Target stack vertically below
-- Spell. The -16 x offset on the dropdowns compensates for WoW's
-- invisible ~16 px left padding on UIDropDownMenu so the dropdown's
-- label aligns with the edit-box labels above.
-- Track Mode dropdown
local trackModeDD = ns:CreateDropdown(ec, "Track Mode", TRACK_MODES, function(dd, value, index)
local bar = frame:GetSelectedBar()
if bar then
bar.trackMode = value
frame:Refresh()
ns:RefreshBarSettings()
end
end,
"What this bar watches: a spell cooldown, buff, debuff, proc, item "
.. "cooldown, weapon enchant, totem, or a class resource.")
UIDropDownMenu_SetWidth(trackModeDD, 180)
trackModeDD:SetPoint("TOPLEFT", spellEdit, "BOTTOMLEFT", -16, -18)
-- Target dropdown
local targetDD = ns:CreateDropdown(ec, "Target", TARGET_UNITS, function(dd, value, index)
local bar = frame:GetSelectedBar()
if bar then
bar.unit = value
bar.target = nil -- clear legacy field so unit takes effect
frame:Refresh()
ns:RefreshBarSettings()
end
end,
"Whose buff or debuff this bar watches (you, your target, focus, pet, or "
.. "mouseover). Ignored for cooldowns and items.")
UIDropDownMenu_SetWidth(targetDD, 180)
targetDD:SetPoint("TOPLEFT", trackModeDD, "BOTTOMLEFT", 0, -18)
-- Only Mine checkbox: +16 x offset reverses the dropdown's -16 so
-- this aligns with barNameEdit / spellEdit on the left.
local onlyMineCB = ns:CreateCheckbox(ec, "Only Mine", "Only track auras cast by you", function(self, checked)
local bar = frame:GetSelectedBar()
if bar then
bar.onlyMine = checked
ns:RefreshBarSettings()
end
end)
onlyMineCB:SetPoint("TOPLEFT", targetDD, "BOTTOMLEFT", 16, -6)
-- ========================================================================
-- CONDITIONS + DISPLAY: declarative schema (ns:BuildSettings).
--
-- All entries use get/set closures (not db paths) because the target bar
-- is dynamic: it changes whenever the user selects a different bar in the
-- list. refreshEditorSettings() is called from UpdateBarEditor on every
-- bar selection change, re-reading all values from the new bar.
-- ========================================================================
local editorWidgets = {}
-- GetSelectedBar is defined later in CreateBarsTab. At BuildSettings
-- build time the method doesn't exist yet, so guard against nil.
local function getBar()
return frame.GetSelectedBar and frame:GetSelectedBar() or nil
end
local function getCond()
local bar = getBar()
return bar and (bar.conditions or {}) or {}
end
local function getDisp()
local bar = getBar()
return bar and (bar.display or {}) or {}
end
-- Factory: condition-toggle schema entry (1 line per checkbox)
local function condCheck(label, field, tip, extra)
local e = { type = "toggle", label = label, tooltip = tip,
get = function() return getCond()[field] end,
set = function(_, v)
local bar = getBar(); if not bar then return end
if not bar.conditions then bar.conditions = {} end
bar.conditions[field] = v
ns:RefreshBarSettings()
end,
spacing = 2 }
if extra then for k, v in pairs(extra) do e[k] = v end end
return e