Various improvements to Visject Surface
This commit is contained in:
@@ -923,7 +923,7 @@ namespace FlaxEditor.Surface
|
||||
OnValuesChanged();
|
||||
Surface?.MarkAsEdited(graphEdited);
|
||||
|
||||
if (Surface?.Undo != null)
|
||||
if (Surface != null)
|
||||
Surface.AddBatchedUndoAction(new EditNodeValuesAction(this, before, graphEdited));
|
||||
|
||||
_isDuringValuesEditing = false;
|
||||
@@ -950,7 +950,7 @@ namespace FlaxEditor.Surface
|
||||
OnValuesChanged();
|
||||
Surface.MarkAsEdited(graphEdited);
|
||||
|
||||
if (Surface?.Undo != null)
|
||||
if (Surface != null)
|
||||
Surface.AddBatchedUndoAction(new EditNodeValuesAction(this, before, graphEdited));
|
||||
|
||||
_isDuringValuesEditing = false;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FlaxEditor.Scripting;
|
||||
using FlaxEditor.Surface.Elements;
|
||||
using FlaxEditor.Surface.Undo;
|
||||
using FlaxEngine;
|
||||
|
||||
@@ -243,9 +243,12 @@ namespace FlaxEditor.Surface
|
||||
node.Location += delta;
|
||||
_leftMouseDownPos = location;
|
||||
_movingNodesDelta += delta;
|
||||
if (_movingNodes.Count > 0)
|
||||
{
|
||||
Cursor = CursorType.SizeAll;
|
||||
MarkAsEdited(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Handled
|
||||
return;
|
||||
|
||||
@@ -730,11 +730,18 @@ namespace FlaxEditor.Surface
|
||||
/// <param name="withUndo">True if use undo/redo action for node removing.</param>
|
||||
public void Delete(IEnumerable<SurfaceControl> controls, bool withUndo = true)
|
||||
{
|
||||
if (!CanEdit || controls == null || !controls.Any())
|
||||
return;
|
||||
|
||||
var selectionChanged = false;
|
||||
List<SurfaceNode> nodes = null;
|
||||
foreach (var control in controls)
|
||||
{
|
||||
selectionChanged |= control.IsSelected;
|
||||
if (control.IsSelected)
|
||||
{
|
||||
selectionChanged = true;
|
||||
control.IsSelected = false;
|
||||
}
|
||||
|
||||
if (control is SurfaceNode node)
|
||||
{
|
||||
@@ -802,54 +809,7 @@ namespace FlaxEditor.Surface
|
||||
{
|
||||
if (!CanEdit)
|
||||
return;
|
||||
|
||||
var node = control as SurfaceNode;
|
||||
if (node == null)
|
||||
{
|
||||
Context.OnControlDeleted(control);
|
||||
MarkAsEdited();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((node.Archetype.Flags & NodeFlags.NoRemove) != 0)
|
||||
return;
|
||||
|
||||
if (control.IsSelected)
|
||||
{
|
||||
control.IsSelected = false;
|
||||
SelectionChanged?.Invoke();
|
||||
}
|
||||
|
||||
if (Undo == null || !withUndo)
|
||||
{
|
||||
// Remove node
|
||||
node.RemoveConnections();
|
||||
Nodes.Remove(node);
|
||||
Context.OnControlDeleted(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
var actions = new List<IUndoAction>();
|
||||
|
||||
// Break connections for node
|
||||
{
|
||||
var action = new EditNodeConnections(Context, node);
|
||||
node.RemoveConnections();
|
||||
action.End();
|
||||
actions.Add(action);
|
||||
}
|
||||
|
||||
// Remove node
|
||||
{
|
||||
var action = new AddRemoveNodeAction(node, false);
|
||||
action.Do();
|
||||
actions.Add(action);
|
||||
}
|
||||
|
||||
Undo.AddAction(new MultiUndoAction(actions, "Remove node"));
|
||||
}
|
||||
|
||||
MarkAsEdited();
|
||||
Delete(new[] { control }, withUndo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -859,72 +819,7 @@ namespace FlaxEditor.Surface
|
||||
{
|
||||
if (!CanEdit)
|
||||
return;
|
||||
bool edited = false;
|
||||
|
||||
List<SurfaceNode> nodes = null;
|
||||
for (int i = 0; i < _rootControl.Children.Count; i++)
|
||||
{
|
||||
if (_rootControl.Children[i] is SurfaceNode node)
|
||||
{
|
||||
if (node.IsSelected && (node.Archetype.Flags & NodeFlags.NoRemove) == 0)
|
||||
{
|
||||
if (nodes == null)
|
||||
nodes = new List<SurfaceNode>();
|
||||
nodes.Add(node);
|
||||
edited = true;
|
||||
}
|
||||
}
|
||||
else if (_rootControl.Children[i] is SurfaceControl control && control.IsSelected)
|
||||
{
|
||||
i--;
|
||||
Context.OnControlDeleted(control);
|
||||
edited = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (nodes != null)
|
||||
{
|
||||
if (Undo == null)
|
||||
{
|
||||
// Remove all nodes
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
node.RemoveConnections();
|
||||
Nodes.Remove(node);
|
||||
Context.OnControlDeleted(node);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var actions = new List<IUndoAction>();
|
||||
|
||||
// Break connections for all nodes
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
var action = new EditNodeConnections(Context, node);
|
||||
node.RemoveConnections();
|
||||
action.End();
|
||||
actions.Add(action);
|
||||
}
|
||||
|
||||
// Remove all nodes
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
var action = new AddRemoveNodeAction(node, false);
|
||||
action.Do();
|
||||
actions.Add(action);
|
||||
}
|
||||
|
||||
Undo.AddAction(new MultiUndoAction(actions, nodes.Count == 1 ? "Remove node" : "Remove nodes"));
|
||||
}
|
||||
}
|
||||
|
||||
if (edited)
|
||||
{
|
||||
MarkAsEdited();
|
||||
}
|
||||
|
||||
SelectionChanged?.Invoke();
|
||||
Delete(SelectedControls, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -395,8 +395,8 @@ namespace FlaxEditor.Surface
|
||||
OnControlSpawned(node);
|
||||
|
||||
// Undo action
|
||||
if (Surface != null && Surface.Undo != null)
|
||||
Surface.Undo.AddAction(new AddRemoveNodeAction(node, true));
|
||||
if (Surface != null)
|
||||
Surface.AddBatchedUndoAction(new AddRemoveNodeAction(node, true));
|
||||
|
||||
MarkAsModified();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user