mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 07:42:57 +08:00
Separate path connections from control points (#7136)
Separate path connections from control points Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
commit
f4ce703490
@ -0,0 +1,75 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Lines;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// A visualisation of the line between two <see cref="PathControlPointPiece"/>s.
|
||||
/// </summary>
|
||||
public class PathControlPointConnectionPiece : CompositeDrawable
|
||||
{
|
||||
public PathControlPoint ControlPoint;
|
||||
|
||||
private readonly Path path;
|
||||
private readonly Slider slider;
|
||||
|
||||
private IBindable<Vector2> sliderPosition;
|
||||
private IBindable<int> pathVersion;
|
||||
|
||||
public PathControlPointConnectionPiece(Slider slider, PathControlPoint controlPoint)
|
||||
{
|
||||
this.slider = slider;
|
||||
ControlPoint = controlPoint;
|
||||
|
||||
Origin = Anchor.Centre;
|
||||
AutoSizeAxes = Axes.Both;
|
||||
|
||||
InternalChild = path = new SmoothPath
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
PathRadius = 1
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
sliderPosition = slider.PositionBindable.GetBoundCopy();
|
||||
sliderPosition.BindValueChanged(_ => updateConnectingPath());
|
||||
|
||||
pathVersion = slider.Path.Version.GetBoundCopy();
|
||||
pathVersion.BindValueChanged(_ => updateConnectingPath());
|
||||
|
||||
updateConnectingPath();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the path connecting this control point to the next one.
|
||||
/// </summary>
|
||||
private void updateConnectingPath()
|
||||
{
|
||||
Position = slider.StackedPosition + ControlPoint.Position.Value;
|
||||
|
||||
path.ClearVertices();
|
||||
|
||||
int index = slider.Path.ControlPoints.IndexOf(ControlPoint) + 1;
|
||||
|
||||
if (index == 0 || index == slider.Path.ControlPoints.Count)
|
||||
return;
|
||||
|
||||
path.AddVertex(Vector2.Zero);
|
||||
path.AddVertex(slider.Path.ControlPoints[index].Position.Value - ControlPoint.Position.Value);
|
||||
|
||||
path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,6 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Lines;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics;
|
||||
@ -19,6 +18,9 @@ using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// A visualisation of a single <see cref="PathControlPoint"/> in a <see cref="Slider"/>.
|
||||
/// </summary>
|
||||
public class PathControlPointPiece : BlueprintPiece<Slider>
|
||||
{
|
||||
public Action<PathControlPointPiece, MouseButtonEvent> RequestSelection;
|
||||
@ -28,7 +30,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
public readonly PathControlPoint ControlPoint;
|
||||
|
||||
private readonly Slider slider;
|
||||
private readonly Path path;
|
||||
private readonly Container marker;
|
||||
private readonly Drawable markerRing;
|
||||
|
||||
@ -39,12 +40,11 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
private OsuColour colours { get; set; }
|
||||
|
||||
private IBindable<Vector2> sliderPosition;
|
||||
private IBindable<int> pathVersion;
|
||||
private IBindable<Vector2> controlPointPosition;
|
||||
|
||||
public PathControlPointPiece(Slider slider, PathControlPoint controlPoint)
|
||||
{
|
||||
this.slider = slider;
|
||||
|
||||
ControlPoint = controlPoint;
|
||||
|
||||
Origin = Anchor.Centre;
|
||||
@ -52,11 +52,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
path = new SmoothPath
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
PathRadius = 1
|
||||
},
|
||||
marker = new Container
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
@ -96,20 +91,14 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
base.LoadComplete();
|
||||
|
||||
sliderPosition = slider.PositionBindable.GetBoundCopy();
|
||||
sliderPosition.BindValueChanged(_ => updateDisplay());
|
||||
sliderPosition.BindValueChanged(_ => updateMarkerDisplay());
|
||||
|
||||
pathVersion = slider.Path.Version.GetBoundCopy();
|
||||
pathVersion.BindValueChanged(_ => updateDisplay());
|
||||
controlPointPosition = ControlPoint.Position.GetBoundCopy();
|
||||
controlPointPosition.BindValueChanged(_ => updateMarkerDisplay());
|
||||
|
||||
IsSelected.BindValueChanged(_ => updateMarkerDisplay());
|
||||
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
private void updateDisplay()
|
||||
{
|
||||
updateMarkerDisplay();
|
||||
updateConnectingPath();
|
||||
}
|
||||
|
||||
// The connecting path is excluded from positional input
|
||||
@ -189,26 +178,5 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
colour = Color4.White;
|
||||
marker.Colour = colour;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the path connecting this control point to the previous one.
|
||||
/// </summary>
|
||||
private void updateConnectingPath()
|
||||
{
|
||||
path.ClearVertices();
|
||||
|
||||
int index = slider.Path.ControlPoints.IndexOf(ControlPoint);
|
||||
|
||||
if (index == -1)
|
||||
return;
|
||||
|
||||
if (++index != slider.Path.ControlPoints.Count)
|
||||
{
|
||||
path.AddVertex(Vector2.Zero);
|
||||
path.AddVertex(slider.Path.ControlPoints[index].Position.Value - ControlPoint.Position.Value);
|
||||
}
|
||||
|
||||
path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
{
|
||||
internal readonly Container<PathControlPointPiece> Pieces;
|
||||
|
||||
private readonly Container<PathControlPointConnectionPiece> connections;
|
||||
|
||||
private readonly Slider slider;
|
||||
|
||||
private readonly bool allowSelection;
|
||||
@ -42,7 +44,11 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
InternalChild = Pieces = new Container<PathControlPointPiece> { RelativeSizeAxes = Axes.Both };
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
connections = new Container<PathControlPointConnectionPiece> { RelativeSizeAxes = Axes.Both },
|
||||
Pieces = new Container<PathControlPointPiece> { RelativeSizeAxes = Axes.Both }
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -62,19 +68,23 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
{
|
||||
foreach (var point in controlPoints)
|
||||
{
|
||||
var piece = new PathControlPointPiece(slider, point);
|
||||
Pieces.Add(new PathControlPointPiece(slider, point).With(d =>
|
||||
{
|
||||
if (allowSelection)
|
||||
d.RequestSelection = selectPiece;
|
||||
}));
|
||||
|
||||
if (allowSelection)
|
||||
piece.RequestSelection = selectPiece;
|
||||
|
||||
Pieces.Add(piece);
|
||||
connections.Add(new PathControlPointConnectionPiece(slider, point));
|
||||
}
|
||||
}
|
||||
|
||||
private void removeControlPoints(IEnumerable<PathControlPoint> controlPoints)
|
||||
{
|
||||
foreach (var point in controlPoints)
|
||||
{
|
||||
Pieces.RemoveAll(p => p.ControlPoint == point);
|
||||
connections.RemoveAll(c => c.ControlPoint == point);
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
|
Loading…
Reference in New Issue
Block a user