Skip to content

Commit

Permalink
Fix weird timer placement when switching between topleft and topcente…
Browse files Browse the repository at this point in the history
…r mid-level
  • Loading branch information
maddie480 committed Sep 17, 2020
1 parent 49016a9 commit fce0023
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions UI/SpeedBerryTimerDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand All @@ -84,14 +83,20 @@ public SpeedBerryTimerDisplay(SpeedBerry berry) {
TrackedBerry = berry;
timerEnded = false;
fadeTime = 3f;
Get<Tween>()?.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<Tween> 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;
Expand Down Expand Up @@ -135,9 +140,10 @@ public override void Update() {
fadeTime -= Engine.DeltaTime;
if (fadeTime <= 0f) {
SceneAs<Level>().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);
});
}
}

Expand All @@ -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;
}

Expand All @@ -167,12 +173,6 @@ public void EndTimer() {
if (!timerEnded) {
timerEnded = true;
fadeTime = 5f;
Get<Tween>()?.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<Level>().Session.Time;
wiggler.Start();

Expand Down

0 comments on commit fce0023

Please sign in to comment.