1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-09 03:37:33 +08:00
osu-lazer/osu.Game.Tests/Visual/Menus/TestSceneScreenNavigation.cs

186 lines
6.8 KiB
C#
Raw Normal View History

// 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;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2019-07-31 18:30:35 +08:00
using osu.Framework.Logging;
using osu.Framework.Platform;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
2019-07-31 18:47:41 +08:00
using osu.Game.Overlays;
using osu.Game.Overlays.Mods;
2019-07-31 15:03:05 +08:00
using osu.Game.Screens;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Select;
2019-07-31 15:03:05 +08:00
using osuTK;
using osuTK.Graphics;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Menus
{
public class TestSceneScreenNavigation : ManualInputManagerTestScene
{
private GameHost gameHost;
private TestOsuGame osuGame;
2019-07-31 18:30:35 +08:00
private Vector2 backButtonPosition => osuGame.ToScreenSpace(new Vector2(25, osuGame.LayoutRectangle.Bottom - 25));
2019-07-31 15:03:05 +08:00
2019-07-31 18:47:41 +08:00
private Vector2 optionsButtonPosition => osuGame.ToScreenSpace(new Vector2(25, 25));
[BackgroundDependencyLoader]
private void load(GameHost gameHost)
{
this.gameHost = gameHost;
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
};
}
[SetUpSteps]
public void SetUpSteps()
{
AddStep("Create new game instance", () =>
{
if (osuGame != null)
Remove(osuGame);
osuGame = new TestOsuGame();
osuGame.SetHost(gameHost);
Add(osuGame);
});
2019-07-31 15:03:05 +08:00
AddUntilStep("Wait for load", () => osuGame.IsLoaded);
2019-07-31 18:30:35 +08:00
AddUntilStep("Wait for intro", () => osuGame.ScreenStack.CurrentScreen is IntroScreen);
AddUntilStep("Wait for main menu", () => osuGame.ScreenStack.CurrentScreen is MainMenu menu && menu.IsLoaded);
}
[Test]
2019-07-30 17:18:03 +08:00
public void TestExitSongSelectWithEscape()
{
TestSongSelect songSelect = null;
pushAndConfirm(() => songSelect = new TestSongSelect(), "song select");
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]
2019-07-30 17:18:03 +08:00
public void TestExitSongSelectWithClick()
{
TestSongSelect songSelect = null;
pushAndConfirm(() => songSelect = new TestSongSelect(), "song select");
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));
// 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));
2019-07-31 15:03:05 +08:00
AddUntilStep("Overlay was hidden", () => songSelect.ModSelectOverlay.State.Value == Visibility.Hidden);
exitViaBackButtonAndConfirm();
}
[Test]
public void TestExitMultiWithEscape()
{
2019-07-31 18:30:35 +08:00
pushAndConfirm(() => new TestMultiplayer(), "multiplayer");
exitViaEscapeAndConfirm();
}
[Test]
public void TestExitMultiWithBackButton()
{
2019-07-31 18:30:35 +08:00
pushAndConfirm(() => new TestMultiplayer(), "multiplayer");
exitViaBackButtonAndConfirm();
}
2019-07-31 18:47:41 +08:00
[Test]
public void TestOpenOptionsAndExitWithEscape()
{
AddStep("Enter menu", () => pressAndRelease(Key.Enter));
AddStep("Move mouse to options overlay", () => InputManager.MoveMouseTo(optionsButtonPosition));
AddStep("Click options overlay", () => InputManager.Click(MouseButton.Left));
AddAssert("Options overlay was opened", () => osuGame.Settings.State.Value == Visibility.Visible);
AddStep("Hide options overlay using escape", () => pressAndRelease(Key.Escape));
AddAssert("Options overlay was closed", () => osuGame.Settings.State.Value == Visibility.Hidden);
}
private void pushAndConfirm(Func<Screen> newScreen, string screenName)
{
Screen screen = null;
2019-07-31 18:30:35 +08:00
AddStep($"Push new {screenName}", () =>
{
if (screenName == "song select")
Logger.Log("fuck");
2019-07-31 18:47:41 +08:00
2019-07-31 18:30:35 +08:00
osuGame.ScreenStack.Push(screen = newScreen());
});
AddUntilStep($"Wait for new {screenName}", () => osuGame.ScreenStack.CurrentScreen == screen && screen.IsLoaded);
}
private void exitViaEscapeAndConfirm()
{
AddStep("Press escape", () => pressAndRelease(Key.Escape));
AddUntilStep("Wait for main menu", () => osuGame.ScreenStack.CurrentScreen is MainMenu);
}
private void exitViaBackButtonAndConfirm()
{
2019-07-31 18:30:35 +08:00
AddStep("Move mouse to backButton", () => InputManager.MoveMouseTo(backButtonPosition));
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;
2019-07-31 15:03:05 +08:00
2019-07-31 18:47:41 +08:00
public new SettingsPanel Settings => base.Settings;
2019-07-31 15:03:05 +08:00
protected override Loader CreateLoader() => new TestLoader();
}
private class TestSongSelect : PlaySongSelect
{
public ModSelectOverlay ModSelectOverlay => ModSelect;
}
2019-07-31 15:03:05 +08:00
2019-07-31 18:30:35 +08:00
private class TestMultiplayer : Screens.Multi.Multiplayer
{
protected override bool RequireOnline => false;
}
2019-07-31 15:03:05 +08:00
private class TestLoader : Loader
{
protected override ShaderPrecompiler CreateShaderPrecompiler() => new TestShaderPrecompiler();
private class TestShaderPrecompiler : ShaderPrecompiler
{
protected override bool AllLoaded => true;
}
}
}
}