mirror of
https://github.com/ppy/osu.git
synced 2025-02-10 01:33:21 +08:00
Merge pull request #30294 from bdach/fuzzin
Fix several cases of deselection not correctly terminating drag operations on slider selection blueprint
This commit is contained in:
commit
b1b0aadbfb
55
osu.Game.Rulesets.Osu.Tests/Editor/TestSceneToolSwitching.cs
Normal file
55
osu.Game.Rulesets.Osu.Tests/Editor/TestSceneToolSwitching.cs
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Tests.Visual;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Tests.Editor
|
||||
{
|
||||
public partial class TestSceneToolSwitching : EditorTestScene
|
||||
{
|
||||
protected override Ruleset CreateEditorRuleset() => new OsuRuleset();
|
||||
|
||||
[Test]
|
||||
public void TestSliderAnchorMoveOperationEndsOnSwitchingTool()
|
||||
{
|
||||
var initialPosition = Vector2.Zero;
|
||||
|
||||
AddStep("store original anchor position", () => initialPosition = EditorBeatmap.HitObjects.OfType<Slider>().First().Path.ControlPoints.ElementAt(1).Position);
|
||||
AddStep("select first slider", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.OfType<Slider>().First()));
|
||||
AddStep("move to second anchor", () => InputManager.MoveMouseTo(this.ChildrenOfType<PathControlPointPiece<Slider>>().ElementAt(1)));
|
||||
AddStep("start dragging", () => InputManager.PressButton(MouseButton.Left));
|
||||
AddStep("drag away", () => InputManager.MoveMouseTo(InputManager.CurrentState.Mouse.Position + new Vector2(0, -200)));
|
||||
AddStep("switch tool", () => InputManager.PressButton(MouseButton.Button1));
|
||||
AddStep("undo", () => Editor.Undo());
|
||||
AddAssert("anchor back at original position",
|
||||
() => EditorBeatmap.HitObjects.OfType<Slider>().First().Path.ControlPoints.ElementAt(1).Position,
|
||||
() => Is.EqualTo(initialPosition));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSliderAnchorCreationOperationEndsOnSwitchingTool()
|
||||
{
|
||||
AddStep("select first slider", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.OfType<Slider>().First()));
|
||||
AddStep("move to second anchor", () => InputManager.MoveMouseTo(this.ChildrenOfType<PathControlPointPiece<Slider>>().ElementAt(1), new Vector2(-50, 0)));
|
||||
AddStep("quick-create anchor", () =>
|
||||
{
|
||||
InputManager.PressKey(Key.ControlLeft);
|
||||
InputManager.PressButton(MouseButton.Left);
|
||||
InputManager.ReleaseKey(Key.ControlLeft);
|
||||
});
|
||||
AddStep("drag away", () => InputManager.MoveMouseTo(InputManager.CurrentState.Mouse.Position + new Vector2(0, -200)));
|
||||
AddStep("switch tool", () => InputManager.PressKey(Key.Number3));
|
||||
AddStep("drag away further", () => InputManager.MoveMouseTo(InputManager.CurrentState.Mouse.Position + new Vector2(0, -200)));
|
||||
AddStep("select first slider", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.OfType<Slider>().First()));
|
||||
AddStep("undo", () => Editor.Undo());
|
||||
AddAssert("slider has three anchors again", () => EditorBeatmap.HitObjects.OfType<Slider>().First().Path.ControlPoints, () => Has.Count.EqualTo(3));
|
||||
}
|
||||
}
|
||||
}
|
@ -333,6 +333,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
base.Dispose(isDisposing);
|
||||
foreach (var p in Pieces)
|
||||
p.ControlPoint.Changed -= controlPointChanged;
|
||||
|
||||
if (draggedControlPointIndex >= 0)
|
||||
DragEnded();
|
||||
}
|
||||
|
||||
private void selectionRequested(PathControlPointPiece<T> piece, MouseButtonEvent e)
|
||||
@ -392,7 +395,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
|
||||
private Vector2[] dragStartPositions;
|
||||
private PathType?[] dragPathTypes;
|
||||
private int draggedControlPointIndex;
|
||||
private int draggedControlPointIndex = -1;
|
||||
private HashSet<PathControlPoint> selectedControlPoints;
|
||||
|
||||
private List<MenuItem> curveTypeItems;
|
||||
@ -473,7 +476,11 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
EnsureValidPathTypes();
|
||||
}
|
||||
|
||||
public void DragEnded() => changeHandler?.EndChange();
|
||||
public void DragEnded()
|
||||
{
|
||||
changeHandler?.EndChange();
|
||||
draggedControlPointIndex = -1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -178,6 +178,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
|
||||
{
|
||||
base.OnDeselected();
|
||||
|
||||
if (placementControlPoint != null)
|
||||
endControlPointPlacement();
|
||||
|
||||
updateVisualDefinition();
|
||||
BodyPiece.RecyclePath();
|
||||
}
|
||||
@ -377,13 +380,16 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
|
||||
protected override void OnMouseUp(MouseUpEvent e)
|
||||
{
|
||||
if (placementControlPoint != null)
|
||||
{
|
||||
if (IsDragged)
|
||||
ControlPointVisualiser?.DragEnded();
|
||||
endControlPointPlacement();
|
||||
}
|
||||
|
||||
placementControlPoint = null;
|
||||
changeHandler?.EndChange();
|
||||
}
|
||||
private void endControlPointPlacement()
|
||||
{
|
||||
if (IsDragged)
|
||||
ControlPointVisualiser?.DragEnded();
|
||||
|
||||
placementControlPoint = null;
|
||||
changeHandler?.EndChange();
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(KeyDownEvent e)
|
||||
|
Loading…
Reference in New Issue
Block a user