1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 03:22:55 +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 LetterboxOverlay letterboxOverlay;
private readonly Container remainingTimeAdjustmentBox;
@ -101,20 +103,8 @@ namespace osu.Game.Screens.Play.BreaksOverlay
if (!b.HasEffect)
continue;
using (BeginAbsoluteSequence(b.StartTime))
using (BeginAbsoluteSequence(b.StartTime, true))
{
Schedule(() => onBreakIn(b));
using (BeginDelayedSequence(b.Duration - fade_duration))
Schedule(onBreakOut);
}
}
}
private void onBreakIn(BreakPeriod b)
{
if (letterboxing)
letterboxOverlay.Show();
remainingTimeAdjustmentBox
.ResizeWidthTo(remaining_time_container_max_size, fade_duration, Easing.OutQuint)
.Delay(b.Duration - fade_duration)
@ -125,14 +115,29 @@ namespace osu.Game.Screens.Play.BreaksOverlay
.Then()
.ResizeWidthTo(1);
remainingTimeCounter.StartCounting(b.EndTime);
remainingTimeCounter.CountTo(b.Duration);
}
using (BeginAbsoluteSequence(b.StartTime))
{
Schedule(() => showBreak(b));
using (BeginDelayedSequence(b.Duration - fade_duration))
Schedule(hideBreak);
}
}
}
private void showBreak(BreakPeriod b)
{
if (letterboxing)
letterboxOverlay.Show();
remainingTimeCounter.Show();
info.Show();
arrowsOverlay.Show();
}
private void onBreakOut()
private void hideBreak()
{
if (letterboxing)
letterboxOverlay.Hide();

View File

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