propagate disabled node boxes across reroute nodes
This commit is contained in:
@@ -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
|
||||
/// <inheritdoc />
|
||||
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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets if the box is disabled (user can still connect, but connections will be ignored).
|
||||
/// </summary>
|
||||
public bool IsDisabled => !(Enabled && IsActive);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether all connections are disabled.
|
||||
/// </summary>
|
||||
public bool AllConnectionsDisabled => Connections.All(c => c.IsDisabled);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected Box(SurfaceNode parentNode, NodeElementArchetype archetype, Float2 location)
|
||||
: base(parentNode, archetype, location, new Float2(Constants.BoxRowHeight), false)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user