1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 04:07:25 +08:00

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);
}
public bool PauseOnFocusLost
{
set => button.PauseOnFocusLost = value;
}
protected override void Update()
{
base.Update();
@ -120,8 +115,6 @@ namespace osu.Game.Screens.Play.HUD
public Action HoverGained;
public Action HoverLost;
private readonly IBindable<bool> gameActive = new Bindable<bool>(true);
[BackgroundDependencyLoader]
private void load(OsuColour colours, Framework.Game game)
{
@ -164,14 +157,6 @@ namespace osu.Game.Screens.Play.HUD
};
bind();
gameActive.BindTo(game.IsActive);
}
protected override void LoadComplete()
{
base.LoadComplete();
gameActive.BindValueChanged(_ => updateActive(), true);
}
private void bind()
@ -221,31 +206,6 @@ namespace osu.Game.Screens.Play.HUD
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)
{
switch (action)

View File

@ -59,6 +59,8 @@ namespace osu.Game.Screens.Play
// We are managing our own adjustments (see OnEntering/OnExiting).
public override bool AllowRateAdjustments => false;
private readonly IBindable<bool> gameActive = new Bindable<bool>(true);
private readonly Bindable<bool> samplePlaybackDisabled = new Bindable<bool>();
/// <summary>
@ -154,6 +156,9 @@ namespace osu.Game.Screens.Play
// replays should never be recorded or played back when autoplay is enabled
if (!Mods.Value.Any(m => m is ModAutoplay))
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]
@ -170,7 +175,7 @@ namespace osu.Game.Screens.Play
}
[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();
@ -186,6 +191,8 @@ namespace osu.Game.Screens.Play
mouseWheelDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableWheel);
gameActive.BindTo(gameBase.IsActive);
if (game != null)
LocalUserPlaying.BindTo(game.LocalUserPlaying);
@ -420,10 +427,14 @@ namespace osu.Game.Screens.Play
samplePlaybackDisabled.Value = DrawableRuleset.FrameStableClock.IsCatchingUp.Value || GameplayClockContainer.GameplayClock.IsPaused.Value;
}
private void updatePauseOnFocusLostState() =>
HUDOverlay.HoldToQuit.PauseOnFocusLost = PauseOnFocusLost
&& !DrawableRuleset.HasReplayLoaded.Value
&& !breakTracker.IsBreakTime.Value;
private void updatePauseOnFocusLostState()
{
if (!IsLoaded || !PauseOnFocusLost || DrawableRuleset.HasReplayLoaded.Value || breakTracker.IsBreakTime.Value)
return;
if (gameActive.Value == false)
performUserRequestedExit();
}
private IBeatmap loadPlayableBeatmap()
{