mirror of
https://github.com/osukey/osukey.git
synced 2025-05-20 21:17:32 +09:00
Fix pauses being triggered in unexpected scenarios (#4750)
Fix pauses being triggered in unexpected scenarios Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
commit
df4e08dd9b
@ -353,6 +353,8 @@ namespace osu.Game.Rulesets.Osu.Tests
|
|||||||
{
|
{
|
||||||
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
|
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
|
||||||
|
|
||||||
|
protected override bool PauseOnFocusLost => false;
|
||||||
|
|
||||||
public ScoreAccessibleReplayPlayer(Score score)
|
public ScoreAccessibleReplayPlayer(Score score)
|
||||||
: base(score, false, false)
|
: base(score, false, false)
|
||||||
{
|
{
|
||||||
|
@ -328,7 +328,7 @@ namespace osu.Game.Tests.Visual.Background
|
|||||||
public bool IsBlurCorrect() => ((FadeAccessibleBackground)Background).CurrentBlur == new Vector2(BACKGROUND_BLUR);
|
public bool IsBlurCorrect() => ((FadeAccessibleBackground)Background).CurrentBlur == new Vector2(BACKGROUND_BLUR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestPlayer : Player
|
private class TestPlayer : Visual.TestPlayer
|
||||||
{
|
{
|
||||||
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value);
|
protected override BackgroundScreen CreateBackground() => new FadeAccessibleBackground(Beatmap.Value);
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
AddUntilStep("key counter counted keys", () => ((ScoreAccessiblePlayer)Player).HUDOverlay.KeyCounter.Children.Any(kc => kc.CountPresses > 0));
|
AddUntilStep("key counter counted keys", () => ((ScoreAccessiblePlayer)Player).HUDOverlay.KeyCounter.Children.Any(kc => kc.CountPresses > 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ScoreAccessiblePlayer : Player
|
private class ScoreAccessiblePlayer : TestPlayer
|
||||||
{
|
{
|
||||||
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
|
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
|
||||||
public new HUDOverlay HUDOverlay => base.HUDOverlay;
|
public new HUDOverlay HUDOverlay => base.HUDOverlay;
|
||||||
|
@ -195,7 +195,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
|
|
||||||
protected override Player CreatePlayer(Ruleset ruleset) => new PausePlayer();
|
protected override Player CreatePlayer(Ruleset ruleset) => new PausePlayer();
|
||||||
|
|
||||||
protected class PausePlayer : Player
|
protected class PausePlayer : TestPlayer
|
||||||
{
|
{
|
||||||
public new GameplayClockContainer GameplayClockContainer => base.GameplayClockContainer;
|
public new GameplayClockContainer GameplayClockContainer => base.GameplayClockContainer;
|
||||||
|
|
||||||
@ -207,12 +207,6 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
|
|
||||||
public bool PauseOverlayVisible => PauseOverlay.State == Visibility.Visible;
|
public bool PauseOverlayVisible => PauseOverlay.State == Visibility.Visible;
|
||||||
|
|
||||||
protected override void LoadComplete()
|
|
||||||
{
|
|
||||||
base.LoadComplete();
|
|
||||||
HUDOverlay.HoldToQuit.PauseOnFocusLost = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnEntering(IScreen last)
|
public override void OnEntering(IScreen last)
|
||||||
{
|
{
|
||||||
base.OnEntering(last);
|
base.OnEntering(last);
|
||||||
|
@ -38,7 +38,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
Player player = null;
|
Player player = null;
|
||||||
SlowLoadPlayer slowPlayer = null;
|
SlowLoadPlayer slowPlayer = null;
|
||||||
|
|
||||||
AddStep("load dummy beatmap", () => stack.Push(loader = new PlayerLoader(() => player = new Player(false, false))));
|
AddStep("load dummy beatmap", () => stack.Push(loader = new PlayerLoader(() => player = new TestPlayer(false, false))));
|
||||||
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
|
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
|
||||||
AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre));
|
AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre));
|
||||||
AddUntilStep("wait for player to be current", () => player.IsCurrentScreen());
|
AddUntilStep("wait for player to be current", () => player.IsCurrentScreen());
|
||||||
@ -102,17 +102,17 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank;
|
public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestPlayer : Player
|
private class TestPlayer : Visual.TestPlayer
|
||||||
{
|
{
|
||||||
public new Bindable<IReadOnlyList<Mod>> Mods => base.Mods;
|
public new Bindable<IReadOnlyList<Mod>> Mods => base.Mods;
|
||||||
|
|
||||||
public TestPlayer()
|
public TestPlayer(bool allowPause = true, bool showResults = true)
|
||||||
: base(false, false)
|
: base(allowPause, showResults)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class SlowLoadPlayer : Player
|
protected class SlowLoadPlayer : Visual.TestPlayer
|
||||||
{
|
{
|
||||||
public readonly ManualResetEventSlim AllowLoad = new ManualResetEventSlim(false);
|
public readonly ManualResetEventSlim AllowLoad = new ManualResetEventSlim(false);
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
|
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
|
||||||
public new HUDOverlay HUDOverlay => base.HUDOverlay;
|
public new HUDOverlay HUDOverlay => base.HUDOverlay;
|
||||||
|
|
||||||
|
protected override bool PauseOnFocusLost => false;
|
||||||
|
|
||||||
public ScoreAccessibleReplayPlayer(Score score)
|
public ScoreAccessibleReplayPlayer(Score score)
|
||||||
: base(score)
|
: base(score)
|
||||||
{
|
{
|
||||||
|
@ -25,6 +25,8 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
{
|
{
|
||||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
||||||
|
|
||||||
|
public readonly Bindable<bool> IsPaused = new Bindable<bool>();
|
||||||
|
|
||||||
private readonly Button button;
|
private readonly Button button;
|
||||||
|
|
||||||
public Action Action
|
public Action Action
|
||||||
@ -51,7 +53,8 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
button = new Button
|
button = new Button
|
||||||
{
|
{
|
||||||
HoverGained = () => text.FadeIn(500, Easing.OutQuint),
|
HoverGained = () => text.FadeIn(500, Easing.OutQuint),
|
||||||
HoverLost = () => text.FadeOut(500, Easing.OutQuint)
|
HoverLost = () => text.FadeOut(500, Easing.OutQuint),
|
||||||
|
IsPaused = { BindTarget = IsPaused }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
AutoSizeAxes = Axes.Both;
|
AutoSizeAxes = Axes.Both;
|
||||||
@ -94,6 +97,8 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
private CircularProgress circularProgress;
|
private CircularProgress circularProgress;
|
||||||
private Circle overlayCircle;
|
private Circle overlayCircle;
|
||||||
|
|
||||||
|
public readonly Bindable<bool> IsPaused = new Bindable<bool>();
|
||||||
|
|
||||||
protected override bool AllowMultipleFires => true;
|
protected override bool AllowMultipleFires => true;
|
||||||
|
|
||||||
public Action HoverGained;
|
public Action HoverGained;
|
||||||
@ -217,7 +222,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
|
|
||||||
private void updateActive()
|
private void updateActive()
|
||||||
{
|
{
|
||||||
if (!pauseOnFocusLost) return;
|
if (!pauseOnFocusLost || IsPaused.Value) return;
|
||||||
|
|
||||||
if (gameActive.Value)
|
if (gameActive.Value)
|
||||||
AbortConfirm();
|
AbortConfirm();
|
||||||
|
@ -131,14 +131,12 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
replayLoaded.ValueChanged += replayLoadedValueChanged;
|
replayLoaded.BindValueChanged(replayLoadedValueChanged, true);
|
||||||
replayLoaded.TriggerChange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void replayLoadedValueChanged(ValueChangedEvent<bool> e)
|
private void replayLoadedValueChanged(ValueChangedEvent<bool> e)
|
||||||
{
|
{
|
||||||
PlayerSettingsOverlay.ReplayLoaded = e.NewValue;
|
PlayerSettingsOverlay.ReplayLoaded = e.NewValue;
|
||||||
HoldToQuit.PauseOnFocusLost = !e.NewValue;
|
|
||||||
|
|
||||||
if (e.NewValue)
|
if (e.NewValue)
|
||||||
{
|
{
|
||||||
|
@ -40,6 +40,11 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
public override OverlayActivation InitialOverlayActivationMode => OverlayActivation.UserTriggered;
|
public override OverlayActivation InitialOverlayActivationMode => OverlayActivation.UserTriggered;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether gameplay should pause when the game window focus is lost.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual bool PauseOnFocusLost => true;
|
||||||
|
|
||||||
public Action RestartRequested;
|
public Action RestartRequested;
|
||||||
|
|
||||||
public bool HasFailed { get; private set; }
|
public bool HasFailed { get; private set; }
|
||||||
@ -132,7 +137,11 @@ namespace osu.Game.Screens.Play
|
|||||||
DrawableRuleset.Cursor?.CreateProxy() ?? new Container(),
|
DrawableRuleset.Cursor?.CreateProxy() ?? new Container(),
|
||||||
HUDOverlay = new HUDOverlay(ScoreProcessor, DrawableRuleset, Mods.Value)
|
HUDOverlay = new HUDOverlay(ScoreProcessor, DrawableRuleset, Mods.Value)
|
||||||
{
|
{
|
||||||
HoldToQuit = { Action = performUserRequestedExit },
|
HoldToQuit =
|
||||||
|
{
|
||||||
|
Action = performUserRequestedExit,
|
||||||
|
IsPaused = { BindTarget = GameplayClockContainer.IsPaused }
|
||||||
|
},
|
||||||
PlayerSettingsOverlay = { PlaybackSettings = { UserPlaybackRate = { BindTarget = GameplayClockContainer.UserPlaybackRate } } },
|
PlayerSettingsOverlay = { PlaybackSettings = { UserPlaybackRate = { BindTarget = GameplayClockContainer.UserPlaybackRate } } },
|
||||||
KeyCounter = { Visible = { BindTarget = DrawableRuleset.HasReplayLoaded } },
|
KeyCounter = { Visible = { BindTarget = DrawableRuleset.HasReplayLoaded } },
|
||||||
RequestSeek = GameplayClockContainer.Seek,
|
RequestSeek = GameplayClockContainer.Seek,
|
||||||
@ -167,6 +176,8 @@ namespace osu.Game.Screens.Play
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DrawableRuleset.HasReplayLoaded.BindValueChanged(e => HUDOverlay.HoldToQuit.PauseOnFocusLost = !e.NewValue && PauseOnFocusLost, 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);
|
||||||
|
|
||||||
|
@ -76,6 +76,6 @@ namespace osu.Game.Tests.Visual
|
|||||||
return Player;
|
return Player;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual Player CreatePlayer(Ruleset ruleset) => new Player(false, false);
|
protected virtual Player CreatePlayer(Ruleset ruleset) => new TestPlayer(false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,6 @@ namespace osu.Game.Tests.Visual
|
|||||||
LoadScreen(Player);
|
LoadScreen(Player);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual Player CreatePlayer(Ruleset ruleset) => new Player(false, false);
|
protected virtual Player CreatePlayer(Ruleset ruleset) => new TestPlayer(false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
osu.Game/Tests/Visual/TestPlayer.cs
Normal file
17
osu.Game/Tests/Visual/TestPlayer.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Game.Screens.Play;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual
|
||||||
|
{
|
||||||
|
public class TestPlayer : Player
|
||||||
|
{
|
||||||
|
protected override bool PauseOnFocusLost => false;
|
||||||
|
|
||||||
|
public TestPlayer(bool allowPause = true, bool showResults = true)
|
||||||
|
: base(allowPause, showResults)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user