From 667eb739111648b2439cfd928a175bc8eaf79b3e Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Tue, 22 Oct 2024 13:10:21 +0200 Subject: [PATCH 1/9] add warning when used param is being deleted "Used" means in graph and connected --- Source/Editor/Surface/VisjectSurfaceWindow.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Source/Editor/Surface/VisjectSurfaceWindow.cs b/Source/Editor/Surface/VisjectSurfaceWindow.cs index 16e4f303b..39c1ce8b2 100644 --- a/Source/Editor/Surface/VisjectSurfaceWindow.cs +++ b/Source/Editor/Surface/VisjectSurfaceWindow.cs @@ -776,6 +776,30 @@ namespace FlaxEditor.Surface private void DeleteParameter(int index) { 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 ((Guid)nodes[i].Values[0] == param.ID && nodes[i].GetBoxes().Any(b => b.Connections.Count > 0)) + connectedParameterNodeCount++; + } + } + + 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."; + string caption = "Delete parameter" + singularPlural; + + if (connectedParameterNodeCount > 0) + if (MessageBox.Show(msg, caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) + return; + var action = new AddRemoveParamAction { Window = window, From aee5382ff64ada6abd0ee12cdb08c13b7e217b92 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Tue, 22 Oct 2024 13:38:37 +0200 Subject: [PATCH 2/9] Remove plural from caption --- Source/Editor/Surface/VisjectSurfaceWindow.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Editor/Surface/VisjectSurfaceWindow.cs b/Source/Editor/Surface/VisjectSurfaceWindow.cs index 39c1ce8b2..fdb9fa9bc 100644 --- a/Source/Editor/Surface/VisjectSurfaceWindow.cs +++ b/Source/Editor/Surface/VisjectSurfaceWindow.cs @@ -794,10 +794,9 @@ namespace FlaxEditor.Surface 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."; - string caption = "Delete parameter" + singularPlural; if (connectedParameterNodeCount > 0) - if (MessageBox.Show(msg, caption, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) + if (MessageBox.Show(msg, "Delete parameter", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) return; var action = new AddRemoveParamAction From b880edc889646e2db59f2eb4a00670f0d65520d6 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Tue, 22 Oct 2024 13:49:26 +0200 Subject: [PATCH 3/9] add editor option to toggle warning --- Source/Editor/Options/InterfaceOptions.cs | 7 +++++++ Source/Editor/Surface/VisjectSurfaceWindow.cs | 18 +++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Source/Editor/Options/InterfaceOptions.cs b/Source/Editor/Options/InterfaceOptions.cs index d8493a70a..976f47d1b 100644 --- a/Source/Editor/Options/InterfaceOptions.cs +++ b/Source/Editor/Options/InterfaceOptions.cs @@ -396,6 +396,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/VisjectSurfaceWindow.cs b/Source/Editor/Surface/VisjectSurfaceWindow.cs index fdb9fa9bc..57ec0d2c9 100644 --- a/Source/Editor/Surface/VisjectSurfaceWindow.cs +++ b/Source/Editor/Surface/VisjectSurfaceWindow.cs @@ -775,6 +775,8 @@ 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]; @@ -786,18 +788,20 @@ namespace FlaxEditor.Surface { if (nodes[i] is IParametersDependantNode node) { - if ((Guid)nodes[i].Values[0] == param.ID && nodes[i].GetBoxes().Any(b => b.Connections.Count > 0)) + if (displayWarning && (Guid)nodes[i].Values[0] == param.ID && nodes[i].GetBoxes().Any(b => b.Connections.Count > 0)) connectedParameterNodeCount++; } } - string singularPlural = connectedParameterNodeCount > 1 ? "s" : ""; + 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."; - 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; + if (connectedParameterNodeCount > 0) + if (MessageBox.Show(msg, "Delete parameter", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) + return; + } var action = new AddRemoveParamAction { From 894741eaa7d9da92aa91f247757f99b1e5f63775 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Tue, 22 Oct 2024 13:59:48 +0200 Subject: [PATCH 4/9] fix typo in filename --- ...{VisjectSurface.Paramaters.cs => VisjectSurface.Parameters.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Source/Editor/Surface/{VisjectSurface.Paramaters.cs => VisjectSurface.Parameters.cs} (100%) 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 From 6b4b85b11393bd3c6bf1be67e7fb91fe08fda1d1 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Thu, 24 Oct 2024 20:48:53 +0200 Subject: [PATCH 5/9] fix code style --- Source/Editor/Surface/Archetypes/Parameters.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/Parameters.cs b/Source/Editor/Surface/Archetypes/Parameters.cs index a75be6bb5..5401ba840 100644 --- a/Source/Editor/Surface/Archetypes/Parameters.cs +++ b/Source/Editor/Surface/Archetypes/Parameters.cs @@ -937,9 +937,7 @@ namespace FlaxEditor.Surface.Archetypes { // Deselect if that parameter is selected if ((Guid)Values[0] == param.ID) - { _combobox.SelectedIndex = -1; - } UpdateCombo(); } From 57b4e9f2955b21d93239d718bc6e8fcaaf811906 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Thu, 24 Oct 2024 23:24:28 +0200 Subject: [PATCH 6/9] move used checks to interface --- .../Editor/Surface/Archetypes/Parameters.cs | 29 +++++++++++++++++++ .../Surface/IParametersDependantNode.cs | 8 +++++ Source/Editor/Surface/VisjectSurfaceWindow.cs | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Surface/Archetypes/Parameters.cs b/Source/Editor/Surface/Archetypes/Parameters.cs index 5401ba840..f30a33090 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,20 @@ namespace FlaxEditor.Surface.Archetypes UpdateCombo(); } + /// + public bool IsParameterReferenced(SurfaceParameter param, VisjectSurface surface) + { + for (int i = 0; i < surface.Nodes.Count; i++) + { + if (surface.Nodes[i] is IParametersDependantNode node) + { + return (Guid)surface.Nodes[i].Values[0] == param.ID && surface.Nodes[i].GetBoxes().Any(b => b.Connections.Count > 0); + } + } + + return false; + } + /// public override void OnLoaded(SurfaceNodeActions action) { @@ -942,6 +957,20 @@ namespace FlaxEditor.Surface.Archetypes UpdateCombo(); } + /// + public bool IsParameterReferenced(SurfaceParameter param, VisjectSurface surface) + { + for (int i = 0; i < surface.Nodes.Count; i++) + { + if (surface.Nodes[i] is IParametersDependantNode node) + { + return (Guid)surface.Nodes[i].Values[0] == param.ID && surface.Nodes[i].GetBoxes().Any(b => b.Connections.Count > 0); + } + } + + return false; + } + /// public override void OnLoaded(SurfaceNodeActions action) { diff --git a/Source/Editor/Surface/IParametersDependantNode.cs b/Source/Editor/Surface/IParametersDependantNode.cs index 9683abd70..c424454d5 100644 --- a/Source/Editor/Surface/IParametersDependantNode.cs +++ b/Source/Editor/Surface/IParametersDependantNode.cs @@ -33,5 +33,13 @@ 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. + /// /// The visject surface. + /// How often the parameter is referenced. + bool IsParameterReferenced(SurfaceParameter param, VisjectSurface surface); } } diff --git a/Source/Editor/Surface/VisjectSurfaceWindow.cs b/Source/Editor/Surface/VisjectSurfaceWindow.cs index 57ec0d2c9..7c653a823 100644 --- a/Source/Editor/Surface/VisjectSurfaceWindow.cs +++ b/Source/Editor/Surface/VisjectSurfaceWindow.cs @@ -788,7 +788,7 @@ namespace FlaxEditor.Surface { if (nodes[i] is IParametersDependantNode node) { - if (displayWarning && (Guid)nodes[i].Values[0] == param.ID && nodes[i].GetBoxes().Any(b => b.Connections.Count > 0)) + if (displayWarning && node.IsParameterReferenced(param, window.VisjectSurface)) connectedParameterNodeCount++; } } From 2952bdca66003f85763ef0f1e36465f88db3b814 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Thu, 24 Oct 2024 23:28:48 +0200 Subject: [PATCH 7/9] fix docs commend and function name --- Source/Editor/Surface/Archetypes/Parameters.cs | 4 ++-- Source/Editor/Surface/IParametersDependantNode.cs | 6 +++--- Source/Editor/Surface/VisjectSurfaceWindow.cs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/Parameters.cs b/Source/Editor/Surface/Archetypes/Parameters.cs index f30a33090..a06ef769e 100644 --- a/Source/Editor/Surface/Archetypes/Parameters.cs +++ b/Source/Editor/Surface/Archetypes/Parameters.cs @@ -427,7 +427,7 @@ namespace FlaxEditor.Surface.Archetypes } /// - public bool IsParameterReferenced(SurfaceParameter param, VisjectSurface surface) + public bool IsParamreferenced(SurfaceParameter param, VisjectSurface surface) { for (int i = 0; i < surface.Nodes.Count; i++) { @@ -958,7 +958,7 @@ namespace FlaxEditor.Surface.Archetypes } /// - public bool IsParameterReferenced(SurfaceParameter param, VisjectSurface surface) + public bool IsParamreferenced(SurfaceParameter param, VisjectSurface surface) { for (int i = 0; i < surface.Nodes.Count; i++) { diff --git a/Source/Editor/Surface/IParametersDependantNode.cs b/Source/Editor/Surface/IParametersDependantNode.cs index c424454d5..650dff545 100644 --- a/Source/Editor/Surface/IParametersDependantNode.cs +++ b/Source/Editor/Surface/IParametersDependantNode.cs @@ -38,8 +38,8 @@ namespace FlaxEditor.Surface /// 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. - /// /// The visject surface. - /// How often the parameter is referenced. - bool IsParameterReferenced(SurfaceParameter param, VisjectSurface surface); + /// The visject surface. + /// If the parameter is referenced. + bool IsParamreferenced(SurfaceParameter param, VisjectSurface surface); } } diff --git a/Source/Editor/Surface/VisjectSurfaceWindow.cs b/Source/Editor/Surface/VisjectSurfaceWindow.cs index 7c653a823..5f6e95a0a 100644 --- a/Source/Editor/Surface/VisjectSurfaceWindow.cs +++ b/Source/Editor/Surface/VisjectSurfaceWindow.cs @@ -788,7 +788,7 @@ namespace FlaxEditor.Surface { if (nodes[i] is IParametersDependantNode node) { - if (displayWarning && node.IsParameterReferenced(param, window.VisjectSurface)) + if (displayWarning && node.IsParamreferenced(param, window.VisjectSurface)) connectedParameterNodeCount++; } } From b055117144d42df15435a98207e41299161185c6 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Sat, 16 Nov 2024 18:37:36 +0100 Subject: [PATCH 8/9] simplify parameter deleted code --- Source/Editor/Surface/Archetypes/Parameters.cs | 16 ++++++++-------- .../Editor/Surface/IParametersDependantNode.cs | 3 +-- Source/Editor/Surface/VisjectSurfaceWindow.cs | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/Parameters.cs b/Source/Editor/Surface/Archetypes/Parameters.cs index a06ef769e..10d4337bd 100644 --- a/Source/Editor/Surface/Archetypes/Parameters.cs +++ b/Source/Editor/Surface/Archetypes/Parameters.cs @@ -427,13 +427,13 @@ namespace FlaxEditor.Surface.Archetypes } /// - public bool IsParamreferenced(SurfaceParameter param, VisjectSurface surface) + public bool IsParamreferenced(SurfaceParameter param) { - for (int i = 0; i < surface.Nodes.Count; i++) + for (int i = 0; i < Surface.Nodes.Count; i++) { - if (surface.Nodes[i] is IParametersDependantNode node) + if (Surface.Nodes[i] is IParametersDependantNode node) { - return (Guid)surface.Nodes[i].Values[0] == param.ID && surface.Nodes[i].GetBoxes().Any(b => b.Connections.Count > 0); + return (Guid)Values[0] == param.ID; } } @@ -958,13 +958,13 @@ namespace FlaxEditor.Surface.Archetypes } /// - public bool IsParamreferenced(SurfaceParameter param, VisjectSurface surface) + public bool IsParamreferenced(SurfaceParameter param) { - for (int i = 0; i < surface.Nodes.Count; i++) + for (int i = 0; i < Surface.Nodes.Count; i++) { - if (surface.Nodes[i] is IParametersDependantNode node) + if (Surface.Nodes[i] is IParametersDependantNode node) { - return (Guid)surface.Nodes[i].Values[0] == param.ID && surface.Nodes[i].GetBoxes().Any(b => b.Connections.Count > 0); + return (Guid)Values[0] == param.ID; } } diff --git a/Source/Editor/Surface/IParametersDependantNode.cs b/Source/Editor/Surface/IParametersDependantNode.cs index 650dff545..0148682f1 100644 --- a/Source/Editor/Surface/IParametersDependantNode.cs +++ b/Source/Editor/Surface/IParametersDependantNode.cs @@ -38,8 +38,7 @@ namespace FlaxEditor.Surface /// 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. - /// The visject surface. /// If the parameter is referenced. - bool IsParamreferenced(SurfaceParameter param, VisjectSurface surface); + bool IsParamreferenced(SurfaceParameter param); } } diff --git a/Source/Editor/Surface/VisjectSurfaceWindow.cs b/Source/Editor/Surface/VisjectSurfaceWindow.cs index 5f6e95a0a..5d6a050a6 100644 --- a/Source/Editor/Surface/VisjectSurfaceWindow.cs +++ b/Source/Editor/Surface/VisjectSurfaceWindow.cs @@ -788,7 +788,7 @@ namespace FlaxEditor.Surface { if (nodes[i] is IParametersDependantNode node) { - if (displayWarning && node.IsParamreferenced(param, window.VisjectSurface)) + if (displayWarning && node.IsParamreferenced(param)) connectedParameterNodeCount++; } } From 38d1e25604cc260fb2f60227a0bae90b43cc30ca Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Thu, 21 Nov 2024 20:20:42 +0100 Subject: [PATCH 9/9] replace for loop --- .../Editor/Surface/Archetypes/Parameters.cs | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/Parameters.cs b/Source/Editor/Surface/Archetypes/Parameters.cs index 10d4337bd..4509ce753 100644 --- a/Source/Editor/Surface/Archetypes/Parameters.cs +++ b/Source/Editor/Surface/Archetypes/Parameters.cs @@ -429,15 +429,7 @@ namespace FlaxEditor.Surface.Archetypes /// public bool IsParamreferenced(SurfaceParameter param) { - for (int i = 0; i < Surface.Nodes.Count; i++) - { - if (Surface.Nodes[i] is IParametersDependantNode node) - { - return (Guid)Values[0] == param.ID; - } - } - - return false; + return (Guid)Values[0] == param.ID; } /// @@ -960,15 +952,7 @@ namespace FlaxEditor.Surface.Archetypes /// public bool IsParamreferenced(SurfaceParameter param) { - for (int i = 0; i < Surface.Nodes.Count; i++) - { - if (Surface.Nodes[i] is IParametersDependantNode node) - { - return (Guid)Values[0] == param.ID; - } - } - - return false; + return (Guid)Values[0] == param.ID; } ///