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-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-09-04 01:34:56 +00:00
|
|
|
|
using NUnit.Framework;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-03-24 03:09:18 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Logging;
|
2019-09-04 02:36:09 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-03-24 03:09:18 +00:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Screens.Play;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2019-03-24 16:02:36 +00:00
|
|
|
|
using osuTK.Input;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-24 16:02:36 +00:00
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-09-05 07:31:10 +00:00
|
|
|
|
[Description("player pause/fail screens")]
|
2019-05-14 19:37:25 +00:00
|
|
|
|
public class TestSceneGameplayMenuOverlay : ManualInputManagerTestScene
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-03-18 02:48:11 +00:00
|
|
|
|
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(FailOverlay), typeof(PauseOverlay) };
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
private FailOverlay failOverlay;
|
2019-03-18 02:48:11 +00:00
|
|
|
|
private PauseOverlay pauseOverlay;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-24 03:09:18 +00:00
|
|
|
|
private GlobalActionContainer globalActionContainer;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2019-03-24 03:09:18 +00:00
|
|
|
|
private void load(OsuGameBase game)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-09-04 02:36:09 +00:00
|
|
|
|
Child = globalActionContainer = new GlobalActionContainer(game);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp() => Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
globalActionContainer.Children = new Drawable[]
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-09-04 02:36:09 +00:00
|
|
|
|
pauseOverlay = new PauseOverlay
|
|
|
|
|
{
|
|
|
|
|
OnResume = () => Logger.Log(@"Resume"),
|
|
|
|
|
OnRetry = () => Logger.Log(@"Retry"),
|
|
|
|
|
OnQuit = () => Logger.Log(@"Quit"),
|
|
|
|
|
},
|
|
|
|
|
failOverlay = new FailOverlay
|
|
|
|
|
|
2019-03-24 03:09:18 +00:00
|
|
|
|
{
|
2019-09-04 02:36:09 +00:00
|
|
|
|
OnRetry = () => Logger.Log(@"Retry"),
|
|
|
|
|
OnQuit = () => Logger.Log(@"Quit"),
|
2019-03-24 03:09:18 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-09-04 02:36:09 +00:00
|
|
|
|
InputManager.MoveMouseTo(Vector2.Zero);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestAdjustRetryCount()
|
|
|
|
|
{
|
|
|
|
|
showOverlay();
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
var retryCount = 0;
|
|
|
|
|
|
2019-09-04 02:36:09 +00:00
|
|
|
|
AddRepeatStep("Add retry", () =>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
retryCount++;
|
|
|
|
|
pauseOverlay.Retries = failOverlay.Retries = retryCount;
|
2019-09-04 02:36:09 +00:00
|
|
|
|
}, 10);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that pressing enter after an overlay shows doesn't trigger an event because a selection hasn't occurred.
|
|
|
|
|
/// </summary>
|
2019-09-04 01:34:56 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestEnterWithoutSelection()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-09-04 02:36:09 +00:00
|
|
|
|
showOverlay();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-24 03:09:18 +00:00
|
|
|
|
AddStep("Press select", () => press(GlobalAction.Select));
|
2019-06-11 05:28:52 +00:00
|
|
|
|
AddAssert("Overlay still open", () => pauseOverlay.State.Value == Visibility.Visible);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that pressing the up arrow from the initial state selects the last button.
|
|
|
|
|
/// </summary>
|
2019-09-04 01:34:56 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestKeyUpFromInitial()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-09-04 02:36:09 +00:00
|
|
|
|
showOverlay();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-18 08:48:37 +00:00
|
|
|
|
AddStep("Up arrow", () => press(Key.Up));
|
2019-02-21 09:56:34 +00:00
|
|
|
|
AddAssert("Last button selected", () => pauseOverlay.Buttons.Last().Selected.Value);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that pressing the down arrow from the initial state selects the first button.
|
|
|
|
|
/// </summary>
|
2019-09-04 01:34:56 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestKeyDownFromInitial()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-09-04 02:36:09 +00:00
|
|
|
|
showOverlay();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-18 08:48:37 +00:00
|
|
|
|
AddStep("Down arrow", () => press(Key.Down));
|
2019-09-04 02:36:09 +00:00
|
|
|
|
AddAssert("First button selected", () => getButton(0).Selected.Value);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that pressing the up arrow repeatedly causes the selected button to wrap correctly.
|
|
|
|
|
/// </summary>
|
2019-09-04 01:34:56 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestKeyUpWrapping()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
AddStep("Show overlay", () => failOverlay.Show());
|
|
|
|
|
|
2018-09-18 08:48:37 +00:00
|
|
|
|
AddStep("Up arrow", () => press(Key.Up));
|
2019-02-21 09:56:34 +00:00
|
|
|
|
AddAssert("Last button selected", () => failOverlay.Buttons.Last().Selected.Value);
|
2018-09-18 08:48:37 +00:00
|
|
|
|
AddStep("Up arrow", () => press(Key.Up));
|
2019-02-21 09:56:34 +00:00
|
|
|
|
AddAssert("First button selected", () => failOverlay.Buttons.First().Selected.Value);
|
2018-09-18 08:48:37 +00:00
|
|
|
|
AddStep("Up arrow", () => press(Key.Up));
|
2019-02-21 09:56:34 +00:00
|
|
|
|
AddAssert("Last button selected", () => failOverlay.Buttons.Last().Selected.Value);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that pressing the down arrow repeatedly causes the selected button to wrap correctly.
|
|
|
|
|
/// </summary>
|
2019-09-04 01:34:56 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestKeyDownWrapping()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
AddStep("Show overlay", () => failOverlay.Show());
|
|
|
|
|
|
2018-09-18 08:48:37 +00:00
|
|
|
|
AddStep("Down arrow", () => press(Key.Down));
|
2019-02-21 09:56:34 +00:00
|
|
|
|
AddAssert("First button selected", () => failOverlay.Buttons.First().Selected.Value);
|
2018-09-18 08:48:37 +00:00
|
|
|
|
AddStep("Down arrow", () => press(Key.Down));
|
2019-02-21 09:56:34 +00:00
|
|
|
|
AddAssert("Last button selected", () => failOverlay.Buttons.Last().Selected.Value);
|
2018-09-18 08:48:37 +00:00
|
|
|
|
AddStep("Down arrow", () => press(Key.Down));
|
2019-02-21 09:56:34 +00:00
|
|
|
|
AddAssert("First button selected", () => failOverlay.Buttons.First().Selected.Value);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-02 18:13:34 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Test that hiding the overlay after hovering a button will reset the overlay to the initial state with no buttons selected.
|
|
|
|
|
/// </summary>
|
2019-09-04 01:34:56 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestHideResets()
|
2019-09-02 18:13:34 +00:00
|
|
|
|
{
|
|
|
|
|
AddStep("Show overlay", () => failOverlay.Show());
|
|
|
|
|
|
|
|
|
|
AddStep("Hover first button", () => InputManager.MoveMouseTo(failOverlay.Buttons.First()));
|
|
|
|
|
AddStep("Hide overlay", () => failOverlay.Hide());
|
|
|
|
|
|
|
|
|
|
AddAssert("Overlay state is reset", () => !failOverlay.Buttons.Any(b => b.Selected.Value));
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 23:56:45 +00:00
|
|
|
|
/// <summary>
|
2019-09-05 07:31:10 +00:00
|
|
|
|
/// Tests that entering menu with cursor initially on button doesn't selects it immediately.
|
|
|
|
|
/// This is to allow for stable keyboard navigation.
|
2019-09-03 23:56:45 +00:00
|
|
|
|
/// </summary>
|
2019-09-04 01:34:56 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestInitialButtonHover()
|
2019-09-03 23:56:45 +00:00
|
|
|
|
{
|
2019-09-04 02:36:09 +00:00
|
|
|
|
showOverlay();
|
2019-09-03 23:56:45 +00:00
|
|
|
|
|
2019-09-04 02:36:09 +00:00
|
|
|
|
AddStep("Hover first button", () => InputManager.MoveMouseTo(getButton(0)));
|
2019-09-03 23:56:45 +00:00
|
|
|
|
|
|
|
|
|
AddStep("Hide overlay", () => pauseOverlay.Hide());
|
2019-09-04 02:36:09 +00:00
|
|
|
|
showOverlay();
|
2019-09-03 23:56:45 +00:00
|
|
|
|
|
2019-09-05 07:31:10 +00:00
|
|
|
|
AddAssert("First button not selected", () => !getButton(0).Selected.Value);
|
|
|
|
|
|
|
|
|
|
AddStep("Move slightly", () => InputManager.MoveMouseTo(InputManager.CurrentState.Mouse.Position + new Vector2(1)));
|
|
|
|
|
|
2019-09-04 02:36:09 +00:00
|
|
|
|
AddAssert("First button selected", () => getButton(0).Selected.Value);
|
2019-09-03 23:56:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that hovering a button that was previously selected with the keyboard correctly selects the new button and deselects the previous button.
|
|
|
|
|
/// </summary>
|
2019-09-04 01:34:56 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestMouseSelectionAfterKeySelection()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-09-04 02:36:09 +00:00
|
|
|
|
showOverlay();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-18 08:48:37 +00:00
|
|
|
|
AddStep("Down arrow", () => press(Key.Down));
|
2019-09-04 02:36:09 +00:00
|
|
|
|
AddStep("Hover second button", () => InputManager.MoveMouseTo(getButton(1)));
|
|
|
|
|
AddAssert("First button not selected", () => !getButton(0).Selected.Value);
|
|
|
|
|
AddAssert("Second button selected", () => getButton(1).Selected.Value);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that pressing a key after selecting a button with a hover event correctly selects a new button and deselects the previous button.
|
|
|
|
|
/// </summary>
|
2019-09-04 01:34:56 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestKeySelectionAfterMouseSelection()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-09-18 08:48:37 +00:00
|
|
|
|
AddStep("Show overlay", () =>
|
|
|
|
|
{
|
|
|
|
|
pauseOverlay.Show();
|
|
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-09-04 02:36:09 +00:00
|
|
|
|
AddStep("Hover second button", () => InputManager.MoveMouseTo(getButton(1)));
|
2018-09-18 08:48:37 +00:00
|
|
|
|
AddStep("Up arrow", () => press(Key.Up));
|
2019-09-04 02:36:09 +00:00
|
|
|
|
AddAssert("Second button not selected", () => !getButton(1).Selected.Value);
|
|
|
|
|
AddAssert("First button selected", () => getButton(0).Selected.Value);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that deselecting with the mouse by losing hover will reset the overlay to the initial state.
|
|
|
|
|
/// </summary>
|
2019-09-04 01:34:56 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestMouseDeselectionResets()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-09-04 02:36:09 +00:00
|
|
|
|
showOverlay();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-09-04 02:36:09 +00:00
|
|
|
|
AddStep("Hover second button", () => InputManager.MoveMouseTo(getButton(1)));
|
2018-09-18 08:48:37 +00:00
|
|
|
|
AddStep("Unhover second button", () => InputManager.MoveMouseTo(Vector2.Zero));
|
|
|
|
|
AddStep("Down arrow", () => press(Key.Down));
|
2019-09-04 02:36:09 +00:00
|
|
|
|
AddAssert("First button selected", () => getButton(0).Selected.Value); // Initial state condition
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that clicking on a button correctly causes a click event for that button.
|
|
|
|
|
/// </summary>
|
2019-09-04 01:34:56 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestClickSelection()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-09-04 02:36:09 +00:00
|
|
|
|
showOverlay();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
bool triggered = false;
|
|
|
|
|
AddStep("Click retry button", () =>
|
|
|
|
|
{
|
|
|
|
|
var lastAction = pauseOverlay.OnRetry;
|
|
|
|
|
pauseOverlay.OnRetry = () => triggered = true;
|
|
|
|
|
|
2019-09-04 02:36:09 +00:00
|
|
|
|
getButton(1).Click();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
pauseOverlay.OnRetry = lastAction;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddAssert("Action was triggered", () => triggered);
|
2019-06-11 05:28:52 +00:00
|
|
|
|
AddAssert("Overlay is closed", () => pauseOverlay.State.Value == Visibility.Hidden);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that pressing the enter key with a button selected correctly causes a click event for that button.
|
|
|
|
|
/// </summary>
|
2019-09-04 01:34:56 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestEnterKeySelection()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-09-04 02:36:09 +00:00
|
|
|
|
showOverlay();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
AddStep("Select second button", () =>
|
|
|
|
|
{
|
2018-09-18 08:48:37 +00:00
|
|
|
|
press(Key.Down);
|
|
|
|
|
press(Key.Down);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
bool triggered = false;
|
2018-09-18 08:48:37 +00:00
|
|
|
|
Action lastAction = null;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
AddStep("Press enter", () =>
|
|
|
|
|
{
|
2018-09-18 08:48:37 +00:00
|
|
|
|
lastAction = pauseOverlay.OnRetry;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
pauseOverlay.OnRetry = () => triggered = true;
|
2018-09-18 08:48:37 +00:00
|
|
|
|
press(Key.Enter);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
});
|
|
|
|
|
|
2018-09-18 08:48:37 +00:00
|
|
|
|
AddAssert("Action was triggered", () =>
|
|
|
|
|
{
|
|
|
|
|
if (lastAction != null)
|
|
|
|
|
{
|
|
|
|
|
pauseOverlay.OnRetry = lastAction;
|
|
|
|
|
lastAction = null;
|
|
|
|
|
}
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2018-09-18 08:48:37 +00:00
|
|
|
|
return triggered;
|
|
|
|
|
});
|
2019-06-11 05:28:52 +00:00
|
|
|
|
AddAssert("Overlay is closed", () => pauseOverlay.State.Value == Visibility.Hidden);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
2019-03-24 03:09:18 +00:00
|
|
|
|
|
2019-09-04 02:36:09 +00:00
|
|
|
|
private void showOverlay() => AddStep("Show overlay", () => pauseOverlay.Show());
|
|
|
|
|
|
|
|
|
|
private DialogButton getButton(int index) => pauseOverlay.Buttons.Skip(index).First();
|
|
|
|
|
|
2019-03-24 03:09:18 +00:00
|
|
|
|
private void press(Key key)
|
|
|
|
|
{
|
|
|
|
|
InputManager.PressKey(key);
|
|
|
|
|
InputManager.ReleaseKey(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void press(GlobalAction action)
|
|
|
|
|
{
|
|
|
|
|
globalActionContainer.TriggerPressed(action);
|
|
|
|
|
globalActionContainer.TriggerReleased(action);
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|