1
0
mirror of https://github.com/ppy/osu.git synced 2026-06-05 04:33:39 +08:00

Merge pull request #34526 from frenzibyte/editor-weird-selection

Fix grid placement completely breaking selection in certain scenarios
This commit is contained in:
Bartłomiej Dach
2025-08-06 18:00:55 +02:00
committed by GitHub
Unverified
2 changed files with 70 additions and 3 deletions
@@ -9,6 +9,7 @@ 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.Rulesets.Osu.Edit.Blueprints.Sliders;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit.Compose.Components;
using osu.Game.Tests.Visual;
@@ -284,5 +285,70 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
&& Precision.AlmostEquals(composer.GridLineRotation.Value, 0.09, 0.01);
});
}
[Test]
public void TestGridPlacementCommittedByDragSelection()
{
AddStep("add circle", () => EditorBeatmap.Add(new HitCircle
{
Position = new Vector2(64, 64),
StartTime = EditorClock.CurrentTime,
}));
AddStep("select circle tool", () => InputManager.Key(Key.Number2));
AddStep("select grid tool", () => InputManager.Key(Key.Number5));
AddStep("move cursor to centre", () => InputManager.MoveMouseTo(Editor));
AddStep("click", () => InputManager.Click(MouseButton.Left));
AddStep("move cursor to (-1, -1)", () =>
{
var composer = Editor.ChildrenOfType<RectangularPositionSnapGrid>().Single();
InputManager.MoveMouseTo(composer.ToScreenSpace(new Vector2(-1, -1)));
});
AddStep("drag to center", () =>
{
InputManager.PressButton(MouseButton.Left);
InputManager.MoveMouseTo(Editor);
});
AddStep("release left", () => InputManager.ReleaseButton(MouseButton.Left));
AddAssert("one selection", () => Editor.ChildrenOfType<OsuSelectionHandler>().Single().SelectedBlueprints, () => Has.One.Items);
AddAssert("selection is circle", () => Editor.ChildrenOfType<OsuSelectionHandler>().Single().SelectedBlueprints.Single(), Is.TypeOf<HitCircleSelectionBlueprint>);
AddStep("move cursor to slider", () =>
{
var composer = Editor.ChildrenOfType<RectangularPositionSnapGrid>().Single();
InputManager.MoveMouseTo(composer.ToScreenSpace(((Slider)EditorBeatmap.HitObjects.ElementAt(1)).EndPosition + new Vector2(1, 1)));
});
AddStep("click", () => InputManager.Click(MouseButton.Left));
AddAssert("one selection", () => Editor.ChildrenOfType<OsuSelectionHandler>().Single().SelectedBlueprints, () => Has.One.Items);
AddAssert("selection is slider", () => Editor.ChildrenOfType<OsuSelectionHandler>().Single().SelectedBlueprints.Single(), Is.TypeOf<SliderSelectionBlueprint>);
}
[Test]
public void TestGridPlacementRevertsToLastTool()
{
AddStep("select circle tool", () => InputManager.Key(Key.Number2));
AddStep("select grid tool", () => InputManager.Key(Key.Number5));
AddStep("move cursor to centre", () => InputManager.MoveMouseTo(Editor));
AddStep("start grid placement", () => InputManager.Click(MouseButton.Left));
AddStep("end grid placement", () => InputManager.Click(MouseButton.Left));
AddAssert("tool reverted to circle", () => getComposer().BlueprintContainer.CurrentTool, Is.TypeOf<HitCircleCompositionTool>);
HitObjectComposer getComposer() => Editor.ChildrenOfType<HitObjectComposer>().Single();
}
[Test]
public void TestGridPlacementDoesNotOverrideToolChange()
{
AddStep("select circle tool", () => InputManager.Key(Key.Number2));
AddStep("select grid tool", () => InputManager.Key(Key.Number5));
AddStep("move cursor to centre", () => InputManager.MoveMouseTo(Editor));
AddStep("start grid placement", () => InputManager.Click(MouseButton.Left));
AddStep("select circle tool again", () => InputManager.Key(Key.Number2));
AddAssert("circle tool selected", () => getComposer().BlueprintContainer.CurrentTool, Is.TypeOf<HitCircleCompositionTool>);
HitObjectComposer getComposer() => Editor.ChildrenOfType<HitObjectComposer>().Single();
}
}
}
@@ -36,9 +36,10 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints
base.EndPlacement(commit);
// You typically only place the grid once, so we switch back to the last tool after placement.
if (commit && hitObjectComposer is OsuHitObjectComposer osuHitObjectComposer)
osuHitObjectComposer.SetLastTool();
// You typically only place the grid once, so we switch back to the last tool after placement -
// but only if the tool hasn't changed from under us (which is possible, as external tool changes will commit any ongoing placements, including this one)
if (commit && hitObjectComposer?.BlueprintContainer.CurrentTool is GridFromPointsTool)
hitObjectComposer.SetLastTool();
}
protected override bool OnClick(ClickEvent e)