mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 11:42:56 +08:00
Implement slider path distance snapping
This commit is contained in:
parent
ef4dd3e028
commit
f45f17339c
@ -33,6 +33,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
|
||||
|
||||
private PlacementState state;
|
||||
|
||||
[Resolved]
|
||||
private HitObjectComposer composer { get; set; }
|
||||
|
||||
public SliderPlacementBlueprint()
|
||||
: base(new Objects.Slider())
|
||||
{
|
||||
@ -131,8 +134,12 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
|
||||
|
||||
private void updateSlider()
|
||||
{
|
||||
var newControlPoints = segments.SelectMany(s => s.ControlPoints).Concat(cursor.Yield()).ToArray();
|
||||
HitObject.Path = new SliderPath(newControlPoints.Length > 2 ? PathType.Bezier : PathType.Linear, newControlPoints);
|
||||
Vector2[] newControlPoints = segments.SelectMany(s => s.ControlPoints).Concat(cursor.Yield()).ToArray();
|
||||
|
||||
var unsnappedPath = new SliderPath(newControlPoints.Length > 2 ? PathType.Bezier : PathType.Linear, newControlPoints);
|
||||
var snappedDistance = composer.GetSnappedDistance((float)unsnappedPath.Distance);
|
||||
|
||||
HitObject.Path = new SliderPath(newControlPoints.Length > 2 ? PathType.Bezier : PathType.Linear, newControlPoints, snappedDistance);
|
||||
|
||||
bodyPiece.UpdateFrom(HitObject);
|
||||
headCirclePiece.UpdateFrom(HitObject.HeadCircle);
|
||||
|
@ -261,6 +261,8 @@ namespace osu.Game.Rulesets.Edit
|
||||
|
||||
public override double GetSnappedTime(double startTime, Vector2 position) => distanceSnapGrid?.GetSnapTime(position) ?? startTime;
|
||||
|
||||
public override float GetSnappedDistance(float distance) => distanceSnapGrid?.GetSnapDistance(distance) ?? distance;
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
@ -313,5 +315,7 @@ namespace osu.Game.Rulesets.Edit
|
||||
public abstract Vector2 GetSnappedPosition(Vector2 position);
|
||||
|
||||
public abstract double GetSnappedTime(double startTime, Vector2 screenSpacePosition);
|
||||
|
||||
public abstract float GetSnappedDistance(float distance);
|
||||
}
|
||||
}
|
||||
|
@ -128,6 +128,13 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
/// <returns>The time at the snapped position.</returns>
|
||||
public double GetSnapTime(Vector2 position) => startTime + (position - CentrePosition).Length / Velocity;
|
||||
|
||||
/// <summary>
|
||||
/// Snaps a distance by the snap distance of this grid.
|
||||
/// </summary>
|
||||
/// <param name="distance">The distance to snap.</param>
|
||||
/// <returns>The snapped distance.</returns>
|
||||
public float GetSnapDistance(float distance) => (int)(distance / DistanceSpacing) * DistanceSpacing;
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the applicable colour for a beat index.
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user