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
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2018-10-04 17:24:25 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
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;
|
|
|
|
|
2018-10-04 17:24:25 +08:00
|
|
|
private readonly List<Segment> segments = new List<Segment>();
|
|
|
|
private Vector2 cursor;
|
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;
|
2018-10-04 12:44:49 +08:00
|
|
|
|
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;
|
2018-10-24 12:42:51 +08:00
|
|
|
segments.Add(new Segment(Vector2.Zero));
|
|
|
|
}
|
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(),
|
2018-11-01 16:59:37 +08:00
|
|
|
new PathControlPointVisualiser(HitObject),
|
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:
|
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-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-10-23 15:03:16 +08:00
|
|
|
cursor = 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:
|
|
|
|
segments.Last().ControlPoints.Add(cursor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-10-04 12:44:49 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-10-04 17:24:25 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnMouseUp(MouseUpEvent e)
|
|
|
|
{
|
|
|
|
if (state == PlacementState.Body && e.Button == MouseButton.Right)
|
|
|
|
endCurve();
|
|
|
|
return base.OnMouseUp(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnDoubleClick(DoubleClickEvent e)
|
|
|
|
{
|
|
|
|
segments.Add(new Segment(segments[segments.Count - 1].ControlPoints.Last()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void beginCurve()
|
|
|
|
{
|
2018-10-17 17:20:39 +08:00
|
|
|
BeginPlacement();
|
2018-10-04 17:24:25 +08:00
|
|
|
setState(PlacementState.Body);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void endCurve()
|
|
|
|
{
|
2018-11-01 18:23:37 +08:00
|
|
|
updateSlider();
|
2018-10-17 17:20:39 +08:00
|
|
|
EndPlacement();
|
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
|
|
|
|
2018-11-01 18:23:37 +08:00
|
|
|
private void updateSlider()
|
|
|
|
{
|
2018-11-12 12:55:14 +08:00
|
|
|
var newControlPoints = segments.SelectMany(s => s.ControlPoints).Concat(cursor.Yield()).ToArray();
|
|
|
|
HitObject.Path = new SliderPath(newControlPoints.Length > 2 ? PathType.Bezier : PathType.Linear, newControlPoints);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
private class Segment
|
|
|
|
{
|
|
|
|
public readonly List<Vector2> ControlPoints = new List<Vector2>();
|
|
|
|
|
|
|
|
public Segment(Vector2 offset)
|
|
|
|
{
|
|
|
|
ControlPoints.Add(offset);
|
|
|
|
}
|
2018-10-04 12:44:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|