Fix invalid BT node decorator linkage after removing it

#2059
This commit is contained in:
Wojtek Figat
2023-12-16 17:08:54 +01:00
parent d8856ddaa7
commit c145042f52
3 changed files with 29 additions and 4 deletions

View File

@@ -755,6 +755,29 @@ namespace FlaxEditor.Surface.Archetypes
}
}
/// <inheritdoc />
public override void OnDeleted(SurfaceNodeActions action)
{
// Unlink from the current parent (when deleted by user)
var node = Node;
if (node != null)
{
if (action == SurfaceNodeActions.User)
{
var decorators = node.DecoratorIds;
decorators.Remove(ID);
node.DecoratorIds = decorators;
}
else
{
node._decorators = null;
node.ResizeAuto();
}
}
base.OnDeleted(action);
}
public override void OnSurfaceCanEditChanged(bool canEdit)
{
base.OnSurfaceCanEditChanged(canEdit);

View File

@@ -19,6 +19,7 @@ namespace FlaxEditor.Surface.Undo
private ushort _typeId;
private Float2 _nodeLocation;
private object[] _nodeValues;
private SurfaceNodeActions _actionType = SurfaceNodeActions.User; // Action usage flow is first to apply user effect such as removing/adding node, then we use Undo type so node can react to this
public AddRemoveNodeAction(SurfaceNode node, bool isAdd)
{
@@ -38,6 +39,7 @@ namespace FlaxEditor.Surface.Undo
Add();
else
Remove();
_actionType = SurfaceNodeActions.Undo;
}
/// <inheritdoc />
@@ -67,8 +69,8 @@ namespace FlaxEditor.Surface.Undo
else if (_nodeValues != null && _nodeValues.Length != 0)
throw new InvalidOperationException("Invalid node values.");
node.Location = _nodeLocation;
context.OnControlLoaded(node, SurfaceNodeActions.Undo);
node.OnSurfaceLoaded(SurfaceNodeActions.Undo);
context.OnControlLoaded(node, _actionType);
node.OnSurfaceLoaded(_actionType);
context.MarkAsModified();
}
@@ -89,7 +91,7 @@ namespace FlaxEditor.Surface.Undo
// Remove node
context.Nodes.Remove(node);
context.OnControlDeleted(node, SurfaceNodeActions.Undo);
context.OnControlDeleted(node, _actionType);
context.MarkAsModified();
}

View File

@@ -837,7 +837,7 @@ namespace FlaxEditor.Surface
actions.Add(action);
}
Undo.AddAction(new MultiUndoAction(actions, nodes.Count == 1 ? "Remove node" : "Remove nodes"));
AddBatchedUndoAction(new MultiUndoAction(actions, nodes.Count == 1 ? "Remove node" : "Remove nodes"));
}
}