From f64fa65fd5c2297f9f0d0355c189feaffb3ec3bb Mon Sep 17 00:00:00 2001 From: Jason Won Date: Tue, 26 Oct 2021 14:52:15 -0400 Subject: [PATCH 1/4] right click on unselected object shows context menu --- .../Editing/TestSceneComposerSelection.cs | 24 +++++++++++++++++++ .../Compose/Components/BlueprintContainer.cs | 12 +++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs b/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs index a2a7b72283..36663591f2 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs @@ -42,6 +42,30 @@ namespace osu.Game.Tests.Visual.Editing }); } + [Test] + public void TestSelectAndShowContextMenu() + { + var addedObject = new HitCircle { StartTime = 100, Position = new Vector2(100, 100) }; + AddStep("add hitobject", () => EditorBeatmap.Add(addedObject)); + + moveMouseToObject(() => addedObject); + AddStep("right click", () => InputManager.Click(MouseButton.Right)); + + AddAssert("hitobject selected", () => EditorBeatmap.SelectedHitObjects.Single() == addedObject); + + AddStep("delete from context menu", () => + { + var pos = blueprintContainer.SelectionBlueprints + .First(s => s.Item == addedObject) + .ChildrenOfType() + .First(); + + InputManager.MoveMouseTo(pos, new Vector2(50, 120)); + InputManager.Click(MouseButton.Left); + }); + AddAssert("no hitobjects in beatmap", () => EditorBeatmap.HitObjects.Count == 0); + } + [Test] public void TestNudgeSelection() { diff --git a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs index 75d4d13f94..0de99831f2 100644 --- a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs @@ -108,11 +108,17 @@ namespace osu.Game.Screens.Edit.Compose.Components protected override bool OnMouseDown(MouseDownEvent e) { bool selectionPerformed = performMouseDownActions(e); - - // even if a selection didn't occur, a drag event may still move the selection. bool movementPossible = prepareSelectionMovement(); - return selectionPerformed || (e.Button == MouseButton.Left && movementPossible); + // check if selection has occurred + if (selectionPerformed) + { + // propagate right click to show context menu on selection + return e.Button != MouseButton.Right; + } + + // even if a selection didn't occur, a drag event may still move the selection. + return e.Button == MouseButton.Left && movementPossible; } protected SelectionBlueprint ClickedBlueprint { get; private set; } From 4efa1f23bb7c0ce836d0d59b8748cc4b8583d962 Mon Sep 17 00:00:00 2001 From: Jason Won Date: Tue, 26 Oct 2021 15:29:50 -0400 Subject: [PATCH 2/4] fix context menu test --- .../Editing/TestSceneComposerSelection.cs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs b/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs index 36663591f2..9aae595808 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs @@ -5,7 +5,10 @@ using System; using System.Linq; using NUnit.Framework; using osu.Framework.Testing; +using osu.Framework.Graphics.Cursor; +using osu.Framework.Graphics.UserInterface; using osu.Game.Beatmaps; +using osu.Game.Graphics.UserInterface; using osu.Game.Rulesets; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Osu; @@ -29,6 +32,9 @@ namespace osu.Game.Tests.Visual.Editing private ComposeBlueprintContainer blueprintContainer => Editor.ChildrenOfType().First(); + private ContextMenuContainer contextMenuContainer + => Editor.ChildrenOfType().First(); + private void moveMouseToObject(Func targetFunc) { AddStep("move mouse to object", () => @@ -52,18 +58,7 @@ namespace osu.Game.Tests.Visual.Editing AddStep("right click", () => InputManager.Click(MouseButton.Right)); AddAssert("hitobject selected", () => EditorBeatmap.SelectedHitObjects.Single() == addedObject); - - AddStep("delete from context menu", () => - { - var pos = blueprintContainer.SelectionBlueprints - .First(s => s.Item == addedObject) - .ChildrenOfType() - .First(); - - InputManager.MoveMouseTo(pos, new Vector2(50, 120)); - InputManager.Click(MouseButton.Left); - }); - AddAssert("no hitobjects in beatmap", () => EditorBeatmap.HitObjects.Count == 0); + AddAssert("context menu is visible", () => contextMenuContainer.ChildrenOfType().Single().State == MenuState.Open); } [Test] From c633e2e9521b9c9ae86defae674a0d65b16efabd Mon Sep 17 00:00:00 2001 From: Jason Won Date: Tue, 26 Oct 2021 16:24:53 -0400 Subject: [PATCH 3/4] only propagate unmodified right click --- .../Visual/Editing/TestSceneComposerSelection.cs | 4 ++-- .../Screens/Edit/Compose/Components/BlueprintContainer.cs | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs b/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs index 9aae595808..dddd9f07ab 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs @@ -57,8 +57,8 @@ namespace osu.Game.Tests.Visual.Editing moveMouseToObject(() => addedObject); AddStep("right click", () => InputManager.Click(MouseButton.Right)); - AddAssert("hitobject selected", () => EditorBeatmap.SelectedHitObjects.Single() == addedObject); - AddAssert("context menu is visible", () => contextMenuContainer.ChildrenOfType().Single().State == MenuState.Open); + AddUntilStep("hitobject selected", () => EditorBeatmap.SelectedHitObjects.Single() == addedObject); + AddUntilStep("context menu is visible", () => contextMenuContainer.ChildrenOfType().Single().State == MenuState.Open); } [Test] diff --git a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs index 0de99831f2..7391c1a642 100644 --- a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs @@ -113,8 +113,11 @@ namespace osu.Game.Screens.Edit.Compose.Components // check if selection has occurred if (selectionPerformed) { - // propagate right click to show context menu on selection - return e.Button != MouseButton.Right; + // only unmodified right click should show context menu + var shouldShowContextMenu = e.Button == MouseButton.Right && !e.ShiftPressed && !e.AltPressed && !e.SuperPressed; + + // stop propagation if not showing context menu + return !shouldShowContextMenu; } // even if a selection didn't occur, a drag event may still move the selection. From 09701d0af12f8ae0f05fdf7fc6e947216ed40388 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 4 Nov 2021 16:02:37 +0900 Subject: [PATCH 4/4] Use explicit primitive type specification --- osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs index 42792bdf5b..29e3f12d03 100644 --- a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs @@ -114,7 +114,7 @@ namespace osu.Game.Screens.Edit.Compose.Components if (selectionPerformed) { // only unmodified right click should show context menu - var shouldShowContextMenu = e.Button == MouseButton.Right && !e.ShiftPressed && !e.AltPressed && !e.SuperPressed; + bool shouldShowContextMenu = e.Button == MouseButton.Right && !e.ShiftPressed && !e.AltPressed && !e.SuperPressed; // stop propagation if not showing context menu return !shouldShowContextMenu;