Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix song select right click handling #31604

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions osu.Game.Tests/Visual/Navigation/TestSceneScreenNavigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
using osu.Game.Screens.Select.Leaderboards;
using osu.Game.Screens.Select.Options;
using osu.Game.Tests.Beatmaps.IO;
using osu.Game.Tests.Resources;
using osu.Game.Utils;
using osuTK;
using osuTK.Input;
Expand Down Expand Up @@ -202,6 +203,38 @@ public void TestSongSelectBackActionHandling()
TextBox filterControlTextBox() => songSelect.ChildrenOfType<FilterControl.FilterControlTextBox>().Single();
}

[Test]
public void TestSongSelectRandomRewindButton()
{
Guid? originalSelection = null;
TestPlaySongSelect songSelect = null;

PushAndConfirm(() => songSelect = new TestPlaySongSelect());
AddUntilStep("wait for song select", () => songSelect.BeatmapSetsLoaded);

AddStep("Add two beatmaps", () =>
{
Game.BeatmapManager.Import(TestResources.CreateTestBeatmapSetInfo(8));
Game.BeatmapManager.Import(TestResources.CreateTestBeatmapSetInfo(8));
});

AddUntilStep("wait for selected", () =>
{
originalSelection = Game.Beatmap.Value.BeatmapInfo.ID;
return !Game.Beatmap.IsDefault;
});

AddStep("hit random", () =>
{
InputManager.MoveMouseTo(Game.ChildrenOfType<FooterButtonRandom>().Single());
InputManager.Click(MouseButton.Left);
});
AddUntilStep("wait for selection changed", () => Game.Beatmap.Value.BeatmapInfo.ID, () => Is.Not.EqualTo(originalSelection));

AddStep("hit random rewind", () => InputManager.Click(MouseButton.Right));
AddUntilStep("wait for selection reverted", () => Game.Beatmap.Value.BeatmapInfo.ID, () => Is.EqualTo(originalSelection));
}

[Test]
public void TestSongSelectScrollHandling()
{
Expand Down
14 changes: 13 additions & 1 deletion osu.Game/Database/RealmAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ public class RealmAccess : IDisposable
/// 44 2024-11-22 Removed several properties from BeatmapInfo which did not need to be persisted to realm.
/// 45 2024-12-23 Change beat snap divisor adjust defaults to be Ctrl+Scroll instead of Ctrl+Shift+Scroll, if not already changed by user.
/// 46 2024-12-26 Change beat snap divisor bindings to match stable directionality ¯\_(ツ)_/¯.
/// 47 2025-01-21 Remove right mouse button binding for absolute scroll. Never use mouse buttons (or scroll) for global actions.
/// </summary>
private const int schema_version = 46;
private const int schema_version = 47;

/// <summary>
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking realm retrieval during blocking periods.
Expand Down Expand Up @@ -1239,6 +1240,17 @@ void remapKeyBinding(int oldAction, int newAction)

break;
}

case 47:
{
var keyBindings = migration.NewRealm.All<RealmKeyBinding>();

var existingBinding = keyBindings.FirstOrDefault(k => k.ActionInt == (int)GlobalAction.AbsoluteScrollSongList);
if (existingBinding != null && existingBinding.KeyCombination.Keys.SequenceEqual(new[] { InputKey.MouseRight }))
migration.NewRealm.Remove(existingBinding);

break;
}
}

Logger.Log($"Migration completed in {stopwatch.ElapsedMilliseconds}ms");
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Input/Bindings/GlobalActionContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public static IEnumerable<GlobalAction> GetGlobalActionsFor(GlobalActionCategory
new KeyBinding(InputKey.BackSpace, GlobalAction.DeselectAllMods),
new KeyBinding(new[] { InputKey.Control, InputKey.Up }, GlobalAction.IncreaseModSpeed),
new KeyBinding(new[] { InputKey.Control, InputKey.Down }, GlobalAction.DecreaseModSpeed),
new KeyBinding(new[] { InputKey.MouseRight }, GlobalAction.AbsoluteScrollSongList),
new KeyBinding(InputKey.None, GlobalAction.AbsoluteScrollSongList),
};

private static IEnumerable<KeyBinding> audioControlKeyBindings => new[]
Expand Down
40 changes: 31 additions & 9 deletions osu.Game/Screens/Select/BeatmapCarousel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,14 +1181,7 @@ public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
switch (e.Action)
{
case GlobalAction.AbsoluteScrollSongList:
// The default binding for absolute scroll is right mouse button.
// To avoid conflicts with context menus, disallow absolute scroll completely if it looks like things will fall over.
if (e.CurrentState.Mouse.Buttons.Contains(MouseButton.Right)
&& GetContainingInputManager()!.HoveredDrawables.OfType<IHasContextMenu>().Any())
return false;

ScrollToAbsolutePosition(e.CurrentState.Mouse.Position);
absoluteScrolling = true;
beginAbsoluteScrolling(e);
return true;
}

Expand All @@ -1200,11 +1193,32 @@ public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
switch (e.Action)
{
case GlobalAction.AbsoluteScrollSongList:
absoluteScrolling = false;
endAbsoluteScrolling();
break;
}
}

protected override bool OnMouseDown(MouseDownEvent e)
{
if (e.Button == MouseButton.Right)
{
// To avoid conflicts with context menus, disallow absolute scroll if it looks like things will fall over.
if (GetContainingInputManager()!.HoveredDrawables.OfType<IHasContextMenu>().Any())
return false;

beginAbsoluteScrolling(e);
}

return base.OnMouseDown(e);
}

protected override void OnMouseUp(MouseUpEvent e)
{
if (e.Button == MouseButton.Right)
endAbsoluteScrolling();
base.OnMouseUp(e);
}

protected override bool OnMouseMove(MouseMoveEvent e)
{
if (absoluteScrolling)
Expand All @@ -1216,6 +1230,14 @@ protected override bool OnMouseMove(MouseMoveEvent e)
return base.OnMouseMove(e);
}

private void beginAbsoluteScrolling(UIEvent e)
{
ScrollToAbsolutePosition(e.CurrentState.Mouse.Position);
absoluteScrolling = true;
}

private void endAbsoluteScrolling() => absoluteScrolling = false;

#endregion

protected override ScrollbarContainer CreateScrollbar(Direction direction)
Expand Down
41 changes: 31 additions & 10 deletions osu.Game/Screens/SelectV2/Carousel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,15 +493,7 @@ public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
switch (e.Action)
{
case GlobalAction.AbsoluteScrollSongList:

// The default binding for absolute scroll is right mouse button.
// To avoid conflicts with context menus, disallow absolute scroll completely if it looks like things will fall over.
if (e.CurrentState.Mouse.Buttons.Contains(MouseButton.Right)
&& GetContainingInputManager()!.HoveredDrawables.OfType<IHasContextMenu>().Any())
return false;

ScrollToAbsolutePosition(e.CurrentState.Mouse.Position);
absoluteScrolling = true;
beginAbsoluteScrolling(e);
return true;
}

Expand All @@ -513,11 +505,32 @@ public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
switch (e.Action)
{
case GlobalAction.AbsoluteScrollSongList:
absoluteScrolling = false;
endAbsoluteScrolling();
break;
}
}

protected override bool OnMouseDown(MouseDownEvent e)
{
if (e.Button == MouseButton.Right)
{
// To avoid conflicts with context menus, disallow absolute scroll if it looks like things will fall over.
if (GetContainingInputManager()!.HoveredDrawables.OfType<IHasContextMenu>().Any())
return false;

beginAbsoluteScrolling(e);
}

return base.OnMouseDown(e);
}

protected override void OnMouseUp(MouseUpEvent e)
{
if (e.Button == MouseButton.Right)
endAbsoluteScrolling();
base.OnMouseUp(e);
}

protected override bool OnMouseMove(MouseMoveEvent e)
{
if (absoluteScrolling)
Expand All @@ -529,6 +542,14 @@ protected override bool OnMouseMove(MouseMoveEvent e)
return base.OnMouseMove(e);
}

private void beginAbsoluteScrolling(UIEvent e)
{
ScrollToAbsolutePosition(e.CurrentState.Mouse.Position);
absoluteScrolling = true;
}

private void endAbsoluteScrolling() => absoluteScrolling = false;

#endregion
}

Expand Down
Loading