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

Allow object deletion with middle mouse #29286

Merged
merged 3 commits into from
Aug 6, 2024
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
68 changes: 68 additions & 0 deletions osu.Game.Tests/Visual/Editing/TestScenePlacementBlueprint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,74 @@ public partial class TestScenePlacementBlueprint : EditorTestScene

private GlobalActionContainer globalActionContainer => this.ChildrenOfType<GlobalActionContainer>().Single();

[Test]
public void TestDeleteUsingMiddleMouse()
{
AddStep("select circle placement tool", () => InputManager.Key(Key.Number2));
AddStep("move mouse to center of playfield", () => InputManager.MoveMouseTo(this.ChildrenOfType<Playfield>().Single()));
AddStep("place circle", () => InputManager.Click(MouseButton.Left));

AddAssert("one circle added", () => EditorBeatmap.HitObjects, () => Has.One.Items);
AddStep("delete with middle mouse", () => InputManager.Click(MouseButton.Middle));
AddAssert("circle removed", () => EditorBeatmap.HitObjects, () => Is.Empty);
}

[Test]
public void TestDeleteUsingShiftRightClick()
{
AddStep("select circle placement tool", () => InputManager.Key(Key.Number2));
AddStep("move mouse to center of playfield", () => InputManager.MoveMouseTo(this.ChildrenOfType<Playfield>().Single()));
AddStep("place circle", () => InputManager.Click(MouseButton.Left));

AddAssert("one circle added", () => EditorBeatmap.HitObjects, () => Has.One.Items);
AddStep("delete with right mouse", () =>
{
InputManager.PressKey(Key.ShiftLeft);
InputManager.Click(MouseButton.Right);
InputManager.ReleaseKey(Key.ShiftLeft);
});
AddAssert("circle removed", () => EditorBeatmap.HitObjects, () => Is.Empty);
}

[Test]
public void TestContextMenu()
{
AddStep("select circle placement tool", () => InputManager.Key(Key.Number2));
AddStep("move mouse to center of playfield", () => InputManager.MoveMouseTo(this.ChildrenOfType<Playfield>().Single()));
AddStep("place circle", () => InputManager.Click(MouseButton.Left));

AddAssert("one circle added", () => EditorBeatmap.HitObjects, () => Has.One.Items);
AddStep("delete with right mouse", () =>
{
InputManager.Click(MouseButton.Right);
});
AddAssert("circle not removed", () => EditorBeatmap.HitObjects, () => Has.One.Items);
AddAssert("circle selected", () => EditorBeatmap.SelectedHitObjects, () => Has.One.Items);
}

[Test]
[Solo]
public void TestCommitPlacementViaRightClick()
{
Playfield playfield = null!;

AddStep("select slider placement tool", () => InputManager.Key(Key.Number3));
AddStep("move mouse to top left of playfield", () =>
{
playfield = this.ChildrenOfType<Playfield>().Single();
var location = (3 * playfield.ScreenSpaceDrawQuad.TopLeft + playfield.ScreenSpaceDrawQuad.BottomRight) / 4;
InputManager.MoveMouseTo(location);
});
AddStep("begin placement", () => InputManager.Click(MouseButton.Left));
AddStep("move mouse to bottom right of playfield", () =>
{
var location = (playfield.ScreenSpaceDrawQuad.TopLeft + 3 * playfield.ScreenSpaceDrawQuad.BottomRight) / 4;
InputManager.MoveMouseTo(location);
});
AddStep("confirm via right click", () => InputManager.Click(MouseButton.Right));
AddAssert("slider placed", () => EditorBeatmap.HitObjects.Count, () => Is.EqualTo(1));
}

[Test]
public void TestCommitPlacementViaGlobalAction()
{
Expand Down
4 changes: 1 addition & 3 deletions osu.Game/Rulesets/Edit/PlacementBlueprint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ protected override bool Handle(UIEvent e)

case MouseButtonEvent mouse:
// placement blueprints should generally block mouse from reaching underlying components (ie. performing clicks on interface buttons).
// for now, the one exception we want to allow is when using a non-main mouse button when shift is pressed, which is used to trigger object deletion
// while in placement mode.
return mouse.Button == MouseButton.Left || !mouse.ShiftPressed;
return mouse.Button == MouseButton.Left || PlacementActive == PlacementState.Active;

default:
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ internal virtual void HandleDeselected(SelectionBlueprint<T> blueprint)
/// <returns>Whether a selection was performed.</returns>
internal virtual bool MouseDownSelectionRequested(SelectionBlueprint<T> blueprint, MouseButtonEvent e)
{
if (e.ShiftPressed && e.Button == MouseButton.Right)
if (e.Button == MouseButton.Middle || (e.ShiftPressed && e.Button == MouseButton.Right))
{
handleQuickDeletion(blueprint);
return true;
Expand Down
Loading