From 093c25539cd85911f4a06ba780e647737c7ac676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 2 May 2024 13:59:40 +0200 Subject: [PATCH 1/3] Add failing test case --- .../Editor/TestSceneOsuEditorGrids.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs b/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs index d14e59358775..b720eb148b50 100644 --- a/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs +++ b/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs @@ -5,6 +5,7 @@ using NUnit.Framework; using osu.Framework.Testing; using osu.Framework.Utils; +using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Osu.Edit; using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles; using osu.Game.Tests.Visual; @@ -54,6 +55,30 @@ public void TestDistanceSnapMomentaryToggle() AddUntilStep("distance snap grid hidden", () => !this.ChildrenOfType().Any()); } + [Test] + public void TestDistanceSnapAdjustDoesNotHideTheGrid() + { + double distanceSnap = double.PositiveInfinity; + + AddStep("enable distance snap grid", () => InputManager.Key(Key.T)); + + AddStep("select second object", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.ElementAt(1))); + AddUntilStep("distance snap grid visible", () => this.ChildrenOfType().Any()); + AddStep("store distance snap", () => distanceSnap = this.ChildrenOfType().First().DistanceSpacingMultiplier.Value); + + AddStep("increase distance", () => + { + InputManager.PressKey(Key.AltLeft); + InputManager.PressKey(Key.ControlLeft); + InputManager.ScrollVerticalBy(1); + InputManager.ReleaseKey(Key.ControlLeft); + InputManager.ReleaseKey(Key.AltLeft); + }); + + AddUntilStep("distance snap increased", () => this.ChildrenOfType().First().DistanceSpacingMultiplier.Value, () => Is.GreaterThan(distanceSnap)); + AddUntilStep("distance snap grid still visible", () => this.ChildrenOfType().Any()); + } + [Test] public void TestGridSnapMomentaryToggle() { From 14658824e712a9aea3d1e6697d169a6e0b873201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 2 May 2024 14:11:44 +0200 Subject: [PATCH 2/3] Adjust distance snap grid momentary toggle logic to not hide it on spacing adjust --- .../Rulesets/Edit/ComposerDistanceSnapProvider.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/Edit/ComposerDistanceSnapProvider.cs b/osu.Game/Rulesets/Edit/ComposerDistanceSnapProvider.cs index 62ad2ce7e906..b9850a94a36e 100644 --- a/osu.Game/Rulesets/Edit/ComposerDistanceSnapProvider.cs +++ b/osu.Game/Rulesets/Edit/ComposerDistanceSnapProvider.cs @@ -63,6 +63,7 @@ public abstract partial class ComposerDistanceSnapProvider : Component, IDistanc public readonly Bindable DistanceSnapToggle = new Bindable(); private bool distanceSnapMomentary; + private TernaryState? distanceSnapStateBeforeMomentaryToggle; private EditorToolboxGroup? toolboxGroup; @@ -213,10 +214,19 @@ private void handleToggleViaKey(KeyboardEvent key) { bool altPressed = key.AltPressed; - if (altPressed != distanceSnapMomentary) + if (altPressed && !distanceSnapMomentary) { - distanceSnapMomentary = altPressed; + distanceSnapStateBeforeMomentaryToggle = DistanceSnapToggle.Value; DistanceSnapToggle.Value = DistanceSnapToggle.Value == TernaryState.False ? TernaryState.True : TernaryState.False; + distanceSnapMomentary = true; + } + + if (!altPressed && distanceSnapMomentary) + { + Debug.Assert(distanceSnapStateBeforeMomentaryToggle != null); + DistanceSnapToggle.Value = distanceSnapStateBeforeMomentaryToggle.Value; + distanceSnapStateBeforeMomentaryToggle = null; + distanceSnapMomentary = false; } } From 6000ffed2a7eb000efb4ea045055d620be2dcbbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 2 May 2024 14:15:46 +0200 Subject: [PATCH 3/3] Add extended test coverage for intended behaviour --- .../Editor/TestSceneOsuEditorGrids.cs | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs b/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs index b720eb148b50..5798869210c8 100644 --- a/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs +++ b/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuEditorGrids.cs @@ -53,10 +53,17 @@ public void TestDistanceSnapMomentaryToggle() AddUntilStep("distance snap grid visible", () => this.ChildrenOfType().Any()); AddStep("release alt", () => InputManager.ReleaseKey(Key.AltLeft)); AddUntilStep("distance snap grid hidden", () => !this.ChildrenOfType().Any()); + + AddStep("enable distance snap grid", () => InputManager.Key(Key.T)); + AddUntilStep("distance snap grid visible", () => this.ChildrenOfType().Any()); + AddStep("hold alt", () => InputManager.PressKey(Key.AltLeft)); + AddUntilStep("distance snap grid hidden", () => !this.ChildrenOfType().Any()); + AddStep("release alt", () => InputManager.ReleaseKey(Key.AltLeft)); + AddUntilStep("distance snap grid visible", () => this.ChildrenOfType().Any()); } [Test] - public void TestDistanceSnapAdjustDoesNotHideTheGrid() + public void TestDistanceSnapAdjustDoesNotHideTheGridIfStartingEnabled() { double distanceSnap = double.PositiveInfinity; @@ -79,6 +86,34 @@ public void TestDistanceSnapAdjustDoesNotHideTheGrid() AddUntilStep("distance snap grid still visible", () => this.ChildrenOfType().Any()); } + [Test] + public void TestDistanceSnapAdjustShowsGridMomentarilyIfStartingDisabled() + { + double distanceSnap = double.PositiveInfinity; + + AddStep("select second object", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.ElementAt(1))); + AddUntilStep("distance snap grid hidden", () => !this.ChildrenOfType().Any()); + AddStep("store distance snap", () => distanceSnap = this.ChildrenOfType().First().DistanceSpacingMultiplier.Value); + + AddStep("start increasing distance", () => + { + InputManager.PressKey(Key.AltLeft); + InputManager.PressKey(Key.ControlLeft); + }); + + AddUntilStep("distance snap grid visible", () => this.ChildrenOfType().Any()); + + AddStep("finish increasing distance", () => + { + InputManager.ScrollVerticalBy(1); + InputManager.ReleaseKey(Key.ControlLeft); + InputManager.ReleaseKey(Key.AltLeft); + }); + + AddUntilStep("distance snap increased", () => this.ChildrenOfType().First().DistanceSpacingMultiplier.Value, () => Is.GreaterThan(distanceSnap)); + AddUntilStep("distance snap hidden in the end", () => !this.ChildrenOfType().Any()); + } + [Test] public void TestGridSnapMomentaryToggle() {