mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 05:22:54 +08:00
Extract drag events into multiple methods
This commit is contained in:
parent
f128e99fb2
commit
a07e5a269b
@ -160,6 +160,33 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
return base.OnMouseMove(e);
|
return base.OnMouseMove(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool OnDragStart(DragStartEvent e)
|
||||||
|
{
|
||||||
|
if (!beginSelectionMovement())
|
||||||
|
dragBox.FadeIn(250, Easing.OutQuint);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnDrag(DragEvent e)
|
||||||
|
{
|
||||||
|
if (!moveCurrentSelection(e))
|
||||||
|
dragBox.UpdateDrag(e);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnDragEnd(DragEndEvent e)
|
||||||
|
{
|
||||||
|
if (!finishSelectionMovement())
|
||||||
|
{
|
||||||
|
dragBox.FadeOut(250, Easing.OutQuint);
|
||||||
|
selectionHandler.UpdateVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
@ -239,29 +266,41 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
private Vector2? screenSpaceMovementStartPosition;
|
private Vector2? screenSpaceMovementStartPosition;
|
||||||
private SelectionBlueprint movementBlueprint;
|
private SelectionBlueprint movementBlueprint;
|
||||||
|
|
||||||
protected override bool OnDragStart(DragStartEvent e)
|
/// <summary>
|
||||||
|
/// Attempts to begin the movement of any selected blueprints.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Whether movement began.</returns>
|
||||||
|
private bool beginSelectionMovement()
|
||||||
{
|
{
|
||||||
if (selectionHandler.SelectedBlueprints.Any(b => b.IsHovered))
|
Debug.Assert(movementBlueprint == null);
|
||||||
{
|
|
||||||
// The earliest hitobject is used for drag-movement/snapping
|
// Any selected blueprints can begin the movement of the group, however only the earliest hitobject is used for movement
|
||||||
|
if (!selectionHandler.SelectedBlueprints.Any(b => b.IsHovered))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Movement is tracked from the blueprint of the earliest hitobject, since it only makes sense to distance snap from that hitobject
|
||||||
movementBlueprint = selectionHandler.SelectedBlueprints.OrderBy(b => b.DrawableObject.HitObject.StartTime).First();
|
movementBlueprint = selectionHandler.SelectedBlueprints.OrderBy(b => b.DrawableObject.HitObject.StartTime).First();
|
||||||
screenSpaceMovementStartPosition = movementBlueprint.DrawableObject.ToScreenSpace(movementBlueprint.DrawableObject.OriginPosition);
|
screenSpaceMovementStartPosition = movementBlueprint.DrawableObject.ToScreenSpace(movementBlueprint.DrawableObject.OriginPosition);
|
||||||
}
|
|
||||||
else
|
|
||||||
dragBox.FadeIn(250, Easing.OutQuint);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnDrag(DragEvent e)
|
/// <summary>
|
||||||
{
|
/// Moves the current selected blueprints.
|
||||||
if (movementBlueprint != null)
|
/// </summary>
|
||||||
|
/// <param name="e">The <see cref="DragEvent"/> defining the movement event.</param>
|
||||||
|
/// <returns>Whether a movement was active.</returns>
|
||||||
|
private bool moveCurrentSelection(DragEvent e)
|
||||||
{
|
{
|
||||||
|
if (movementBlueprint == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
Debug.Assert(screenSpaceMovementStartPosition != null);
|
Debug.Assert(screenSpaceMovementStartPosition != null);
|
||||||
|
|
||||||
Vector2 startPosition = screenSpaceMovementStartPosition.Value;
|
Vector2 startPosition = screenSpaceMovementStartPosition.Value;
|
||||||
HitObject draggedObject = movementBlueprint.DrawableObject.HitObject;
|
HitObject draggedObject = movementBlueprint.DrawableObject.HitObject;
|
||||||
|
|
||||||
|
// The final movement position, relative to screenSpaceMovementStartPosition
|
||||||
Vector2 movePosition = startPosition + e.ScreenSpaceMousePosition - e.ScreenSpaceMouseDownPosition;
|
Vector2 movePosition = startPosition + e.ScreenSpaceMousePosition - e.ScreenSpaceMouseDownPosition;
|
||||||
Vector2 snappedPosition = composer.GetSnappedPosition(ToLocalSpace(movePosition));
|
Vector2 snappedPosition = composer.GetSnappedPosition(ToLocalSpace(movePosition));
|
||||||
|
|
||||||
@ -272,25 +311,21 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
double offset = composer.GetSnappedTime(draggedObject.StartTime, snappedPosition) - draggedObject.StartTime;
|
double offset = composer.GetSnappedTime(draggedObject.StartTime, snappedPosition) - draggedObject.StartTime;
|
||||||
foreach (HitObject obj in selectionHandler.SelectedHitObjects)
|
foreach (HitObject obj in selectionHandler.SelectedHitObjects)
|
||||||
obj.StartTime += offset;
|
obj.StartTime += offset;
|
||||||
}
|
|
||||||
else
|
|
||||||
dragBox.UpdateDrag(e);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnDragEnd(DragEndEvent e)
|
/// <summary>
|
||||||
{
|
/// Finishes the current movement of selected blueprints.
|
||||||
if (movementBlueprint != null)
|
/// </summary>
|
||||||
|
/// <returns>Whether a movement was active.</returns>
|
||||||
|
private bool finishSelectionMovement()
|
||||||
{
|
{
|
||||||
|
if (movementBlueprint == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
screenSpaceMovementStartPosition = null;
|
screenSpaceMovementStartPosition = null;
|
||||||
movementBlueprint = null;
|
movementBlueprint = null;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dragBox.FadeOut(250, Easing.OutQuint);
|
|
||||||
selectionHandler.UpdateVisibility();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user