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
|
|
|
|
{
|
|
|
|
public class BreakTracker : Component
|
|
|
|
{
|
|
|
|
private readonly ScoreProcessor scoreProcessor;
|
|
|
|
private readonly double gameplayStartTime;
|
|
|
|
|
2020-04-29 10:07:58 +08:00
|
|
|
private readonly PeriodTracker tracker = new PeriodTracker();
|
|
|
|
|
2020-03-26 14:28:56 +08: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-10 04:00:16 +08:00
|
|
|
|
2020-04-29 10:07:58 +08:00
|
|
|
tracker.Periods = value?.Where(b => b.HasEffect)
|
|
|
|
.Select(b => new Period(b.StartTime, b.EndTime - BreakOverlay.BREAK_FADE_DURATION));
|
2020-03-26 14:28:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public BreakTracker(double gameplayStartTime = 0, ScoreProcessor scoreProcessor = null)
|
|
|
|
{
|
|
|
|
this.gameplayStartTime = gameplayStartTime;
|
|
|
|
this.scoreProcessor = scoreProcessor;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2020-04-10 04:00:16 +08:00
|
|
|
var time = Clock.CurrentTime;
|
2020-03-26 14:28:56 +08:00
|
|
|
|
2020-04-29 10:08:38 +08:00
|
|
|
isBreakTime.Value = tracker.IsInAny(time)
|
2020-04-10 04:00:16 +08:00
|
|
|
|| time < gameplayStartTime
|
|
|
|
|| scoreProcessor?.HasCompleted == true;
|
2020-03-26 14:28:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|