mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 06:36:31 +09:00
Refactor pause logic so GameplayClockContainer is in control
This commit is contained in:
@ -118,11 +118,16 @@ namespace osu.Game.Screens.Play
|
||||
// This accounts for the audio clock source potentially taking time to enter a completely stopped state
|
||||
adjustableClock.Seek(adjustableClock.CurrentTime);
|
||||
adjustableClock.Start();
|
||||
IsPaused.Value = false;
|
||||
}
|
||||
|
||||
public void Seek(double time) => adjustableClock.Seek(time);
|
||||
|
||||
public void Stop() => adjustableClock.Stop();
|
||||
public void Stop()
|
||||
{
|
||||
adjustableClock.Stop();
|
||||
IsPaused.Value = true;
|
||||
}
|
||||
|
||||
public void ResetLocalAdjustments()
|
||||
{
|
||||
|
@ -41,8 +41,8 @@ namespace osu.Game.Screens.Play
|
||||
public Action OnRetry;
|
||||
public Action OnQuit;
|
||||
|
||||
public Action Stop;
|
||||
public Action Start;
|
||||
public Action RequestPause;
|
||||
public Action<Action> RequestResume;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="PausableGameplayContainer"/>.
|
||||
@ -70,15 +70,12 @@ namespace osu.Game.Screens.Play
|
||||
};
|
||||
}
|
||||
|
||||
public void Pause(bool force = false) => Schedule(() => // Scheduled to ensure a stable position in execution order, no matter how it was called.
|
||||
public void Pause() => Schedule(() => // Scheduled to ensure a stable position in execution order, no matter how it was called.
|
||||
{
|
||||
if (!CanPause && !force) return;
|
||||
|
||||
if (IsPaused.Value) return;
|
||||
if (!CanPause) return;
|
||||
|
||||
// stop the seekable clock (stops the audio eventually)
|
||||
Stop?.Invoke();
|
||||
IsPaused.Value = true;
|
||||
RequestPause?.Invoke();
|
||||
|
||||
pauseOverlay.Show();
|
||||
|
||||
@ -89,14 +86,13 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
if (!IsPaused.Value) return;
|
||||
|
||||
IsResuming = false;
|
||||
lastPauseActionTime = Time.Current;
|
||||
|
||||
IsPaused.Value = false;
|
||||
|
||||
Start?.Invoke();
|
||||
|
||||
pauseOverlay.Hide();
|
||||
|
||||
RequestResume?.Invoke(() =>
|
||||
{
|
||||
IsResuming = false;
|
||||
lastPauseActionTime = Time.Current;
|
||||
});
|
||||
}
|
||||
|
||||
private OsuGameBase game;
|
||||
|
@ -111,10 +111,14 @@ namespace osu.Game.Screens.Play
|
||||
Retries = RestartCount,
|
||||
OnRetry = restart,
|
||||
OnQuit = performUserRequestedExit,
|
||||
Start = gameplayClockContainer.Start,
|
||||
Stop = gameplayClockContainer.Stop,
|
||||
RequestResume = completion =>
|
||||
{
|
||||
gameplayClockContainer.Start();
|
||||
completion();
|
||||
},
|
||||
RequestPause = gameplayClockContainer.Stop,
|
||||
IsPaused = { BindTarget = gameplayClockContainer.IsPaused },
|
||||
CheckCanPause = () => AllowPause && ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded.Value,
|
||||
CheckCanPause = () => CanPause,
|
||||
Children = new[]
|
||||
{
|
||||
StoryboardContainer = CreateStoryboardContainer(),
|
||||
@ -337,6 +341,9 @@ namespace osu.Game.Screens.Play
|
||||
base.OnSuspending(next);
|
||||
}
|
||||
|
||||
public bool CanPause => AllowPause && ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded.Value
|
||||
&& (PausableGameplayContainer?.IsPaused.Value == false || PausableGameplayContainer?.IsResuming == true);
|
||||
|
||||
public override bool OnExiting(IScreen next)
|
||||
{
|
||||
if (onCompletionEvent != null)
|
||||
@ -346,18 +353,16 @@ namespace osu.Game.Screens.Play
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((!AllowPause || HasFailed || !ValidForResume || PausableGameplayContainer?.IsPaused.Value != false || RulesetContainer?.HasReplayLoaded.Value != false) && (!PausableGameplayContainer?.IsResuming ?? true))
|
||||
if (LoadedBeatmapSuccessfully && CanPause)
|
||||
{
|
||||
gameplayClockContainer.ResetLocalAdjustments();
|
||||
|
||||
fadeOut();
|
||||
return base.OnExiting(next);
|
||||
PausableGameplayContainer?.Pause();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (LoadedBeatmapSuccessfully)
|
||||
PausableGameplayContainer?.Pause();
|
||||
gameplayClockContainer.ResetLocalAdjustments();
|
||||
|
||||
return true;
|
||||
fadeOut();
|
||||
return base.OnExiting(next);
|
||||
}
|
||||
|
||||
private void fadeOut(bool instant = false)
|
||||
|
Reference in New Issue
Block a user