1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 16:02:55 +08:00

Merge pull request #11844 from peppy/fix-exit-from-player

Fix support for instant exit if pausing is not allowed in the current game mode
This commit is contained in:
Dan Balasescu 2021-02-20 17:01:33 +09:00 committed by GitHub
commit 23ce5e7077
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 10 deletions

View File

@ -90,6 +90,15 @@ namespace osu.Game.Tests.Visual.Gameplay
resumeAndConfirm(); resumeAndConfirm();
} }
[Test]
public void TestUserPauseWhenPauseNotAllowed()
{
AddStep("disable pause support", () => Player.Configuration.AllowPause = false);
pauseFromUserExitKey();
confirmExited();
}
[Test] [Test]
public void TestUserPauseDuringCooldownTooSoon() public void TestUserPauseDuringCooldownTooSoon()
{ {

View File

@ -508,10 +508,14 @@ namespace osu.Game.Screens.Play
return; return;
} }
// in the case a dialog needs to be shown, attempt to pause and show it. // there's a chance the pausing is not supported in the current state, at which point immediate exit should be preferred.
// this may fail (see internal checks in Pause()) at which point the exit attempt will be aborted. if (pausingSupportedByCurrentState)
Pause(); {
return; // in the case a dialog needs to be shown, attempt to pause and show it.
// this may fail (see internal checks in Pause()) but the fail cases are temporary, so don't fall through to Exit().
Pause();
return;
}
} }
this.Exit(); this.Exit();
@ -670,15 +674,17 @@ namespace osu.Game.Screens.Play
private double? lastPauseActionTime; private double? lastPauseActionTime;
private bool canPause => /// <summary>
/// A set of conditionals which defines whether the current game state and configuration allows for
/// pausing to be attempted via <see cref="Pause"/>. If false, the game should generally exit if a user pause
/// is attempted.
/// </summary>
private bool pausingSupportedByCurrentState =>
// must pass basic screen conditions (beatmap loaded, instance allows pause) // must pass basic screen conditions (beatmap loaded, instance allows pause)
LoadedBeatmapSuccessfully && Configuration.AllowPause && ValidForResume LoadedBeatmapSuccessfully && Configuration.AllowPause && ValidForResume
// replays cannot be paused and exit immediately // replays cannot be paused and exit immediately
&& !DrawableRuleset.HasReplayLoaded.Value && !DrawableRuleset.HasReplayLoaded.Value
// cannot pause if we are already in a fail state && !HasFailed;
&& !HasFailed
// cannot pause if already paused (or in a cooldown state) unless we are in a resuming state.
&& (IsResuming || (GameplayClockContainer.IsPaused.Value == false && !pauseCooldownActive));
private bool pauseCooldownActive => private bool pauseCooldownActive =>
lastPauseActionTime.HasValue && GameplayClockContainer.GameplayClock.CurrentTime < lastPauseActionTime + pause_cooldown; lastPauseActionTime.HasValue && GameplayClockContainer.GameplayClock.CurrentTime < lastPauseActionTime + pause_cooldown;
@ -693,7 +699,10 @@ namespace osu.Game.Screens.Play
public void Pause() public void Pause()
{ {
if (!canPause) return; if (!pausingSupportedByCurrentState) return;
if (!IsResuming && pauseCooldownActive)
return;
if (IsResuming) if (IsResuming)
{ {