mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Implement drag operation for multiple path control points
This commit is contained in:
@ -64,19 +64,20 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
|
|||||||
public void TestDragMultipleControlPoints()
|
public void TestDragMultipleControlPoints()
|
||||||
{
|
{
|
||||||
moveMouseToControlPoint(2);
|
moveMouseToControlPoint(2);
|
||||||
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
AddStep("click left mouse", () => InputManager.Click(MouseButton.Left));
|
||||||
|
|
||||||
AddStep("hold control", () => InputManager.PressKey(Key.LControl));
|
AddStep("hold control", () => InputManager.PressKey(Key.LControl));
|
||||||
|
|
||||||
moveMouseToControlPoint(3);
|
moveMouseToControlPoint(3);
|
||||||
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
AddStep("click left mouse", () => InputManager.Click(MouseButton.Left));
|
||||||
|
|
||||||
moveMouseToControlPoint(4);
|
moveMouseToControlPoint(4);
|
||||||
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
AddStep("click left mouse", () => InputManager.Click(MouseButton.Left));
|
||||||
|
|
||||||
moveMouseToControlPoint(2);
|
moveMouseToControlPoint(2);
|
||||||
|
AddStep("hold left mouse", () => InputManager.PressButton(MouseButton.Left));
|
||||||
addMovementStep(new Vector2(450, 50));
|
addMovementStep(new Vector2(450, 50));
|
||||||
AddStep("release", () => InputManager.ReleaseButton(MouseButton.Left));
|
AddStep("release left mouse", () => InputManager.ReleaseButton(MouseButton.Left));
|
||||||
|
|
||||||
assertControlPointPosition(2, new Vector2(450, 50));
|
assertControlPointPosition(2, new Vector2(450, 50));
|
||||||
assertControlPointType(2, PathType.PerfectCurve);
|
assertControlPointType(2, PathType.PerfectCurve);
|
||||||
|
@ -32,8 +32,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
|||||||
{
|
{
|
||||||
public Action<PathControlPointPiece, MouseButtonEvent> RequestSelection;
|
public Action<PathControlPointPiece, MouseButtonEvent> RequestSelection;
|
||||||
|
|
||||||
public Action<PathControlPoint> DragStarted;
|
public Action DragStarted;
|
||||||
public Action<PathControlPoint, DragEvent> DragInProgress;
|
public Action<DragEvent> DragInProgress;
|
||||||
public Action DragEnded;
|
public Action DragEnded;
|
||||||
|
|
||||||
public List<PathControlPoint> PointsInSegment;
|
public List<PathControlPoint> PointsInSegment;
|
||||||
@ -185,14 +185,14 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
|||||||
|
|
||||||
if (e.Button == MouseButton.Left)
|
if (e.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
DragStarted?.Invoke(ControlPoint);
|
DragStarted?.Invoke();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDrag(DragEvent e) => DragInProgress?.Invoke(ControlPoint, e);
|
protected override void OnDrag(DragEvent e) => DragInProgress?.Invoke(e);
|
||||||
|
|
||||||
protected override void OnDragEnd(DragEndEvent e) => DragEnded?.Invoke();
|
protected override void OnDragEnd(DragEndEvent e) => DragEnded?.Invoke();
|
||||||
|
|
||||||
|
@ -213,26 +213,28 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
|||||||
|
|
||||||
#region Drag handling
|
#region Drag handling
|
||||||
|
|
||||||
private Vector2 dragStartPosition;
|
private Vector2[] dragStartPositions;
|
||||||
private PathType? dragPathType;
|
private PathType?[] dragPathTypes;
|
||||||
|
private HashSet<PathControlPoint> draggedControlPoints;
|
||||||
|
|
||||||
private void dragStarted(PathControlPoint controlPoint)
|
private void dragStarted()
|
||||||
{
|
{
|
||||||
dragStartPosition = controlPoint.Position;
|
dragStartPositions = slider.Path.ControlPoints.Select(point => point.Position).ToArray();
|
||||||
dragPathType = slider.Path.PointsInSegment(controlPoint).First().Type;
|
dragPathTypes = slider.Path.ControlPoints.Select(point => point.Type).ToArray();
|
||||||
|
draggedControlPoints = new HashSet<PathControlPoint>(Pieces.Where(piece => piece.IsSelected.Value).Select(piece => piece.ControlPoint));
|
||||||
|
|
||||||
changeHandler?.BeginChange();
|
changeHandler?.BeginChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dragInProgress(PathControlPoint controlPoint, DragEvent e)
|
private void dragInProgress(DragEvent e)
|
||||||
{
|
{
|
||||||
Vector2[] oldControlPoints = slider.Path.ControlPoints.Select(cp => cp.Position).ToArray();
|
Vector2[] oldControlPoints = slider.Path.ControlPoints.Select(cp => cp.Position).ToArray();
|
||||||
var oldPosition = slider.Position;
|
var oldPosition = slider.Position;
|
||||||
double oldStartTime = slider.StartTime;
|
double oldStartTime = slider.StartTime;
|
||||||
|
|
||||||
if (controlPoint == slider.Path.ControlPoints[0])
|
if (draggedControlPoints.Contains(slider.Path.ControlPoints[0]))
|
||||||
{
|
{
|
||||||
// Special handling for the head control point - the position of the slider changes which means the snapped position and time have to be taken into account
|
// Special handling for selections containing head control point - the position of the slider changes which means the snapped position and time have to be taken into account
|
||||||
var result = snapProvider?.SnapScreenSpacePositionToValidTime(e.ScreenSpaceMousePosition);
|
var result = snapProvider?.SnapScreenSpacePositionToValidTime(e.ScreenSpaceMousePosition);
|
||||||
|
|
||||||
Vector2 movementDelta = Parent.ToLocalSpace(result?.ScreenSpacePosition ?? e.ScreenSpaceMousePosition) - slider.Position;
|
Vector2 movementDelta = Parent.ToLocalSpace(result?.ScreenSpacePosition ?? e.ScreenSpaceMousePosition) - slider.Position;
|
||||||
@ -240,12 +242,26 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
|||||||
slider.Position += movementDelta;
|
slider.Position += movementDelta;
|
||||||
slider.StartTime = result?.Time ?? slider.StartTime;
|
slider.StartTime = result?.Time ?? slider.StartTime;
|
||||||
|
|
||||||
// Since control points are relative to the position of the slider, they all need to be offset backwards by the delta
|
|
||||||
for (int i = 1; i < slider.Path.ControlPoints.Count; i++)
|
for (int i = 1; i < slider.Path.ControlPoints.Count; i++)
|
||||||
slider.Path.ControlPoints[i].Position -= movementDelta;
|
{
|
||||||
|
var controlPoint = slider.Path.ControlPoints[i];
|
||||||
|
// Since control points are relative to the position of the slider, all points that are _not_ selected
|
||||||
|
// need to be offset _back_ by the delta corresponding to the movement of the head point.
|
||||||
|
// All other selected control points (if any) will move together with the head point
|
||||||
|
// (and so they will not move at all, relative to each other).
|
||||||
|
if (!draggedControlPoints.Contains(controlPoint))
|
||||||
|
controlPoint.Position -= movementDelta;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
controlPoint.Position = dragStartPosition + (e.MousePosition - e.MouseDownPosition);
|
{
|
||||||
|
for (int i = 0; i < controlPoints.Count; ++i)
|
||||||
|
{
|
||||||
|
var controlPoint = controlPoints[i];
|
||||||
|
if (draggedControlPoints.Contains(controlPoint))
|
||||||
|
controlPoint.Position = dragStartPositions[i] + (e.MousePosition - e.MouseDownPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!slider.Path.HasValidLength)
|
if (!slider.Path.HasValidLength)
|
||||||
{
|
{
|
||||||
@ -257,8 +273,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maintain the path type in case it got defaulted to bezier at some point during the drag.
|
// Maintain the path types in case they got defaulted to bezier at some point during the drag.
|
||||||
slider.Path.PointsInSegment(controlPoint).First().Type = dragPathType;
|
for (int i = 0; i < slider.Path.ControlPoints.Count; i++)
|
||||||
|
slider.Path.ControlPoints[i].Type = dragPathTypes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dragEnded() => changeHandler?.EndChange();
|
private void dragEnded() => changeHandler?.EndChange();
|
||||||
|
Reference in New Issue
Block a user