diff --git a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs index c5414542e4..583627f78e 100644 --- a/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs +++ b/osu.Game/Screens/Edit/Compose/Components/BlueprintContainer.cs @@ -152,15 +152,16 @@ protected override bool OnDragStart(DragStartEvent e) if (e.Button == MouseButton.Right) return false; - if (!beginSelectionMovement()) - { - if (!DragBox.UpdateDrag(e)) - return false; + if (beginSelectionMovement()) + return true; - DragBox.FadeIn(250, Easing.OutQuint); + if (DragBox.HandleDrag(e)) + { + DragBox.Show(); + return true; } - return true; + return false; } protected override bool OnDrag(DragEvent e) @@ -168,13 +169,10 @@ protected override bool OnDrag(DragEvent e) if (e.Button == MouseButton.Right) return false; - if (!moveCurrentSelection(e)) - { - if (!DragBox.UpdateDrag(e)) - return false; - } + if (DragBox.State == Visibility.Visible) + return DragBox.HandleDrag(e); - return true; + return moveCurrentSelection(e); } protected override bool OnDragEnd(DragEndEvent e) @@ -182,13 +180,14 @@ protected override bool OnDragEnd(DragEndEvent e) if (e.Button == MouseButton.Right) return false; - if (!finishSelectionMovement()) + if (DragBox.State == Visibility.Visible) { - DragBox.FadeOut(250, Easing.OutQuint); + DragBox.Hide(); selectionHandler.UpdateVisibility(); + return true; } - return true; + return finishSelectionMovement(); } protected override bool OnKeyDown(KeyDownEvent e) diff --git a/osu.Game/Screens/Edit/Compose/Components/DragBox.cs b/osu.Game/Screens/Edit/Compose/Components/DragBox.cs index adbab1767b..c5f1bd1575 100644 --- a/osu.Game/Screens/Edit/Compose/Components/DragBox.cs +++ b/osu.Game/Screens/Edit/Compose/Components/DragBox.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using osu.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -15,7 +16,7 @@ namespace osu.Game.Screens.Edit.Compose.Components /// /// A box that displays the drag selection and provides selection events for users to handle. /// - public class DragBox : CompositeDrawable + public class DragBox : CompositeDrawable, IStateful { protected readonly Action PerformSelection; @@ -57,7 +58,7 @@ private void load() /// /// The mouse event. /// Whether the event should be handled and blocking. - public virtual bool UpdateDrag(MouseButtonEvent e) + public virtual bool HandleDrag(MouseButtonEvent e) { var dragPosition = e.ScreenSpaceMousePosition; var dragStartPosition = e.ScreenSpaceMouseDownPosition; @@ -76,5 +77,26 @@ public virtual bool UpdateDrag(MouseButtonEvent e) PerformSelection?.Invoke(dragRectangle); return true; } + + private Visibility state; + + public Visibility State + { + get => state; + set + { + if (value == state) return; + + state = value; + this.FadeTo(state == Visibility.Hidden ? 0 : 1, 250, Easing.OutQuint); + StateChanged?.Invoke(state); + } + } + + public override void Hide() => State = Visibility.Hidden; + + public override void Show() => State = Visibility.Visible; + + public event Action StateChanged; } } diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectDisplay.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectDisplay.cs index a11958c8c9..7101fac310 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectDisplay.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectDisplay.cs @@ -52,6 +52,12 @@ protected override bool OnDrag(DragEvent e) return base.OnDrag(e); } + protected override bool OnDragEnd(DragEndEvent e) + { + lastDragEvent = null; + return base.OnDragEnd(e); + } + protected override void Update() { // trigger every frame so drags continue to update selection while playback is scrolling the timeline. @@ -81,7 +87,7 @@ public TimelineDragBox(Action performSelect) Alpha = 0.3f }; - public override bool UpdateDrag(MouseButtonEvent e) + public override bool HandleDrag(MouseButtonEvent e) { // store the original position of the mouse down, as we may be scrolled during selection. if (lastMouseDown != e.ScreenSpaceMouseDownPosition)