Fix incorrect index lookup on non-ordered selections

This commit is contained in:
Dean Herbert 2020-11-25 17:25:54 +09:00
parent 4eef6c0d40
commit 0ddeff648d

View File

@ -187,7 +187,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (e.Button == MouseButton.Right) if (e.Button == MouseButton.Right)
return false; return false;
if (movementBlueprint != null) if (movementBlueprints != null)
{ {
isDraggingBlueprint = true; isDraggingBlueprint = true;
changeHandler?.BeginChange(); changeHandler?.BeginChange();
@ -299,7 +299,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
SelectionBlueprints.Remove(blueprint); SelectionBlueprints.Remove(blueprint);
if (movementBlueprint == blueprint) if (movementBlueprints?.Contains(blueprint) == true)
finishSelectionMovement(); finishSelectionMovement();
OnBlueprintRemoved(hitObject); OnBlueprintRemoved(hitObject);
@ -425,7 +425,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
#region Selection Movement #region Selection Movement
private Vector2[] movementBlueprintOriginalPositions; private Vector2[] movementBlueprintOriginalPositions;
private SelectionBlueprint movementBlueprint; private SelectionBlueprint[] movementBlueprints;
private bool isDraggingBlueprint; private bool isDraggingBlueprint;
/// <summary> /// <summary>
@ -442,9 +442,8 @@ 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
var orderedSelection = SelectionHandler.SelectedBlueprints.OrderBy(b => b.HitObject.StartTime); movementBlueprints = SelectionHandler.SelectedBlueprints.OrderBy(b => b.HitObject.StartTime).ToArray();
movementBlueprint = orderedSelection.First(); movementBlueprintOriginalPositions = movementBlueprints.Select(m => m.ScreenSpaceSelectionPoint).ToArray();
movementBlueprintOriginalPositions = orderedSelection.Select(m => m.ScreenSpaceSelectionPoint).ToArray();
} }
/// <summary> /// <summary>
@ -454,7 +453,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <returns>Whether a movement was active.</returns> /// <returns>Whether a movement was active.</returns>
private bool moveCurrentSelection(DragEvent e) private bool moveCurrentSelection(DragEvent e)
{ {
if (movementBlueprint == null) if (movementBlueprints == null)
return false; return false;
if (snapProvider == null) if (snapProvider == null)
@ -474,7 +473,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (positionalResult.ScreenSpacePosition == testPosition) continue; if (positionalResult.ScreenSpacePosition == testPosition) continue;
// attempt to move the objects, and abort any time based snapping if we can. // 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))) if (SelectionHandler.HandleMovement(new MoveSelectionEvent(movementBlueprints[i], positionalResult.ScreenSpacePosition)))
return true; return true;
} }
@ -488,13 +487,13 @@ namespace osu.Game.Screens.Edit.Compose.Components
var result = snapProvider.SnapScreenSpacePositionToValidTime(movePosition); var result = snapProvider.SnapScreenSpacePositionToValidTime(movePosition);
// Move the hitobjects. // Move the hitobjects.
if (!SelectionHandler.HandleMovement(new MoveSelectionEvent(movementBlueprint, result.ScreenSpacePosition))) if (!SelectionHandler.HandleMovement(new MoveSelectionEvent(movementBlueprints.First(), result.ScreenSpacePosition)))
return true; return true;
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 - movementBlueprint.HitObject.StartTime; double offset = result.Time.Value - movementBlueprints.First().HitObject.StartTime;
foreach (HitObject obj in Beatmap.SelectedHitObjects) foreach (HitObject obj in Beatmap.SelectedHitObjects)
{ {
@ -512,11 +511,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <returns>Whether a movement was active.</returns> /// <returns>Whether a movement was active.</returns>
private bool finishSelectionMovement() private bool finishSelectionMovement()
{ {
if (movementBlueprint == null) if (movementBlueprints == null)
return false; return false;
movementBlueprintOriginalPositions = null; movementBlueprintOriginalPositions = null;
movementBlueprint = null; movementBlueprints = null;
return true; return true;
} }