-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperSwingTimer_UI.lua
More file actions
executable file
·2773 lines (2536 loc) · 101 KB
/
Copy pathSuperSwingTimer_UI.lua
File metadata and controls
executable file
·2773 lines (2536 loc) · 101 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
local _, ns = ...
local CreateFrame = rawget(_G, "CreateFrame")
local UIParent = rawget(_G, "UIParent")
local InCombatLockdown = rawget(_G, "InCombatLockdown")
local UnitAttackSpeed = rawget(_G, "UnitAttackSpeed")
local UnitChannelInfo = rawget(_G, "UnitChannelInfo")
local strtrim = rawget(_G, "strtrim")
local function GetSparkBlendMode()
-- Keep the main swing spark color-preserving so a white/manual spark does
-- not visually warm itself from the colored bar fill underneath.
return "BLEND"
end
local function GetRangedCastWindow()
local baseWindow = ns.CAST_WINDOW or 0
local castWindow = baseWindow + (ns.cachedLatency or 0)
if castWindow < 0 then
return 0
end
return castWindow
end
local ShouldShowHunterCastBar
local UpdateHunterMeleeBarAnchor = function (_, force)
if ns.playerClass ~= "HUNTER" or not ns.mhBar or not ns.rangedBar then
return
end
if not force and ns.mhBar.hunterAnchorTarget == ns.rangedBar then
return
end
ns.mhBar:ClearAllPoints()
ns.mhBar:SetPoint("BOTTOMLEFT", ns.rangedBar, "TOPLEFT", 0, 2)
ns.mhBar:SetPoint("BOTTOMRIGHT", ns.rangedBar, "TOPRIGHT", 0, 2)
ns.mhBar.hunterAnchorTarget = ns.rangedBar
end
local function IsHunterMeleeActive()
if ns.IsHunterMeleeActive then
return ns.IsHunterMeleeActive()
end
return false
end
local function IsHunterMeleeBarVisible()
if ns.IsHunterMeleeBarVisible then
return ns.IsHunterMeleeBarVisible()
end
return IsHunterMeleeActive()
end
local function ShouldKeepHunterRangedTimerActive(now)
if ns.playerClass ~= "HUNTER" then
return false
end
if IsHunterMeleeActive() then
return false
end
if ns.IsHunterAutoRepeatActive and ns.IsHunterAutoRepeatActive() then
return true
end
if ns.GetAutoShotCooldown then
local cooldownStart, cooldownDuration = ns.GetAutoShotCooldown()
if cooldownStart and cooldownDuration and cooldownDuration > 0 then
local graceWindow = math.max(ns.cachedLatency or 0, 0.05)
if (now or ns.GetAlignedTime()) <= (cooldownStart + cooldownDuration + graceWindow) then
return true
end
end
end
-- ShouldShowHunterCastBar is assigned later in this file (forward declaration pattern)
if type(ShouldShowHunterCastBar) == "function" and ShouldShowHunterCastBar() then
return true
end
return false
end
local function GetAutoShotWindowColor(colorKey, fallback)
local color = ns.GetBarColor and ns.GetBarColor(colorKey) or nil
if color then
return color
end
local fallbackColor = fallback or { r = 1, g = 1, b = 1, a = 1 }
return {
r = fallbackColor.r or 1,
g = fallbackColor.g or 1,
b = fallbackColor.b or 1,
a = fallbackColor.a ~= nil and fallbackColor.a or 1
}
end
local function ClampSparkHeightForBar(bar, requestedHeight)
local targetHeight = tonumber(requestedHeight) or 1
local barHeight = bar and bar:GetHeight() or targetHeight
if not barHeight or barHeight <= 0 then
barHeight = targetHeight
end
return math.max(1, math.min(targetHeight, barHeight))
end
local function GetOffHandBarHeight(mainHeight)
if ns.GetOffHandBarHeight then
return ns.GetOffHandBarHeight(mainHeight)
end
local baseHeight = tonumber(mainHeight) or ns.BAR_HEIGHT or 15
return math.max(6, baseHeight - 7)
end
local function GetRogueSliceAndDiceBarHeight(mainHeight)
if ns.GetRogueSliceAndDiceBarHeight then
return ns.GetRogueSliceAndDiceBarHeight(mainHeight)
end
local baseHeight = tonumber(mainHeight) or ns.BAR_HEIGHT or 15
return math.max(3, math.min(4, math.floor((baseHeight * 0.3) + 0.5)))
end
local function GetBarProgressFraction(bar)
if not bar or not bar.GetMinMaxValues or not bar.GetValue then
return 0
end
local minValue, maxValue = bar:GetMinMaxValues()
if type(minValue) ~= "number" or type(maxValue) ~= "number" or maxValue <= minValue then
return 0
end
local value = bar:GetValue() or minValue
local fraction = (value - minValue) / (maxValue - minValue)
if fraction < 0 then
return 0
elseif fraction > 1 then
return 1
end
return fraction
end
local function UpdateSparkPosition(bar, explicitFraction)
if not bar or not bar.sparkTexture then
return
end
local sparkAnchor = ns.GetOverlayFrame and ns.GetOverlayFrame(bar) or bar
local barWidth = bar:GetWidth() or bar.barWidth or ns.BAR_WIDTH or 0
local sparkWidth = (bar.sparkTexture.GetWidth and bar.sparkTexture:GetWidth()) or (ns.GetSparkWidth
and ns.GetSparkWidth())
or 0
local sparkPos
local fill = bar.statusBarTexture or (bar.GetStatusBarTexture and bar:GetStatusBarTexture()) or nil
if fill and sparkAnchor.GetLeft and fill.GetRight and barWidth > 0 then
local anchorLeft = sparkAnchor:GetLeft()
local fillRight = fill:GetRight()
if anchorLeft and fillRight then
sparkPos = fillRight - anchorLeft
end
end
if type(sparkPos) ~= "number" then
local fraction = explicitFraction
if fraction == nil then
fraction = GetBarProgressFraction(bar)
end
sparkPos = (fraction or 0) * barWidth
end
if sparkWidth > 1 then
sparkPos = sparkPos + math.min((sparkWidth - 1) * 0.25, 1)
end
sparkPos = math.floor((sparkPos or 0) + 0.5)
if sparkPos < 0 then
sparkPos = 0
elseif sparkPos > barWidth then
sparkPos = barWidth
end
bar.sparkTexture:ClearAllPoints()
bar.sparkTexture:SetPoint("CENTER", sparkAnchor, "LEFT", sparkPos, 0)
end
ns.RefreshBarSparkPosition = UpdateSparkPosition
-- Green means the player stopped before the breakpoint.
-- Red means the player is still moving through the cast window, or stopped too late.
local function IsRangedCastWindowSafe(t, castWindow)
if not t or t.state ~= "swinging" or not t.duration or t.duration <= 0 then
return false
end
if not castWindow or castWindow <= 0 then
return false
end
local cooldownEnd = t.lastSwing + t.duration - castWindow
if ns.isMoving then
return false
end
local stoppedAt = ns.lastStoppedMovingAt
if stoppedAt and stoppedAt > cooldownEnd then
return false
end
return true
end
local function CreateOverlayFrame(parent)
local overlayFrame = CreateFrame("Frame", nil, parent)
overlayFrame:SetAllPoints(parent)
overlayFrame:SetFrameStrata(parent:GetFrameStrata())
overlayFrame:SetFrameLevel((parent:GetFrameLevel() or 0) + 1)
overlayFrame:EnableMouse(false)
return overlayFrame
end
function ns.GetOverlayFrame(frame)
if frame and frame.overlayFrame then
return frame.overlayFrame
end
return frame
end
local function UsesInvertedClassLabelStyle(bar)
local db = SuperSwingTimerDB or ns.DB_DEFAULTS
if not db or db.useClassColors ~= true then
return false
end
return bar == ns.mhBar or bar == ns.ohBar or bar == ns.rangedBar or bar == ns.hunterCastBar
end
local function SyncBarLabelText(bar, text)
if not bar or not bar.labelText then
return
end
text = text or ""
bar.labelText:SetText(text)
if bar.labelOutlineText then
bar.labelOutlineText:SetText(text)
end
end
local function ApplyBarLabelStyle(bar)
if not bar or not bar.labelText then
return
end
local useInverted = UsesInvertedClassLabelStyle(bar)
if useInverted then
bar.labelText:SetTextColor(0, 0, 0, 1)
bar.labelText:SetShadowColor(0, 0, 0, 0)
bar.labelText:SetShadowOffset(0, 0)
if bar.labelOutlineText then
local fontPath, fontSize = bar.labelText:GetFont()
if fontPath and fontSize then
bar.labelOutlineText:SetFont(fontPath, fontSize, "OUTLINE")
end
bar.labelOutlineText:SetTextColor(1, 1, 1, 1)
end
else
bar.labelText:SetTextColor(1, 1, 1, 1)
bar.labelText:SetShadowColor(0, 0, 0, 1)
bar.labelText:SetShadowOffset(1, -1)
if bar.labelOutlineText then
bar.labelOutlineText:Hide()
end
end
end
local function SetBarLabelShown(bar, shown)
if not bar or not bar.labelText then
return
end
shown = shown == true
if shown then
bar.labelText:Show()
else
bar.labelText:Hide()
end
if bar.labelOutlineText then
bar.labelOutlineText:SetShown(shown and UsesInvertedClassLabelStyle(bar))
end
ApplyBarLabelStyle(bar)
end
local function SetBarLabelText(bar, text, shown)
if not bar or not bar.labelText then
return
end
SyncBarLabelText(bar, text)
if shown == nil then
shown = (text or "") ~= ""
end
SetBarLabelShown(bar, shown)
end
local function RestoreBarDefaultLabel(bar)
if not bar then
return
end
local text = bar.defaultLabelText or ""
SetBarLabelText(bar, text, text ~= "")
end
function ns.SetBarLabelText(bar, text, shown)
SetBarLabelText(bar, text, shown)
end
function ns.RestoreBarDefaultLabel(bar)
RestoreBarDefaultLabel(bar)
end
function ns.RefreshBarLabelStyles()
for _, bar in ipairs({
ns.enemyBar,
ns.mhBar,
ns.ohBar,
ns.rangedBar,
ns.hunterCastBar,
ns.rogueSliceAndDiceBar,
ns.rogueEnergyTickBar,
ns.rogueEnergyTotalBar,
ns.warriorRageBar
}) do
if bar and bar.labelText then
ApplyBarLabelStyle(bar)
SetBarLabelShown(bar, bar.labelText:IsShown())
end
end
if ns.enemyBar and ns.enemyBar.labelText then
SyncBarLabelText(ns.enemyBar, ns.enemyBar.labelText:GetText())
end
if ns.hunterCastBar and ns.hunterCastBar.labelText then
SyncBarLabelText(ns.hunterCastBar, ns.hunterCastBar.labelText:GetText())
end
if ns.rangedBar and ns.rangedBar.labelText then
SyncBarLabelText(ns.rangedBar, ns.rangedBar.labelText:GetText())
end
if ns.mhBar and ns.mhBar.labelText then
SyncBarLabelText(ns.mhBar, ns.mhBar.labelText:GetText())
end
if ns.ohBar and ns.ohBar.labelText then
SyncBarLabelText(ns.ohBar, ns.ohBar.labelText:GetText())
end
end
local function IsHunterCastSpell(spellId)
return spellId ~= nil and ns.IsHunterCastSpell and ns.IsHunterCastSpell(spellId)
end
local function GetLiveHunterCastInfo()
if type(ns.GetUnitCastingSpellInfo) ~= "function" then
return nil, nil, nil, nil
end
return ns.GetUnitCastingSpellInfo("player")
end
local function GetHunterHiddenCastWindowFromRangedTimer(now)
-- NOTE: The hidden cast window depends only on the ranged timer, not melee state.
-- Hunters can have both MH and ranged swings active simultaneously, and the
-- Auto Shot cast window should always be available for the cast bar to render.
local t = ns.timers and ns.timers.ranged
if not t or t.state ~= "swinging" or not t.duration or t.duration <= 0 then
return nil, nil
end
if t.hiddenCastWindowStart and t.hiddenCastWindowDuration and t.hiddenCastWindowDuration > 0 then
local storedWindowStart = t.hiddenCastWindowStart
local storedWindowEnd = storedWindowStart + t.hiddenCastWindowDuration
if now < storedWindowStart then
t.hiddenCastWindowStart = nil
t.hiddenCastWindowDuration = nil
elseif now <= storedWindowEnd then
return storedWindowStart, t.hiddenCastWindowDuration
elseif ns.isMoving == true and now >= storedWindowStart then
-- Moving past cached window: recompute from live timer instead of
-- shifting the start forward, which can push the window past the real swing end
t.hiddenCastWindowStart = nil
t.hiddenCastWindowDuration = nil
else
t.hiddenCastWindowStart = nil
t.hiddenCastWindowDuration = nil
end
end
local castWindow = math.max(GetRangedCastWindow() or 0.5, 0.01)
local windowEnd = t.lastSwing + t.duration
local windowStart = windowEnd - castWindow
if now < windowStart or now > windowEnd then
return nil, nil
end
t.hiddenCastWindowStart = windowStart
t.hiddenCastWindowDuration = castWindow
return windowStart, castWindow
end
local function IsStoredHunterCastDisplayStateActive(now)
if ns.hunterCastActive ~= true or not IsHunterCastSpell(ns.hunterCastSpellId) then
return false
end
if ns.IsAutoShotSpell and ns.IsAutoShotSpell(ns.hunterCastSpellId) then
return false
end
local startTime = ns.hunterCastStartTime
local duration = ns.hunterCastDuration
if not startTime or not duration or duration <= 0 then
return false
end
if now and now >= (startTime + duration) then
if ns.ClearHunterCastState then
ns.ClearHunterCastState()
end
if ns.RefreshUpdateLoop then
ns.RefreshUpdateLoop()
end
return false
end
return true
end
ShouldShowHunterCastBar = function ()
local cfg = ns.classConfig or {}
local db = SuperSwingTimerDB or ns.DB_DEFAULTS
if ns.playerClass ~= "HUNTER" or not ns.hunterCastBar or not cfg.ranged or db.showRanged == false then
return false
end
local now = ns.GetAlignedTime()
local rangedWindowStart = GetHunterHiddenCastWindowFromRangedTimer(now)
if IsStoredHunterCastDisplayStateActive(now) then
return true
end
if type(ns.GetUnitCastingSpellInfo) == "function" then
local liveSpell = GetLiveHunterCastInfo()
if IsHunterCastSpell(liveSpell) then
if ns.IsAutoShotSpell and ns.IsAutoShotSpell(liveSpell) then
if rangedWindowStart then
return true
end
else
return true
end
end
end
if rangedWindowStart then
return true
end
return false
end
-- ============================================================
-- Bar factory
-- ============================================================
local function CreateBar(frameName, width, height)
local f = CreateFrame("StatusBar", frameName, UIParent)
f:SetSize(ns.Scale(width or ns.BAR_WIDTH), ns.Scale(height or ns.BAR_HEIGHT))
f:SetPoint("CENTER", UIParent, "CENTER", 0, -100)
f:SetMovable(true)
f:EnableMouse(false) -- mouse enabled later by ns.ApplyLockBars() when unlocked
f:SetClampedToScreen(true)
f:SetHitRectInsets(-50, -50, -50, -50)
f:SetStatusBarTexture(ns.GetBarTexture())
f:SetStatusBarColor(0, 0, 0, 1)
f:SetAlpha(0)
local overlayFrame = CreateOverlayFrame(f)
f.overlayFrame = overlayFrame
local statusBarTexture = f:GetStatusBarTexture()
if statusBarTexture then
statusBarTexture:SetDrawLayer(ns.GetBarTextureLayer())
end
local backgroundTexture = f:CreateTexture(nil, "BACKGROUND")
backgroundTexture:SetAllPoints(true)
local backgroundColor = ns.GetBarBackgroundColor and ns.GetBarBackgroundColor()
or (ns.DB_DEFAULTS and ns.DB_DEFAULTS.barBackgroundColor)
backgroundColor = backgroundColor or { r = 0, g = 0, b = 0, a = 0.5 }
backgroundTexture:SetColorTexture(backgroundColor.r or 0, backgroundColor.g or 0, backgroundColor.b or 0, 1)
backgroundTexture:SetAlpha(backgroundColor.a ~= nil and backgroundColor.a or (ns.GetBarBackgroundAlpha() or 1))
-- Border: 4 thin edges so the fill remains visible
local borderColor = ns.GetBarBorderColor and ns.GetBarBorderColor()
or (ns.DB_DEFAULTS and ns.DB_DEFAULTS.barBorderColor)
borderColor = borderColor or { r = 0, g = 0, b = 0, a = 1 }
local borderTop = f:CreateTexture(nil, "OVERLAY")
borderTop:SetColorTexture(borderColor.r or 0, borderColor.g or 0, borderColor.b or 0, borderColor.a or 1)
borderTop:SetPoint("TOPLEFT", -1, 1)
borderTop:SetPoint("TOPRIGHT", 1, 1)
borderTop:SetHeight(1)
local borderBottom = f:CreateTexture(nil, "OVERLAY")
borderBottom:SetColorTexture(borderColor.r or 0, borderColor.g or 0, borderColor.b or 0, borderColor.a or 1)
borderBottom:SetPoint("BOTTOMLEFT", -1, -1)
borderBottom:SetPoint("BOTTOMRIGHT", 1, -1)
borderBottom:SetHeight(1)
local borderLeft = f:CreateTexture(nil, "OVERLAY")
borderLeft:SetColorTexture(borderColor.r or 0, borderColor.g or 0, borderColor.b or 0, borderColor.a or 1)
borderLeft:SetPoint("TOPLEFT", -1, 1)
borderLeft:SetPoint("BOTTOMLEFT", -1, -1)
borderLeft:SetWidth(1)
local borderRight = f:CreateTexture(nil, "OVERLAY")
borderRight:SetColorTexture(borderColor.r or 0, borderColor.g or 0, borderColor.b or 0, borderColor.a or 1)
borderRight:SetPoint("TOPRIGHT", 1, 1)
borderRight:SetPoint("BOTTOMRIGHT", 1, -1)
borderRight:SetWidth(1)
f.borderTextures = { top = borderTop, bottom = borderBottom, left = borderLeft, right = borderRight }
local sparkTexture = overlayFrame:CreateTexture(nil, "OVERLAY")
sparkTexture:SetTexture(ns.GetSparkTexture())
if ns.SetTextureLayerAboveBar then
ns.SetTextureLayerAboveBar(sparkTexture, ns.GetSparkTextureLayer(), ns.GetBarTextureLayer())
else
sparkTexture:SetDrawLayer(ns.GetSparkTextureLayer())
end
sparkTexture:SetBlendMode(GetSparkBlendMode())
sparkTexture:SetWidth(ns.GetSparkWidth())
local sparkHeight = ClampSparkHeightForBar(f, ns.GetSparkHeight())
sparkTexture:SetHeight(sparkHeight)
local sparkColor = ns.GetSparkColor() or ns.DB_DEFAULTS.sparkColor
if sparkColor then
sparkTexture:SetVertexColor(sparkColor.r or 1, sparkColor.g or 1, sparkColor.b or 1, sparkColor.a or 1)
else
sparkTexture:SetVertexColor(1, 1, 1, 1)
end
sparkTexture:SetAlpha(1)
sparkTexture:SetPoint("CENTER", overlayFrame, "LEFT", 0, 0)
local labelOutlineText = overlayFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
labelOutlineText:SetPoint("CENTER")
local outlineFontPath, outlineFontSize = labelOutlineText:GetFont()
if outlineFontPath and outlineFontSize then
labelOutlineText:SetFont(outlineFontPath, outlineFontSize, "OUTLINE")
end
labelOutlineText:SetTextColor(1, 1, 1, 1)
labelOutlineText:Hide()
local labelText = overlayFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
labelText:SetPoint("CENTER")
labelText:SetShadowColor(0, 0, 0, 1)
labelText:SetShadowOffset(1, -1)
labelText:Show()
f.backgroundTexture = backgroundTexture
f.statusBarTexture = statusBarTexture
f.sparkTexture = sparkTexture
f.labelOutlineText = labelOutlineText
f.labelText = labelText
f.barWidth = f:GetWidth()
return f
end
local function CreateEnemyBar()
local f = CreateBar("SuperSwingTimerEnemyBar")
local c = ns.GetBarColor and ns.GetBarColor("enemy")
or (SuperSwingTimerDB and SuperSwingTimerDB.colors and SuperSwingTimerDB.colors.enemy)
if c then
f:SetStatusBarColor(c.r, c.g, c.b, c.a or 1)
else
f:SetStatusBarColor(1, 0, 0, 1)
end
f.defaultLabelText = "Enemy"
RestoreBarDefaultLabel(f)
f:SetMinMaxValues(0, 1)
ns.enemyBar = f
return f
end
-- ============================================================
-- Ranged bar (preserves v1.x behavior exactly)
-- ============================================================
local function CreateRangedBar()
local f = CreateBar("SuperSwingTimerRangedBar")
local overlayFrame = ns.GetOverlayFrame and ns.GetOverlayFrame(f) or f
-- Cast-window overlay (red while moving, green when stopped before the breakpoint)
local castOverlay = overlayFrame:CreateTexture(nil, "ARTWORK")
local autoShotUnsafeColor = GetAutoShotWindowColor("autoShotUnsafe", { r = 1, g = 0, b = 0, a = 0.4 })
castOverlay:SetColorTexture(
autoShotUnsafeColor.r or 1, autoShotUnsafeColor.g or 0, autoShotUnsafeColor.b or 0,
autoShotUnsafeColor.a ~= nil and autoShotUnsafeColor.a or 0.4
)
castOverlay:SetPoint("TOPRIGHT")
castOverlay:SetPoint("BOTTOMRIGHT")
if ns.SetTextureLayerAboveBar then
ns.SetTextureLayerAboveBar(
castOverlay, ns.GetWeaveMarkerLayer and ns.GetWeaveMarkerLayer() or "OVERLAY",
ns.GetBarTextureLayer and ns.GetBarTextureLayer() or "ARTWORK"
)
end
castOverlay:SetWidth(0)
f.castOverlay = castOverlay
-- Opaque marker showing where the bar will switch into the cast window.
local castThresholdMarker = overlayFrame:CreateTexture(nil, "OVERLAY")
castThresholdMarker:SetColorTexture(0, 0, 0, 1)
castThresholdMarker:SetWidth(3)
castThresholdMarker:SetPoint("TOPLEFT")
castThresholdMarker:SetPoint("BOTTOMLEFT")
if ns.SetTextureLayerAboveBar then
ns.SetTextureLayerAboveBar(castThresholdMarker, ns.GetWeaveTriangleLayer(), ns.GetBarTextureLayer())
end
castThresholdMarker:Hide()
f.castThresholdMarker = castThresholdMarker
f.defaultLabelText = ""
RestoreBarDefaultLabel(f)
f:SetMinMaxValues(0, 1)
ns.rangedBar = f
return f
end
local function GetHunterRangedBarLabel()
local db = SuperSwingTimerDB or ns.DB_DEFAULTS
local label = db and db.hunterRangedBarLabel or (ns.DB_DEFAULTS and ns.DB_DEFAULTS.hunterRangedBarLabel) or ""
return strtrim(label or "")
end
function ns.ApplyHunterRangedBarLabel(labelText)
local normalized = strtrim(labelText or "")
SuperSwingTimerDB.hunterRangedBarLabel = normalized
if ns.rangedBar then
ns.rangedBar.defaultLabelText = normalized
RestoreBarDefaultLabel(ns.rangedBar)
end
end
local function CreateHunterCastBar()
local f = CreateBar("SuperSwingTimerHunterCastBar", nil, ns.HUNTER_CAST_BAR_HEIGHT or 10)
local rangedBar = ns.rangedBar
if not rangedBar then
-- No ranged bar yet — hide until bars are fully initialized
f:SetAlpha(0)
ns.hunterCastBar = f
return f
end
local overlayFrame = ns.GetOverlayFrame and ns.GetOverlayFrame(f) or f
f:ClearAllPoints()
f:SetPoint("TOPLEFT", rangedBar, "BOTTOMLEFT", 0, -(ns.HUNTER_CAST_BAR_GAP or 2))
f:SetPoint("TOPRIGHT", rangedBar, "BOTTOMRIGHT", 0, -(ns.HUNTER_CAST_BAR_GAP or 2))
f:SetMovable(false)
f:EnableMouse(false)
f.defaultLabelText = ""
RestoreBarDefaultLabel(f)
if f.labelText then
f.labelText:ClearAllPoints()
f.labelText:SetPoint("LEFT", f, "LEFT", 4, 0)
f.labelText:SetPoint("RIGHT", f, "RIGHT", -60, 0)
f.labelText:SetJustifyH("LEFT")
end
if f.labelOutlineText then
f.labelOutlineText:ClearAllPoints()
f.labelOutlineText:SetPoint("LEFT", f, "LEFT", 4, 0)
f.labelOutlineText:SetPoint("RIGHT", f, "RIGHT", -60, 0)
f.labelOutlineText:SetJustifyH("LEFT")
end
local countdownText = overlayFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
countdownText:SetPoint("RIGHT", f, "RIGHT", -4, 0)
countdownText:SetJustifyH("RIGHT")
countdownText:SetTextColor(1, 1, 1, 1)
f.countdownText = countdownText
if ns.GetRangedBarTexture then
f:SetStatusBarTexture(ns.GetRangedBarTexture())
end
if ns.GetBarColor then
local c = ns.GetBarColor("hunterCastBar")
if c then
f:SetStatusBarColor(c.r, c.g, c.b, c.a or 1)
end
end
f:SetAlpha(0)
local latencyOverlay = overlayFrame:CreateTexture(nil, "ARTWORK")
latencyOverlay:SetPoint("TOPRIGHT")
latencyOverlay:SetPoint("BOTTOMRIGHT")
latencyOverlay:SetWidth(0)
if ns.SetTextureLayerAboveBar then
ns.SetTextureLayerAboveBar(
latencyOverlay, ns.GetWeaveMarkerLayer and ns.GetWeaveMarkerLayer() or "OVERLAY",
ns.GetBarTextureLayer and ns.GetBarTextureLayer() or "ARTWORK"
)
end
f.latencyOverlay = latencyOverlay
local latencyMarker = overlayFrame:CreateTexture(nil, "OVERLAY")
latencyMarker:SetColorTexture(1, 1, 1, 1)
latencyMarker:SetPoint("TOPLEFT")
latencyMarker:SetPoint("BOTTOMLEFT")
latencyMarker:SetWidth(2)
if ns.SetTextureLayerAboveBar then
ns.SetTextureLayerAboveBar(
latencyMarker, ns.GetWeaveTriangleLayer and ns.GetWeaveTriangleLayer() or "OVERLAY",
ns.GetBarTextureLayer and ns.GetBarTextureLayer() or "ARTWORK"
)
end
latencyMarker:Hide()
f.latencyMarker = latencyMarker
f:SetMinMaxValues(0, 1)
f:SetValue(0)
f:SetAlpha(0)
ns.hunterCastBar = f
return f
end
-- ============================================================
-- Melee bars (MH and optional OH)
-- ============================================================
local function CreateMHBar()
local f = CreateBar("SuperSwingTimerMHBar")
local c = ns.GetBarColor and ns.GetBarColor("mh")
or (SuperSwingTimerDB and SuperSwingTimerDB.colors and SuperSwingTimerDB.colors.mh)
if c then
f:SetStatusBarColor(c.r, c.g, c.b, c.a)
else
f:SetStatusBarColor(0, 0, 0, 1)
end
f.defaultLabelText = "Main Hand"
RestoreBarDefaultLabel(f)
f:SetMinMaxValues(0, 1)
ns.mhBar = f
return f
end
local function CreateOHBar()
local mh = ns.mhBar
local f = ns.ohBar or rawget(_G, "SuperSwingTimerOHBar")
local offHandHeight = GetOffHandBarHeight((mh and mh:GetHeight()) or ns.BAR_HEIGHT)
local offHandWidth = (mh and mh:GetWidth()) or ns.BAR_WIDTH
if not f then
f = CreateBar("SuperSwingTimerOHBar", offHandWidth, offHandHeight)
end
local c = ns.GetBarColor and ns.GetBarColor("oh")
or (SuperSwingTimerDB and SuperSwingTimerDB.colors and SuperSwingTimerDB.colors.oh)
if c then
f:SetStatusBarColor(c.r, c.g, c.b, c.a)
else
f:SetStatusBarColor(0, 0, 0, 1)
end
f.defaultLabelText = "Off Hand"
RestoreBarDefaultLabel(f)
f:SetMinMaxValues(0, 1)
f:SetSize(offHandWidth, offHandHeight)
if f.sparkTexture then
f.sparkTexture:SetHeight(ClampSparkHeightForBar(f, ns.GetSparkHeight()))
end
-- Anchor OH below MH with 2px gap
f:ClearAllPoints()
f:SetPoint("TOPLEFT", mh, "BOTTOMLEFT", 0, -2)
f:SetPoint("TOPRIGHT", mh, "BOTTOMRIGHT", 0, -2)
f:Show()
ns.ohBar = f
return f
end
-- ============================================================
-- Cast-zone visual for ranged bar
-- ============================================================
local function UpdateCastZoneVisual(castWindow, isSafeStop)
local f = ns.rangedBar
if not f then return end
local t = ns.timers.ranged
local duration = t and t.duration or 0
local barWidth = f:GetWidth() or f.barWidth or ns.BAR_WIDTH or 0
castWindow = castWindow or GetRangedCastWindow()
if t and t.state == "swinging" and duration > 0 and castWindow > 0 then
local width = math.min((castWindow / duration) * barWidth, barWidth)
if width < 0 then width = 0 end
f.castOverlay:SetWidth(width)
if isSafeStop == nil then
isSafeStop = IsRangedCastWindowSafe(t, castWindow)
end
if isSafeStop then
local safeColor = GetAutoShotWindowColor("autoShotSafe", { r = 0.2, g = 0.78, b = 0.25, a = 0.4 })
f.castOverlay:SetColorTexture(
safeColor.r or 0.2, safeColor.g or 0.78, safeColor.b or 0.25, safeColor.a ~= nil and safeColor.a or 0.4
)
else
local unsafeColor = GetAutoShotWindowColor("autoShotUnsafe", { r = 1, g = 0, b = 0, a = 0.4 })
f.castOverlay:SetColorTexture(
unsafeColor.r or 1, unsafeColor.g or 0, unsafeColor.b or 0,
unsafeColor.a ~= nil and unsafeColor.a or 0.4
)
end
if f.castThresholdMarker then
local markerWidth = math.min(3, barWidth)
local markerLeft = math.max(barWidth - width - (markerWidth * 0.5), 0)
local markerAnchor = ns.GetOverlayFrame and ns.GetOverlayFrame(f) or f
f.castThresholdMarker:ClearAllPoints()
f.castThresholdMarker:SetPoint("TOPLEFT", markerAnchor, "LEFT", markerLeft, 0)
f.castThresholdMarker:SetPoint("BOTTOMLEFT", markerAnchor, "LEFT", markerLeft, 0)
f.castThresholdMarker:SetWidth(markerWidth)
f.castThresholdMarker:Show()
end
else
f.castOverlay:SetWidth(0)
if f.castThresholdMarker then
f.castThresholdMarker:Hide()
end
end
end
ns.UpdateCastZoneVisual = UpdateCastZoneVisual
local function ApplyHunterCastBarColor(spellId, remainingCastTime, now)
local f = ns.hunterCastBar
if not f then
return nil
end
-- Use the dedicated hunter cast bar color, not the ranged bar fill color
-- This allows users to set the cast bar color independently from the ranged bar
local baseColor = (ns.GetBarColor and ns.GetBarColor("hunterCastBar")) or { r = 0, g = 0, b = 0, a = 1 }
local alpha = baseColor.a ~= nil and baseColor.a or 1
local clipSafe = nil
if spellId and remainingCastTime and remainingCastTime > 0 then
local isSpellEligible = (ns.IsHunterActualCastSpell and ns.IsHunterActualCastSpell(spellId))
or (ns.IsMultiShotSpell and ns.IsMultiShotSpell(spellId))
if isSpellEligible then
local timeUntilNextShot = ns.GetTimeUntilNextHunterRangedShot and ns.GetTimeUntilNextHunterRangedShot(now)
or nil
if timeUntilNextShot ~= nil then
local safetyBuffer = math.max(ns.cachedLatency or 0, 0.03)
local isMultiShot = ns.IsMultiShotSpell and ns.IsMultiShotSpell(spellId)
-- Multi-Shot has 0 grace: its hidden window delays Auto Shot on overlap.
-- Steady Shot has a 0.5s grace period: Auto Shot fires during the last 0.5s
-- of the cast without clipping. This makes the green/red tint match real
-- TBC hunter clip behavior for both spell types.
local gracePeriod = isMultiShot and 0 or (ns.STEADY_SHOT_GRACE or 0.5)
clipSafe = remainingCastTime <= math.max(timeUntilNextShot + gracePeriod - safetyBuffer, 0)
if clipSafe then
local safeColor = GetAutoShotWindowColor("autoShotSafe", { r = 0.2, g = 0.78, b = 0.25, a = 0.4 })
f:SetStatusBarColor(safeColor.r or 0.2, safeColor.g or 0.78, safeColor.b or 0.25, alpha)
else
local unsafeColor = GetAutoShotWindowColor("autoShotUnsafe", { r = 1, g = 0, b = 0, a = 0.4 })
f:SetStatusBarColor(unsafeColor.r or 1, unsafeColor.g or 0, unsafeColor.b or 0, alpha)
end
return clipSafe
end
end
end
f:SetStatusBarColor(baseColor.r or 0, baseColor.g or 0, baseColor.b or 0, alpha)
return clipSafe
end
---@param duration number|nil
---@param showVisual boolean
local function UpdateHunterCastLatencyVisual(duration, showVisual)
local f = ns.hunterCastBar
if not f or not f.latencyOverlay then
return
end
if not showVisual or not duration or duration <= 0 then
f.latencyOverlay:SetWidth(0)
if f.latencyMarker then
f.latencyMarker:Hide()
end
return
end
local latencyWindow = math.max(ns.cachedLatency or 0, 0)
local barWidth = f:GetWidth() or f.barWidth or ns.BAR_WIDTH or 0
if latencyWindow <= 0 or barWidth <= 0 then
f.latencyOverlay:SetWidth(0)
if f.latencyMarker then
f.latencyMarker:Hide()
end
return
end
local overlayColor = GetAutoShotWindowColor("autoShotUnsafe", { r = 1, g = 0, b = 0, a = 0.4 })
local overlayAlpha = overlayColor.a ~= nil and overlayColor.a or 0.4
f.latencyOverlay:SetColorTexture(
overlayColor.r or 1, overlayColor.g or 0, overlayColor.b or 0,
math.max(math.min(overlayAlpha * 0.6, 0.35), 0.12)
)
local width = math.min((latencyWindow / duration) * barWidth, barWidth)
if width <= 0 then
f.latencyOverlay:SetWidth(0)
if f.latencyMarker then
f.latencyMarker:Hide()
end
return
end
f.latencyOverlay:SetWidth(width)
if f.latencyMarker then
local markerAnchor = ns.GetOverlayFrame and ns.GetOverlayFrame(f) or f
local markerWidth = math.min(2, barWidth)
local markerLeft = math.max(barWidth - width - (markerWidth * 0.5), 0)
f.latencyMarker:ClearAllPoints()
f.latencyMarker:SetPoint("TOPLEFT", markerAnchor, "LEFT", markerLeft, 0)
f.latencyMarker:SetPoint("BOTTOMLEFT", markerAnchor, "LEFT", markerLeft, 0)
f.latencyMarker:SetWidth(markerWidth)
f.latencyMarker:Show()
end
end
local function UpdateHunterCastBar()
local f = ns.hunterCastBar
if not f then
return
end
if not ShouldShowHunterCastBar() then
RestoreBarDefaultLabel(f)
f:SetAlpha(0)
f:SetMinMaxValues(0, 1)
f:SetValue(0)
UpdateHunterCastLatencyVisual(nil, false)
UpdateHunterMeleeBarAnchor(false)
return
end
local now = ns.GetAlignedTime()
local castWindow = math.max(GetRangedCastWindow() or 0.5, 0.01)
-- ns.CAST_WINDOW is a constant defined in Constants.lua
local elapsedTime
local duration
local rangedWindowStart, rangedWindowDuration = GetHunterHiddenCastWindowFromRangedTimer(now)
local usingStoredHunterCast = false
local usingLiveHunterCast = false
local isAutoShotHiddenWindow = false
local spellId = ns.hunterCastSpellId or ns.currentCastSpellId
local startTime = nil
if type(ns.GetUnitCastingSpellInfo) == "function" then
local liveSpell, liveSpellName, startTimeMs, endTimeMs = GetLiveHunterCastInfo()
if IsHunterCastSpell(liveSpell) then
local isAutoShotSpell = ns.IsAutoShotSpell and ns.IsAutoShotSpell(liveSpell)
spellId = liveSpell
if isAutoShotSpell then
if rangedWindowStart and rangedWindowDuration and rangedWindowDuration > 0 then
usingLiveHunterCast = true
startTime = rangedWindowStart
duration = rangedWindowDuration
end
else
usingLiveHunterCast = true
spellId = liveSpell or liveSpellName
if type(startTimeMs) == "number" and startTimeMs > 0 then
startTime = (startTimeMs / 1000)
end
if type(startTimeMs) == "number" and type(endTimeMs) == "number" and endTimeMs > startTimeMs then
duration = math.max((endTimeMs - startTimeMs) / 1000, 0.01)
end
end
end
end
if usingLiveHunterCast and not startTime then
startTime = now
end
if usingLiveHunterCast and (not duration or duration <= 0) then
duration = math.max(ns.hunterCastDuration or castWindow, 0.01)
end
if not startTime and IsStoredHunterCastDisplayStateActive(now) then
usingStoredHunterCast = true
spellId = ns.hunterCastSpellId
startTime = ns.hunterCastStartTime
duration = math.max(ns.hunterCastDuration or castWindow, 0.01)
end
if not startTime and rangedWindowStart and rangedWindowDuration and rangedWindowDuration > 0 then