mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 03:25:11 +08:00
Merge pull request #17950 from Susko3/ButtonSystem-keys
Allow any key to trigger the osu! cookie in the initial state
This commit is contained in:
commit
d0fee3c212
@ -0,0 +1,46 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Screens.Menu;
|
||||||
|
using osu.Game.Screens.Select;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Navigation
|
||||||
|
{
|
||||||
|
public class TestSceneButtonSystemNavigation : OsuGameTestScene
|
||||||
|
{
|
||||||
|
private ButtonSystem buttons => ((MainMenu)Game.ScreenStack.CurrentScreen).ChildrenOfType<ButtonSystem>().Single();
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestGlobalActionHasPriority()
|
||||||
|
{
|
||||||
|
AddAssert("state is initial", () => buttons.State == ButtonSystemState.Initial);
|
||||||
|
|
||||||
|
// triggering the cookie in the initial state with any key should only happen if no other action is bound to that key.
|
||||||
|
// here, F10 is bound to GlobalAction.ToggleGameplayMouseButtons.
|
||||||
|
AddStep("press F10", () => InputManager.Key(Key.F10));
|
||||||
|
AddAssert("state is initial", () => buttons.State == ButtonSystemState.Initial);
|
||||||
|
|
||||||
|
AddStep("press P", () => InputManager.Key(Key.P));
|
||||||
|
AddAssert("state is top level", () => buttons.State == ButtonSystemState.TopLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestShortcutKeys()
|
||||||
|
{
|
||||||
|
AddAssert("state is initial", () => buttons.State == ButtonSystemState.Initial);
|
||||||
|
|
||||||
|
AddStep("press P", () => InputManager.Key(Key.P));
|
||||||
|
AddAssert("state is top level", () => buttons.State == ButtonSystemState.TopLevel);
|
||||||
|
|
||||||
|
AddStep("press P", () => InputManager.Key(Key.P));
|
||||||
|
AddAssert("state is play", () => buttons.State == ButtonSystemState.Play);
|
||||||
|
|
||||||
|
AddStep("press P", () => InputManager.Key(Key.P));
|
||||||
|
AddAssert("entered song select", () => Game.ScreenStack.CurrentScreen is PlaySongSelect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,11 +10,12 @@ using osu.Framework.Graphics.Shapes;
|
|||||||
using osu.Game.Screens.Menu;
|
using osu.Game.Screens.Menu;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestSceneButtonSystem : OsuTestScene
|
public class TestSceneButtonSystem : OsuManualInputManagerTestScene
|
||||||
{
|
{
|
||||||
private OsuLogo logo;
|
private OsuLogo logo;
|
||||||
private ButtonSystem buttons;
|
private ButtonSystem buttons;
|
||||||
@ -64,6 +65,66 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
AddStep("Enter mode", performEnterMode);
|
AddStep("Enter mode", performEnterMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestCase(Key.P, true)]
|
||||||
|
[TestCase(Key.M, true)]
|
||||||
|
[TestCase(Key.L, true)]
|
||||||
|
[TestCase(Key.E, false)]
|
||||||
|
[TestCase(Key.D, false)]
|
||||||
|
[TestCase(Key.Q, false)]
|
||||||
|
[TestCase(Key.O, false)]
|
||||||
|
public void TestShortcutKeys(Key key, bool entersPlay)
|
||||||
|
{
|
||||||
|
int activationCount = -1;
|
||||||
|
AddStep("set up action", () =>
|
||||||
|
{
|
||||||
|
activationCount = 0;
|
||||||
|
void action() => activationCount++;
|
||||||
|
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case Key.P:
|
||||||
|
buttons.OnSolo = action;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.M:
|
||||||
|
buttons.OnMultiplayer = action;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.L:
|
||||||
|
buttons.OnPlaylists = action;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.E:
|
||||||
|
buttons.OnEdit = action;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D:
|
||||||
|
buttons.OnBeatmapListing = action;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.Q:
|
||||||
|
buttons.OnExit = action;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.O:
|
||||||
|
buttons.OnSettings = action;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep($"press {key}", () => InputManager.Key(key));
|
||||||
|
AddAssert("state is top level", () => buttons.State == ButtonSystemState.TopLevel);
|
||||||
|
|
||||||
|
if (entersPlay)
|
||||||
|
{
|
||||||
|
AddStep("press P", () => InputManager.Key(Key.P));
|
||||||
|
AddAssert("state is play", () => buttons.State == ButtonSystemState.Play);
|
||||||
|
}
|
||||||
|
|
||||||
|
AddStep($"press {key}", () => InputManager.Key(key));
|
||||||
|
AddAssert("action triggered", () => activationCount == 1);
|
||||||
|
}
|
||||||
|
|
||||||
private void performEnterMode()
|
private void performEnterMode()
|
||||||
{
|
{
|
||||||
buttons.State = ButtonSystemState.EnteringMode;
|
buttons.State = ButtonSystemState.EnteringMode;
|
||||||
|
@ -195,13 +195,10 @@ namespace osu.Game.Screens.Menu
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (State == ButtonSystemState.Initial)
|
if (State == ButtonSystemState.Initial)
|
||||||
{
|
|
||||||
if (buttonsTopLevel.Any(b => e.Key == b.TriggerKey))
|
|
||||||
{
|
{
|
||||||
logo?.TriggerClick();
|
logo?.TriggerClick();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return base.OnKeyDown(e);
|
return base.OnKeyDown(e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user