improve behaviour of visject node cm menu

This commit is contained in:
xxSeys1
2025-06-12 18:12:06 +02:00
parent eee4e55cf0
commit 47e1547d29
2 changed files with 23 additions and 3 deletions

View File

@@ -40,6 +40,11 @@ namespace FlaxEditor.Surface
[HideInEditor]
public class SurfaceNode : SurfaceControl
{
/// <summary>
/// The box to draw a highlight around. Drawing will be skipped if null.
/// </summary>
internal Box highlightBox;
/// <summary>
/// Flag used to discard node values setting during event sending for node UI flushing.
/// </summary>
@@ -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);
}
/// <inheritdoc />

View File

@@ -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<SurfaceNode>)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));