2019-07-29 13:30:46 +08: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;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2019-10-10 10:58:43 +08:00
|
|
|
using osu.Framework.Audio.Track;
|
2019-07-29 13:30:46 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-10-10 10:58:43 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2019-07-31 18:47:41 +08:00
|
|
|
using osu.Game.Overlays;
|
2019-07-29 13:30:46 +08:00
|
|
|
using osu.Game.Overlays.Mods;
|
2019-10-10 10:58:43 +08:00
|
|
|
using osu.Game.Screens.Play;
|
2019-07-29 13:30:46 +08:00
|
|
|
using osu.Game.Screens.Select;
|
2019-10-10 10:58:43 +08:00
|
|
|
using osu.Game.Tests.Beatmaps.IO;
|
2019-07-31 15:03:05 +08:00
|
|
|
using osuTK;
|
2019-07-29 13:30:46 +08:00
|
|
|
using osuTK.Input;
|
|
|
|
|
2020-01-29 13:23:23 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Navigation
|
2019-07-29 13:30:46 +08:00
|
|
|
{
|
2020-01-29 13:23:23 +08:00
|
|
|
public class TestSceneScreenNavigation : OsuGameTestScene
|
2019-07-29 13:30:46 +08:00
|
|
|
{
|
2019-08-13 11:26:06 +08:00
|
|
|
private const float click_padding = 25;
|
|
|
|
|
2020-01-29 13:23:23 +08:00
|
|
|
private Vector2 backButtonPosition => Game.ToScreenSpace(new Vector2(click_padding, Game.LayoutRectangle.Bottom - click_padding));
|
2019-07-29 13:30:46 +08:00
|
|
|
|
2020-01-29 13:23:23 +08:00
|
|
|
private Vector2 optionsButtonPosition => Game.ToScreenSpace(new Vector2(click_padding, click_padding));
|
2019-07-29 13:30:46 +08:00
|
|
|
|
|
|
|
[Test]
|
2019-07-30 17:18:03 +08:00
|
|
|
public void TestExitSongSelectWithEscape()
|
2019-07-29 13:30:46 +08:00
|
|
|
{
|
|
|
|
TestSongSelect songSelect = null;
|
|
|
|
|
2020-01-30 22:45:15 +08:00
|
|
|
PushAndConfirm(() => songSelect = new TestSongSelect());
|
2019-07-29 13:30:46 +08:00
|
|
|
AddStep("Show mods overlay", () => songSelect.ModSelectOverlay.Show());
|
|
|
|
AddAssert("Overlay was shown", () => songSelect.ModSelectOverlay.State.Value == Visibility.Visible);
|
2019-10-10 10:58:43 +08:00
|
|
|
pushEscape();
|
2019-07-29 13:30:46 +08:00
|
|
|
AddAssert("Overlay was hidden", () => songSelect.ModSelectOverlay.State.Value == Visibility.Hidden);
|
|
|
|
exitViaEscapeAndConfirm();
|
|
|
|
}
|
|
|
|
|
2019-10-10 19:12:47 +08:00
|
|
|
[TestCase(true)]
|
|
|
|
[TestCase(false)]
|
|
|
|
public void TestSongContinuesAfterExitPlayer(bool withUserPause)
|
2019-10-10 10:58:43 +08:00
|
|
|
{
|
|
|
|
Player player = null;
|
|
|
|
|
2020-01-29 13:23:23 +08:00
|
|
|
WorkingBeatmap beatmap() => Game.Beatmap.Value;
|
2019-10-10 10:58:43 +08:00
|
|
|
Track track() => beatmap().Track;
|
|
|
|
|
2020-01-30 22:45:15 +08:00
|
|
|
PushAndConfirm(() => new TestSongSelect());
|
2019-10-10 10:58:43 +08:00
|
|
|
|
2020-01-29 13:23:23 +08:00
|
|
|
AddStep("import beatmap", () => ImportBeatmapTest.LoadOszIntoOsu(Game, virtualTrack: true).Wait());
|
2019-10-10 10:58:43 +08:00
|
|
|
|
2020-01-29 13:23:23 +08:00
|
|
|
AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault);
|
2019-10-10 10:58:43 +08:00
|
|
|
|
2019-10-10 19:12:47 +08:00
|
|
|
if (withUserPause)
|
2020-01-29 13:23:23 +08:00
|
|
|
AddStep("pause", () => Game.Dependencies.Get<MusicController>().Stop());
|
2019-10-10 19:12:47 +08:00
|
|
|
|
2019-10-10 10:58:43 +08:00
|
|
|
AddStep("press enter", () => pressAndRelease(Key.Enter));
|
|
|
|
|
2020-01-29 13:23:23 +08:00
|
|
|
AddUntilStep("wait for player", () => (player = Game.ScreenStack.CurrentScreen as Player) != null);
|
2019-10-10 10:58:43 +08:00
|
|
|
AddUntilStep("wait for fail", () => player.HasFailed);
|
|
|
|
|
|
|
|
AddUntilStep("wait for track stop", () => !track().IsRunning);
|
|
|
|
AddAssert("Ensure time before preview point", () => track().CurrentTime < beatmap().Metadata.PreviewTime);
|
|
|
|
|
|
|
|
pushEscape();
|
|
|
|
|
|
|
|
AddUntilStep("wait for track playing", () => track().IsRunning);
|
|
|
|
AddAssert("Ensure time wasn't reset to preview point", () => track().CurrentTime < beatmap().Metadata.PreviewTime);
|
|
|
|
}
|
|
|
|
|
2019-07-29 13:30:46 +08:00
|
|
|
[Test]
|
2019-07-30 17:18:03 +08:00
|
|
|
public void TestExitSongSelectWithClick()
|
2019-07-29 13:30:46 +08:00
|
|
|
{
|
|
|
|
TestSongSelect songSelect = null;
|
|
|
|
|
2020-01-30 22:45:15 +08:00
|
|
|
PushAndConfirm(() => songSelect = new TestSongSelect());
|
2019-07-29 13:30:46 +08:00
|
|
|
AddStep("Show mods overlay", () => songSelect.ModSelectOverlay.Show());
|
|
|
|
AddAssert("Overlay was shown", () => songSelect.ModSelectOverlay.State.Value == Visibility.Visible);
|
2019-07-31 18:30:35 +08:00
|
|
|
AddStep("Move mouse to backButton", () => InputManager.MoveMouseTo(backButtonPosition));
|
2019-07-29 13:30:46 +08:00
|
|
|
|
|
|
|
// BackButton handles hover using its child button, so this checks whether or not any of BackButton's children are hovered.
|
2020-01-29 13:23:23 +08:00
|
|
|
AddUntilStep("Back button is hovered", () => InputManager.HoveredDrawables.Any(d => d.Parent == Game.BackButton));
|
2019-07-29 13:30:46 +08:00
|
|
|
|
|
|
|
AddStep("Click back button", () => InputManager.Click(MouseButton.Left));
|
2019-07-31 15:03:05 +08:00
|
|
|
AddUntilStep("Overlay was hidden", () => songSelect.ModSelectOverlay.State.Value == Visibility.Hidden);
|
2019-07-29 13:30:46 +08:00
|
|
|
exitViaBackButtonAndConfirm();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestExitMultiWithEscape()
|
|
|
|
{
|
2020-01-30 22:45:15 +08:00
|
|
|
PushAndConfirm(() => new Screens.Multi.Multiplayer());
|
2019-07-29 13:30:46 +08:00
|
|
|
exitViaEscapeAndConfirm();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestExitMultiWithBackButton()
|
|
|
|
{
|
2020-01-30 22:45:15 +08:00
|
|
|
PushAndConfirm(() => new Screens.Multi.Multiplayer());
|
2019-07-29 13:30:46 +08:00
|
|
|
exitViaBackButtonAndConfirm();
|
|
|
|
}
|
|
|
|
|
2019-07-31 18:47:41 +08:00
|
|
|
[Test]
|
|
|
|
public void TestOpenOptionsAndExitWithEscape()
|
|
|
|
{
|
2020-01-29 13:23:23 +08:00
|
|
|
AddUntilStep("Wait for options to load", () => Game.Settings.IsLoaded);
|
2019-07-31 18:47:41 +08:00
|
|
|
AddStep("Enter menu", () => pressAndRelease(Key.Enter));
|
|
|
|
AddStep("Move mouse to options overlay", () => InputManager.MoveMouseTo(optionsButtonPosition));
|
|
|
|
AddStep("Click options overlay", () => InputManager.Click(MouseButton.Left));
|
2020-01-29 13:23:23 +08:00
|
|
|
AddAssert("Options overlay was opened", () => Game.Settings.State.Value == Visibility.Visible);
|
2019-07-31 18:47:41 +08:00
|
|
|
AddStep("Hide options overlay using escape", () => pressAndRelease(Key.Escape));
|
2020-01-29 13:23:23 +08:00
|
|
|
AddAssert("Options overlay was closed", () => Game.Settings.State.Value == Visibility.Hidden);
|
2019-07-31 18:47:41 +08:00
|
|
|
}
|
|
|
|
|
2020-03-05 16:12:14 +08:00
|
|
|
[Test]
|
|
|
|
public void TestWaitForNextTrackInMenu()
|
|
|
|
{
|
|
|
|
bool trackCompleted = false;
|
|
|
|
|
|
|
|
AddUntilStep("Wait for music controller", () => Game.MusicController.IsLoaded);
|
|
|
|
AddStep("Seek close to end", () =>
|
|
|
|
{
|
|
|
|
Game.MusicController.SeekTo(Game.Beatmap.Value.Track.Length - 1000);
|
|
|
|
Game.Beatmap.Value.Track.Completed += () => trackCompleted = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("Track was completed", () => trackCompleted);
|
|
|
|
AddUntilStep("Track was restarted", () => Game.Beatmap.Value.Track.IsRunning);
|
|
|
|
}
|
|
|
|
|
2019-10-10 10:58:43 +08:00
|
|
|
private void pushEscape() =>
|
|
|
|
AddStep("Press escape", () => pressAndRelease(Key.Escape));
|
|
|
|
|
2019-07-29 13:30:46 +08:00
|
|
|
private void exitViaEscapeAndConfirm()
|
|
|
|
{
|
2019-10-10 10:58:43 +08:00
|
|
|
pushEscape();
|
2020-01-29 13:23:23 +08:00
|
|
|
ConfirmAtMainMenu();
|
2019-07-29 13:30:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void exitViaBackButtonAndConfirm()
|
|
|
|
{
|
2019-07-31 18:30:35 +08:00
|
|
|
AddStep("Move mouse to backButton", () => InputManager.MoveMouseTo(backButtonPosition));
|
2019-07-29 13:30:46 +08:00
|
|
|
AddStep("Click back button", () => InputManager.Click(MouseButton.Left));
|
2020-01-29 13:23:23 +08:00
|
|
|
ConfirmAtMainMenu();
|
2019-07-29 13:30:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void pressAndRelease(Key key)
|
|
|
|
{
|
|
|
|
InputManager.PressKey(key);
|
|
|
|
InputManager.ReleaseKey(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestSongSelect : PlaySongSelect
|
|
|
|
{
|
|
|
|
public ModSelectOverlay ModSelectOverlay => ModSelect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|