diff options
Diffstat (limited to 'editor/import_dock.cpp')
-rw-r--r-- | editor/import_dock.cpp | 68 |
1 files changed, 50 insertions, 18 deletions
diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index a6e1e1d094..10654cfe43 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -31,6 +31,7 @@ #include "import_dock.h" #include "editor_node.h" #include "editor_resource_preview.h" +#include "editor_scale.h" class ImportDockParameters : public Object { GDCLASS(ImportDockParameters, Object); @@ -42,6 +43,7 @@ public: Vector<String> paths; Set<StringName> checked; bool checking; + String base_options_path; bool _set(const StringName &p_name, const Variant &p_value) { if (values.has(p_name)) { @@ -66,7 +68,7 @@ public: } void _get_property_list(List<PropertyInfo> *p_list) const { for (const PropertyInfo &E : properties) { - if (!importer->get_option_visibility(E.name, values)) { + if (!importer->get_option_visibility(base_options_path, E.name, values)) { continue; } PropertyInfo pi = E; @@ -104,8 +106,9 @@ void ImportDock::set_edit_path(const String &p_path) { params->paths.clear(); params->paths.push_back(p_path); + params->base_options_path = p_path; - _update_options(config); + _update_options(p_path, config); List<Ref<ResourceImporter>> importers; ResourceFormatImporter::get_singleton()->get_importers_for_extension(p_path.get_extension(), &importers); @@ -133,6 +136,8 @@ void ImportDock::set_edit_path(const String &p_path) { _set_dirty(false); import_as->set_disabled(false); preset->set_disabled(false); + content->show(); + select_a_resource->hide(); imported->set_text(p_path.get_file()); } @@ -146,17 +151,18 @@ void ImportDock::_add_keep_import_option(const String &p_importer_name) { } } -void ImportDock::_update_options(const Ref<ConfigFile> &p_config) { +void ImportDock::_update_options(const String &p_path, const Ref<ConfigFile> &p_config) { List<ResourceImporter::ImportOption> options; if (params->importer.is_valid()) { - params->importer->get_import_options(&options); + params->importer->get_import_options(p_path, &options); } params->properties.clear(); params->values.clear(); params->checking = params->paths.size() > 1; params->checked.clear(); + params->base_options_path = p_path; for (const ResourceImporter::ImportOption &E : options) { params->properties.push_back(E.option); @@ -184,10 +190,12 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) { // Use the value that is repeated the most. Map<String, Dictionary> value_frequency; + Set<String> extensions; for (int i = 0; i < p_paths.size(); i++) { Ref<ConfigFile> config; config.instantiate(); + extensions.insert(p_paths[i].get_extension()); Error err = config->load(p_paths[i] + ".import"); ERR_CONTINUE(err != OK); @@ -223,13 +231,18 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) { ERR_FAIL_COND(params->importer.is_null()); + String base_path; + if (extensions.size() == 1 && p_paths.size() > 0) { + base_path = p_paths[0]; + } List<ResourceImporter::ImportOption> options; - params->importer->get_import_options(&options); + params->importer->get_import_options(base_path, &options); params->properties.clear(); params->values.clear(); params->checking = true; params->checked.clear(); + params->base_options_path = base_path; for (const ResourceImporter::ImportOption &E : options) { params->properties.push_back(E.option); @@ -284,6 +297,8 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) { _set_dirty(false); import_as->set_disabled(false); preset->set_disabled(false); + content->show(); + select_a_resource->hide(); imported->set_text(vformat(TTR("%d Files"), p_paths.size())); @@ -327,22 +342,22 @@ void ImportDock::_importer_selected(int i_idx) { String name = import_as->get_selected_metadata(); if (name == "keep") { params->importer.unref(); - _update_options(Ref<ConfigFile>()); + _update_options(params->base_options_path, Ref<ConfigFile>()); } else { Ref<ResourceImporter> importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(name); ERR_FAIL_COND(importer.is_null()); params->importer = importer; - Ref<ConfigFile> config; if (params->paths.size()) { + String path = params->paths[0]; config.instantiate(); - Error err = config->load(params->paths[0] + ".import"); + Error err = config->load(path + ".import"); if (err != OK) { config.unref(); } } - _update_options(config); + _update_options(params->base_options_path, config); } } @@ -387,7 +402,7 @@ void ImportDock::_preset_selected(int p_idx) { default: { List<ResourceImporter::ImportOption> options; - params->importer->get_import_options(&options, p_idx); + params->importer->get_import_options(params->base_options_path, &options, p_idx); if (params->checking) { params->checked.clear(); @@ -413,6 +428,8 @@ void ImportDock::clear() { params->properties.clear(); params->update(); preset->get_popup()->clear(); + content->hide(); + select_a_resource->show(); } static bool _find_owners(EditorFileSystemDirectory *efsd, const String &p_path) { @@ -515,7 +532,7 @@ void ImportDock::_reimport() { Ref<ResourceImporter> importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(importer_name); ERR_CONTINUE(!importer.is_valid()); String group_file_property = importer->get_option_group_file(); - if (group_file_property != String()) { + if (!group_file_property.is_empty()) { //can import from a group (as in, atlas) ERR_CONTINUE(!params->values.has(group_file_property)); String group_file = params->values[group_file_property]; @@ -590,12 +607,18 @@ void ImportDock::initialize_import_options() const { ImportDock::ImportDock() { set_name("Import"); + + content = memnew(VBoxContainer); + content->set_v_size_flags(SIZE_EXPAND_FILL); + add_child(content); + content->hide(); + imported = memnew(Label); imported->add_theme_style_override("normal", EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox(SNAME("normal"), SNAME("LineEdit"))); imported->set_clip_text(true); - add_child(imported); + content->add_child(imported); HBoxContainer *hb = memnew(HBoxContainer); - add_margin_child(TTR("Import As:"), hb); + content->add_margin_child(TTR("Import As:"), hb); import_as = memnew(OptionButton); import_as->set_disabled(true); import_as->connect("item_selected", callable_mp(this, &ImportDock::_importer_selected)); @@ -608,13 +631,13 @@ ImportDock::ImportDock() { hb->add_child(preset); import_opts = memnew(EditorInspector); - add_child(import_opts); + content->add_child(import_opts); 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)); hb = memnew(HBoxContainer); - add_child(hb); + content->add_child(hb); import = memnew(Button); import->set_text(TTR("Reimport")); import->set_disabled(true); @@ -642,7 +665,7 @@ ImportDock::ImportDock() { reimport_confirm = memnew(ConfirmationDialog); reimport_confirm->get_ok_button()->set_text(TTR("Save Scenes, Re-Import, and Restart")); - add_child(reimport_confirm); + content->add_child(reimport_confirm); reimport_confirm->connect("confirmed", callable_mp(this, &ImportDock::_reimport_and_restart)); VBoxContainer *vbc_confirm = memnew(VBoxContainer()); @@ -652,6 +675,15 @@ ImportDock::ImportDock() { reimport_confirm->add_child(vbc_confirm); params = memnew(ImportDockParameters); + + select_a_resource = memnew(Label); + select_a_resource->set_text(TTR("Select a resource file in the filesystem or in the inspector to adjust import settings.")); + select_a_resource->set_autowrap_mode(Label::AUTOWRAP_WORD); + select_a_resource->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); + select_a_resource->set_v_size_flags(SIZE_EXPAND_FILL); + select_a_resource->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); + select_a_resource->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER); + add_child(select_a_resource); } ImportDock::~ImportDock() { |