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/TestSceneExitingScreens.cs

153 lines
5.5 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.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
{
public class TestSceneExitingScreens : ManualInputManagerTestScene
{
private readonly TestOsuGame osuGame = new TestOsuGame();
[BackgroundDependencyLoader]
private void load(GameHost gameHost)
{
osuGame.SetHost(gameHost);
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
},
osuGame
};
}
[SetUpSteps]
public void SetUpSteps()
{
AddUntilStep("wait for load", () => osuGame.IsLoaded);
AddUntilStep("wait for main menu", () =>
{
2019-07-29 16:23:45 +08:00
var current = osuGame.ScreenStack.CurrentScreen;
switch (current)
{
case null:
case Intro _:
case Disclaimer _:
return false;
case MainMenu _:
return true;
default:
current.Exit();
return false;
}
});
}
[Test]
public void TestExitingSongSelectWithEscape()
{
TestSongSelect songSelect = null;
2019-07-29 16:23:45 +08:00
AddStep("Push song select", () => osuGame.ScreenStack.Push(songSelect = new TestSongSelect()));
AddUntilStep("Wait for song select", () => songSelect.IsCurrentScreen());
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-29 16:23:45 +08:00
AddStep("Push song select", () => osuGame.ScreenStack.Push(songSelect = new TestSongSelect()));
AddUntilStep("Wait for song select", () => songSelect.IsCurrentScreen());
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()
{
Screens.Multi.Multiplayer multiplayer = null;
2019-07-29 16:23:45 +08:00
AddStep("Push multiplayer", () => osuGame.ScreenStack.Push(multiplayer = new Screens.Multi.Multiplayer()));
AddUntilStep("Wait for multiplayer", () => multiplayer.IsCurrentScreen());
exitViaEscapeAndConfirm();
}
[Test]
public void TestExitMultiWithBackButton()
{
Screens.Multi.Multiplayer multiplayer = null;
2019-07-29 16:23:45 +08:00
AddStep("Push multiplayer", () => osuGame.ScreenStack.Push(multiplayer = new Screens.Multi.Multiplayer()));
AddUntilStep("Wait for multiplayer", () => multiplayer.IsCurrentScreen());
exitViaBackButtonAndConfirm();
}
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;
}
}
}