1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 00:47:24 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneOsuHoverContainer.cs

195 lines
6.4 KiB
C#
Raw Normal View History

2019-06-07 10:45:58 +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.
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
2019-06-07 11:37:10 +08:00
using osu.Framework.Graphics.Shapes;
2019-06-07 10:45:58 +08:00
using osu.Game.Graphics.Containers;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual.UserInterface
{
[TestFixture]
public class TestSceneOsuHoverContainer : OsuManualInputManagerTestScene
2019-06-07 10:45:58 +08:00
{
private OsuHoverTestContainer hoverContainer;
2019-06-07 11:37:10 +08:00
private Box colourContainer;
2019-06-07 10:45:58 +08:00
[SetUp]
2019-06-07 10:59:07 +08:00
public void SetUp() => Schedule(() =>
2019-06-07 10:45:58 +08:00
{
Child = hoverContainer = new OsuHoverTestContainer
{
2019-06-07 11:42:01 +08:00
Enabled = { Value = true },
2019-06-07 10:45:58 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2019-06-07 11:37:10 +08:00
Size = new Vector2(100),
Child = colourContainer = new Box
2019-06-07 10:45:58 +08:00
{
2019-06-07 11:37:10 +08:00
RelativeSizeAxes = Axes.Both,
},
2019-06-07 10:45:58 +08:00
};
2019-06-07 11:42:01 +08:00
doMoveOut();
2019-06-07 10:59:07 +08:00
});
2019-06-07 10:45:58 +08:00
[Description("Checks IsHovered property value on a container when it is hovered/unhovered.")]
[TestCase(true, TestName = "Enabled_Check_IsHovered")]
[TestCase(false, TestName = "Disabled_Check_IsHovered")]
2019-06-07 10:59:07 +08:00
public void TestIsHoveredHasProperValue(bool isEnabled)
2019-06-07 10:45:58 +08:00
{
setContainerEnabledTo(isEnabled);
checkNotHovered();
moveToText();
checkHovered();
moveOut();
checkNotHovered();
moveToText();
checkHovered();
moveOut();
checkNotHovered();
}
[Test]
[Description("Checks colour fading on an enabled container when it is hovered/unhovered.")]
2019-06-07 10:59:07 +08:00
public void TestTransitionWhileEnabled()
2019-06-07 10:45:58 +08:00
{
enableContainer();
2019-06-07 10:59:07 +08:00
checkColour(OsuHoverTestContainer.IDLE_COLOUR);
2019-06-07 10:45:58 +08:00
moveToText();
2019-06-07 10:59:07 +08:00
waitUntilColourIs(OsuHoverTestContainer.HOVER_COLOUR);
2019-06-07 10:45:58 +08:00
moveOut();
2019-06-07 10:59:07 +08:00
waitUntilColourIs(OsuHoverTestContainer.IDLE_COLOUR);
2019-06-07 10:45:58 +08:00
moveToText();
2019-06-07 10:59:07 +08:00
waitUntilColourIs(OsuHoverTestContainer.HOVER_COLOUR);
2019-06-07 10:45:58 +08:00
moveOut();
2019-06-07 10:59:07 +08:00
waitUntilColourIs(OsuHoverTestContainer.IDLE_COLOUR);
2019-06-07 10:45:58 +08:00
}
[Test]
[Description("Checks colour fading on a disabled container when it is hovered/unhovered.")]
2019-06-07 10:59:07 +08:00
public void TestNoTransitionWhileDisabled()
2019-06-07 10:45:58 +08:00
{
disableContainer();
2019-06-07 10:59:07 +08:00
checkColour(OsuHoverTestContainer.IDLE_COLOUR);
2019-06-07 10:45:58 +08:00
moveToText();
2019-06-07 10:59:07 +08:00
checkColour(OsuHoverTestContainer.IDLE_COLOUR);
2019-06-07 10:45:58 +08:00
moveOut();
2019-06-07 10:59:07 +08:00
checkColour(OsuHoverTestContainer.IDLE_COLOUR);
2019-06-07 10:45:58 +08:00
moveToText();
2019-06-07 10:59:07 +08:00
checkColour(OsuHoverTestContainer.IDLE_COLOUR);
2019-06-07 10:45:58 +08:00
moveOut();
2019-06-07 10:59:07 +08:00
checkColour(OsuHoverTestContainer.IDLE_COLOUR);
2019-06-07 10:45:58 +08:00
}
[Test]
[Description("Checks that when a disabled & hovered container gets enabled, colour fading happens")]
2019-06-07 10:59:07 +08:00
public void TestBecomesEnabledTransition()
2019-06-07 10:45:58 +08:00
{
disableContainer();
2019-06-07 10:59:07 +08:00
checkColour(OsuHoverTestContainer.IDLE_COLOUR);
2019-06-07 10:45:58 +08:00
moveToText();
2019-06-07 10:59:07 +08:00
checkColour(OsuHoverTestContainer.IDLE_COLOUR);
2019-06-07 10:45:58 +08:00
enableContainer();
2019-06-07 10:59:07 +08:00
waitUntilColourIs(OsuHoverTestContainer.HOVER_COLOUR);
2019-06-07 10:45:58 +08:00
}
[Test]
[Description("Checks that when an enabled & hovered container gets disabled, colour fading happens")]
2019-06-07 10:59:07 +08:00
public void TestBecomesDisabledTransition()
2019-06-07 10:45:58 +08:00
{
enableContainer();
2019-06-07 10:59:07 +08:00
checkColour(OsuHoverTestContainer.IDLE_COLOUR);
2019-06-07 10:45:58 +08:00
moveToText();
2019-06-07 10:59:07 +08:00
waitUntilColourIs(OsuHoverTestContainer.HOVER_COLOUR);
2019-06-07 10:45:58 +08:00
disableContainer();
2019-06-07 10:59:07 +08:00
waitUntilColourIs(OsuHoverTestContainer.IDLE_COLOUR);
2019-06-07 10:45:58 +08:00
}
[Test]
[Description("Checks that when a hovered container gets enabled and disabled multiple times, colour fading happens")]
2019-06-07 10:59:07 +08:00
public void TestDisabledChangesMultipleTimes()
2019-06-07 10:45:58 +08:00
{
enableContainer();
2019-06-07 10:59:07 +08:00
checkColour(OsuHoverTestContainer.IDLE_COLOUR);
2019-06-07 10:45:58 +08:00
moveToText();
2019-06-07 10:59:07 +08:00
waitUntilColourIs(OsuHoverTestContainer.HOVER_COLOUR);
2019-06-07 10:45:58 +08:00
disableContainer();
2019-06-07 10:59:07 +08:00
waitUntilColourIs(OsuHoverTestContainer.IDLE_COLOUR);
2019-06-07 10:45:58 +08:00
enableContainer();
2019-06-07 10:59:07 +08:00
waitUntilColourIs(OsuHoverTestContainer.HOVER_COLOUR);
2019-06-07 10:45:58 +08:00
disableContainer();
2019-06-07 10:59:07 +08:00
waitUntilColourIs(OsuHoverTestContainer.IDLE_COLOUR);
2019-06-07 10:45:58 +08:00
}
private void enableContainer() => setContainerEnabledTo(true);
private void disableContainer() => setContainerEnabledTo(false);
private void setContainerEnabledTo(bool newValue)
{
string word = newValue ? "Enable" : "Disable";
AddStep($"{word} container", () => hoverContainer.Enabled.Value = newValue);
}
private void moveToText() => AddStep("Move mouse to text", () => InputManager.MoveMouseTo(hoverContainer));
private void moveOut() => AddStep("Move out", doMoveOut);
private void checkHovered() => AddAssert("Check hovered", () => hoverContainer.IsHovered);
private void checkNotHovered() => AddAssert("Check not hovered", () => !hoverContainer.IsHovered);
private void checkColour(ColourInfo expectedColour)
=> AddAssert($"Check colour to be '{expectedColour}'", () => currentColour.Equals(expectedColour));
private void waitUntilColourIs(ColourInfo expectedColour)
=> AddUntilStep($"Wait until hover colour is {expectedColour}", () => currentColour.Equals(expectedColour));
2019-06-07 11:37:10 +08:00
private ColourInfo currentColour => colourContainer.DrawColourInfo.Colour;
2019-06-07 10:45:58 +08:00
/// <summary>
/// Moves the cursor to top left corner of the screen
/// </summary>
private void doMoveOut()
=> InputManager.MoveMouseTo(new Vector2(InputManager.ScreenSpaceDrawQuad.TopLeft.X, InputManager.ScreenSpaceDrawQuad.TopLeft.Y));
private sealed class OsuHoverTestContainer : OsuHoverContainer
{
2019-06-07 10:59:07 +08:00
public static readonly Color4 HOVER_COLOUR = Color4.Red;
public static readonly Color4 IDLE_COLOUR = Color4.Green;
public OsuHoverTestContainer()
{
HoverColour = HOVER_COLOUR;
IdleColour = IDLE_COLOUR;
}
2019-06-07 10:45:58 +08:00
}
}
}