Skip to content

Commit

Permalink
Allow right-clicking to rewind on random button
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzibyte committed Apr 29, 2022
1 parent a9d67d3 commit 856ca96
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
16 changes: 15 additions & 1 deletion osu.Game.Tests/Visual/SongSelect/TestSceneSongSelectFooter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Screens.Select;
using osuTK;
using osuTK.Input;

namespace osu.Game.Tests.Visual.SongSelect
Expand Down Expand Up @@ -36,6 +37,8 @@ public void SetUp() => Schedule(() =>
PreviousRandom = () => previousRandomCalled = true,
}, null);
footer.AddButton(new FooterButtonOptions(), null);

InputManager.MoveMouseTo(Vector2.Zero);
});

[Test]
Expand Down Expand Up @@ -70,7 +73,7 @@ public void TestFooterRewind()
}

[Test]
public void TestFooterRewindViaMouse()
public void TestFooterRewindViaShiftMouseLeft()
{
AddStep("shift + click button", () =>
{
Expand All @@ -81,5 +84,16 @@ public void TestFooterRewindViaMouse()
});
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);
}
}
}
21 changes: 18 additions & 3 deletions osu.Game/Screens/Select/FooterButtonRandom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using osu.Game.Graphics.Sprites;
using osu.Game.Input.Bindings;
using osuTK;
using osuTK.Input;

namespace osu.Game.Screens.Select
{
Expand Down Expand Up @@ -73,13 +74,27 @@ protected override void OnKeyUp(KeyUpEvent e)

protected override bool OnClick(ClickEvent e)
{
rewindSearch = e.ShiftPressed;
return base.OnClick(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)
{
rewindSearch = false;
if (e.Button == MouseButton.Right)
{
rewindSearch = true;
TriggerClick();
return;
}

base.OnMouseUp(e);
}

Expand Down

0 comments on commit 856ca96

Please sign in to comment.