diff --git a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/SliderCircleOverlay.cs b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/SliderCircleOverlay.cs index 6bc3926279..247ceb4078 100644 --- a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/SliderCircleOverlay.cs +++ b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/SliderCircleOverlay.cs @@ -2,22 +2,18 @@ // See the LICENCE file in the repository root for full licence text. using System; -using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Lines; using osu.Framework.Graphics.Primitives; -using osu.Framework.Input.Events; -using osu.Framework.Utils; -using osu.Game.Graphics; using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles.Components; using osu.Game.Rulesets.Osu.Objects; -using osuTK; namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders { public partial class SliderCircleOverlay : CompositeDrawable { + public SliderEndDragMarker? EndDragMarker { get; } + public RectangleF VisibleQuad { get @@ -62,8 +58,6 @@ public SliderCircleOverlay(Slider slider, SliderPosition position) } } - public SliderEndDragMarker? EndDragMarker { get; } - protected override void Update() { base.Update(); @@ -94,75 +88,5 @@ public override void Show() CirclePiece.Show(); endDragMarkerContainer?.Show(); } - - public partial class SliderEndDragMarker : SmoothPath - { - public Action? StartDrag { get; set; } - public Action? Drag { get; set; } - public Action? EndDrag { get; set; } - - [Resolved] - private OsuColour colours { get; set; } = null!; - - [BackgroundDependencyLoader] - private void load() - { - var path = PathApproximator.CircularArcToPiecewiseLinear([ - new Vector2(0, OsuHitObject.OBJECT_RADIUS), - new Vector2(OsuHitObject.OBJECT_RADIUS, 0), - new Vector2(0, -OsuHitObject.OBJECT_RADIUS) - ]); - - Anchor = Anchor.CentreLeft; - Origin = Anchor.CentreLeft; - PathRadius = 5; - Vertices = path; - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - updateState(); - } - - protected override bool OnHover(HoverEvent e) - { - updateState(); - return true; - } - - protected override void OnHoverLost(HoverLostEvent e) - { - updateState(); - base.OnHoverLost(e); - } - - protected override bool OnDragStart(DragStartEvent e) - { - updateState(); - StartDrag?.Invoke(e); - return true; - } - - protected override void OnDrag(DragEvent e) - { - updateState(); - base.OnDrag(e); - Drag?.Invoke(e); - } - - protected override void OnDragEnd(DragEndEvent e) - { - updateState(); - EndDrag?.Invoke(); - base.OnDragEnd(e); - } - - private void updateState() - { - Colour = IsHovered || IsDragged ? colours.Red : colours.Yellow; - } - } } } diff --git a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/SliderEndDragMarker.cs b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/SliderEndDragMarker.cs new file mode 100644 index 0000000000..37383544dc --- /dev/null +++ b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/SliderEndDragMarker.cs @@ -0,0 +1,84 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Lines; +using osu.Framework.Input.Events; +using osu.Framework.Utils; +using osu.Game.Graphics; +using osu.Game.Rulesets.Osu.Objects; +using osuTK; + +namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders +{ + public partial class SliderEndDragMarker : SmoothPath + { + public Action? StartDrag { get; set; } + public Action? Drag { get; set; } + public Action? EndDrag { get; set; } + + [Resolved] + private OsuColour colours { get; set; } = null!; + + [BackgroundDependencyLoader] + private void load() + { + var path = PathApproximator.CircularArcToPiecewiseLinear([ + new Vector2(0, OsuHitObject.OBJECT_RADIUS), + new Vector2(OsuHitObject.OBJECT_RADIUS, 0), + new Vector2(0, -OsuHitObject.OBJECT_RADIUS) + ]); + + Anchor = Anchor.CentreLeft; + Origin = Anchor.CentreLeft; + PathRadius = 5; + Vertices = path; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + updateState(); + } + + protected override bool OnHover(HoverEvent e) + { + updateState(); + return true; + } + + protected override void OnHoverLost(HoverLostEvent e) + { + updateState(); + base.OnHoverLost(e); + } + + protected override bool OnDragStart(DragStartEvent e) + { + updateState(); + StartDrag?.Invoke(e); + return true; + } + + protected override void OnDrag(DragEvent e) + { + updateState(); + base.OnDrag(e); + Drag?.Invoke(e); + } + + protected override void OnDragEnd(DragEndEvent e) + { + updateState(); + EndDrag?.Invoke(); + base.OnDragEnd(e); + } + + private void updateState() + { + Colour = IsHovered || IsDragged ? colours.Red : colours.Yellow; + } + } +} diff --git a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/SliderSelectionBlueprint.cs b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/SliderSelectionBlueprint.cs index 691c053e4d..aca704609a 100644 --- a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/SliderSelectionBlueprint.cs +++ b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/SliderSelectionBlueprint.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using JetBrains.Annotations; using osu.Framework.Allocation; @@ -57,6 +58,9 @@ public partial class SliderSelectionBlueprint : OsuSelectionBlueprint [Resolved(CanBeNull = true)] private BindableBeatDivisor beatDivisor { get; set; } + [CanBeNull] + private PathControlPoint placementControlPoint; + public override Quad SelectionQuad { get @@ -84,6 +88,8 @@ public override Quad SelectionQuad // Cached slider path which ignored the expected distance value. private readonly Cached fullPathCache = new Cached(); + private Vector2 lastRightClickPosition; + public SliderSelectionBlueprint(Slider slider) : base(slider) { @@ -99,7 +105,10 @@ private void load(OsuConfigManager config) TailOverlay = CreateCircleOverlay(HitObject, SliderPosition.End), }; - TailOverlay.EndDragMarker!.StartDrag += startAdjustingLength; + // tail will always have a non-null end drag marker. + Debug.Assert(TailOverlay.EndDragMarker != null); + + TailOverlay.EndDragMarker.StartDrag += startAdjustingLength; TailOverlay.EndDragMarker.Drag += adjustLength; TailOverlay.EndDragMarker.EndDrag += endAdjustLength; @@ -154,7 +163,6 @@ protected override void Update() protected override bool OnHover(HoverEvent e) { updateVisualDefinition(); - return base.OnHover(e); } @@ -199,14 +207,12 @@ private void updateVisualDefinition() } } - private Vector2 rightClickPosition; - protected override bool OnMouseDown(MouseDownEvent e) { switch (e.Button) { case MouseButton.Right: - rightClickPosition = e.MouseDownPosition; + lastRightClickPosition = e.MouseDownPosition; return false; // Allow right click to be handled by context menu case MouseButton.Left: @@ -226,6 +232,8 @@ protected override bool OnMouseDown(MouseDownEvent e) return false; } + #region Length Adjustment (independent of path nodes) + private Vector2 lengthAdjustMouseOffset; private double oldDuration; private double oldVelocityMultiplier; @@ -351,8 +359,7 @@ private double findClosestPathDistance(MouseEvent e) return bestValue; } - [CanBeNull] - private PathControlPoint placementControlPoint; + #endregion protected override bool OnDragStart(DragStartEvent e) { @@ -586,7 +593,7 @@ private void convertToStream() new OsuMenuItem("Add control point", MenuItemType.Standard, () => { changeHandler?.BeginChange(); - addControlPoint(rightClickPosition); + addControlPoint(lastRightClickPosition); changeHandler?.EndChange(); }), new OsuMenuItem("Convert to stream", MenuItemType.Destructive, convertToStream),