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;
|
|
|
|
|
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
|
|
|
|
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-05 18:53:31 +08:00
|
|
|
HitObject.Path.ControlPoints.Add(new PathControlPoint { Position = { Value = Vector2.Zero } });
|
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:
|
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-12-06 12:08:28 +08:00
|
|
|
HitObject.Path.ControlPoints.Last().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 12:08:28 +08:00
|
|
|
HitObject.Path.ControlPoints.Add(new PathControlPoint { Position = { Value = HitObject.Path.ControlPoints.Last().Position.Value } });
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2019-12-06 12:08:28 +08:00
|
|
|
// At the point of a double click, there's guaranteed to be at least two points - one from the click, and one from the cursor
|
2019-12-05 18:53:31 +08:00
|
|
|
HitObject.Path.ControlPoints[HitObject.Path.ControlPoints.Count - 2].Type.Value = PathType.Bezier;
|
2018-10-04 17:24:25 +08:00
|
|
|
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()
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|