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;
|
2019-09-25 14:29:02 +08:00
|
|
|
using osu.Game.Configuration;
|
2019-07-29 13:30:46 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-08-01 13:19:45 +08:00
|
|
|
using osu.Game.Online.API;
|
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-07-31 15:03:05 +08:00
|
|
|
using osu.Game.Screens;
|
2019-07-29 13:30:46 +08:00
|
|
|
using osu.Game.Screens.Menu;
|
|
|
|
using osu.Game.Screens.Select;
|
2019-07-31 15:03:05 +08:00
|
|
|
using osuTK;
|
2019-07-29 13:30:46 +08:00
|
|
|
using osuTK.Graphics;
|
|
|
|
using osuTK.Input;
|
2019-09-25 14:29:02 +08:00
|
|
|
using IntroSequence = osu.Game.Configuration.IntroSequence;
|
2019-07-29 13:30:46 +08:00
|
|
|
|
|
|
|
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-08-13 11:26:06 +08:00
|
|
|
private const float click_padding = 25;
|
|
|
|
|
2019-09-25 14:00:08 +08:00
|
|
|
private GameHost host;
|
2019-07-30 17:16:17 +08:00
|
|
|
private TestOsuGame osuGame;
|
2019-07-29 13:30:46 +08:00
|
|
|
|
2019-08-13 11:26:06 +08:00
|
|
|
private Vector2 backButtonPosition => osuGame.ToScreenSpace(new Vector2(click_padding, osuGame.LayoutRectangle.Bottom - click_padding));
|
2019-07-31 15:03:05 +08:00
|
|
|
|
2019-08-13 11:26:06 +08:00
|
|
|
private Vector2 optionsButtonPosition => osuGame.ToScreenSpace(new Vector2(click_padding, click_padding));
|
2019-07-31 18:47:41 +08:00
|
|
|
|
2019-07-29 13:30:46 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2019-09-25 14:00:08 +08:00
|
|
|
private void load(GameHost host)
|
2019-07-29 13:30:46 +08:00
|
|
|
{
|
2019-09-25 14:00:08 +08:00
|
|
|
this.host = host;
|
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)
|
2019-08-07 13:51:24 +08:00
|
|
|
{
|
2019-07-30 17:16:17 +08:00
|
|
|
Remove(osuGame);
|
2019-08-07 13:51:24 +08:00
|
|
|
osuGame.Dispose();
|
|
|
|
}
|
2019-07-29 13:30:46 +08:00
|
|
|
|
2019-09-25 14:00:08 +08:00
|
|
|
osuGame = new TestOsuGame(LocalStorage, API);
|
|
|
|
osuGame.SetHost(host);
|
2019-07-29 13:30:46 +08:00
|
|
|
|
2019-09-25 14:29:02 +08:00
|
|
|
// todo: this can be removed once we can run audio trakcs without a device present
|
|
|
|
// see https://github.com/ppy/osu/issues/1302
|
|
|
|
osuGame.LocalConfig.Set(OsuSetting.IntroSequence, IntroSequence.Circles);
|
|
|
|
|
2019-07-30 17:16:17 +08:00
|
|
|
Add(osuGame);
|
2019-07-29 13:30:46 +08:00
|
|
|
});
|
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);
|
2019-08-13 11:26:06 +08:00
|
|
|
confirmAtMainMenu();
|
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;
|
|
|
|
|
2019-08-13 11:26:06 +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);
|
|
|
|
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()
|
2019-07-29 13:30:46 +08:00
|
|
|
{
|
|
|
|
TestSongSelect songSelect = null;
|
|
|
|
|
2019-08-13 11:26:06 +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.
|
|
|
|
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);
|
2019-07-29 13:30:46 +08:00
|
|
|
exitViaBackButtonAndConfirm();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestExitMultiWithEscape()
|
|
|
|
{
|
2019-08-13 11:26:06 +08:00
|
|
|
pushAndConfirm(() => new Screens.Multi.Multiplayer());
|
2019-07-29 13:30:46 +08:00
|
|
|
exitViaEscapeAndConfirm();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestExitMultiWithBackButton()
|
|
|
|
{
|
2019-08-13 11:26:06 +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()
|
|
|
|
{
|
2019-08-01 13:19:45 +08:00
|
|
|
AddUntilStep("Wait for options to load", () => osuGame.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));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-08-13 11:26:06 +08:00
|
|
|
private void pushAndConfirm(Func<Screen> newScreen)
|
2019-07-30 11:00:04 +08:00
|
|
|
{
|
|
|
|
Screen screen = null;
|
2019-08-13 11:26:06 +08:00
|
|
|
AddStep("Push new screen", () => osuGame.ScreenStack.Push(screen = newScreen()));
|
|
|
|
AddUntilStep("Wait for new screen", () => osuGame.ScreenStack.CurrentScreen == screen && screen.IsLoaded);
|
2019-07-30 11:00:04 +08:00
|
|
|
}
|
|
|
|
|
2019-07-29 13:30:46 +08:00
|
|
|
private void exitViaEscapeAndConfirm()
|
|
|
|
{
|
|
|
|
AddStep("Press escape", () => pressAndRelease(Key.Escape));
|
2019-08-13 11:26:06 +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));
|
2019-08-13 11:26:06 +08:00
|
|
|
confirmAtMainMenu();
|
2019-07-29 13:30:46 +08:00
|
|
|
}
|
|
|
|
|
2019-08-14 11:51:43 +08:00
|
|
|
private void confirmAtMainMenu() => AddUntilStep("Wait for main menu", () => osuGame.ScreenStack.CurrentScreen is MainMenu menu && menu.IsLoaded);
|
2019-08-13 11:26:06 +08:00
|
|
|
|
2019-07-29 13:30:46 +08:00
|
|
|
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-09-25 14:29:02 +08:00
|
|
|
public new OsuConfigManager LocalConfig => base.LocalConfig;
|
|
|
|
|
2019-07-31 15:03:05 +08:00
|
|
|
protected override Loader CreateLoader() => new TestLoader();
|
2019-08-01 13:19:45 +08:00
|
|
|
|
2019-09-25 14:00:08 +08:00
|
|
|
public TestOsuGame(Storage storage, IAPIProvider api)
|
|
|
|
{
|
|
|
|
Storage = storage;
|
|
|
|
API = api;
|
|
|
|
}
|
2019-08-01 13:19:45 +08:00
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2019-09-25 14:00:08 +08:00
|
|
|
API.Login("Rhythm Champion", "osu!");
|
2019-08-01 13:19:45 +08:00
|
|
|
}
|
2019-07-29 13:30:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private class TestSongSelect : PlaySongSelect
|
|
|
|
{
|
|
|
|
public ModSelectOverlay ModSelectOverlay => ModSelect;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|
2019-07-29 13:30:46 +08:00
|
|
|
}
|
|
|
|
}
|