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.
|
|
|
|
|
2019-07-30 11:00:04 +08:00
|
|
|
using System;
|
2019-07-29 13:30:46 +08:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Overlays.Mods;
|
|
|
|
using osu.Game.Screens.Menu;
|
|
|
|
using osu.Game.Screens.Select;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Menus
|
|
|
|
{
|
2019-07-30 17:16:17 +08:00
|
|
|
public class TestSceneScreenNavigation : ManualInputManagerTestScene
|
2019-07-29 13:30:46 +08:00
|
|
|
{
|
2019-07-30 17:16:17 +08:00
|
|
|
private GameHost gameHost;
|
|
|
|
private TestOsuGame osuGame;
|
2019-07-29 13:30:46 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(GameHost gameHost)
|
|
|
|
{
|
2019-07-30 17:16:17 +08:00
|
|
|
this.gameHost = gameHost;
|
2019-07-29 13:30:46 +08:00
|
|
|
|
2019-07-30 17:16:17 +08:00
|
|
|
Child = new Box
|
2019-07-29 13:30:46 +08:00
|
|
|
{
|
2019-07-30 17:16:17 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Black,
|
2019-07-29 13:30:46 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[SetUpSteps]
|
|
|
|
public void SetUpSteps()
|
|
|
|
{
|
2019-07-30 17:16:17 +08:00
|
|
|
AddStep("Create new game instance", () =>
|
2019-07-29 13:30:46 +08:00
|
|
|
{
|
2019-07-30 17:16:17 +08:00
|
|
|
if (osuGame != null)
|
|
|
|
Remove(osuGame);
|
2019-07-29 13:30:46 +08:00
|
|
|
|
2019-07-30 17:16:17 +08:00
|
|
|
osuGame = new TestOsuGame();
|
|
|
|
osuGame.SetHost(gameHost);
|
2019-07-29 13:30:46 +08:00
|
|
|
|
2019-07-30 17:16:17 +08:00
|
|
|
Add(osuGame);
|
2019-07-29 13:30:46 +08:00
|
|
|
});
|
2019-07-30 17:16:17 +08:00
|
|
|
AddUntilStep("wait for load and menu is current", () => osuGame.IsLoaded && osuGame.ScreenStack.CurrentScreen is MainMenu);
|
2019-07-29 13:30:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestExitingSongSelectWithEscape()
|
|
|
|
{
|
|
|
|
TestSongSelect songSelect = null;
|
|
|
|
|
2019-07-30 11:00:04 +08:00
|
|
|
pushAndConfirm(() => songSelect = new TestSongSelect(), "song select");
|
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);
|
|
|
|
AddStep("Press escape", () => pressAndRelease(Key.Escape));
|
|
|
|
AddAssert("Overlay was hidden", () => songSelect.ModSelectOverlay.State.Value == Visibility.Hidden);
|
|
|
|
exitViaEscapeAndConfirm();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestExitingSongSelectWithClick()
|
|
|
|
{
|
|
|
|
TestSongSelect songSelect = null;
|
|
|
|
|
2019-07-30 11:00:04 +08:00
|
|
|
pushAndConfirm(() => songSelect = new TestSongSelect(), "song select");
|
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);
|
|
|
|
AddStep("Move mouse to backButton", () => InputManager.MoveMouseTo(osuGame.BackButton));
|
|
|
|
|
|
|
|
// BackButton handles hover using its child button, so this checks whether or not any of BackButton's children are hovered.
|
|
|
|
AddUntilStep("Back button is hovered", () => InputManager.HoveredDrawables.Any(d => d.Parent == osuGame.BackButton));
|
|
|
|
|
|
|
|
AddStep("Click back button", () => InputManager.Click(MouseButton.Left));
|
|
|
|
AddAssert("Overlay was hidden", () => songSelect.ModSelectOverlay.State.Value == Visibility.Hidden);
|
|
|
|
exitViaBackButtonAndConfirm();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestExitMultiWithEscape()
|
|
|
|
{
|
2019-07-30 11:00:04 +08:00
|
|
|
pushAndConfirm(() => new Screens.Multi.Multiplayer(), "multiplayer");
|
2019-07-29 13:30:46 +08:00
|
|
|
exitViaEscapeAndConfirm();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestExitMultiWithBackButton()
|
|
|
|
{
|
2019-07-30 11:00:04 +08:00
|
|
|
pushAndConfirm(() => new Screens.Multi.Multiplayer(), "multiplayer");
|
2019-07-29 13:30:46 +08:00
|
|
|
exitViaBackButtonAndConfirm();
|
|
|
|
}
|
|
|
|
|
2019-07-30 11:00:04 +08:00
|
|
|
private void pushAndConfirm(Func<Screen> newScreen, string screenName)
|
|
|
|
{
|
|
|
|
Screen screen = null;
|
|
|
|
AddStep($"Push new {screenName}", () => osuGame.ScreenStack.Push(screen = newScreen()));
|
|
|
|
AddUntilStep($"Wait for new {screenName}", () => screen.IsCurrentScreen());
|
|
|
|
}
|
|
|
|
|
2019-07-29 13:30:46 +08:00
|
|
|
private void exitViaEscapeAndConfirm()
|
|
|
|
{
|
|
|
|
AddStep("Press escape", () => pressAndRelease(Key.Escape));
|
|
|
|
AddUntilStep("Wait for main menu", () => osuGame.ScreenStack.CurrentScreen is MainMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void exitViaBackButtonAndConfirm()
|
|
|
|
{
|
|
|
|
AddStep("Move mouse to backButton", () => InputManager.MoveMouseTo(osuGame.BackButton));
|
|
|
|
AddStep("Click back button", () => InputManager.Click(MouseButton.Left));
|
|
|
|
AddUntilStep("Wait for main menu", () => osuGame.ScreenStack.CurrentScreen is MainMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void pressAndRelease(Key key)
|
|
|
|
{
|
|
|
|
InputManager.PressKey(key);
|
|
|
|
InputManager.ReleaseKey(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestOsuGame : OsuGame
|
|
|
|
{
|
|
|
|
public new ScreenStack ScreenStack => base.ScreenStack;
|
|
|
|
|
|
|
|
public new BackButton BackButton => base.BackButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestSongSelect : PlaySongSelect
|
|
|
|
{
|
|
|
|
public ModSelectOverlay ModSelectOverlay => ModSelect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|