osu/osu.Game.Tests/Visual/UserInterface/TestSceneButtonSystem.cs

85 lines
2.6 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 09:19:50 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
2018-04-13 09:19:50 +00: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 08:06:28 +00:00
using osuTK;
2018-11-20 07:51:59 +00:00
using osuTK.Graphics;
2018-04-13 09:19:50 +00:00
2019-03-24 16:02:36 +00:00
namespace osu.Game.Tests.Visual.UserInterface
2018-04-13 09:19:50 +00:00
{
[TestFixture]
public class TestSceneButtonSystem : OsuTestScene
2018-04-13 09:19:50 +00:00
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(ButtonSystem),
typeof(ButtonArea),
typeof(Button)
};
2019-07-05 02:29:47 +00:00
private OsuLogo logo;
private ButtonSystem buttons;
2018-04-13 09:19:50 +00:00
2019-07-05 02:29:47 +00:00
[SetUp]
public void SetUp() => Schedule(() =>
{
2018-04-13 09:19:50 +00:00
Children = new Drawable[]
{
new Box
{
Colour = ColourInfo.GradientVertical(Color4.Gray, Color4.WhiteSmoke),
RelativeSizeAxes = Axes.Both,
},
buttons = new ButtonSystem(),
2019-07-05 02:29:47 +00:00
logo = new OsuLogo
{
RelativePositionAxes = Axes.Both,
Position = new Vector2(0.5f)
}
2018-04-13 09:19:50 +00:00
};
buttons.SetOsuLogo(logo);
2019-07-05 02:29:47 +00:00
});
2019-07-05 02:29:47 +00:00
[Test]
public void TestAllStates()
{
foreach (var s in Enum.GetValues(typeof(ButtonSystemState)).OfType<ButtonSystemState>().Skip(1))
2019-07-04 08:05:29 +00:00
AddStep($"State to {s}", () => buttons.State = s);
2019-07-05 04:10:59 +00:00
AddStep("Enter mode", performEnterMode);
2019-07-05 02:29:47 +00:00
AddStep("Return to menu", () =>
2019-07-04 08:05:29 +00: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 08:05:29 +00:00
logo.FadeColour(Color4.White, 100, Easing.OutQuint);
logo.FadeIn(100, Easing.OutQuint);
});
2018-04-13 09:19:50 +00:00
}
2019-07-05 02:29:47 +00:00
[Test]
public void TestSmoothExit()
{
2019-07-05 04:10:59 +00:00
AddStep("Enter mode", performEnterMode);
}
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 02:29:47 +00:00
}
2018-04-13 09:19:50 +00:00
}
}