mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 15:53:51 +08:00
Move editor selections relative to hitobject start positions (#6431)
Move editor selections relative to hitobject start positions
This commit is contained in:
commit
00d4d976b7
@ -18,7 +18,7 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
|
||||
public Vector2 ScreenSpaceDragPosition { get; private set; }
|
||||
public Vector2 DragPosition { get; private set; }
|
||||
|
||||
protected new DrawableManiaHitObject HitObject => (DrawableManiaHitObject)base.HitObject;
|
||||
public new DrawableManiaHitObject HitObject => (DrawableManiaHitObject)base.HitObject;
|
||||
|
||||
protected IClock EditorClock { get; private set; }
|
||||
|
||||
|
@ -3,9 +3,7 @@
|
||||
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Mania.Edit.Blueprints;
|
||||
using osu.Game.Rulesets.Mania.Objects;
|
||||
using osu.Game.Rulesets.UI;
|
||||
@ -31,13 +29,16 @@ namespace osu.Game.Rulesets.Mania.Edit
|
||||
editorClock = clock;
|
||||
}
|
||||
|
||||
public override void HandleDrag(SelectionBlueprint blueprint, DragEvent dragEvent)
|
||||
public override void HandleMovement(MoveSelectionEvent moveEvent)
|
||||
{
|
||||
adjustOrigins((ManiaSelectionBlueprint)blueprint);
|
||||
performDragMovement(dragEvent);
|
||||
performColumnMovement(dragEvent);
|
||||
var maniaBlueprint = (ManiaSelectionBlueprint)moveEvent.Blueprint;
|
||||
int lastColumn = maniaBlueprint.HitObject.HitObject.Column;
|
||||
|
||||
base.HandleDrag(blueprint, dragEvent);
|
||||
adjustOrigins(maniaBlueprint);
|
||||
performDragMovement(moveEvent);
|
||||
performColumnMovement(lastColumn, moveEvent);
|
||||
|
||||
base.HandleMovement(moveEvent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -62,7 +63,7 @@ namespace osu.Game.Rulesets.Mania.Edit
|
||||
b.HitObject.Y += movementDelta;
|
||||
}
|
||||
|
||||
private void performDragMovement(DragEvent dragEvent)
|
||||
private void performDragMovement(MoveSelectionEvent moveEvent)
|
||||
{
|
||||
foreach (var b in SelectedBlueprints)
|
||||
{
|
||||
@ -72,7 +73,7 @@ namespace osu.Game.Rulesets.Mania.Edit
|
||||
|
||||
// Using the hitobject position is required since AdjustPosition can be invoked multiple times per frame
|
||||
// without the position having been updated by the parenting ScrollingHitObjectContainer
|
||||
hitObject.Y += dragEvent.Delta.Y;
|
||||
hitObject.Y += moveEvent.InstantDelta.Y;
|
||||
|
||||
float targetPosition;
|
||||
|
||||
@ -94,14 +95,13 @@ namespace osu.Game.Rulesets.Mania.Edit
|
||||
}
|
||||
}
|
||||
|
||||
private void performColumnMovement(DragEvent dragEvent)
|
||||
private void performColumnMovement(int lastColumn, MoveSelectionEvent moveEvent)
|
||||
{
|
||||
var lastColumn = composer.ColumnAt(dragEvent.ScreenSpaceLastMousePosition);
|
||||
var currentColumn = composer.ColumnAt(dragEvent.ScreenSpaceMousePosition);
|
||||
if (lastColumn == null || currentColumn == null)
|
||||
var currentColumn = composer.ColumnAt(moveEvent.ScreenSpacePosition);
|
||||
if (currentColumn == null)
|
||||
return;
|
||||
|
||||
int columnDelta = currentColumn.Index - lastColumn.Index;
|
||||
int columnDelta = currentColumn.Index - lastColumn;
|
||||
if (columnDelta == 0)
|
||||
return;
|
||||
|
||||
|
@ -2,8 +2,6 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Linq;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Screens.Edit.Compose.Components;
|
||||
|
||||
@ -11,7 +9,7 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
{
|
||||
public class OsuSelectionHandler : SelectionHandler
|
||||
{
|
||||
public override void HandleDrag(SelectionBlueprint blueprint, DragEvent dragEvent)
|
||||
public override void HandleMovement(MoveSelectionEvent moveEvent)
|
||||
{
|
||||
foreach (var h in SelectedHitObjects.OfType<OsuHitObject>())
|
||||
{
|
||||
@ -21,10 +19,10 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
continue;
|
||||
}
|
||||
|
||||
h.Position += dragEvent.Delta;
|
||||
h.Position += moveEvent.InstantDelta;
|
||||
}
|
||||
|
||||
base.HandleDrag(blueprint, dragEvent);
|
||||
base.HandleMovement(moveEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,11 @@ namespace osu.Game.Rulesets.Edit
|
||||
/// </summary>
|
||||
public readonly DrawableHitObject HitObject;
|
||||
|
||||
/// <summary>
|
||||
/// The screen-space position of <see cref="HitObject"/> prior to handling a movement event.
|
||||
/// </summary>
|
||||
internal Vector2 ScreenSpaceMovementStartPosition { get; private set; }
|
||||
|
||||
protected override bool ShouldBeAlive => (HitObject.IsAlive && HitObject.IsPresent) || State == SelectionState.Selected;
|
||||
public override bool HandlePositionalInput => ShouldBeAlive;
|
||||
public override bool RemoveWhenNotAlive => false;
|
||||
@ -131,7 +136,11 @@ namespace osu.Game.Rulesets.Edit
|
||||
return base.OnClick(e);
|
||||
}
|
||||
|
||||
protected override bool OnDragStart(DragStartEvent e) => true;
|
||||
protected override bool OnDragStart(DragStartEvent e)
|
||||
{
|
||||
ScreenSpaceMovementStartPosition = HitObject.ToScreenSpace(HitObject.OriginPosition);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnDrag(DragEvent e)
|
||||
{
|
||||
|
@ -216,7 +216,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
|
||||
private void onSelectionRequested(SelectionBlueprint blueprint, InputState state) => selectionHandler.HandleSelectionRequested(blueprint, state);
|
||||
|
||||
private void onDragRequested(SelectionBlueprint blueprint, DragEvent dragEvent) => selectionHandler.HandleDrag(blueprint, dragEvent);
|
||||
private void onDragRequested(SelectionBlueprint blueprint, DragEvent dragEvent)
|
||||
{
|
||||
var movePosition = blueprint.ScreenSpaceMovementStartPosition + dragEvent.ScreenSpaceMousePosition - dragEvent.ScreenSpaceMouseDownPosition;
|
||||
|
||||
selectionHandler.HandleMovement(new MoveSelectionEvent(blueprint, blueprint.ScreenSpaceMovementStartPosition, movePosition));
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
|
@ -0,0 +1,46 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Compose.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// An event which occurs when a <see cref="SelectionBlueprint"/> is moved.
|
||||
/// </summary>
|
||||
public class MoveSelectionEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="SelectionBlueprint"/> that triggered this <see cref="MoveSelectionEvent"/>.
|
||||
/// </summary>
|
||||
public readonly SelectionBlueprint Blueprint;
|
||||
|
||||
/// <summary>
|
||||
/// The starting screen-space position of the hitobject.
|
||||
/// </summary>
|
||||
public readonly Vector2 ScreenSpaceStartPosition;
|
||||
|
||||
/// <summary>
|
||||
/// The expected screen-space position of the hitobject at the current cursor position.
|
||||
/// </summary>
|
||||
public readonly Vector2 ScreenSpacePosition;
|
||||
|
||||
/// <summary>
|
||||
/// The distance between <see cref="ScreenSpacePosition"/> and the hitobject's current position, in the coordinate-space of the hitobject's parent.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This does not use <see cref="ScreenSpaceStartPosition"/> and does not represent the cumulative movement distance.
|
||||
/// </remarks>
|
||||
public readonly Vector2 InstantDelta;
|
||||
|
||||
public MoveSelectionEvent(SelectionBlueprint blueprint, Vector2 screenSpaceStartPosition, Vector2 screenSpacePosition)
|
||||
{
|
||||
Blueprint = blueprint;
|
||||
ScreenSpaceStartPosition = screenSpaceStartPosition;
|
||||
ScreenSpacePosition = screenSpacePosition;
|
||||
|
||||
InstantDelta = Blueprint.HitObject.Parent.ToLocalSpace(ScreenSpacePosition) - Blueprint.HitObject.Position;
|
||||
}
|
||||
}
|
||||
}
|
@ -65,11 +65,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
#region User Input Handling
|
||||
|
||||
/// <summary>
|
||||
/// Handles the selected <see cref="DrawableHitObject"/>s being dragged.
|
||||
/// Handles the selected <see cref="DrawableHitObject"/>s being moved.
|
||||
/// </summary>
|
||||
/// <param name="blueprint">The <see cref="SelectionBlueprint"/> that received the drag event.</param>
|
||||
/// <param name="dragEvent">The drag event.</param>
|
||||
public virtual void HandleDrag(SelectionBlueprint blueprint, DragEvent dragEvent)
|
||||
/// <param name="moveEvent">The move event.</param>
|
||||
public virtual void HandleMovement(MoveSelectionEvent moveEvent)
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user