Merge branch 'VjDeleteUsedParamWarning' of https://github.com/xxSeys1/FlaxEngine into xxSeys1-VjDeleteUsedParamWarning

This commit is contained in:
Wojtek Figat
2024-11-26 16:03:56 +01:00
5 changed files with 54 additions and 2 deletions

View File

@@ -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;
/// <summary>
/// Gets or sets a value that indicates if a warning should be displayed when deleting a Visject parameter that is used in a graph.
/// </summary>
[DefaultValue(true)]
[EditorDisplay("Visject", "Warn when deleting used parameter"), EditorOrder(552)]
public bool WarnOnDeletingUsedVisjectParameter { get; set; } = true;
private static FontAsset DefaultFont => FlaxEngine.Content.LoadAsyncInternal<FontAsset>(EditorAssets.PrimaryFont);
private static FontAsset ConsoleFont => FlaxEngine.Content.LoadAsyncInternal<FontAsset>(EditorAssets.InconsolataRegularFont);

View File

@@ -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();
}
/// <inheritdoc />
public bool IsParamreferenced(SurfaceParameter param)
{
return (Guid)Values[0] == param.ID;
}
/// <inheritdoc />
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();
}
/// <inheritdoc />
public bool IsParamreferenced(SurfaceParameter param)
{
return (Guid)Values[0] == param.ID;
}
/// <inheritdoc />
public override void OnLoaded(SurfaceNodeActions action)
{

View File

@@ -33,5 +33,12 @@ namespace FlaxEditor.Surface
/// </summary>
/// <param name="param">The parameter.</param>
void OnParamDeleted(SurfaceParameter param);
/// <summary>
/// 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.
/// </summary>
/// <param name="param">The parameter.</param>
/// <returns>If the parameter is referenced.</returns>
bool IsParamreferenced(SurfaceParameter param);
}
}

View File

@@ -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<SurfaceNode> 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,