mirror of https://github.com/ppy/osu
Rewrite updateBreakTimeBindable
This commit is contained in:
parent
cdda264c49
commit
5e51012800
|
@ -1,8 +1,13 @@
|
||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NUnit.Framework;
|
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.Beatmaps.Timing;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
|
|
||||||
|
@ -11,11 +16,30 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestSceneBreakOverlay : OsuTestScene
|
public class TestSceneBreakOverlay : OsuTestScene
|
||||||
{
|
{
|
||||||
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
|
{
|
||||||
|
typeof(BreakOverlay),
|
||||||
|
};
|
||||||
|
|
||||||
private readonly BreakOverlay breakOverlay;
|
private readonly BreakOverlay breakOverlay;
|
||||||
|
private readonly IBindable<bool> isBreakTimeBindable = new BindableBool();
|
||||||
|
|
||||||
public TestSceneBreakOverlay()
|
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("2s break", () => startBreak(2000));
|
||||||
AddStep("5s break", () => startBreak(5000));
|
AddStep("5s break", () => startBreak(5000));
|
||||||
|
|
|
@ -31,7 +31,7 @@ public List<BreakPeriod> Breaks
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
breaks = value;
|
breaks = value;
|
||||||
currentBreakIndex = 0;
|
nearestBreakIndex = 0;
|
||||||
|
|
||||||
initializeBreaks();
|
initializeBreaks();
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ public List<BreakPeriod> Breaks
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IBindable<bool> IsBreakTime => isBreakTime;
|
public IBindable<bool> IsBreakTime => isBreakTime;
|
||||||
|
|
||||||
private int currentBreakIndex;
|
private int nearestBreakIndex;
|
||||||
private readonly BindableBool isBreakTime = new BindableBool();
|
private readonly BindableBool isBreakTime = new BindableBool();
|
||||||
|
|
||||||
private readonly Container remainingTimeAdjustmentBox;
|
private readonly Container remainingTimeAdjustmentBox;
|
||||||
|
@ -136,24 +136,17 @@ private void updateBreakTimeBindable()
|
||||||
return;
|
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)
|
while (nearestBreakIndex > 0 && Clock.CurrentTime < breaks[nearestBreakIndex].StartTime)
|
||||||
{
|
nearestBreakIndex--;
|
||||||
currentBreakIndex += indexDirection;
|
|
||||||
|
|
||||||
if (currentBreakIndex < 0 || currentBreakIndex >= breaks.Count)
|
// This ensures that IsBreakTime is generally consistent with the overlay's transforms during a break.
|
||||||
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];
|
||||||
if (currentBreakIndex < 0 || currentBreakIndex >= breaks.Count)
|
isBreakTime.Value = nearestBreak.HasEffect && Clock.CurrentTime >= nearestBreak.StartTime && Clock.CurrentTime <= nearestBreak.EndTime - fade_duration;
|
||||||
{
|
|
||||||
isBreakTime.Value = false;
|
|
||||||
currentBreakIndex = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
isBreakTime.Value = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeBreaks()
|
private void initializeBreaks()
|
||||||
|
|
Loading…
Reference in New Issue