mirror of
https://github.com/ppy/osu.git
synced 2025-01-18 11:52:54 +08:00
Refactor to avoid dual-boolean mess
This commit is contained in:
parent
fd39a8a78f
commit
eee3b6eaf3
@ -223,7 +223,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
|
|
||||||
protected partial class OutroPlayer : TestPlayer
|
protected partial class OutroPlayer : TestPlayer
|
||||||
{
|
{
|
||||||
public void ExitViaPause() => PerformExit(true);
|
public void ExitViaPause() => PerformExitWithConfirmation();
|
||||||
|
|
||||||
public new FailOverlay FailOverlay => base.FailOverlay;
|
public new FailOverlay FailOverlay => base.FailOverlay;
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
if (!string.IsNullOrEmpty(message))
|
if (!string.IsNullOrEmpty(message))
|
||||||
Logger.Log(message, LoggingTarget.Runtime, LogLevel.Important);
|
Logger.Log(message, LoggingTarget.Runtime, LogLevel.Important);
|
||||||
|
|
||||||
Schedule(() => PerformExit(false));
|
Schedule(() => PerformExit());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onGameplayStarted() => Scheduler.Add(() =>
|
private void onGameplayStarted() => Scheduler.Add(() =>
|
||||||
|
@ -86,7 +86,7 @@ namespace osu.Game.Screens.Play
|
|||||||
public Action<bool> RestartRequested;
|
public Action<bool> RestartRequested;
|
||||||
|
|
||||||
private bool isRestarting;
|
private bool isRestarting;
|
||||||
private bool noExitTransition;
|
private bool skipExitTransition;
|
||||||
|
|
||||||
private Bindable<bool> mouseWheelDisabled;
|
private Bindable<bool> mouseWheelDisabled;
|
||||||
|
|
||||||
@ -290,7 +290,7 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
SaveReplay = async () => await prepareAndImportScoreAsync(true).ConfigureAwait(false),
|
SaveReplay = async () => await prepareAndImportScoreAsync(true).ConfigureAwait(false),
|
||||||
OnRetry = Configuration.AllowUserInteraction ? () => Restart() : null,
|
OnRetry = Configuration.AllowUserInteraction ? () => Restart() : null,
|
||||||
OnQuit = () => PerformExit(true),
|
OnQuit = () => PerformExitWithConfirmation(),
|
||||||
},
|
},
|
||||||
new HotkeyExitOverlay
|
new HotkeyExitOverlay
|
||||||
{
|
{
|
||||||
@ -298,7 +298,7 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
if (!this.IsCurrentScreen()) return;
|
if (!this.IsCurrentScreen()) return;
|
||||||
|
|
||||||
PerformExit(false, true);
|
PerformExit(true);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -443,7 +443,7 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
HoldToQuit =
|
HoldToQuit =
|
||||||
{
|
{
|
||||||
Action = () => PerformExit(true),
|
Action = () => PerformExitWithConfirmation(),
|
||||||
IsPaused = { BindTarget = GameplayClockContainer.IsPaused },
|
IsPaused = { BindTarget = GameplayClockContainer.IsPaused },
|
||||||
ReplayLoaded = { BindTarget = DrawableRuleset.HasReplayLoaded },
|
ReplayLoaded = { BindTarget = DrawableRuleset.HasReplayLoaded },
|
||||||
},
|
},
|
||||||
@ -480,7 +480,7 @@ namespace osu.Game.Screens.Play
|
|||||||
OnResume = Resume,
|
OnResume = Resume,
|
||||||
Retries = RestartCount,
|
Retries = RestartCount,
|
||||||
OnRetry = () => Restart(),
|
OnRetry = () => Restart(),
|
||||||
OnQuit = () => PerformExit(true),
|
OnQuit = () => PerformExitWithConfirmation(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -583,26 +583,24 @@ namespace osu.Game.Screens.Play
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempts to complete a user request to exit gameplay.
|
/// Attempts to complete a user request to exit gameplay, with confirmation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// <list type="bullet">
|
/// <list type="bullet">
|
||||||
/// <item>This should only be called in response to a user interaction. Exiting is not guaranteed.</item>
|
/// <item>This should only be called in response to a user interaction. Exiting is not guaranteed.</item>
|
||||||
/// <item>This will interrupt any pending progression to the results screen, even if the transition has begun.</item>
|
/// <item>This will interrupt any pending progression to the results screen, even if the transition has begun.</item>
|
||||||
/// </list>
|
/// </list>
|
||||||
|
///
|
||||||
|
/// This method will show the pause or fail dialog before performing an exit.
|
||||||
|
/// If a dialog is not yet displayed, the exit will be blocked and the relevant dialog will display instead.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="showDialogFirst">
|
/// <returns></returns>
|
||||||
/// Whether the pause or fail dialog should be shown before performing an exit.
|
protected bool PerformExitWithConfirmation()
|
||||||
/// If <see langword="true"/> and a dialog is not yet displayed, the exit will be blocked and the relevant dialog will display instead.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="withoutTransition">Whether the exit should perform without a transition, because the screen had faded to black already.</param>
|
|
||||||
/// <returns>Whether this call resulted in a final exit.</returns>
|
|
||||||
protected bool PerformExit(bool showDialogFirst, bool withoutTransition = false)
|
|
||||||
{
|
{
|
||||||
bool pauseOrFailDialogVisible =
|
bool pauseOrFailDialogVisible =
|
||||||
PauseOverlay.State.Value == Visibility.Visible || FailOverlay.State.Value == Visibility.Visible;
|
PauseOverlay.State.Value == Visibility.Visible || FailOverlay.State.Value == Visibility.Visible;
|
||||||
|
|
||||||
if (showDialogFirst && !pauseOrFailDialogVisible)
|
if (!pauseOrFailDialogVisible)
|
||||||
{
|
{
|
||||||
// if the fail animation is currently in progress, accelerate it (it will show the pause dialog on completion).
|
// if the fail animation is currently in progress, accelerate it (it will show the pause dialog on completion).
|
||||||
if (ValidForResume && GameplayState.HasFailed)
|
if (ValidForResume && GameplayState.HasFailed)
|
||||||
@ -621,6 +619,22 @@ namespace osu.Game.Screens.Play
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return PerformExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attempts to complete a user request to exit gameplay.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// <list type="bullet">
|
||||||
|
/// <item>This should only be called in response to a user interaction. Exiting is not guaranteed.</item>
|
||||||
|
/// <item>This will interrupt any pending progression to the results screen, even if the transition has begun.</item>
|
||||||
|
/// </list>
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="skipTransition">Whether the exit should perform without a transition, because the screen had faded to black already.</param>
|
||||||
|
/// <returns>Whether this call resulted in a final exit.</returns>
|
||||||
|
protected bool PerformExit(bool skipTransition = false)
|
||||||
|
{
|
||||||
// Matching osu!stable behaviour, if the results screen is pending and the user requests an exit,
|
// Matching osu!stable behaviour, if the results screen is pending and the user requests an exit,
|
||||||
// show the results instead.
|
// show the results instead.
|
||||||
if (GameplayState.HasPassed && !isRestarting)
|
if (GameplayState.HasPassed && !isRestarting)
|
||||||
@ -635,7 +649,7 @@ namespace osu.Game.Screens.Play
|
|||||||
// Screen may not be current if a restart has been performed.
|
// Screen may not be current if a restart has been performed.
|
||||||
if (this.IsCurrentScreen())
|
if (this.IsCurrentScreen())
|
||||||
{
|
{
|
||||||
noExitTransition = withoutTransition;
|
skipExitTransition = skipTransition;
|
||||||
|
|
||||||
// The actual exit is performed if
|
// The actual exit is performed if
|
||||||
// - the pause / fail dialog was not requested
|
// - the pause / fail dialog was not requested
|
||||||
@ -707,7 +721,7 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
RestartRequested?.Invoke(quickRestart);
|
RestartRequested?.Invoke(quickRestart);
|
||||||
|
|
||||||
return PerformExit(false, quickRestart);
|
return PerformExit(quickRestart);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -1254,7 +1268,7 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
private void fadeOut()
|
private void fadeOut()
|
||||||
{
|
{
|
||||||
if (!noExitTransition)
|
if (!skipExitTransition)
|
||||||
this.FadeOut(250);
|
this.FadeOut(250);
|
||||||
|
|
||||||
if (this.IsCurrentScreen())
|
if (this.IsCurrentScreen())
|
||||||
|
Loading…
Reference in New Issue
Block a user