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

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();
// messaging to the user about this disconnect will be provided by the RealtimeMatchSubScreen.
Schedule(PerformImmediateExit);
Schedule(() => PerformExit(false));
}
}, 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);
Schedule(PerformImmediateExit);
Schedule(() => PerformExit(false));
}
Debug.Assert(client.Room != null);

View File

@ -386,7 +386,7 @@ namespace osu.Game.Screens.Play
if (!this.IsCurrentScreen()) return;
fadeOut(true);
PerformImmediateExit();
PerformExit(true);
},
},
failAnimation = new FailAnimation(DrawableRuleset) { OnComplete = onFailComplete, },
@ -458,20 +458,30 @@ namespace osu.Game.Screens.Play
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).
completionProgressDelegate?.Cancel();
ValidForResume = false;
performUserRequestedExit();
if (!this.IsCurrentScreen()) return;
if (userRequested)
performUserRequestedExit();
else
this.Exit();
}
private void performUserRequestedExit()
{
if (!this.IsCurrentScreen()) return;
if (ValidForResume && HasFailed && !FailOverlay.IsPresent)
{
failAnimation.FinishTransforms(true);
@ -498,7 +508,7 @@ namespace osu.Game.Screens.Play
RestartRequested?.Invoke();
if (this.IsCurrentScreen())
PerformImmediateExit();
PerformExit(true);
else
this.MakeCurrent();
}