2019-01-24 08:43:03 +00: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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-11-12 04:32:31 +00:00
|
|
|
|
using System;
|
2019-10-24 10:02:59 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-11-12 04:32:31 +00:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-10-24 10:02:59 +00:00
|
|
|
|
using osu.Game.Rulesets.Edit;
|
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2018-11-07 07:08:56 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2019-11-12 04:32:31 +00:00
|
|
|
|
using osuTK.Input;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-07 07:08:56 +00:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-11-12 04:38:42 +00:00
|
|
|
|
public class SliderSelectionBlueprint : OsuSelectionBlueprint<Slider>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-10-01 10:33:24 +00:00
|
|
|
|
protected readonly SliderBodyPiece BodyPiece;
|
|
|
|
|
protected readonly SliderCircleSelectionBlueprint HeadBlueprint;
|
|
|
|
|
protected readonly SliderCircleSelectionBlueprint TailBlueprint;
|
2019-10-31 07:51:58 +00:00
|
|
|
|
protected readonly PathControlPointVisualiser ControlPointVisualiser;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-10-24 10:04:00 +00:00
|
|
|
|
[Resolved(CanBeNull = true)]
|
2019-10-24 10:02:59 +00:00
|
|
|
|
private HitObjectComposer composer { get; set; }
|
|
|
|
|
|
2018-11-06 08:56:04 +00:00
|
|
|
|
public SliderSelectionBlueprint(DrawableSlider slider)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
: base(slider)
|
|
|
|
|
{
|
|
|
|
|
var sliderObject = (Slider)slider.HitObject;
|
|
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
2019-10-01 10:33:24 +00:00
|
|
|
|
BodyPiece = new SliderBodyPiece(),
|
|
|
|
|
HeadBlueprint = CreateCircleSelectionBlueprint(slider, SliderPosition.Start),
|
|
|
|
|
TailBlueprint = CreateCircleSelectionBlueprint(slider, SliderPosition.End),
|
2019-11-03 10:59:37 +00:00
|
|
|
|
ControlPointVisualiser = new PathControlPointVisualiser(sliderObject, true) { ControlPointsChanged = onNewControlPoints },
|
2018-04-13 09:19:50 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-27 09:45:22 +00:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2019-10-01 10:33:24 +00:00
|
|
|
|
BodyPiece.UpdateFrom(HitObject);
|
2019-09-27 09:45:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-12 04:32:31 +00:00
|
|
|
|
private Vector2 rightClickPosition;
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button == MouseButton.Right)
|
|
|
|
|
rightClickPosition = e.MouseDownPosition;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addControlPoint()
|
|
|
|
|
{
|
|
|
|
|
Vector2 position = rightClickPosition - HitObject.Position;
|
|
|
|
|
|
|
|
|
|
var controlPoints = new Vector2[HitObject.Path.ControlPoints.Length + 1];
|
|
|
|
|
HitObject.Path.ControlPoints.CopyTo(controlPoints);
|
|
|
|
|
|
|
|
|
|
// Find the index at which the point will be inserted, by increasing x-coordinates
|
|
|
|
|
int insertionIndex = Array.FindIndex(controlPoints, 0, controlPoints.Length - 1, c => c.X >= position.X);
|
|
|
|
|
|
|
|
|
|
// If no index was found, it should be inserted at the end
|
|
|
|
|
if (insertionIndex == -1)
|
|
|
|
|
insertionIndex = controlPoints.Length - 1;
|
|
|
|
|
|
|
|
|
|
// Move the control points from the insertion index onwards to make room for the insertion
|
|
|
|
|
Array.Copy(controlPoints, insertionIndex, controlPoints, insertionIndex + 1, controlPoints.Length - insertionIndex - 1);
|
|
|
|
|
|
|
|
|
|
if (insertionIndex == 0)
|
|
|
|
|
{
|
|
|
|
|
// Special case for a new first control point being added - the entire slider moves
|
|
|
|
|
HitObject.Position += position;
|
|
|
|
|
|
|
|
|
|
// The first control point is always at (0, 0), but all other control points need to be re-referenced
|
|
|
|
|
for (int i = 1; i < controlPoints.Length; i++)
|
|
|
|
|
controlPoints[i] -= position;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
controlPoints[insertionIndex] = position;
|
|
|
|
|
|
|
|
|
|
onNewControlPoints(controlPoints);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 10:02:59 +00:00
|
|
|
|
private void onNewControlPoints(Vector2[] controlPoints)
|
|
|
|
|
{
|
|
|
|
|
var unsnappedPath = new SliderPath(controlPoints.Length > 2 ? PathType.Bezier : PathType.Linear, controlPoints);
|
2019-10-25 03:34:49 +00:00
|
|
|
|
var snappedDistance = composer?.GetSnappedDistanceFromDistance(HitObject.StartTime, (float)unsnappedPath.Distance) ?? (float)unsnappedPath.Distance;
|
2019-10-24 10:02:59 +00:00
|
|
|
|
|
|
|
|
|
HitObject.Path = new SliderPath(unsnappedPath.Type, controlPoints, snappedDistance);
|
2019-10-31 09:24:38 +00:00
|
|
|
|
|
|
|
|
|
UpdateHitObject();
|
2019-10-24 10:02:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-12 04:38:42 +00:00
|
|
|
|
public override MenuItem[] ContextMenuItems => new MenuItem[]
|
2019-11-12 04:32:31 +00:00
|
|
|
|
{
|
|
|
|
|
new OsuMenuItem("Add control point", MenuItemType.Standard, addControlPoint),
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-01 10:33:24 +00:00
|
|
|
|
public override Vector2 SelectionPoint => HeadBlueprint.SelectionPoint;
|
|
|
|
|
|
2019-10-25 09:37:44 +00:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => BodyPiece.ReceivePositionalInputAt(screenSpacePos);
|
|
|
|
|
|
2019-10-01 10:33:24 +00:00
|
|
|
|
protected virtual SliderCircleSelectionBlueprint CreateCircleSelectionBlueprint(DrawableSlider slider, SliderPosition position) => new SliderCircleSelectionBlueprint(slider, position);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|