2020-03-26 06:28:56 +00: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 02:07:58 +00:00
|
|
|
using System.Linq;
|
2020-03-26 06:28:56 +00:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Beatmaps.Timing;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2020-04-29 02:07:58 +00:00
|
|
|
using osu.Game.Utils;
|
2020-03-26 06:28:56 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
{
|
|
|
|
public class BreakTracker : Component
|
|
|
|
{
|
|
|
|
private readonly ScoreProcessor scoreProcessor;
|
|
|
|
private readonly double gameplayStartTime;
|
|
|
|
|
2020-05-01 23:33:33 +00:00
|
|
|
private PeriodTracker breaks;
|
2020-04-29 02:07:58 +00:00
|
|
|
|
2020-03-26 06:28:56 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Whether the gameplay is currently in a break.
|
|
|
|
/// </summary>
|
|
|
|
public IBindable<bool> IsBreakTime => isBreakTime;
|
|
|
|
|
|
|
|
private readonly BindableBool isBreakTime = new BindableBool();
|
|
|
|
|
|
|
|
public IReadOnlyList<BreakPeriod> Breaks
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
isBreakTime.Value = false;
|
2020-04-09 20:00:16 +00:00
|
|
|
|
2020-05-01 23:33:33 +00:00
|
|
|
breaks = new PeriodTracker(value.Where(b => b.HasEffect)
|
|
|
|
.Select(b => new Period(b.StartTime, b.EndTime - BreakOverlay.BREAK_FADE_DURATION)));
|
2020-03-26 06:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public BreakTracker(double gameplayStartTime = 0, ScoreProcessor scoreProcessor = null)
|
|
|
|
{
|
|
|
|
this.gameplayStartTime = gameplayStartTime;
|
|
|
|
this.scoreProcessor = scoreProcessor;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2020-04-09 20:00:16 +00:00
|
|
|
var time = Clock.CurrentTime;
|
2020-03-26 06:28:56 +00:00
|
|
|
|
2020-05-01 23:33:33 +00:00
|
|
|
isBreakTime.Value = breaks?.IsInAny(time) == true
|
2020-04-09 20:00:16 +00:00
|
|
|
|| time < gameplayStartTime
|
2020-04-29 02:13:17 +00:00
|
|
|
|| scoreProcessor?.HasCompleted.Value == true;
|
2020-03-26 06:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|