From 27ac755bbefd22b59352ee3f38e58f56e8da7dcf Mon Sep 17 00:00:00 2001 From: Zode Date: Wed, 11 Jun 2025 23:15:11 +0300 Subject: [PATCH 1/2] Make particle emitter editor window source code button disable itself is no source code is available --- .../Windows/Assets/ParticleEmitterWindow.cs | 16 +++++++++++++++- Source/Engine/Particles/ParticleEmitter.cpp | 17 +++++++++++++++++ Source/Engine/Particles/ParticleEmitter.h | 6 ++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Windows/Assets/ParticleEmitterWindow.cs b/Source/Editor/Windows/Assets/ParticleEmitterWindow.cs index 80eafd9e0..bc1f49443 100644 --- a/Source/Editor/Windows/Assets/ParticleEmitterWindow.cs +++ b/Source/Editor/Windows/Assets/ParticleEmitterWindow.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using FlaxEditor.Content; using FlaxEditor.CustomEditors; +using FlaxEditor.GUI; using FlaxEditor.Scripting; using FlaxEditor.Surface; using FlaxEditor.Viewport.Previews; @@ -114,6 +115,7 @@ namespace FlaxEditor.Windows.Assets private readonly PropertiesProxy _properties; private Tab _previewTab; + private ToolStripButton _showSourceCodeButton; /// public ParticleEmitterWindow(Editor editor, AssetItem item) @@ -146,7 +148,8 @@ namespace FlaxEditor.Windows.Assets // Toolstrip SurfaceUtils.PerformCommonSetup(this, _toolstrip, _surface, out _saveButton, out _undoButton, out _redoButton); - _toolstrip.AddButton(editor.Icons.Code64, ShowSourceCode).LinkTooltip("Show generated shader source code"); + _showSourceCodeButton = _toolstrip.AddButton(editor.Icons.Code64, ShowSourceCode); + _showSourceCodeButton.LinkTooltip("Show generated shader source code"); _toolstrip.AddSeparator(); _toolstrip.AddButton(editor.Icons.Docs64, () => Platform.OpenUrl(Utilities.Constants.DocsUrl + "manual/particles/index.html")).LinkTooltip("See documentation to learn more"); } @@ -285,5 +288,16 @@ namespace FlaxEditor.Windows.Assets /// public SearchAssetTypes AssetType => SearchAssetTypes.ParticleEmitter; + + /// + public override void Update(float deltaTime) + { + base.Update(deltaTime); + + if(_asset == null) + return; + + _showSourceCodeButton.Enabled = _asset.HasShaderCode(); + } } } diff --git a/Source/Engine/Particles/ParticleEmitter.cpp b/Source/Engine/Particles/ParticleEmitter.cpp index 452d4560a..4490406bc 100644 --- a/Source/Engine/Particles/ParticleEmitter.cpp +++ b/Source/Engine/Particles/ParticleEmitter.cpp @@ -440,4 +440,21 @@ bool ParticleEmitter::Save(const StringView& path) return SaveSurface(data); } +bool ParticleEmitter::HasShaderCode() +{ + if(SimulationMode != ParticlesSimulationMode::GPU) + { + return false; + } + + #if COMPILE_WITH_PARTICLE_GPU_GRAPH && COMPILE_WITH_SHADER_COMPILER + if(_shaderHeader.ParticleEmitter.GraphVersion == PARTICLE_GPU_GRAPH_VERSION + && HasChunk(SHADER_FILE_CHUNK_SOURCE) + && !HasDependenciesModified()) + return true; + #endif + + return false; +} + #endif diff --git a/Source/Engine/Particles/ParticleEmitter.h b/Source/Engine/Particles/ParticleEmitter.h index b3343da1a..4b27036f7 100644 --- a/Source/Engine/Particles/ParticleEmitter.h +++ b/Source/Engine/Particles/ParticleEmitter.h @@ -173,6 +173,12 @@ public: #if USE_EDITOR void GetReferences(Array& assets, Array& files) const override; bool Save(const StringView& path = StringView::Empty) override; + + /// + /// Determine if the particle emitter has valid shader code present. + /// + /// True if particle emitter has shader code, otherwise false. + API_FUNCTION() bool HasShaderCode(); #endif protected: From 2f02ec52ed3d42e4f64f1487a36c6408625d57ba Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 15 Jun 2025 20:48:19 +0200 Subject: [PATCH 2/2] Cleanup code #3546 --- .../Editor/Windows/Assets/ParticleEmitterWindow.cs | 7 +++---- Source/Engine/Particles/ParticleEmitter.cpp | 13 +++++-------- Source/Engine/Particles/ParticleEmitter.h | 5 ++--- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Source/Editor/Windows/Assets/ParticleEmitterWindow.cs b/Source/Editor/Windows/Assets/ParticleEmitterWindow.cs index bc1f49443..6513ac9e0 100644 --- a/Source/Editor/Windows/Assets/ParticleEmitterWindow.cs +++ b/Source/Editor/Windows/Assets/ParticleEmitterWindow.cs @@ -288,16 +288,15 @@ namespace FlaxEditor.Windows.Assets /// public SearchAssetTypes AssetType => SearchAssetTypes.ParticleEmitter; - + /// public override void Update(float deltaTime) { base.Update(deltaTime); - if(_asset == null) + if (_asset == null) return; - - _showSourceCodeButton.Enabled = _asset.HasShaderCode(); + _showSourceCodeButton.Enabled = _asset.HasShaderCode; } } } diff --git a/Source/Engine/Particles/ParticleEmitter.cpp b/Source/Engine/Particles/ParticleEmitter.cpp index 4490406bc..6264ce412 100644 --- a/Source/Engine/Particles/ParticleEmitter.cpp +++ b/Source/Engine/Particles/ParticleEmitter.cpp @@ -440,20 +440,17 @@ bool ParticleEmitter::Save(const StringView& path) return SaveSurface(data); } -bool ParticleEmitter::HasShaderCode() +bool ParticleEmitter::HasShaderCode() const { - if(SimulationMode != ParticlesSimulationMode::GPU) - { + if (SimulationMode != ParticlesSimulationMode::GPU) return false; - } - #if COMPILE_WITH_PARTICLE_GPU_GRAPH && COMPILE_WITH_SHADER_COMPILER - if(_shaderHeader.ParticleEmitter.GraphVersion == PARTICLE_GPU_GRAPH_VERSION +#if COMPILE_WITH_PARTICLE_GPU_GRAPH && COMPILE_WITH_SHADER_COMPILER + if (_shaderHeader.ParticleEmitter.GraphVersion == PARTICLE_GPU_GRAPH_VERSION && HasChunk(SHADER_FILE_CHUNK_SOURCE) && !HasDependenciesModified()) return true; - #endif - +#endif return false; } diff --git a/Source/Engine/Particles/ParticleEmitter.h b/Source/Engine/Particles/ParticleEmitter.h index 4b27036f7..772f5569e 100644 --- a/Source/Engine/Particles/ParticleEmitter.h +++ b/Source/Engine/Particles/ParticleEmitter.h @@ -175,10 +175,9 @@ public: bool Save(const StringView& path = StringView::Empty) override; /// - /// Determine if the particle emitter has valid shader code present. + /// Checks if the particle emitter has valid shader code present. /// - /// True if particle emitter has shader code, otherwise false. - API_FUNCTION() bool HasShaderCode(); + API_PROPERTY() bool HasShaderCode() const; #endif protected: