mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:47:26 +08:00
Move selection drag events to BlueprintContainer
This commit is contained in:
parent
cef2318cf5
commit
714c89faa4
@ -35,21 +35,11 @@ namespace osu.Game.Rulesets.Edit
|
||||
/// </summary>
|
||||
public event Action<SelectionBlueprint, InputState> SelectionRequested;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when this <see cref="SelectionBlueprint"/> has requested drag.
|
||||
/// </summary>
|
||||
public event Action<SelectionBlueprint, DragEvent> DragRequested;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="DrawableHitObject"/> which this <see cref="SelectionBlueprint"/> applies to.
|
||||
/// </summary>
|
||||
public readonly DrawableHitObject DrawableObject;
|
||||
|
||||
/// <summary>
|
||||
/// The screen-space position of <see cref="DrawableObject"/> prior to handling a movement event.
|
||||
/// </summary>
|
||||
internal Vector2 ScreenSpaceMovementStartPosition { get; private set; }
|
||||
|
||||
protected override bool ShouldBeAlive => (DrawableObject.IsAlive && DrawableObject.IsPresent) || State == SelectionState.Selected;
|
||||
public override bool HandlePositionalInput => ShouldBeAlive;
|
||||
public override bool RemoveWhenNotAlive => false;
|
||||
@ -136,18 +126,6 @@ namespace osu.Game.Rulesets.Edit
|
||||
return base.OnClick(e);
|
||||
}
|
||||
|
||||
protected override bool OnDragStart(DragStartEvent e)
|
||||
{
|
||||
ScreenSpaceMovementStartPosition = DrawableObject.ToScreenSpace(DrawableObject.OriginPosition);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnDrag(DragEvent e)
|
||||
{
|
||||
DragRequested?.Invoke(this, e);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The screen-space point that causes this <see cref="SelectionBlueprint"/> to be selected.
|
||||
/// </summary>
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
@ -109,7 +110,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
blueprint.Selected -= onBlueprintSelected;
|
||||
blueprint.Deselected -= onBlueprintDeselected;
|
||||
blueprint.SelectionRequested -= onSelectionRequested;
|
||||
blueprint.DragRequested -= onDragRequested;
|
||||
|
||||
selectionBlueprints.Remove(blueprint);
|
||||
}
|
||||
@ -125,7 +125,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
blueprint.Selected += onBlueprintSelected;
|
||||
blueprint.Deselected += onBlueprintDeselected;
|
||||
blueprint.SelectionRequested += onSelectionRequested;
|
||||
blueprint.DragRequested += onDragRequested;
|
||||
|
||||
selectionBlueprints.Add(blueprint);
|
||||
}
|
||||
@ -227,9 +226,18 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
|
||||
private void onSelectionRequested(SelectionBlueprint blueprint, InputState state) => selectionHandler.HandleSelectionRequested(blueprint, state);
|
||||
|
||||
private Vector2? screenSpaceMovementStartPosition;
|
||||
private SelectionBlueprint movementBlueprint;
|
||||
|
||||
protected override bool OnDragStart(DragStartEvent e)
|
||||
{
|
||||
if (!selectionHandler.SelectedBlueprints.Any(b => b.IsHovered))
|
||||
if (selectionHandler.SelectedBlueprints.Any(b => b.IsHovered))
|
||||
{
|
||||
// The earliest hitobject is used for drag-movement/snapping
|
||||
movementBlueprint = selectionHandler.SelectedBlueprints.OrderBy(b => b.DrawableObject.HitObject.StartTime).First();
|
||||
screenSpaceMovementStartPosition = movementBlueprint.DrawableObject.ToScreenSpace(movementBlueprint.DrawableObject.OriginPosition);
|
||||
}
|
||||
else
|
||||
dragBox.FadeIn(250, Easing.OutQuint);
|
||||
|
||||
return true;
|
||||
@ -237,34 +245,46 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
|
||||
protected override bool OnDrag(DragEvent e)
|
||||
{
|
||||
dragBox.UpdateDrag(e);
|
||||
if (movementBlueprint != null)
|
||||
{
|
||||
Debug.Assert(screenSpaceMovementStartPosition != null);
|
||||
|
||||
Vector2 startPosition = screenSpaceMovementStartPosition.Value;
|
||||
HitObject draggedObject = movementBlueprint.DrawableObject.HitObject;
|
||||
|
||||
Vector2 movePosition = startPosition + e.ScreenSpaceMousePosition - e.ScreenSpaceMouseDownPosition;
|
||||
Vector2 snappedPosition = composer.GetSnappedPosition(ToLocalSpace(movePosition));
|
||||
|
||||
// Move the hitobjects
|
||||
selectionHandler.HandleMovement(new MoveSelectionEvent(movementBlueprint, startPosition, ToScreenSpace(snappedPosition)));
|
||||
|
||||
// Apply the start time at the newly snapped-to position
|
||||
double offset = composer.GetSnappedTime(draggedObject.StartTime, snappedPosition) - draggedObject.StartTime;
|
||||
foreach (HitObject obj in selectionHandler.SelectedHitObjects)
|
||||
obj.StartTime += offset;
|
||||
}
|
||||
else
|
||||
dragBox.UpdateDrag(e);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnDragEnd(DragEndEvent e)
|
||||
{
|
||||
dragBox.FadeOut(250, Easing.OutQuint);
|
||||
selectionHandler.UpdateVisibility();
|
||||
if (movementBlueprint != null)
|
||||
{
|
||||
screenSpaceMovementStartPosition = null;
|
||||
movementBlueprint = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
dragBox.FadeOut(250, Easing.OutQuint);
|
||||
selectionHandler.UpdateVisibility();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void onDragRequested(SelectionBlueprint blueprint, DragEvent dragEvent)
|
||||
{
|
||||
HitObject draggedObject = blueprint.DrawableObject.HitObject;
|
||||
|
||||
Vector2 movePosition = blueprint.ScreenSpaceMovementStartPosition + dragEvent.ScreenSpaceMousePosition - dragEvent.ScreenSpaceMouseDownPosition;
|
||||
Vector2 snappedPosition = composer.GetSnappedPosition(ToLocalSpace(movePosition));
|
||||
|
||||
// Move the hitobjects
|
||||
selectionHandler.HandleMovement(new MoveSelectionEvent(blueprint, blueprint.ScreenSpaceMovementStartPosition, ToScreenSpace(snappedPosition)));
|
||||
|
||||
// Apply the start time at the newly snapped-to position
|
||||
double offset = composer.GetSnappedTime(draggedObject.StartTime, snappedPosition) - draggedObject.StartTime;
|
||||
foreach (HitObject obj in selectionHandler.SelectedHitObjects)
|
||||
obj.StartTime += offset;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
Loading…
Reference in New Issue
Block a user