From d47a191d5ccf2742d675f957a814c4cafeaf3afe Mon Sep 17 00:00:00 2001 From: Nils Hausfeld Date: Fri, 24 May 2024 22:26:20 +0200 Subject: [PATCH] - Added IsActive state to boxes - Replaced box.enabled with box.isActive on some nodes - Made connection lines draw with alpha when connected box is inactive --- Source/Editor/Surface/Archetypes/Material.cs | 168 +++++++++--------- .../Surface/Archetypes/ParticleModules.cs | 2 +- Source/Editor/Surface/Elements/Box.cs | 14 ++ Source/Editor/Surface/Elements/OutputBox.cs | 7 +- Source/Editor/Surface/SurfaceStyle.cs | 2 +- 5 files changed, 105 insertions(+), 88 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/Material.cs b/Source/Editor/Surface/Archetypes/Material.cs index 5182fdb36..58d1b854d 100644 --- a/Source/Editor/Surface/Archetypes/Material.cs +++ b/Source/Editor/Surface/Archetypes/Material.cs @@ -71,20 +71,20 @@ namespace FlaxEditor.Surface.Archetypes // Layered material if (GetBox(MaterialNodeBoxes.Layer).HasAnyConnection) { - GetBox(MaterialNodeBoxes.Color).Enabled = false; - GetBox(MaterialNodeBoxes.Mask).Enabled = false; - GetBox(MaterialNodeBoxes.Emissive).Enabled = false; - GetBox(MaterialNodeBoxes.Metalness).Enabled = false; - GetBox(MaterialNodeBoxes.Specular).Enabled = false; - GetBox(MaterialNodeBoxes.Roughness).Enabled = false; - GetBox(MaterialNodeBoxes.AmbientOcclusion).Enabled = false; - GetBox(MaterialNodeBoxes.Normal).Enabled = false; - GetBox(MaterialNodeBoxes.Opacity).Enabled = false; - GetBox(MaterialNodeBoxes.Refraction).Enabled = false; - GetBox(MaterialNodeBoxes.PositionOffset).Enabled = false; - GetBox(MaterialNodeBoxes.TessellationMultiplier).Enabled = false; - GetBox(MaterialNodeBoxes.WorldDisplacement).Enabled = false; - GetBox(MaterialNodeBoxes.SubsurfaceColor).Enabled = false; + GetBox(MaterialNodeBoxes.Color).IsActive = false; + GetBox(MaterialNodeBoxes.Mask).IsActive = false; + GetBox(MaterialNodeBoxes.Emissive).IsActive = false; + GetBox(MaterialNodeBoxes.Metalness).IsActive = false; + GetBox(MaterialNodeBoxes.Specular).IsActive = false; + GetBox(MaterialNodeBoxes.Roughness).IsActive = false; + GetBox(MaterialNodeBoxes.AmbientOcclusion).IsActive = false; + GetBox(MaterialNodeBoxes.Normal).IsActive = false; + GetBox(MaterialNodeBoxes.Opacity).IsActive = false; + GetBox(MaterialNodeBoxes.Refraction).IsActive = false; + GetBox(MaterialNodeBoxes.PositionOffset).IsActive = false; + GetBox(MaterialNodeBoxes.TessellationMultiplier).IsActive = false; + GetBox(MaterialNodeBoxes.WorldDisplacement).IsActive = false; + GetBox(MaterialNodeBoxes.SubsurfaceColor).IsActive = false; return; } @@ -102,94 +102,94 @@ namespace FlaxEditor.Surface.Archetypes bool isNotUnlit = info.ShadingModel != MaterialShadingModel.Unlit; bool withTess = info.TessellationMode != TessellationMethod.None; - GetBox(MaterialNodeBoxes.Color).Enabled = isNotUnlit; - GetBox(MaterialNodeBoxes.Mask).Enabled = true; - GetBox(MaterialNodeBoxes.Emissive).Enabled = true; - GetBox(MaterialNodeBoxes.Metalness).Enabled = isNotUnlit; - GetBox(MaterialNodeBoxes.Specular).Enabled = isNotUnlit; - GetBox(MaterialNodeBoxes.Roughness).Enabled = isNotUnlit; - GetBox(MaterialNodeBoxes.AmbientOcclusion).Enabled = isNotUnlit; - GetBox(MaterialNodeBoxes.Normal).Enabled = isNotUnlit; - GetBox(MaterialNodeBoxes.Opacity).Enabled = info.ShadingModel == MaterialShadingModel.Subsurface || info.ShadingModel == MaterialShadingModel.Foliage || info.BlendMode != MaterialBlendMode.Opaque; - GetBox(MaterialNodeBoxes.Refraction).Enabled = info.BlendMode != MaterialBlendMode.Opaque; - GetBox(MaterialNodeBoxes.PositionOffset).Enabled = true; - GetBox(MaterialNodeBoxes.TessellationMultiplier).Enabled = withTess; - GetBox(MaterialNodeBoxes.WorldDisplacement).Enabled = withTess; - GetBox(MaterialNodeBoxes.SubsurfaceColor).Enabled = info.ShadingModel == MaterialShadingModel.Subsurface || info.ShadingModel == MaterialShadingModel.Foliage; + GetBox(MaterialNodeBoxes.Color).IsActive = isNotUnlit; + GetBox(MaterialNodeBoxes.Mask).IsActive = true; + GetBox(MaterialNodeBoxes.Emissive).IsActive = true; + GetBox(MaterialNodeBoxes.Metalness).IsActive = isNotUnlit; + GetBox(MaterialNodeBoxes.Specular).IsActive = isNotUnlit; + GetBox(MaterialNodeBoxes.Roughness).IsActive = isNotUnlit; + GetBox(MaterialNodeBoxes.AmbientOcclusion).IsActive = isNotUnlit; + GetBox(MaterialNodeBoxes.Normal).IsActive = isNotUnlit; + GetBox(MaterialNodeBoxes.Opacity).IsActive = info.ShadingModel == MaterialShadingModel.Subsurface || info.ShadingModel == MaterialShadingModel.Foliage || info.BlendMode != MaterialBlendMode.Opaque; + GetBox(MaterialNodeBoxes.Refraction).IsActive = info.BlendMode != MaterialBlendMode.Opaque; + GetBox(MaterialNodeBoxes.PositionOffset).IsActive = true; + GetBox(MaterialNodeBoxes.TessellationMultiplier).IsActive = withTess; + GetBox(MaterialNodeBoxes.WorldDisplacement).IsActive = withTess; + GetBox(MaterialNodeBoxes.SubsurfaceColor).IsActive = info.ShadingModel == MaterialShadingModel.Subsurface || info.ShadingModel == MaterialShadingModel.Foliage; break; } case MaterialDomain.PostProcess: { - GetBox(MaterialNodeBoxes.Color).Enabled = false; - GetBox(MaterialNodeBoxes.Mask).Enabled = false; - GetBox(MaterialNodeBoxes.Emissive).Enabled = true; - GetBox(MaterialNodeBoxes.Metalness).Enabled = false; - GetBox(MaterialNodeBoxes.Specular).Enabled = false; - GetBox(MaterialNodeBoxes.Roughness).Enabled = false; - GetBox(MaterialNodeBoxes.AmbientOcclusion).Enabled = false; - GetBox(MaterialNodeBoxes.Normal).Enabled = false; - GetBox(MaterialNodeBoxes.Opacity).Enabled = true; - GetBox(MaterialNodeBoxes.Refraction).Enabled = false; - GetBox(MaterialNodeBoxes.PositionOffset).Enabled = false; - GetBox(MaterialNodeBoxes.TessellationMultiplier).Enabled = false; - GetBox(MaterialNodeBoxes.WorldDisplacement).Enabled = false; - GetBox(MaterialNodeBoxes.SubsurfaceColor).Enabled = false; + GetBox(MaterialNodeBoxes.Color).IsActive = false; + GetBox(MaterialNodeBoxes.Mask).IsActive = false; + GetBox(MaterialNodeBoxes.Emissive).IsActive = true; + GetBox(MaterialNodeBoxes.Metalness).IsActive = false; + GetBox(MaterialNodeBoxes.Specular).IsActive = false; + GetBox(MaterialNodeBoxes.Roughness).IsActive = false; + GetBox(MaterialNodeBoxes.AmbientOcclusion).IsActive = false; + GetBox(MaterialNodeBoxes.Normal).IsActive = false; + GetBox(MaterialNodeBoxes.Opacity).IsActive = true; + GetBox(MaterialNodeBoxes.Refraction).IsActive = false; + GetBox(MaterialNodeBoxes.PositionOffset).IsActive = false; + GetBox(MaterialNodeBoxes.TessellationMultiplier).IsActive = false; + GetBox(MaterialNodeBoxes.WorldDisplacement).IsActive = false; + GetBox(MaterialNodeBoxes.SubsurfaceColor).IsActive = false; break; } case MaterialDomain.Decal: { var mode = info.DecalBlendingMode; - GetBox(MaterialNodeBoxes.Color).Enabled = mode == MaterialDecalBlendingMode.Translucent || mode == MaterialDecalBlendingMode.Stain; - GetBox(MaterialNodeBoxes.Mask).Enabled = true; - GetBox(MaterialNodeBoxes.Emissive).Enabled = mode == MaterialDecalBlendingMode.Translucent || mode == MaterialDecalBlendingMode.Emissive; - GetBox(MaterialNodeBoxes.Metalness).Enabled = mode == MaterialDecalBlendingMode.Translucent; - GetBox(MaterialNodeBoxes.Specular).Enabled = mode == MaterialDecalBlendingMode.Translucent; - GetBox(MaterialNodeBoxes.Roughness).Enabled = mode == MaterialDecalBlendingMode.Translucent; - GetBox(MaterialNodeBoxes.AmbientOcclusion).Enabled = false; - GetBox(MaterialNodeBoxes.Normal).Enabled = mode == MaterialDecalBlendingMode.Translucent || mode == MaterialDecalBlendingMode.Normal; - GetBox(MaterialNodeBoxes.Opacity).Enabled = true; - GetBox(MaterialNodeBoxes.Refraction).Enabled = false; - GetBox(MaterialNodeBoxes.PositionOffset).Enabled = false; - GetBox(MaterialNodeBoxes.TessellationMultiplier).Enabled = false; - GetBox(MaterialNodeBoxes.WorldDisplacement).Enabled = false; - GetBox(MaterialNodeBoxes.SubsurfaceColor).Enabled = false; + GetBox(MaterialNodeBoxes.Color).IsActive = mode == MaterialDecalBlendingMode.Translucent || mode == MaterialDecalBlendingMode.Stain; + GetBox(MaterialNodeBoxes.Mask).IsActive = true; + GetBox(MaterialNodeBoxes.Emissive).IsActive = mode == MaterialDecalBlendingMode.Translucent || mode == MaterialDecalBlendingMode.Emissive; + GetBox(MaterialNodeBoxes.Metalness).IsActive = mode == MaterialDecalBlendingMode.Translucent; + GetBox(MaterialNodeBoxes.Specular).IsActive = mode == MaterialDecalBlendingMode.Translucent; + GetBox(MaterialNodeBoxes.Roughness).IsActive = mode == MaterialDecalBlendingMode.Translucent; + GetBox(MaterialNodeBoxes.AmbientOcclusion).IsActive = false; + GetBox(MaterialNodeBoxes.Normal).IsActive = mode == MaterialDecalBlendingMode.Translucent || mode == MaterialDecalBlendingMode.Normal; + GetBox(MaterialNodeBoxes.Opacity).IsActive = true; + GetBox(MaterialNodeBoxes.Refraction).IsActive = false; + GetBox(MaterialNodeBoxes.PositionOffset).IsActive = false; + GetBox(MaterialNodeBoxes.TessellationMultiplier).IsActive = false; + GetBox(MaterialNodeBoxes.WorldDisplacement).IsActive = false; + GetBox(MaterialNodeBoxes.SubsurfaceColor).IsActive = false; break; } case MaterialDomain.GUI: { - GetBox(MaterialNodeBoxes.Color).Enabled = false; - GetBox(MaterialNodeBoxes.Mask).Enabled = true; - GetBox(MaterialNodeBoxes.Emissive).Enabled = true; - GetBox(MaterialNodeBoxes.Metalness).Enabled = false; - GetBox(MaterialNodeBoxes.Specular).Enabled = false; - GetBox(MaterialNodeBoxes.Roughness).Enabled = false; - GetBox(MaterialNodeBoxes.AmbientOcclusion).Enabled = false; - GetBox(MaterialNodeBoxes.Normal).Enabled = false; - GetBox(MaterialNodeBoxes.Opacity).Enabled = true; - GetBox(MaterialNodeBoxes.Refraction).Enabled = false; - GetBox(MaterialNodeBoxes.PositionOffset).Enabled = false; - GetBox(MaterialNodeBoxes.TessellationMultiplier).Enabled = false; - GetBox(MaterialNodeBoxes.WorldDisplacement).Enabled = false; - GetBox(MaterialNodeBoxes.SubsurfaceColor).Enabled = false; + GetBox(MaterialNodeBoxes.Color).IsActive = false; + GetBox(MaterialNodeBoxes.Mask).IsActive = true; + GetBox(MaterialNodeBoxes.Emissive).IsActive = true; + GetBox(MaterialNodeBoxes.Metalness).IsActive = false; + GetBox(MaterialNodeBoxes.Specular).IsActive = false; + GetBox(MaterialNodeBoxes.Roughness).IsActive = false; + GetBox(MaterialNodeBoxes.AmbientOcclusion).IsActive = false; + GetBox(MaterialNodeBoxes.Normal).IsActive = false; + GetBox(MaterialNodeBoxes.Opacity).IsActive = true; + GetBox(MaterialNodeBoxes.Refraction).IsActive = false; + GetBox(MaterialNodeBoxes.PositionOffset).IsActive = false; + GetBox(MaterialNodeBoxes.TessellationMultiplier).IsActive = false; + GetBox(MaterialNodeBoxes.WorldDisplacement).IsActive = false; + GetBox(MaterialNodeBoxes.SubsurfaceColor).IsActive = false; break; } case MaterialDomain.VolumeParticle: { - GetBox(MaterialNodeBoxes.Color).Enabled = true; - GetBox(MaterialNodeBoxes.Mask).Enabled = true; - GetBox(MaterialNodeBoxes.Emissive).Enabled = true; - GetBox(MaterialNodeBoxes.Metalness).Enabled = false; - GetBox(MaterialNodeBoxes.Specular).Enabled = false; - GetBox(MaterialNodeBoxes.Roughness).Enabled = false; - GetBox(MaterialNodeBoxes.AmbientOcclusion).Enabled = false; - GetBox(MaterialNodeBoxes.Normal).Enabled = false; - GetBox(MaterialNodeBoxes.Opacity).Enabled = true; - GetBox(MaterialNodeBoxes.Refraction).Enabled = false; - GetBox(MaterialNodeBoxes.PositionOffset).Enabled = false; - GetBox(MaterialNodeBoxes.TessellationMultiplier).Enabled = false; - GetBox(MaterialNodeBoxes.WorldDisplacement).Enabled = false; - GetBox(MaterialNodeBoxes.SubsurfaceColor).Enabled = false; + GetBox(MaterialNodeBoxes.Color).IsActive = true; + GetBox(MaterialNodeBoxes.Mask).IsActive = true; + GetBox(MaterialNodeBoxes.Emissive).IsActive = true; + GetBox(MaterialNodeBoxes.Metalness).IsActive = false; + GetBox(MaterialNodeBoxes.Specular).IsActive = false; + GetBox(MaterialNodeBoxes.Roughness).IsActive = false; + GetBox(MaterialNodeBoxes.AmbientOcclusion).IsActive = false; + GetBox(MaterialNodeBoxes.Normal).IsActive = false; + GetBox(MaterialNodeBoxes.Opacity).IsActive = true; + GetBox(MaterialNodeBoxes.Refraction).IsActive = false; + GetBox(MaterialNodeBoxes.PositionOffset).IsActive = false; + GetBox(MaterialNodeBoxes.TessellationMultiplier).IsActive = false; + GetBox(MaterialNodeBoxes.WorldDisplacement).IsActive = false; + GetBox(MaterialNodeBoxes.SubsurfaceColor).IsActive = false; break; } default: throw new ArgumentOutOfRangeException(); diff --git a/Source/Editor/Surface/Archetypes/ParticleModules.cs b/Source/Editor/Surface/Archetypes/ParticleModules.cs index a995009ad..9dbfbce77 100644 --- a/Source/Editor/Surface/Archetypes/ParticleModules.cs +++ b/Source/Editor/Surface/Archetypes/ParticleModules.cs @@ -399,7 +399,7 @@ namespace FlaxEditor.Surface.Archetypes private void UpdateInputBox() { var facingMode = (ParticleSpriteFacingMode)Values[2]; - GetBox(0).Enabled = facingMode == ParticleSpriteFacingMode.CustomFacingVector || facingMode == ParticleSpriteFacingMode.FixedAxis; + GetBox(0).IsActive = facingMode == ParticleSpriteFacingMode.CustomFacingVector || facingMode == ParticleSpriteFacingMode.FixedAxis; } } diff --git a/Source/Editor/Surface/Elements/Box.cs b/Source/Editor/Surface/Elements/Box.cs index 90022f482..eca1e15af 100644 --- a/Source/Editor/Surface/Elements/Box.cs +++ b/Source/Editor/Surface/Elements/Box.cs @@ -41,6 +41,11 @@ namespace FlaxEditor.Surface.Elements /// protected bool _isSelected; + /// + /// The is active flag for the box. Unlike , inactive boxes can still be interacted with, they just will be drawn like disabled boxes + /// + protected bool _isActive = true; + /// /// Unique box ID within single node. /// @@ -180,6 +185,15 @@ namespace FlaxEditor.Surface.Elements } } + /// + /// Gets or sets the active state of the box. Unlike , inactive boxes can still be interacted with, they just will be drawn like disabled boxes + /// + public bool IsActive + { + get => _isActive; + set => _isActive = value; + } + /// protected Box(SurfaceNode parentNode, NodeElementArchetype archetype, Float2 location) : base(parentNode, archetype, location, new Float2(Constants.BoxSize), false) diff --git a/Source/Editor/Surface/Elements/OutputBox.cs b/Source/Editor/Surface/Elements/OutputBox.cs index 555b0ae4e..999b1bb72 100644 --- a/Source/Editor/Surface/Elements/OutputBox.cs +++ b/Source/Editor/Surface/Elements/OutputBox.cs @@ -152,7 +152,8 @@ namespace FlaxEditor.Surface.Elements Box targetBox = Connections[i]; var endPos = targetBox.ConnectionOrigin; var highlight = 1 + Mathf.Max(startHighlight, targetBox.ConnectionsHighlightIntensity); - var color = _currentTypeColor * highlight; + var alpha = targetBox.Enabled && targetBox.IsActive ? 1.0f : 0.6f; + var color = _currentTypeColor * highlight * alpha; // TODO: Figure out how to only draw the topmost connection if (IntersectsConnection(ref startPos, ref endPos, ref mousePosition, mouseOverDistance)) @@ -172,7 +173,9 @@ namespace FlaxEditor.Surface.Elements // Draw all the connections var startPos = ConnectionOrigin; var endPos = targetBox.ConnectionOrigin; - DrawConnection(Surface.Style, ref startPos, ref endPos, ref _currentTypeColor, 2.5f); + var alpha = targetBox.Enabled && targetBox.IsActive ? 1.0f : 0.6f; + var color = _currentTypeColor * alpha; + DrawConnection(Surface.Style, ref startPos, ref endPos, ref color, 2.5f); } /// diff --git a/Source/Editor/Surface/SurfaceStyle.cs b/Source/Editor/Surface/SurfaceStyle.cs index d91b81089..f4db6dfa2 100644 --- a/Source/Editor/Surface/SurfaceStyle.cs +++ b/Source/Editor/Surface/SurfaceStyle.cs @@ -228,7 +228,7 @@ namespace FlaxEditor.Surface // Draw icon bool hasConnections = box.HasAnyConnection; - float alpha = box.Enabled ? 1.0f : 0.6f; + float alpha = box.Enabled && box.IsActive ? 1.0f : 0.6f; Color color = box.CurrentTypeColor * alpha; var style = box.Surface.Style; SpriteHandle icon;