diff --git a/doc/classes/EditorInterface.xml b/doc/classes/EditorInterface.xml index d4acb820232..62a31301ec3 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 c0d7b1b1fa7..e879aa7ab87 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 { @@ -774,6 +805,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 b6d163d2fdd..e3c8fbf64f9 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 b8af4603e80..20a5c3614a9 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" @@ -8256,6 +8257,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 a74fe113373..16e1b612b0b 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -715,6 +715,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 1dfe399a24a..4fa4c960061 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);