From adb5e0e207d301307365b5b9f9e2a80e577b4478 Mon Sep 17 00:00:00 2001 From: Travis Lange Date: Fri, 10 Jan 2025 13:07:40 -0500 Subject: [PATCH] exposed visual_shader_editor_plugin, find_resource_conversion_plugin_for_resource, and find_resource_conversion_plugin_for_type_name --- doc/classes/EditorInterface.xml | 14 ++++++++ doc/classes/VisualShaderConversionPlugin.xml | 33 +++++++++++++++++++ editor/editor_interface.cpp | 33 +++++++++++++++++++ editor/editor_interface.h | 3 ++ .../plugins/visual_shader_editor_plugin.cpp | 7 ++++ editor/plugins/visual_shader_editor_plugin.h | 3 ++ editor/register_editor_types.cpp | 2 ++ 7 files changed, 95 insertions(+) create mode 100644 doc/classes/VisualShaderConversionPlugin.xml diff --git a/doc/classes/EditorInterface.xml b/doc/classes/EditorInterface.xml index b8b69586fe9..280c2369af7 100644 --- a/doc/classes/EditorInterface.xml +++ b/doc/classes/EditorInterface.xml @@ -43,6 +43,20 @@ Edits the given [Script]. The line and column on which to open the script can also be specified. The script will be open with the user-configured editor for the script's language which may be an external editor. + + + + + Returns an [Array] of [EditorResourceConversionPlugin] that can handle the [param for_resource]. + + + + + + + Returns an [Array] of [EditorResourceConversionPlugin] that can handle the [param type]. + + diff --git a/doc/classes/VisualShaderConversionPlugin.xml b/doc/classes/VisualShaderConversionPlugin.xml new file mode 100644 index 00000000000..0694fcaec74 --- /dev/null +++ b/doc/classes/VisualShaderConversionPlugin.xml @@ -0,0 +1,33 @@ + + + + Plugin for converting from [VisualShader] to [Shader]. + + + [VisualShaderConversionPlugin] is invoked when the context menu is brought up for a [VisualShader] in the editor inspector. + + + + + + + + + Takes an input [Resource] expected to be of type [VisualShader] and converts it to [Shader] in [method converts_to]. The returned [Resource] is the resulting [Shader] of the conversion, and the input [Resource] remains unchanged. + + + + + + Returns "Shader" which is the class name [Shader] this plugin converts the source resource [VisualShader] to. + + + + + + + Called to determine whether a particular [Resource] can be converted to the [Shader] resource type by this plugin. Will return false if the particular [Resource] is not of type [VisualShader]. + + + + diff --git a/editor/editor_interface.cpp b/editor/editor_interface.cpp index 92fb2e0cb6a..dd6bfa14c93 100644 --- a/editor/editor_interface.cpp +++ b/editor/editor_interface.cpp @@ -48,6 +48,7 @@ #include "editor/gui/editor_toaster.h" #include "editor/gui/scene_tree_editor.h" #include "editor/inspector_dock.h" +#include "editor/plugins/editor_resource_conversion_plugin.h" #include "editor/plugins/node_3d_editor_plugin.h" #include "editor/property_selector.h" #include "editor/themes/editor_scale.h" @@ -368,6 +369,36 @@ bool EditorInterface::is_plugin_enabled(const String &p_plugin) const { return EditorNode::get_singleton()->is_addon_plugin_enabled(p_plugin); } +Array EditorInterface::find_resource_conversion_plugin_for_resource(const Ref &p_for_resource) { + Array ret = Array(); + Vector> converters = EditorNode::get_singleton()->find_resource_conversion_plugin_for_resource(p_for_resource); + + if (converters.is_empty()) { + return ret; + } + + for (int i = 0; i < converters.size(); i++) { + ret.push_back(converters[i]); + } + + return ret; +} + +Array EditorInterface::find_resource_conversion_plugin_for_type_name(const String &p_type) { + Array ret = Array(); + Vector> converters = EditorNode::get_singleton()->find_resource_conversion_plugin_for_type_name(p_type); + + if (converters.is_empty()) { + return ret; + } + + for (int i = 0; i < converters.size(); i++) { + ret.push_back(converters[i]); + } + + return ret; +} + // Editor GUI. Ref EditorInterface::get_editor_theme() const { @@ -786,6 +817,8 @@ void EditorInterface::_bind_methods() { ClassDB::bind_method(D_METHOD("set_plugin_enabled", "plugin", "enabled"), &EditorInterface::set_plugin_enabled); ClassDB::bind_method(D_METHOD("is_plugin_enabled", "plugin"), &EditorInterface::is_plugin_enabled); + ClassDB::bind_method(D_METHOD("find_resource_conversion_plugin_for_resource", "for_resource"), &EditorInterface::find_resource_conversion_plugin_for_resource); + ClassDB::bind_method(D_METHOD("find_resource_conversion_plugin_for_type_name", "type"), &EditorInterface::find_resource_conversion_plugin_for_type_name); // Editor GUI. diff --git a/editor/editor_interface.h b/editor/editor_interface.h index bd2cd1187a3..9659166bd82 100644 --- a/editor/editor_interface.h +++ b/editor/editor_interface.h @@ -43,6 +43,7 @@ class EditorFileSystem; class EditorInspector; class EditorPaths; class EditorPlugin; +class EditorResourceConversionPlugin; class EditorResourcePreview; class EditorSelection; class EditorSettings; @@ -115,6 +116,8 @@ public: void set_plugin_enabled(const String &p_plugin, bool p_enabled); bool is_plugin_enabled(const String &p_plugin) const; + Array find_resource_conversion_plugin_for_resource(const Ref &p_for_resource); + Array find_resource_conversion_plugin_for_type_name(const String &p_type); // Editor GUI. diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 3b8180ec3f6..0d747b0402c 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -33,6 +33,7 @@ #include "core/config/project_settings.h" #include "core/io/resource_loader.h" #include "core/math/math_defs.h" +#include "core/object/class_db.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" #include "editor/editor_properties.h" @@ -8216,6 +8217,12 @@ void VisualShaderNodePortPreview::_notification(int p_what) { ////////////////////////////////// +void VisualShaderConversionPlugin::_bind_methods() { + ClassDB::bind_method(D_METHOD("converts_to"), &VisualShaderConversionPlugin::converts_to); + ClassDB::bind_method(D_METHOD("handles", "resource"), &VisualShaderConversionPlugin::handles); + ClassDB::bind_method(D_METHOD("convert", "resource"), &VisualShaderConversionPlugin::convert); +} + String VisualShaderConversionPlugin::converts_to() const { return "Shader"; } diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index 4e20a0a980a..ea40087c053 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -712,6 +712,9 @@ public: class VisualShaderConversionPlugin : public EditorResourceConversionPlugin { GDCLASS(VisualShaderConversionPlugin, EditorResourceConversionPlugin); +protected: + static void _bind_methods(); + public: virtual String converts_to() const override; virtual bool handles(const Ref &p_resource) const override; diff --git a/editor/register_editor_types.cpp b/editor/register_editor_types.cpp index e4c97f1783d..8ce23d38935 100644 --- a/editor/register_editor_types.cpp +++ b/editor/register_editor_types.cpp @@ -127,6 +127,7 @@ #include "editor/plugins/theme_editor_plugin.h" #include "editor/plugins/tiles/tiles_editor_plugin.h" #include "editor/plugins/tool_button_editor_plugin.h" +#include "editor/plugins/visual_shader_editor_plugin.h" #include "editor/plugins/voxel_gi_editor_plugin.h" #include "editor/register_exporters.h" @@ -168,6 +169,7 @@ void register_editor_types() { register_exporter_types(); GDREGISTER_CLASS(EditorResourceConversionPlugin); + GDREGISTER_CLASS(VisualShaderConversionPlugin); GDREGISTER_CLASS(EditorSceneFormatImporter); GDREGISTER_CLASS(EditorScenePostImportPlugin); GDREGISTER_CLASS(EditorInspector);