1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 09:12:54 +08:00

Fix BreakOverlay not properly working with rewinding

In various ways:
* It wouldn't show up if rewound after the break was complete.
* The time would increase backwards if rewind happened during a break.
* Etc.
* Basically the fix is to use transformations everywhere. BreakOverlay could be refactored further, but this is enough to make it work for now.
This commit is contained in:
smoogipoo 2017-11-03 21:20:36 +09:00
parent 5fd3115142
commit 3b189c1ffe
2 changed files with 36 additions and 45 deletions

View File

@ -30,6 +30,8 @@ namespace osu.Game.Screens.Play.BreaksOverlay
} }
} }
public override bool RemoveCompletedTransforms => false;
private readonly bool letterboxing; private readonly bool letterboxing;
private readonly LetterboxOverlay letterboxOverlay; private readonly LetterboxOverlay letterboxOverlay;
private readonly Container remainingTimeAdjustmentBox; private readonly Container remainingTimeAdjustmentBox;
@ -101,38 +103,41 @@ namespace osu.Game.Screens.Play.BreaksOverlay
if (!b.HasEffect) if (!b.HasEffect)
continue; continue;
using (BeginAbsoluteSequence(b.StartTime, true))
{
remainingTimeAdjustmentBox
.ResizeWidthTo(remaining_time_container_max_size, fade_duration, Easing.OutQuint)
.Delay(b.Duration - fade_duration)
.ResizeWidthTo(0);
remainingTimeBox
.ResizeWidthTo(0, b.Duration - fade_duration)
.Then()
.ResizeWidthTo(1);
remainingTimeCounter.CountTo(b.Duration);
}
using (BeginAbsoluteSequence(b.StartTime)) using (BeginAbsoluteSequence(b.StartTime))
{ {
Schedule(() => onBreakIn(b)); Schedule(() => showBreak(b));
using (BeginDelayedSequence(b.Duration - fade_duration)) using (BeginDelayedSequence(b.Duration - fade_duration))
Schedule(onBreakOut); Schedule(hideBreak);
} }
} }
} }
private void onBreakIn(BreakPeriod b) private void showBreak(BreakPeriod b)
{ {
if (letterboxing) if (letterboxing)
letterboxOverlay.Show(); letterboxOverlay.Show();
remainingTimeAdjustmentBox
.ResizeWidthTo(remaining_time_container_max_size, fade_duration, Easing.OutQuint)
.Delay(b.Duration - fade_duration)
.ResizeWidthTo(0);
remainingTimeBox
.ResizeWidthTo(0, b.Duration - fade_duration)
.Then()
.ResizeWidthTo(1);
remainingTimeCounter.StartCounting(b.EndTime);
remainingTimeCounter.Show(); remainingTimeCounter.Show();
info.Show(); info.Show();
arrowsOverlay.Show(); arrowsOverlay.Show();
} }
private void onBreakOut() private void hideBreak()
{ {
if (letterboxing) if (letterboxing)
letterboxOverlay.Hide(); letterboxOverlay.Hide();

View File

@ -9,18 +9,12 @@ using osu.Game.Beatmaps.Timing;
namespace osu.Game.Screens.Play.BreaksOverlay namespace osu.Game.Screens.Play.BreaksOverlay
{ {
public class RemainingTimeCounter : VisibilityContainer public class RemainingTimeCounter : Container
{ {
private const double fade_duration = BreakPeriod.MIN_BREAK_DURATION / 2; private const double fade_duration = BreakPeriod.MIN_BREAK_DURATION / 2;
private readonly OsuSpriteText counter; private readonly OsuSpriteText counter;
private int? previousSecond;
private double endTime;
private bool isCounting;
public RemainingTimeCounter() public RemainingTimeCounter()
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
@ -31,35 +25,27 @@ namespace osu.Game.Screens.Play.BreaksOverlay
TextSize = 33, TextSize = 33,
Font = "Venera", Font = "Venera",
}; };
Alpha = 0;
} }
public void StartCounting(double endTime) public void CountTo(double duration)
{ {
this.endTime = endTime; double offset = 0;
isCounting = true;
}
protected override void Update() while (duration > 0)
{
base.Update();
if (isCounting)
{ {
var currentTime = Clock.CurrentTime; int seconds = (int)Math.Ceiling(duration / 1000);
if (currentTime < endTime) counter.Delay(offset).TransformTextTo(seconds.ToString());
{
int currentSecond = (int)Math.Ceiling((endTime - Clock.CurrentTime) / 1000.0); double localOffset = duration - (seconds - 1) * 1000 + 1; // +1 because we want the duration to be the next second when ceiled
if (currentSecond != previousSecond)
{ offset += localOffset;
counter.Text = currentSecond.ToString(); duration -= localOffset;
previousSecond = currentSecond;
}
}
else isCounting = false;
} }
} }
protected override void PopIn() => this.FadeIn(fade_duration); public override void Show() => this.FadeIn(fade_duration);
protected override void PopOut() => this.FadeOut(fade_duration); public override void Hide() => this.FadeOut(fade_duration);
} }
} }