2020-03-26 14:28:56 +08:00
|
|
|
// 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;
|
2020-04-29 10:07:58 +08:00
|
|
|
using System.Linq;
|
2020-03-26 14:28:56 +08:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Beatmaps.Timing;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2020-04-29 10:07:58 +08:00
|
|
|
using osu.Game.Utils;
|
2020-03-26 14:28:56 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class BreakTracker : Component
|
2020-03-26 14:28:56 +08:00
|
|
|
{
|
|
|
|
private readonly ScoreProcessor scoreProcessor;
|
|
|
|
private readonly double gameplayStartTime;
|
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
private PeriodTracker breaks = new PeriodTracker(Enumerable.Empty<Period>());
|
2020-04-29 10:07:58 +08:00
|
|
|
|
2020-03-26 14:28:56 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether the gameplay is currently in a break.
|
|
|
|
/// </summary>
|
|
|
|
public IBindable<bool> IsBreakTime => isBreakTime;
|
|
|
|
|
2021-02-05 15:28:33 +08:00
|
|
|
private readonly BindableBool isBreakTime = new BindableBool(true);
|
2020-03-26 14:28:56 +08:00
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
public readonly Bindable<Period?> CurrentPeriod = new Bindable<Period?>();
|
|
|
|
|
2020-03-26 14:28:56 +08:00
|
|
|
public IReadOnlyList<BreakPeriod> Breaks
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
2020-05-02 07:33:33 +08:00
|
|
|
breaks = new PeriodTracker(value.Where(b => b.HasEffect)
|
|
|
|
.Select(b => new Period(b.StartTime, b.EndTime - BreakOverlay.BREAK_FADE_DURATION)));
|
2021-02-05 15:28:33 +08:00
|
|
|
|
2021-02-07 01:54:13 +08:00
|
|
|
if (IsLoaded)
|
|
|
|
updateBreakTime();
|
2020-03-26 14:28:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
public BreakTracker(double gameplayStartTime, ScoreProcessor scoreProcessor)
|
2020-03-26 14:28:56 +08:00
|
|
|
{
|
|
|
|
this.gameplayStartTime = gameplayStartTime;
|
|
|
|
this.scoreProcessor = scoreProcessor;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
2021-02-05 15:28:33 +08:00
|
|
|
updateBreakTime();
|
|
|
|
}
|
2020-03-26 14:28:56 +08:00
|
|
|
|
2021-02-05 15:28:33 +08:00
|
|
|
private void updateBreakTime()
|
|
|
|
{
|
2021-10-27 12:04:41 +08:00
|
|
|
double time = Clock.CurrentTime;
|
2020-03-26 14:28:56 +08:00
|
|
|
|
2024-08-27 15:30:49 +08:00
|
|
|
if (breaks.IsInAny(time, out var currentBreak))
|
|
|
|
{
|
|
|
|
CurrentPeriod.Value = currentBreak;
|
|
|
|
isBreakTime.Value = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CurrentPeriod.Value = null;
|
|
|
|
isBreakTime.Value = time < gameplayStartTime || scoreProcessor.HasCompleted.Value;
|
|
|
|
}
|
2020-03-26 14:28:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|