1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-05 13:42:59 +08:00

Merge pull request #11680 from frenzibyte/instant-pause-on-focus-loss

Make pausing on window focus loss instantaneous
This commit is contained in:
Dean Herbert 2021-02-08 17:00:17 +09:00 committed by GitHub
commit 59dc148a48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 49 deletions

View File

@ -23,16 +23,17 @@ namespace osu.Game.Screens.Play
/// </summary> /// </summary>
public IBindable<bool> IsBreakTime => isBreakTime; public IBindable<bool> IsBreakTime => isBreakTime;
private readonly BindableBool isBreakTime = new BindableBool(); private readonly BindableBool isBreakTime = new BindableBool(true);
public IReadOnlyList<BreakPeriod> Breaks public IReadOnlyList<BreakPeriod> Breaks
{ {
set set
{ {
isBreakTime.Value = false;
breaks = new PeriodTracker(value.Where(b => b.HasEffect) breaks = new PeriodTracker(value.Where(b => b.HasEffect)
.Select(b => new Period(b.StartTime, b.EndTime - BreakOverlay.BREAK_FADE_DURATION))); .Select(b => new Period(b.StartTime, b.EndTime - BreakOverlay.BREAK_FADE_DURATION)));
if (IsLoaded)
updateBreakTime();
} }
} }
@ -45,7 +46,11 @@ namespace osu.Game.Screens.Play
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
updateBreakTime();
}
private void updateBreakTime()
{
var time = Clock.CurrentTime; var time = Clock.CurrentTime;
isBreakTime.Value = breaks?.IsInAny(time) == true isBreakTime.Value = breaks?.IsInAny(time) == true

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,8 @@ 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();
gameActive.BindValueChanged(_ => updatePauseOnFocusLostState(), true);
} }
[CanBeNull] [CanBeNull]
@ -187,7 +191,10 @@ namespace osu.Game.Screens.Play
mouseWheelDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableWheel); mouseWheelDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableWheel);
if (game != null) if (game != null)
{
LocalUserPlaying.BindTo(game.LocalUserPlaying); LocalUserPlaying.BindTo(game.LocalUserPlaying);
gameActive.BindTo(game.IsActive);
}
DrawableRuleset = ruleset.CreateDrawableRulesetWith(playableBeatmap, Mods.Value); DrawableRuleset = ruleset.CreateDrawableRulesetWith(playableBeatmap, Mods.Value);
@ -258,8 +265,6 @@ namespace osu.Game.Screens.Play
DrawableRuleset.HasReplayLoaded.BindValueChanged(_ => updateGameplayState()); DrawableRuleset.HasReplayLoaded.BindValueChanged(_ => updateGameplayState());
DrawableRuleset.HasReplayLoaded.BindValueChanged(_ => updatePauseOnFocusLostState(), true);
// bind clock into components that require it // bind clock into components that require it
DrawableRuleset.IsPaused.BindTo(GameplayClockContainer.IsPaused); DrawableRuleset.IsPaused.BindTo(GameplayClockContainer.IsPaused);
@ -420,10 +425,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 (!PauseOnFocusLost || breakTracker.IsBreakTime.Value)
&& !breakTracker.IsBreakTime.Value; return;
if (gameActive.Value == false)
Pause();
}
private IBeatmap loadPlayableBeatmap() private IBeatmap loadPlayableBeatmap()
{ {