Improvements for Visject Surface
This commit is contained in:
@@ -156,7 +156,7 @@ namespace FlaxEditor.Surface
|
||||
/// </summary>
|
||||
/// <param name="width">The width.</param>
|
||||
/// <param name="height">The height.</param>
|
||||
protected void Resize(float width, float height)
|
||||
public void Resize(float width, float height)
|
||||
{
|
||||
Size = CalculateNodeSize(width, height);
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace FlaxEditor.Surface
|
||||
/// <summary>
|
||||
/// Automatically resizes the node to match the title size and all the elements for best fit of the node dimensions.
|
||||
/// </summary>
|
||||
protected void ResizeAuto()
|
||||
public void ResizeAuto()
|
||||
{
|
||||
var width = 0.0f;
|
||||
var height = 0.0f;
|
||||
|
||||
@@ -141,8 +141,11 @@ namespace FlaxEditor.Surface
|
||||
// Create secondary context menu
|
||||
var menu = new FlaxEditor.GUI.ContextMenu.ContextMenu();
|
||||
|
||||
menu.AddButton("Save", _onSave).Enabled = CanEdit;
|
||||
menu.AddSeparator();
|
||||
if (_onSave != null)
|
||||
{
|
||||
menu.AddButton("Save", _onSave).Enabled = CanEdit;
|
||||
menu.AddSeparator();
|
||||
}
|
||||
_cmCopyButton = menu.AddButton("Copy", Copy);
|
||||
menu.AddButton("Paste", Paste).Enabled = CanEdit && CanPaste();
|
||||
_cmDuplicateButton = menu.AddButton("Duplicate", Duplicate);
|
||||
@@ -219,13 +222,9 @@ namespace FlaxEditor.Surface
|
||||
}
|
||||
menu.AddSeparator();
|
||||
|
||||
_cmFormatNodesConnectionButton = menu.AddButton("Format node(s)", () =>
|
||||
{
|
||||
FormatGraph(SelectedNodes);
|
||||
});
|
||||
_cmFormatNodesConnectionButton.Enabled = HasNodesSelection;
|
||||
_cmFormatNodesConnectionButton = menu.AddButton("Format node(s)", () => { FormatGraph(SelectedNodes); });
|
||||
_cmFormatNodesConnectionButton.Enabled = CanEdit && HasNodesSelection;
|
||||
|
||||
menu.AddSeparator();
|
||||
_cmRemoveNodeConnectionsButton = menu.AddButton("Remove all connections to that node(s)", () =>
|
||||
{
|
||||
var nodes = ((List<SurfaceNode>)menu.Tag);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FlaxEngine;
|
||||
using FlaxEditor.Surface.Elements;
|
||||
using FlaxEditor.Surface.Undo;
|
||||
@@ -36,9 +34,10 @@ namespace FlaxEditor.Surface
|
||||
/// Uses the Sugiyama method
|
||||
/// </summary>
|
||||
/// <param name="nodes">List of nodes</param>
|
||||
protected void FormatGraph(List<SurfaceNode> nodes)
|
||||
public void FormatGraph(List<SurfaceNode> nodes)
|
||||
{
|
||||
if (nodes.Count <= 1 || !CanEdit) return;
|
||||
if (nodes.Count <= 1)
|
||||
return;
|
||||
|
||||
var nodesToVisit = new HashSet<SurfaceNode>(nodes);
|
||||
|
||||
@@ -70,7 +69,6 @@ namespace FlaxEditor.Surface
|
||||
queue.Enqueue(box.Connections[j].ParentNode);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,7 +83,8 @@ namespace FlaxEditor.Surface
|
||||
/// <param name="nodes">List of connected nodes</param>
|
||||
protected void FormatConnectedGraph(List<SurfaceNode> nodes)
|
||||
{
|
||||
if (nodes.Count <= 1 || !CanEdit) return;
|
||||
if (nodes.Count <= 1)
|
||||
return;
|
||||
|
||||
var boundingBox = GetNodesBounds(nodes);
|
||||
|
||||
@@ -93,9 +92,9 @@ namespace FlaxEditor.Surface
|
||||
|
||||
// Rightmost nodes with none of our nodes to the right of them
|
||||
var endNodes = nodes
|
||||
.Where(n => !n.GetBoxes().Any(b => b.IsOutput && b.Connections.Any(c => nodeData.ContainsKey(c.ParentNode))))
|
||||
.OrderBy(n => n.Top) // Keep their relative order
|
||||
.ToList();
|
||||
.Where(n => !n.GetBoxes().Any(b => b.IsOutput && b.Connections.Any(c => nodeData.ContainsKey(c.ParentNode))))
|
||||
.OrderBy(n => n.Top) // Keep their relative order
|
||||
.ToList();
|
||||
|
||||
// Longest path layering
|
||||
int maxLayer = SetLayers(nodeData, endNodes);
|
||||
@@ -219,7 +218,8 @@ namespace FlaxEditor.Surface
|
||||
|
||||
void SetOffsets(SurfaceNode node, NodeFormattingData straightParentData)
|
||||
{
|
||||
if (!nodeData.TryGetValue(node, out var data)) return;
|
||||
if (!nodeData.TryGetValue(node, out var data))
|
||||
return;
|
||||
|
||||
// If we realize that the current node would collide with an already existing node in this layer
|
||||
if (data.Layer >= 0 && offsets[data.Layer] > data.Offset)
|
||||
@@ -282,6 +282,5 @@ namespace FlaxEditor.Surface
|
||||
|
||||
return maxOffset;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ namespace FlaxEditor.Surface
|
||||
/// <param name="style">The custom surface style. Use null to create the default style.</param>
|
||||
/// <param name="groups">The custom surface node types. Pass null to use the default nodes set.</param>
|
||||
/// <param name="supportsDebugging">True if surface supports debugging features (breakpoints, etc.).</param>
|
||||
public VisjectSurface(IVisjectSurfaceOwner owner, Action onSave, FlaxEditor.Undo undo = null, SurfaceStyle style = null, List<GroupArchetype> groups = null, bool supportsDebugging = false)
|
||||
public VisjectSurface(IVisjectSurfaceOwner owner, Action onSave = null, FlaxEditor.Undo undo = null, SurfaceStyle style = null, List<GroupArchetype> groups = null, bool supportsDebugging = false)
|
||||
{
|
||||
AnchorPreset = AnchorPresets.StretchAll;
|
||||
Offsets = Margin.Zero;
|
||||
|
||||
Reference in New Issue
Block a user