diff --git a/Source/Editor/Options/InterfaceOptions.cs b/Source/Editor/Options/InterfaceOptions.cs index ec46ccdd9..1654df920 100644 --- a/Source/Editor/Options/InterfaceOptions.cs +++ b/Source/Editor/Options/InterfaceOptions.cs @@ -449,6 +449,13 @@ namespace FlaxEditor.Options [EditorDisplay("Visject", "Grid Snapping Size"), EditorOrder(551), Tooltip("Defines the size of the grid for nodes snapping."), VisibleIf(nameof(SurfaceGridSnapping))] public float SurfaceGridSnappingSize { get; set; } = 20.0f; + /// + /// Gets or sets a value that indicates if a warning should be displayed when deleting a Visject parameter that is used in a graph. + /// + [DefaultValue(true)] + [EditorDisplay("Visject", "Warn when deleting used parameter"), EditorOrder(552)] + public bool WarnOnDeletingUsedVisjectParameter { get; set; } = true; + private static FontAsset DefaultFont => FlaxEngine.Content.LoadAsyncInternal(EditorAssets.PrimaryFont); private static FontAsset ConsoleFont => FlaxEngine.Content.LoadAsyncInternal(EditorAssets.InconsolataRegularFont); diff --git a/Source/Editor/Surface/Archetypes/Parameters.cs b/Source/Editor/Surface/Archetypes/Parameters.cs index a75be6bb5..4509ce753 100644 --- a/Source/Editor/Surface/Archetypes/Parameters.cs +++ b/Source/Editor/Surface/Archetypes/Parameters.cs @@ -13,6 +13,7 @@ using FlaxEditor.Scripting; using FlaxEditor.Surface.Elements; using FlaxEngine; using FlaxEngine.Utilities; +using System.Linq; namespace FlaxEditor.Surface.Archetypes { @@ -425,6 +426,12 @@ namespace FlaxEditor.Surface.Archetypes UpdateCombo(); } + /// + public bool IsParamreferenced(SurfaceParameter param) + { + return (Guid)Values[0] == param.ID; + } + /// public override void OnLoaded(SurfaceNodeActions action) { @@ -937,13 +944,17 @@ namespace FlaxEditor.Surface.Archetypes { // Deselect if that parameter is selected if ((Guid)Values[0] == param.ID) - { _combobox.SelectedIndex = -1; - } UpdateCombo(); } + /// + public bool IsParamreferenced(SurfaceParameter param) + { + return (Guid)Values[0] == param.ID; + } + /// public override void OnLoaded(SurfaceNodeActions action) { diff --git a/Source/Editor/Surface/IParametersDependantNode.cs b/Source/Editor/Surface/IParametersDependantNode.cs index 9683abd70..0148682f1 100644 --- a/Source/Editor/Surface/IParametersDependantNode.cs +++ b/Source/Editor/Surface/IParametersDependantNode.cs @@ -33,5 +33,12 @@ namespace FlaxEditor.Surface /// /// The parameter. void OnParamDeleted(SurfaceParameter param); + + /// + /// Get if the parameter is referenced in a graph. Referenced in this case means in a graph and at least one node in-/output connected to another node. + /// + /// The parameter. + /// If the parameter is referenced. + bool IsParamreferenced(SurfaceParameter param); } } diff --git a/Source/Editor/Surface/VisjectSurface.Paramaters.cs b/Source/Editor/Surface/VisjectSurface.Parameters.cs similarity index 100% rename from Source/Editor/Surface/VisjectSurface.Paramaters.cs rename to Source/Editor/Surface/VisjectSurface.Parameters.cs diff --git a/Source/Editor/Surface/VisjectSurfaceWindow.cs b/Source/Editor/Surface/VisjectSurfaceWindow.cs index 16e4f303b..5d6a050a6 100644 --- a/Source/Editor/Surface/VisjectSurfaceWindow.cs +++ b/Source/Editor/Surface/VisjectSurfaceWindow.cs @@ -775,7 +775,34 @@ namespace FlaxEditor.Surface private void DeleteParameter(int index) { + bool displayWarning = Editor.Instance.Options.Options.Interface.WarnOnDeletingUsedVisjectParameter; + var window = (IVisjectSurfaceWindow)Values[0]; + SurfaceParameter param = window.VisjectSurface.Parameters[index]; + + int connectedParameterNodeCount = 0; + + List nodes = window.VisjectSurface.Nodes; + + for (int i = 0; i < window.VisjectSurface.Nodes.Count; i++) + { + if (nodes[i] is IParametersDependantNode node) + { + if (displayWarning && node.IsParamreferenced(param)) + connectedParameterNodeCount++; + } + } + + if (displayWarning) + { + string singularPlural = connectedParameterNodeCount > 1 ? "s" : ""; + string msg = $"Delete parameter {param.Name}?\nParameter is being used in a graph {connectedParameterNodeCount} time{singularPlural}.\n\nYou can disable this warning in the editor settings."; + + if (connectedParameterNodeCount > 0) + if (MessageBox.Show(msg, "Delete parameter", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) + return; + } + var action = new AddRemoveParamAction { Window = window,