Add initial path type progression support

This commit is contained in:
smoogipoo 2019-12-06 19:39:25 +09:00
parent 52dd7bf716
commit 41437242a2
1 changed files with 46 additions and 5 deletions

View File

@ -30,6 +30,9 @@ public class SliderPlacementBlueprint : PlacementBlueprint
private InputManager inputManager;
private PlacementState state;
private PathControlPoint segmentStart;
private PathControlPoint cursor;
private int currentSegmentLength = 1;
[Resolved(CanBeNull = true)]
private HitObjectComposer composer { get; set; }
@ -38,7 +41,9 @@ public SliderPlacementBlueprint()
: base(new Objects.Slider())
{
RelativeSizeAxes = Axes.Both;
HitObject.Path.ControlPoints.Add(new PathControlPoint { Position = { Value = Vector2.Zero } });
segmentStart = HitObject.Path.ControlPoints[0];
}
[BackgroundDependencyLoader]
@ -70,9 +75,11 @@ public override void UpdatePosition(Vector2 screenSpacePosition)
break;
case PlacementState.Body:
ensureCursor();
// The given screen-space position may have been externally snapped, but the unsnapped position from the input manager
// is used instead since snapping control points doesn't make much sense
HitObject.Path.ControlPoints.Last().Position.Value = ToLocalSpace(inputManager.CurrentState.Mouse.Position) - HitObject.Position;
cursor.Position.Value = ToLocalSpace(inputManager.CurrentState.Mouse.Position) - HitObject.Position;
break;
}
}
@ -89,7 +96,10 @@ protected override bool OnClick(ClickEvent e)
switch (e.Button)
{
case MouseButton.Left:
HitObject.Path.ControlPoints.Add(new PathControlPoint { Position = { Value = HitObject.Path.ControlPoints.Last().Position.Value } });
ensureCursor();
// Detatch the cursor
cursor = null;
break;
}
@ -108,8 +118,11 @@ protected override bool OnMouseUp(MouseUpEvent e)
protected override bool OnDoubleClick(DoubleClickEvent e)
{
// At the point of a double click, there's guaranteed to be at least two points - one from the click, and one from the cursor
HitObject.Path.ControlPoints[HitObject.Path.ControlPoints.Count - 2].Type.Value = PathType.Bezier;
// Todo: This should all not occur on double click, but rather if the previous control point is hovered.
segmentStart = HitObject.Path.ControlPoints[HitObject.Path.ControlPoints.Count - 1];
segmentStart.Type.Value = PathType.Linear;
currentSegmentLength = 1;
return true;
}
@ -131,6 +144,34 @@ protected override void Update()
updateSlider();
}
private void updatePathType()
{
switch (currentSegmentLength)
{
case 1:
case 2:
segmentStart.Type.Value = PathType.Linear;
break;
case 3:
segmentStart.Type.Value = PathType.PerfectCurve;
break;
default:
segmentStart.Type.Value = PathType.Bezier;
break;
}
}
private void ensureCursor()
{
if (cursor == null)
{
HitObject.Path.ControlPoints.Add(cursor = new PathControlPoint { Position = { Value = Vector2.Zero } });
currentSegmentLength++;
updatePathType();
}
}
private void updateSlider()
{
HitObject.Path.ExpectedDistance.Value = composer?.GetSnappedDistanceFromDistance(HitObject.StartTime, (float)HitObject.Path.CalculatedDistance) ?? (float)HitObject.Path.CalculatedDistance;