diff --git a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointPiece.cs b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointPiece.cs index 9b40b39a9d..8ddc38c38e 100644 --- a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointPiece.cs +++ b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointPiece.cs @@ -37,8 +37,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components public Action DragInProgress; public Action DragEnded; - public List PointsInSegment; - public readonly BindableBool IsSelected = new BindableBool(); public readonly PathControlPoint ControlPoint; diff --git a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs index a02a07f2b6..d057565c2b 100644 --- a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs +++ b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs @@ -9,7 +9,6 @@ using System.Collections.Specialized; using System.Diagnostics; using System.Linq; using Humanizer; -using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -55,9 +54,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components [Resolved(CanBeNull = true)] private IDistanceSnapProvider distanceSnapProvider { get; set; } - [UsedImplicitly] - private readonly IBindable hitObjectVersion; - public PathControlPointVisualiser(T hitObject, bool allowSelection) { this.hitObject = hitObject; @@ -70,8 +66,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components Connections = new Container> { RelativeSizeAxes = Axes.Both }, Pieces = new Container> { RelativeSizeAxes = Axes.Both } }; - - hitObjectVersion = hitObject.Path.Version.GetBoundCopy(); } protected override void LoadComplete() @@ -85,20 +79,20 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components // schedule ensure that updates are only applied after all operations from a single frame are applied. // this avoids inadvertently changing the hit object path type for batch operations. - hitObject.Path.Validating += cachePointsAndEnsureValidPathTypes; + hitObject.Path.Validating += ensureValidPathTypes; } protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); - hitObject.Path.Validating -= cachePointsAndEnsureValidPathTypes; + hitObject.Path.Validating -= ensureValidPathTypes; } /// - /// Caches the PointsInSegment of Pieces and handles correction of invalid path types. + /// Handles correction of invalid path types. /// - private void cachePointsAndEnsureValidPathTypes() + private void ensureValidPathTypes() { List pointsInCurrentSegment = new List(); @@ -107,31 +101,33 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components if (controlPoint.Type != null) { pointsInCurrentSegment.Add(controlPoint); - pointsInCurrentSegment = new List(); + ensureValidPathType(pointsInCurrentSegment); + pointsInCurrentSegment.Clear(); } pointsInCurrentSegment.Add(controlPoint); - - // Pieces might not be ordered so we need to find the piece corresponding to the current control point. - Pieces.Single(o => o.ControlPoint == controlPoint).PointsInSegment = pointsInCurrentSegment; } - foreach (var piece in Pieces) - { - if (piece.ControlPoint.Type != PathType.PERFECT_CURVE) - continue; + ensureValidPathType(pointsInCurrentSegment); + } - if (piece.PointsInSegment.Count > 3) - piece.ControlPoint.Type = PathType.BEZIER; + private void ensureValidPathType(IReadOnlyList segment) + { + var first = segment[0]; - if (piece.PointsInSegment.Count != 3) - continue; + if (first.Type != PathType.PERFECT_CURVE) + return; - ReadOnlySpan points = piece.PointsInSegment.Select(p => p.Position).ToArray(); - RectangleF boundingBox = PathApproximator.CircularArcBoundingBox(points); - if (boundingBox.Width >= 640 || boundingBox.Height >= 480) - piece.ControlPoint.Type = PathType.BEZIER; - } + if (segment.Count > 3) + first.Type = PathType.BEZIER; + + if (segment.Count != 3) + return; + + ReadOnlySpan points = segment.Select(p => p.Position).ToArray(); + RectangleF boundingBox = PathApproximator.CircularArcBoundingBox(points); + if (boundingBox.Width >= 640 || boundingBox.Height >= 480) + first.Type = PathType.BEZIER; } /// @@ -298,7 +294,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components /// The path type we want to assign to the given control point piece. private void updatePathType(PathControlPointPiece piece, PathType? type) { - int indexInSegment = piece.PointsInSegment.IndexOf(piece.ControlPoint); + var pointsInSegment = hitObject.Path.PointsInSegment(piece.ControlPoint); + int indexInSegment = pointsInSegment.IndexOf(piece.ControlPoint); if (type?.Type == SplineType.PerfectCurve) { @@ -307,8 +304,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components // and one segment of the previous type. int thirdPointIndex = indexInSegment + 2; - if (piece.PointsInSegment.Count > thirdPointIndex + 1) - piece.PointsInSegment[thirdPointIndex].Type = piece.PointsInSegment[0].Type; + if (pointsInSegment.Count > thirdPointIndex + 1) + pointsInSegment[thirdPointIndex].Type = pointsInSegment[0].Type; } hitObject.Path.ExpectedDistance.Value = null;