From 78e093245d8594356cd995e1ca87cc8e8a621b94 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 8 Oct 2021 15:30:42 +0200 Subject: [PATCH] Improvements for Visject Surface --- Source/Editor/Surface/SurfaceNode.cs | 4 ++-- .../Surface/VisjectSurface.ContextMenu.cs | 15 +++++++------ .../Surface/VisjectSurface.Formatting.cs | 21 +++++++++---------- Source/Editor/Surface/VisjectSurface.cs | 2 +- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Source/Editor/Surface/SurfaceNode.cs b/Source/Editor/Surface/SurfaceNode.cs index ed77446ff..d52a845c4 100644 --- a/Source/Editor/Surface/SurfaceNode.cs +++ b/Source/Editor/Surface/SurfaceNode.cs @@ -156,7 +156,7 @@ namespace FlaxEditor.Surface /// /// The width. /// The height. - 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 /// /// Automatically resizes the node to match the title size and all the elements for best fit of the node dimensions. /// - protected void ResizeAuto() + public void ResizeAuto() { var width = 0.0f; var height = 0.0f; diff --git a/Source/Editor/Surface/VisjectSurface.ContextMenu.cs b/Source/Editor/Surface/VisjectSurface.ContextMenu.cs index 5510b0fa8..3ae634fc7 100644 --- a/Source/Editor/Surface/VisjectSurface.ContextMenu.cs +++ b/Source/Editor/Surface/VisjectSurface.ContextMenu.cs @@ -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)menu.Tag); diff --git a/Source/Editor/Surface/VisjectSurface.Formatting.cs b/Source/Editor/Surface/VisjectSurface.Formatting.cs index 848f79157..80df9e9f7 100644 --- a/Source/Editor/Surface/VisjectSurface.Formatting.cs +++ b/Source/Editor/Surface/VisjectSurface.Formatting.cs @@ -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 /// /// List of nodes - protected void FormatGraph(List nodes) + public void FormatGraph(List nodes) { - if (nodes.Count <= 1 || !CanEdit) return; + if (nodes.Count <= 1) + return; var nodesToVisit = new HashSet(nodes); @@ -70,7 +69,6 @@ namespace FlaxEditor.Surface queue.Enqueue(box.Connections[j].ParentNode); } } - } } } @@ -85,7 +83,8 @@ namespace FlaxEditor.Surface /// List of connected nodes protected void FormatConnectedGraph(List 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; } - } } diff --git a/Source/Editor/Surface/VisjectSurface.cs b/Source/Editor/Surface/VisjectSurface.cs index 4d0ab8e63..52aa37bf4 100644 --- a/Source/Editor/Surface/VisjectSurface.cs +++ b/Source/Editor/Surface/VisjectSurface.cs @@ -329,7 +329,7 @@ namespace FlaxEditor.Surface /// The custom surface style. Use null to create the default style. /// The custom surface node types. Pass null to use the default nodes set. /// True if surface supports debugging features (breakpoints, etc.). - public VisjectSurface(IVisjectSurfaceOwner owner, Action onSave, FlaxEditor.Undo undo = null, SurfaceStyle style = null, List groups = null, bool supportsDebugging = false) + public VisjectSurface(IVisjectSurfaceOwner owner, Action onSave = null, FlaxEditor.Undo undo = null, SurfaceStyle style = null, List groups = null, bool supportsDebugging = false) { AnchorPreset = AnchorPresets.StretchAll; Offsets = Margin.Zero;