From d8059c3db3c1851b1218e7c5284471b86b0b5300 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Sun, 4 May 2025 20:08:12 +0200 Subject: [PATCH] disable create file dialog create button if asset can't be created --- Source/Editor/Content/Create/CreateFileEntry.cs | 5 +++++ Source/Editor/Content/Create/CreateFilesDialog.cs | 8 +++++--- .../Editor/Content/Create/ParticleEmitterCreateEntry.cs | 3 +++ Source/Editor/Content/Create/PrefabCreateEntry.cs | 5 +++++ Source/Editor/Content/Create/SettingsCreateEntry.cs | 2 ++ Source/Editor/Content/Create/VisualScriptCreateEntry.cs | 3 +++ Source/Editor/Content/Proxy/JsonAssetProxy.cs | 3 +++ Source/Editor/Windows/Assets/CollisionDataWindow.cs | 2 ++ 8 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Content/Create/CreateFileEntry.cs b/Source/Editor/Content/Create/CreateFileEntry.cs index da2779b98..3346bd2ab 100644 --- a/Source/Editor/Content/Create/CreateFileEntry.cs +++ b/Source/Editor/Content/Create/CreateFileEntry.cs @@ -13,6 +13,11 @@ namespace FlaxEditor.Content.Create /// public string ResultUrl { get; } + /// + /// Gets or sets wether a file can be created based on the current settings. + /// + public abstract bool CanBeCreated { get; } + /// /// Gets a value indicating whether this entry has settings to modify. /// diff --git a/Source/Editor/Content/Create/CreateFilesDialog.cs b/Source/Editor/Content/Create/CreateFilesDialog.cs index ef5f2d58b..a49aac52a 100644 --- a/Source/Editor/Content/Create/CreateFilesDialog.cs +++ b/Source/Editor/Content/Create/CreateFilesDialog.cs @@ -60,7 +60,8 @@ namespace FlaxEditor.Content.Create Text = "Create", AnchorPreset = AnchorPresets.BottomRight, Offsets = new Margin(-ButtonsWidth - ButtonsMargin, ButtonsWidth, -ButtonsHeight - ButtonsMargin, ButtonsHeight), - Parent = this + Parent = this, + Enabled = entry.CanBeCreated, }; createButton.Clicked += OnSubmit; var cancelButton = new Button @@ -68,7 +69,7 @@ namespace FlaxEditor.Content.Create Text = "Cancel", AnchorPreset = AnchorPresets.BottomRight, Offsets = new Margin(-ButtonsWidth - ButtonsMargin - ButtonsWidth - ButtonsMargin, ButtonsWidth, -ButtonsHeight - ButtonsMargin, ButtonsHeight), - Parent = this + Parent = this, }; cancelButton.Clicked += OnCancel; @@ -77,7 +78,7 @@ namespace FlaxEditor.Content.Create { AnchorPreset = AnchorPresets.HorizontalStretchTop, Offsets = new Margin(2, 2, infoLabel.Bottom + 2, EditorHeight), - Parent = this + Parent = this, }; // Settings editor @@ -87,6 +88,7 @@ namespace FlaxEditor.Content.Create _dialogSize = new Float2(TotalWidth, panel.Bottom); _settingsEditor.Select(_entry.Settings); + _settingsEditor.Modified += () => createButton.Enabled = _entry.CanBeCreated; } /// diff --git a/Source/Editor/Content/Create/ParticleEmitterCreateEntry.cs b/Source/Editor/Content/Create/ParticleEmitterCreateEntry.cs index a862c3370..b64f7b1d0 100644 --- a/Source/Editor/Content/Create/ParticleEmitterCreateEntry.cs +++ b/Source/Editor/Content/Create/ParticleEmitterCreateEntry.cs @@ -12,6 +12,9 @@ namespace FlaxEditor.Content.Create /// public class ParticleEmitterCreateEntry : CreateFileEntry { + /// + public override bool CanBeCreated => true; + /// /// Types of the emitter templates that can be created. /// diff --git a/Source/Editor/Content/Create/PrefabCreateEntry.cs b/Source/Editor/Content/Create/PrefabCreateEntry.cs index db187e37f..2ddfccfde 100644 --- a/Source/Editor/Content/Create/PrefabCreateEntry.cs +++ b/Source/Editor/Content/Create/PrefabCreateEntry.cs @@ -14,6 +14,8 @@ namespace FlaxEditor.Content.Create /// public class PrefabCreateEntry : CreateFileEntry { + public override bool CanBeCreated => _options.RootActorType != null; + /// /// The create options. /// @@ -73,6 +75,9 @@ namespace FlaxEditor.Content.Create /// public class WidgetCreateEntry : CreateFileEntry { + /// + public override bool CanBeCreated => _options.RootControlType != null; + /// /// The create options. /// diff --git a/Source/Editor/Content/Create/SettingsCreateEntry.cs b/Source/Editor/Content/Create/SettingsCreateEntry.cs index fd43f43e0..bdeeeadf0 100644 --- a/Source/Editor/Content/Create/SettingsCreateEntry.cs +++ b/Source/Editor/Content/Create/SettingsCreateEntry.cs @@ -17,6 +17,8 @@ namespace FlaxEditor.Content.Create /// internal class SettingsCreateEntry : CreateFileEntry { + public override bool CanBeCreated => _options.Type != null; + internal class Options { [Tooltip("The settings type.")] diff --git a/Source/Editor/Content/Create/VisualScriptCreateEntry.cs b/Source/Editor/Content/Create/VisualScriptCreateEntry.cs index 768db6310..b74eb6ab2 100644 --- a/Source/Editor/Content/Create/VisualScriptCreateEntry.cs +++ b/Source/Editor/Content/Create/VisualScriptCreateEntry.cs @@ -11,6 +11,9 @@ namespace FlaxEditor.Content.Create /// public class VisualScriptCreateEntry : CreateFileEntry { + /// + public override bool CanBeCreated => _options.BaseClass != null; + /// /// The create options. /// diff --git a/Source/Editor/Content/Proxy/JsonAssetProxy.cs b/Source/Editor/Content/Proxy/JsonAssetProxy.cs index b71c044b5..2d5f20b47 100644 --- a/Source/Editor/Content/Proxy/JsonAssetProxy.cs +++ b/Source/Editor/Content/Proxy/JsonAssetProxy.cs @@ -65,6 +65,9 @@ namespace FlaxEditor.Content /// public class GenericJsonCreateEntry : CreateFileEntry { + /// + public override bool CanBeCreated => _options.Type != null; + /// /// The create options. /// diff --git a/Source/Editor/Windows/Assets/CollisionDataWindow.cs b/Source/Editor/Windows/Assets/CollisionDataWindow.cs index 5158f6046..3f265eea9 100644 --- a/Source/Editor/Windows/Assets/CollisionDataWindow.cs +++ b/Source/Editor/Windows/Assets/CollisionDataWindow.cs @@ -102,6 +102,8 @@ namespace FlaxEditor.Windows.Assets private class CookData : CreateFileEntry { + public override bool CanBeCreated => true; + public PropertiesProxy Proxy; public CollisionDataType Type; public ModelBase Model;