osu/osu.Game.Tests/Visual/Gameplay/TestScenePause.cs

218 lines
6.4 KiB
C#
Raw Normal View History

2019-03-17 15:46:15 +00:00
// 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 System.Linq;
2019-03-18 10:44:21 +00:00
using NUnit.Framework;
using osu.Framework.Graphics;
2019-03-18 02:48:11 +00:00
using osu.Framework.Graphics.Containers;
2019-03-18 05:57:06 +00:00
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
2019-03-17 15:46:15 +00:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play;
using osuTK;
using osuTK.Input;
2019-03-17 15:46:15 +00:00
2019-03-24 16:02:36 +00:00
namespace osu.Game.Tests.Visual.Gameplay
2019-03-17 15:46:15 +00:00
{
public class TestScenePause : PlayerTestScene
2019-03-17 15:46:15 +00:00
{
2019-03-18 10:44:21 +00:00
protected new PausePlayer Player => (PausePlayer)base.Player;
private readonly Container content;
protected override Container<Drawable> Content => content;
public TestScenePause()
2019-03-17 15:46:15 +00:00
: base(new OsuRuleset())
{
base.Content.Add(content = new MenuCursorContainer { RelativeSizeAxes = Axes.Both });
2019-03-17 15:46:15 +00:00
}
[SetUpSteps]
public override void SetUpSteps()
{
base.SetUpSteps();
AddStep("resume player", () => Player.GameplayClockContainer.Start());
confirmClockRunning(true);
}
2019-03-18 10:44:21 +00:00
[Test]
public void TestPauseResume()
2019-03-17 15:46:15 +00:00
{
AddStep("move cursor outside", () => InputManager.MoveMouseTo(Player.ScreenSpaceDrawQuad.TopLeft - new Vector2(10)));
pauseAndConfirm();
resumeAndConfirm();
}
[Test]
public void TestResumeWithResumeOverlay()
{
AddStep("move cursor to center", () => InputManager.MoveMouseTo(Player.ScreenSpaceDrawQuad.Centre));
AddUntilStep("wait for hitobjects", () => Player.ScoreProcessor.Health.Value < 1);
pauseAndConfirm();
resume();
confirmClockRunning(false);
confirmPauseOverlayShown(false);
AddStep("click to resume", () =>
{
InputManager.PressButton(MouseButton.Left);
InputManager.ReleaseButton(MouseButton.Left);
});
confirmClockRunning(true);
}
[Test]
public void TestResumeWithResumeOverlaySkipped()
{
AddStep("move cursor to button", () =>
InputManager.MoveMouseTo(Player.HUDOverlay.HoldToQuit.Children.OfType<HoldToConfirmContainer>().First().ScreenSpaceDrawQuad.Centre));
AddUntilStep("wait for hitobjects", () => Player.ScoreProcessor.Health.Value < 1);
2019-03-21 07:33:34 +00:00
pauseAndConfirm();
resumeAndConfirm();
2019-03-18 10:44:21 +00:00
}
2019-03-18 02:48:11 +00:00
2019-03-18 10:44:21 +00:00
[Test]
public void TestPauseTooSoon()
{
AddStep("move cursor outside", () => InputManager.MoveMouseTo(Player.ScreenSpaceDrawQuad.TopLeft - new Vector2(10)));
2019-03-21 07:33:34 +00:00
pauseAndConfirm();
resume();
2019-03-21 07:33:34 +00:00
pause();
confirmClockRunning(true);
confirmPauseOverlayShown(false);
2019-03-18 10:44:21 +00:00
}
2019-03-18 02:48:11 +00:00
2019-03-21 07:11:44 +00:00
[Test]
public void TestExitTooSoon()
{
2019-03-21 07:33:34 +00:00
pauseAndConfirm();
resume();
AddStep("exit too soon", () => Player.Exit());
confirmClockRunning(true);
confirmPauseOverlayShown(false);
2019-03-21 07:11:44 +00:00
AddAssert("not exited", () => Player.IsCurrentScreen());
}
2019-03-18 10:44:21 +00:00
[Test]
public void TestPauseAfterFail()
{
AddUntilStep("wait for fail", () => Player.HasFailed);
2019-06-04 07:13:16 +00:00
AddUntilStep("fail overlay shown", () => Player.FailOverlayVisible);
2019-03-18 02:48:11 +00:00
2019-03-21 07:33:34 +00:00
confirmClockRunning(false);
pause();
confirmClockRunning(false);
confirmPauseOverlayShown(false);
2019-03-18 05:57:06 +00:00
2019-03-18 10:44:21 +00:00
AddAssert("fail overlay still shown", () => Player.FailOverlayVisible);
2019-03-21 07:11:44 +00:00
2019-03-21 07:33:34 +00:00
exitAndConfirm();
2019-03-21 07:11:44 +00:00
}
[Test]
public void TestExitFromGameplay()
{
AddStep("exit", () => Player.Exit());
2019-03-21 07:33:34 +00:00
confirmPaused();
exitAndConfirm();
2019-03-18 10:44:21 +00:00
}
2019-03-18 05:57:06 +00:00
2019-03-18 10:44:21 +00:00
[Test]
public void TestExitFromPause()
{
2019-03-21 07:33:34 +00:00
pauseAndConfirm();
exitAndConfirm();
}
2019-03-18 05:57:06 +00:00
2019-03-21 07:33:34 +00:00
private void pauseAndConfirm()
{
pause();
confirmPaused();
2019-03-21 07:11:44 +00:00
}
2019-03-21 07:33:34 +00:00
private void resumeAndConfirm()
{
resume();
confirmResumed();
}
private void exitAndConfirm()
2019-03-21 07:11:44 +00:00
{
AddUntilStep("player not exited", () => Player.IsCurrentScreen());
2019-03-18 10:44:21 +00:00
AddStep("exit", () => Player.Exit());
2019-03-21 07:33:34 +00:00
confirmExited();
}
private void confirmPaused()
{
confirmClockRunning(false);
AddAssert("player not exited", () => Player.IsCurrentScreen());
AddAssert("player not failed", () => !Player.HasFailed);
2019-03-21 07:33:34 +00:00
AddAssert("pause overlay shown", () => Player.PauseOverlayVisible);
}
private void confirmResumed()
{
confirmClockRunning(true);
confirmPauseOverlayShown(false);
}
private void confirmExited()
{
AddUntilStep("player exited", () => !Player.IsCurrentScreen());
2019-03-17 15:46:15 +00:00
}
2019-03-21 07:33:34 +00:00
private void pause() => AddStep("pause", () => Player.Pause());
private void resume() => AddStep("resume", () => Player.Resume());
private void confirmPauseOverlayShown(bool isShown) =>
AddAssert("pause overlay " + (isShown ? "shown" : "hidden"), () => Player.PauseOverlayVisible == isShown);
private void confirmClockRunning(bool isRunning) =>
AddAssert("clock " + (isRunning ? "running" : "stopped"), () => Player.GameplayClockContainer.GameplayClock.IsRunning == isRunning);
2019-03-18 10:44:21 +00:00
protected override bool AllowFail => true;
protected override Player CreatePlayer(Ruleset ruleset) => new PausePlayer();
protected class PausePlayer : TestPlayer
2019-03-17 15:46:15 +00:00
{
public new GameplayClockContainer GameplayClockContainer => base.GameplayClockContainer;
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
2019-03-18 02:48:11 +00:00
public new HUDOverlay HUDOverlay => base.HUDOverlay;
2019-03-18 02:48:11 +00:00
public bool FailOverlayVisible => FailOverlay.State == Visibility.Visible;
public bool PauseOverlayVisible => PauseOverlay.State == Visibility.Visible;
public override void OnEntering(IScreen last)
{
base.OnEntering(last);
GameplayClockContainer.Stop();
}
2019-03-17 15:46:15 +00:00
}
}
}