1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 13:22:55 +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>
public IBindable<bool> IsBreakTime => isBreakTime;
private readonly BindableBool isBreakTime = new BindableBool();
private readonly BindableBool isBreakTime = new BindableBool(true);
public IReadOnlyList<BreakPeriod> Breaks
{
set
{
isBreakTime.Value = false;
breaks = new PeriodTracker(value.Where(b => b.HasEffect)
.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()
{
base.Update();
updateBreakTime();
}
private void updateBreakTime()
{
var time = Clock.CurrentTime;
isBreakTime.Value = breaks?.IsInAny(time) == true

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