diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index dc1de6b9ceb..fcf4a727ca4 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -394,6 +394,15 @@ Ref ResourceFormatImporter::get_importer_by_name(const String return Ref(); } +void ResourceFormatImporter::add_importer(const Ref &p_importer, bool p_first_priority) { + ERR_FAIL_COND(p_importer.is_null()); + if (p_first_priority) { + importers.insert(0, p_importer); + } else { + importers.push_back(p_importer); + } +} + void ResourceFormatImporter::get_importers_for_extension(const String &p_extension, List> *r_importers) { for (int i = 0; i < importers.size(); i++) { List local_exts; @@ -472,20 +481,13 @@ ResourceFormatImporter::ResourceFormatImporter() { singleton = this; } +////////////// + void ResourceImporter::_bind_methods() { BIND_ENUM_CONSTANT(IMPORT_ORDER_DEFAULT); BIND_ENUM_CONSTANT(IMPORT_ORDER_SCENE); } -void ResourceFormatImporter::add_importer(const Ref &p_importer, bool p_first_priority) { - ERR_FAIL_COND(p_importer.is_null()); - if (p_first_priority) { - importers.insert(0, p_importer); - } else { - importers.push_back(p_importer); - } -} - ///// Error ResourceFormatImporterSaver::set_uid(const String &p_path, ResourceUID::ID p_uid) { diff --git a/doc/classes/ResourceImporterBMFont.xml b/doc/classes/ResourceImporterBMFont.xml new file mode 100644 index 00000000000..044f3c76394 --- /dev/null +++ b/doc/classes/ResourceImporterBMFont.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/doc/classes/ResourceImporterBitMap.xml b/doc/classes/ResourceImporterBitMap.xml new file mode 100644 index 00000000000..4a55d4d4af0 --- /dev/null +++ b/doc/classes/ResourceImporterBitMap.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/doc/classes/ResourceImporterCSVTranslation.xml b/doc/classes/ResourceImporterCSVTranslation.xml new file mode 100644 index 00000000000..04fe9b95d2e --- /dev/null +++ b/doc/classes/ResourceImporterCSVTranslation.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/doc/classes/ResourceImporterDynamicFont.xml b/doc/classes/ResourceImporterDynamicFont.xml new file mode 100644 index 00000000000..ea0065e2d83 --- /dev/null +++ b/doc/classes/ResourceImporterDynamicFont.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/classes/ResourceImporterImage.xml b/doc/classes/ResourceImporterImage.xml new file mode 100644 index 00000000000..f370fc2a593 --- /dev/null +++ b/doc/classes/ResourceImporterImage.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/doc/classes/ResourceImporterImageFont.xml b/doc/classes/ResourceImporterImageFont.xml new file mode 100644 index 00000000000..63874abee44 --- /dev/null +++ b/doc/classes/ResourceImporterImageFont.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/classes/ResourceImporterLayeredTexture.xml b/doc/classes/ResourceImporterLayeredTexture.xml new file mode 100644 index 00000000000..229bca84ce2 --- /dev/null +++ b/doc/classes/ResourceImporterLayeredTexture.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/classes/ResourceImporterOBJ.xml b/doc/classes/ResourceImporterOBJ.xml new file mode 100644 index 00000000000..e9b899d04cf --- /dev/null +++ b/doc/classes/ResourceImporterOBJ.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/doc/classes/ResourceImporterScene.xml b/doc/classes/ResourceImporterScene.xml new file mode 100644 index 00000000000..1836960f199 --- /dev/null +++ b/doc/classes/ResourceImporterScene.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/classes/ResourceImporterShaderFile.xml b/doc/classes/ResourceImporterShaderFile.xml new file mode 100644 index 00000000000..cb1ed616df5 --- /dev/null +++ b/doc/classes/ResourceImporterShaderFile.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/doc/classes/ResourceImporterTexture.xml b/doc/classes/ResourceImporterTexture.xml new file mode 100644 index 00000000000..1cc696aef30 --- /dev/null +++ b/doc/classes/ResourceImporterTexture.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/classes/ResourceImporterTextureAtlas.xml b/doc/classes/ResourceImporterTextureAtlas.xml new file mode 100644 index 00000000000..efae901069c --- /dev/null +++ b/doc/classes/ResourceImporterTextureAtlas.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/doc/classes/ResourceImporterWAV.xml b/doc/classes/ResourceImporterWAV.xml new file mode 100644 index 00000000000..f2827d29615 --- /dev/null +++ b/doc/classes/ResourceImporterWAV.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index 67a8814aa18..83ad2bf4e38 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -36,6 +36,7 @@ #include "core/io/compression.h" #include "core/io/dir_access.h" #include "core/io/marshalls.h" +#include "core/io/resource_importer.h" #include "core/object/script_language.h" #include "core/string/translation.h" #include "core/version.h" @@ -392,7 +393,13 @@ void DocTools::generate(bool p_basic_types) { List properties; List own_properties; - // Special case for editor and project settings, so they can be documented. + // Special cases for editor/project settings, and ResourceImporter classes, + // we have to rely on Object's property list to get settings and import options. + // Otherwise we just use ClassDB's property list (pure registered properties). + + bool properties_from_instance = true; // To skip `script`, etc. + bool import_option = false; // Special case for default value. + HashMap import_options_default; if (name == "EditorSettings") { // We don't create the full blown EditorSettings (+ config file) with `create()`, // instead we just make a local instance to get default values. @@ -402,7 +409,20 @@ void DocTools::generate(bool p_basic_types) { } else if (name == "ProjectSettings") { ProjectSettings::get_singleton()->get_property_list(&properties); own_properties = properties; + } else if (ClassDB::is_parent_class(name, "ResourceImporter") && name != "EditorImportPlugin" && ClassDB::can_instantiate(name)) { + import_option = true; + ResourceImporter *resimp = Object::cast_to(ClassDB::instantiate(name)); + List options; + resimp->get_import_options("", &options); + for (int i = 0; i < options.size(); i++) { + const PropertyInfo &prop = options[i].option; + properties.push_back(prop); + import_options_default[prop.name] = options[i].default_value; + } + own_properties = properties; + memdelete(resimp); } else if (name.begins_with("EditorExportPlatform") && ClassDB::can_instantiate(name)) { + properties_from_instance = false; Ref platform = Object::cast_to(ClassDB::instantiate(name)); if (platform.is_valid()) { List options; @@ -413,6 +433,7 @@ void DocTools::generate(bool p_basic_types) { own_properties = properties; } } else { + properties_from_instance = false; ClassDB::get_property_list(name, &properties); ClassDB::get_property_list(name, &own_properties, true); } @@ -429,6 +450,13 @@ void DocTools::generate(bool p_basic_types) { EO = EO->next(); } + if (properties_from_instance) { + if (E.name == "resource_local_to_scene" || E.name == "resource_name" || E.name == "resource_path" || E.name == "script") { + // Don't include spurious properties from Object property list. + continue; + } + } + if (E.usage & PROPERTY_USAGE_GROUP || E.usage & PROPERTY_USAGE_SUBGROUP || E.usage & PROPERTY_USAGE_CATEGORY || E.usage & PROPERTY_USAGE_INTERNAL || (E.type == Variant::NIL && E.usage & PROPERTY_USAGE_ARRAY)) { continue; } @@ -448,22 +476,9 @@ void DocTools::generate(bool p_basic_types) { bool default_value_valid = false; Variant default_value; - if (name == "EditorSettings") { - if (E.name == "resource_local_to_scene" || E.name == "resource_name" || E.name == "resource_path" || E.name == "script") { - // Don't include spurious properties in the generated EditorSettings class reference. - continue; - } - } - - if (name.begins_with("EditorExportPlatform")) { - if (E.name == "script") { - continue; - } - } - if (name == "ProjectSettings") { // Special case for project settings, so that settings are not taken from the current project's settings - if (E.name == "script" || !ProjectSettings::get_singleton()->is_builtin_setting(E.name)) { + if (!ProjectSettings::get_singleton()->is_builtin_setting(E.name)) { continue; } if (E.usage & PROPERTY_USAGE_EDITOR) { @@ -472,6 +487,9 @@ void DocTools::generate(bool p_basic_types) { default_value_valid = true; } } + } else if (import_option) { + default_value = import_options_default[E.name]; + default_value_valid = true; } else { default_value = get_documentation_default_value(name, E.name, default_value_valid); if (inherited) { diff --git a/editor/import_defaults_editor.cpp b/editor/import_defaults_editor.cpp index ebbea827c0e..98a9bfe9dce 100644 --- a/editor/import_defaults_editor.cpp +++ b/editor/import_defaults_editor.cpp @@ -157,6 +157,9 @@ void ImportDefaultsEditor::_update_importer() { settings->notify_property_list_changed(); + // Set the importer class to fetch the correct class in the XML class reference. + // This allows tooltips to display when hovering properties. + inspector->set_object_class(importer->get_class_name()); inspector->edit(settings); } @@ -210,9 +213,14 @@ ImportDefaultsEditor::ImportDefaultsEditor() { reset_defaults->connect("pressed", callable_mp(this, &ImportDefaultsEditor::_reset)); hb->add_child(reset_defaults); add_child(hb); + inspector = memnew(EditorInspector); add_child(inspector); inspector->set_v_size_flags(SIZE_EXPAND_FILL); + // Make it possible to display tooltips stored in the XML class reference. + // The object name is set when the importer changes in `_update_importer()`. + inspector->set_use_doc_hints(true); + CenterContainer *cc = memnew(CenterContainer); save_defaults = memnew(Button); save_defaults->set_text(TTR("Save")); diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index 7b8b9cd7a48..8e3a247ace3 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -157,6 +157,13 @@ void ImportDock::_add_keep_import_option(const String &p_importer_name) { } void ImportDock::_update_options(const String &p_path, const Ref &p_config) { + // Set the importer class to fetch the correct class in the XML class reference. + // This allows tooltips to display when hovering properties. + if (params->importer != nullptr) { + // Null check to avoid crashing if the "Keep File (No Import)" mode is selected. + import_opts->set_object_class(params->importer->get_class_name()); + } + List options; if (params->importer.is_valid()) { @@ -644,6 +651,9 @@ ImportDock::ImportDock() { import_opts->set_v_size_flags(SIZE_EXPAND_FILL); import_opts->connect("property_edited", callable_mp(this, &ImportDock::_property_edited)); import_opts->connect("property_toggled", callable_mp(this, &ImportDock::_property_toggled)); + // Make it possible to display tooltips stored in the XML class reference. + // The object name is set when the importer changes in `_update_options()`. + import_opts->set_use_doc_hints(true); hb = memnew(HBoxContainer); content->add_child(hb); diff --git a/editor/register_editor_types.cpp b/editor/register_editor_types.cpp index b674ce5967b..1cc281ba38e 100644 --- a/editor/register_editor_types.cpp +++ b/editor/register_editor_types.cpp @@ -50,7 +50,19 @@ #include "editor/gui/editor_file_dialog.h" #include "editor/gui/editor_spin_slider.h" #include "editor/import/editor_import_plugin.h" +#include "editor/import/resource_importer_bitmask.h" +#include "editor/import/resource_importer_bmfont.h" +#include "editor/import/resource_importer_csv_translation.h" +#include "editor/import/resource_importer_dynamic_font.h" +#include "editor/import/resource_importer_image.h" +#include "editor/import/resource_importer_imagefont.h" +#include "editor/import/resource_importer_layered_texture.h" +#include "editor/import/resource_importer_obj.h" #include "editor/import/resource_importer_scene.h" +#include "editor/import/resource_importer_shader_file.h" +#include "editor/import/resource_importer_texture.h" +#include "editor/import/resource_importer_texture_atlas.h" +#include "editor/import/resource_importer_wav.h" #include "editor/plugins/animation_tree_editor_plugin.h" #include "editor/plugins/audio_stream_editor_plugin.h" #include "editor/plugins/audio_stream_randomizer_editor_plugin.h" @@ -168,6 +180,21 @@ void register_editor_types() { GDREGISTER_CLASS(EditorDebuggerPlugin); GDREGISTER_ABSTRACT_CLASS(EditorDebuggerSession); + // Required to document import options in the class reference. + GDREGISTER_CLASS(ResourceImporterBitMap); + GDREGISTER_CLASS(ResourceImporterBMFont); + GDREGISTER_CLASS(ResourceImporterCSVTranslation); + GDREGISTER_CLASS(ResourceImporterDynamicFont); + GDREGISTER_CLASS(ResourceImporterImage); + GDREGISTER_CLASS(ResourceImporterImageFont); + GDREGISTER_CLASS(ResourceImporterLayeredTexture); + GDREGISTER_CLASS(ResourceImporterOBJ); + GDREGISTER_CLASS(ResourceImporterScene); + GDREGISTER_CLASS(ResourceImporterShaderFile); + GDREGISTER_CLASS(ResourceImporterTexture); + GDREGISTER_CLASS(ResourceImporterTextureAtlas); + GDREGISTER_CLASS(ResourceImporterWAV); + // This list is alphabetized, and plugins that depend on Node2D are in their own section below. EditorPlugins::add_by_type(); EditorPlugins::add_by_type(); diff --git a/modules/minimp3/config.py b/modules/minimp3/config.py index bd35d099b93..e6bdcb2a83d 100644 --- a/modules/minimp3/config.py +++ b/modules/minimp3/config.py @@ -9,6 +9,7 @@ def configure(env): def get_doc_classes(): return [ "AudioStreamMP3", + "ResourceImporterMP3", ] diff --git a/modules/minimp3/doc_classes/ResourceImporterMP3.xml b/modules/minimp3/doc_classes/ResourceImporterMP3.xml new file mode 100644 index 00000000000..56bb613d25e --- /dev/null +++ b/modules/minimp3/doc_classes/ResourceImporterMP3.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + If [code]true[/code], the audio will play again from the specified [member loop_offset] once it is done playing. Useful for ambient sounds and background music. + + + + + diff --git a/modules/minimp3/register_types.cpp b/modules/minimp3/register_types.cpp index c9e05c44e17..4ffc0691d9d 100644 --- a/modules/minimp3/register_types.cpp +++ b/modules/minimp3/register_types.cpp @@ -48,7 +48,11 @@ void initialize_minimp3_module(ModuleInitializationLevel p_level) { mp3_import.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(mp3_import); } + + // Required to document import options in the class reference. + GDREGISTER_CLASS(ResourceImporterMP3); #endif + GDREGISTER_CLASS(AudioStreamMP3); } diff --git a/modules/vorbis/config.py b/modules/vorbis/config.py index a231ef179df..9e10a58849e 100644 --- a/modules/vorbis/config.py +++ b/modules/vorbis/config.py @@ -11,6 +11,7 @@ def get_doc_classes(): return [ "AudioStreamOggVorbis", "AudioStreamPlaybackOggVorbis", + "ResourceImporterOggVorbis", ] diff --git a/modules/vorbis/doc_classes/AudioStreamOggVorbis.xml b/modules/vorbis/doc_classes/AudioStreamOggVorbis.xml index 4551d395df4..c553955192c 100644 --- a/modules/vorbis/doc_classes/AudioStreamOggVorbis.xml +++ b/modules/vorbis/doc_classes/AudioStreamOggVorbis.xml @@ -14,7 +14,7 @@ - If [code]true[/code], the stream will automatically loop when it reaches the end. + If [code]true[/code], the audio will play again from the specified [member loop_offset] once it is done playing. Useful for ambient sounds and background music. Time in seconds at which the stream starts after being looped. diff --git a/modules/vorbis/doc_classes/ResourceImporterOggVorbis.xml b/modules/vorbis/doc_classes/ResourceImporterOggVorbis.xml new file mode 100644 index 00000000000..e5da120519e --- /dev/null +++ b/modules/vorbis/doc_classes/ResourceImporterOggVorbis.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + If [code]true[/code], the audio will play again from the specified [member loop_offset] once it is done playing. Useful for ambient sounds and background music. + + + + + diff --git a/modules/vorbis/register_types.cpp b/modules/vorbis/register_types.cpp index e131ff6dc99..028b7a30863 100644 --- a/modules/vorbis/register_types.cpp +++ b/modules/vorbis/register_types.cpp @@ -44,7 +44,11 @@ void initialize_vorbis_module(ModuleInitializationLevel p_level) { ogg_vorbis_importer.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(ogg_vorbis_importer); } + + // Required to document import options in the class reference. + GDREGISTER_CLASS(ResourceImporterOggVorbis); #endif + GDREGISTER_CLASS(AudioStreamOggVorbis); GDREGISTER_CLASS(AudioStreamPlaybackOggVorbis); }