From 73dd21c8fcdaa49157287747b8be14abb1388296 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 11 Sep 2020 20:27:04 +0900 Subject: [PATCH 1/5] Add failing test --- .../Visual/Editing/TestSceneEditorChangeStates.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneEditorChangeStates.cs b/osu.Game.Tests/Visual/Editing/TestSceneEditorChangeStates.cs index c8a32d966f..dfe1e434dc 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneEditorChangeStates.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneEditorChangeStates.cs @@ -27,6 +27,17 @@ namespace osu.Game.Tests.Visual.Editing AddStep("get beatmap", () => editorBeatmap = Editor.ChildrenOfType().Single()); } + [Test] + public void TestSelectedObjects() + { + HitCircle obj = null; + AddStep("add hitobject", () => editorBeatmap.Add(obj = new HitCircle { StartTime = 1000 })); + AddStep("select hitobject", () => editorBeatmap.SelectedHitObjects.Add(obj)); + AddAssert("confirm 1 selected", () => editorBeatmap.SelectedHitObjects.Count == 1); + AddStep("deselect hitobject", () => editorBeatmap.SelectedHitObjects.Remove(obj)); + AddAssert("confirm 0 selected", () => editorBeatmap.SelectedHitObjects.Count == 0); + } + [Test] public void TestUndoFromInitialState() { From 22e6df02b650d72d6d22a0787c446984e9df982b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 11 Sep 2020 20:13:54 +0900 Subject: [PATCH 2/5] Fix editor selected hitobjects containing the selection up to five times --- .../Compose/Components/BlueprintContainer.cs | 2 -- .../Compose/Components/SelectionHandler.cs | 20 +++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs index 865e225645..b7b222d87b 100644 --- a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs @@ -367,14 +367,12 @@ namespace osu.Game.Screens.Edit.Compose.Components { selectionHandler.HandleSelected(blueprint); SelectionBlueprints.ChangeChildDepth(blueprint, 1); - beatmap.SelectedHitObjects.Add(blueprint.HitObject); } private void onBlueprintDeselected(SelectionBlueprint blueprint) { selectionHandler.HandleDeselected(blueprint); SelectionBlueprints.ChangeChildDepth(blueprint, 0); - beatmap.SelectedHitObjects.Remove(blueprint.HitObject); } #endregion diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs index 9700cb8c8e..f397ee1596 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs @@ -145,10 +145,16 @@ namespace osu.Game.Screens.Edit.Compose.Components /// The blueprint. internal void HandleSelected(SelectionBlueprint blueprint) { - selectedBlueprints.Add(blueprint); - EditorBeatmap.SelectedHitObjects.Add(blueprint.HitObject); + if (!selectedBlueprints.Contains(blueprint)) + { + selectedBlueprints.Add(blueprint); - UpdateVisibility(); + // need to check this as well, as there are potentially multiple SelectionHandlers and the above check is not enough. + if (!EditorBeatmap.SelectedHitObjects.Contains(blueprint.HitObject)) + EditorBeatmap.SelectedHitObjects.Add(blueprint.HitObject); + + UpdateVisibility(); + } } /// @@ -157,10 +163,12 @@ namespace osu.Game.Screens.Edit.Compose.Components /// The blueprint. internal void HandleDeselected(SelectionBlueprint blueprint) { - selectedBlueprints.Remove(blueprint); - EditorBeatmap.SelectedHitObjects.Remove(blueprint.HitObject); + if (selectedBlueprints.Remove(blueprint)) + { + EditorBeatmap.SelectedHitObjects.Remove(blueprint.HitObject); - UpdateVisibility(); + UpdateVisibility(); + } } /// From 94d929d8cdf64a648afca7408ecd192287fc2479 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 11 Sep 2020 22:03:19 +0900 Subject: [PATCH 3/5] Remove unnecessary contains checks --- .../Compose/Components/SelectionHandler.cs | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs index f397ee1596..0a3c9072cf 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs @@ -145,16 +145,13 @@ namespace osu.Game.Screens.Edit.Compose.Components /// The blueprint. internal void HandleSelected(SelectionBlueprint blueprint) { - if (!selectedBlueprints.Contains(blueprint)) - { - selectedBlueprints.Add(blueprint); + selectedBlueprints.Add(blueprint); - // need to check this as well, as there are potentially multiple SelectionHandlers and the above check is not enough. - if (!EditorBeatmap.SelectedHitObjects.Contains(blueprint.HitObject)) - EditorBeatmap.SelectedHitObjects.Add(blueprint.HitObject); + // need to check this as well, as there are potentially multiple SelectionHandlers and the above check is not enough. + if (!EditorBeatmap.SelectedHitObjects.Contains(blueprint.HitObject)) + EditorBeatmap.SelectedHitObjects.Add(blueprint.HitObject); - UpdateVisibility(); - } + UpdateVisibility(); } /// @@ -163,12 +160,9 @@ namespace osu.Game.Screens.Edit.Compose.Components /// The blueprint. internal void HandleDeselected(SelectionBlueprint blueprint) { - if (selectedBlueprints.Remove(blueprint)) - { - EditorBeatmap.SelectedHitObjects.Remove(blueprint.HitObject); + EditorBeatmap.SelectedHitObjects.Remove(blueprint.HitObject); - UpdateVisibility(); - } + UpdateVisibility(); } /// From 75e4f224e5a1d0a2f21db48d711dce86f1ee4239 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 14 Sep 2020 15:47:04 +0900 Subject: [PATCH 4/5] Add back accidentally removed remove --- osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs index 0a3c9072cf..60e25b01df 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs @@ -160,6 +160,8 @@ namespace osu.Game.Screens.Edit.Compose.Components /// The blueprint. internal void HandleDeselected(SelectionBlueprint blueprint) { + selectedBlueprints.Remove(blueprint); + EditorBeatmap.SelectedHitObjects.Remove(blueprint.HitObject); UpdateVisibility(); From b7a06524fb94c77f0c1719047b0f58466ab2a52a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 14 Sep 2020 15:47:10 +0900 Subject: [PATCH 5/5] Update comment to make more sense --- osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs index 60e25b01df..f95bf350b6 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs @@ -147,7 +147,7 @@ namespace osu.Game.Screens.Edit.Compose.Components { selectedBlueprints.Add(blueprint); - // need to check this as well, as there are potentially multiple SelectionHandlers and the above check is not enough. + // there are potentially multiple SelectionHandlers active, but we only want to add hitobjects to the selected list once. if (!EditorBeatmap.SelectedHitObjects.Contains(blueprint.HitObject)) EditorBeatmap.SelectedHitObjects.Add(blueprint.HitObject);