From b32b570d7a64dfdce02605557532754a8629e68a Mon Sep 17 00:00:00 2001 From: PucklaMotzer09 Date: Tue, 4 Jan 2022 18:52:32 +0100 Subject: [PATCH] Show dependency warning when removing remaps and fallback if translation remap does not exist --- core/io/resource_loader.cpp | 6 +++++ editor/dependency_editor.cpp | 40 ++++++++++++++++++++++++++++++++++ editor/dependency_editor.h | 1 + editor/editor_node.cpp | 2 +- editor/localization_editor.cpp | 6 +++++ 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index fc4177004b8..3e595557f91 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -819,6 +819,12 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem if (r_translation_remapped) { *r_translation_remapped = true; } + + // Fallback to p_path if new_path does not exist. + if (!FileAccess::exists(new_path)) { + WARN_PRINT(vformat("Translation remap '%s' does not exist. Falling back to '%s'.", new_path, p_path)); + new_path = p_path; + } } if (path_remaps.has(new_path)) { diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp index 5b4da0e32b1..43961a7cebc 100644 --- a/editor/dependency_editor.cpp +++ b/editor/dependency_editor.cpp @@ -417,6 +417,45 @@ void DependencyRemoveDialog::_find_all_removed_dependencies(EditorFileSystemDire } } +void DependencyRemoveDialog::_find_localization_remaps_of_removed_files(Vector &p_removed) { + for (KeyValue &files : all_remove_files) { + const String &path = files.key; + + // Look for dependencies in the translation remaps. + if (ProjectSettings::get_singleton()->has_setting("internationalization/locale/translation_remaps")) { + Dictionary remaps = ProjectSettings::get_singleton()->get("internationalization/locale/translation_remaps"); + + if (remaps.has(path)) { + RemovedDependency dep; + dep.file = TTR("Localization remap"); + dep.file_type = ""; + dep.dependency = path; + dep.dependency_folder = files.value; + p_removed.push_back(dep); + } + + Array remap_keys = remaps.keys(); + for (int j = 0; j < remap_keys.size(); j++) { + PackedStringArray remapped_files = remaps[remap_keys[j]]; + for (int k = 0; k < remapped_files.size(); k++) { + int splitter_pos = remapped_files[k].rfind(":"); + String res_path = remapped_files[k].substr(0, splitter_pos); + if (res_path == path) { + String locale_name = remapped_files[k].substr(splitter_pos + 1); + + RemovedDependency dep; + dep.file = vformat(TTR("Localization remap for path '%s' and locale '%s'."), remap_keys[j], locale_name); + dep.file_type = ""; + dep.dependency = path; + dep.dependency_folder = files.value; + p_removed.push_back(dep); + } + } + } + } + } +} + void DependencyRemoveDialog::_build_removed_dependency_tree(const Vector &p_removed) { owners->clear(); owners->create_item(); // root @@ -473,6 +512,7 @@ void DependencyRemoveDialog::show(const Vector &p_folders, const Vector< Vector removed_deps; _find_all_removed_dependencies(EditorFileSystem::get_singleton()->get_filesystem(), removed_deps); + _find_localization_remaps_of_removed_files(removed_deps); removed_deps.sort(); if (removed_deps.is_empty()) { owners->hide(); diff --git a/editor/dependency_editor.h b/editor/dependency_editor.h index 96d82d58eb7..6e39015ec34 100644 --- a/editor/dependency_editor.h +++ b/editor/dependency_editor.h @@ -119,6 +119,7 @@ class DependencyRemoveDialog : public ConfirmationDialog { void _find_files_in_removed_folder(EditorFileSystemDirectory *efsd, const String &p_folder); void _find_all_removed_dependencies(EditorFileSystemDirectory *efsd, Vector &p_removed); + void _find_localization_remaps_of_removed_files(Vector &p_removed); void _build_removed_dependency_tree(const Vector &p_removed); void ok_pressed() override; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 532bc3041db..84c567ee319 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -6877,7 +6877,7 @@ EditorNode::EditorNode() { filesystem_dock->connect("inherit", callable_mp(this, &EditorNode::_inherit_request)); filesystem_dock->connect("instance", callable_mp(this, &EditorNode::_instantiate_request)); filesystem_dock->connect("display_mode_changed", callable_mp(this, &EditorNode::_save_docks)); - project_settings->connect_filesystem_dock_signals(filesystem_dock); + get_project_settings()->connect_filesystem_dock_signals(filesystem_dock); // Scene: Top left. dock_slot[DOCK_SLOT_LEFT_UR]->add_child(SceneTreeDock::get_singleton()); diff --git a/editor/localization_editor.cpp b/editor/localization_editor.cpp index 5d944956f6b..e8fb80eb57d 100644 --- a/editor/localization_editor.cpp +++ b/editor/localization_editor.cpp @@ -551,6 +551,12 @@ void LocalizationEditor::update_translations() { t2->set_editable(1, true); t2->set_metadata(1, path); t2->set_tooltip(1, locale); + + // Display that it has been removed if this is the case. + if (!FileAccess::exists(path)) { + t2->set_text(0, t2->get_text(0) + vformat(" (%s)", TTR("Removed"))); + t2->set_tooltip(0, vformat(TTR("%s cannot be found."), t2->get_tooltip(0))); + } } } }