2019-12-10 10:20:08 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2019-12-10 10:20:08 +08:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Lines;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2022-11-03 19:25:23 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2019-12-10 10:20:08 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
|
|
|
{
|
2019-12-11 19:14:16 +08:00
|
|
|
/// <summary>
|
2022-11-03 19:25:23 +08:00
|
|
|
/// A visualisation of the line between two <see cref="PathControlPointPiece{T}"/>s.
|
2019-12-11 19:14:16 +08:00
|
|
|
/// </summary>
|
2022-11-03 19:25:23 +08:00
|
|
|
/// <typeparam name="T">The type of <see cref="OsuHitObject"/> which this <see cref="PathControlPointConnectionPiece{T}"/> visualises.</typeparam>
|
|
|
|
public partial class PathControlPointConnectionPiece<T> : CompositeDrawable where T : OsuHitObject, IHasPath
|
2019-12-10 10:20:08 +08:00
|
|
|
{
|
2020-04-13 15:13:14 +08:00
|
|
|
public readonly PathControlPoint ControlPoint;
|
2019-12-10 10:20:08 +08:00
|
|
|
|
|
|
|
private readonly Path path;
|
2022-11-03 19:25:23 +08:00
|
|
|
private readonly T hitObject;
|
2020-11-18 05:23:46 +08:00
|
|
|
public int ControlPointIndex { get; set; }
|
2019-12-10 10:20:08 +08:00
|
|
|
|
2022-11-03 19:25:23 +08:00
|
|
|
private IBindable<Vector2> hitObjectPosition;
|
2019-12-10 10:20:08 +08:00
|
|
|
private IBindable<int> pathVersion;
|
|
|
|
|
2022-11-03 19:25:23 +08:00
|
|
|
public PathControlPointConnectionPiece(T hitObject, int controlPointIndex)
|
2019-12-10 10:20:08 +08:00
|
|
|
{
|
2022-11-03 19:25:23 +08:00
|
|
|
this.hitObject = hitObject;
|
2020-11-18 05:23:46 +08:00
|
|
|
ControlPointIndex = controlPointIndex;
|
2019-12-10 10:20:08 +08:00
|
|
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
2022-11-03 19:25:23 +08:00
|
|
|
ControlPoint = hitObject.Path.ControlPoints[controlPointIndex];
|
2020-04-13 15:13:14 +08:00
|
|
|
|
2019-12-10 10:20:08 +08:00
|
|
|
InternalChild = path = new SmoothPath
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
PathRadius = 1
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-11-03 19:25:23 +08:00
|
|
|
hitObjectPosition = hitObject.PositionBindable.GetBoundCopy();
|
|
|
|
hitObjectPosition.BindValueChanged(_ => updateConnectingPath());
|
2019-12-10 10:20:08 +08:00
|
|
|
|
2022-11-03 19:25:23 +08:00
|
|
|
pathVersion = hitObject.Path.Version.GetBoundCopy();
|
2019-12-10 10:20:08 +08:00
|
|
|
pathVersion.BindValueChanged(_ => updateConnectingPath());
|
|
|
|
|
|
|
|
updateConnectingPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates the path connecting this control point to the next one.
|
|
|
|
/// </summary>
|
|
|
|
private void updateConnectingPath()
|
|
|
|
{
|
2022-11-03 19:25:23 +08:00
|
|
|
Position = hitObject.StackedPosition + ControlPoint.Position;
|
2019-12-10 10:20:08 +08:00
|
|
|
|
|
|
|
path.ClearVertices();
|
|
|
|
|
2020-11-18 05:23:46 +08:00
|
|
|
int nextIndex = ControlPointIndex + 1;
|
2022-11-03 19:25:23 +08:00
|
|
|
if (nextIndex == 0 || nextIndex >= hitObject.Path.ControlPoints.Count)
|
2019-12-10 10:20:08 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
path.AddVertex(Vector2.Zero);
|
2022-11-03 19:25:23 +08:00
|
|
|
path.AddVertex(hitObject.Path.ControlPoints[nextIndex].Position - ControlPoint.Position);
|
2019-12-10 10:20:08 +08:00
|
|
|
|
|
|
|
path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|