mirror of
https://github.com/ppy/osu.git
synced 2025-02-22 23:23:28 +08:00
Better pause logic
This commit is contained in:
parent
ffd3040fe2
commit
c2cdf12986
@ -89,6 +89,14 @@ namespace osu.Game.Rulesets.UI
|
|||||||
Ruleset = ruleset;
|
Ruleset = ruleset;
|
||||||
playfield = new Lazy<Playfield>(CreatePlayfield);
|
playfield = new Lazy<Playfield>(CreatePlayfield);
|
||||||
|
|
||||||
|
IsPaused.ValueChanged += paused =>
|
||||||
|
{
|
||||||
|
if (HasReplayLoaded)
|
||||||
|
return;
|
||||||
|
|
||||||
|
KeyBindingInputManager.UseParentInput = !paused;
|
||||||
|
};
|
||||||
|
|
||||||
Cursor = CreateCursor();
|
Cursor = CreateCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +128,11 @@ namespace osu.Game.Rulesets.UI
|
|||||||
|
|
||||||
public Replay Replay { get; private set; }
|
public Replay Replay { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the game is paused. Used to block user input.
|
||||||
|
/// </summary>
|
||||||
|
public readonly BindableBool IsPaused = new BindableBool();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets a replay to be used, overriding local input.
|
/// Sets a replay to be used, overriding local input.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Timing;
|
using osu.Framework.Timing;
|
||||||
@ -18,7 +19,7 @@ namespace osu.Game.Screens.Play
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class PauseContainer : Container
|
public class PauseContainer : Container
|
||||||
{
|
{
|
||||||
public bool IsPaused { get; private set; }
|
public readonly BindableBool IsPaused = new BindableBool();
|
||||||
|
|
||||||
public Func<bool> CheckCanPause;
|
public Func<bool> CheckCanPause;
|
||||||
|
|
||||||
@ -39,9 +40,6 @@ namespace osu.Game.Screens.Play
|
|||||||
public Action OnRetry;
|
public Action OnRetry;
|
||||||
public Action OnQuit;
|
public Action OnQuit;
|
||||||
|
|
||||||
public Action OnResume;
|
|
||||||
public Action OnPause;
|
|
||||||
|
|
||||||
private readonly FramedClock framedClock;
|
private readonly FramedClock framedClock;
|
||||||
private readonly DecoupleableInterpolatingFramedClock decoupledClock;
|
private readonly DecoupleableInterpolatingFramedClock decoupledClock;
|
||||||
|
|
||||||
@ -84,9 +82,8 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
// stop the seekable clock (stops the audio eventually)
|
// stop the seekable clock (stops the audio eventually)
|
||||||
decoupledClock.Stop();
|
decoupledClock.Stop();
|
||||||
IsPaused = true;
|
IsPaused.Value = true;
|
||||||
|
|
||||||
OnPause?.Invoke();
|
|
||||||
pauseOverlay.Show();
|
pauseOverlay.Show();
|
||||||
|
|
||||||
lastPauseActionTime = Time.Current;
|
lastPauseActionTime = Time.Current;
|
||||||
@ -96,7 +93,7 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
if (!IsPaused) return;
|
if (!IsPaused) return;
|
||||||
|
|
||||||
IsPaused = false;
|
IsPaused.Value = false;
|
||||||
IsResuming = false;
|
IsResuming = false;
|
||||||
lastPauseActionTime = Time.Current;
|
lastPauseActionTime = Time.Current;
|
||||||
|
|
||||||
@ -105,7 +102,6 @@ namespace osu.Game.Screens.Play
|
|||||||
decoupledClock.Seek(decoupledClock.CurrentTime);
|
decoupledClock.Seek(decoupledClock.CurrentTime);
|
||||||
decoupledClock.Start();
|
decoupledClock.Start();
|
||||||
|
|
||||||
OnResume?.Invoke();
|
|
||||||
pauseOverlay.Hide();
|
pauseOverlay.Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,12 +165,6 @@ namespace osu.Game.Screens.Play
|
|||||||
OnRetry = Restart,
|
OnRetry = Restart,
|
||||||
OnQuit = Exit,
|
OnQuit = Exit,
|
||||||
CheckCanPause = () => AllowPause && ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded,
|
CheckCanPause = () => AllowPause && ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded,
|
||||||
OnPause = () =>
|
|
||||||
{
|
|
||||||
pauseContainer.Retries = RestartCount;
|
|
||||||
hudOverlay.KeyCounter.IsCounting = !pauseContainer.IsPaused;
|
|
||||||
},
|
|
||||||
OnResume = () => hudOverlay.KeyCounter.IsCounting = true,
|
|
||||||
Children = new[]
|
Children = new[]
|
||||||
{
|
{
|
||||||
storyboardContainer = new Container
|
storyboardContainer = new Container
|
||||||
@ -227,6 +221,8 @@ namespace osu.Game.Screens.Play
|
|||||||
hudOverlay.HoldToQuit.Action = Exit;
|
hudOverlay.HoldToQuit.Action = Exit;
|
||||||
hudOverlay.KeyCounter.Visible.BindTo(RulesetContainer.HasReplayLoaded);
|
hudOverlay.KeyCounter.Visible.BindTo(RulesetContainer.HasReplayLoaded);
|
||||||
|
|
||||||
|
RulesetContainer.IsPaused.BindTo(pauseContainer.IsPaused);
|
||||||
|
|
||||||
if (ShowStoryboard)
|
if (ShowStoryboard)
|
||||||
initializeStoryboard(false);
|
initializeStoryboard(false);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user