mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 00:02:54 +08:00
Make dragbox stateful to fix blueprint movement
This commit is contained in:
parent
f0d810fe20
commit
cb6e7425ae
@ -152,15 +152,16 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
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 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
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 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
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)
|
||||
|
@ -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
|
||||
/// <summary>
|
||||
/// A box that displays the drag selection and provides selection events for users to handle.
|
||||
/// </summary>
|
||||
public class DragBox : CompositeDrawable
|
||||
public class DragBox : CompositeDrawable, IStateful<Visibility>
|
||||
{
|
||||
protected readonly Action<RectangleF> PerformSelection;
|
||||
|
||||
@ -57,7 +58,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
/// </summary>
|
||||
/// <param name="e">The mouse event.</param>
|
||||
/// <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 dragStartPosition = e.ScreenSpaceMouseDownPosition;
|
||||
@ -76,5 +77,26 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
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<Visibility> StateChanged;
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
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 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user