From 29376ffcc0c7a52620ddbbe6096261b7ca6dd3ab Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 28 Jun 2023 12:54:12 +0900 Subject: [PATCH 1/3] Trigger state change when flipping via hotkey in the editor This will trigger a change even if nothing happens. But I think that's okay (not easy to avoid) because the change handler should be aware that nothing changed, if anything. Closes https://github.com/ppy/osu/issues/24065. --- .../Edit/Compose/Components/SelectionHandler.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs index 5cedf1ca42..9ec59cf833 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs @@ -163,10 +163,18 @@ namespace osu.Game.Screens.Edit.Compose.Components switch (e.Action) { case GlobalAction.EditorFlipHorizontally: - return HandleFlip(Direction.Horizontal, true); + ChangeHandler?.BeginChange(); + HandleFlip(Direction.Horizontal, true); + ChangeHandler?.EndChange(); + + return true; case GlobalAction.EditorFlipVertically: - return HandleFlip(Direction.Vertical, true); + ChangeHandler?.BeginChange(); + HandleFlip(Direction.Vertical, true); + ChangeHandler?.EndChange(); + + return true; } return false; From 0940ab1e11cb246975908f8f00974511f1864fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 28 Jun 2023 20:47:00 +0200 Subject: [PATCH 2/3] Add failing tests covering correct flip handling --- .../Editing/TestSceneComposerSelection.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs b/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs index 4d99c47f77..d6934a3770 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs @@ -133,6 +133,32 @@ namespace osu.Game.Tests.Visual.Editing AddAssert("objects reverted to original position", () => addedObjects[0].Position == new Vector2(0)); } + [Test] + public void TestGlobalFlipHotkeys() + { + HitCircle addedObject = null; + + AddStep("add hitobjects", () => EditorBeatmap.Add(addedObject = new HitCircle { StartTime = 100 })); + + AddStep("select objects", () => EditorBeatmap.SelectedHitObjects.Add(addedObject)); + + AddStep("flip horizontally across playfield", () => + { + InputManager.PressKey(Key.ControlLeft); + InputManager.Key(Key.H); + InputManager.ReleaseKey(Key.ControlLeft); + }); + AddAssert("objects flipped horizontally", () => addedObject.Position == new Vector2(OsuPlayfield.BASE_SIZE.X, 0)); + + AddStep("flip vertically across playfield", () => + { + InputManager.PressKey(Key.ControlLeft); + InputManager.Key(Key.J); + InputManager.ReleaseKey(Key.ControlLeft); + }); + AddAssert("objects flipped vertically", () => addedObject.Position == OsuPlayfield.BASE_SIZE); + } + [Test] public void TestBasicSelect() { From e4e08c0f5fb787091d28a38b4e67bc59b2b0b846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 28 Jun 2023 20:48:22 +0200 Subject: [PATCH 3/3] Fix selection handlers eating hotkey presses they didn't handle --- .../Edit/Compose/Components/SelectionHandler.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs index 9ec59cf833..052cb18a5d 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs @@ -160,21 +160,23 @@ namespace osu.Game.Screens.Edit.Compose.Components if (e.Repeat) return false; + bool handled; + switch (e.Action) { case GlobalAction.EditorFlipHorizontally: ChangeHandler?.BeginChange(); - HandleFlip(Direction.Horizontal, true); + handled = HandleFlip(Direction.Horizontal, true); ChangeHandler?.EndChange(); - return true; + return handled; case GlobalAction.EditorFlipVertically: ChangeHandler?.BeginChange(); - HandleFlip(Direction.Vertical, true); + handled = HandleFlip(Direction.Vertical, true); ChangeHandler?.EndChange(); - return true; + return handled; } return false;