2018-04-28 16:24:49 +00:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NUnit.Framework;
|
2018-05-21 16:44:06 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-04-28 16:24:49 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Screens.Play.HUD;
|
2018-05-21 16:44:06 +00:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Input;
|
2018-04-28 16:24:49 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
|
{
|
|
|
|
|
[Description("'Hold to Quit' UI element")]
|
2018-05-21 16:44:06 +00:00
|
|
|
|
public class TestCaseQuitButton : ManualInputManagerTestCase
|
2018-04-28 16:24:49 +00:00
|
|
|
|
{
|
|
|
|
|
private bool exitAction;
|
|
|
|
|
|
2018-05-21 16:44:06 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2018-04-28 16:24:49 +00:00
|
|
|
|
{
|
2018-05-21 16:44:06 +00:00
|
|
|
|
QuitButton quitButton;
|
|
|
|
|
|
2018-05-03 21:01:00 +00:00
|
|
|
|
Add(quitButton = new QuitButton
|
2018-04-28 16:24:49 +00:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
|
Anchor = Anchor.BottomRight,
|
2018-05-21 16:44:06 +00:00
|
|
|
|
Action = () => exitAction = true
|
2018-04-28 16:24:49 +00:00
|
|
|
|
});
|
|
|
|
|
|
2018-05-21 16:44:06 +00:00
|
|
|
|
var text = quitButton.Children.OfType<SpriteText>().First();
|
2018-05-03 21:01:00 +00:00
|
|
|
|
|
2018-05-21 16:44:06 +00:00
|
|
|
|
AddStep("Trigger text fade in", () => InputManager.MoveMouseTo(quitButton));
|
2018-04-28 16:24:49 +00:00
|
|
|
|
AddUntilStep(() => text.IsPresent && !exitAction, "Text visible");
|
2018-05-21 16:44:06 +00:00
|
|
|
|
AddStep("Trigger text fade out", () => InputManager.MoveMouseTo(Vector2.One));
|
2018-04-28 16:24:49 +00:00
|
|
|
|
AddUntilStep(() => !text.IsPresent && !exitAction, "Text is not visible");
|
|
|
|
|
|
|
|
|
|
AddStep("Trigger exit action", () =>
|
|
|
|
|
{
|
|
|
|
|
exitAction = false;
|
2018-05-21 16:44:06 +00:00
|
|
|
|
InputManager.MoveMouseTo(quitButton);
|
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));
|
2018-05-21 16:44:06 +00:00
|
|
|
|
AddUntilStep(() => exitAction, $"{nameof(quitButton.Action)} was triggered");
|
2018-04-28 16:24:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|