1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-04 07:04:04 +08:00

Add ability to better control slider control point type during placement via Tab

This commit is contained in:
Bartłomiej Dach 2024-06-17 15:06:17 +02:00
parent b535f7c519
commit b5f0e58524
No known key found for this signature in database

View File

@ -40,6 +40,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private PathControlPoint segmentStart; private PathControlPoint segmentStart;
private PathControlPoint cursor; private PathControlPoint cursor;
private int currentSegmentLength; private int currentSegmentLength;
private bool usingCustomSegmentType;
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
[CanBeNull] [CanBeNull]
@ -149,12 +150,17 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
case SliderPlacementState.ControlPoints: case SliderPlacementState.ControlPoints:
if (canPlaceNewControlPoint(out var lastPoint)) if (canPlaceNewControlPoint(out var lastPoint))
{ placeNewControlPoint();
// Place a new point by detatching the current cursor.
updateCursor();
cursor = null;
}
else else
beginNewSegment(lastPoint);
break;
}
return true;
}
private void beginNewSegment(PathControlPoint lastPoint)
{ {
// Transform the last point into a new segment. // Transform the last point into a new segment.
Debug.Assert(lastPoint != null); Debug.Assert(lastPoint != null);
@ -163,12 +169,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
segmentStart.Type = PathType.LINEAR; segmentStart.Type = PathType.LINEAR;
currentSegmentLength = 1; currentSegmentLength = 1;
} usingCustomSegmentType = false;
break;
}
return true;
} }
protected override bool OnDragStart(DragStartEvent e) protected override bool OnDragStart(DragStartEvent e)
@ -223,6 +224,47 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
base.OnMouseUp(e); base.OnMouseUp(e);
} }
private static readonly PathType[] path_types =
[
PathType.LINEAR,
PathType.BEZIER,
PathType.PERFECT_CURVE,
PathType.BSpline(4),
];
protected override bool OnKeyDown(KeyDownEvent e)
{
if (e.Repeat)
return false;
if (state != SliderPlacementState.ControlPoints)
return false;
switch (e.Key)
{
case Key.Tab:
{
usingCustomSegmentType = true;
int currentTypeIndex = segmentStart.Type.HasValue ? Array.IndexOf(path_types, segmentStart.Type.Value) : -1;
if (currentTypeIndex < 0 && e.ShiftPressed)
currentTypeIndex = 0;
do
{
currentTypeIndex = (path_types.Length + currentTypeIndex + (e.ShiftPressed ? -1 : 1)) % path_types.Length;
segmentStart.Type = path_types[currentTypeIndex];
controlPointVisualiser.EnsureValidPathTypes();
} while (segmentStart.Type != path_types[currentTypeIndex]);
return true;
}
}
return true;
}
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
@ -246,6 +288,12 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private void updatePathType() private void updatePathType()
{ {
if (usingCustomSegmentType)
{
controlPointVisualiser.EnsureValidPathTypes();
return;
}
if (state == SliderPlacementState.Drawing) if (state == SliderPlacementState.Drawing)
{ {
segmentStart.Type = PathType.BSpline(4); segmentStart.Type = PathType.BSpline(4);
@ -316,6 +364,13 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
return lastPiece.IsHovered != true; return lastPiece.IsHovered != true;
} }
private void placeNewControlPoint()
{
// Place a new point by detatching the current cursor.
updateCursor();
cursor = null;
}
private void updateSlider() private void updateSlider()
{ {
if (state == SliderPlacementState.Drawing) if (state == SliderPlacementState.Drawing)