Add resume requesting support and fix exit scenarios

This commit is contained in:
Dean Herbert 2019-03-18 14:40:53 +09:00
parent 536b5e0dab
commit 9433a97747
2 changed files with 28 additions and 6 deletions

View File

@ -130,6 +130,13 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
/// <returns>The input manager.</returns>
public abstract PassThroughInputManager CreateInputManager();
/// <summary>
/// Invoked when the interactive user requests resuming from a paused state.
/// Allows potentially delaying the resume process until an interaction is performed.
/// </summary>
/// <param name="continueResume">The action to run when resuming is to be completed.</param>
public void RequestResume(Action continueResume) => continueResume();
protected virtual ReplayInputHandler CreateReplayInputHandler(Replay replay) => null;
protected FrameStabilityContainer FrameStabilityContainer;

View File

@ -352,8 +352,10 @@ private bool onFail()
&& !HasFailed
// cannot pause if already paused (and not in the process of resuming)
&& (GameplayClockContainer.IsPaused.Value == false || IsResuming)
// cannot pause too soon after previous pause
&& (!lastPauseActionTime.HasValue || GameplayClockContainer.GameplayClock.CurrentTime >= lastPauseActionTime + pause_cooldown);
&& (!pauseCooldownActive || IsResuming);
private bool pauseCooldownActive =>
lastPauseActionTime.HasValue && GameplayClockContainer.GameplayClock.CurrentTime < lastPauseActionTime + pause_cooldown;
private bool canResume =>
// cannot resume from a non-paused state
@ -376,6 +378,7 @@ public void Pause()
{
if (!canPause) return;
IsResuming = false;
GameplayClockContainer.Stop();
PauseOverlay.Show();
lastPauseActionTime = GameplayClockContainer.GameplayClock.CurrentTime;
@ -385,12 +388,20 @@ public void Resume()
{
if (!canResume) return;
//todo: add resume request support to ruleset
IsResuming = true;
GameplayClockContainer.Start();
PauseOverlay.Hide();
IsResuming = false;
// time-based conditions may allow instant resume.
if (GameplayClockContainer.GameplayClock.CurrentTime < Beatmap.Value.Beatmap.HitObjects.First().StartTime)
completeResume();
else
RulesetContainer.RequestResume(completeResume);
void completeResume()
{
GameplayClockContainer.Start();
IsResuming = false;
}
}
#endregion
@ -445,6 +456,10 @@ public override bool OnExiting(IScreen next)
return true;
}
if (pauseCooldownActive && !GameplayClockContainer.IsPaused.Value)
// still want to block if we are within the cooldown period and not already paused.
return true;
GameplayClockContainer.ResetLocalAdjustments();
fadeOut();