2019-03-18 00:46:15 +09: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.
|
|
|
|
|
2019-03-26 13:18:33 +09:00
|
|
|
using System.Linq;
|
2019-03-18 19:44:21 +09:00
|
|
|
using NUnit.Framework;
|
2019-03-26 13:18:33 +09:00
|
|
|
using osu.Framework.Graphics;
|
2019-03-18 11:48:11 +09:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-03-18 14:57:06 +09:00
|
|
|
using osu.Framework.Screens;
|
2019-05-10 18:10:07 +09:00
|
|
|
using osu.Framework.Testing;
|
2019-03-26 13:18:33 +09:00
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Cursor;
|
2019-03-18 00:46:15 +09:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Screens.Play;
|
2019-03-26 13:18:33 +09:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Input;
|
2019-03-18 00:46:15 +09:00
|
|
|
|
2019-03-25 01:02:36 +09:00
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
2019-03-18 00:46:15 +09:00
|
|
|
{
|
2019-05-14 22:37:25 +03:00
|
|
|
public class TestScenePause : PlayerTestScene
|
2019-03-18 00:46:15 +09:00
|
|
|
{
|
2019-03-18 19:44:21 +09:00
|
|
|
protected new PausePlayer Player => (PausePlayer)base.Player;
|
|
|
|
|
2019-03-26 13:18:33 +09:00
|
|
|
private readonly Container content;
|
|
|
|
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
2019-05-14 22:37:25 +03:00
|
|
|
public TestScenePause()
|
2019-03-18 00:46:15 +09:00
|
|
|
: base(new OsuRuleset())
|
|
|
|
{
|
2019-03-26 13:18:33 +09:00
|
|
|
base.Content.Add(content = new MenuCursorContainer { RelativeSizeAxes = Axes.Both });
|
2019-03-18 00:46:15 +09:00
|
|
|
}
|
|
|
|
|
2019-05-10 18:10:07 +09:00
|
|
|
[SetUpSteps]
|
|
|
|
public override void SetUpSteps()
|
|
|
|
{
|
|
|
|
base.SetUpSteps();
|
2020-01-31 13:54:26 +09:00
|
|
|
|
2019-05-10 18:10:07 +09:00
|
|
|
AddStep("resume player", () => Player.GameplayClockContainer.Start());
|
|
|
|
confirmClockRunning(true);
|
|
|
|
}
|
|
|
|
|
2019-03-18 19:44:21 +09:00
|
|
|
[Test]
|
|
|
|
public void TestPauseResume()
|
2019-03-18 00:46:15 +09:00
|
|
|
{
|
2019-03-26 13:18:33 +09: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));
|
2019-12-19 20:03:14 +09:00
|
|
|
AddUntilStep("wait for hitobjects", () => Player.HealthProcessor.Health.Value < 1);
|
2019-03-26 13:18:33 +09:00
|
|
|
|
|
|
|
pauseAndConfirm();
|
|
|
|
resume();
|
|
|
|
|
|
|
|
confirmClockRunning(false);
|
|
|
|
confirmPauseOverlayShown(false);
|
|
|
|
|
|
|
|
AddStep("click to resume", () =>
|
|
|
|
{
|
|
|
|
InputManager.PressButton(MouseButton.Left);
|
|
|
|
InputManager.ReleaseButton(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
|
|
|
confirmClockRunning(true);
|
|
|
|
}
|
|
|
|
|
2019-10-26 14:29:52 -05:00
|
|
|
[Test]
|
|
|
|
public void TestPauseWithResumeOverlay()
|
|
|
|
{
|
|
|
|
AddStep("move cursor to center", () => InputManager.MoveMouseTo(Player.ScreenSpaceDrawQuad.Centre));
|
2019-12-19 20:03:14 +09:00
|
|
|
AddUntilStep("wait for hitobjects", () => Player.HealthProcessor.Health.Value < 1);
|
2019-10-26 14:29:52 -05:00
|
|
|
|
|
|
|
pauseAndConfirm();
|
|
|
|
|
|
|
|
resume();
|
|
|
|
confirmClockRunning(false);
|
|
|
|
confirmPauseOverlayShown(false);
|
|
|
|
|
|
|
|
pauseAndConfirm();
|
|
|
|
|
|
|
|
AddUntilStep("resume overlay is not active", () => Player.DrawableRuleset.ResumeOverlay.State.Value == Visibility.Hidden);
|
|
|
|
confirmPaused();
|
|
|
|
}
|
|
|
|
|
2019-03-26 13:18:33 +09:00
|
|
|
[Test]
|
|
|
|
public void TestResumeWithResumeOverlaySkipped()
|
|
|
|
{
|
|
|
|
AddStep("move cursor to button", () =>
|
|
|
|
InputManager.MoveMouseTo(Player.HUDOverlay.HoldToQuit.Children.OfType<HoldToConfirmContainer>().First().ScreenSpaceDrawQuad.Centre));
|
2019-12-19 20:03:14 +09:00
|
|
|
AddUntilStep("wait for hitobjects", () => Player.HealthProcessor.Health.Value < 1);
|
2019-03-26 13:18:33 +09:00
|
|
|
|
2019-03-21 16:33:34 +09:00
|
|
|
pauseAndConfirm();
|
|
|
|
resumeAndConfirm();
|
2019-03-18 19:44:21 +09:00
|
|
|
}
|
2019-03-18 11:48:11 +09:00
|
|
|
|
2019-03-18 19:44:21 +09:00
|
|
|
[Test]
|
|
|
|
public void TestPauseTooSoon()
|
|
|
|
{
|
2019-03-26 13:18:33 +09:00
|
|
|
AddStep("move cursor outside", () => InputManager.MoveMouseTo(Player.ScreenSpaceDrawQuad.TopLeft - new Vector2(10)));
|
|
|
|
|
2019-03-21 16:33:34 +09:00
|
|
|
pauseAndConfirm();
|
|
|
|
|
2019-05-13 19:23:38 +09:00
|
|
|
resume();
|
2019-03-21 16:33:34 +09:00
|
|
|
pause();
|
|
|
|
|
|
|
|
confirmClockRunning(true);
|
|
|
|
confirmPauseOverlayShown(false);
|
2019-03-18 19:44:21 +09:00
|
|
|
}
|
2019-03-18 11:48:11 +09:00
|
|
|
|
2019-03-21 16:11:44 +09:00
|
|
|
[Test]
|
|
|
|
public void TestExitTooSoon()
|
|
|
|
{
|
2019-11-28 15:58:26 +09:00
|
|
|
AddStep("seek before gameplay", () => Player.GameplayClockContainer.Seek(-5000));
|
2019-03-21 16:33:34 +09:00
|
|
|
|
2019-11-28 15:58:26 +09:00
|
|
|
pauseAndConfirm();
|
2019-03-21 16:33:34 +09:00
|
|
|
resume();
|
|
|
|
|
|
|
|
AddStep("exit too soon", () => Player.Exit());
|
|
|
|
|
|
|
|
confirmClockRunning(true);
|
|
|
|
confirmPauseOverlayShown(false);
|
|
|
|
|
2019-03-21 16:11:44 +09:00
|
|
|
AddAssert("not exited", () => Player.IsCurrentScreen());
|
|
|
|
}
|
|
|
|
|
2019-03-18 19:44:21 +09:00
|
|
|
[Test]
|
|
|
|
public void TestPauseAfterFail()
|
|
|
|
{
|
2019-03-20 10:30:17 +09:00
|
|
|
AddUntilStep("wait for fail", () => Player.HasFailed);
|
2019-06-04 16:13:16 +09:00
|
|
|
AddUntilStep("fail overlay shown", () => Player.FailOverlayVisible);
|
2019-03-18 11:48:11 +09:00
|
|
|
|
2019-03-21 16:33:34 +09:00
|
|
|
confirmClockRunning(false);
|
|
|
|
|
|
|
|
pause();
|
|
|
|
|
|
|
|
confirmClockRunning(false);
|
|
|
|
confirmPauseOverlayShown(false);
|
2019-03-18 14:57:06 +09:00
|
|
|
|
2019-03-18 19:44:21 +09:00
|
|
|
AddAssert("fail overlay still shown", () => Player.FailOverlayVisible);
|
2019-03-21 16:11:44 +09:00
|
|
|
|
2019-03-21 16:33:34 +09:00
|
|
|
exitAndConfirm();
|
2019-03-21 16:11:44 +09:00
|
|
|
}
|
|
|
|
|
2019-10-04 11:25:23 +08:00
|
|
|
[Test]
|
|
|
|
public void TestExitFromFailedGameplay()
|
|
|
|
{
|
|
|
|
AddUntilStep("wait for fail", () => Player.HasFailed);
|
|
|
|
AddStep("exit", () => Player.Exit());
|
|
|
|
|
|
|
|
confirmExited();
|
|
|
|
}
|
|
|
|
|
2019-10-04 12:23:01 +08:00
|
|
|
[Test]
|
|
|
|
public void TestQuickRetryFromFailedGameplay()
|
|
|
|
{
|
|
|
|
AddUntilStep("wait for fail", () => Player.HasFailed);
|
|
|
|
AddStep("quick retry", () => Player.GameplayClockContainer.OfType<HotkeyRetryOverlay>().First().Action?.Invoke());
|
|
|
|
|
|
|
|
confirmExited();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestQuickExitFromFailedGameplay()
|
|
|
|
{
|
|
|
|
AddUntilStep("wait for fail", () => Player.HasFailed);
|
|
|
|
AddStep("quick exit", () => Player.GameplayClockContainer.OfType<HotkeyExitOverlay>().First().Action?.Invoke());
|
|
|
|
|
|
|
|
confirmExited();
|
|
|
|
}
|
|
|
|
|
2019-03-21 16:11:44 +09:00
|
|
|
[Test]
|
|
|
|
public void TestExitFromGameplay()
|
|
|
|
{
|
|
|
|
AddStep("exit", () => Player.Exit());
|
2019-11-28 15:58:26 +09:00
|
|
|
confirmPaused();
|
2019-03-21 16:11:44 +09:00
|
|
|
|
2019-11-28 15:58:26 +09:00
|
|
|
AddStep("exit", () => Player.Exit());
|
2019-10-02 12:07:07 -07:00
|
|
|
confirmExited();
|
2019-03-18 19:44:21 +09:00
|
|
|
}
|
2019-03-18 14:57:06 +09:00
|
|
|
|
2019-10-04 12:23:01 +08:00
|
|
|
[Test]
|
|
|
|
public void TestQuickExitFromGameplay()
|
|
|
|
{
|
|
|
|
AddStep("quick exit", () => Player.GameplayClockContainer.OfType<HotkeyExitOverlay>().First().Action?.Invoke());
|
|
|
|
|
|
|
|
confirmExited();
|
|
|
|
}
|
|
|
|
|
2019-06-25 23:48:42 +09:00
|
|
|
[Test]
|
|
|
|
public void TestExitViaHoldToExit()
|
|
|
|
{
|
|
|
|
AddStep("exit", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(Player.HUDOverlay.HoldToQuit.First(c => c is HoldToConfirmContainer));
|
|
|
|
InputManager.PressButton(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
|
|
|
confirmPaused();
|
|
|
|
|
|
|
|
AddStep("release", () => InputManager.ReleaseButton(MouseButton.Left));
|
|
|
|
|
|
|
|
exitAndConfirm();
|
|
|
|
}
|
|
|
|
|
2019-03-18 19:44:21 +09:00
|
|
|
[Test]
|
|
|
|
public void TestExitFromPause()
|
|
|
|
{
|
2019-03-21 16:33:34 +09:00
|
|
|
pauseAndConfirm();
|
|
|
|
exitAndConfirm();
|
|
|
|
}
|
2019-03-18 14:57:06 +09:00
|
|
|
|
2019-09-13 15:41:53 +09:00
|
|
|
[Test]
|
|
|
|
public void TestRestartAfterResume()
|
|
|
|
{
|
2019-11-28 15:58:26 +09:00
|
|
|
AddStep("seek before gameplay", () => Player.GameplayClockContainer.Seek(-5000));
|
|
|
|
|
2019-09-13 15:41:53 +09:00
|
|
|
pauseAndConfirm();
|
|
|
|
resumeAndConfirm();
|
|
|
|
restart();
|
|
|
|
confirmExited();
|
|
|
|
}
|
|
|
|
|
2019-03-21 16:33:34 +09:00
|
|
|
private void pauseAndConfirm()
|
|
|
|
{
|
|
|
|
pause();
|
|
|
|
confirmPaused();
|
2019-03-21 16:11:44 +09:00
|
|
|
}
|
|
|
|
|
2019-03-21 16:33:34 +09:00
|
|
|
private void resumeAndConfirm()
|
|
|
|
{
|
|
|
|
resume();
|
|
|
|
confirmResumed();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void exitAndConfirm()
|
2019-03-21 16:11:44 +09:00
|
|
|
{
|
|
|
|
AddUntilStep("player not exited", () => Player.IsCurrentScreen());
|
2019-03-18 19:44:21 +09:00
|
|
|
AddStep("exit", () => Player.Exit());
|
2019-03-21 16:33:34 +09:00
|
|
|
confirmExited();
|
2019-11-06 10:32:09 +09:00
|
|
|
confirmNoTrackAdjustments();
|
2019-03-21 16:33:34 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
private void confirmPaused()
|
|
|
|
{
|
|
|
|
confirmClockRunning(false);
|
2019-05-09 11:31:40 +09:00
|
|
|
AddAssert("player not exited", () => Player.IsCurrentScreen());
|
|
|
|
AddAssert("player not failed", () => !Player.HasFailed);
|
2019-03-21 16:33:34 +09:00
|
|
|
AddAssert("pause overlay shown", () => Player.PauseOverlayVisible);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void confirmResumed()
|
|
|
|
{
|
|
|
|
confirmClockRunning(true);
|
|
|
|
confirmPauseOverlayShown(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void confirmExited()
|
|
|
|
{
|
2019-03-20 10:30:17 +09:00
|
|
|
AddUntilStep("player exited", () => !Player.IsCurrentScreen());
|
2019-03-18 00:46:15 +09:00
|
|
|
}
|
|
|
|
|
2019-11-06 10:32:09 +09:00
|
|
|
private void confirmNoTrackAdjustments()
|
|
|
|
{
|
|
|
|
AddAssert("track has no adjustments", () => Beatmap.Value.Track.AggregateFrequency.Value == 1);
|
|
|
|
}
|
|
|
|
|
2019-09-13 15:41:53 +09:00
|
|
|
private void restart() => AddStep("restart", () => Player.Restart());
|
2019-03-21 16:33:34 +09: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) =>
|
2019-06-10 01:08:39 +09:00
|
|
|
AddUntilStep("clock " + (isRunning ? "running" : "stopped"), () => Player.GameplayClockContainer.GameplayClock.IsRunning == isRunning);
|
2019-03-21 16:33:34 +09:00
|
|
|
|
2019-03-18 19:44:21 +09:00
|
|
|
protected override bool AllowFail => true;
|
|
|
|
|
|
|
|
protected override Player CreatePlayer(Ruleset ruleset) => new PausePlayer();
|
|
|
|
|
2019-05-10 15:39:25 +09:00
|
|
|
protected class PausePlayer : TestPlayer
|
2019-03-18 00:46:15 +09:00
|
|
|
{
|
2019-12-19 20:03:14 +09:00
|
|
|
public new HealthProcessor HealthProcessor => base.HealthProcessor;
|
2019-03-18 11:48:11 +09:00
|
|
|
|
2019-03-26 13:18:33 +09:00
|
|
|
public new HUDOverlay HUDOverlay => base.HUDOverlay;
|
|
|
|
|
2019-06-11 14:28:52 +09:00
|
|
|
public bool FailOverlayVisible => FailOverlay.State.Value == Visibility.Visible;
|
2019-03-18 11:48:11 +09:00
|
|
|
|
2019-06-11 14:28:52 +09:00
|
|
|
public bool PauseOverlayVisible => PauseOverlay.State.Value == Visibility.Visible;
|
2019-03-26 13:18:33 +09:00
|
|
|
|
2019-05-10 18:10:07 +09:00
|
|
|
public override void OnEntering(IScreen last)
|
|
|
|
{
|
|
|
|
base.OnEntering(last);
|
|
|
|
GameplayClockContainer.Stop();
|
|
|
|
}
|
2019-03-18 00:46:15 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|