Make pausing on window focus lose instant

This commit is contained in:
Salman Ahmed 2021-02-05 09:07:59 +03:00
parent 8a176e32d6
commit 730e66f0ee
2 changed files with 16 additions and 45 deletions

View File

@ -88,11 +88,6 @@ namespace osu.Game.Screens.Play.HUD
return base.OnMouseMove(e); return base.OnMouseMove(e);
} }
public bool PauseOnFocusLost
{
set => button.PauseOnFocusLost = value;
}
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
@ -120,8 +115,6 @@ namespace osu.Game.Screens.Play.HUD
public Action HoverGained; public Action HoverGained;
public Action HoverLost; public Action HoverLost;
private readonly IBindable<bool> gameActive = new Bindable<bool>(true);
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, Framework.Game game) private void load(OsuColour colours, Framework.Game game)
{ {
@ -164,14 +157,6 @@ namespace osu.Game.Screens.Play.HUD
}; };
bind(); bind();
gameActive.BindTo(game.IsActive);
}
protected override void LoadComplete()
{
base.LoadComplete();
gameActive.BindValueChanged(_ => updateActive(), true);
} }
private void bind() private void bind()
@ -221,31 +206,6 @@ namespace osu.Game.Screens.Play.HUD
base.OnHoverLost(e); base.OnHoverLost(e);
} }
private bool pauseOnFocusLost = true;
public bool PauseOnFocusLost
{
set
{
if (pauseOnFocusLost == value)
return;
pauseOnFocusLost = value;
if (IsLoaded)
updateActive();
}
}
private void updateActive()
{
if (!pauseOnFocusLost || IsPaused.Value) return;
if (gameActive.Value)
AbortConfirm();
else
BeginConfirm();
}
public bool OnPressed(GlobalAction action) public bool OnPressed(GlobalAction action)
{ {
switch (action) switch (action)

View File

@ -59,6 +59,8 @@ namespace osu.Game.Screens.Play
// We are managing our own adjustments (see OnEntering/OnExiting). // We are managing our own adjustments (see OnEntering/OnExiting).
public override bool AllowRateAdjustments => false; public override bool AllowRateAdjustments => false;
private readonly IBindable<bool> gameActive = new Bindable<bool>(true);
private readonly Bindable<bool> samplePlaybackDisabled = new Bindable<bool>(); private readonly Bindable<bool> samplePlaybackDisabled = new Bindable<bool>();
/// <summary> /// <summary>
@ -154,6 +156,9 @@ namespace osu.Game.Screens.Play
// replays should never be recorded or played back when autoplay is enabled // replays should never be recorded or played back when autoplay is enabled
if (!Mods.Value.Any(m => m is ModAutoplay)) if (!Mods.Value.Any(m => m is ModAutoplay))
PrepareReplay(); PrepareReplay();
// needs to be bound here as the last binding, otherwise starting a replay while not focused causes player to exit.
gameActive.BindValueChanged(_ => updatePauseOnFocusLostState(), true);
} }
[CanBeNull] [CanBeNull]
@ -170,7 +175,7 @@ namespace osu.Game.Screens.Play
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(AudioManager audio, OsuConfigManager config, OsuGame game) private void load(AudioManager audio, OsuConfigManager config, OsuGame game, OsuGameBase gameBase)
{ {
Mods.Value = base.Mods.Value.Select(m => m.CreateCopy()).ToArray(); Mods.Value = base.Mods.Value.Select(m => m.CreateCopy()).ToArray();
@ -186,6 +191,8 @@ namespace osu.Game.Screens.Play
mouseWheelDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableWheel); mouseWheelDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableWheel);
gameActive.BindTo(gameBase.IsActive);
if (game != null) if (game != null)
LocalUserPlaying.BindTo(game.LocalUserPlaying); LocalUserPlaying.BindTo(game.LocalUserPlaying);
@ -420,10 +427,14 @@ namespace osu.Game.Screens.Play
samplePlaybackDisabled.Value = DrawableRuleset.FrameStableClock.IsCatchingUp.Value || GameplayClockContainer.GameplayClock.IsPaused.Value; samplePlaybackDisabled.Value = DrawableRuleset.FrameStableClock.IsCatchingUp.Value || GameplayClockContainer.GameplayClock.IsPaused.Value;
} }
private void updatePauseOnFocusLostState() => private void updatePauseOnFocusLostState()
HUDOverlay.HoldToQuit.PauseOnFocusLost = PauseOnFocusLost {
&& !DrawableRuleset.HasReplayLoaded.Value if (!IsLoaded || !PauseOnFocusLost || DrawableRuleset.HasReplayLoaded.Value || breakTracker.IsBreakTime.Value)
&& !breakTracker.IsBreakTime.Value; return;
if (gameActive.Value == false)
performUserRequestedExit();
}
private IBeatmap loadPlayableBeatmap() private IBeatmap loadPlayableBeatmap()
{ {