2019-01-24 08:43:03 +00: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.
|
2018-04-28 16:24:49 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-04-28 16:24:49 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2022-01-28 05:48:17 +00:00
|
|
|
|
using osu.Framework.Testing;
|
2018-04-28 16:24:49 +00:00
|
|
|
|
using osu.Game.Screens.Play.HUD;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Input;
|
2018-04-28 16:24:49 +00:00
|
|
|
|
|
2019-03-24 16:02:36 +00:00
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
2018-04-28 16:24:49 +00:00
|
|
|
|
{
|
|
|
|
|
[Description("'Hold to Quit' UI element")]
|
2020-03-23 01:01:33 +00:00
|
|
|
|
public partial class TestSceneHoldForMenuButton : OsuManualInputManagerTestScene
|
2018-04-28 16:24:49 +00:00
|
|
|
|
{
|
|
|
|
|
private bool exitAction;
|
|
|
|
|
|
2019-08-16 04:21:28 +00:00
|
|
|
|
protected override double TimePerAction => 100; // required for the early exit test, since hold-to-confirm delay is 200ms
|
|
|
|
|
|
2022-01-28 05:48:17 +00:00
|
|
|
|
private HoldForMenuButton holdForMenuButton;
|
2018-05-21 16:44:06 +00:00
|
|
|
|
|
2022-01-28 05:48:17 +00:00
|
|
|
|
[SetUpSteps]
|
|
|
|
|
public void SetUpSteps()
|
|
|
|
|
{
|
|
|
|
|
AddStep("create button", () =>
|
2018-04-28 16:24:49 +00:00
|
|
|
|
{
|
2022-01-28 05:48:17 +00:00
|
|
|
|
exitAction = false;
|
2018-04-28 16:24:49 +00:00
|
|
|
|
|
2022-01-28 05:48:17 +00:00
|
|
|
|
Child = holdForMenuButton = new HoldForMenuButton
|
|
|
|
|
{
|
|
|
|
|
Scale = new Vector2(2),
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Action = () => exitAction = true
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-05-03 21:01:00 +00:00
|
|
|
|
|
2022-01-28 05:48:17 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestMovementAndTrigger()
|
|
|
|
|
{
|
2018-11-06 16:47:02 +00:00
|
|
|
|
AddStep("Trigger text fade in", () => InputManager.MoveMouseTo(holdForMenuButton));
|
2022-01-28 05:48:17 +00:00
|
|
|
|
AddUntilStep("Text visible", () => getSpriteText().IsPresent && !exitAction);
|
2018-05-21 16:44:06 +00:00
|
|
|
|
AddStep("Trigger text fade out", () => InputManager.MoveMouseTo(Vector2.One));
|
2022-01-28 05:48:17 +00:00
|
|
|
|
AddUntilStep("Text is not visible", () => !getSpriteText().IsPresent && !exitAction);
|
2018-04-28 16:24:49 +00:00
|
|
|
|
|
|
|
|
|
AddStep("Trigger exit action", () =>
|
|
|
|
|
{
|
2018-11-06 16:47:02 +00:00
|
|
|
|
InputManager.MoveMouseTo(holdForMenuButton);
|
2018-05-25 10:08:46 +00:00
|
|
|
|
InputManager.PressButton(MouseButton.Left);
|
2018-04-28 16:24:49 +00:00
|
|
|
|
});
|
|
|
|
|
|
2018-05-25 10:08:46 +00:00
|
|
|
|
AddStep("Early release", () => InputManager.ReleaseButton(MouseButton.Left));
|
2018-05-21 16:44:06 +00:00
|
|
|
|
AddAssert("action not triggered", () => !exitAction);
|
|
|
|
|
|
2018-05-25 10:08:46 +00:00
|
|
|
|
AddStep("Trigger exit action", () => InputManager.PressButton(MouseButton.Left));
|
2019-03-19 08:24:26 +00:00
|
|
|
|
AddUntilStep($"{nameof(holdForMenuButton.Action)} was triggered", () => exitAction);
|
2022-01-28 05:48:17 +00:00
|
|
|
|
AddStep("Release", () => InputManager.ReleaseButton(MouseButton.Left));
|
2018-04-28 16:24:49 +00:00
|
|
|
|
}
|
2022-01-28 05:48:34 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestFadeOnNoInput()
|
|
|
|
|
{
|
|
|
|
|
AddStep("move mouse away", () => InputManager.MoveMouseTo(Vector2.One));
|
|
|
|
|
AddUntilStep("wait for text fade out", () => !getSpriteText().IsPresent);
|
|
|
|
|
AddUntilStep("wait for button fade out", () => holdForMenuButton.Alpha < 0.1f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SpriteText getSpriteText() => holdForMenuButton.Children.OfType<SpriteText>().First();
|
2018-04-28 16:24:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|