2019-01-24 16:43:03 +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.
|
2018-10-04 12:44:49 +08:00
|
|
|
|
2018-10-04 17:24:25 +08:00
|
|
|
using osu.Framework.Allocation;
|
2018-10-04 12:44:49 +08:00
|
|
|
using osu.Framework.Graphics;
|
2019-10-23 15:03:16 +08:00
|
|
|
using osu.Framework.Input;
|
2018-10-04 12:44:49 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2018-10-04 17:24:25 +08:00
|
|
|
using osu.Game.Graphics;
|
2018-10-04 12:44:49 +08:00
|
|
|
using osu.Game.Rulesets.Edit;
|
2018-11-12 12:55:14 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2018-10-04 12:44:49 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2019-09-27 17:45:22 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles.Components;
|
2018-11-07 15:08:56 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Input;
|
2018-10-04 12:44:49 +08:00
|
|
|
|
2018-11-07 15:08:56 +08:00
|
|
|
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
|
2018-10-04 12:44:49 +08:00
|
|
|
{
|
2018-11-06 17:04:03 +08:00
|
|
|
public class SliderPlacementBlueprint : PlacementBlueprint
|
2018-10-04 12:44:49 +08:00
|
|
|
{
|
2018-10-25 18:34:35 +08:00
|
|
|
public new Objects.Slider HitObject => (Objects.Slider)base.HitObject;
|
2018-10-04 12:44:49 +08:00
|
|
|
|
2019-09-27 17:45:22 +08:00
|
|
|
private SliderBodyPiece bodyPiece;
|
|
|
|
private HitCirclePiece headCirclePiece;
|
|
|
|
private HitCirclePiece tailCirclePiece;
|
|
|
|
|
2019-10-23 15:03:16 +08:00
|
|
|
private InputManager inputManager;
|
2018-10-04 12:44:49 +08:00
|
|
|
|
2018-10-04 17:24:25 +08:00
|
|
|
private PlacementState state;
|
2019-12-06 18:39:25 +08:00
|
|
|
private PathControlPoint segmentStart;
|
|
|
|
private PathControlPoint cursor;
|
2019-12-09 17:10:33 +08:00
|
|
|
private int currentSegmentLength;
|
2018-10-04 12:44:49 +08:00
|
|
|
|
2019-10-24 18:04:00 +08:00
|
|
|
[Resolved(CanBeNull = true)]
|
2019-10-24 17:09:20 +08:00
|
|
|
private HitObjectComposer composer { get; set; }
|
|
|
|
|
2018-11-06 17:04:03 +08:00
|
|
|
public SliderPlacementBlueprint()
|
2018-10-25 18:34:35 +08:00
|
|
|
: base(new Objects.Slider())
|
2018-10-04 12:44:49 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2019-12-06 18:39:25 +08:00
|
|
|
|
2019-12-09 17:10:33 +08:00
|
|
|
HitObject.Path.ControlPoints.Add(segmentStart = new PathControlPoint(Vector2.Zero, PathType.Linear));
|
|
|
|
currentSegmentLength = 1;
|
2018-10-24 12:42:51 +08:00
|
|
|
}
|
2018-10-04 12:44:49 +08:00
|
|
|
|
2018-10-24 12:42:51 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
2018-10-04 12:44:49 +08:00
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2019-09-27 17:45:22 +08:00
|
|
|
bodyPiece = new SliderBodyPiece(),
|
|
|
|
headCirclePiece = new HitCirclePiece(),
|
|
|
|
tailCirclePiece = new HitCirclePiece(),
|
2019-12-06 11:31:22 +08:00
|
|
|
new PathControlPointVisualiser(HitObject, false)
|
2018-10-04 12:44:49 +08:00
|
|
|
};
|
|
|
|
|
2018-10-04 17:24:25 +08:00
|
|
|
setState(PlacementState.Initial);
|
|
|
|
}
|
|
|
|
|
2019-10-23 15:03:16 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
inputManager = GetContainingInputManager();
|
|
|
|
}
|
|
|
|
|
2019-10-03 15:14:42 +08:00
|
|
|
public override void UpdatePosition(Vector2 screenSpacePosition)
|
2018-10-04 12:44:49 +08:00
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
2018-10-04 17:24:25 +08:00
|
|
|
case PlacementState.Initial:
|
2020-02-07 17:02:48 +08:00
|
|
|
BeginPlacement();
|
2019-10-03 15:14:42 +08:00
|
|
|
HitObject.Position = ToLocalSpace(screenSpacePosition);
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
2018-10-04 17:24:25 +08:00
|
|
|
case PlacementState.Body:
|
2019-12-06 18:39:25 +08:00
|
|
|
ensureCursor();
|
|
|
|
|
2019-10-23 16:58:44 +08:00
|
|
|
// The given screen-space position may have been externally snapped, but the unsnapped position from the input manager
|
|
|
|
// is used instead since snapping control points doesn't make much sense
|
2019-12-06 18:39:25 +08:00
|
|
|
cursor.Position.Value = ToLocalSpace(inputManager.CurrentState.Mouse.Position) - HitObject.Position;
|
2019-10-03 15:14:42 +08:00
|
|
|
break;
|
2018-10-04 12:44:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
2018-10-04 17:24:25 +08:00
|
|
|
case PlacementState.Initial:
|
|
|
|
beginCurve();
|
2018-10-04 12:44:49 +08:00
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
2018-10-04 17:24:25 +08:00
|
|
|
case PlacementState.Body:
|
|
|
|
switch (e.Button)
|
|
|
|
{
|
|
|
|
case MouseButton.Left:
|
2019-12-06 18:39:25 +08:00
|
|
|
ensureCursor();
|
|
|
|
|
|
|
|
// Detatch the cursor
|
|
|
|
cursor = null;
|
2018-10-04 17:24:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-10-04 12:44:49 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-10-04 17:24:25 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-20 17:17:21 +08:00
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
2018-10-04 17:24:25 +08:00
|
|
|
{
|
|
|
|
if (state == PlacementState.Body && e.Button == MouseButton.Right)
|
|
|
|
endCurve();
|
2020-01-20 17:17:21 +08:00
|
|
|
base.OnMouseUp(e);
|
2018-10-04 17:24:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnDoubleClick(DoubleClickEvent e)
|
|
|
|
{
|
2019-12-06 18:39:25 +08:00
|
|
|
// Todo: This should all not occur on double click, but rather if the previous control point is hovered.
|
2019-12-14 20:54:22 +08:00
|
|
|
segmentStart = HitObject.Path.ControlPoints[^1];
|
2019-12-06 18:39:25 +08:00
|
|
|
segmentStart.Type.Value = PathType.Linear;
|
|
|
|
|
|
|
|
currentSegmentLength = 1;
|
2018-10-04 17:24:25 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void beginCurve()
|
|
|
|
{
|
2020-02-13 08:03:48 +08:00
|
|
|
BeginPlacement(commitStart: true);
|
2018-10-04 17:24:25 +08:00
|
|
|
setState(PlacementState.Body);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void endCurve()
|
|
|
|
{
|
2018-11-01 18:23:37 +08:00
|
|
|
updateSlider();
|
2020-02-07 17:02:48 +08:00
|
|
|
EndPlacement(true);
|
2018-10-04 17:24:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
2018-11-01 18:23:37 +08:00
|
|
|
updateSlider();
|
|
|
|
}
|
2018-10-04 17:24:25 +08:00
|
|
|
|
2019-12-06 18:39:25 +08:00
|
|
|
private void updatePathType()
|
|
|
|
{
|
|
|
|
switch (currentSegmentLength)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
segmentStart.Type.Value = PathType.Linear;
|
|
|
|
break;
|
2019-12-09 15:44:19 +08:00
|
|
|
|
2019-12-06 18:39:25 +08:00
|
|
|
case 3:
|
|
|
|
segmentStart.Type.Value = PathType.PerfectCurve;
|
|
|
|
break;
|
2019-12-09 15:44:19 +08:00
|
|
|
|
2019-12-06 18:39:25 +08:00
|
|
|
default:
|
|
|
|
segmentStart.Type.Value = PathType.Bezier;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ensureCursor()
|
|
|
|
{
|
|
|
|
if (cursor == null)
|
|
|
|
{
|
|
|
|
HitObject.Path.ControlPoints.Add(cursor = new PathControlPoint { Position = { Value = Vector2.Zero } });
|
|
|
|
currentSegmentLength++;
|
|
|
|
|
|
|
|
updatePathType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-01 18:23:37 +08:00
|
|
|
private void updateSlider()
|
|
|
|
{
|
2019-12-06 14:53:19 +08:00
|
|
|
HitObject.Path.ExpectedDistance.Value = composer?.GetSnappedDistanceFromDistance(HitObject.StartTime, (float)HitObject.Path.CalculatedDistance) ?? (float)HitObject.Path.CalculatedDistance;
|
2019-09-27 17:45:22 +08:00
|
|
|
|
|
|
|
bodyPiece.UpdateFrom(HitObject);
|
|
|
|
headCirclePiece.UpdateFrom(HitObject.HeadCircle);
|
|
|
|
tailCirclePiece.UpdateFrom(HitObject.TailCircle);
|
2018-10-04 12:44:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setState(PlacementState newState)
|
|
|
|
{
|
|
|
|
state = newState;
|
|
|
|
}
|
|
|
|
|
|
|
|
private enum PlacementState
|
|
|
|
{
|
2018-10-04 17:24:25 +08:00
|
|
|
Initial,
|
2018-10-04 12:44:49 +08:00
|
|
|
Body,
|
2018-10-04 17:24:25 +08:00
|
|
|
}
|
2018-10-04 12:44:49 +08:00
|
|
|
}
|
|
|
|
}
|