2021-07-22 14:41:01 +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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using osu.Game.Rulesets.Catch.Objects;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.Edit.Blueprints.Components
|
|
|
|
{
|
|
|
|
public class PlacementEditablePath : EditablePath
|
|
|
|
{
|
2021-07-23 09:13:55 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The original position of the last added vertex.
|
|
|
|
/// This is not same as the last vertex of the current path because the vertex ordering can change.
|
|
|
|
/// </summary>
|
|
|
|
private JuiceStreamPathVertex lastVertex;
|
2021-07-22 14:41:01 +08:00
|
|
|
|
2022-05-08 17:32:01 +08:00
|
|
|
public PlacementEditablePath(Func<float, double> positionToTime)
|
|
|
|
: base(positionToTime)
|
2021-07-22 14:41:01 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddNewVertex()
|
|
|
|
{
|
|
|
|
var endVertex = Vertices[^1];
|
2022-05-08 17:32:01 +08:00
|
|
|
int index = AddVertex(endVertex.Time, endVertex.X);
|
2021-07-22 14:41:01 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < VertexCount; i++)
|
|
|
|
{
|
|
|
|
VertexStates[i].IsSelected = i == index;
|
2021-07-23 09:17:42 +08:00
|
|
|
VertexStates[i].IsFixed = i != index;
|
2021-07-22 14:41:01 +08:00
|
|
|
VertexStates[i].VertexBeforeChange = Vertices[i];
|
|
|
|
}
|
|
|
|
|
2021-07-23 09:13:55 +08:00
|
|
|
lastVertex = Vertices[index];
|
2021-07-22 14:41:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Move the vertex added by <see cref="AddNewVertex"/> in the last time.
|
|
|
|
/// </summary>
|
|
|
|
public void MoveLastVertex(Vector2 screenSpacePosition)
|
|
|
|
{
|
|
|
|
Vector2 position = ToRelativePosition(screenSpacePosition);
|
2022-05-08 17:32:01 +08:00
|
|
|
double timeDelta = PositionToTime(position.Y) - lastVertex.Time;
|
2021-07-23 09:13:55 +08:00
|
|
|
float xDelta = position.X - lastVertex.X;
|
2022-05-08 17:32:01 +08:00
|
|
|
MoveSelectedVertices(timeDelta, xDelta);
|
2021-07-22 14:41:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|