1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 09:32:55 +08:00

Modify flow to avoid weird bindable and value resetting

This commit is contained in:
Dean Herbert 2022-08-16 13:04:56 +09:00
parent c9baadcf88
commit 6761f869f9
4 changed files with 14 additions and 26 deletions

View File

@ -23,7 +23,7 @@ namespace osu.Game.Tests.Visual.Mods
protected override TestPlayer CreateModPlayer(Ruleset ruleset)
{
var player = base.CreateModPlayer(ruleset);
player.RestartRequested = () => restartRequested = true;
player.RestartRequested = _ => restartRequested = true;
return player;
}

View File

@ -77,15 +77,10 @@ namespace osu.Game.Screens.Play
/// </summary>
protected virtual bool PauseOnFocusLost => true;
public Action RestartRequested;
public Action<bool> RestartRequested;
private bool isRestarting;
/// <summary>
/// Is set to true when the quick retry hotkey has been pressed.
/// </summary>
public Bindable<bool> IsQuickRestart = new Bindable<bool>();
private Bindable<bool> mouseWheelDisabled;
private readonly Bindable<bool> storyboardReplacesBackground = new Bindable<bool>();
@ -272,7 +267,7 @@ namespace osu.Game.Screens.Play
FailOverlay = new FailOverlay
{
SaveReplay = prepareAndImportScore,
OnRetry = Restart,
OnRetry = () => Restart(),
OnQuit = () => PerformExit(true),
},
new HotkeyExitOverlay
@ -298,9 +293,8 @@ namespace osu.Game.Screens.Play
{
if (!this.IsCurrentScreen()) return;
IsQuickRestart.Value = true;
fadeOut(true);
Restart();
Restart(true);
},
});
}
@ -453,7 +447,7 @@ namespace osu.Game.Screens.Play
{
OnResume = Resume,
Retries = RestartCount,
OnRetry = Restart,
OnRetry = () => Restart(),
OnQuit = () => PerformExit(true),
},
},
@ -660,7 +654,8 @@ namespace osu.Game.Screens.Play
/// Restart gameplay via a parent <see cref="PlayerLoader"/>.
/// <remarks>This can be called from a child screen in order to trigger the restart process.</remarks>
/// </summary>
public void Restart()
/// <param name="quickRestart">Whether a quick restart was requested (skipping intro etc.).</param>
public void Restart(bool quickRestart = false)
{
if (!Configuration.AllowRestart)
return;
@ -672,7 +667,7 @@ namespace osu.Game.Screens.Play
musicController.Stop();
sampleRestart?.Play();
RestartRequested?.Invoke();
RestartRequested?.Invoke(quickRestart);
PerformExit(false);
}
@ -852,7 +847,7 @@ namespace osu.Game.Screens.Play
failAnimationLayer.Start();
if (GameplayState.Mods.OfType<IApplicableFailOverride>().Any(m => m.RestartOnFail))
Restart();
Restart(true);
return true;
}

View File

@ -123,7 +123,7 @@ namespace osu.Game.Screens.Play
private EpilepsyWarning? epilepsyWarning;
private bool isHotKeyRestart;
private bool quickRestart;
[Resolved(CanBeNull = true)]
private INotificationOverlay? notificationOverlay { get; set; }
@ -363,17 +363,12 @@ namespace osu.Game.Screens.Play
return;
CurrentPlayer = createPlayer();
CurrentPlayer.Configuration.AutomaticallySkipIntro = quickRestart;
CurrentPlayer.RestartCount = restartCount++;
CurrentPlayer.RestartRequested = restartRequested;
LoadTask = LoadComponentAsync(CurrentPlayer, _ =>
{
if (isHotKeyRestart)
{
CurrentPlayer.Configuration.AutomaticallySkipIntro = true;
isHotKeyRestart = false;
}
MetadataInfo.Loading = false;
OnPlayerLoaded();
});
@ -383,11 +378,9 @@ namespace osu.Game.Screens.Play
{
}
private void restartRequested()
private void restartRequested(bool quickRestartRequested)
{
if (CurrentPlayer != null)
isHotKeyRestart = CurrentPlayer.IsQuickRestart.Value;
quickRestart = quickRestartRequested;
hideOverlays = true;
ValidForResume = true;
}

View File

@ -177,7 +177,7 @@ namespace osu.Game.Screens.Ranking
{
if (!this.IsCurrentScreen()) return;
player?.Restart();
player?.Restart(true);
},
});
}