1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 15:12:57 +08:00

Make dragbox stateful to fix blueprint movement

This commit is contained in:
Dean Herbert 2020-01-22 17:54:11 +09:00
parent f0d810fe20
commit cb6e7425ae
3 changed files with 45 additions and 18 deletions

View File

@ -152,15 +152,16 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (e.Button == MouseButton.Right) if (e.Button == MouseButton.Right)
return false; return false;
if (!beginSelectionMovement()) if (beginSelectionMovement())
{ return true;
if (!DragBox.UpdateDrag(e))
return false;
DragBox.FadeIn(250, Easing.OutQuint); if (DragBox.HandleDrag(e))
{
DragBox.Show();
return true;
} }
return true; return false;
} }
protected override bool OnDrag(DragEvent e) protected override bool OnDrag(DragEvent e)
@ -168,13 +169,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (e.Button == MouseButton.Right) if (e.Button == MouseButton.Right)
return false; return false;
if (!moveCurrentSelection(e)) if (DragBox.State == Visibility.Visible)
{ return DragBox.HandleDrag(e);
if (!DragBox.UpdateDrag(e))
return false;
}
return true; return moveCurrentSelection(e);
} }
protected override bool OnDragEnd(DragEndEvent e) protected override bool OnDragEnd(DragEndEvent e)
@ -182,13 +180,14 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (e.Button == MouseButton.Right) if (e.Button == MouseButton.Right)
return false; return false;
if (!finishSelectionMovement()) if (DragBox.State == Visibility.Visible)
{ {
DragBox.FadeOut(250, Easing.OutQuint); DragBox.Hide();
selectionHandler.UpdateVisibility(); selectionHandler.UpdateVisibility();
return true;
} }
return true; return finishSelectionMovement();
} }
protected override bool OnKeyDown(KeyDownEvent e) protected override bool OnKeyDown(KeyDownEvent e)

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using osu.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -15,7 +16,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <summary> /// <summary>
/// A box that displays the drag selection and provides selection events for users to handle. /// A box that displays the drag selection and provides selection events for users to handle.
/// </summary> /// </summary>
public class DragBox : CompositeDrawable public class DragBox : CompositeDrawable, IStateful<Visibility>
{ {
protected readonly Action<RectangleF> PerformSelection; protected readonly Action<RectangleF> PerformSelection;
@ -57,7 +58,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </summary> /// </summary>
/// <param name="e">The mouse event.</param> /// <param name="e">The mouse event.</param>
/// <returns>Whether the event should be handled and blocking.</returns> /// <returns>Whether the event should be handled and blocking.</returns>
public virtual bool UpdateDrag(MouseButtonEvent e) public virtual bool HandleDrag(MouseButtonEvent e)
{ {
var dragPosition = e.ScreenSpaceMousePosition; var dragPosition = e.ScreenSpaceMousePosition;
var dragStartPosition = e.ScreenSpaceMouseDownPosition; var dragStartPosition = e.ScreenSpaceMouseDownPosition;
@ -76,5 +77,26 @@ namespace osu.Game.Screens.Edit.Compose.Components
PerformSelection?.Invoke(dragRectangle); PerformSelection?.Invoke(dragRectangle);
return true; 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<Visibility> StateChanged;
} }
} }

View File

@ -52,6 +52,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
return base.OnDrag(e); return base.OnDrag(e);
} }
protected override bool OnDragEnd(DragEndEvent e)
{
lastDragEvent = null;
return base.OnDragEnd(e);
}
protected override void Update() protected override void Update()
{ {
// trigger every frame so drags continue to update selection while playback is scrolling the timeline. // trigger every frame so drags continue to update selection while playback is scrolling the timeline.
@ -81,7 +87,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
Alpha = 0.3f 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. // store the original position of the mouse down, as we may be scrolled during selection.
if (lastMouseDown != e.ScreenSpaceMouseDownPosition) if (lastMouseDown != e.ScreenSpaceMouseDownPosition)