From 47e1547d292f210986dd5de06477244f59ec7d37 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Thu, 12 Jun 2025 18:12:06 +0200 Subject: [PATCH] improve behaviour of visject node cm menu --- Source/Editor/Surface/SurfaceNode.cs | 8 ++++++++ .../Surface/VisjectSurface.ContextMenu.cs | 18 +++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Surface/SurfaceNode.cs b/Source/Editor/Surface/SurfaceNode.cs index 8a42a7a92..1fe9ea44b 100644 --- a/Source/Editor/Surface/SurfaceNode.cs +++ b/Source/Editor/Surface/SurfaceNode.cs @@ -40,6 +40,11 @@ namespace FlaxEditor.Surface [HideInEditor] public class SurfaceNode : SurfaceControl { + /// + /// The box to draw a highlight around. Drawing will be skipped if null. + /// + internal Box highlightBox; + /// /// Flag used to discard node values setting during event sending for node UI flushing. /// @@ -1101,6 +1106,9 @@ namespace FlaxEditor.Surface Render2D.DrawSprite(icon, new Rectangle(-7, -7, 16, 16), new Color(0.9f, 0.9f, 0.9f)); Render2D.DrawSprite(icon, new Rectangle(-6, -6, 14, 14), new Color(0.894117647f, 0.0784313725f, 0.0f)); } + + if (highlightBox != null) + Render2D.DrawRectangle(highlightBox.Bounds, style.BorderHighlighted, 2f); } /// diff --git a/Source/Editor/Surface/VisjectSurface.ContextMenu.cs b/Source/Editor/Surface/VisjectSurface.ContextMenu.cs index ee7dd33e5..23e52ca7d 100644 --- a/Source/Editor/Surface/VisjectSurface.ContextMenu.cs +++ b/Source/Editor/Surface/VisjectSurface.ContextMenu.cs @@ -402,7 +402,7 @@ namespace FlaxEditor.Surface _cmFormatNodesConnectionButton = menu.AddButton("Format node(s)", () => { FormatGraph(SelectedNodes); }); _cmFormatNodesConnectionButton.Enabled = CanEdit && HasNodesSelection; - _cmRemoveNodeConnectionsButton = menu.AddButton("Remove all connections to that node(s)", () => + _cmRemoveNodeConnectionsButton = menu.AddButton("Remove all connections", () => { var nodes = ((List)menu.Tag); @@ -428,8 +428,10 @@ namespace FlaxEditor.Surface MarkAsEdited(); }); - _cmRemoveNodeConnectionsButton.Enabled = CanEdit; - _cmRemoveBoxConnectionsButton = menu.AddButton("Remove all connections to that box", () => + bool anyConnection = SelectedNodes.Any(n => n.GetBoxes().Any(b => b.HasAnyConnection)); + _cmRemoveNodeConnectionsButton.Enabled = CanEdit && anyConnection; + + _cmRemoveBoxConnectionsButton = menu.AddButton("Remove all socket connections", () => { var boxUnderMouse = (Box)_cmRemoveBoxConnectionsButton.Tag; if (Undo != null) @@ -450,6 +452,16 @@ namespace FlaxEditor.Surface var boxUnderMouse = GetChildAtRecursive(location) as Box; _cmRemoveBoxConnectionsButton.Enabled = boxUnderMouse != null && boxUnderMouse.HasAnyConnection; _cmRemoveBoxConnectionsButton.Tag = boxUnderMouse; + + if (boxUnderMouse != null) + { + boxUnderMouse.ParentNode.highlightBox = boxUnderMouse; + menu.VisibleChanged += (c) => + { + if (!c.Visible) + boxUnderMouse.ParentNode.highlightBox = null; + }; + } } controlUnderMouse?.OnShowSecondaryContextMenu(menu, controlUnderMouse.PointFromParent(location));