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-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-03-24 11:09:18 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Logging;
|
2019-03-24 11:09:18 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Screens.Play;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2019-03-25 00:02:36 +08:00
|
|
|
|
using osuTK.Input;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-03-25 00:02:36 +08:00
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
[Description("player pause/fail screens")]
|
2019-05-15 03:37:25 +08:00
|
|
|
|
public class TestSceneGameplayMenuOverlay : ManualInputManagerTestScene
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-03-18 10:48:11 +08:00
|
|
|
|
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(FailOverlay), typeof(PauseOverlay) };
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private FailOverlay failOverlay;
|
2019-03-18 10:48:11 +08:00
|
|
|
|
private PauseOverlay pauseOverlay;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-03-24 11:09:18 +08:00
|
|
|
|
private GlobalActionContainer globalActionContainer;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2019-03-24 11:09:18 +08:00
|
|
|
|
private void load(OsuGameBase game)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-03-24 11:09:18 +08:00
|
|
|
|
Child = globalActionContainer = new GlobalActionContainer(game)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-03-24 11:09:18 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
pauseOverlay = new PauseOverlay
|
|
|
|
|
{
|
|
|
|
|
OnResume = () => Logger.Log(@"Resume"),
|
|
|
|
|
OnRetry = () => Logger.Log(@"Retry"),
|
|
|
|
|
OnQuit = () => Logger.Log(@"Quit"),
|
|
|
|
|
},
|
|
|
|
|
failOverlay = new FailOverlay
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
OnRetry = () => Logger.Log(@"Retry"),
|
|
|
|
|
OnQuit = () => Logger.Log(@"Quit"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
var retryCount = 0;
|
|
|
|
|
|
|
|
|
|
AddStep("Add retry", () =>
|
|
|
|
|
{
|
|
|
|
|
retryCount++;
|
|
|
|
|
pauseOverlay.Retries = failOverlay.Retries = retryCount;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddToggleStep("Toggle pause overlay", t => pauseOverlay.ToggleVisibility());
|
|
|
|
|
AddToggleStep("Toggle fail overlay", t => failOverlay.ToggleVisibility());
|
|
|
|
|
|
|
|
|
|
testHideResets();
|
|
|
|
|
|
|
|
|
|
testEnterWithoutSelection();
|
|
|
|
|
testKeyUpFromInitial();
|
|
|
|
|
testKeyDownFromInitial();
|
|
|
|
|
testKeyUpWrapping();
|
|
|
|
|
testKeyDownWrapping();
|
|
|
|
|
|
|
|
|
|
testMouseSelectionAfterKeySelection();
|
|
|
|
|
testKeySelectionAfterMouseSelection();
|
|
|
|
|
|
|
|
|
|
testMouseDeselectionResets();
|
|
|
|
|
|
|
|
|
|
testClickSelection();
|
|
|
|
|
testEnterKeySelection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Test that hiding the overlay after hovering a button will reset the overlay to the initial state with no buttons selected.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testHideResets()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Show overlay", () => failOverlay.Show());
|
|
|
|
|
|
2018-09-18 16:48:37 +08:00
|
|
|
|
AddStep("Hover first button", () => InputManager.MoveMouseTo(failOverlay.Buttons.First()));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
AddStep("Hide overlay", () => failOverlay.Hide());
|
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
AddAssert("Overlay state is reset", () => !failOverlay.Buttons.Any(b => b.Selected.Value));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that pressing enter after an overlay shows doesn't trigger an event because a selection hasn't occurred.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testEnterWithoutSelection()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Show overlay", () => pauseOverlay.Show());
|
|
|
|
|
|
2019-03-24 11:09:18 +08:00
|
|
|
|
AddStep("Press select", () => press(GlobalAction.Select));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
AddAssert("Overlay still open", () => pauseOverlay.State == Visibility.Visible);
|
|
|
|
|
|
|
|
|
|
AddStep("Hide overlay", () => pauseOverlay.Hide());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that pressing the up arrow from the initial state selects the last button.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testKeyUpFromInitial()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Show overlay", () => pauseOverlay.Show());
|
|
|
|
|
|
2018-09-18 16:48:37 +08:00
|
|
|
|
AddStep("Up arrow", () => press(Key.Up));
|
2019-02-21 17:56:34 +08:00
|
|
|
|
AddAssert("Last button selected", () => pauseOverlay.Buttons.Last().Selected.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
AddStep("Hide overlay", () => pauseOverlay.Hide());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that pressing the down arrow from the initial state selects the first button.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testKeyDownFromInitial()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Show overlay", () => pauseOverlay.Show());
|
|
|
|
|
|
2018-09-18 16:48:37 +08:00
|
|
|
|
AddStep("Down arrow", () => press(Key.Down));
|
2019-02-21 17:56:34 +08:00
|
|
|
|
AddAssert("First button selected", () => pauseOverlay.Buttons.First().Selected.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
AddStep("Hide overlay", () => pauseOverlay.Hide());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that pressing the up arrow repeatedly causes the selected button to wrap correctly.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testKeyUpWrapping()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Show overlay", () => failOverlay.Show());
|
|
|
|
|
|
2018-09-18 16:48:37 +08:00
|
|
|
|
AddStep("Up arrow", () => press(Key.Up));
|
2019-02-21 17:56:34 +08:00
|
|
|
|
AddAssert("Last button selected", () => failOverlay.Buttons.Last().Selected.Value);
|
2018-09-18 16:48:37 +08:00
|
|
|
|
AddStep("Up arrow", () => press(Key.Up));
|
2019-02-21 17:56:34 +08:00
|
|
|
|
AddAssert("First button selected", () => failOverlay.Buttons.First().Selected.Value);
|
2018-09-18 16:48:37 +08:00
|
|
|
|
AddStep("Up arrow", () => press(Key.Up));
|
2019-02-21 17:56:34 +08:00
|
|
|
|
AddAssert("Last button selected", () => failOverlay.Buttons.Last().Selected.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
AddStep("Hide overlay", () => failOverlay.Hide());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that pressing the down arrow repeatedly causes the selected button to wrap correctly.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testKeyDownWrapping()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Show overlay", () => failOverlay.Show());
|
|
|
|
|
|
2018-09-18 16:48:37 +08:00
|
|
|
|
AddStep("Down arrow", () => press(Key.Down));
|
2019-02-21 17:56:34 +08:00
|
|
|
|
AddAssert("First button selected", () => failOverlay.Buttons.First().Selected.Value);
|
2018-09-18 16:48:37 +08:00
|
|
|
|
AddStep("Down arrow", () => press(Key.Down));
|
2019-02-21 17:56:34 +08:00
|
|
|
|
AddAssert("Last button selected", () => failOverlay.Buttons.Last().Selected.Value);
|
2018-09-18 16:48:37 +08:00
|
|
|
|
AddStep("Down arrow", () => press(Key.Down));
|
2019-02-21 17:56:34 +08:00
|
|
|
|
AddAssert("First button selected", () => failOverlay.Buttons.First().Selected.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
AddStep("Hide overlay", () => failOverlay.Hide());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that hovering a button that was previously selected with the keyboard correctly selects the new button and deselects the previous button.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testMouseSelectionAfterKeySelection()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Show overlay", () => pauseOverlay.Show());
|
|
|
|
|
|
|
|
|
|
var secondButton = pauseOverlay.Buttons.Skip(1).First();
|
|
|
|
|
|
2018-09-18 16:48:37 +08:00
|
|
|
|
AddStep("Down arrow", () => press(Key.Down));
|
|
|
|
|
AddStep("Hover second button", () => InputManager.MoveMouseTo(secondButton));
|
2019-02-21 17:56:34 +08:00
|
|
|
|
AddAssert("First button not selected", () => !pauseOverlay.Buttons.First().Selected.Value);
|
|
|
|
|
AddAssert("Second button selected", () => secondButton.Selected.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
AddStep("Hide overlay", () => pauseOverlay.Hide());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
|
private void testKeySelectionAfterMouseSelection()
|
|
|
|
|
{
|
2018-09-18 16:48:37 +08:00
|
|
|
|
AddStep("Show overlay", () =>
|
|
|
|
|
{
|
|
|
|
|
pauseOverlay.Show();
|
|
|
|
|
InputManager.MoveMouseTo(Vector2.Zero);
|
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
var secondButton = pauseOverlay.Buttons.Skip(1).First();
|
|
|
|
|
|
2018-09-18 16:48:37 +08:00
|
|
|
|
AddStep("Hover second button", () => InputManager.MoveMouseTo(secondButton));
|
|
|
|
|
AddStep("Up arrow", () => press(Key.Up));
|
2019-02-21 17:56:34 +08:00
|
|
|
|
AddAssert("Second button not selected", () => !secondButton.Selected.Value);
|
|
|
|
|
AddAssert("First button selected", () => pauseOverlay.Buttons.First().Selected.Value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
AddStep("Hide overlay", () => pauseOverlay.Hide());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that deselecting with the mouse by losing hover will reset the overlay to the initial state.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testMouseDeselectionResets()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Show overlay", () => pauseOverlay.Show());
|
|
|
|
|
|
|
|
|
|
var secondButton = pauseOverlay.Buttons.Skip(1).First();
|
|
|
|
|
|
2018-09-18 16:48:37 +08:00
|
|
|
|
AddStep("Hover second button", () => InputManager.MoveMouseTo(secondButton));
|
|
|
|
|
AddStep("Unhover second button", () => InputManager.MoveMouseTo(Vector2.Zero));
|
|
|
|
|
AddStep("Down arrow", () => press(Key.Down));
|
2019-02-21 17:56:34 +08:00
|
|
|
|
AddAssert("First button selected", () => pauseOverlay.Buttons.First().Selected.Value); // Initial state condition
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
AddStep("Hide overlay", () => pauseOverlay.Hide());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that clicking on a button correctly causes a click event for that button.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testClickSelection()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Show overlay", () => pauseOverlay.Show());
|
|
|
|
|
|
|
|
|
|
var retryButton = pauseOverlay.Buttons.Skip(1).First();
|
|
|
|
|
|
|
|
|
|
bool triggered = false;
|
|
|
|
|
AddStep("Click retry button", () =>
|
|
|
|
|
{
|
|
|
|
|
var lastAction = pauseOverlay.OnRetry;
|
|
|
|
|
pauseOverlay.OnRetry = () => triggered = true;
|
|
|
|
|
|
2018-09-18 17:05:25 +08:00
|
|
|
|
retryButton.Click();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
pauseOverlay.OnRetry = lastAction;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddAssert("Action was triggered", () => triggered);
|
|
|
|
|
AddAssert("Overlay is closed", () => pauseOverlay.State == Visibility.Hidden);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that pressing the enter key with a button selected correctly causes a click event for that button.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testEnterKeySelection()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Show overlay", () => pauseOverlay.Show());
|
|
|
|
|
|
|
|
|
|
AddStep("Select second button", () =>
|
|
|
|
|
{
|
2018-09-18 16:48:37 +08:00
|
|
|
|
press(Key.Down);
|
|
|
|
|
press(Key.Down);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
bool triggered = false;
|
2018-09-18 16:48:37 +08:00
|
|
|
|
Action lastAction = null;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
AddStep("Press enter", () =>
|
|
|
|
|
{
|
2018-09-18 16:48:37 +08:00
|
|
|
|
lastAction = pauseOverlay.OnRetry;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
pauseOverlay.OnRetry = () => triggered = true;
|
2018-09-18 16:48:37 +08:00
|
|
|
|
press(Key.Enter);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
});
|
|
|
|
|
|
2018-09-18 16:48:37 +08:00
|
|
|
|
AddAssert("Action was triggered", () =>
|
|
|
|
|
{
|
|
|
|
|
if (lastAction != null)
|
|
|
|
|
{
|
|
|
|
|
pauseOverlay.OnRetry = lastAction;
|
|
|
|
|
lastAction = null;
|
|
|
|
|
}
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-09-18 16:48:37 +08:00
|
|
|
|
return triggered;
|
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
AddAssert("Overlay is closed", () => pauseOverlay.State == Visibility.Hidden);
|
|
|
|
|
}
|
2019-03-24 11:09:18 +08: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 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|