2019-01-24 16:43:03 +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.
|
2018-04-29 00:24:49 +08:00
|
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NUnit.Framework;
|
2018-05-22 00:44:06 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-04-29 00:24:49 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Screens.Play.HUD;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Input;
|
2018-04-29 00:24:49 +08:00
|
|
|
|
|
2019-03-25 00:02:36 +08:00
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
2018-04-29 00:24:49 +08:00
|
|
|
|
{
|
|
|
|
|
[Description("'Hold to Quit' UI element")]
|
2019-05-15 03:37:25 +08:00
|
|
|
|
public class TestSceneHoldForMenuButton : ManualInputManagerTestScene
|
2018-04-29 00:24:49 +08:00
|
|
|
|
{
|
|
|
|
|
private bool exitAction;
|
|
|
|
|
|
2019-08-16 12:21:28 +08:00
|
|
|
|
protected override double TimePerAction => 100; // required for the early exit test, since hold-to-confirm delay is 200ms
|
|
|
|
|
|
2018-05-22 00:44:06 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2018-04-29 00:24:49 +08:00
|
|
|
|
{
|
2018-11-07 00:47:02 +08:00
|
|
|
|
HoldForMenuButton holdForMenuButton;
|
2018-05-22 00:44:06 +08:00
|
|
|
|
|
2018-11-07 00:47:02 +08:00
|
|
|
|
Add(holdForMenuButton = new HoldForMenuButton
|
2018-04-29 00:24:49 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
|
Anchor = Anchor.BottomRight,
|
2018-05-22 00:44:06 +08:00
|
|
|
|
Action = () => exitAction = true
|
2018-04-29 00:24:49 +08:00
|
|
|
|
});
|
|
|
|
|
|
2018-11-07 00:47:02 +08:00
|
|
|
|
var text = holdForMenuButton.Children.OfType<SpriteText>().First();
|
2018-05-04 05:01:00 +08:00
|
|
|
|
|
2018-11-07 00:47:02 +08:00
|
|
|
|
AddStep("Trigger text fade in", () => InputManager.MoveMouseTo(holdForMenuButton));
|
2019-03-19 16:24:26 +08:00
|
|
|
|
AddUntilStep("Text visible", () => text.IsPresent && !exitAction);
|
2018-05-22 00:44:06 +08:00
|
|
|
|
AddStep("Trigger text fade out", () => InputManager.MoveMouseTo(Vector2.One));
|
2019-03-19 16:24:26 +08:00
|
|
|
|
AddUntilStep("Text is not visible", () => !text.IsPresent && !exitAction);
|
2018-04-29 00:24:49 +08:00
|
|
|
|
|
|
|
|
|
AddStep("Trigger exit action", () =>
|
|
|
|
|
{
|
|
|
|
|
exitAction = false;
|
2018-11-07 00:47:02 +08:00
|
|
|
|
InputManager.MoveMouseTo(holdForMenuButton);
|
2018-05-25 18:08:46 +08:00
|
|
|
|
InputManager.PressButton(MouseButton.Left);
|
2018-04-29 00:24:49 +08:00
|
|
|
|
});
|
|
|
|
|
|
2018-05-25 18:08:46 +08:00
|
|
|
|
AddStep("Early release", () => InputManager.ReleaseButton(MouseButton.Left));
|
2018-05-22 00:44:06 +08:00
|
|
|
|
AddAssert("action not triggered", () => !exitAction);
|
|
|
|
|
|
2018-05-25 18:08:46 +08:00
|
|
|
|
AddStep("Trigger exit action", () => InputManager.PressButton(MouseButton.Left));
|
2019-03-19 16:24:26 +08:00
|
|
|
|
AddUntilStep($"{nameof(holdForMenuButton.Action)} was triggered", () => exitAction);
|
2018-04-29 00:24:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|