From 667eb739111648b2439cfd928a175bc8eaf79b3e Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Tue, 22 Oct 2024 13:10:21 +0200 Subject: [PATCH] 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,