1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:17:23 +08:00

Rewrite updateBreakTimeBindable

This commit is contained in:
Shane Woolcock 2019-07-25 22:54:05 +09:30
parent cdda264c49
commit 5e51012800
2 changed files with 36 additions and 19 deletions

View File

@ -1,8 +1,13 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps.Timing;
using osu.Game.Screens.Play;
@ -11,11 +16,30 @@ namespace osu.Game.Tests.Visual.Gameplay
[TestFixture]
public class TestSceneBreakOverlay : OsuTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(BreakOverlay),
};
private readonly BreakOverlay breakOverlay;
private readonly IBindable<bool> isBreakTimeBindable = new BindableBool();
public TestSceneBreakOverlay()
{
Child = breakOverlay = new BreakOverlay(true);
SpriteText breakTimeText;
Child = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
breakTimeText = new SpriteText(),
breakOverlay = new BreakOverlay(true)
}
};
isBreakTimeBindable.BindTo(breakOverlay.IsBreakTime);
isBreakTimeBindable.BindValueChanged(e => breakTimeText.Text = $"IsBreakTime: {e.NewValue}", true);
AddStep("2s break", () => startBreak(2000));
AddStep("5s break", () => startBreak(5000));

View File

@ -31,7 +31,7 @@ namespace osu.Game.Screens.Play
set
{
breaks = value;
currentBreakIndex = 0;
nearestBreakIndex = 0;
initializeBreaks();
}
@ -44,7 +44,7 @@ namespace osu.Game.Screens.Play
/// </summary>
public IBindable<bool> IsBreakTime => isBreakTime;
private int currentBreakIndex;
private int nearestBreakIndex;
private readonly BindableBool isBreakTime = new BindableBool();
private readonly Container remainingTimeAdjustmentBox;
@ -136,24 +136,17 @@ namespace osu.Game.Screens.Play
return;
}
int indexDirection = Clock.CurrentTime < breaks[currentBreakIndex].StartTime ? -1 : (Clock.CurrentTime > breaks[currentBreakIndex].EndTime ? 1 : 0);
while (nearestBreakIndex < breaks.Count - 1 && Clock.CurrentTime > breaks[nearestBreakIndex].EndTime)
nearestBreakIndex++;
while (Clock.CurrentTime < breaks[currentBreakIndex].StartTime || Clock.CurrentTime > breaks[currentBreakIndex].EndTime)
{
currentBreakIndex += indexDirection;
while (nearestBreakIndex > 0 && Clock.CurrentTime < breaks[nearestBreakIndex].StartTime)
nearestBreakIndex--;
if (currentBreakIndex < 0 || currentBreakIndex >= breaks.Count)
break;
}
if (currentBreakIndex < 0 || currentBreakIndex >= breaks.Count)
{
isBreakTime.Value = false;
currentBreakIndex = 0;
return;
}
isBreakTime.Value = true;
// This ensures that IsBreakTime is generally consistent with the overlay's transforms during a break.
// If the overlay never shows (break.HasEffect is false), IsBreakTime should be false.
// We also assume that the overlay's fade out transform is "not break time".
var nearestBreak = breaks[nearestBreakIndex];
isBreakTime.Value = nearestBreak.HasEffect && Clock.CurrentTime >= nearestBreak.StartTime && Clock.CurrentTime <= nearestBreak.EndTime - fade_duration;
}
private void initializeBreaks()