1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 15:12:57 +08:00

Fix testcase players pausing on window unfocus

This commit is contained in:
smoogipoo 2019-05-10 15:39:25 +09:00
parent 5fa721fdab
commit 7c105fd99f
11 changed files with 36 additions and 28 deletions

View File

@ -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)
{ {

View File

@ -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);

View File

@ -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;

View File

@ -186,7 +186,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;
@ -197,12 +197,6 @@ namespace osu.Game.Tests.Visual.Gameplay
public bool FailOverlayVisible => FailOverlay.State == Visibility.Visible; public bool FailOverlayVisible => FailOverlay.State == Visibility.Visible;
public bool PauseOverlayVisible => PauseOverlay.State == Visibility.Visible; public bool PauseOverlayVisible => PauseOverlay.State == Visibility.Visible;
protected override void LoadComplete()
{
base.LoadComplete();
HUDOverlay.HoldToQuit.PauseOnFocusLost = false;
}
} }
} }
} }

View File

@ -1,12 +1,10 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
@ -34,7 +32,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test] [Test]
public void TestLoadContinuation() public void TestLoadContinuation()
{ {
AddStep("load dummy beatmap", () => stack.Push(loader = new PlayerLoader(() => new Player(false, false)))); AddStep("load dummy beatmap", () => stack.Push(loader = new PlayerLoader(() => 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 no longer current", () => !loader.IsCurrentScreen()); AddUntilStep("wait for no longer current", () => !loader.IsCurrentScreen());
@ -101,17 +99,7 @@ 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 protected class SlowLoadPlayer : TestPlayer
{
public new Bindable<IReadOnlyList<Mod>> Mods => base.Mods;
public TestPlayer()
: base(false, false)
{
}
}
protected class SlowLoadPlayer : Player
{ {
public bool Ready; public bool Ready;

View File

@ -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)
{ {

View File

@ -122,14 +122,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)
{ {

View File

@ -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; }
@ -167,6 +172,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);

View File

@ -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);
} }
} }

View File

@ -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);
} }
} }

View 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)
{
}
}
}