2018-10-29 13:07:06 +08:00
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
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;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks.Components
|
|
|
|
{
|
2018-11-01 02:52:24 +08:00
|
|
|
public class PathControlPointPiece : CompositeDrawable
|
2018-10-29 13:07:06 +08:00
|
|
|
{
|
|
|
|
private readonly Slider slider;
|
|
|
|
private readonly int index;
|
|
|
|
|
|
|
|
private readonly Path path;
|
|
|
|
private readonly CircularContainer marker;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
2018-11-01 02:52:24 +08:00
|
|
|
public PathControlPointPiece(Slider slider, int index)
|
2018-10-29 13:07:06 +08:00
|
|
|
{
|
|
|
|
this.slider = slider;
|
|
|
|
this.index = index;
|
|
|
|
|
|
|
|
Origin = Anchor.Centre;
|
2018-10-29 15:15:04 +08:00
|
|
|
AutoSizeAxes = Axes.Both;
|
2018-10-29 13:07:06 +08:00
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
path = new SmoothPath
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
PathWidth = 1
|
|
|
|
},
|
|
|
|
marker = new CircularContainer
|
|
|
|
{
|
2018-10-29 15:15:04 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2018-10-31 17:01:53 +08:00
|
|
|
Size = new Vector2(10),
|
2018-10-29 13:07:06 +08:00
|
|
|
Masking = true,
|
|
|
|
Child = new Box { RelativeSizeAxes = Axes.Both }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
Position = slider.StackedPosition + slider.ControlPoints[index];
|
|
|
|
|
2018-10-29 14:52:28 +08:00
|
|
|
marker.Colour = isSegmentSeparator ? colours.Red : colours.Yellow;
|
2018-10-29 13:07:06 +08:00
|
|
|
|
|
|
|
path.ClearVertices();
|
|
|
|
|
|
|
|
if (index != slider.ControlPoints.Length - 1)
|
|
|
|
{
|
|
|
|
path.AddVertex(Vector2.Zero);
|
|
|
|
path.AddVertex(slider.ControlPoints[index + 1] - slider.ControlPoints[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero);
|
|
|
|
}
|
|
|
|
|
2018-10-29 15:15:04 +08:00
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => marker.ReceivePositionalInputAt(screenSpacePos);
|
|
|
|
|
2018-10-29 13:07:06 +08:00
|
|
|
protected override bool OnDragStart(DragStartEvent e) => true;
|
|
|
|
|
|
|
|
protected override bool OnDrag(DragEvent e)
|
|
|
|
{
|
2018-10-31 17:02:08 +08:00
|
|
|
var newControlPoints = slider.ControlPoints.ToArray();
|
|
|
|
|
2018-10-29 14:36:43 +08:00
|
|
|
if (index == 0)
|
|
|
|
{
|
|
|
|
// Special handling for the head - only the position of the slider changes
|
|
|
|
slider.Position += e.Delta;
|
|
|
|
|
|
|
|
// Since control points are relative to the position of the slider, they all need to be offset backwards by the delta
|
|
|
|
for (int i = 1; i < newControlPoints.Length; i++)
|
|
|
|
newControlPoints[i] -= e.Delta;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
newControlPoints[index] += e.Delta;
|
2018-10-29 13:07:06 +08:00
|
|
|
|
2018-10-31 17:02:08 +08:00
|
|
|
if (isSegmentSeparatorWithNext)
|
|
|
|
newControlPoints[index + 1] = newControlPoints[index];
|
|
|
|
|
|
|
|
if (isSegmentSeparatorWithPrevious)
|
|
|
|
newControlPoints[index - 1] = newControlPoints[index];
|
|
|
|
|
|
|
|
slider.ControlPoints = newControlPoints;
|
2018-11-01 02:52:24 +08:00
|
|
|
slider.Path.Calculate(true);
|
2018-10-29 13:07:06 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnDragEnd(DragEndEvent e) => true;
|
|
|
|
|
2018-10-31 17:02:08 +08:00
|
|
|
private bool isSegmentSeparator => isSegmentSeparatorWithNext || isSegmentSeparatorWithPrevious;
|
2018-10-29 14:52:28 +08:00
|
|
|
|
2018-10-31 17:02:08 +08:00
|
|
|
private bool isSegmentSeparatorWithNext => index < slider.ControlPoints.Length - 1 && slider.ControlPoints[index + 1] == slider.ControlPoints[index];
|
2018-10-29 14:52:28 +08:00
|
|
|
|
2018-10-31 17:02:08 +08:00
|
|
|
private bool isSegmentSeparatorWithPrevious => index > 0 && slider.ControlPoints[index - 1] == slider.ControlPoints[index];
|
2018-10-29 13:07:06 +08:00
|
|
|
}
|
|
|
|
}
|