-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSBM_Layout.lua
More file actions
executable file
·1986 lines (1769 loc) · 51.1 KB
/
SBM_Layout.lua
File metadata and controls
executable file
·1986 lines (1769 loc) · 51.1 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
-- SimpleBossMods layout and record management.
local ADDON_NAME = ...
local M = _G[ADDON_NAME]
if not M then return end
local C = M.Const
local L = M.Live
local U = M.Util
local frames = M.frames
local wipe = _G.wipe or function(t)
for k in pairs(t) do
t[k] = nil
end
end
local layoutIconList = {}
local layoutBarList = {}
local Enum_EncounterTimelineEventState = Enum and Enum.EncounterTimelineEventState
local EVENT_STATE_FINISHED = Enum_EncounterTimelineEventState and Enum_EncounterTimelineEventState.Finished
local EVENT_STATE_CANCELED = Enum_EncounterTimelineEventState and Enum_EncounterTimelineEventState.Canceled
local function isSecretValue(value)
return type(issecretvalue) == "function" and issecretvalue(value)
end
local function unpackColor(color)
if type(color) ~= "table" then
return nil
end
local rawR = color.r or color[1]
local rawG = color.g or color[2]
local rawB = color.b or color[3]
local rawA = color.a or color[4] or 1
local hasSecret = isSecretValue(rawR) or isSecretValue(rawG) or isSecretValue(rawB) or isSecretValue(rawA)
if hasSecret then
if rawR ~= nil and rawG ~= nil and rawB ~= nil then
return rawR, rawG, rawB, rawA, true
end
return nil
end
local r = tonumber(rawR)
local g = tonumber(rawG)
local b = tonumber(rawB)
local a = tonumber(rawA)
if isSecretValue(r) or isSecretValue(g) or isSecretValue(b) or isSecretValue(a) then
return nil
end
if type(r) ~= "number" or type(g) ~= "number" or type(b) ~= "number" then
return nil
end
return U.clamp(r, 0, 1), U.clamp(g, 0, 1), U.clamp(b, 0, 1), U.clamp(a, 0, 1), false
end
local function getIndicatorBarColor(rec)
if type(rec) ~= "table" then return nil end
local eventInfo = rec.eventInfo
if type(eventInfo) ~= "table" then return nil end
local rawMask = eventInfo.icons
if rawMask == nil then
rawMask = rec._indicatorMask
end
if isSecretValue(rawMask) then
rawMask = nil
end
local mask = tonumber(rawMask)
if type(mask) ~= "number" or mask <= 0 then
mask = nil
end
local rawSeverity = eventInfo.severity
if isSecretValue(rawSeverity) then
rawSeverity = nil
end
if type(M.ResolveIndicatorColorForEvent) == "function" then
return M.ResolveIndicatorColorForEvent(mask, rawSeverity)
end
if type(M.ResolveIndicatorColorForMask) == "function" and mask then
return M.ResolveIndicatorColorForMask(mask)
end
return nil
end
local function getTimelineBarColor(rec)
if type(rec) ~= "table" then return nil end
local eventInfo = rec.eventInfo
if type(eventInfo) ~= "table" then return nil end
local indicatorR, indicatorG, indicatorB, indicatorA = getIndicatorBarColor(rec)
if indicatorR then
return indicatorR, indicatorG, indicatorB, indicatorA
end
local colorR, colorG, colorB, colorA, colorSecret = unpackColor(eventInfo.color or eventInfo.barColor)
local fromR, fromG, fromB, fromA, fromSecret = unpackColor(eventInfo.colorFrom)
local toR, toG, toB, toA, toSecret = unpackColor(eventInfo.colorTo)
if fromR and toR then
if fromSecret or toSecret then
return fromR, fromG, fromB, fromA
end
local rawRem = rec.remaining
if isSecretValue(rawRem) then
rawRem = nil
end
local rem = tonumber(rawRem)
if isSecretValue(rem) then
rem = nil
end
local window = tonumber(rec._timelineColorStartRemaining)
if isSecretValue(window) then
window = nil
end
if not window or window <= 0 then
window = tonumber(L.THRESHOLD_TO_BAR) or 0
end
if window > 0 and rem then
local shown = rem
if shown < 0 then shown = 0 end
if shown > window then shown = window end
local progress = (window - shown) / window
if progress < 0 then progress = 0 end
if progress > 1 then progress = 1 end
local r = (
fromR + (toR - fromR) * progress
)
local g = (
fromG + (toG - fromG) * progress
)
local b = (
fromB + (toB - fromB) * progress
)
local a = (
fromA + (toA - fromA) * progress
)
return r, g, b, a
end
end
if colorR then
if colorSecret then
return colorR, colorG, colorB, colorA
end
return colorR, colorG, colorB, colorA
end
if fromR then
return fromR, fromG, fromB, fromA
end
if toR then
return toR, toG, toB, toA
end
return nil
end
local function resolveAppliedBarColor(rec)
local r, g, b, a = getTimelineBarColor(rec)
if r then
return true, r, g, b, a or 1
end
return false, L.BAR_FG_R, L.BAR_FG_G, L.BAR_FG_B, L.BAR_FG_A or 1
end
local function getIconBorderColor(rec)
if not L.USE_ICON_BORDER_COLORS then
return nil
end
local _, r, g, b, a = resolveAppliedBarColor(rec)
return r, g, b, a
end
local QUEUED_LABEL = "Queued"
local PAUSED_LABEL = "Paused"
local BLOCKED_LABEL = "Blocked"
local BLOCKED_ICON_VERTEX = 0.55
local BLOCKED_BORDER_COLOR = 0.50
local BAR_OUTRO_KIND_FINISH = "finish"
local BAR_OUTRO_KIND_CANCEL = "cancel"
local BAR_CANCEL_ANIMATION_DURATION = 0.35
local BAR_CANCEL_ANIMATION_FADE_DURATION = 0.30
local BAR_FINISH_ANIMATION_DURATION = 0.35
local BAR_FINISH_ANIMATION_FADE_DURATION = 0.30
local BAR_FINISH_ANIMATION_MOVE_DURATION = 0.40
local BAR_FINISH_ANIMATION_MOVE_DISTANCE = -80
local function saturate(value)
return U.clamp(tonumber(value) or 0, 0, 1)
end
local function evaluateInCubic(progress)
if EasingUtil and EasingUtil.InCubic then
return EasingUtil.InCubic(progress)
end
progress = saturate(progress)
return progress * progress * progress
end
local function evaluateInBack(progress)
if EasingUtil and EasingUtil.InBack then
return EasingUtil.InBack(progress)
end
progress = saturate(progress)
local c1 = 1.70158
local c3 = c1 + 1
return c3 * progress * progress * progress - c1 * progress * progress
end
local function lerp(a, b, progress)
return a + ((b - a) * progress)
end
local function barsAnimationEnabled()
return L.ANIMATE_BARS ~= false
end
local function iconsAnimationEnabled()
return L.ANIMATE_ICONS ~= false
end
local function finishBarOutro(bar)
if M and M.releaseBar then
M.releaseBar(bar)
else
bar:SetScript("OnUpdate", nil)
bar:Hide()
end
end
local function barOutroOnUpdate(bar, elapsed)
local data = bar and bar.__sbmBarOutro
if not data then
if bar then
bar:SetScript("OnUpdate", nil)
end
return
end
if not barsAnimationEnabled() then
local owner = data.owner
if owner and owner.ClearBarAnimation then
owner:ClearBarAnimation(bar, false)
end
finishBarOutro(bar)
return
end
data.elapsed = data.elapsed + (elapsed or 0)
local elapsedTime = data.elapsed
local alphaProgress = saturate(elapsedTime / data.fadeDuration)
local alphaValue = 1 - evaluateInCubic(alphaProgress)
bar:SetAlpha((data.startAlpha or 1) * alphaValue)
if data.moveDuration and data.moveDuration > 0 and data.moveDistance and data.moveDistance ~= 0 then
local moveProgress = saturate(elapsedTime / data.moveDuration)
local moveOffset = lerp(0, data.moveDistance, evaluateInBack(moveProgress))
bar:ClearAllPoints()
bar:SetPoint(data.point, data.relativeTo, data.relativePoint, data.x + moveOffset, data.y)
end
if elapsedTime >= data.duration then
local owner = data.owner
if owner and owner.ClearBarAnimation then
-- Natural outro completion should not reset alpha/position before release.
owner:ClearBarAnimation(bar, false)
end
finishBarOutro(bar)
end
end
function M:HasDetachedBarOutros()
return (self._barOutroCount or 0) > 0
end
function M:HasDetachedIconOutros()
return (self._iconOutroCount or 0) > 0
end
local function requestDeferredLayout(owner)
if not owner or owner._layoutFlushPending then
return
end
owner._layoutFlushPending = true
C_Timer.After(0, function()
owner._layoutFlushPending = nil
if owner._layoutDirty
and not owner:HasDetachedBarOutros()
and not owner:HasDetachedIconOutros() then
owner:LayoutAll()
end
end)
end
function M:ClearBarAnimation(bar, resetVisual)
if not bar then return end
local data = bar.__sbmBarOutro
if not data then
return
end
bar.__sbmBarOutro = nil
bar:SetScript("OnUpdate", nil)
if resetVisual ~= false then
bar:SetAlpha(data.startAlpha or 1)
bar:ClearAllPoints()
bar:SetPoint(data.point, data.relativeTo, data.relativePoint, data.x, data.y)
end
local outroFrames = self._barOutroFrames
if outroFrames and outroFrames[bar] then
outroFrames[bar] = nil
self._barOutroCount = math.max((self._barOutroCount or 1) - 1, 0)
if self._barOutroCount == 0 and self._layoutDirty then
requestDeferredLayout(self)
end
end
end
local function getRecordRemainingForOutro(rec)
if type(rec) ~= "table" then
return nil
end
local rem = rec.remaining
if isSecretValue(rem) then
rem = nil
end
rem = tonumber(rem)
if rec.isQueued or rec.isPaused or rec.isBlocked then
return rem
end
local duration = rec.duration
local startTime = rec.startTime
if not isSecretValue(duration) and not isSecretValue(startTime) then
duration = tonumber(duration)
startTime = tonumber(startTime)
if type(duration) == "number" and duration > 0 and type(startTime) == "number" then
local now = (GetTime and GetTime()) or 0
return duration - (now - startTime)
end
end
return rem
end
function M:GetTimelineBarOutroKind(rec, _reason)
return BAR_OUTRO_KIND_FINISH
end
function M:PlayTimelineBarOutro(rec, outroKind)
local bar = rec and rec.barFrame
if not bar or not bar:IsShown() then
return false
end
if not barsAnimationEnabled() then
return false
end
local point, relativeTo, relativePoint, x, y = bar:GetPoint(1)
if not point or not relativePoint then
return false
end
self:StopBarLayoutMotion(bar, false)
self:StopBarFadeIn(bar, false)
self:ClearBarAnimation(bar)
local duration = BAR_CANCEL_ANIMATION_DURATION
local fadeDuration = BAR_CANCEL_ANIMATION_FADE_DURATION
local moveDuration = nil
local moveDistance = nil
if outroKind == BAR_OUTRO_KIND_FINISH then
duration = BAR_FINISH_ANIMATION_DURATION
fadeDuration = BAR_FINISH_ANIMATION_FADE_DURATION
moveDuration = BAR_FINISH_ANIMATION_MOVE_DURATION
moveDistance = BAR_FINISH_ANIMATION_MOVE_DISTANCE
if L.BAR_FILL_REVERSE then
moveDistance = moveDistance * -1
end
end
bar.__sbmBarOutro = {
owner = self,
duration = duration,
elapsed = 0,
fadeDuration = fadeDuration,
moveDuration = moveDuration,
moveDistance = moveDistance,
point = point,
relativeTo = relativeTo,
relativePoint = relativePoint,
x = x,
y = y,
startAlpha = bar:GetAlpha(),
}
local outroFrames = self._barOutroFrames
if not outroFrames then
outroFrames = {}
self._barOutroFrames = outroFrames
end
if not outroFrames[bar] then
outroFrames[bar] = true
self._barOutroCount = (self._barOutroCount or 0) + 1
end
bar:SetScript("OnUpdate", barOutroOnUpdate)
return true
end
-- =========================
-- Layout
-- =========================
local function sortByRemaining(a, b)
return (a.remaining or 999999) < (b.remaining or 999999)
end
local BAR_LAYOUT_MOVE_RATE = 14
local BAR_LAYOUT_SNAP_DISTANCE = 0.75
local BAR_LAYOUT_ENTRY_OFFSET_FACTOR = 0.35
local BAR_LAYOUT_FADE_IN_DURATION = 0.18
local function setBarLayoutPoint(bar, point, offsetY)
bar:ClearAllPoints()
bar:SetPoint(point, frames.barsParent, point, 0, offsetY)
bar.__sbmLayoutPoint = point
bar.__sbmLayoutY = offsetY
bar.__sbmLayoutTargetY = offsetY
end
local function stopBarFadeIn(owner, bar, setOpaque)
if not bar then
return
end
local fadeBars = owner and owner._barLayoutFadeInBars
if fadeBars then
fadeBars[bar] = nil
end
bar.__sbmFadeInElapsed = nil
if setOpaque then
bar:SetAlpha(1)
end
end
local function startBarFadeIn(owner, bar)
if not owner or not bar then
return
end
if not barsAnimationEnabled() then
bar:SetAlpha(1)
return
end
stopBarFadeIn(owner, bar, false)
local fadeBars = owner._barLayoutFadeInBars
if not fadeBars then
fadeBars = {}
owner._barLayoutFadeInBars = fadeBars
end
bar.__sbmFadeInElapsed = 0
bar:SetAlpha(0)
fadeBars[bar] = true
end
local function ensureBarLayoutMotionDriver(owner)
local driver = owner._barLayoutMotionDriver
if driver then
return driver
end
driver = CreateFrame("Frame")
driver:Hide()
driver:SetScript("OnUpdate", function(_, elapsed)
local movingBars = owner._barLayoutMovingBars
local fadeBars = owner._barLayoutFadeInBars
local hasMovingBars = movingBars and next(movingBars) ~= nil
local hasFadingBars = fadeBars and next(fadeBars) ~= nil
if not hasMovingBars and not hasFadingBars then
driver:Hide()
return
end
if not barsAnimationEnabled() then
if hasMovingBars then
for bar in pairs(movingBars) do
local point = bar and bar.__sbmLayoutPoint
local targetY = bar and tonumber(bar.__sbmLayoutTargetY)
if bar and bar:IsShown() and point and type(targetY) == "number" then
setBarLayoutPoint(bar, point, targetY)
end
movingBars[bar] = nil
end
end
if hasFadingBars then
for bar in pairs(fadeBars) do
if bar and bar:IsShown() then
bar:SetAlpha(1)
end
fadeBars[bar] = nil
end
end
driver:Hide()
return
end
local layoutLocked = owner.HasDetachedBarOutros and owner:HasDetachedBarOutros()
if hasMovingBars and not layoutLocked then
local progress = saturate((elapsed or 0) * BAR_LAYOUT_MOVE_RATE)
if progress > 0 then
for bar in pairs(movingBars) do
if not bar or not bar:IsShown() then
movingBars[bar] = nil
else
local point = bar.__sbmLayoutPoint
local targetY = tonumber(bar.__sbmLayoutTargetY)
local currentY = tonumber(bar.__sbmLayoutY)
if not point or type(targetY) ~= "number" then
movingBars[bar] = nil
else
if type(currentY) ~= "number" then
currentY = targetY
end
local nextY = lerp(currentY, targetY, progress)
if math.abs(nextY - targetY) <= BAR_LAYOUT_SNAP_DISTANCE then
nextY = targetY
movingBars[bar] = nil
end
bar.__sbmLayoutY = nextY
bar:ClearAllPoints()
bar:SetPoint(point, frames.barsParent, point, 0, nextY)
end
end
end
end
end
if hasFadingBars then
local fadeProgress = saturate((elapsed or 0) / BAR_LAYOUT_FADE_IN_DURATION)
if fadeProgress > 0 then
for bar in pairs(fadeBars) do
if not bar or not bar:IsShown() then
fadeBars[bar] = nil
else
local alpha = bar:GetAlpha()
local nextAlpha = lerp(alpha, 1, fadeProgress)
if nextAlpha >= 0.995 then
nextAlpha = 1
fadeBars[bar] = nil
bar.__sbmFadeInElapsed = nil
else
bar.__sbmFadeInElapsed = (bar.__sbmFadeInElapsed or 0) + (elapsed or 0)
end
bar:SetAlpha(nextAlpha)
end
end
end
end
local stillMoving = movingBars and next(movingBars) ~= nil
local stillFading = fadeBars and next(fadeBars) ~= nil
if not stillMoving and not stillFading then
driver:Hide()
end
end)
owner._barLayoutMotionDriver = driver
return driver
end
function M:StopBarFadeIn(bar, setOpaque)
stopBarFadeIn(self, bar, setOpaque)
local movingBars = self._barLayoutMovingBars
local fadeBars = self._barLayoutFadeInBars
if (not movingBars or not next(movingBars)) and (not fadeBars or not next(fadeBars)) and self._barLayoutMotionDriver then
self._barLayoutMotionDriver:Hide()
end
end
function M:StopBarLayoutMotion(bar, snapToTarget)
if not bar then
return
end
local movingBars = self._barLayoutMovingBars
if movingBars then
movingBars[bar] = nil
local fadeBars = self._barLayoutFadeInBars
if not next(movingBars) and (not fadeBars or not next(fadeBars)) and self._barLayoutMotionDriver then
self._barLayoutMotionDriver:Hide()
end
end
if snapToTarget then
local point = bar.__sbmLayoutPoint
local targetY = tonumber(bar.__sbmLayoutTargetY)
if point and type(targetY) == "number" then
setBarLayoutPoint(bar, point, targetY)
end
end
end
function M:SetBarLayoutTarget(bar, point, offsetY, animate)
if not bar or not point then
return
end
local doAnimate = animate and barsAnimationEnabled()
local targetY = tonumber(offsetY) or 0
bar.__sbmLayoutPoint = point
bar.__sbmLayoutTargetY = targetY
local currentY = tonumber(bar.__sbmLayoutY)
local isNewBarPosition = type(currentY) ~= "number"
if isNewBarPosition and bar:IsShown() and doAnimate then
startBarFadeIn(self, bar)
local driver = ensureBarLayoutMotionDriver(self)
driver:Show()
elseif isNewBarPosition and bar:IsShown() then
self:StopBarFadeIn(bar, true)
end
local hasMovingBars = self._barLayoutMovingBars and next(self._barLayoutMovingBars) ~= nil
local hasDetachedBarOutros = self.HasDetachedBarOutros and self:HasDetachedBarOutros()
if isNewBarPosition and doAnimate and bar:IsShown() and hasMovingBars and not hasDetachedBarOutros then
local spawnOffset = ((tonumber(L.BAR_HEIGHT) or 0) + (tonumber(L.GAP) or 0)) * BAR_LAYOUT_ENTRY_OFFSET_FACTOR
if spawnOffset <= 0 then
spawnOffset = 1
end
local spawnY = targetY + spawnOffset
setBarLayoutPoint(bar, point, spawnY)
currentY = spawnY
end
if not doAnimate or not bar:IsShown() or type(currentY) ~= "number" then
self:StopBarLayoutMotion(bar, false)
setBarLayoutPoint(bar, point, targetY)
return
end
if math.abs(currentY - targetY) <= BAR_LAYOUT_SNAP_DISTANCE then
self:StopBarLayoutMotion(bar, false)
setBarLayoutPoint(bar, point, targetY)
return
end
local movingBars = self._barLayoutMovingBars
if not movingBars then
movingBars = {}
self._barLayoutMovingBars = movingBars
end
movingBars[bar] = true
local driver = ensureBarLayoutMotionDriver(self)
driver:Show()
end
local ICON_LAYOUT_MOVE_RATE = 14
local ICON_LAYOUT_SNAP_DISTANCE = 0.75
local ICON_FADE_IN_DURATION = 0.14
local ICON_OUTRO_FADE_DURATION = 0.20
local function setIconLayoutPoint(icon, point, offsetX, offsetY)
icon:ClearAllPoints()
icon:SetPoint(point, frames.iconsParent, point, offsetX, offsetY)
icon.__sbmIconLayoutPoint = point
icon.__sbmIconLayoutX = offsetX
icon.__sbmIconLayoutY = offsetY
icon.__sbmIconLayoutTargetX = offsetX
icon.__sbmIconLayoutTargetY = offsetY
end
local function stopIconFadeIn(owner, icon, setOpaque)
if not icon then
return
end
local fadeIcons = owner and owner._iconLayoutFadeInIcons
if fadeIcons then
fadeIcons[icon] = nil
end
if setOpaque then
icon:SetAlpha(1)
end
end
local function stopIconOutro(owner, icon, setOpaque)
if not icon then
return
end
local outroIcons = owner and owner._iconOutroIcons
if outroIcons and outroIcons[icon] then
outroIcons[icon] = nil
owner._iconOutroCount = math.max((owner._iconOutroCount or 1) - 1, 0)
if owner._iconOutroCount == 0 and owner._layoutDirty then
requestDeferredLayout(owner)
end
end
icon.__sbmIconOutro = nil
if setOpaque then
icon:SetAlpha(1)
end
end
local function startIconFadeIn(owner, icon)
if not owner or not icon then
return
end
if not iconsAnimationEnabled() then
icon:SetAlpha(1)
return
end
stopIconFadeIn(owner, icon, false)
local fadeIcons = owner._iconLayoutFadeInIcons
if not fadeIcons then
fadeIcons = {}
owner._iconLayoutFadeInIcons = fadeIcons
end
icon:SetAlpha(0)
fadeIcons[icon] = true
end
local function finishIconOutro(icon)
if M and M.releaseIcon then
M.releaseIcon(icon)
else
icon:Hide()
end
end
local function ensureIconLayoutMotionDriver(owner)
local driver = owner._iconLayoutMotionDriver
if driver then
return driver
end
driver = CreateFrame("Frame")
driver:Hide()
driver:SetScript("OnUpdate", function(_, elapsed)
local moveIcons = owner._iconLayoutMovingIcons
local fadeInIcons = owner._iconLayoutFadeInIcons
local outroIcons = owner._iconOutroIcons
local hasMove = moveIcons and next(moveIcons) ~= nil
local hasFadeIn = fadeInIcons and next(fadeInIcons) ~= nil
local hasOutro = outroIcons and next(outroIcons) ~= nil
if not hasMove and not hasFadeIn and not hasOutro then
driver:Hide()
return
end
if not iconsAnimationEnabled() then
if hasMove then
for icon in pairs(moveIcons) do
local point = icon and icon.__sbmIconLayoutPoint
local targetX = icon and tonumber(icon.__sbmIconLayoutTargetX)
local targetY = icon and tonumber(icon.__sbmIconLayoutTargetY)
if icon and icon:IsShown() and point and type(targetX) == "number" and type(targetY) == "number" then
setIconLayoutPoint(icon, point, targetX, targetY)
end
moveIcons[icon] = nil
end
end
if hasFadeIn then
for icon in pairs(fadeInIcons) do
if icon and icon:IsShown() then
icon:SetAlpha(1)
end
fadeInIcons[icon] = nil
end
end
if hasOutro then
for icon in pairs(outroIcons) do
stopIconOutro(owner, icon, false)
if icon then
finishIconOutro(icon)
end
end
end
driver:Hide()
return
end
local layoutLocked = owner.HasDetachedIconOutros and owner:HasDetachedIconOutros()
if hasMove and not layoutLocked then
local progress = saturate((elapsed or 0) * ICON_LAYOUT_MOVE_RATE)
if progress > 0 then
for icon in pairs(moveIcons) do
if not icon or not icon:IsShown() then
moveIcons[icon] = nil
else
local point = icon.__sbmIconLayoutPoint
local targetX = tonumber(icon.__sbmIconLayoutTargetX)
local targetY = tonumber(icon.__sbmIconLayoutTargetY)
local currentX = tonumber(icon.__sbmIconLayoutX)
local currentY = tonumber(icon.__sbmIconLayoutY)
if not point or type(targetX) ~= "number" or type(targetY) ~= "number" then
moveIcons[icon] = nil
else
if type(currentX) ~= "number" then currentX = targetX end
if type(currentY) ~= "number" then currentY = targetY end
local nextX = lerp(currentX, targetX, progress)
local nextY = lerp(currentY, targetY, progress)
if math.abs(nextX - targetX) <= ICON_LAYOUT_SNAP_DISTANCE
and math.abs(nextY - targetY) <= ICON_LAYOUT_SNAP_DISTANCE then
nextX = targetX
nextY = targetY
moveIcons[icon] = nil
end
icon.__sbmIconLayoutX = nextX
icon.__sbmIconLayoutY = nextY
icon:ClearAllPoints()
icon:SetPoint(point, frames.iconsParent, point, nextX, nextY)
end
end
end
end
end
if hasFadeIn then
local fadeProgress = saturate((elapsed or 0) / ICON_FADE_IN_DURATION)
if fadeProgress > 0 then
for icon in pairs(fadeInIcons) do
if not icon or not icon:IsShown() then
fadeInIcons[icon] = nil
else
local nextAlpha = lerp(icon:GetAlpha(), 1, fadeProgress)
if nextAlpha >= 0.995 then
nextAlpha = 1
fadeInIcons[icon] = nil
end
icon:SetAlpha(nextAlpha)
end
end
end
end
if hasOutro then
local fadeProgress = saturate((elapsed or 0) / ICON_OUTRO_FADE_DURATION)
if fadeProgress > 0 then
for icon in pairs(outroIcons) do
local data = icon and icon.__sbmIconOutro
if not icon or not data then
stopIconOutro(owner, icon, false)
else
local nextAlpha = lerp(icon:GetAlpha(), 0, fadeProgress)
if nextAlpha <= 0.005 then
nextAlpha = 0
stopIconOutro(owner, icon, false)
finishIconOutro(icon)
else
icon:SetAlpha(nextAlpha)
end
end
end
end
end
local stillMove = moveIcons and next(moveIcons) ~= nil
local stillFadeIn = fadeInIcons and next(fadeInIcons) ~= nil
local stillOutro = outroIcons and next(outroIcons) ~= nil
if not stillMove and not stillFadeIn and not stillOutro then
driver:Hide()
end
end)
owner._iconLayoutMotionDriver = driver
return driver
end
function M:StopIconFadeIn(icon, setOpaque)
stopIconFadeIn(self, icon, setOpaque)
local moveIcons = self._iconLayoutMovingIcons
local fadeInIcons = self._iconLayoutFadeInIcons
local outroIcons = self._iconOutroIcons
if (not moveIcons or not next(moveIcons))
and (not fadeInIcons or not next(fadeInIcons))
and (not outroIcons or not next(outroIcons))
and self._iconLayoutMotionDriver then
self._iconLayoutMotionDriver:Hide()
end
end
function M:StopIconLayoutMotion(icon, snapToTarget)
if not icon then
return
end
local moveIcons = self._iconLayoutMovingIcons
if moveIcons then
moveIcons[icon] = nil
end
if snapToTarget then
local point = icon.__sbmIconLayoutPoint
local targetX = tonumber(icon.__sbmIconLayoutTargetX)
local targetY = tonumber(icon.__sbmIconLayoutTargetY)
if point and type(targetX) == "number" and type(targetY) == "number" then
setIconLayoutPoint(icon, point, targetX, targetY)
end
end
local fadeInIcons = self._iconLayoutFadeInIcons
local outroIcons = self._iconOutroIcons
if (not moveIcons or not next(moveIcons))
and (not fadeInIcons or not next(fadeInIcons))
and (not outroIcons or not next(outroIcons))
and self._iconLayoutMotionDriver then
self._iconLayoutMotionDriver:Hide()
end
end
function M:SetIconLayoutTarget(icon, point, offsetX, offsetY, animate)
if not icon or not point then
return
end
local doAnimate = animate and iconsAnimationEnabled()
local targetX = tonumber(offsetX) or 0
local targetY = tonumber(offsetY) or 0
icon.__sbmIconLayoutPoint = point
icon.__sbmIconLayoutTargetX = targetX
icon.__sbmIconLayoutTargetY = targetY
local currentX = tonumber(icon.__sbmIconLayoutX)
local currentY = tonumber(icon.__sbmIconLayoutY)
local isNew = type(currentX) ~= "number" or type(currentY) ~= "number"
if isNew and icon:IsShown() and doAnimate then
startIconFadeIn(self, icon)
elseif isNew and icon:IsShown() then
self:StopIconFadeIn(icon, true)
end
if not doAnimate or not icon:IsShown() or isNew then
self:StopIconLayoutMotion(icon, false)
setIconLayoutPoint(icon, point, targetX, targetY)
if isNew and doAnimate then
local driver = ensureIconLayoutMotionDriver(self)
driver:Show()
end
return
end
if math.abs(currentX - targetX) <= ICON_LAYOUT_SNAP_DISTANCE
and math.abs(currentY - targetY) <= ICON_LAYOUT_SNAP_DISTANCE then
self:StopIconLayoutMotion(icon, false)
setIconLayoutPoint(icon, point, targetX, targetY)
return
end
local moveIcons = self._iconLayoutMovingIcons
if not moveIcons then
moveIcons = {}
self._iconLayoutMovingIcons = moveIcons
end
moveIcons[icon] = true
local driver = ensureIconLayoutMotionDriver(self)
driver:Show()
end
function M:ClearIconAnimation(icon, resetVisual)
if not icon then
return
end
stopIconOutro(self, icon, resetVisual ~= false)
end
function M:PlayTimelineIconOutro(rec)
local icon = rec and rec.iconFrame
if not icon or not icon:IsShown() then
return false
end
if not iconsAnimationEnabled() then
return false
end
self:StopIconLayoutMotion(icon, false)
self:StopIconFadeIn(icon, false)
self:ClearIconAnimation(icon)
if icon.cd then
icon.cd:Clear()
icon.cd:Hide()
end
if icon.timeText then
icon.timeText:SetText("")