Repository navigation
Expand file tree
/
Copy pathbars.lua
More file actions
2088 lines (1968 loc) · 86.4 KB
/
Copy pathbars.lua
File metadata and controls
2088 lines (1968 loc) · 86.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
------------------------------------------------------------------------------------
-- Module for all swing timer bar/widget code.
--
-- Contains:
-- - The function to initialise all the frames on addon load
-- - configuration functions that are used on init/setting change
-- - UIHANDLER objects to handle drag/drop etc behaviour
-- - OnUpdate scripts to handle the limited number of things that are
-- best done on a per-frame basis.
-- - functions to manipulate the widgets in predefined ways
------------------------------------------------------------------------------------
local addon_name, st = ...
-- Chat output policy: st.utils.print_msg (utils.lua) is the addon's single chat path,
-- and every message in this file names it explicitly. There is deliberately no local
-- alias for the client's raw global print here: a bare call to it would bypass the
-- addon's chat path, so the identifier is kept out of the file on purpose.
local LSM = LibStub("LibSharedMedia-3.0")
---@type LibCustomGlow
local LCG = LibStub("LibCustomGlow-1.0")
local floor = math.floor
local max = math.max
local format = string.format
---@class ST: AceAddon
---@field get_hand_table fun(self: ST, hand: string): table
---@field get_class_table fun(self: ST): table
---@field options_table_name string
---@field player_class string
---@field target_min_range any
---@field target_max_range any
---@field db table
---@field latency table
---@field gcd table
---@field is_cat_or_bear boolean
---@field convert_color fun(self: ST, t: table, new_alpha: number?): number, number, number, number
local ST = LibStub("AceAddon-3.0"):GetAddon(addon_name)
local LWIN = LibStub("LibWindow-1.1")
-- A statusbar texture fetch must never leave a bar textureless. LibSharedMedia's
-- Fetch legitimately returns nil (the key is not in the registry - a registration
-- that failed on this client - or the registered path is empty), and a nil texture
-- is an INVISIBLE bar. The chain degrades instead of giving up: the requested key ->
-- the shipped fallback key ("Minimalist", registered in main.lua) -> the client's own
-- white pixel. The fetch is pcall-guarded too, so a throwing media library cannot
-- abort the configuration pass and leave the bar without a texture.
local FALLBACK_STATUSBAR_KEY = "Minimalist"
local CLIENT_WHITE_PIXEL = "Interface\\Buttons\\WHITE8X8"
local function fetch_statusbar_texture(key)
local ok, texture = pcall(LSM.Fetch, LSM, 'statusbar', key)
if not ok or texture == nil then
local ok_fallback, fallback = pcall(LSM.Fetch, LSM, 'statusbar', FALLBACK_STATUSBAR_KEY)
if ok_fallback and fallback ~= nil then
texture = fallback
else
texture = CLIENT_WHITE_PIXEL
end
end
return texture
end
-- Initialize hand tables
ST.mainhand = {}
ST.offhand = {}
ST.ranged = {}
--=========================================================================================
-- Intialisation func (called once relevant libs are loaded once per hand)
--=========================================================================================
function ST:init_visuals_template(hand)
-- Get the relevant db table.
local db = self:get_hand_table(hand)
-- Initialize GCD state table if not already present.
if not self.gcd then
self.gcd = {
expires = 0,
gcd1_phys_time_before_swing = 0,
gcd1_spell_time_before_swing = 0,
}
end
-- Initialize form tracking field if not already present.
if self.is_cat_or_bear == nil then
self.is_cat_or_bear = false
end
-- Make the anchor frame, which is the top-level parent of the bar
-- visual frames in our addon, and set its initial size/position properties.
local anchor_frame = CreateFrame(
"Frame",
addon_name .. "_" .. hand .. "_" .. "AnchorFrame",
UIParent
)
self[hand].anchor_frame = anchor_frame
-- Configure drag and drop handlers with LibWindow, adding a callback
-- to the config menu to let the panel know the coords have changed.
LWIN.RegisterConfig(anchor_frame, db)
anchor_frame:RegisterForDrag("LeftButton")
anchor_frame:SetScript("OnDragStart", function()
LWIN.OnDragStart(anchor_frame)
end
)
anchor_frame:SetScript("OnDragStop", function()
LWIN.OnDragStop(anchor_frame)
local ACR = LibStub("AceConfigRegistry-3.0")
ACR:NotifyChange(self.options_table_name)
end
)
-- Make a frame, also the size of the anchor, that will receive
-- calls to show and hide the bar, so other addons like WeakAuras
-- can anchor to this frame and respect show/hide but not our bar's
-- dim settings.
local hiding_anchor_frame = CreateFrame(
"Frame",
addon_name .. "_" .. hand .. "_" .. "HidingAnchorFrame",
anchor_frame
)
anchor_frame.hiding_anchor_frame = hiding_anchor_frame
-- Make a frame to house the bar components in full.
-- This frame has to inherit from BackdropTemplate.
local bar_frame = CreateFrame(
"Frame",
addon_name .. "_" .. hand .. "_" .. "TimerFrame",
anchor_frame,
"BackdropTemplate"
)
anchor_frame.bar_frame = bar_frame
-- Now make a frame to house the progress bar components
local visuals_frame = CreateFrame(
"Frame",
nil,
bar_frame
)
bar_frame.visuals_frame = visuals_frame
-- Create the swing timer bar texture
visuals_frame.bar = visuals_frame:CreateTexture(nil, "ARTWORK")
visuals_frame.bar:SetPoint("TOPLEFT", 0, 0)
-- Create the GCD timer bar
visuals_frame.gcd_bar = visuals_frame:CreateTexture(nil, "ARTWORK")
visuals_frame.gcd_bar:Hide()
-- Create the deadzone bar
visuals_frame.deadzone = visuals_frame:CreateTexture(nil, "ARTWORK")
-- Create the spark texture (visual brainstorm item 1)
visuals_frame.spark = visuals_frame:CreateTexture(nil, "OVERLAY")
visuals_frame.spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
if visuals_frame.spark.SetBlendMode then
visuals_frame.spark:SetBlendMode("ADD")
end
visuals_frame.spark:Hide()
-- Create the completion flash overlay (visual brainstorm item 2)
visuals_frame.flash = visuals_frame:CreateTexture(nil, "OVERLAY")
visuals_frame.flash:SetAllPoints(visuals_frame)
if visuals_frame.flash.SetColorTexture then
visuals_frame.flash:SetColorTexture(1, 1, 1, 1)
else
visuals_frame.flash:SetTexture("Interface\\Buttons\\WHITE8X8")
visuals_frame.flash:SetVertexColor(1, 1, 1, 1)
end
if visuals_frame.flash.SetBlendMode then
visuals_frame.flash:SetBlendMode("ADD")
end
visuals_frame.flash:Hide()
-- Create the attack speed/swing timer texts and init them
visuals_frame.left_text = visuals_frame:CreateFontString(nil, "OVERLAY")
visuals_frame.center_text = visuals_frame:CreateFontString(nil, "OVERLAY")
visuals_frame.right_text = visuals_frame:CreateFontString(nil, "OVERLAY")
-- Create the line markers
visuals_frame.gcd1a_marker = visuals_frame:CreateLine()
visuals_frame.gcd1b_marker = visuals_frame:CreateLine()
self:configure_frame_strata(hand)
self:configure_draw_layers(hand)
self:configure_bar_size_and_positions(hand)
self:configure_bar_outline(hand)
self:configure_bar_appearances(hand)
self:configure_deadzone(hand)
self:set_deadzone_width(hand)
self:configure_texts(hand)
self:configure_gcd_markers(hand)
end
--=========================================================================================
-- HU-22 lazy bars: a swing hand's frames exist only when the bar is enabled AND the
-- hand is in use. Frames are built once through ST:ensure_bar(hand) and never
-- destroyed (unequip / switch-off hides through the existing visibility paths, which
-- live in main.lua and already treat a disabled bar as hidden). Until the build
-- points land (init / equip / option-on, owned by the engine lane's main.lua
-- half), every getter and per-hand consumer below treats "not built" exactly like
-- a disabled bar: no show, no update, no text, no error.
--=========================================================================================
function ST:bar_is_built(hand)
-- Built-state is the full frame chain (never the option/weapon gate, which
-- ensure_bar owns): init-built hands read true, a hand whose frames were
-- never created reads false, and no caller can nil-index through it. The
-- visuals frame is the read because it is what every per-hand consumer
-- touches - an anchor without its children still reads unbuilt.
return self:get_visuals_frame(hand) ~= nil
end
function ST:ensure_bar(hand)
-- One idempotent constructor for a hand's frames. The gate is exactly
-- db.enabled AND (mainhand OR has_weapon); mainhand.has_weapon is
-- permanently true (main.lua), so the mainhand gate reduces to db.enabled.
-- A second call builds nothing; a gated-off call builds nothing and
-- reports false so the caller skips the rest of the per-hand init.
if self:bar_is_built(hand) then
return true
end
local ok, db = pcall(self.get_hand_table, self, hand)
if not ok or type(db) ~= "table" or not db.enabled then
return false
end
if hand ~= "mainhand" then
local state = self[hand]
if type(state) ~= "table" or not state.has_weapon then
return false
end
end
self:init_visuals_template(hand)
self:set_bar_texts(hand)
return true
end
------------------------------------------------------------------------------------
-- Bar configuration functions (called on frame inits and setting changes)
-- These all operate on a given hand.
------------------------------------------------------------------------------------
function ST:configure_draw_layers(hand)
if not self:bar_is_built(hand) then
return
end
-- Sets the draw layers within the visuals frame for the swing timer
-- bar sub-components.
local f = self:get_visuals_frame(hand)
if not f then return end
if f.gcd_bar then f.gcd_bar:SetDrawLayer("ARTWORK", -2) end
if f.deadzone then f.deadzone:SetDrawLayer("ARTWORK", -1) end
if f.gcd1a_marker then f.gcd1a_marker:SetDrawLayer("OVERLAY", -1) end
if f.gcd1b_marker then f.gcd1b_marker:SetDrawLayer("OVERLAY", -1) end
end
-- width_override / height_override are for per-hand layout policies that must resize a
-- hand without writing its saved bar_width/bar_height (the hunter melee stack: the MH/OH
-- bars follow the ranged bar's width). They change only this pass's geometry; the saved
-- keys are the authority again on the next call without an override, which is exactly how
-- the stack toggle restores the user's own size.
--
-- Offhand size invariant (operator order 2026-10-28: "off hand should be same size as
-- mh", for every class): the offhand is the same bar one hand later, so its rendered
-- width and height are the MAINHAND's on every pass - not its own saved keys. A profile
-- saved before this rule (or an offhand key left at an old default) can therefore never
-- leave the two hands different sizes. An explicit override still wins for that pass,
-- because a layout policy (the hunter stack) owns the whole row while it applies.
--
-- Melee pair height (operator order 2026-10-28: "off hand should always be same width as
-- main hand. maybe have it so u can adjust the height for both"): ONE class-level key,
-- `melee_bar_height` (documented in config_presets.lua as a comment because nil is its
-- shipped value - AceDB stores no default for it). While it is a positive number BOTH
-- melee hands render at exactly that height, which makes the offhand-follows-mainhand
-- rule trivially true for the pair; nil, false or any non-positive value keeps the
-- shipped behaviour (each hand's own bar_height, offhand following the mainhand's
-- effective height). The ranged hand is never part of the pair, and an explicit per-pass
-- height override still wins (a layout policy owns the whole row while it applies).
function ST:melee_pair_height()
local class_db = self:get_class_table()
if type(class_db) ~= "table" then
return nil
end
-- rawget, NOT a plain read: AceDB gives every class row a '**' metatable whose __index
-- CREATES a defaults-filled sub-table and rawsets it for any missing key
-- (Libs/AceDB-3.0/AceDB-3.0.lua:88-107). A plain read here would persist a junk
-- melee_bar_height table in SavedVariables on the first layout pass.
-- tonumber() reads false (the "use each hand's own height" reset in the options) and
-- any junk as nil, so the nil-safe gate is one comparison.
local height = tonumber(rawget(class_db, "melee_bar_height"))
if height == nil or height <= 0 then
return nil
end
return height
end
function ST:hand_bar_size(hand, width_override, height_override)
local db = self:get_hand_table(hand)
if type(db) ~= "table" then
return nil, nil
end
local width_override_on = type(width_override) == "number" and width_override > 0
local height_override_on = type(height_override) == "number" and height_override > 0
-- The melee pair height is authoritative for the two melee hands only.
local pair_height = nil
if hand == "mainhand" or hand == "offhand" then
pair_height = self:melee_pair_height()
end
local bar_width = width_override_on and width_override or db.bar_width
local bar_height = height_override_on and height_override or pair_height or db.bar_height
if hand == "offhand" then
local mainhand = self:get_hand_table("mainhand")
if type(mainhand) == "table" then
if not width_override_on and type(mainhand.bar_width) == "number" then
bar_width = mainhand.bar_width
end
if not height_override_on then
-- The mainhand's EFFECTIVE height: the pair height when set, else its own
-- saved key. Reading the raw key here would silently undo the pair.
bar_height = pair_height
or ((type(mainhand.bar_height) == "number") and mainhand.bar_height or bar_height)
end
end
end
return bar_width, bar_height
end
--=========================================================================================
-- Ranged row placement policy (operator order 2026-10-28; brief ranged-forced)
--
-- The slot directly below the bottom-most melee row belongs to the POWER BAR
-- (power_bar.lua: "ranged bar shouldnt be below mh/oh bar because thats where power bar
-- should be for each class"). The ranged hand is a separate widget and must never sit in
-- that row. A FRESH profile ships above the melee stack, but AceDB never rewrites a saved
-- key: a profile created before that default move (or one whose row the user dragged or
-- scaled) keeps a legacy row. The operator's ruling of 2026-10-28 closes that: the ranged
-- bar "should stay with the rest, aka the new way" - a legacy saved position does not win.
--
-- The rule (ST:migrate_ranged_placement, called once from main.lua's OnInitialize before
-- any frame or options table exists) therefore NORMALISES the ranged row to the new
-- layout for EVERY class that owns a ranged hand:
-- * the anchor becomes x = 0, point = CENTER, scale = 1 (the shipped LibWindow anchor),
-- so a legacy drag and a legacy scale are replaced, not preserved;
-- * y becomes the class's shipped ranged row when that row clears the melee stack and
-- the power slot by RANGED_PLACEMENT_GAP, else the lowest integer y that clears them -
-- the same row a fresh profile gets, so a migrated row never lands between two
-- layouts;
-- * the band is read from the melee rows' own SAVED geometry (melee_reserved_band),
-- including a dragged anchor point or a scale, so a profile whose melee row was
-- dragged still gets the ranged row above the stack instead of being skipped;
-- * the row is written only while it is not already exactly the target row, so a fresh
-- profile is never touched (AceDB's own defaults already ARE the new layout) and
-- nothing is rewritten after the first pass;
-- * a per-class profile latch, stored as the rule's VERSION, makes it a once-per-profile
-- pass: no per-tick work, no geometry hopping, at most one notice per class per
-- session, and a drag made AFTER the pass is never fought.
-- The version matters: the first, weaker pass (version 1, stored as `true`) skipped a
-- dragged/scaled row, so a profile that already ran it is evaluated exactly once more
-- under this ruling and then latched at the current version - otherwise the operator's own
-- profile would keep its legacy row forever.
--=========================================================================================
-- Latch, per profile (the appearance migration's shape: config.lua owns that precedent).
ST.RANGED_PLACEMENT_FLAG = "ranged_placement_213"
-- The placement rule's own version. 1 was the first pass (shipped-default rows only, a
-- drag won); 2 is this forced pass. Any other stored value - including the `true` the
-- first pass wrote - is evaluated exactly once more, then latched here.
ST.RANGED_PLACEMENT_VERSION = 2
-- The shipped LibWindow anchor of an untouched row (ST.bar_defaults in config_presets.lua).
ST.SHIPPED_HAND_X = 0
ST.SHIPPED_HAND_POINT = "CENTER"
ST.SHIPPED_HAND_SCALE = 1
-- Clearance kept between the ranged row and the band it must not enter (px).
ST.RANGED_PLACEMENT_GAP = 2
-- One saved row's vertical extent (top, bottom) in the db's own units, read from the row's
-- LibWindow anchor. LibWindow-1.1 stores the offset of the ANCHORED EDGE from the same edge
-- of the parent (LibWindow-1.1.lua SavePosition/RestorePosition; the bar anchor frame's
-- parent is UIParent, so the stored units are UIParent units), which means a TOP row's
-- saved y IS its top edge, a BOTTOM row's saved y is its bottom edge, and every other
-- point (CENTER/LEFT/RIGHT) stores the vertical centre. The row is as tall as the hand
-- renders (hand_bar_size) times the row's scale, because LibWindow scales the anchor
-- frame - so a dragged anchor and a scaled row are read at their real size instead of
-- being refused. nil only when the row is missing or its y/height is unreadable: the
-- anchor point is never guessed, because every point LibWindow can save has a defined
-- vertical edge.
function ST:saved_row_extent(hand)
local db = self:get_hand_table(hand)
if type(db) ~= "table" then
return nil
end
local y = tonumber(db.y)
local _, height = self:hand_bar_size(hand)
height = tonumber(height)
if y == nil or height == nil or height <= 0 then
return nil
end
local scale = tonumber(db.scale)
if scale == nil or scale <= 0 then
-- LibWindow restores a missing/garbage scale with the frame's own (1 at creation).
scale = 1
end
local row_height = height * (scale or 0)
local vertical = nil
if type(db.point) == "string" then
vertical = db.point:match("^TOP") or db.point:match("^BOTTOM")
end
if vertical == "TOP" then
return y, y - row_height
end
if vertical == "BOTTOM" then
return y + row_height, y
end
return y + (row_height / 2), y - (row_height / 2)
end
-- The enabled-hand signature, stored beside the version latch under its own key (the
-- version latch keeps its historical numeric shape, so every pinned assertion and every
-- saved profile keeps reading the same value). It exists because shipping
-- `offhand.enabled = false` CHANGES the reserved band: the version latch alone would keep
-- a profile latched forever and the ranged row would never be re-checked against the new
-- hand set. The signature is the set of hands whose bar is switched on, in the class's
-- own hand order, joined by "+".
ST.RANGED_PLACEMENT_HANDS_FLAG = "ranged_placement_hands"
-- One hand's saved row participates in the reserved band only while its bar is switched
-- on: a disabled hand has no frames and no fill (HU-22 lazy bars), so reserving its stale
-- row would push the ranged bar above empty space. `~= false` is deliberate - a profile
-- saved before the key existed has no value there and keeps the old reserved-row reading.
function ST:hand_row_is_reserved(hand)
local db = self:get_hand_table(hand)
return type(db) == "table" and db.enabled ~= false
end
-- The enabled-MELEE-hand signature (see RANGED_PLACEMENT_HANDS_FLAG): exactly the hands
-- that feed the reserved band, so a change in the set is a change in what the ranged row
-- has to clear. The ranged hand is excluded on purpose - it is the row being placed, and
-- whether its own bar is switched on must not force a re-check. Iterates the class hand
-- set, so it needs no class name and no frame: it is safe at OnInitialize, before any
-- frame or options table exists.
function ST:ranged_placement_signature()
local parts = {}
for hand in self:iter_hands() do
if hand ~= "ranged" and self:hand_row_is_reserved(hand) then
parts[#parts + 1] = hand
end
end
return table.concat(parts, "+")
end
-- Does the class render ANY melee row? A caster class ships `mainhand.enabled = false`
-- and owns no offhand, so it has no stack to clear - the ranged row is then placed by the
-- class's own shipped row alone, never refused as "unknown". Used to tell "there is no
-- melee row" apart from "a melee row exists but cannot be read".
function ST:has_reserved_melee_row()
for hand in self:iter_hands() do
if hand ~= "ranged" and self:hand_row_is_reserved(hand) then
return true
end
end
return false
end
-- The band the ranged row must stay out of: the melee stack (every owned hand except the
-- ranged one) plus the power-bar slot hanging under its bottom edge. Returns (top, bottom),
-- or nil when any involved row is unreadable or the class has no melee row. The extents
-- come from the rows' SAVED geometry (saved_row_extent), so a dragged or scaled melee row
-- is read at its real position and the rule still lands the ranged row above the stack.
function ST:melee_reserved_band()
local top, bottom
for hand in self:iter_hands() do
if hand ~= "ranged" and self:hand_row_is_reserved(hand) then
local row_top, row_bottom = self:saved_row_extent(hand)
if row_top == nil or row_bottom == nil then
return nil
end
if top == nil or row_top > top then
top = row_top
end
if bottom == nil or row_bottom < bottom then
bottom = row_bottom
end
end
end
if top == nil or bottom == nil then
return nil
end
-- The power slot: one gap under the bottom-most melee row, at the class's own height.
-- power_bar.lua is loaded after this file in the TOC, so the module is read at call
-- time (a sandbox without it keeps the shipped constants). The slot is reserved even
-- while the power bar itself is switched off: the operator's rule is about the row,
-- and a reserved slot cannot start colliding when the bar is switched back on.
local gap = ST.RANGED_PLACEMENT_GAP
local power_height = 14
local pb = rawget(st, "power_bar")
if type(pb) == "table" then
if tonumber(pb.GAP) ~= nil then
gap = tonumber(pb.GAP)
end
if type(pb.height_for) == "function" then
local ok, height = pcall(pb.height_for, self:get_class_table())
if ok and tonumber(height) ~= nil then
power_height = tonumber(height)
end
end
end
return top, bottom - (gap or 0) - (power_height or 0)
end
-- Does a row (top, bottom) intersect a band (band_top, band_bottom)? Touching edges do not
-- intersect; only a real overlap counts, so a row parked exactly one gap away is left alone.
function ST:row_intersects_band(row_top, row_bottom, band_top, band_bottom)
if type(row_top) ~= "number" or type(row_bottom) ~= "number" then
return false
end
if type(band_top) ~= "number" or type(band_bottom) ~= "number" then
return false
end
return row_top > band_bottom and row_bottom < band_top
end
-- The class's shipped ranged y (its own default, else the shared bar default), or nil when
-- the assembled defaults are unreadable. Read-only: the defaults table is never mutated.
function ST:shipped_ranged_y()
local defaults = self.defaults
local profile_defaults = type(defaults) == "table" and defaults.profile or nil
local class_defaults = type(profile_defaults) == "table"
and profile_defaults[self.player_class] or nil
if type(class_defaults) ~= "table" then
return nil
end
local ranged_defaults = class_defaults.ranged
if type(ranged_defaults) == "table" and tonumber(ranged_defaults.y) ~= nil then
return tonumber(ranged_defaults.y)
end
local bar_defaults = class_defaults["**"]
if type(bar_defaults) == "table" then
return tonumber(bar_defaults.y)
end
return nil
end
-- The one-time rule. Returns an outcome token (tests pin it, and the bench report quotes
-- it): "moved" | "kept" | "done" | "no-ranged" | "unknown". Only "moved" writes a position,
-- and the version latch is written BEFORE the geometry is read, so every outcome - an
-- unreadable layout included - is evaluated at most once and an unreadable layout is left
-- alone for good, because the user owns it. The latch lives on the CLASS row, not on the
-- profile: the rows being corrected are the class's own, so a second class in the same
-- profile must still get its own evaluation. `profile` is the profile table the addon runs
-- on (main.lua passes get_profile_table()); the geometry is read back through
-- get_hand_table, which is the same row in production.
--
-- THE LATCH MUST BE READ WITH rawget. AceDB gives the profile root and every class row a
-- '**' metatable whose __index CREATES a defaults-filled sub-table and rawsets it for any
-- missing key (Libs/AceDB-3.0/AceDB-3.0.lua:88-107). A plain `class_row[flag]` read would
-- therefore be truthy on the first login, would persist a junk table in SavedVariables and
-- would make the rule dead exactly as production runs it. The class row itself is only
-- trusted when the shipped defaults name it (a real class); an unsupported class answers
-- "unknown" instead of writing a phantom row.
function ST:migrate_ranged_placement(profile)
if type(profile) ~= "table" then
return "unknown"
end
local defaults = self.defaults
local profile_defaults = type(defaults) == "table" and defaults.profile or nil
if type(profile_defaults) ~= "table" or type(profile_defaults[self.player_class]) ~= "table" then
return "unknown"
end
local class_row = rawget(profile, self.player_class)
if type(class_row) ~= "table" then
return "unknown"
end
-- The exact VERSION, not a truthy read: a profile that ran the first, weaker pass holds
-- `true` and must be evaluated once more under this ruling (the operator's own profile
-- is exactly that case), while a profile that already ran this pass holds the number
-- and is never touched again.
--
-- The HAND SIGNATURE rides beside the version. The version alone latches a profile
-- forever, so a change to which hands are switched on (the shipped
-- `offhand.enabled = false` is exactly that) would never be re-checked against the
-- reserved band. A stored signature means this class already ran the enforced pass, so
-- a later pass is a RE-CHECK, not a first placement: it only moves a row that actually
-- sits in the band, and never fights a drag that is already clear (the standing
-- "a drag made AFTER the pass is never fought" contract). A profile with no stored
-- signature is the first enforced pass and keeps the operator's FORCED behaviour.
local signature = self:ranged_placement_signature()
local stored_version = rawget(class_row, ST.RANGED_PLACEMENT_FLAG)
local stored_signature = rawget(class_row, ST.RANGED_PLACEMENT_HANDS_FLAG)
if stored_version == ST.RANGED_PLACEMENT_VERSION and stored_signature == signature then
return "done"
end
local re_evaluating = stored_version == ST.RANGED_PLACEMENT_VERSION
and stored_signature ~= nil
-- Both latches are written BEFORE the geometry is read, so every outcome - an
-- unreadable layout included - is evaluated at most once per hand set.
class_row[ST.RANGED_PLACEMENT_FLAG] = ST.RANGED_PLACEMENT_VERSION
class_row[ST.RANGED_PLACEMENT_HANDS_FLAG] = signature
if not self:has_hand("ranged") then
-- Paladin/shaman/druid have no ranged bar at all (main.lua class_hands): there is
-- nothing to place. The check is the hand set, never the class name, so a class
-- that ever gains a ranged bar picks the rule up with no edit here.
return "no-ranged"
end
-- rawget: a plain read of a missing hand row would CREATE a defaults table through the
-- class row's '**' metatable (AceDB-3.0.lua:88-107) and persist it. A ranged-owning
-- class always has the row, because the shipped defaults name it.
local ranged = rawget(class_row, "ranged")
if type(ranged) ~= "table" then
return "unknown"
end
local band_top, band_bottom = self:melee_reserved_band()
local _, ranged_height = self:hand_bar_size("ranged")
ranged_height = tonumber(ranged_height)
if ranged_height == nil or ranged_height <= 0 then
return "unknown"
end
-- The new layout's row: the class's own shipped ranged y when it clears the band by
-- RANGED_PLACEMENT_GAP, else the lowest integer y that does - the same arithmetic a
-- fresh profile ships, so a migrated row lands exactly where a new one starts.
local target
if band_top == nil or band_bottom == nil then
-- An unreadable band is only acceptable when there is no melee row to clear. A
-- class that renders NO melee bar (every caster class ships mainhand.enabled
-- false) has nothing to collide with, so the shipped ranged row is the whole rule.
-- A reserved melee row that merely could not be READ stays "unknown": no guess.
if self:has_reserved_melee_row() then
return "unknown"
end
target = self:shipped_ranged_y()
else
local minimum = band_top + ST.RANGED_PLACEMENT_GAP + (ranged_height / 2)
target = self:shipped_ranged_y()
if target == nil or target < minimum then
target = math.ceil(minimum)
end
end
if target == nil then
return "unknown"
end
-- Already the target row: no write and no notice. This is every fresh profile (AceDB
-- filled the shipped row, which is the new layout) and every profile this pass already
-- moved, so a login never rewrites a row that is already right.
if tonumber(ranged.x) == ST.SHIPPED_HAND_X
and tonumber(ranged.y) == target
and ranged.point == ST.SHIPPED_HAND_POINT
and tonumber(ranged.scale) == ST.SHIPPED_HAND_SCALE then
return "kept"
end
-- Why the row moves, for the notice: a row whose SAVED extent sits inside the reserved
-- band was occupying the power-bar slot; anything else is a legacy drag/scale that the
-- new layout replaces. Read before the write, from the row's own geometry.
local row_top, row_bottom = self:saved_row_extent("ranged")
local was_in_band = self:row_intersects_band(row_top, row_bottom, band_top, band_bottom)
-- A signature re-check only corrects a row the new hand set put IN the band. A row the
-- user dragged somewhere clear stays exactly where the user put it.
if re_evaluating and not was_in_band then
return "kept"
end
ranged.x = ST.SHIPPED_HAND_X
ranged.y = target
ranged.point = ST.SHIPPED_HAND_POINT
ranged.scale = ST.SHIPPED_HAND_SCALE
-- No silent paths: the rule changed a saved position, so say so ONCE. Best-effort
-- through the addon's single chat path (utils.print_msg) and pcall'd: a missing/broken
-- chat frame must never undo the placement or throw out of login.
if type(st.utils) == "table" and type(st.utils.print_msg) == "function" then
local notice
if was_in_band then
notice = "the ranged bar was moved above the melee bars (that row belongs to "
.. "the power bar). Drag it to reposition it; your position is never "
.. "changed again."
else
notice = "the ranged bar was placed in the standard layout above the melee "
.. "bars. Drag it to reposition it; your position is never changed again."
end
pcall(st.utils.print_msg, notice)
end
return "moved"
end
function ST:configure_bar_size_and_positions(hand, width_override, height_override)
if not self:bar_is_built(hand) then
return
end
local db = self:get_hand_table(hand)
if type(db) ~= "table" then
return
end
local bar_width, bar_height = self:hand_bar_size(hand, width_override, height_override)
-- First set the anchor frame and bar frames
-- to the full size in the settings, and restore their
-- positions with LibWindow
local anchor_frame = self:get_anchor_frame(hand)
if anchor_frame then
anchor_frame:ClearAllPoints()
anchor_frame:SetWidth(bar_width)
anchor_frame:SetHeight(bar_height)
LWIN.RestorePosition(anchor_frame)
anchor_frame:Show()
end
-- And also the hiding anchor frame.
local hiding_anchor_frame = self:get_hiding_anchor_frame(hand)
if hiding_anchor_frame then
hiding_anchor_frame:ClearAllPoints()
hiding_anchor_frame:SetPoint("CENTER")
hiding_anchor_frame:SetWidth(bar_width)
hiding_anchor_frame:SetHeight(bar_height)
hiding_anchor_frame:Show()
end
-- Might need to set the width/height of the bar_frame too
local bar_frame = self:get_bar_frame(hand)
if bar_frame then
bar_frame:ClearAllPoints()
bar_frame:SetPoint("CENTER")
bar_frame:SetWidth(bar_width)
bar_frame:SetHeight(bar_height)
end
-- For the visuals frame, we calculate a reduced size
-- based on the backplane settings.
-- Set it internally for use elsewhere
local visuals_frame = self:get_visuals_frame(hand)
local vf_width = bar_width - (db.border_width * 2)
local vf_height = bar_height - (db.border_width * 2)
if self[hand] then
self[hand].vf_width = vf_width
self[hand].vf_height = vf_height
end
if visuals_frame then
visuals_frame:SetHeight(vf_height)
visuals_frame:SetWidth(vf_width)
-- And set the subcomponent anchors (where appropriate)
-- and sizes.
if visuals_frame.bar then
visuals_frame.bar:SetPoint("TOPLEFT", 0, 0)
visuals_frame.bar:SetHeight(vf_height)
-- A resize is not a progress reset (2026-10-28, hunter mainhand report: "the
-- bar stays full ... it never starts"). The tick owns the fill width and
-- paints it from the live progress; this function runs BETWEEN two ticks
-- whenever a layout policy re-applies a hand (the hunter melee stack sizes
-- the melee bars from the ranged bar on every pass). Painting the fill full
-- here left a full-width fill owning the rest of the cycle - the fill texture
-- then showed the tick's cropped TexCoord stretched across the whole bar,
-- which reads exactly like a bar that never animates. Repaint the hand's own
-- progress instead, so a configure pass cannot outlive one frame. A fresh
-- hand (or one whose state has no progress yet) keeps the full-width
-- default; its first tick paints the real value.
local progress
local state = self[hand]
if type(state) == "table" then
progress = tonumber(state.current_progress)
end
if progress ~= nil then
if progress < 0 then
progress = 0
elseif progress > 1 then
progress = 1
end
visuals_frame.bar:SetWidth(max(1, vf_width * progress))
visuals_frame.bar:SetTexCoord(0, progress, 0, 1)
else
visuals_frame.bar:SetWidth(vf_width)
end
end
if visuals_frame.gcd_bar then
visuals_frame.gcd_bar:SetHeight(vf_height)
end
if visuals_frame.deadzone then
visuals_frame.deadzone:SetHeight(vf_height)
visuals_frame.deadzone:SetPoint("TOPRIGHT")
end
visuals_frame:ClearAllPoints()
visuals_frame:SetPoint("CENTER")
end
self:configure_texts(hand)
self:configure_gcd_markers(hand)
self:configure_bar_outline(hand)
-- A mainhand size change IS an offhand size change (the invariant above), and the
-- options call this for one hand only, so re-apply the paired hand here. Guarded on
-- no override: a layout policy pass (the hunter stack) sizes both hands itself.
if hand == "mainhand" and width_override == nil and height_override == nil
and self:bar_is_built("offhand") then
self:configure_bar_size_and_positions("offhand")
end
end
function ST:configure_frame_strata(hand)
if not self:bar_is_built(hand) then
return
end
local frame = self:get_bar_frame(hand)
-- Draw level and frame strata are profile-wide settings: config.lua ships both in
-- ST.defaults.profile and the strata option setter writes them through
-- get_profile_table. They are not per-hand keys (AceDB expands the hand tables from
-- ST.bar_defaults, which carries neither), so reading them off the hand table made
-- db.draw_level nil here - a nil-arithmetic crash in init_timers -> init_libs on
-- every fresh profile (see tests/bars_state.lua, which reproduces it).
local db = self:get_profile_table()
if frame and db and db.draw_level then
frame:SetFrameLevel(db.draw_level + 1)
if db.frame_strata then
frame:SetFrameStrata(db.frame_strata)
end
end
end
function ST:configure_bar_appearances(hand)
if not self:bar_is_built(hand) then
return
end
-- COnfigure textures/colors for bar and GCD underlay
local frame = self:get_visuals_frame(hand)
local db = self:get_hand_table(hand)
if not frame or not db then
return
end
if frame.bar then
frame.bar:SetTexture(fetch_statusbar_texture(db.bar_texture_key))
end
if frame.gcd_bar then
frame.gcd_bar:SetTexture(fetch_statusbar_texture(db.gcd_texture_key))
frame.gcd_bar:SetVertexColor(
self:convert_color(db.bar_color_gcd)
)
end
self:set_bar_color(hand)
end
function ST:configure_gcd_markers(hand)
if not self:bar_is_built(hand) then
return
end
-- Configure textures and marker widths.
local db = self:get_hand_table(hand)
local f = self:get_visuals_frame(hand)
if not f or not db then
return
end
if f.gcd1a_marker then
f.gcd1a_marker:SetColorTexture(
self:convert_color(db.gcd1a_marker_color)
)
f.gcd1a_marker:SetThickness(db.gcd1a_marker_width or 1)
end
if f.gcd1b_marker then
f.gcd1b_marker:SetColorTexture(
self:convert_color(db.gcd1b_marker_color)
)
f.gcd1b_marker:SetThickness(db.gcd1b_marker_width or 1)
end
end
function ST:configure_deadzone(hand)
if not self:bar_is_built(hand) then
return
end
local db = self:get_hand_table(hand)
local vf = self:get_visuals_frame(hand)
local f = vf and vf.deadzone
if not f or not db then
return
end
if not db.enable_deadzone then
f:Hide()
else
f:Show()
end
f:SetTexture(fetch_statusbar_texture(db.deadzone_texture_key))
f:SetVertexColor(
self:convert_color(db.deadzone_bar_color)
)
end
function ST:configure_texts(hand)
if not self:bar_is_built(hand) then
return
end
local db = self:get_hand_table(hand)
local frame = self:get_visuals_frame(hand)
if not frame or not db then
return
end
local font_path = st.utils.fetch_font_path(db.text_font)
local outlines = {
none = "",
outline = "OUTLINE",
thickoutline = "THICKOUTLINE",
monochrome = "MONOCHROME",
}
local opt_string = outlines[db.text_outline_key]
local w, h = self:get_bar_visuals_width_and_height(hand)
-------------------------------------
-- Left text
-------------------------------------
if frame.left_text then
local left_text_x_offset = ((db.left_text_x_percent_offset + 1)/ 100) * w
local left_text_y_offset = ((db.left_text_y_percent_offset - 1)/ 100) * h
frame.left_text:SetPoint(
"LEFT",
left_text_x_offset,
left_text_y_offset
)
st.utils.apply_font(frame.left_text, font_path, db.text_size, opt_string)
frame.left_text:SetTextColor(
self:convert_color(db.text_color)
)
if db.left_text_enabled then
frame.left_text:Show()
else
frame.left_text:Hide()
end
end
-------------------------------------
-- Center text
-------------------------------------
if frame.center_text then
local center_text_x_offset = ((db.center_text_x_percent_offset + 1)/ 100) * w
local center_text_y_offset = ((db.center_text_y_percent_offset - 1)/ 100) * h
frame.center_text:SetPoint(
"CENTER",
center_text_x_offset,
center_text_y_offset
)
st.utils.apply_font(frame.center_text, font_path, db.text_size, opt_string)
frame.center_text:SetTextColor(
select(1, self:convert_color(db.text_color))
)
if db.center_text_enabled then
frame.center_text:Show()
else
frame.center_text:Hide()
end
end
-------------------------------------
-- Right text
-------------------------------------
if frame.right_text then
local right_text_x_offset = ((db.right_text_x_percent_offset -1)/ 100) * w
local right_text_y_offset = ((db.right_text_y_percent_offset - 1)/ 100) * h
frame.right_text:SetPoint(
"RIGHT",
right_text_x_offset,
right_text_y_offset
)
st.utils.apply_font(frame.right_text, font_path, db.text_size, opt_string)
frame.right_text:SetTextColor(
self:convert_color(db.text_color)
)
if db.right_text_enabled then
frame.right_text:Show()
else
frame.right_text:Hide()
end
end
end
function ST:configure_bar_outline(hand)
if not self:bar_is_built(hand) then
return
end
local frame = self:get_bar_frame(hand)
local db = self:get_hand_table(hand)
if not frame or not db then
return
end
frame.backdropInfo = {
bgFile = fetch_statusbar_texture(db.background_texture_key),
edgeFile = LSM:Fetch('border', db.border_texture_key),
tile = true, tileSize = 16, edgeSize = db.border_width,
}
if frame.ApplyBackdrop then
frame:ApplyBackdrop()
end
if frame.SetBackdropBorderColor then
frame:SetBackdropBorderColor(
self:convert_color(db.border_color)
)
end
if frame.SetBackdropColor then
frame:SetBackdropColor(
self:convert_color(db.background_color)
)
end
end
function ST:configure_gcd_underlay(hand)
if not self:bar_is_built(hand) then
return
end
local db = self:get_hand_table(hand)
local frame = self:get_visuals_frame(hand)
if not frame or not frame.gcd_bar or not db then
return
end
frame.gcd_bar:SetTexture(fetch_statusbar_texture(db.gcd_texture_key))
frame.gcd_bar:SetVertexColor(
self:convert_color(db.bar_color_gcd)