diff options
Diffstat (limited to 'editor/import_dock.cpp')
-rw-r--r-- | editor/import_dock.cpp | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index cc6b4e66e4..4df46f2348 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 */ @@ -29,8 +29,11 @@ /*************************************************************************/ #include "import_dock.h" -#include "editor_node.h" -#include "editor_resource_preview.h" + +#include "core/config/project_settings.h" +#include "editor/editor_node.h" +#include "editor/editor_resource_preview.h" +#include "editor/editor_scale.h" class ImportDockParameters : public Object { GDCLASS(ImportDockParameters, Object); @@ -90,6 +93,8 @@ public: } }; +ImportDock *ImportDock::singleton = nullptr; + void ImportDock::set_edit_path(const String &p_path) { Ref<ConfigFile> config; config.instantiate(); @@ -123,7 +128,7 @@ void ImportDock::set_edit_path(const String &p_path) { for (const Pair<String, String> &E : importer_names) { import_as->add_item(E.first); - import_as->set_item_metadata(import_as->get_item_count() - 1, E.second); + import_as->set_item_metadata(-1, E.second); if (E.second == importer_name) { import_as->select(import_as->get_item_count() - 1); } @@ -135,6 +140,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()); } @@ -142,7 +149,7 @@ void ImportDock::set_edit_path(const String &p_path) { void ImportDock::_add_keep_import_option(const String &p_importer_name) { import_as->add_separator(); import_as->add_item(TTR("Keep File (No Import)")); - import_as->set_item_metadata(import_as->get_item_count() - 1, "keep"); + import_as->set_item_metadata(-1, "keep"); if (p_importer_name == "keep") { import_as->select(import_as->get_item_count() - 1); } @@ -279,7 +286,7 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) { for (const Pair<String, String> &E : importer_names) { import_as->add_item(E.first); - import_as->set_item_metadata(import_as->get_item_count() - 1, E.second); + import_as->set_item_metadata(-1, E.second); if (E.second == params->importer->get_importer_name()) { import_as->select(import_as->get_item_count() - 1); } @@ -294,6 +301,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())); @@ -423,6 +432,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) { @@ -438,7 +449,7 @@ static bool _find_owners(EditorFileSystemDirectory *efsd, const String &p_path) for (int i = 0; i < efsd->get_file_count(); i++) { Vector<String> deps = efsd->get_file_deps(i); - if (deps.find(p_path) != -1) { + if (deps.has(p_path)) { return true; } } @@ -525,7 +536,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]; @@ -553,6 +564,7 @@ void ImportDock::_notification(int p_what) { switch (p_what) { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { imported->add_theme_style_override("normal", get_theme_stylebox(SNAME("normal"), SNAME("LineEdit"))); + import_opts->set_property_name_style(EditorPropertyNameProcessor::get_settings_style()); } break; case NOTIFICATION_ENTER_TREE: { @@ -599,13 +611,20 @@ void ImportDock::initialize_import_options() const { } ImportDock::ImportDock() { + singleton = this; 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)); @@ -618,13 +637,14 @@ 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->set_property_name_style(EditorPropertyNameProcessor::get_settings_style()); 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); @@ -652,7 +672,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()); @@ -662,8 +682,18 @@ 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() { + singleton = nullptr; memdelete(params); } |