1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 07:07:45 +08:00

Fix crashes when opening scale/rotation popovers during selection box operations

This commit is contained in:
Bartłomiej Dach 2024-06-25 15:01:43 +02:00
parent 6cd1367329
commit 2fda45cad4
No known key found for this signature in database
7 changed files with 40 additions and 10 deletions

View File

@ -53,9 +53,11 @@ namespace osu.Game.Rulesets.Osu.Edit
public override void Begin()
{
if (objectsInRotation != null)
if (OperationInProgress.Value)
throw new InvalidOperationException($"Cannot {nameof(Begin)} a rotate operation while another is in progress!");
base.Begin();
changeHandler?.BeginChange();
objectsInRotation = selectedMovableObjects.ToArray();
@ -68,10 +70,10 @@ namespace osu.Game.Rulesets.Osu.Edit
public override void Update(float rotation, Vector2? origin = null)
{
if (objectsInRotation == null)
if (!OperationInProgress.Value)
throw new InvalidOperationException($"Cannot {nameof(Update)} a rotate operation without calling {nameof(Begin)} first!");
Debug.Assert(originalPositions != null && originalPathControlPointPositions != null && defaultOrigin != null);
Debug.Assert(objectsInRotation != null && originalPositions != null && originalPathControlPointPositions != null && defaultOrigin != null);
Vector2 actualOrigin = origin ?? defaultOrigin.Value;
@ -91,11 +93,13 @@ namespace osu.Game.Rulesets.Osu.Edit
public override void Commit()
{
if (objectsInRotation == null)
if (!OperationInProgress.Value)
throw new InvalidOperationException($"Cannot {nameof(Commit)} a rotate operation without calling {nameof(Begin)} first!");
changeHandler?.EndChange();
base.Commit();
objectsInRotation = null;
originalPositions = null;
originalPathControlPointPositions = null;

View File

@ -72,9 +72,11 @@ namespace osu.Game.Rulesets.Osu.Edit
public override void Begin()
{
if (objectsInScale != null)
if (OperationInProgress.Value)
throw new InvalidOperationException($"Cannot {nameof(Begin)} a scale operation while another is in progress!");
base.Begin();
changeHandler?.BeginChange();
objectsInScale = selectedMovableObjects.ToDictionary(ho => ho, ho => new OriginalHitObjectState(ho));
@ -86,10 +88,10 @@ namespace osu.Game.Rulesets.Osu.Edit
public override void Update(Vector2 scale, Vector2? origin = null, Axes adjustAxis = Axes.Both)
{
if (objectsInScale == null)
if (!OperationInProgress.Value)
throw new InvalidOperationException($"Cannot {nameof(Update)} a scale operation without calling {nameof(Begin)} first!");
Debug.Assert(defaultOrigin != null && OriginalSurroundingQuad != null);
Debug.Assert(objectsInScale != null && defaultOrigin != null && OriginalSurroundingQuad != null);
Vector2 actualOrigin = origin ?? defaultOrigin.Value;
@ -117,11 +119,13 @@ namespace osu.Game.Rulesets.Osu.Edit
public override void Commit()
{
if (objectsInScale == null)
if (!OperationInProgress.Value)
throw new InvalidOperationException($"Cannot {nameof(Commit)} a rotate operation without calling {nameof(Begin)} first!");
changeHandler?.EndChange();
base.Commit();
objectsInScale = null;
OriginalSurroundingQuad = null;
defaultOrigin = null;

View File

@ -77,13 +77,15 @@ namespace osu.Game.Rulesets.Osu.Edit
{
case GlobalAction.EditorToggleRotateControl:
{
rotateButton.TriggerClick();
if (!RotationHandler.OperationInProgress.Value || rotateButton.Selected.Value)
rotateButton.TriggerClick();
return true;
}
case GlobalAction.EditorToggleScaleControl:
{
scaleButton.TriggerClick();
if (!ScaleHandler.OperationInProgress.Value || scaleButton.Selected.Value)
scaleButton.TriggerClick();
return true;
}
}

View File

@ -67,6 +67,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (rotationHandler == null) return false;
if (rotationHandler.OperationInProgress.Value)
return false;
rotationHandler.Begin();
return true;
}

View File

@ -32,6 +32,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (scaleHandler == null) return false;
if (scaleHandler.OperationInProgress.Value)
return false;
originalAnchor = Anchor;
scaleHandler.Begin();

View File

@ -12,6 +12,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </summary>
public partial class SelectionRotationHandler : Component
{
/// <summary>
/// Whether there is any ongoing scale operation right now.
/// </summary>
public Bindable<bool> OperationInProgress { get; private set; } = new BindableBool();
/// <summary>
/// Whether rotation anchored by the selection origin can currently be performed.
/// </summary>
@ -50,6 +55,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </remarks>
public virtual void Begin()
{
OperationInProgress.Value = true;
}
/// <summary>
@ -85,6 +91,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </remarks>
public virtual void Commit()
{
OperationInProgress.Value = false;
}
}
}

View File

@ -13,6 +13,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </summary>
public partial class SelectionScaleHandler : Component
{
/// <summary>
/// Whether there is any ongoing scale operation right now.
/// </summary>
public Bindable<bool> OperationInProgress { get; private set; } = new BindableBool();
/// <summary>
/// Whether horizontal scaling (from the left or right edge) support should be enabled.
/// </summary>
@ -63,6 +68,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </remarks>
public virtual void Begin()
{
OperationInProgress.Value = true;
}
/// <summary>
@ -99,6 +105,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </remarks>
public virtual void Commit()
{
OperationInProgress.Value = false;
}
}
}