mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 09:03:50 +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
|
// This accounts for the audio clock source potentially taking time to enter a completely stopped state
|
||||||
adjustableClock.Seek(adjustableClock.CurrentTime);
|
adjustableClock.Seek(adjustableClock.CurrentTime);
|
||||||
adjustableClock.Start();
|
adjustableClock.Start();
|
||||||
|
IsPaused.Value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Seek(double time) => adjustableClock.Seek(time);
|
public void Seek(double time) => adjustableClock.Seek(time);
|
||||||
|
|
||||||
public void Stop() => adjustableClock.Stop();
|
public void Stop()
|
||||||
|
{
|
||||||
|
adjustableClock.Stop();
|
||||||
|
IsPaused.Value = true;
|
||||||
|
}
|
||||||
|
|
||||||
public void ResetLocalAdjustments()
|
public void ResetLocalAdjustments()
|
||||||
{
|
{
|
||||||
|
@ -41,8 +41,8 @@ namespace osu.Game.Screens.Play
|
|||||||
public Action OnRetry;
|
public Action OnRetry;
|
||||||
public Action OnQuit;
|
public Action OnQuit;
|
||||||
|
|
||||||
public Action Stop;
|
public Action RequestPause;
|
||||||
public Action Start;
|
public Action<Action> RequestResume;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="PausableGameplayContainer"/>.
|
/// 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 (!CanPause) return;
|
||||||
|
|
||||||
if (IsPaused.Value) return;
|
|
||||||
|
|
||||||
// stop the seekable clock (stops the audio eventually)
|
// stop the seekable clock (stops the audio eventually)
|
||||||
Stop?.Invoke();
|
RequestPause?.Invoke();
|
||||||
IsPaused.Value = true;
|
|
||||||
|
|
||||||
pauseOverlay.Show();
|
pauseOverlay.Show();
|
||||||
|
|
||||||
@ -89,14 +86,13 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
if (!IsPaused.Value) return;
|
if (!IsPaused.Value) return;
|
||||||
|
|
||||||
|
pauseOverlay.Hide();
|
||||||
|
|
||||||
|
RequestResume?.Invoke(() =>
|
||||||
|
{
|
||||||
IsResuming = false;
|
IsResuming = false;
|
||||||
lastPauseActionTime = Time.Current;
|
lastPauseActionTime = Time.Current;
|
||||||
|
});
|
||||||
IsPaused.Value = false;
|
|
||||||
|
|
||||||
Start?.Invoke();
|
|
||||||
|
|
||||||
pauseOverlay.Hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private OsuGameBase game;
|
private OsuGameBase game;
|
||||||
|
@ -111,10 +111,14 @@ namespace osu.Game.Screens.Play
|
|||||||
Retries = RestartCount,
|
Retries = RestartCount,
|
||||||
OnRetry = restart,
|
OnRetry = restart,
|
||||||
OnQuit = performUserRequestedExit,
|
OnQuit = performUserRequestedExit,
|
||||||
Start = gameplayClockContainer.Start,
|
RequestResume = completion =>
|
||||||
Stop = gameplayClockContainer.Stop,
|
{
|
||||||
|
gameplayClockContainer.Start();
|
||||||
|
completion();
|
||||||
|
},
|
||||||
|
RequestPause = gameplayClockContainer.Stop,
|
||||||
IsPaused = { BindTarget = gameplayClockContainer.IsPaused },
|
IsPaused = { BindTarget = gameplayClockContainer.IsPaused },
|
||||||
CheckCanPause = () => AllowPause && ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded.Value,
|
CheckCanPause = () => CanPause,
|
||||||
Children = new[]
|
Children = new[]
|
||||||
{
|
{
|
||||||
StoryboardContainer = CreateStoryboardContainer(),
|
StoryboardContainer = CreateStoryboardContainer(),
|
||||||
@ -337,6 +341,9 @@ namespace osu.Game.Screens.Play
|
|||||||
base.OnSuspending(next);
|
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)
|
public override bool OnExiting(IScreen next)
|
||||||
{
|
{
|
||||||
if (onCompletionEvent != null)
|
if (onCompletionEvent != null)
|
||||||
@ -346,20 +353,18 @@ namespace osu.Game.Screens.Play
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!AllowPause || HasFailed || !ValidForResume || PausableGameplayContainer?.IsPaused.Value != false || RulesetContainer?.HasReplayLoaded.Value != false) && (!PausableGameplayContainer?.IsResuming ?? true))
|
if (LoadedBeatmapSuccessfully && CanPause)
|
||||||
{
|
{
|
||||||
|
PausableGameplayContainer?.Pause();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
gameplayClockContainer.ResetLocalAdjustments();
|
gameplayClockContainer.ResetLocalAdjustments();
|
||||||
|
|
||||||
fadeOut();
|
fadeOut();
|
||||||
return base.OnExiting(next);
|
return base.OnExiting(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LoadedBeatmapSuccessfully)
|
|
||||||
PausableGameplayContainer?.Pause();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fadeOut(bool instant = false)
|
private void fadeOut(bool instant = false)
|
||||||
{
|
{
|
||||||
float fadeOutDuration = instant ? 0 : 250;
|
float fadeOutDuration = instant ? 0 : 250;
|
||||||
|
Reference in New Issue
Block a user