Refactor player exit logic to convey intention better

This commit is contained in:
Bartłomiej Dach
2020-12-23 15:51:26 +01:00
parent c839892a4c
commit 980e85ce25
2 changed files with 18 additions and 8 deletions

View File

@ -61,7 +61,7 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
startedEvent.Set(); startedEvent.Set();
// messaging to the user about this disconnect will be provided by the RealtimeMatchSubScreen. // messaging to the user about this disconnect will be provided by the RealtimeMatchSubScreen.
Schedule(PerformImmediateExit); Schedule(() => PerformExit(false));
} }
}, true); }, true);
@ -71,7 +71,7 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
{ {
Logger.Log("Failed to start the multiplayer match in time.", LoggingTarget.Runtime, LogLevel.Important); Logger.Log("Failed to start the multiplayer match in time.", LoggingTarget.Runtime, LogLevel.Important);
Schedule(PerformImmediateExit); Schedule(() => PerformExit(false));
} }
Debug.Assert(client.Room != null); Debug.Assert(client.Room != null);

View File

@ -386,7 +386,7 @@ namespace osu.Game.Screens.Play
if (!this.IsCurrentScreen()) return; if (!this.IsCurrentScreen()) return;
fadeOut(true); fadeOut(true);
PerformImmediateExit(); PerformExit(true);
}, },
}, },
failAnimation = new FailAnimation(DrawableRuleset) { OnComplete = onFailComplete, }, failAnimation = new FailAnimation(DrawableRuleset) { OnComplete = onFailComplete, },
@ -458,20 +458,30 @@ namespace osu.Game.Screens.Play
return playable; return playable;
} }
protected void PerformImmediateExit() /// <summary>
/// Exits the <see cref="Player"/>.
/// </summary>
/// <param name="userRequested">
/// Whether the exit is requested by the user, or a higher-level game component.
/// Pausing is allowed only in the former case.
/// </param>
protected void PerformExit(bool userRequested)
{ {
// if a restart has been requested, cancel any pending completion (user has shown intent to restart). // if a restart has been requested, cancel any pending completion (user has shown intent to restart).
completionProgressDelegate?.Cancel(); completionProgressDelegate?.Cancel();
ValidForResume = false; ValidForResume = false;
performUserRequestedExit(); if (!this.IsCurrentScreen()) return;
if (userRequested)
performUserRequestedExit();
else
this.Exit();
} }
private void performUserRequestedExit() private void performUserRequestedExit()
{ {
if (!this.IsCurrentScreen()) return;
if (ValidForResume && HasFailed && !FailOverlay.IsPresent) if (ValidForResume && HasFailed && !FailOverlay.IsPresent)
{ {
failAnimation.FinishTransforms(true); failAnimation.FinishTransforms(true);
@ -498,7 +508,7 @@ namespace osu.Game.Screens.Play
RestartRequested?.Invoke(); RestartRequested?.Invoke();
if (this.IsCurrentScreen()) if (this.IsCurrentScreen())
PerformImmediateExit(); PerformExit(true);
else else
this.MakeCurrent(); this.MakeCurrent();
} }