diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 75f01ef055b..0ff0bca7eee 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -1108,12 +1108,15 @@ void EditorNode::_save_scene(String p_file, int idx) { } } -void EditorNode::save_all_scenes_and_restart() { +void EditorNode::save_all_scenes() { _menu_option_confirm(RUN_STOP, true); - exiting = true; - _save_all_scenes(); +} + +void EditorNode::restart_editor() { + + exiting = true; String to_reopen; if (get_tree()->get_edited_scene_root()) { @@ -2305,7 +2308,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { ProjectSettings::get_singleton()->set("rendering/quality/driver/driver_name", video_driver_request); ProjectSettings::get_singleton()->save(); - save_all_scenes_and_restart(); + save_all_scenes(); + restart_editor(); } break; default: { if (p_option >= IMPORT_PLUGIN_BASE) { diff --git a/editor/editor_node.h b/editor/editor_node.h index 13bebea5f02..a45ea54186d 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -782,7 +782,8 @@ public: void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu); void remove_tool_menu_item(const String &p_name); - void save_all_scenes_and_restart(); + void save_all_scenes(); + void restart_editor(); void dim_editor(bool p_dimming); diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index e59df7c9325..e050c53a3b8 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -372,6 +372,62 @@ void ImportDock::clear() { preset->get_popup()->clear(); } +static bool _find_owners(EditorFileSystemDirectory *efsd, const String &p_path) { + + if (!efsd) + return false; + + for (int i = 0; i < efsd->get_subdir_count(); i++) { + + if (_find_owners(efsd->get_subdir(i), p_path)) { + return true; + } + } + + for (int i = 0; i < efsd->get_file_count(); i++) { + + Vector deps = efsd->get_file_deps(i); + if (deps.find(p_path) != -1) + return true; + } + + return false; +} +void ImportDock::_reimport_attempt() { + + bool need_restart = false; + bool used_in_resources = false; + for (int i = 0; i < params->paths.size(); i++) { + Ref config; + config.instance(); + Error err = config->load(params->paths[i] + ".import"); + ERR_CONTINUE(err != OK); + + String imported_with = config->get_value("remap", "importer"); + if (imported_with != params->importer->get_importer_name()) { + need_restart = true; + if (_find_owners(EditorFileSystem::get_singleton()->get_filesystem(), params->paths[i])) { + used_in_resources = true; + } + } + } + + if (need_restart) { + label_warning->set_visible(used_in_resources); + reimport_confirm->popup_centered_minsize(); + return; + } + + _reimport(); +} + +void ImportDock::_reimport_and_restart() { + + EditorNode::get_singleton()->save_all_scenes(); + _reimport(); + EditorNode::get_singleton()->restart_editor(); +} + void ImportDock::_reimport() { for (int i = 0; i < params->paths.size(); i++) { @@ -416,6 +472,7 @@ void ImportDock::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { import_opts->edit(params); + label_warning->add_color_override("font_color", get_color("warning_color", "Editor")); } break; } } @@ -433,6 +490,8 @@ void ImportDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_preset_selected"), &ImportDock::_preset_selected); ClassDB::bind_method(D_METHOD("_importer_selected"), &ImportDock::_importer_selected); ClassDB::bind_method(D_METHOD("_property_toggled"), &ImportDock::_property_toggled); + ClassDB::bind_method(D_METHOD("_reimport_and_restart"), &ImportDock::_reimport_and_restart); + ClassDB::bind_method(D_METHOD("_reimport_attempt"), &ImportDock::_reimport_attempt); } void ImportDock::initialize_import_options() const { @@ -469,11 +528,22 @@ ImportDock::ImportDock() { add_child(hb); import = memnew(Button); import->set_text(TTR("Reimport")); - import->connect("pressed", this, "_reimport"); + import->connect("pressed", this, "_reimport_attempt"); hb->add_spacer(); hb->add_child(import); hb->add_spacer(); + reimport_confirm = memnew(ConfirmationDialog); + reimport_confirm->get_ok()->set_text(TTR("Save scenes, re-import and restart")); + add_child(reimport_confirm); + reimport_confirm->connect("confirmed", this, "_reimport_and_restart"); + + VBoxContainer *vbc_confirm = memnew(VBoxContainer()); + vbc_confirm->add_child(memnew(Label(TTR("Changing the type of an imported file requires editor restart.")))); + label_warning = memnew(Label(TTR("WARNING: Assets exist that use this resource, they may stop loading properly."))); + vbc_confirm->add_child(label_warning); + reimport_confirm->add_child(vbc_confirm); + params = memnew(ImportDockParameters); } diff --git a/editor/import_dock.h b/editor/import_dock.h index bc992b2f7ec..1d43e00b633 100644 --- a/editor/import_dock.h +++ b/editor/import_dock.h @@ -36,6 +36,7 @@ #include "editor/editor_file_system.h" #include "editor/editor_inspector.h" #include "scene/gui/box_container.h" +#include "scene/gui/dialogs.h" #include "scene/gui/menu_button.h" #include "scene/gui/option_button.h" #include "scene/gui/popup_menu.h" @@ -52,6 +53,8 @@ class ImportDock : public VBoxContainer { List properties; Map property_values; + ConfirmationDialog *reimport_confirm; + Label *label_warning; Button *import; ImportDockParameters *params; @@ -61,6 +64,8 @@ class ImportDock : public VBoxContainer { void _update_options(const Ref &p_config = Ref()); void _property_toggled(const StringName &p_prop, bool p_checked); + void _reimport_attempt(); + void _reimport_and_restart(); void _reimport(); enum { diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index dd31853e736..cc33550ac9c 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -1606,7 +1606,8 @@ TabContainer *ProjectSettingsEditor::get_tabs() { } void ProjectSettingsEditor::_editor_restart() { - EditorNode::get_singleton()->save_all_scenes_and_restart(); + EditorNode::get_singleton()->save_all_scenes(); + EditorNode::get_singleton()->restart_editor(); } void ProjectSettingsEditor::_editor_restart_request() { diff --git a/editor/settings_config_dialog.cpp b/editor/settings_config_dialog.cpp index e4d5573a9a5..ecd35cb9302 100644 --- a/editor/settings_config_dialog.cpp +++ b/editor/settings_config_dialog.cpp @@ -375,7 +375,8 @@ void EditorSettingsDialog::_focus_current_search_box() { } void EditorSettingsDialog::_editor_restart() { - EditorNode::get_singleton()->save_all_scenes_and_restart(); + EditorNode::get_singleton()->save_all_scenes(); + EditorNode::get_singleton()->restart_editor(); } void EditorSettingsDialog::_editor_restart_request() {