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-29 13:07:06 +08:00
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2019-10-24 18:02:59 +08:00
|
|
|
using System;
|
2018-10-29 13:07:06 +08:00
|
|
|
using osu.Framework.Allocation;
|
2019-10-31 15:23:54 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-04-13 20:59:23 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2018-10-29 13:07:06 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-03-19 15:58:08 +08:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2018-10-29 13:07:06 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
2021-06-26 01:10:04 +08:00
|
|
|
using osu.Framework.Localisation;
|
2018-10-29 13:07:06 +08:00
|
|
|
using osu.Game.Graphics;
|
2019-12-09 19:49:59 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2021-03-19 13:00:26 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2018-10-29 13:07:06 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
2019-10-31 15:23:54 +08:00
|
|
|
using osuTK.Graphics;
|
2019-11-12 17:35:28 +08:00
|
|
|
using osuTK.Input;
|
2018-10-29 13:07:06 +08:00
|
|
|
|
2018-11-07 15:08:56 +08:00
|
|
|
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
2018-10-29 13:07:06 +08:00
|
|
|
{
|
2019-12-11 19:14:16 +08:00
|
|
|
/// <summary>
|
2022-11-03 19:25:23 +08:00
|
|
|
/// A visualisation of a single <see cref="PathControlPoint"/> in an osu hit object with a path.
|
2019-12-11 19:14:16 +08:00
|
|
|
/// </summary>
|
2022-11-03 19:25:23 +08:00
|
|
|
/// <typeparam name="T">The type of <see cref="OsuHitObject"/> which this <see cref="PathControlPointPiece{T}"/> visualises.</typeparam>
|
2023-01-26 16:12:41 +08:00
|
|
|
public partial class PathControlPointPiece<T> : BlueprintPiece<T>, IHasTooltip
|
|
|
|
where T : OsuHitObject, IHasPath
|
2018-10-29 13:07:06 +08:00
|
|
|
{
|
2022-11-03 19:25:23 +08:00
|
|
|
public Action<PathControlPointPiece<T>, MouseButtonEvent> RequestSelection;
|
2021-12-21 03:56:06 +08:00
|
|
|
|
2021-12-21 19:35:48 +08:00
|
|
|
public Action<PathControlPoint> DragStarted;
|
2021-12-21 04:29:57 +08:00
|
|
|
public Action<DragEvent> DragInProgress;
|
2021-12-21 03:56:06 +08:00
|
|
|
public Action DragEnded;
|
|
|
|
|
2019-11-03 17:41:29 +08:00
|
|
|
public readonly BindableBool IsSelected = new BindableBool();
|
2019-12-09 19:49:59 +08:00
|
|
|
public readonly PathControlPoint ControlPoint;
|
2018-10-29 13:07:06 +08:00
|
|
|
|
2022-11-03 19:25:23 +08:00
|
|
|
private readonly T hitObject;
|
2019-10-31 15:23:54 +08:00
|
|
|
private readonly Container marker;
|
|
|
|
private readonly Drawable markerRing;
|
2018-10-29 13:07:06 +08:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
2022-11-03 19:25:23 +08:00
|
|
|
private IBindable<Vector2> hitObjectPosition;
|
|
|
|
private IBindable<float> hitObjectScale;
|
2024-04-01 14:31:34 +08:00
|
|
|
private IBindable<int> stackHeight;
|
2019-12-09 19:49:59 +08:00
|
|
|
|
2022-11-03 19:25:23 +08:00
|
|
|
public PathControlPointPiece(T hitObject, PathControlPoint controlPoint)
|
2018-10-29 13:07:06 +08:00
|
|
|
{
|
2022-11-03 19:25:23 +08:00
|
|
|
this.hitObject = hitObject;
|
2019-12-09 19:49:59 +08:00
|
|
|
ControlPoint = controlPoint;
|
2021-04-13 14:35:57 +08:00
|
|
|
|
2021-08-26 00:42:57 +08:00
|
|
|
controlPoint.Changed += updateMarkerDisplay;
|
2020-04-13 20:59:23 +08:00
|
|
|
|
2018-10-29 13:07:06 +08:00
|
|
|
Origin = Anchor.Centre;
|
2018-10-29 15:15:04 +08:00
|
|
|
AutoSizeAxes = Axes.Both;
|
2018-10-29 13:07:06 +08:00
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2019-10-31 15:23:54 +08:00
|
|
|
marker = new Container
|
2018-10-29 13:07:06 +08:00
|
|
|
{
|
2018-10-29 15:15:04 +08:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2019-10-31 15:23:54 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
new Circle
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2020-12-01 13:17:36 +08:00
|
|
|
Size = new Vector2(20),
|
2019-10-31 15:23:54 +08:00
|
|
|
},
|
|
|
|
markerRing = new CircularContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2020-12-01 13:17:36 +08:00
|
|
|
Size = new Vector2(28),
|
2019-10-31 15:23:54 +08:00
|
|
|
Masking = true,
|
|
|
|
BorderThickness = 2,
|
|
|
|
BorderColour = Color4.White,
|
|
|
|
Alpha = 0,
|
|
|
|
Child = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0,
|
|
|
|
AlwaysPresent = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-29 13:07:06 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-12-09 19:49:59 +08:00
|
|
|
protected override void LoadComplete()
|
2018-10-29 13:07:06 +08:00
|
|
|
{
|
2019-12-09 19:49:59 +08:00
|
|
|
base.LoadComplete();
|
2018-10-29 13:07:06 +08:00
|
|
|
|
2022-11-03 19:25:23 +08:00
|
|
|
hitObjectPosition = hitObject.PositionBindable.GetBoundCopy();
|
|
|
|
hitObjectPosition.BindValueChanged(_ => updateMarkerDisplay());
|
2019-10-31 15:23:54 +08:00
|
|
|
|
2022-11-03 19:25:23 +08:00
|
|
|
hitObjectScale = hitObject.ScaleBindable.GetBoundCopy();
|
|
|
|
hitObjectScale.BindValueChanged(_ => updateMarkerDisplay());
|
2020-12-01 13:17:36 +08:00
|
|
|
|
2024-04-01 14:31:34 +08:00
|
|
|
stackHeight = hitObject.StackHeightBindable.GetBoundCopy();
|
|
|
|
stackHeight.BindValueChanged(_ => updateMarkerDisplay());
|
2024-03-31 08:23:05 +08:00
|
|
|
|
2019-12-09 19:49:59 +08:00
|
|
|
IsSelected.BindValueChanged(_ => updateMarkerDisplay());
|
2018-10-29 13:07:06 +08:00
|
|
|
|
2019-12-09 19:49:59 +08:00
|
|
|
updateMarkerDisplay();
|
2018-10-29 13:07:06 +08:00
|
|
|
}
|
|
|
|
|
2019-10-31 15:23:54 +08:00
|
|
|
// The connecting path is excluded from positional input
|
2018-10-29 15:15:04 +08:00
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => marker.ReceivePositionalInputAt(screenSpacePos);
|
|
|
|
|
2019-12-09 19:49:59 +08:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
updateMarkerDisplay();
|
2019-12-09 23:08:38 +08:00
|
|
|
return false;
|
2019-12-09 19:49:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
updateMarkerDisplay();
|
|
|
|
}
|
|
|
|
|
2021-12-21 04:53:51 +08:00
|
|
|
// Used to pair up mouse down/drag events with their corresponding mouse up events,
|
|
|
|
// to avoid deselecting the piece by accident when the mouse up corresponding to the mouse down/drag fires.
|
|
|
|
private bool keepSelection;
|
2021-12-21 04:18:38 +08:00
|
|
|
|
2019-10-31 16:13:10 +08:00
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
|
|
{
|
2019-11-13 16:28:18 +08:00
|
|
|
if (RequestSelection == null)
|
2019-11-12 17:35:28 +08:00
|
|
|
return false;
|
|
|
|
|
2019-11-13 16:28:18 +08:00
|
|
|
switch (e.Button)
|
2019-11-03 18:59:37 +08:00
|
|
|
{
|
2019-11-13 16:28:18 +08:00
|
|
|
case MouseButton.Left:
|
2021-12-21 04:56:06 +08:00
|
|
|
// if control is pressed, do not do anything as the user may be adding to current selection
|
|
|
|
// or dragging all currently selected control points.
|
|
|
|
// if it isn't and the user's intent is to deselect, deselection will happen on mouse up.
|
|
|
|
if (e.ControlPressed && IsSelected.Value)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
RequestSelection.Invoke(this, e);
|
|
|
|
keepSelection = true;
|
2021-12-21 04:18:38 +08:00
|
|
|
|
2019-11-13 16:28:18 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case MouseButton.Right:
|
|
|
|
if (!IsSelected.Value)
|
2019-12-09 19:49:59 +08:00
|
|
|
RequestSelection.Invoke(this, e);
|
2021-12-22 15:55:26 +08:00
|
|
|
|
|
|
|
keepSelection = true;
|
2019-11-13 16:28:18 +08:00
|
|
|
return false; // Allow context menu to show
|
2019-11-03 18:59:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2019-10-31 16:13:10 +08:00
|
|
|
}
|
|
|
|
|
2021-12-21 04:18:38 +08:00
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
|
|
|
{
|
|
|
|
base.OnMouseUp(e);
|
|
|
|
|
|
|
|
// ctrl+click deselects this piece, but only if this event
|
2021-12-21 04:53:51 +08:00
|
|
|
// wasn't immediately preceded by a matching mouse down or drag.
|
|
|
|
if (IsSelected.Value && e.ControlPressed && !keepSelection)
|
2021-12-21 04:18:38 +08:00
|
|
|
IsSelected.Value = false;
|
|
|
|
|
2021-12-21 04:53:51 +08:00
|
|
|
keepSelection = false;
|
2021-12-21 04:18:38 +08:00
|
|
|
}
|
|
|
|
|
2019-11-13 16:28:18 +08:00
|
|
|
protected override bool OnClick(ClickEvent e) => RequestSelection != null;
|
2019-11-05 01:21:50 +08:00
|
|
|
|
2020-04-09 21:00:56 +08:00
|
|
|
protected override bool OnDragStart(DragStartEvent e)
|
|
|
|
{
|
2020-04-23 11:17:11 +08:00
|
|
|
if (RequestSelection == null)
|
|
|
|
return false;
|
|
|
|
|
2020-04-09 21:00:56 +08:00
|
|
|
if (e.Button == MouseButton.Left)
|
|
|
|
{
|
2021-12-21 19:35:48 +08:00
|
|
|
DragStarted?.Invoke(ControlPoint);
|
2021-12-21 04:53:51 +08:00
|
|
|
keepSelection = true;
|
2020-04-09 21:00:56 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-29 13:07:06 +08:00
|
|
|
|
2021-12-21 04:29:57 +08:00
|
|
|
protected override void OnDrag(DragEvent e) => DragInProgress?.Invoke(e);
|
2018-10-29 13:07:06 +08:00
|
|
|
|
2021-12-21 03:56:06 +08:00
|
|
|
protected override void OnDragEnd(DragEndEvent e) => DragEnded?.Invoke();
|
2020-04-09 21:00:56 +08:00
|
|
|
|
2019-12-09 19:49:59 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Updates the state of the circular control point marker.
|
|
|
|
/// </summary>
|
|
|
|
private void updateMarkerDisplay()
|
|
|
|
{
|
2022-11-03 19:25:23 +08:00
|
|
|
Position = hitObject.StackedPosition + ControlPoint.Position;
|
2019-12-09 19:49:59 +08:00
|
|
|
|
|
|
|
markerRing.Alpha = IsSelected.Value ? 1 : 0;
|
|
|
|
|
2021-03-19 13:00:26 +08:00
|
|
|
Color4 colour = getColourFromNodeType();
|
2020-04-13 20:59:23 +08:00
|
|
|
|
2019-12-09 19:49:59 +08:00
|
|
|
if (IsHovered || IsSelected.Value)
|
2020-04-13 20:59:23 +08:00
|
|
|
colour = colour.Lighten(1);
|
|
|
|
|
2019-12-09 19:49:59 +08:00
|
|
|
marker.Colour = colour;
|
2022-11-03 19:25:23 +08:00
|
|
|
marker.Scale = new Vector2(hitObject.Scale);
|
2019-12-09 19:49:59 +08:00
|
|
|
}
|
2021-03-19 13:00:26 +08:00
|
|
|
|
|
|
|
private Color4 getColourFromNodeType()
|
|
|
|
{
|
2023-11-08 18:43:54 +08:00
|
|
|
if (ControlPoint.Type is not PathType pathType)
|
2021-03-19 13:00:26 +08:00
|
|
|
return colours.Yellow;
|
|
|
|
|
2023-11-13 15:24:09 +08:00
|
|
|
switch (pathType.Type)
|
2021-03-19 13:00:26 +08:00
|
|
|
{
|
2023-11-13 15:24:09 +08:00
|
|
|
case SplineType.Catmull:
|
2021-12-10 13:15:00 +08:00
|
|
|
return colours.SeaFoam;
|
2021-03-19 13:00:26 +08:00
|
|
|
|
2023-11-13 15:24:09 +08:00
|
|
|
case SplineType.BSpline:
|
|
|
|
if (!pathType.Degree.HasValue)
|
|
|
|
return colours.PinkLighter;
|
2021-03-19 13:00:26 +08:00
|
|
|
|
2023-11-08 18:43:54 +08:00
|
|
|
int idx = Math.Clamp(pathType.Degree.Value, 0, 3);
|
|
|
|
return new[] { colours.PinkDarker, colours.PinkDark, colours.Pink, colours.PinkLight }[idx];
|
|
|
|
|
2023-11-13 15:24:09 +08:00
|
|
|
case SplineType.PerfectCurve:
|
2021-03-19 13:00:26 +08:00
|
|
|
return colours.PurpleDark;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return colours.Red;
|
|
|
|
}
|
|
|
|
}
|
2021-03-19 15:58:08 +08:00
|
|
|
|
2023-11-15 14:45:09 +08:00
|
|
|
public LocalisableString TooltipText => ControlPoint.Type?.Description ?? string.Empty;
|
2018-10-29 13:07:06 +08:00
|
|
|
}
|
|
|
|
}
|