diff --git a/UI/SpeedBerryTimerDisplay.cs b/UI/SpeedBerryTimerDisplay.cs index cad50a7..741093a 100644 --- a/UI/SpeedBerryTimerDisplay.cs +++ b/UI/SpeedBerryTimerDisplay.cs @@ -58,14 +58,13 @@ private static void onTotalStrawberriesDisplayUpdate(On.Celeste.TotalStrawberrie // draw state private float fadeTime; private bool timerEnded; - private float drawLerp; - private bool tweenStarted; + private float drawLerp; private Vector2 offscreenPosition; private Vector2 onscreenPosition; private Wiggler wiggler; - private Tween tween; + private bool tweenActive; private MTexture bg = GFX.Gui["CollabUtils2/extendedStrawberryCountBG"]; @@ -84,14 +83,20 @@ public SpeedBerryTimerDisplay(SpeedBerry berry) { TrackedBerry = berry; timerEnded = false; fadeTime = 3f; - Get()?.RemoveSelf(); - tween = Tween.Create(Tween.TweenMode.Oneshot, Ease.CubeInOut, 0.6f, true); - tween.OnUpdate = t => { + + createTween(0.6f, t => { Position = Vector2.Lerp(offscreenPosition, onscreenPosition, t.Eased); - }; + }); + } + + private void createTween(float fadeTime, Action onUpdate) { + Tween tween = Tween.Create(Tween.TweenMode.Oneshot, Ease.CubeInOut, fadeTime, true); + tween.OnUpdate = onUpdate; + tween.OnComplete = _ => tweenActive = false; Add(tween); - } - + tweenActive = true; + } + public long GetSpentTime() { if (startChapterTimer == -1) { return 0; @@ -135,9 +140,10 @@ public override void Update() { fadeTime -= Engine.DeltaTime; if (fadeTime <= 0f) { SceneAs().Remove(this); - } else if (!tweenStarted && fadeTime <= 1.5f) { - tween.Start(); - tweenStarted = true; + } else if (!tweenActive && fadeTime <= 1.5f) { + createTween(1.5f, t => { + Position = Vector2.Lerp(onscreenPosition, offscreenPosition, t.Eased); + }); } } @@ -154,7 +160,7 @@ public override void Update() { offscreenPosition = new Vector2(-400f, 180f); onscreenPosition = new Vector2(32f, 180f); } - if (!tween.Active) { + if (!tweenActive) { Position = onscreenPosition; } @@ -167,12 +173,6 @@ public void EndTimer() { if (!timerEnded) { timerEnded = true; fadeTime = 5f; - Get()?.RemoveSelf(); - tween = Tween.Create(Tween.TweenMode.Oneshot, Ease.CubeInOut, 1.5f); - tween.OnUpdate = t => { - Position = Vector2.Lerp(onscreenPosition, offscreenPosition, t.Eased); - }; - Add(tween); endChapterTimer = SceneAs().Session.Time; wiggler.Start();