mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 08:27:49 +08:00
Merge pull request #28589 from bdach/scale-handling-crash
Fix crashes when opening scale/rotation popovers during selection box operations
This commit is contained in:
commit
aadb104851
@ -53,9 +53,11 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
|
|
||||||
public override void Begin()
|
public override void Begin()
|
||||||
{
|
{
|
||||||
if (objectsInRotation != null)
|
if (OperationInProgress.Value)
|
||||||
throw new InvalidOperationException($"Cannot {nameof(Begin)} a rotate operation while another is in progress!");
|
throw new InvalidOperationException($"Cannot {nameof(Begin)} a rotate operation while another is in progress!");
|
||||||
|
|
||||||
|
base.Begin();
|
||||||
|
|
||||||
changeHandler?.BeginChange();
|
changeHandler?.BeginChange();
|
||||||
|
|
||||||
objectsInRotation = selectedMovableObjects.ToArray();
|
objectsInRotation = selectedMovableObjects.ToArray();
|
||||||
@ -68,10 +70,10 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
|
|
||||||
public override void Update(float rotation, Vector2? origin = null)
|
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!");
|
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;
|
Vector2 actualOrigin = origin ?? defaultOrigin.Value;
|
||||||
|
|
||||||
@ -91,11 +93,13 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
|
|
||||||
public override void Commit()
|
public override void Commit()
|
||||||
{
|
{
|
||||||
if (objectsInRotation == null)
|
if (!OperationInProgress.Value)
|
||||||
throw new InvalidOperationException($"Cannot {nameof(Commit)} a rotate operation without calling {nameof(Begin)} first!");
|
throw new InvalidOperationException($"Cannot {nameof(Commit)} a rotate operation without calling {nameof(Begin)} first!");
|
||||||
|
|
||||||
changeHandler?.EndChange();
|
changeHandler?.EndChange();
|
||||||
|
|
||||||
|
base.Commit();
|
||||||
|
|
||||||
objectsInRotation = null;
|
objectsInRotation = null;
|
||||||
originalPositions = null;
|
originalPositions = null;
|
||||||
originalPathControlPointPositions = null;
|
originalPathControlPointPositions = null;
|
||||||
|
@ -72,9 +72,11 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
|
|
||||||
public override void Begin()
|
public override void Begin()
|
||||||
{
|
{
|
||||||
if (objectsInScale != null)
|
if (OperationInProgress.Value)
|
||||||
throw new InvalidOperationException($"Cannot {nameof(Begin)} a scale operation while another is in progress!");
|
throw new InvalidOperationException($"Cannot {nameof(Begin)} a scale operation while another is in progress!");
|
||||||
|
|
||||||
|
base.Begin();
|
||||||
|
|
||||||
changeHandler?.BeginChange();
|
changeHandler?.BeginChange();
|
||||||
|
|
||||||
objectsInScale = selectedMovableObjects.ToDictionary(ho => ho, ho => new OriginalHitObjectState(ho));
|
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)
|
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!");
|
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;
|
Vector2 actualOrigin = origin ?? defaultOrigin.Value;
|
||||||
|
|
||||||
@ -117,11 +119,13 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
|
|
||||||
public override void Commit()
|
public override void Commit()
|
||||||
{
|
{
|
||||||
if (objectsInScale == null)
|
if (!OperationInProgress.Value)
|
||||||
throw new InvalidOperationException($"Cannot {nameof(Commit)} a rotate operation without calling {nameof(Begin)} first!");
|
throw new InvalidOperationException($"Cannot {nameof(Commit)} a rotate operation without calling {nameof(Begin)} first!");
|
||||||
|
|
||||||
changeHandler?.EndChange();
|
changeHandler?.EndChange();
|
||||||
|
|
||||||
|
base.Commit();
|
||||||
|
|
||||||
objectsInScale = null;
|
objectsInScale = null;
|
||||||
OriginalSurroundingQuad = null;
|
OriginalSurroundingQuad = null;
|
||||||
defaultOrigin = null;
|
defaultOrigin = null;
|
||||||
|
@ -77,12 +77,14 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
{
|
{
|
||||||
case GlobalAction.EditorToggleRotateControl:
|
case GlobalAction.EditorToggleRotateControl:
|
||||||
{
|
{
|
||||||
|
if (!RotationHandler.OperationInProgress.Value || rotateButton.Selected.Value)
|
||||||
rotateButton.TriggerClick();
|
rotateButton.TriggerClick();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
case GlobalAction.EditorToggleScaleControl:
|
case GlobalAction.EditorToggleScaleControl:
|
||||||
{
|
{
|
||||||
|
if (!ScaleHandler.OperationInProgress.Value || scaleButton.Selected.Value)
|
||||||
scaleButton.TriggerClick();
|
scaleButton.TriggerClick();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,8 @@ namespace osu.Game.Tests.Visual.Editing
|
|||||||
|
|
||||||
targetContainer = getTargetContainer();
|
targetContainer = getTargetContainer();
|
||||||
initialRotation = targetContainer!.Rotation;
|
initialRotation = targetContainer!.Rotation;
|
||||||
|
|
||||||
|
base.Begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(float rotation, Vector2? origin = null)
|
public override void Update(float rotation, Vector2? origin = null)
|
||||||
@ -102,6 +104,8 @@ namespace osu.Game.Tests.Visual.Editing
|
|||||||
|
|
||||||
targetContainer = null;
|
targetContainer = null;
|
||||||
initialRotation = null;
|
initialRotation = null;
|
||||||
|
|
||||||
|
base.Commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,8 @@ namespace osu.Game.Overlays.SkinEditor
|
|||||||
originalRotations = objectsInRotation.ToDictionary(d => d, d => d.Rotation);
|
originalRotations = objectsInRotation.ToDictionary(d => d, d => d.Rotation);
|
||||||
originalPositions = objectsInRotation.ToDictionary(d => d, d => d.ToScreenSpace(d.OriginPosition));
|
originalPositions = objectsInRotation.ToDictionary(d => d, d => d.ToScreenSpace(d.OriginPosition));
|
||||||
defaultOrigin = GeometryUtils.GetSurroundingQuad(objectsInRotation.SelectMany(d => d.ScreenSpaceDrawQuad.GetVertices().ToArray())).Centre;
|
defaultOrigin = GeometryUtils.GetSurroundingQuad(objectsInRotation.SelectMany(d => d.ScreenSpaceDrawQuad.GetVertices().ToArray())).Centre;
|
||||||
|
|
||||||
|
base.Begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(float rotation, Vector2? origin = null)
|
public override void Update(float rotation, Vector2? origin = null)
|
||||||
@ -99,6 +101,8 @@ namespace osu.Game.Overlays.SkinEditor
|
|||||||
originalPositions = null;
|
originalPositions = null;
|
||||||
originalRotations = null;
|
originalRotations = null;
|
||||||
defaultOrigin = null;
|
defaultOrigin = null;
|
||||||
|
|
||||||
|
base.Commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
|
|
||||||
if (rotationHandler == null) return false;
|
if (rotationHandler == null) return false;
|
||||||
|
|
||||||
|
if (rotationHandler.OperationInProgress.Value)
|
||||||
|
return false;
|
||||||
|
|
||||||
rotationHandler.Begin();
|
rotationHandler.Begin();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
|
|
||||||
if (scaleHandler == null) return false;
|
if (scaleHandler == null) return false;
|
||||||
|
|
||||||
|
if (scaleHandler.OperationInProgress.Value)
|
||||||
|
return false;
|
||||||
|
|
||||||
originalAnchor = Anchor;
|
originalAnchor = Anchor;
|
||||||
|
|
||||||
scaleHandler.Begin();
|
scaleHandler.Begin();
|
||||||
|
@ -12,6 +12,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class SelectionRotationHandler : Component
|
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>
|
/// <summary>
|
||||||
/// Whether rotation anchored by the selection origin can currently be performed.
|
/// Whether rotation anchored by the selection origin can currently be performed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -50,6 +55,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
public virtual void Begin()
|
public virtual void Begin()
|
||||||
{
|
{
|
||||||
|
OperationInProgress.Value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -85,6 +91,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
public virtual void Commit()
|
public virtual void Commit()
|
||||||
{
|
{
|
||||||
|
OperationInProgress.Value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class SelectionScaleHandler : Component
|
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>
|
/// <summary>
|
||||||
/// Whether horizontal scaling (from the left or right edge) support should be enabled.
|
/// Whether horizontal scaling (from the left or right edge) support should be enabled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -63,6 +68,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
public virtual void Begin()
|
public virtual void Begin()
|
||||||
{
|
{
|
||||||
|
OperationInProgress.Value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -99,6 +105,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
public virtual void Commit()
|
public virtual void Commit()
|
||||||
{
|
{
|
||||||
|
OperationInProgress.Value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user