Repository navigation
Expand file tree
/
Copy pathhunter_ui.lua
More file actions
2002 lines (1911 loc) · 84 KB
/
Copy pathhunter_ui.lua
File metadata and controls
2002 lines (1911 loc) · 84 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
--=========================================================================================
-- Hunter visual set: the cast bar above the ranged bar (a live cast with its name,
-- progress, latency end-slice and no-clip tint, else the hidden Auto Shot window), the
-- 4-state range helper strip, the Rapid Fire aura bar and the aspect icon.
--
-- Ported from the read-only reference SuperSwingTimer-WoW:
-- cast bar + window label SuperSwingTimer_UI.lua:943-1095 (frame 673-762)
-- hidden cast window SuperSwingTimer_UI.lua:418-428
-- no-clip tint SuperSwingTimer_UI.lua:858-886
-- latency end-slice SuperSwingTimer_UI.lua:890-941
-- cast-bar visibility SuperSwingTimer_UI.lua:459-491
-- movement-safe cast zone SuperSwingTimer_UI.lua:204-225 (IsRangedCastWindowSafe),
-- 805-850 (the overlay + threshold marker)
-- pet badges SuperSwingTimer_ClassMods.lua:6224-6385 (the tracked-icon
-- pattern: icon + countdown + stacks + gold glow last 4 s)
-- range helper SuperSwingTimer_ClassMods.lua:5538-5701
-- Rapid Fire bar SuperSwingTimer_ClassMods.lua:5879-6024
-- aspect icon SuperSwingTimer_ClassMods.lua:6026-6135
-- colours / heights SuperSwingTimer_Constants.lua:160-167, 970-978, 1010
--
-- The pure maths live in hunter_window.lua (range_state, cast_bar_display,
-- latency_slice_fraction, clip_tint, cast_window, hidden_window, is_cast_safe,
-- time_until_next_shot); every timestamp here is in the api.get_time() domain. The
-- frames are created from the hunter class module's post_init (out of combat; a
-- creation that lands under combat lockdown is deferred to the next per-frame tick) and
-- driven by the class module's on_bar_update hook from the ranged bar while that bar is
-- visible, plus by the hunter hook installed on the hand's anchor frame below (HU-37) on
-- every frame where the ranged bar's own tick cannot run: main.lua's activity gate hides
-- the bar while the hand is idle, and a hidden frame runs no OnUpdate - so without that
-- hook a Steady Shot / Volley cast with Auto Shot off had no cast bar at all. The widgets
-- parent to the anchor frame, but every anchor and width is still keyed to the ranged bar
-- frame. The
-- cast bar anchors above the ranged bar (UIParent centre when no ranged bar frame exists
-- at all), and the whole set is a silent no-op while the ranged hand is disabled, so it
-- never shows on clients without a ranged swing (Retail).
--
-- The melee bars are pinned under the ranged bar at its width on request (2026-10-27:
-- "mh/oh should be small/thin ... same width as ranged bar and under it"). The anchor
-- target is the ranged bar itself, never the cast bar, so the Auto Shot hidden-window
-- face cannot move them; the 2026-10-25 "mixed up" regression came from the old
-- cast-bar-gated re-anchor. See apply_melee_stack below.
--=========================================================================================
local addon_name, st = ...
local LSM = LibStub("LibSharedMedia-3.0")
local api = st.api
st.hunter_ui = st.hunter_ui or {}
local ui = st.hunter_ui
-- Error-isolation labels for the per-subfeature guard sites registered in ui.update.
st.guard.label("hunter_ui", "Hunter UI")
--=========================================================================================
-- Constants (reference values in the comments)
--=========================================================================================
local CAST_BAR_GAP = 2 -- HUNTER_CAST_BAR_GAP, Constants:162
local MELEE_STACK_GAP = 2 -- gap between the ranged bar and the thin melee stack
local RANGE_HELPER_GAP = 3 -- HUNTER_RANGE_HELPER_GAP, ClassMods.lua:5533
local RANGE_HELPER_WIDTH = 7 -- HUNTER_RANGE_HELPER_WIDTH, Constants:163
-- Sweet-spot band, expressed in exact yards (R3, 2026-10-21). The reference's index-3
-- CheckInteractDistance probe is the trade band at ~10 yd ("just outside melee"), so the
-- band is 5 < yards <= 10. 5 is main.lua's RF_MELEE_RANGE (the library's 5 yd item
-- ladder; see main.lua's range section) and the lower bound keeps a 4 yd reading with a
-- dead melee spell probe from being labelled "sweet". CheckInteractDistance is gone
-- from this file (protected on TBC Anniversary; compat exposes no wrapper at all).
-- Blizzard calls it only from secure popup code (UnitPopupSharedUtils.lua:194,
-- classic_anniversary); the addon block is the 2026-10-21 in-client
-- ADDON_ACTION_BLOCKED log, not a documented restriction.
local RANGE_HELPER_MELEE_RANGE = 5
local RANGE_HELPER_SWEET_SPOT = 10
local RAPID_FIRE_SPELL_ID = 3045 -- RAPID_FIRE_SPELL_ID, ClassMods.lua:5880
local RAPID_FIRE_FALLBACK_DURATION = 15 -- RAPID_FIRE_DURATION, ClassMods.lua:5882
local RAPID_FIRE_BAR_HEIGHT = 4 -- HUNTER_RAPID_FIRE_BAR_HEIGHT, Constants:167
local RAPID_FIRE_SCAN_INTERVAL = 0.1 -- rapidFireUpdateInterval, ClassMods.lua:5884
local ASPECT_SCAN_INTERVAL = 0.2 -- HUNTER_ASPECT_UPDATE_INTERVAL, ClassMods.lua:6114
local ASPECT_ICON_SIZE = 20 -- icon size (reference sized it to the strip)
local AURA_SCAN_LIMIT = 40 -- reference aura scans, ClassMods.lua:5917
local AUTO_SHOT_ID = 75 -- the Auto Shot spell (Constants:170)
local WING_CLIP_ID = 2974 -- Wing Clip (Constants:172)
local RAPTOR_STRIKE_ID = 2973 -- the melee-range fallback token
local AUTO_SHOT_LABEL_KEY = "auto_shot"
local CAST_BAR_FALLBACK_HEIGHT = 15 -- HUNTER_CAST_BAR_HEIGHT, Constants:160
-- Width used only when no ranged bar exists to size the cast bar against (the fallback
-- anchor below); every healthy client builds a ranged bar for hunters.
local CAST_BAR_FALLBACK_WIDTH = 200
local CAST_BAR_FALLBACK_COLOR = {0.35, 0.65, 0.95, 1.0} -- hunterCastBar, Constants:970
local RAPID_FIRE_BAR_COLOR = {0.15, 0.85, 0.45, 0.85} -- rapidFireBar, Constants:1010
-- autoShotUnsafe {1, 0, 0, 0.4} with the reference's alpha clamp (0.4 * 0.6 -> 0.24),
-- SuperSwingTimer_UI.lua:918-921.
-- One visual language for the cast window (operator order 2026-10-28: "update the
-- other bars colors/alpha so they are in sync"): the safe face is white and the
-- unsafe face is red, at the same alphas on the zone and on the cast bar's own
-- overlay. The latency end-slice is the same red at the same alpha.
local LATENCY_SLICE_COLOR = {1, 0, 0, 0.4}
local RANGE_STATE_COLORS = { -- hunterRange*, Constants:971-974
melee = {0.20, 0.85, 0.25, 1},
sweet_spot = {0.98, 0.82, 0.18, 1},
ranged = {0.20, 0.55, 1.00, 1},
out_of_range = {0.50, 0.50, 0.50, 1},
}
local CLIP_TINT_COLORS = { -- clipSafe / clipZone, Constants:975-976
-- Same white/red pair and the same alphas as the Auto Shot zone (they describe
-- the same window: safe = white, unsafe = red).
clipSafe = {1, 1, 1, 0.55},
clipZone = {1, 0, 0, 0.4},
}
-- Aspect of the Hawk (both ranks), Cheetah, Monkey, Pack, Wild, Viper, Beast
-- (ClassMods.lua:6026-6035).
local ASPECT_SPELL_IDS = {
[13165] = true, [27044] = true, [5118] = true, [13163] = true,
[13159] = true, [20190] = true, [34074] = true, [13171] = true,
}
-- Bestial Wrath (wowhead TBC spell 19574: 18 s buff, 2 min cooldown - the badge shows
-- the buff's duration, never the cooldown) and Frenzy Effect (wowhead TBC/WotLK spell
-- 19615: the pet's 8 s, 30% attack-speed buff; stacks up to 3, the community-tracked
-- BM pattern). Id-first matching with the localized-name fallback resolved from the
-- client's own spell data; an id missing from a client simply never matches, so the
-- badge stays inert there.
local BW_SPELL_ID = 19574
local FRENZY_EFFECT_ID = 19615
-- Badge geometry and cadence: same 20 px as the aspect icon, aura scans throttled to
-- the aspect cadence, gold glow inside the final 4 s (the reference glow window,
-- ClassMods.lua:6363-6372).
local BADGE_ICON_SIZE = 20
local BADGE_SCAN_INTERVAL = 0.2
local BADGE_GLOW_WINDOW = 4
-- The reference pulses the glow with a sine (ClassMods.lua:6366-6370); a static alpha
-- at the pulse's midpoint is used here instead - same signal, no per-frame colour
-- churn (documented deviation in the build-out report).
local BADGE_GLOW_COLOR = {1, 0.85, 0, 0.35}
-- Auto Shot cast window: the final 0.5 s of the ranged swing, at the END of the bar.
-- Operator order: constant red ("the endzone part of the ranged should be just red
-- because the changing colors is just confusing").
local CAST_ZONE_COLOR = {1, 0, 0, 0.4}
local CAST_ZONE_SAFE = CAST_ZONE_COLOR
local CAST_ZONE_UNSAFE = CAST_ZONE_COLOR
local CAST_ZONE_MARKER_WIDTH = 3 -- the reference's threshold marker (UI.lua:834)
-- Target-of-target warning (H1, bench/competitor_gaps_2026-10-19.md §Hunter): HST's
-- "target warning state ... when your target's target is you", as a red label above
-- the cast bar. Option-gated nil = off (hunter_target_warning_enabled strictly true
-- shows it; the options pass wires the default); an unknown state hides, so the label
-- only ever shows on an explicit true from ST.HUNTER.get_target_warning.
local TARGET_WARNING_TEXT = ">> TARGETING YOU <<"
local TARGET_WARNING_COLOR = {1, 0.15, 0.15, 1}
local TARGET_WARNING_GAP = 4
local TARGET_WARNING_TEXT_SIZE = 12
-- The anchor hook's own failure budget (H3 discipline, the power_bar/weave_range
-- pattern): after this many throwing ticks the hook gives up and the set is hidden
-- instead of spraying the client's error handler every frame. The value matches
-- guard.lua's shared quarantine threshold; the per-subfeature sites keep their own
-- counters there.
local TICK_QUARANTINE_THROWS = 25
--=========================================================================================
-- Helpers
--=========================================================================================
-- Raw world latency in seconds: the same basis the swing maths and the shaman/paladin
-- helpers consume.
local function world_latency_seconds(self)
return ((self.latency and self.latency.world_ms) or 0) / 1000
end
-- Effective visibility (a hidden parent hides its children; the widgets below now hang
-- off the hand's anchor frame, so the ranged bar's own Hide() has to be read here).
local function frame_visible(frame)
if not frame then
return false
end
if frame.IsVisible then
return frame:IsVisible() == true
end
return frame:IsShown() == true
end
-- Whether the hunter's ranged bar is usable right now: the ranged hand state exists and
-- the ranged hand is enabled. A hunter without a ranged weapon reads false, and so does
-- the Retail client, where UnitRangedDamage does not exist, so no ranged weapon is ever
-- detected. Everything in this module is a silent no-op while false.
--
-- The ACTIVITY gate is deliberately not part of this answer (main.lua's hand_is_in_use):
-- the set must keep painting while the activity gate hides the bar (HU-37). The CONFIG
-- half of the visibility rule is ranged_ui_allowed below.
local function ranged_bar_ready(self)
return self.ranged ~= nil and self:bar_is_enabled("ranged") == true
end
-- The CONFIGURED half of the ranged bar's visibility (HU-37): the class/spec/hand enable
-- flags and, while the bar frame is hidden, the hand's own show rule - i.e. main.lua's
-- handle_bar_visibility MINUS the activity gate. The visual set is allowed to ignore
-- "the hand is idle", but it must never surface anything the configuration keeps hidden
-- (class switched off, a spec gate, a show rule such as "in combat only" during the
-- idle out-of-combat state).
--
-- The show-rule leg is evaluated only while the bar frame is NOT visible: a bar tick
-- means the bar is visible, and main.lua only shows a hand after the same rule passed,
-- so the answer is already known. Nil-safe: a sandbox that does not model main.lua
-- skips the legs it does not provide.
local function ranged_ui_allowed(self, db)
if type(db) == "table" and db.class_enabled == false then
return false
end
local check = self.check_bar_enable_settings
if type(check) == "function" and check(self, db, "ranged") ~= true then
return false
end
if not frame_visible(ui.ranged_frame) then
local cond = self.hand_show_condition_met
if type(cond) == "function" then
local hand_db = self:get_hand_table("ranged")
if type(hand_db) == "table" and cond(self, "ranged", hand_db) == false then
return false
end
end
end
return true
end
-- Whether the hunter melee stack is on. Nil-safe: only an explicit false turns it
-- off, so a profile saved before the key existed reads the shipped ON behaviour.
local function melee_stack_on(self)
local db = self:get_class_table()
return type(db) == "table" and db.hunter_melee_stack ~= false
end
-- Is a melee hand built? HU-22 lazy bars means an unequipped/disabled hand has no
-- frames; a sandbox without bar_is_built is treated as built (its frames are the
-- fixture's own contract).
local function hand_is_built(self, hand)
if type(self.bar_is_built) == "function" then
return self:bar_is_built(hand) == true
end
local state = self[hand]
return type(state) == "table" and state.anchor_frame ~= nil
end
--=========================================================================================
-- HU-37: the always-running hunter tick
--
-- The set used to be parented to the ranged bar frame and ticked only from its OnUpdate.
-- main.lua's activity gate hides that frame while the hand is idle (no Auto Shot
-- auto-repeat and no shot receipt inside the window), and a hidden frame runs no
-- OnUpdate - so a Steady Shot / Volley cast with Auto Shot off painted no cast bar at
-- all. The tick now rides the hand's ANCHOR frame: bars.lua's per-hand top-level frame
-- and the one hide_bar() never hides (it hides the bar frame and the hiding proxy), so
-- it stays shown for as long as the hand exists. The hook is hunter-installed and
-- hunter-owned; the host is that existing per-hand frame rather than a new one because
-- the build-time frame census (tests/bars_state.lua) pins the hunter widget count and is
-- outside this lane's write scope - the lazy-badge precedent: do not move that pin.
--
-- The widgets parent to the same anchor frame (so they render while the bar frame is
-- hidden) but keep EVERY anchor and width against the ranged bar frame. To render
-- identically, the host is put on the bar frame's own strata/level BEFORE the widgets
-- are created: a child created afterwards then defaults to bar-level + 1 (what it had as
-- the bar's child) and inherits the bar's strata. The ranged bar itself is never shown
-- from here: the activity gate owns its visibility.
--
-- Exactly one source per frame: while the ranged bar is visible and carries its own
-- OnUpdate, that tick drives the set (the pre-2026-10-28 source) and the anchor tick
-- defers; the anchor tick takes every frame the bar's tick cannot run.
--=========================================================================================
-- Is the ranged bar's own tick going to run this frame? True only when the bar frame is
-- actually visible AND carries its OnUpdate (the pre-fix source). A visible bar without
-- the script - a sandbox build, or frames that came up without bring_up_hand - leaves
-- the frame to the anchor tick rather than going blank.
local function ranged_tick_is_live()
local frame = ui.ranged_frame
if not frame then
return false
end
if not frame_visible(frame) then
return false
end
if type(frame.GetScript) ~= "function" then
return false
end
return frame:GetScript("OnUpdate") ~= nil
end
-- Mirror the ranged bar's effective layering onto the tick host. The widgets used to
-- inherit the bar's strata/level as its children; the profile-wide draw_level /
-- frame_strata settings can move that frame after the build, so the host follows it
-- (one compare per frame, a Set only on a real change). In ui.build this runs BEFORE
-- the widgets exist, because a child's default frame level is assigned at creation.
local function sync_tick_host_layering()
local host = ui.tick_host
local bar = ui.ranged_frame
if not host or not bar then
return
end
if type(bar.GetFrameStrata) == "function" then
local strata = bar:GetFrameStrata()
if strata ~= nil and strata ~= ui.host_strata then
ui.host_strata = strata
if type(host.SetFrameStrata) == "function" then
host:SetFrameStrata(strata)
end
end
end
if type(bar.GetFrameLevel) == "function" then
local level = bar:GetFrameLevel()
if type(level) == "number" and level ~= ui.host_level then
ui.host_level = level
if type(host.SetFrameLevel) == "function" then
host:SetFrameLevel(level)
end
end
end
end
-- Claim the hand's anchor frame as the tick host: put it on the ranged bar's layering
-- and install the hunter hook once. Returns nil when the hand has no anchor frame (no
-- built hand); in that degenerate build the ranged bar's own tick stays the only source,
-- which is exactly the pre-fix wiring.
local function claim_tick_host(self)
local anchor = self.ranged and self.ranged.anchor_frame
if not anchor then
return nil
end
ui.tick_host = anchor
sync_tick_host_layering()
if not ui.tick_installed then
ui.tick_installed = true
anchor:SetScript("OnUpdate", function(_, elapsed)
ui.poll(ui.owner)
end)
end
return anchor
end
-- One anchor-tick frame: keep the host on the bar's layering, then update the set
-- unless the ranged bar's own tick is going to run this frame.
local function tick_once(self)
sync_tick_host_layering()
if ranged_tick_is_live() then
return
end
ui.update(self)
end
-- The host's guarded entry (H3 discipline, the power_bar/weave_range pattern): a
-- throwing tick must never break the OnUpdate chain. The per-subfeature sites inside
-- ui.update already isolate their own throws, so this catches only the entry's own
-- failure path; after TICK_QUARANTINE_THROWS the hook gives up and the set hides.
function ui.poll(self)
if not self then
return
end
local ok, err = pcall(tick_once, self)
if ok then
ui.tick_failures = nil
return
end
local failures = (ui.tick_failures or 0) + 1
ui.tick_failures = failures
ui.tick_last_error = tostring(err)
if failures == 1 and type(st.utils) == "table"
and type(st.utils.print_msg) == "function" then
-- Best-effort chat line: a missing/broken chat frame must never re-break the
-- OnUpdate chain this guard exists to protect.
pcall(st.utils.print_msg,
"Hunter UI update failed and was isolated: " .. tostring(err))
end
if failures >= TICK_QUARANTINE_THROWS then
if ui.tick_host and type(ui.tick_host.SetScript) == "function" then
ui.tick_host:SetScript("OnUpdate", nil)
end
ui.hide_all(self)
end
end
-- Pin the thin melee bars under the ranged bar at its width. Runs on the ranged and
-- mainhand ticks (the ranged tick may be stopped while the bar is hidden). The anchor
-- target is the RANGED BAR, never the cast bar: the 2026-10-25 regression happened
-- because the old re-anchor was gated on cast-bar visibility, which is true for the
-- Auto Shot window in every ranged cycle. Here the position is the requested layout,
-- not a transient state, so the window cannot move it.
function ui.apply_melee_stack(self)
if not melee_stack_on(self) or not ranged_bar_ready(self) then
return
end
local ranged_state = self.ranged
local ranged_anchor = ranged_state and ranged_state.anchor_frame
local parent = ranged_anchor and ranged_anchor.bar_frame
if parent == nil then
return
end
local ranged_db = self:get_hand_table("ranged")
local width = ranged_db and ranged_db.bar_width
if type(width) ~= "number" or width <= 0 then
-- A sandbox/flavor without the db width still has the live frame width.
width = parent.GetWidth and parent:GetWidth()
end
if type(width) ~= "number" or width <= 0 then
return
end
local configure = self.configure_bar_size_and_positions
for _, hand in ipairs({ "mainhand", "offhand" }) do
local state = self[hand]
local anchor = state and state.anchor_frame
if anchor ~= nil and hand_is_built(self, hand) then
local bar_frame = anchor.bar_frame
local current_width = bar_frame and bar_frame.GetWidth and bar_frame:GetWidth()
or anchor.GetWidth and anchor:GetWidth()
-- Half a UI unit of tolerance (2026-10-28, mainhand report: the thin bar
-- sat at 100% and never animated). An exact compare re-ran the resize - and
-- with it the fill's width reset - on any float/scale noise, once per tick.
-- A real width change is whole units, so this tolerance cannot hide one.
local matched = type(current_width) == "number" and current_width > 0
and math.abs(current_width - width) <= 0.5
if not matched and type(configure) == "function" then
-- Resize WITHOUT writing bar_width: the user's saved width returns
-- when the stack is switched off (configure with no override).
configure(self, hand, width)
end
local point, relative, relative_point, x, y = anchor:GetPoint(1)
if point ~= "TOPLEFT" or relative ~= parent
or relative_point ~= "BOTTOMLEFT" or x ~= 0 or y ~= -MELEE_STACK_GAP then
anchor:ClearAllPoints()
anchor:SetPoint("TOPLEFT", parent, "BOTTOMLEFT", 0, -MELEE_STACK_GAP)
end
parent = anchor
end
end
end
-- Turn the stack off: restore each built melee hand's own width and saved LibWindow
-- position. Only the geometry is restored; no saved key is written by either path.
function ui.restore_melee_layout(self)
if type(self.configure_bar_size_and_positions) ~= "function" then
return
end
for _, hand in ipairs({ "mainhand", "offhand" }) do
if hand_is_built(self, hand) then
self:configure_bar_size_and_positions(hand)
end
end
end
-- Resolve a spell id to the running client's token for range probes. The rule is
-- the operator's name-vs-id matrix, one family gate at a time: Classic Era (SoD
-- included), Forever, Cata/Mists/Retail and the unknown fallback take the numeric
-- ID; TBC Anniversary and Wrath/Titanforge take the localized NAME first and the
-- ID as the approved fallback (HU-34: "i never banned fallback to ids"). The
-- display name is the SECOND return so Era still has its label while probing by
-- id. A cold spell cache on a name family therefore degrades to the id, never to
-- a nil token.
local function resolve_spell(spell_id)
local name = api.GetSpellInfo(spell_id)
if type(name) ~= "string" then
name = nil
end
if st.family ~= "ERA" then
if type(api.get_spell_query) == "function" then
return api.get_spell_query(name, spell_id) or spell_id, name
end
return name or spell_id, name
end
return spell_id, name
end
--=========================================================================================
-- Frame construction (called once from ST.HUNTER.post_init, out of combat)
--
-- HU-37: each creator takes the CREATION parent (the hand's anchor frame, which the
-- activity gate never hides) separately from the ANCHOR target (the ranged bar frame).
-- The widgets render under the anchor while the activity gate hides the bar; every
-- SetPoint/width below still reads exactly what it read when they were the bar's
-- children.
--=========================================================================================
local function create_cast_bar(parent, ranged_frame, texture, font_path, db_hand)
local frame = CreateFrame("Frame", addon_name .. "HunterCastBar",
parent or ranged_frame or UIParent)
frame:SetHeight(CAST_BAR_FALLBACK_HEIGHT)
if ranged_frame then
frame:SetPoint("BOTTOMLEFT", ranged_frame, "TOPLEFT", 0, CAST_BAR_GAP)
frame:SetPoint("BOTTOMRIGHT", ranged_frame, "TOPRIGHT", 0, CAST_BAR_GAP)
else
-- No ranged bar on this client: keep the bar anchored and usable at the screen
-- centre instead of leaving it unanchored (the reference simply hides it, UI.lua
-- 676-681; this layout still sizes it so the widget stays visible on demand).
frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
frame:SetWidth(CAST_BAR_FALLBACK_WIDTH)
end
frame:SetFrameLevel(ranged_frame and ranged_frame:GetFrameLevel() + 2 or 1)
frame:EnableMouse(false)
frame.bg = frame:CreateTexture(nil, "BACKGROUND")
frame.bg:SetAllPoints()
frame.bg:SetColorTexture(0, 0, 0, 0.8)
-- The fill keeps the configured cast-bar colour and is never repainted by the Auto
-- Shot window colours (reference UI.lua:858-860).
frame.bar = frame:CreateTexture(nil, "ARTWORK")
frame.bar:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, 0)
frame.bar:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 0, 0)
if texture then
frame.bar:SetTexture(texture)
end
-- No-clip tint: a translucent green/red overlay shown for live casts only.
frame.tint = frame:CreateTexture(nil, "ARTWORK", nil, 1)
frame.tint:SetAllPoints(frame.bar)
frame.tint:Hide()
-- Latency end-slice: right-anchored, width set per frame.
frame.latency = frame:CreateTexture(nil, "ARTWORK", nil, 2)
frame.latency:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 0, 0)
frame.latency:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, 0)
frame.latency:SetColorTexture(unpack(LATENCY_SLICE_COLOR))
frame.latency:Hide()
frame.text = frame:CreateFontString(nil, "OVERLAY")
-- The font goes on BEFORE the first SetText: a FontString with no font throws
-- "Font not set" on a real client. The chain (the LSM path, then
-- STANDARD_TEXT_FONT, then the classic client font) never throws and always
-- leaves a font that exists.
st.utils.apply_font(frame.text, font_path, db_hand.text_size or 12, "")
frame.text:SetPoint("CENTER", frame, "CENTER", 0, 0)
frame.text:SetTextColor(1, 1, 1, 1)
frame.text:SetShadowColor(0, 0, 0, 1)
frame.text:SetShadowOffset(1, -1)
frame:Hide()
return frame
end
local function create_range_helper(parent, ranged_frame)
local helper = CreateFrame("Frame", addon_name .. "HunterRangeHelper",
parent or ranged_frame or UIParent)
helper:SetWidth(RANGE_HELPER_WIDTH)
helper.tex = helper:CreateTexture(nil, "ARTWORK")
helper.tex:SetAllPoints()
helper.tex:SetColorTexture(1, 1, 1, 1)
helper:Hide()
return helper
end
local function create_rapid_fire_bar(parent, ranged_frame, texture, font_path, text_size)
local bar = CreateFrame("StatusBar", addon_name .. "HunterRapidFireBar",
parent or ranged_frame or UIParent)
bar:SetHeight(RAPID_FIRE_BAR_HEIGHT)
bar:SetMinMaxValues(0, 1)
bar:SetValue(0)
bar:EnableMouse(false)
if texture then
bar:SetStatusBarTexture(texture)
end
bar:SetStatusBarColor(unpack(RAPID_FIRE_BAR_COLOR))
bar.bg = bar:CreateTexture(nil, "BACKGROUND")
bar.bg:SetAllPoints()
bar.bg:SetColorTexture(0, 0, 0, 0.5)
-- Whole-seconds label beside the bar (reference ClassMods.lua:5968-5974).
bar.label = bar:CreateFontString(nil, "OVERLAY")
-- The label is written per frame, so it carries a font from the start: a
-- FontString with no font throws "Font not set" on the first SetText.
st.utils.apply_font(bar.label, font_path, text_size, "")
bar.label:SetPoint("LEFT", bar, "RIGHT", 2, 0)
bar.label:SetJustifyH("LEFT")
bar.label:SetTextColor(unpack(RAPID_FIRE_BAR_COLOR))
bar:Hide()
return bar
end
local function create_aspect_icon(parent)
local icon = CreateFrame("Frame", addon_name .. "HunterAspectIcon",
parent or UIParent)
icon:SetSize(ASPECT_ICON_SIZE, ASPECT_ICON_SIZE)
icon:EnableMouse(false)
icon.tex = icon:CreateTexture(nil, "ARTWORK")
icon.tex:SetAllPoints()
icon.tex:SetTexCoord(0.07, 0.93, 0.07, 0.93)
icon.border = icon:CreateTexture(nil, "OVERLAY")
icon.border:SetDrawLayer("OVERLAY", -1)
icon.border:SetColorTexture(0, 0, 0, 0.65)
icon.border:SetPoint("TOPLEFT", icon, "TOPLEFT", -1, 1)
icon.border:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT", 1, -1)
icon:Hide()
return icon
end
local function create_cast_zone(ranged_frame)
-- The movement-safe cast zone lives on the ranged bar's visuals frame (the same
-- surface the paladin twist band uses): a texture on the bar frame itself would
-- render under the child visuals frame. Without a visuals frame (degenerate build)
-- both textures stay nil and the update is a no-op. The zone is right-anchored and
-- width-driven; the marker is a thin dark line at the window boundary.
--
-- HU-37: this one overlay stays on the bar's surface (a texture cannot be re-parented)
-- and deliberately so. Its own update gate only paints inside a LIVE ranged cycle
-- (update_cast_zone), and a live cycle always implies the activity gate shows the bar
-- for that cycle's receipt window - so a zone painted while the bar is hidden is never
-- observable today. It still TICKS from the anchor hook with the rest of the set (its
-- update runs and hides itself when there is no live cycle).
local parent = ranged_frame and ranged_frame.visuals_frame
if not parent then
return nil, nil
end
local zone = parent:CreateTexture(nil, "OVERLAY")
zone:SetDrawLayer("OVERLAY", -2)
zone:SetPoint("TOPRIGHT", parent, "TOPRIGHT", 0, 0)
zone:SetPoint("BOTTOMRIGHT", parent, "BOTTOMRIGHT", 0, 0)
zone:SetWidth(0)
zone:Hide()
local marker = parent:CreateTexture(nil, "OVERLAY")
marker:SetDrawLayer("OVERLAY", -1)
marker:SetColorTexture(0, 0, 0, 1)
marker:SetWidth(CAST_ZONE_MARKER_WIDTH)
marker:Hide()
return zone, marker
end
local function create_target_warning(cast_frame, font_path)
-- H1 target warning label (see the TARGET_WARNING_* constants): a red text line
-- above the cast bar, CENTER-fallback when no frame exists to hang it on.
local parent = cast_frame or UIParent
local label = parent:CreateFontString(nil, "OVERLAY")
-- The font goes on BEFORE the text: a FontString with no font throws
-- "Font not set" on a real client (the label is written once, at creation).
-- The chain never throws and always leaves a font that exists.
st.utils.apply_font(label, font_path, TARGET_WARNING_TEXT_SIZE, "OUTLINE")
label:SetText(TARGET_WARNING_TEXT)
label:SetTextColor(unpack(TARGET_WARNING_COLOR))
if cast_frame then
label:SetPoint("BOTTOM", cast_frame, "TOP", 0, TARGET_WARNING_GAP)
else
label:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
end
label:Hide()
return label
end
local function create_badge(name, parent, font_path, text_size)
-- The tracked-icon pattern (reference ClassMods.lua:6224-6279): icon texture with
-- the standard inset, an additive gold glow overlay, one text. Callers place the
-- text (BW: the countdown above the icon; Frenzy: the stack count bottom-right).
local frame = CreateFrame("Frame", addon_name .. name, parent or UIParent)
frame:SetSize(BADGE_ICON_SIZE, BADGE_ICON_SIZE)
frame:EnableMouse(false)
frame.tex = frame:CreateTexture(nil, "ARTWORK")
frame.tex:SetAllPoints()
frame.tex:SetTexCoord(0.07, 0.93, 0.07, 0.93)
frame.glow = frame:CreateTexture(nil, "OVERLAY", nil, 7)
frame.glow:SetAllPoints()
frame.glow:SetColorTexture(unpack(BADGE_GLOW_COLOR))
if frame.glow.SetBlendMode then
frame.glow:SetBlendMode("ADD")
end
frame.glow:Hide()
frame.text = frame:CreateFontString(nil, "OVERLAY")
-- The badge text is written per frame, so it carries a font from the start: a
-- FontString with no font throws "Font not set" on the first SetText.
st.utils.apply_font(frame.text, font_path, text_size, "")
frame.text:SetTextColor(1, 1, 1, 0.95)
frame.text:Hide()
frame:Hide()
return frame
end
function ui.build(self, ranged_frame)
local db_hand = self:get_hand_table("ranged")
-- No ranged row means no configuration to build the hunter UI from. Report
-- "not ready" so ui.init's per-tick retry can pick it up (profile switch),
-- instead of throwing out of the class hook on a nil field.
if type(db_hand) ~= "table" then
return false
end
local texture = LSM:Fetch("statusbar", db_hand.bar_texture_key)
-- The font path is resolved through the shared chain (utils.lua): a key that no
-- longer resolves (the font lives in another addon's LSM registration) must not
-- leave a FontString without a font - the fallback chain takes over.
local font_path = st.utils.fetch_font_path(db_hand.text_font)
local text_size = db_hand.text_size or 12
-- HU-37: the tick host is claimed BEFORE the widgets so their default frame levels
-- (host level + 1) are the bar-child levels they had before, and so the set has a
-- never-hidden parent from its first frame. The ranged bar frame is still the ANCHOR
-- target for every widget below. A hand with no anchor frame (degenerate build)
-- keeps the pre-fix wiring: children of the bar frame, ticked by its own OnUpdate.
ui.owner = self
ui.ranged_frame = ranged_frame
local parent = ui.tick_host or claim_tick_host(self)
if not parent and ranged_frame then
parent = ranged_frame
end
ui.cast_frame = create_cast_bar(parent, ranged_frame, texture, font_path, db_hand)
ui.range_helper = create_range_helper(parent, ranged_frame)
ui.rapid_fire_bar = create_rapid_fire_bar(parent, ranged_frame, texture,
font_path, text_size)
ui.aspect_icon = create_aspect_icon(parent)
-- H1 target warning (option-gated nil = off; text set once, visibility per frame).
ui.target_warning = create_target_warning(ui.cast_frame, font_path)
-- Transition state: nil/false means "normal anchors". (The melee stack is stateless:
-- apply_melee_stack compares the live anchor points each tick, so a toggle-off or a
-- drag is handled without a cached "was stacked" flag.)
ui.helper_top = nil
ui.rf_anchor = nil
ui.rf_width = nil
ui.aspect_anchor = nil
ui.cast_height = nil
-- Client spell tokens (Era ids; TBC/Wrath localized names with the ids as fallback).
ui.wing_clip_token = resolve_spell(WING_CLIP_ID)
ui.raptor_token = resolve_spell(RAPTOR_STRIKE_ID)
ui.auto_shot_token, ui.auto_shot_name = resolve_spell(AUTO_SHOT_ID)
local _, rapid_fire_name = resolve_spell(RAPID_FIRE_SPELL_ID)
ui.rapid_fire_name = rapid_fire_name
-- Aspect aura matchers: spell ids always, localized names resolved from the
-- client's own spell data (a localized aura name never matches the English list).
ui.aspect_names = {}
ui.aspect_textures = {}
for spell_id in pairs(ASPECT_SPELL_IDS) do
local aspect_name, _, icon = api.GetSpellInfo(spell_id)
if aspect_name then
ui.aspect_names[aspect_name] = spell_id
ui.aspect_textures[spell_id] = icon
end
end
-- Movement-safe cast zone (option-gated; nil = off) and the H6 pet badges. The
-- zone lives on the ranged bar's visuals frame (nil when that is absent, in which
-- case its update is a no-op). Badge text placement follows the reference: BW's
-- countdown above the icon, Frenzy's stack count bottom-right.
ui.cast_zone, ui.cast_zone_marker = create_cast_zone(ranged_frame)
ui.bw_badge = create_badge("HunterBWBadge", parent, font_path, text_size)
ui.bw_badge.text:SetPoint("BOTTOM", ui.bw_badge, "TOP", 0, 2)
ui.bw_badge.text:SetJustifyH("CENTER")
ui.frenzy_badge = create_badge("HunterFrenzyBadge", parent, font_path, text_size)
ui.frenzy_badge.text:SetPoint("BOTTOMRIGHT", ui.frenzy_badge, "BOTTOMRIGHT", -1, 1)
ui.frenzy_badge.text:SetJustifyH("RIGHT")
-- Badge spell tokens: localized names and icon textures from the client's own data
-- (the ids stay the primary matcher, so a cold cache only disables the name
-- fallback and leaves a texture-less badge hidden).
ui.bw_name, _, ui.bw_texture = api.GetSpellInfo(BW_SPELL_ID)
ui.frenzy_name, _, ui.frenzy_texture = api.GetSpellInfo(FRENZY_EFFECT_ID)
if ui.bw_texture then
ui.bw_badge.tex:SetTexture(ui.bw_texture)
end
if ui.frenzy_texture then
ui.frenzy_badge.tex:SetTexture(ui.frenzy_texture)
end
-- Transition caches for the new widgets (nil = "no change seen yet").
ui.zone_width = nil
ui.zone_left = nil
ui.zone_safe = nil
ui.bw_anchor = nil
ui.frenzy_anchor = nil
ui.badge_scan_at = nil
ui.bw_text = nil
ui.frenzy_text = nil
ui.ready = true
end
function ui.init(self)
-- Called from ST.HUNTER.post_init; also retried from the per-frame hook when the
-- creation was deferred (combat lockdown) or the ranged bar was not ready yet.
if ui.ready then
return
end
if InCombatLockdown and InCombatLockdown() then
return
end
if not ranged_bar_ready(self) then
return
end
local ranged_state = self.ranged
local ranged_frame
if ranged_state and ranged_state.anchor_frame then
ranged_frame = ranged_state.anchor_frame.bar_frame
end
ui.build(self, ranged_frame)
end
--=========================================================================================
-- Melee bar stack (2026-10-27 operator request)
--=========================================================================================
-- The thin mainhand/offhand bars are pinned directly under the ranged bar at the ranged
-- bar's width (ranged -> MH -> OH). This is a stable layout, not a transient cast-bar
-- state: the anchor target is the ranged bar frame, so the Auto Shot hidden-window face
-- (the old 2026-10-25 regression trigger) cannot move them. The stack is off-switchable
-- (hunter_melee_stack = false) and restores each hand's own width + LibWindow position.
--
-- The reference's UpdateHunterMeleeBarAnchor (SuperSwingTimer_UI.lua:31-44) is not
-- ported: it gated the stack on cast-bar visibility and hid the MH bar at range. This
-- addon deliberately keeps the melee cycle visible for melee weaving; only the geometry
-- policy is adopted.
--=========================================================================================
-- Cast bar
--=========================================================================================
-- Read the live player cast through compat's folding wrapper (a cast first, a channel
-- second). Auto Shot readings are ignored here: they drive the hidden window label
-- instead (reference UI.lua:1030-1043), and a cast without usable bounds cannot drive a
-- progress bar at all.
local function read_live_cast()
local name, spell_id, cast_start, cast_end = api.UnitCastingSpell("player")
if not name then
return nil
end
-- Auto Shot exclusion (reference IsAutoShotSpell: id OR name): the older
-- classic payloads carry no numeric id (compat folds them to nil) and the
-- build-time name is nil while the spell data has not answered, so either
-- check alone lets a live Auto Shot reading through as a "cast" instead of
-- the hidden window. The English fallback covers a cold cache the same way
-- the reference's `or "Auto Shot"` does.
local auto_name = ui.auto_shot_name or "Auto Shot"
if canaccessallvalues(spell_id, name) then
if spell_id == AUTO_SHOT_ID or name == auto_name then
return nil
end
end
if type(cast_start) ~= "number" or type(cast_end) ~= "number" or cast_end <= cast_start then
return nil
end
return name, spell_id, cast_start, cast_end
end
-- The hidden Auto Shot window of the current ranged cycle, cached on the phase-1 ranged
-- state fields (hunter_window.hidden_window; reference UI.lua:394-430). Only an
-- inside window is cached: past and future recompute every tick like the reference
-- (UI.lua:421-426 returns nil without caching outside the window), so the
-- per-frame cost is one pure-arithmetic call until the window opens.
local function get_hidden_window(self, now)
local ranged = self.ranged
if not ranged then
return nil, nil
end
local cycle_duration = ranged.synced_duration or ranged.speed
-- Provenance (see gather_guide_inputs): the cache counts only while it still
-- ends on the live cycle's end. A ranged re-anchor the hunter sync did not
-- clear (the engine's START/UPDATE stamps next to the sync's own clears; the
-- reference clears on every StartSwing) leaves a stale end behind, and the
-- stale bounds must lose to the live recompute.
local live_end
if type(ranged.start) == "number" and type(cycle_duration) == "number"
and cycle_duration > 0 then
live_end = ranged.start + cycle_duration
end
local start = ranged.hidden_window_start
local duration = ranged.hidden_window_duration
if type(start) == "number" and type(duration) == "number" and duration > 0
and live_end ~= nil and math.abs((start + duration) - live_end) <= 1e-9
and now >= start and now <= start + duration then
return start, duration
end
ranged.hidden_window_start = nil
ranged.hidden_window_duration = nil
if live_end == nil then
return nil, nil
end
local window_start, window_end = st.hunter_window.hidden_window(
ranged.start, cycle_duration, st.hunter_window.cast_window(world_latency_seconds(self)))
if not window_start or type(now) ~= "number" or now < window_start or now > window_end then
-- Outside (past or future): never cache. The reference recomputes a
-- future window every tick instead of holding it (UI.lua:421-423).
return nil, nil
end
ranged.hidden_window_start = window_start
ranged.hidden_window_duration = window_end - window_start
return window_start, window_end - window_start
end
local function hide_cast_bar()
local frame = ui.cast_frame
if not frame then
return
end
if frame:IsShown() then
frame:Hide()
end
frame.tint:Hide()
frame.latency:Hide()
ui.tint_key = nil
-- The cast is gone: drop the fill anchor so the next cast re-anchors on its own
-- first tick instead of inheriting the previous cast's elapsed time.
ui.cast_key = nil
ui.cast_anchor = nil
end
local function update_cast_text(mode, name, remaining, spell_id)
-- One SetText per tenth of a second and per label identity, mirroring the
-- reference's _lastRemTenth / _lastCastSpellId gates (UI.lua:1075-1095).
local rem_tenth = math.floor(remaining * 10 + 0.5)
local key = AUTO_SHOT_LABEL_KEY
if mode == "cast" then
key = spell_id or name
end
if ui.label_tenth == rem_tenth and ui.label_key == key then
return
end
ui.label_tenth, ui.label_key = rem_tenth, key
local frame = ui.cast_frame
if mode == "cast" then
frame.text:SetText(string.format("%s %.1f", name or "Cast", remaining))
else
frame.text:SetText(string.format("Auto Shot %.1f", remaining))
end
end
function ui.update_cast_bar(self, db, now)
local frame = ui.cast_frame
if db.hunter_cast_bar_enabled == false then
hide_cast_bar()
return
end
-- Height and colour are read live so the options apply without a reload.
local height = db.hunter_cast_bar_height or CAST_BAR_FALLBACK_HEIGHT
if ui.cast_height ~= height then
ui.cast_height = height
frame:SetHeight(height)
end
local color = db.hunter_cast_bar_color or CAST_BAR_FALLBACK_COLOR
local r = color[1] or color.r or CAST_BAR_FALLBACK_COLOR[1]
local g = color[2] or color.g or CAST_BAR_FALLBACK_COLOR[2]
local b = color[3] or color.b or CAST_BAR_FALLBACK_COLOR[3]
local a = color[4] or color.a or CAST_BAR_FALLBACK_COLOR[4]
if ui.cast_color_r ~= r or ui.cast_color_g ~= g
or ui.cast_color_b ~= b or ui.cast_color_a ~= a then
ui.cast_color_r, ui.cast_color_g, ui.cast_color_b, ui.cast_color_a = r, g, b, a
frame.bar:SetVertexColor(r, g, b, a)
end
local cast_name, cast_spell_id, cast_start, cast_end = read_live_cast()
local window_start, window_duration = get_hidden_window(self, now)
local mode = st.hunter_window.cast_bar_display(
cast_name ~= nil, window_start, window_duration, now)
if mode == "hidden" then
hide_cast_bar()
return
end
-- Progress through the active face, clamped like the reference before it is drawn.
local duration, elapsed
if mode == "cast" then
duration = (cast_end or 0) - (cast_start or 0)
-- Fill anchor on OUR clock. The cast's absolute start stamp sits on the client
-- clock; when that axis sits at any offset from api.get_time(), now - cast_start
-- is negative and the bar freezes at zero while the label sits on the full
-- duration - the "bar comes up but does nothing" shape. A cast is identified by
-- (name, spell id, end stamp); on first sight the anchor is back-dated by the
-- elapsed the two clocks agree on, or starts now when they do not.
local cast_key = tostring(cast_name) .. "|" .. tostring(cast_spell_id)
.. "|" .. tostring(cast_end)
if canaccessvalue(ui.cast_key) then
if canaccessvalue(cast_key) then
if ui.cast_key ~= cast_key then
ui.cast_key = cast_key
local stamped = now - cast_start
if type(stamped) == "number" and stamped > 0 and stamped <= duration then
ui.cast_anchor = now - stamped
else
ui.cast_anchor = now
end
end
end
end
elapsed = now - (ui.cast_anchor or now)
else
ui.cast_key = nil
ui.cast_anchor = nil
duration = window_duration
elapsed = now - window_start
cast_name = nil
cast_spell_id = nil
end
if elapsed < 0 then
elapsed = 0
elseif elapsed > duration then
elapsed = duration
end
local remaining = duration - elapsed
if mode ~= "cast" then
-- H1 shot clock: the window face's countdown is the HOLD-seconds kernel over
-- the same bounds cast_bar_display just matched (the moment the window closes
-- and the next Auto Shot fires). Falls back to the clamped arithmetic only if
-- the kernel is absent (a flavor without hunter_window).
remaining = st.hunter_window.hold_seconds(window_start, window_duration, now)
or remaining
end
local bar_width = frame:GetWidth() or 0
local progress = 0
if duration > 0 then
progress = elapsed / duration
end
frame.bar:SetWidth(math.max(1, progress * bar_width))
-- No-clip tint: live casts only, never the Auto Shot window (its bar keeps the
-- configured colour, reference UI.lua:858-860).
local tint_key