mirror of
https://github.com/ppy/osu.git
synced 2024-12-18 02:02:54 +08:00
6f1664f0a6
I've been meaning to make the progress bar synchronise with the beat rather than a continuous countdown, just to give the overlay a bit more of a rhythmic feel. Not completely happy with how this feels but I think it's a start? I had to refactor how the break overlay works in the process. It no longer creates transforms for all breaks ahead-of-time, which could be argued as a better way of doing things. It's more dynamically able to handle breaks now (maybe useful for the future, who knows).
71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
// 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.Collections.Generic;
|
|
using System.Linq;
|
|
using osu.Framework.Bindables;
|
|
using osu.Framework.Graphics;
|
|
using osu.Game.Beatmaps.Timing;
|
|
using osu.Game.Rulesets.Scoring;
|
|
using osu.Game.Utils;
|
|
|
|
namespace osu.Game.Screens.Play
|
|
{
|
|
public partial class BreakTracker : Component
|
|
{
|
|
private readonly ScoreProcessor scoreProcessor;
|
|
private readonly double gameplayStartTime;
|
|
|
|
private PeriodTracker breaks = new PeriodTracker(Enumerable.Empty<Period>());
|
|
|
|
/// <summary>
|
|
/// Whether the gameplay is currently in a break.
|
|
/// </summary>
|
|
public IBindable<bool> IsBreakTime => isBreakTime;
|
|
|
|
private readonly BindableBool isBreakTime = new BindableBool(true);
|
|
|
|
public readonly Bindable<Period?> CurrentPeriod = new Bindable<Period?>();
|
|
|
|
public IReadOnlyList<BreakPeriod> Breaks
|
|
{
|
|
set
|
|
{
|
|
breaks = new PeriodTracker(value.Where(b => b.HasEffect)
|
|
.Select(b => new Period(b.StartTime, b.EndTime - BreakOverlay.BREAK_FADE_DURATION)));
|
|
|
|
if (IsLoaded)
|
|
updateBreakTime();
|
|
}
|
|
}
|
|
|
|
public BreakTracker(double gameplayStartTime, ScoreProcessor scoreProcessor)
|
|
{
|
|
this.gameplayStartTime = gameplayStartTime;
|
|
this.scoreProcessor = scoreProcessor;
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
updateBreakTime();
|
|
}
|
|
|
|
private void updateBreakTime()
|
|
{
|
|
double time = Clock.CurrentTime;
|
|
|
|
if (breaks.IsInAny(time, out var currentBreak))
|
|
{
|
|
CurrentPeriod.Value = currentBreak;
|
|
isBreakTime.Value = true;
|
|
}
|
|
else
|
|
{
|
|
CurrentPeriod.Value = null;
|
|
isBreakTime.Value = time < gameplayStartTime || scoreProcessor.HasCompleted.Value;
|
|
}
|
|
}
|
|
}
|
|
}
|