mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 10:53:10 +08:00
Merge pull request #18011 from frenzibyte/rewind-shift-click
Allow rewinding random in song select with "Shift + Left Click"
This commit is contained in:
commit
5c04ab18ec
@ -1,35 +1,99 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using NUnit.Framework;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Screens.Select;
|
using osu.Game.Screens.Select;
|
||||||
|
using osuTK;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.SongSelect
|
namespace osu.Game.Tests.Visual.SongSelect
|
||||||
{
|
{
|
||||||
public class TestSceneSongSelectFooter : OsuManualInputManagerTestScene
|
public class TestSceneSongSelectFooter : OsuManualInputManagerTestScene
|
||||||
{
|
{
|
||||||
public TestSceneSongSelectFooter()
|
private FooterButtonRandom randomButton;
|
||||||
{
|
|
||||||
AddStep("Create footer", () =>
|
private bool nextRandomCalled;
|
||||||
|
private bool previousRandomCalled;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp() => Schedule(() =>
|
||||||
{
|
{
|
||||||
|
nextRandomCalled = false;
|
||||||
|
previousRandomCalled = false;
|
||||||
|
|
||||||
Footer footer;
|
Footer footer;
|
||||||
AddRange(new Drawable[]
|
|
||||||
{
|
Child = footer = new Footer
|
||||||
footer = new Footer
|
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
}
|
};
|
||||||
});
|
|
||||||
|
|
||||||
footer.AddButton(new FooterButtonMods(), null);
|
footer.AddButton(new FooterButtonMods(), null);
|
||||||
footer.AddButton(new FooterButtonRandom
|
footer.AddButton(randomButton = new FooterButtonRandom
|
||||||
{
|
{
|
||||||
NextRandom = () => { },
|
NextRandom = () => nextRandomCalled = true,
|
||||||
PreviousRandom = () => { },
|
PreviousRandom = () => previousRandomCalled = true,
|
||||||
}, null);
|
}, null);
|
||||||
footer.AddButton(new FooterButtonOptions(), null);
|
footer.AddButton(new FooterButtonOptions(), null);
|
||||||
|
|
||||||
|
InputManager.MoveMouseTo(Vector2.Zero);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestFooterRandom()
|
||||||
|
{
|
||||||
|
AddStep("press F2", () => InputManager.Key(Key.F2));
|
||||||
|
AddAssert("next random invoked", () => nextRandomCalled && !previousRandomCalled);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestFooterRandomViaMouse()
|
||||||
|
{
|
||||||
|
AddStep("click button", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(randomButton);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
AddAssert("next random invoked", () => nextRandomCalled && !previousRandomCalled);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestFooterRewind()
|
||||||
|
{
|
||||||
|
AddStep("press Shift+F2", () =>
|
||||||
|
{
|
||||||
|
InputManager.PressKey(Key.LShift);
|
||||||
|
InputManager.PressKey(Key.F2);
|
||||||
|
InputManager.ReleaseKey(Key.F2);
|
||||||
|
InputManager.ReleaseKey(Key.LShift);
|
||||||
|
});
|
||||||
|
AddAssert("previous random invoked", () => previousRandomCalled && !nextRandomCalled);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestFooterRewindViaShiftMouseLeft()
|
||||||
|
{
|
||||||
|
AddStep("shift + click button", () =>
|
||||||
|
{
|
||||||
|
InputManager.PressKey(Key.LShift);
|
||||||
|
InputManager.MoveMouseTo(randomButton);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
InputManager.ReleaseKey(Key.LShift);
|
||||||
|
});
|
||||||
|
AddAssert("previous random invoked", () => previousRandomCalled && !nextRandomCalled);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestFooterRewindViaMouseRight()
|
||||||
|
{
|
||||||
|
AddStep("right click button", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(randomButton);
|
||||||
|
InputManager.Click(MouseButton.Right);
|
||||||
|
});
|
||||||
|
AddAssert("previous random invoked", () => previousRandomCalled && !nextRandomCalled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ using osu.Game.Graphics;
|
|||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Select
|
namespace osu.Game.Screens.Select
|
||||||
{
|
{
|
||||||
@ -25,7 +26,7 @@ namespace osu.Game.Screens.Select
|
|||||||
{
|
{
|
||||||
SelectedColour = colours.Green;
|
SelectedColour = colours.Green;
|
||||||
DeselectedColour = SelectedColour.Opacity(0.5f);
|
DeselectedColour = SelectedColour.Opacity(0.5f);
|
||||||
Text = @"random";
|
updateText();
|
||||||
|
|
||||||
Action = () =>
|
Action = () =>
|
||||||
{
|
{
|
||||||
@ -59,6 +60,44 @@ namespace osu.Game.Screens.Select
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool OnKeyDown(KeyDownEvent e)
|
||||||
|
{
|
||||||
|
updateText(e.ShiftPressed);
|
||||||
|
return base.OnKeyDown(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnKeyUp(KeyUpEvent e)
|
||||||
|
{
|
||||||
|
updateText(e.ShiftPressed);
|
||||||
|
base.OnKeyUp(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnClick(ClickEvent e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// this uses OR to handle rewinding when clicks are triggered by other sources (i.e. right button in OnMouseUp).
|
||||||
|
rewindSearch |= e.ShiftPressed;
|
||||||
|
return base.OnClick(e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
rewindSearch = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseUp(MouseUpEvent e)
|
||||||
|
{
|
||||||
|
if (e.Button == MouseButton.Right)
|
||||||
|
{
|
||||||
|
rewindSearch = true;
|
||||||
|
TriggerClick();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.OnMouseUp(e);
|
||||||
|
}
|
||||||
|
|
||||||
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
||||||
{
|
{
|
||||||
rewindSearch = e.Action == GlobalAction.SelectPreviousRandom;
|
rewindSearch = e.Action == GlobalAction.SelectPreviousRandom;
|
||||||
@ -79,5 +118,7 @@ namespace osu.Game.Screens.Select
|
|||||||
rewindSearch = false;
|
rewindSearch = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateText(bool rewind = false) => Text = rewind ? "rewind" : "random";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user