1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 23:47:25 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneButtonSystem.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

145 lines
4.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.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
using System;
using System.Linq;
2018-03-02 14:34:31 +08:00
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Shapes;
using osu.Game.Screens.Menu;
2019-07-04 16:06:28 +08:00
using osuTK;
2018-11-20 15:51:59 +08:00
using osuTK.Graphics;
2022-04-24 00:44:50 +08:00
using osuTK.Input;
2018-04-13 17:19:50 +08:00
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.UserInterface
{
2018-03-02 14:34:31 +08:00
[TestFixture]
2022-04-24 00:44:50 +08:00
public partial class TestSceneButtonSystem : OsuManualInputManagerTestScene
{
2019-07-05 10:29:47 +08:00
private OsuLogo logo;
private ButtonSystem buttons;
2018-04-13 17:19:50 +08:00
2019-07-05 10:29:47 +08:00
[SetUp]
public void SetUp() => Schedule(() =>
{
Children = new Drawable[]
{
new Box
{
Colour = ColourInfo.GradientVertical(Color4.Gray, Color4.WhiteSmoke),
RelativeSizeAxes = Axes.Both,
},
buttons = new ButtonSystem(),
2019-07-05 10:29:47 +08:00
logo = new OsuLogo
{
RelativePositionAxes = Axes.Both,
Position = new Vector2(0.5f)
}
};
2018-04-13 17:19:50 +08:00
buttons.SetOsuLogo(logo);
2019-07-05 10:29:47 +08:00
});
2019-07-05 10:29:47 +08:00
[Test]
public void TestAllStates()
{
foreach (var s in Enum.GetValues(typeof(ButtonSystemState)).OfType<ButtonSystemState>().Skip(1))
2019-07-04 16:05:29 +08:00
AddStep($"State to {s}", () => buttons.State = s);
2019-07-05 12:10:59 +08:00
AddStep("Enter mode", performEnterMode);
2019-07-05 10:29:47 +08:00
AddStep("Return to menu", () =>
2019-07-04 16:05:29 +08:00
{
buttons.State = ButtonSystemState.Play;
buttons.FadeIn(MainMenu.FADE_IN_DURATION, Easing.OutQuint);
buttons.MoveTo(new Vector2(0), MainMenu.FADE_IN_DURATION, Easing.OutQuint);
2019-07-04 16:05:29 +08:00
logo.FadeColour(Color4.White, 100, Easing.OutQuint);
logo.FadeIn(100, Easing.OutQuint);
});
}
2019-07-05 10:29:47 +08:00
[Test]
public void TestSmoothExit()
{
2019-07-05 12:10:59 +08:00
AddStep("Enter mode", performEnterMode);
}
2023-11-24 10:28:06 +08:00
[TestCase(Key.P, Key.P)]
[TestCase(Key.M, Key.P)]
[TestCase(Key.L, Key.P)]
[TestCase(Key.B, Key.E)]
[TestCase(Key.S, Key.E)]
[TestCase(Key.D, null)]
[TestCase(Key.Q, null)]
[TestCase(Key.O, null)]
public void TestShortcutKeys(Key key, Key? subMenuEnterKey)
2022-04-24 00:44:50 +08:00
{
int activationCount = -1;
AddStep("set up action", () =>
{
activationCount = 0;
void action() => activationCount++;
switch (key)
{
case Key.P:
buttons.OnSolo = action;
break;
case Key.M:
buttons.OnMultiplayer = action;
break;
case Key.L:
buttons.OnPlaylists = action;
break;
2023-11-24 10:28:06 +08:00
case Key.B:
2023-11-24 09:56:59 +08:00
buttons.OnEditBeatmap = action;
2022-04-24 00:44:50 +08:00
break;
2023-11-24 10:28:06 +08:00
case Key.S:
buttons.OnEditSkin = action;
break;
2022-04-24 00:44:50 +08:00
case Key.D:
buttons.OnBeatmapListing = action;
break;
case Key.Q:
buttons.OnExit = action;
break;
case Key.O:
buttons.OnSettings = action;
break;
}
});
AddStep($"press {key}", () => InputManager.Key(key));
AddAssert("state is top level", () => buttons.State == ButtonSystemState.TopLevel);
2023-11-24 10:28:06 +08:00
if (subMenuEnterKey != null)
2022-04-24 00:44:50 +08:00
{
2023-11-24 10:28:06 +08:00
AddStep($"press {subMenuEnterKey}", () => InputManager.Key(subMenuEnterKey.Value));
AddAssert("state is not top menu", () => buttons.State != ButtonSystemState.TopLevel);
2022-04-24 00:44:50 +08:00
}
AddStep($"press {key}", () => InputManager.Key(key));
AddAssert("action triggered", () => activationCount == 1);
}
2019-07-05 12:10:59 +08:00
private void performEnterMode()
{
buttons.State = ButtonSystemState.EnteringMode;
buttons.FadeOut(MainMenu.FADE_OUT_DURATION, Easing.InSine);
buttons.MoveTo(new Vector2(-800, 0), MainMenu.FADE_OUT_DURATION, Easing.InSine);
logo.FadeOut(300, Easing.InSine)
.ScaleTo(0.2f, 300, Easing.InSine);
2019-07-05 10:29:47 +08:00
}
}
}