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

Move selection relative to the hitobject start positions

This commit is contained in:
smoogipoo 2019-10-08 18:57:03 +09:00
parent dba526279e
commit 08d043f447
7 changed files with 87 additions and 18 deletions

View File

@ -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; }

View File

@ -3,7 +3,6 @@
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;
@ -31,11 +30,14 @@ namespace osu.Game.Rulesets.Mania.Edit
editorClock = clock;
}
public override void HandleDrag(SelectionBlueprint blueprint, DragEvent dragEvent)
public override void HandleDrag(SelectionBlueprint blueprint, SelectionDragEvent dragEvent)
{
adjustOrigins((ManiaSelectionBlueprint)blueprint);
var maniaBlueprint = (ManiaSelectionBlueprint)blueprint;
int lastColumn = maniaBlueprint.HitObject.HitObject.Column;
adjustOrigins(maniaBlueprint);
performDragMovement(dragEvent);
performColumnMovement(dragEvent);
performColumnMovement(lastColumn, dragEvent);
base.HandleDrag(blueprint, dragEvent);
}
@ -62,7 +64,7 @@ namespace osu.Game.Rulesets.Mania.Edit
b.HitObject.Y += movementDelta;
}
private void performDragMovement(DragEvent dragEvent)
private void performDragMovement(SelectionDragEvent dragEvent)
{
foreach (var b in SelectedBlueprints)
{
@ -72,7 +74,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 += dragEvent.InstantDragDelta.Y;
float targetPosition;
@ -94,14 +96,13 @@ namespace osu.Game.Rulesets.Mania.Edit
}
}
private void performColumnMovement(DragEvent dragEvent)
private void performColumnMovement(int lastColumn, SelectionDragEvent dragEvent)
{
var lastColumn = composer.ColumnAt(dragEvent.ScreenSpaceLastMousePosition);
var currentColumn = composer.ColumnAt(dragEvent.ScreenSpaceMousePosition);
if (lastColumn == null || currentColumn == null)
var currentColumn = composer.ColumnAt(dragEvent.ScreenSpaceDragPosition);
if (currentColumn == null)
return;
int columnDelta = currentColumn.Index - lastColumn.Index;
int columnDelta = currentColumn.Index - lastColumn;
if (columnDelta == 0)
return;

View File

@ -2,7 +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 +10,7 @@ namespace osu.Game.Rulesets.Osu.Edit
{
public class OsuSelectionHandler : SelectionHandler
{
public override void HandleDrag(SelectionBlueprint blueprint, DragEvent dragEvent)
public override void HandleDrag(SelectionBlueprint blueprint, SelectionDragEvent dragEvent)
{
foreach (var h in SelectedHitObjects.OfType<OsuHitObject>())
{
@ -21,7 +20,7 @@ namespace osu.Game.Rulesets.Osu.Edit
continue;
}
h.Position += dragEvent.Delta;
h.Position += dragEvent.InstantDragDelta;
}
base.HandleDrag(blueprint, dragEvent);

View File

@ -45,6 +45,11 @@ namespace osu.Game.Rulesets.Edit
/// </summary>
public readonly DrawableHitObject HitObject;
/// <summary>
/// The screen-space position of <see cref="HitObject"/> when a drag was started.
/// </summary>
public Vector2 ScreenSpaceDragStartPosition { 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)
{
ScreenSpaceDragStartPosition = HitObject.ToScreenSpace(HitObject.OriginPosition);
return true;
}
protected override bool OnDrag(DragEvent e)
{

View File

@ -216,7 +216,14 @@ 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 dragPosition = blueprint.ScreenSpaceDragStartPosition + dragEvent.ScreenSpaceMousePosition - dragEvent.ScreenSpaceMouseDownPosition;
// Todo: Snap dragPosition
selectionHandler.HandleDrag(blueprint, new SelectionDragEvent(blueprint, blueprint.ScreenSpaceDragStartPosition, dragPosition));
}
protected override void Dispose(bool isDisposing)
{

View File

@ -0,0 +1,53 @@
// 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 dragged.
/// </summary>
public class SelectionDragEvent
{
/// <summary>
/// The dragged <see cref="SelectionBlueprint"/>.
/// </summary>
public readonly SelectionBlueprint DraggedBlueprint;
/// <summary>
/// The screen-space position of the hitobject at the start of the drag.
/// </summary>
public readonly Vector2 ScreenSpaceDragStartPosition;
/// <summary>
/// The new screen-space position of the hitobject at the current drag point.
/// </summary>
public readonly Vector2 ScreenSpaceDragPosition;
/// <summary>
/// The distance between <see cref="ScreenSpaceDragPosition"/> and the hitobject's current position, in the coordinate-space of the hitobject's parent.
/// </summary>
/// <remarks>
/// This does not use <see cref="ScreenSpaceDragStartPosition"/> and does not represent the cumulative drag distance.
/// </remarks>
public readonly Vector2 InstantDragDelta;
public SelectionDragEvent(SelectionBlueprint blueprint, Vector2 screenSpaceDragStartPosition, Vector2 screenSpaceDragPosition)
{
DraggedBlueprint = blueprint;
ScreenSpaceDragStartPosition = screenSpaceDragStartPosition;
ScreenSpaceDragPosition = screenSpaceDragPosition;
InstantDragDelta = toLocalSpace(ScreenSpaceDragPosition) - DraggedBlueprint.HitObject.Position;
}
/// <summary>
/// Converts a screen-space position into the coordinate space of the hitobject's parents.
/// </summary>
/// <param name="screenSpacePosition">The screen-space position.</param>
/// <returns>The position in the coordinate space of the hitobject's parent.</returns>
private Vector2 toLocalSpace(Vector2 screenSpacePosition) => DraggedBlueprint.HitObject.Parent.ToLocalSpace(screenSpacePosition);
}
}

View File

@ -69,7 +69,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </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)
public virtual void HandleDrag(SelectionBlueprint blueprint, SelectionDragEvent dragEvent)
{
}