Merge branch 'VjDeleteUsedParamWarning' of https://github.com/xxSeys1/FlaxEngine into xxSeys1-VjDeleteUsedParamWarning
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user