diff --git a/Source/Editor/Surface/Archetypes/Tools.cs b/Source/Editor/Surface/Archetypes/Tools.cs index 555f7ad55..685068986 100644 --- a/Source/Editor/Surface/Archetypes/Tools.cs +++ b/Source/Editor/Surface/Archetypes/Tools.cs @@ -1059,7 +1059,10 @@ namespace FlaxEditor.Surface.Archetypes internal class RerouteNode : SurfaceNode, IConnectionInstigator { internal static readonly Float2 DefaultSize = new Float2(FlaxEditor.Surface.Constants.BoxRowHeight); + + internal bool DrawDisabled => _input.AllConnectionsDisabled || _output.AllConnectionsDisabled; internal override bool DrawBasicShadow => false; + private Rectangle _localBounds; private InputBox _input; private OutputBox _output; @@ -1165,6 +1168,9 @@ namespace FlaxEditor.Surface.Archetypes /// public override void Draw() { + // Update active state of input + _input.IsActive = !_output.AllConnectionsDisabled; + var style = Surface.Style; var connectionColor = style.Colors.Default; var type = ScriptType.Null; @@ -1178,6 +1184,10 @@ namespace FlaxEditor.Surface.Archetypes Surface.Style.GetConnectionColor(type, hints, out connectionColor); } + // Draw the box as disabled if needed + if (DrawDisabled) + connectionColor = connectionColor * 0.6f; + if (!_input.HasAnyConnection) Render2D.FillRectangle(new Rectangle(-barHorizontalOffset - barHeight * 2, (DefaultSize.Y - barHeight) / 2, barHeight * 2, barHeight), connectionColor); if (!_output.HasAnyConnection) diff --git a/Source/Editor/Surface/Elements/Box.cs b/Source/Editor/Surface/Elements/Box.cs index 08023ac93..4c86af041 100644 --- a/Source/Editor/Surface/Elements/Box.cs +++ b/Source/Editor/Surface/Elements/Box.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Linq; using FlaxEditor.Scripting; using FlaxEditor.Surface.Undo; using FlaxEngine; @@ -194,6 +195,16 @@ namespace FlaxEditor.Surface.Elements set => _isActive = value; } + /// + /// Gets if the box is disabled (user can still connect, but connections will be ignored). + /// + public bool IsDisabled => !(Enabled && IsActive); + + /// + /// Gets a value indicating whether all connections are disabled. + /// + public bool AllConnectionsDisabled => Connections.All(c => c.IsDisabled); + /// protected Box(SurfaceNode parentNode, NodeElementArchetype archetype, Float2 location) : base(parentNode, archetype, location, new Float2(Constants.BoxRowHeight), false) diff --git a/Source/Editor/Surface/Elements/OutputBox.cs b/Source/Editor/Surface/Elements/OutputBox.cs index 7e271fef0..0673f694b 100644 --- a/Source/Editor/Surface/Elements/OutputBox.cs +++ b/Source/Editor/Surface/Elements/OutputBox.cs @@ -190,7 +190,7 @@ namespace FlaxEditor.Surface.Elements Box targetBox = Connections[i]; var endPos = targetBox.ConnectionOrigin; var highlight = DefaultConnectionThickness + Mathf.Max(startHighlight, targetBox.ConnectionsHighlightIntensity); - var alpha = targetBox.Enabled && targetBox.IsActive ? 1.0f : 0.6f; + var alpha = targetBox.IsDisabled ? 0.6f : 1.0f; // We have to calculate an offset here to preserve the original color for when the default connection thickness is larger than 1 var highlightOffset = (highlight - (DefaultConnectionThickness - 1)); @@ -216,7 +216,7 @@ namespace FlaxEditor.Surface.Elements // Draw all the connections var startPos = ConnectionOrigin; var endPos = targetBox.ConnectionOrigin; - var alpha = targetBox.Enabled && targetBox.IsActive ? 1.0f : 0.6f; + var alpha = targetBox.IsDisabled ? 0.6f : 1.0f; var color = _currentTypeColor * alpha; DrawConnection(Surface.Style, ref startPos, ref endPos, ref color, SelectedConnectionThickness); } diff --git a/Source/Editor/Surface/SurfaceStyle.cs b/Source/Editor/Surface/SurfaceStyle.cs index 654cf7abf..86707efd3 100644 --- a/Source/Editor/Surface/SurfaceStyle.cs +++ b/Source/Editor/Surface/SurfaceStyle.cs @@ -233,7 +233,7 @@ namespace FlaxEditor.Surface // Draw icon bool hasConnections = box.HasAnyConnection; - float alpha = box.Enabled && box.IsActive ? 1.0f : 0.6f; + float alpha = box.IsDisabled ? 0.6f : 1.0f; Color color = box.CurrentTypeColor * alpha; var style = box.Surface.Style; SpriteHandle icon;