mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 15:33:21 +08:00
Make all objects in selection candidates for spatial snapping
Closes #10898.
This commit is contained in:
parent
5d65665b42
commit
c9a41f9dae
@ -96,6 +96,11 @@ namespace osu.Game.Rulesets.Mania.Tests.Editor
|
|||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override SnapResult SnapScreenSpacePositionToValidPosition(Vector2 screenSpacePosition)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
public override float GetBeatSnapDistanceAt(double referenceTime)
|
public override float GetBeatSnapDistanceAt(double referenceTime)
|
||||||
{
|
{
|
||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
|
@ -174,6 +174,9 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
|
|||||||
|
|
||||||
private class SnapProvider : IPositionSnapProvider
|
private class SnapProvider : IPositionSnapProvider
|
||||||
{
|
{
|
||||||
|
public SnapResult SnapScreenSpacePositionToValidPosition(Vector2 screenSpacePosition) =>
|
||||||
|
new SnapResult(screenSpacePosition, null);
|
||||||
|
|
||||||
public SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition) => new SnapResult(screenSpacePosition, 0);
|
public SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition) => new SnapResult(screenSpacePosition, 0);
|
||||||
|
|
||||||
public float GetBeatSnapDistanceAt(double referenceTime) => (float)beat_length;
|
public float GetBeatSnapDistanceAt(double referenceTime) => (float)beat_length;
|
||||||
|
@ -105,11 +105,20 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition)
|
public override SnapResult SnapScreenSpacePositionToValidPosition(Vector2 screenSpacePosition)
|
||||||
{
|
{
|
||||||
if (snapToVisibleBlueprints(screenSpacePosition, out var snapResult))
|
if (snapToVisibleBlueprints(screenSpacePosition, out var snapResult))
|
||||||
return snapResult;
|
return snapResult;
|
||||||
|
|
||||||
|
return new SnapResult(screenSpacePosition, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition)
|
||||||
|
{
|
||||||
|
var positionSnap = SnapScreenSpacePositionToValidPosition(screenSpacePosition);
|
||||||
|
if (positionSnap.ScreenSpacePosition != screenSpacePosition)
|
||||||
|
return positionSnap;
|
||||||
|
|
||||||
// will be null if distance snap is disabled or not feasible for the current time value.
|
// will be null if distance snap is disabled or not feasible for the current time value.
|
||||||
if (distanceSnapGrid == null)
|
if (distanceSnapGrid == null)
|
||||||
return base.SnapScreenSpacePositionToValidTime(screenSpacePosition);
|
return base.SnapScreenSpacePositionToValidTime(screenSpacePosition);
|
||||||
|
@ -153,6 +153,9 @@ namespace osu.Game.Tests.Visual.Editing
|
|||||||
|
|
||||||
private class SnapProvider : IPositionSnapProvider
|
private class SnapProvider : IPositionSnapProvider
|
||||||
{
|
{
|
||||||
|
public SnapResult SnapScreenSpacePositionToValidPosition(Vector2 screenSpacePosition) =>
|
||||||
|
new SnapResult(screenSpacePosition, null);
|
||||||
|
|
||||||
public SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition) => new SnapResult(screenSpacePosition, 0);
|
public SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition) => new SnapResult(screenSpacePosition, 0);
|
||||||
|
|
||||||
public float GetBeatSnapDistanceAt(double referenceTime) => 10;
|
public float GetBeatSnapDistanceAt(double referenceTime) => 10;
|
||||||
|
@ -442,6 +442,9 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
|
|
||||||
public abstract SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition);
|
public abstract SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition);
|
||||||
|
|
||||||
|
public virtual SnapResult SnapScreenSpacePositionToValidPosition(Vector2 screenSpacePosition) =>
|
||||||
|
new SnapResult(screenSpacePosition, null);
|
||||||
|
|
||||||
public abstract float GetBeatSnapDistanceAt(double referenceTime);
|
public abstract float GetBeatSnapDistanceAt(double referenceTime);
|
||||||
|
|
||||||
public abstract float DurationToDistance(double referenceTime, double duration);
|
public abstract float DurationToDistance(double referenceTime, double duration);
|
||||||
|
@ -8,12 +8,22 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
public interface IPositionSnapProvider
|
public interface IPositionSnapProvider
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Given a position, find a valid time snap.
|
/// Given a position, find a valid time and position snap.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This call should be equivalent to running <see cref="SnapScreenSpacePositionToValidPosition"/> with any additional logic that can be performed without the time immutability restriction.
|
||||||
|
/// </remarks>
|
||||||
/// <param name="screenSpacePosition">The screen-space position to be snapped.</param>
|
/// <param name="screenSpacePosition">The screen-space position to be snapped.</param>
|
||||||
/// <returns>The time and position post-snapping.</returns>
|
/// <returns>The time and position post-snapping.</returns>
|
||||||
SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition);
|
SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Given a position, find a value position snap, restricting time to its input value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="screenSpacePosition">The screen-space position to be snapped.</param>
|
||||||
|
/// <returns>The position post-snapping. Time will always be null.</returns>
|
||||||
|
SnapResult SnapScreenSpacePositionToValidPosition(Vector2 screenSpacePosition);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the distance between two points within a timing point that are one beat length apart.
|
/// Retrieves the distance between two points within a timing point that are one beat length apart.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -424,7 +424,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
|
|
||||||
#region Selection Movement
|
#region Selection Movement
|
||||||
|
|
||||||
private Vector2? movementBlueprintOriginalPosition;
|
private Vector2[] movementBlueprintOriginalPositions;
|
||||||
private SelectionBlueprint movementBlueprint;
|
private SelectionBlueprint movementBlueprint;
|
||||||
private bool isDraggingBlueprint;
|
private bool isDraggingBlueprint;
|
||||||
|
|
||||||
@ -442,8 +442,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Movement is tracked from the blueprint of the earliest hitobject, since it only makes sense to distance snap from that hitobject
|
// 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.HitObject.StartTime).First();
|
var orderedSelection = SelectionHandler.SelectedBlueprints.OrderBy(b => b.HitObject.StartTime);
|
||||||
movementBlueprintOriginalPosition = movementBlueprint.ScreenSpaceSelectionPoint; // todo: unsure if correct
|
movementBlueprint = orderedSelection.First();
|
||||||
|
movementBlueprintOriginalPositions = orderedSelection.Select(m => m.ScreenSpaceSelectionPoint).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -459,12 +460,29 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
if (snapProvider == null)
|
if (snapProvider == null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Debug.Assert(movementBlueprintOriginalPosition != null);
|
Debug.Assert(movementBlueprintOriginalPositions != null);
|
||||||
|
|
||||||
HitObject draggedObject = movementBlueprint.HitObject;
|
Vector2 distanceTravelled = e.ScreenSpaceMousePosition - e.ScreenSpaceMouseDownPosition;
|
||||||
|
|
||||||
|
// check for positional snap for every object in selection (for things like object-object snapping)
|
||||||
|
for (var i = 0; i < movementBlueprintOriginalPositions.Length; i++)
|
||||||
|
{
|
||||||
|
var testPosition = movementBlueprintOriginalPositions[i] + distanceTravelled;
|
||||||
|
|
||||||
|
var positionalResult = snapProvider.SnapScreenSpacePositionToValidPosition(testPosition);
|
||||||
|
|
||||||
|
if (positionalResult.ScreenSpacePosition == testPosition) continue;
|
||||||
|
|
||||||
|
// attempt to move the objects, and abort any time based snapping if we can.
|
||||||
|
if (SelectionHandler.HandleMovement(new MoveSelectionEvent(SelectionHandler.SelectedBlueprints.ElementAt(i), positionalResult.ScreenSpacePosition)))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if no positional snapping could be performed, try unrestricted snapping from the earliest
|
||||||
|
// hitobject in the selection.
|
||||||
|
|
||||||
// The final movement position, relative to movementBlueprintOriginalPosition.
|
// The final movement position, relative to movementBlueprintOriginalPosition.
|
||||||
Vector2 movePosition = movementBlueprintOriginalPosition.Value + e.ScreenSpaceMousePosition - e.ScreenSpaceMouseDownPosition;
|
Vector2 movePosition = movementBlueprintOriginalPositions.First() + distanceTravelled;
|
||||||
|
|
||||||
// Retrieve a snapped position.
|
// Retrieve a snapped position.
|
||||||
var result = snapProvider.SnapScreenSpacePositionToValidTime(movePosition);
|
var result = snapProvider.SnapScreenSpacePositionToValidTime(movePosition);
|
||||||
@ -476,7 +494,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
if (result.Time.HasValue)
|
if (result.Time.HasValue)
|
||||||
{
|
{
|
||||||
// Apply the start time at the newly snapped-to position
|
// Apply the start time at the newly snapped-to position
|
||||||
double offset = result.Time.Value - draggedObject.StartTime;
|
double offset = result.Time.Value - movementBlueprint.HitObject.StartTime;
|
||||||
|
|
||||||
foreach (HitObject obj in Beatmap.SelectedHitObjects)
|
foreach (HitObject obj in Beatmap.SelectedHitObjects)
|
||||||
{
|
{
|
||||||
@ -497,7 +515,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
if (movementBlueprint == null)
|
if (movementBlueprint == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
movementBlueprintOriginalPosition = null;
|
movementBlueprintOriginalPositions = null;
|
||||||
movementBlueprint = null;
|
movementBlueprint = null;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -224,6 +224,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public double VisibleRange => track.Length / Zoom;
|
public double VisibleRange => track.Length / Zoom;
|
||||||
|
|
||||||
|
public SnapResult SnapScreenSpacePositionToValidPosition(Vector2 screenSpacePosition) =>
|
||||||
|
new SnapResult(screenSpacePosition, null);
|
||||||
|
|
||||||
public SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition) =>
|
public SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition) =>
|
||||||
new SnapResult(screenSpacePosition, beatSnapProvider.SnapTime(getTimeFromPosition(Content.ToLocalSpace(screenSpacePosition))));
|
new SnapResult(screenSpacePosition, beatSnapProvider.SnapTime(getTimeFromPosition(Content.ToLocalSpace(screenSpacePosition))));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user