Replace UID and Surface upgrade tools with universal one

This commit is contained in:
kobewi 2025-02-19 14:27:27 +01:00
parent 30bb49ec1f
commit a3a1cf0a7f
7 changed files with 169 additions and 525 deletions

View File

@ -158,12 +158,11 @@
#include "editor/plugins/visual_shader_editor_plugin.h"
#include "editor/progress_dialog.h"
#include "editor/project_settings_editor.h"
#include "editor/project_upgrade_tool.h"
#include "editor/register_exporters.h"
#include "editor/scene_tree_dock.h"
#include "editor/surface_upgrade_tool.h"
#include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h"
#include "editor/uid_upgrade_tool.h"
#include "editor/window_wrapper.h"
#include "modules/modules_enabled.gen.h" // For gdscript, mono.
@ -649,10 +648,7 @@ void EditorNode::_notification(int p_what) {
OS::get_singleton()->benchmark_begin_measure("Editor", "First Scan");
if (run_surface_upgrade_tool || run_uid_upgrade_tool) {
EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &EditorNode::_execute_upgrades), CONNECT_ONE_SHOT);
}
EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &EditorNode::_execute_upgrades), CONNECT_ONE_SHOT);
EditorFileSystem::get_singleton()->scan();
}
} break;
@ -735,23 +731,6 @@ void EditorNode::_notification(int p_what) {
// Save the project after opening to mark it as last modified, except in headless mode.
if (DisplayServer::get_singleton()->window_can_draw()) {
// Try to determine if this project's Godot version was less than 4.4 - if
// so, we'll ask the user if they want to upgrade the project.
PackedStringArray features = ProjectSettings::get_singleton()->get_setting("application/config/features");
if (!features.is_empty()) {
String version_str = features[0];
PackedStringArray version_parts = version_str.split(".", true, 1);
if (version_parts.size() >= 2) {
if (version_parts[0].is_valid_int() && version_parts[1].is_valid_int()) {
int major_ver = version_parts[0].to_int();
int minor_ver = version_parts[1].to_int();
if (major_ver < 4 || (major_ver == 4 && minor_ver < 4)) {
should_prompt_uid_upgrade_tool = true;
}
}
}
}
ProjectSettings::get_singleton()->save();
}
@ -896,16 +875,11 @@ void EditorNode::_update_update_spinner() {
}
void EditorNode::_execute_upgrades() {
if (run_surface_upgrade_tool) {
run_surface_upgrade_tool = false;
if (run_project_upgrade_tool) {
run_project_upgrade_tool = false;
// Execute another scan to reimport the modified files.
SurfaceUpgradeTool::get_singleton()->connect("upgrade_finished", callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::scan), CONNECT_ONE_SHOT);
SurfaceUpgradeTool::get_singleton()->finish_upgrade();
} else if (run_uid_upgrade_tool) {
run_uid_upgrade_tool = false;
// Execute another scan to reimport the modified files.
UIDUpgradeTool::get_singleton()->connect("upgrade_finished", callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::scan), CONNECT_ONE_SHOT);
UIDUpgradeTool::get_singleton()->finish_upgrade();
project_upgrade_tool->connect(project_upgrade_tool->UPGRADE_FINISHED, callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::scan), CONNECT_ONE_SHOT);
project_upgrade_tool->finish_upgrade();
}
}
@ -1202,20 +1176,10 @@ void EditorNode::_sources_changed(bool p_exist) {
OS::get_singleton()->benchmark_dump();
}
if (SurfaceUpgradeTool::get_singleton()->is_show_requested()) {
SurfaceUpgradeTool::get_singleton()->show_popup();
}
// Start preview thread now that it's safe.
if (!singleton->cmdline_mode) {
EditorResourcePreview::get_singleton()->start();
}
if (should_prompt_uid_upgrade_tool) {
should_prompt_uid_upgrade_tool = false;
uid_upgrade_dialog->popup_on_demand();
}
get_tree()->create_timer(1.0f)->connect("timeout", callable_mp(this, &EditorNode::_remove_lock_file));
}
}
@ -3349,11 +3313,8 @@ void EditorNode::_tool_menu_option(int p_idx) {
case TOOLS_BUILD_PROFILE_MANAGER: {
build_profile_manager->popup_centered_clamped(Size2(700, 800) * EDSCALE, 0.8);
} break;
case TOOLS_SURFACE_UPGRADE: {
surface_upgrade_dialog->popup_on_demand();
} break;
case TOOLS_UID_UPGRADE: {
uid_upgrade_dialog->popup_on_demand();
case TOOLS_PROJECT_UPGRADE: {
project_upgrade_tool->popup_dialog();
} break;
case TOOLS_CUSTOM: {
if (tool_menu->get_item_submenu(p_idx) == "") {
@ -6963,18 +6924,11 @@ EditorNode::EditorNode() {
_update_vsync_mode();
// Warm up the surface upgrade tool as early as possible.
surface_upgrade_tool = memnew(SurfaceUpgradeTool);
run_surface_upgrade_tool = EditorSettings::get_singleton()->get_project_metadata("surface_upgrade_tool", "run_on_restart", false);
if (run_surface_upgrade_tool) {
SurfaceUpgradeTool::get_singleton()->begin_upgrade();
}
// Same for UID upgrade tool.
uid_upgrade_tool = memnew(UIDUpgradeTool);
run_uid_upgrade_tool = EditorSettings::get_singleton()->get_project_metadata(UIDUpgradeTool::META_UID_UPGRADE_TOOL, UIDUpgradeTool::META_RUN_ON_RESTART, false);
if (run_uid_upgrade_tool) {
UIDUpgradeTool::get_singleton()->begin_upgrade();
// Warm up the project upgrade tool as early as possible.
project_upgrade_tool = memnew(ProjectUpgradeTool);
run_project_upgrade_tool = EditorSettings::get_singleton()->get_project_metadata(project_upgrade_tool->META_PROJECT_UPGRADE_TOOL, project_upgrade_tool->META_RUN_ON_RESTART, false);
if (run_project_upgrade_tool) {
project_upgrade_tool->begin_upgrade();
}
{
@ -7518,8 +7472,7 @@ EditorNode::EditorNode() {
project_menu->add_submenu_node_item(TTR("Tools"), tool_menu);
tool_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/orphan_resource_explorer", TTRC("Orphan Resource Explorer...")), TOOLS_ORPHAN_RESOURCES);
tool_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/engine_compilation_configuration_editor", TTRC("Engine Compilation Configuration Editor...")), TOOLS_BUILD_PROFILE_MANAGER);
tool_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/upgrade_mesh_surfaces", TTRC("Upgrade Mesh Surfaces...")), TOOLS_SURFACE_UPGRADE);
tool_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/upgrade_uids", TTRC("Upgrade UIDs...")), TOOLS_UID_UPGRADE);
tool_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/upgrade_project", TTRC("Upgrade Project Files...")), TOOLS_PROJECT_UPGRADE);
project_menu->add_separator();
project_menu->add_shortcut(ED_SHORTCUT("editor/reload_current_project", TTRC("Reload Current Project")), PROJECT_RELOAD_CURRENT_PROJECT);
@ -7797,12 +7750,6 @@ EditorNode::EditorNode() {
orphan_resources = memnew(OrphanResourcesDialog);
gui_base->add_child(orphan_resources);
surface_upgrade_dialog = memnew(SurfaceUpgradeDialog);
gui_base->add_child(surface_upgrade_dialog);
uid_upgrade_dialog = memnew(UIDUpgradeDialog);
gui_base->add_child(uid_upgrade_dialog);
confirmation = memnew(ConfirmationDialog);
gui_base->add_child(confirmation);
confirmation->connect(SceneStringName(confirmed), callable_mp(this, &EditorNode::_menu_confirm_current));
@ -8196,8 +8143,7 @@ EditorNode::~EditorNode() {
memdelete(editor_plugins_force_over);
memdelete(editor_plugins_force_input_forwarding);
memdelete(progress_hb);
memdelete(surface_upgrade_tool);
memdelete(uid_upgrade_tool);
memdelete(project_upgrade_tool);
memdelete(editor_dock_manager);
EditorSettings::destroy();

View File

@ -97,10 +97,7 @@ class ProgressDialog;
class ProjectExportDialog;
class ProjectSettingsEditor;
class SceneImportSettingsDialog;
class SurfaceUpgradeTool;
class SurfaceUpgradeDialog;
class UIDUpgradeTool;
class UIDUpgradeDialog;
class ProjectUpgradeTool;
struct EditorProgress {
String task;
@ -166,8 +163,7 @@ public:
TOOLS_ORPHAN_RESOURCES,
TOOLS_BUILD_PROFILE_MANAGER,
TOOLS_SURFACE_UPGRADE,
TOOLS_UID_UPGRADE,
TOOLS_PROJECT_UPGRADE,
TOOLS_CUSTOM,
VCS_METADATA,
@ -226,7 +222,6 @@ public:
private:
friend class EditorSceneTabs;
friend class SurfaceUpgradeTool;
enum {
MAX_INIT_CALLBACKS = 128,
@ -460,16 +455,8 @@ private:
HashMap<String, Ref<Texture2D>> icon_type_cache;
SurfaceUpgradeTool *surface_upgrade_tool = nullptr;
SurfaceUpgradeDialog *surface_upgrade_dialog = nullptr;
bool run_surface_upgrade_tool = false;
UIDUpgradeTool *uid_upgrade_tool = nullptr;
UIDUpgradeDialog *uid_upgrade_dialog = nullptr;
bool run_uid_upgrade_tool = false;
bool should_prompt_uid_upgrade_tool = false;
ProjectUpgradeTool *project_upgrade_tool = nullptr;
bool run_project_upgrade_tool = false;
bool was_window_windowed_last = false;

View File

@ -0,0 +1,135 @@
/**************************************************************************/
/* project_upgrade_tool.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "project_upgrade_tool.h"
#include "core/io/dir_access.h"
#include "editor/editor_file_system.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/gui/editor_scene_tabs.h"
#include "editor/themes/editor_scale.h"
#include "scene/gui/dialogs.h"
void ProjectUpgradeTool::_add_files(EditorFileSystemDirectory *p_dir, Vector<String> &r_reimport_paths, Vector<String> &r_resave_scenes, Vector<String> &r_resave_resources) {
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
for (int i = 0; i < p_dir->get_file_count(); i++) {
const String path = p_dir->get_file_path(i);
const String ext = path.get_extension();
if (ext == "tscn" || ext == "scn") {
r_resave_scenes.append(path);
} else if (ext == "tres" || ext == "res") {
r_resave_resources.append(path);
} else if (da->file_exists(path + ".import")) {
r_reimport_paths.append(path);
}
}
for (int i = 0; i < p_dir->get_subdir_count(); i++) {
_add_files(p_dir->get_subdir(i), r_reimport_paths, r_resave_scenes, r_resave_resources);
}
}
void ProjectUpgradeTool::_bind_methods() {
ADD_SIGNAL(MethodInfo("upgrade_finished"));
}
void ProjectUpgradeTool::popup_dialog() {
if (!upgrade_dialog) {
upgrade_dialog = memnew(ConfirmationDialog);
upgrade_dialog->set_autowrap(true);
upgrade_dialog->set_text(TTRC("Different engine version may have minor differences in various Resources, like additional fields or removed properties. When upgrading the project to a new version, such changes can cause diffs when saving scenes or resources, or reimporting.\n\nThis tool ensures that such changes are performed all at once. It will:\n- Regenerate UID cache\n- Load and re-save every text/binary Resource\n- Reimport every importable Resource\n\nFull upgrade will take considerable amount of time, but afterwards saving/reimporting any scene/resource should not cause unintended changes."));
upgrade_dialog->get_ok_button()->set_text(TTRC("Restart & Upgrade"));
upgrade_dialog->get_label()->set_custom_minimum_size(Size2(750 * EDSCALE, 0));
EditorNode::get_singleton()->get_gui_base()->add_child(upgrade_dialog);
upgrade_dialog->connect(SceneStringName(confirmed), callable_mp(this, &ProjectUpgradeTool::prepare_upgrade));
}
upgrade_dialog->popup_centered();
}
void ProjectUpgradeTool::prepare_upgrade() {
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RUN_ON_RESTART, true);
Vector<String> reimport_paths;
Vector<String> resave_scenes;
Vector<String> resave_resources;
_add_files(EditorFileSystem::get_singleton()->get_filesystem(), reimport_paths, resave_scenes, resave_resources);
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_REIMPORT_PATHS, reimport_paths);
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RESAVE_SCENES, resave_scenes);
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RESAVE_RESOURCES, resave_resources);
// Delay to avoid deadlocks, since this dialog can be triggered by loading a scene.
callable_mp(EditorNode::get_singleton(), &EditorNode::restart_editor).call_deferred(false);
}
void ProjectUpgradeTool::begin_upgrade() {
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RUN_ON_RESTART, false);
DirAccess::remove_absolute("res://.godot/uid_cache.bin");
}
void ProjectUpgradeTool::finish_upgrade() {
EditorNode::get_singleton()->trigger_menu_option(EditorSceneTabs::SCENE_CLOSE_ALL, true);
Vector<String> paths = EditorSettings::get_singleton()->get_project_metadata(META_PROJECT_UPGRADE_TOOL, META_REIMPORT_PATHS, Vector<String>());
EditorFileSystem::get_singleton()->reimport_files(paths);
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_REIMPORT_PATHS, Variant());
{
paths = EditorSettings::get_singleton()->get_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RESAVE_SCENES, Vector<String>());
EditorProgress ep("uid_upgrade_resave", TTR("Updating Project Scenes"), paths.size());
int step = 0;
for (const String &file_path : paths) {
ep.step(TTR("Re-saving scene:") + " " + file_path, step++);
EditorNode::get_singleton()->load_scene(file_path);
EditorNode::get_singleton()->trigger_menu_option(EditorNode::FILE_SAVE_SCENE, true);
EditorNode::get_singleton()->trigger_menu_option(EditorNode::FILE_CLOSE, true);
}
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RESAVE_SCENES, Variant());
}
{
paths = EditorSettings::get_singleton()->get_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RESAVE_RESOURCES, Vector<String>());
EditorProgress ep("uid_upgrade_resave", TTR("Updating Project Resources"), paths.size());
int step = 0;
for (const String &file_path : paths) {
ep.step(TTR("Re-saving resource:") + " " + file_path, step++);
Ref<Resource> res = ResourceLoader::load(file_path, "", ResourceFormatLoader::CACHE_MODE_REPLACE);
if (res.is_valid()) {
ResourceSaver::save(res);
}
}
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RESAVE_RESOURCES, Variant());
}
emit_signal(UPGRADE_FINISHED);
}

View File

@ -1,5 +1,5 @@
/**************************************************************************/
/* surface_upgrade_tool.h */
/* project_upgrade_tool.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -30,50 +30,33 @@
#pragma once
#include "scene/gui/dialogs.h"
#include "core/object/class_db.h"
class ConfirmationDialog;
class EditorFileSystemDirectory;
class SurfaceUpgradeTool : public Object {
GDCLASS(SurfaceUpgradeTool, Object);
class ProjectUpgradeTool : public Object {
GDCLASS(ProjectUpgradeTool, Object);
static SurfaceUpgradeTool *singleton;
ConfirmationDialog *upgrade_dialog = nullptr;
Mutex mutex;
void _add_files(EditorFileSystemDirectory *p_dir, Vector<String> &r_reimport_paths, Vector<String> &r_resave_scenes, Vector<String> &r_resave_resources);
bool show_requested = false;
bool updating = false;
const String META_REIMPORT_PATHS = "reimport_paths";
const String META_RESAVE_SCENES = "resave_scenes";
const String META_RESAVE_RESOURCES = "resave_resources";
static void _try_show_popup();
void _show_popup();
void _add_files(EditorFileSystemDirectory *p_dir, Vector<String> &r_reimport_paths, Vector<String> &r_resave_paths);
public:
const String META_PROJECT_UPGRADE_TOOL = "project_upgrade_tool";
const String META_RUN_ON_RESTART = "run_on_restart";
const StringName UPGRADE_FINISHED = "upgrade_finished";
protected:
static void _bind_methods();
public:
static SurfaceUpgradeTool *get_singleton() { return singleton; }
bool is_show_requested() const { return show_requested; }
void show_popup() { _show_popup(); }
void popup_dialog();
void prepare_upgrade();
void begin_upgrade();
void finish_upgrade();
SurfaceUpgradeTool();
~SurfaceUpgradeTool();
};
class SurfaceUpgradeDialog : public ConfirmationDialog {
GDCLASS(SurfaceUpgradeDialog, ConfirmationDialog);
protected:
void _notification(int p_what);
public:
void popup_on_demand();
SurfaceUpgradeDialog();
};

View File

@ -1,202 +0,0 @@
/**************************************************************************/
/* surface_upgrade_tool.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "surface_upgrade_tool.h"
#include "editor/editor_file_system.h"
#include "editor/editor_log.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/gui/editor_scene_tabs.h"
#include "editor/gui/editor_toaster.h"
#include "editor/themes/editor_scale.h"
#include "servers/rendering_server.h"
SurfaceUpgradeTool *SurfaceUpgradeTool::singleton = nullptr;
void SurfaceUpgradeTool::_add_files(EditorFileSystemDirectory *p_dir, Vector<String> &r_reimport_paths, Vector<String> &r_resave_paths) {
for (int i = 0; i < p_dir->get_subdir_count(); i++) {
_add_files(p_dir->get_subdir(i), r_reimport_paths, r_resave_paths);
}
for (int i = 0; i < p_dir->get_file_count(); i++) {
if (p_dir->get_file_type(i) == "Mesh" ||
p_dir->get_file_type(i) == "ArrayMesh" ||
p_dir->get_file_type(i) == "PackedScene") {
if (FileAccess::exists(p_dir->get_file_path(i) + ".import")) {
r_reimport_paths.append(p_dir->get_file_path(i) + ".import");
} else {
r_resave_paths.append(p_dir->get_file_path(i));
}
}
}
}
void SurfaceUpgradeTool::_try_show_popup() {
if (singleton->show_requested || singleton->updating) {
return;
}
singleton->show_requested = true;
if (!EditorNode::get_singleton()->is_editor_ready()) {
// EditorNode may not be ready yet. It will call this tool when it is.
return;
}
if (EditorFileSystem::get_singleton()->is_importing()) {
EditorFileSystem::get_singleton()->connect("resources_reimported", callable_mp(singleton, &SurfaceUpgradeTool::_show_popup), CONNECT_ONE_SHOT);
} else {
singleton->_show_popup();
}
RS::get_singleton()->set_warn_on_surface_upgrade(false);
}
void SurfaceUpgradeTool::_show_popup() {
MutexLock lock(mutex);
if (!show_requested) {
return; // We only show the dialog if it was previously requested.
}
show_requested = false;
// These messages are supposed to be translated as they are critical to users migrating their projects.
const String confirmation_message = TTR("This project uses meshes with an outdated mesh format from previous Godot versions. The engine needs to update the format in order to use those meshes. Please use the 'Upgrade Mesh Surfaces' tool from the 'Project > Tools' menu. You can ignore this message and keep using outdated meshes, but keep in mind that this leads to increased load times every time you load the project.");
EditorNode::get_log()->add_message(confirmation_message, EditorLog::MSG_TYPE_WARNING);
const String toast_message = TTR("This project uses meshes with an outdated mesh format. Check the output log.");
EditorToaster::get_singleton()->popup_str(toast_message, EditorToaster::SEVERITY_WARNING);
}
void SurfaceUpgradeTool::prepare_upgrade() {
EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "run_on_restart", true);
Vector<String> reimport_paths;
Vector<String> resave_paths;
_add_files(EditorFileSystem::get_singleton()->get_filesystem(), reimport_paths, resave_paths);
EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "reimport_paths", reimport_paths);
EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "resave_paths", resave_paths);
// Delay to avoid deadlocks, since this dialog can be triggered by loading a scene.
callable_mp(EditorNode::get_singleton(), &EditorNode::restart_editor).call_deferred(false);
}
// Ensure that the warnings and popups are skipped.
void SurfaceUpgradeTool::begin_upgrade() {
updating = true;
EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "run_on_restart", false);
RS::get_singleton()->set_surface_upgrade_callback(nullptr);
RS::get_singleton()->set_warn_on_surface_upgrade(false);
}
void SurfaceUpgradeTool::finish_upgrade() {
EditorNode::get_singleton()->trigger_menu_option(EditorSceneTabs::SCENE_CLOSE_ALL, true);
// Update all meshes here.
Vector<String> resave_paths = EditorSettings::get_singleton()->get_project_metadata("surface_upgrade_tool", "resave_paths", Vector<String>());
Vector<String> reimport_paths = EditorSettings::get_singleton()->get_project_metadata("surface_upgrade_tool", "reimport_paths", Vector<String>());
EditorProgress ep("surface_upgrade_resave", TTR("Upgrading All Meshes in Project"), resave_paths.size() + reimport_paths.size());
int step = 0;
for (const String &file_path : resave_paths) {
Ref<Resource> res = ResourceLoader::load(file_path);
ep.step(TTR("Attempting to re-save ") + file_path, step++);
if (res.is_valid()) {
// Ignore things that fail to load.
ResourceSaver::save(res);
}
}
EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "resave_paths", Vector<String>());
// Remove the imported scenes/meshes from .import so they will be reimported automatically after this.
for (const String &file_path : reimport_paths) {
Ref<ConfigFile> config;
config.instantiate();
Error err = config->load(file_path);
if (err != OK) {
ERR_PRINT("Could not open " + file_path + " for upgrade.");
continue;
}
String remap_path = config->get_value("remap", "path", "");
if (remap_path.is_empty()) {
continue;
}
ep.step(TTR("Attempting to remove ") + remap_path, step++);
String path = OS::get_singleton()->get_resource_dir() + remap_path.replace_first("res://", "/");
print_verbose("Moving to trash: " + path);
err = OS::get_singleton()->move_to_trash(path);
if (err != OK) {
EditorNode::get_singleton()->add_io_error(TTR("Cannot remove:") + "\n" + remap_path + "\n");
}
}
EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "reimport_paths", Vector<String>());
emit_signal(SNAME("upgrade_finished"));
}
void SurfaceUpgradeTool::_bind_methods() {
ADD_SIGNAL(MethodInfo("upgrade_finished"));
}
SurfaceUpgradeTool::SurfaceUpgradeTool() {
singleton = this;
RS::get_singleton()->set_surface_upgrade_callback(_try_show_popup);
}
SurfaceUpgradeTool::~SurfaceUpgradeTool() {
singleton = nullptr;
}
void SurfaceUpgradeDialog::popup_on_demand() {
const String confirmation_message = TTR("The mesh format has changed in Godot 4.2, which affects both imported meshes and meshes authored inside of Godot. The engine needs to update the format in order to use those meshes.\n\nIf your project predates Godot 4.2 and contains meshes, we recommend you run this one time conversion tool. This update will restart the editor and may take several minutes. Upgrading will make the meshes incompatible with previous versions of Godot.\n\nYou can still use your existing meshes as is. The engine will update each mesh in memory, but the update will not be saved. Choosing this option will lead to slower load times every time this project is loaded.");
set_text(confirmation_message);
get_ok_button()->set_text(TTR("Restart & Upgrade"));
popup_centered(Size2(750 * EDSCALE, 0));
}
void SurfaceUpgradeDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY:
// Can't do it in the constructor because it doesn't know that the signal exists.
connect(SceneStringName(confirmed), callable_mp(SurfaceUpgradeTool::get_singleton(), &SurfaceUpgradeTool::prepare_upgrade));
break;
}
}
SurfaceUpgradeDialog::SurfaceUpgradeDialog() {
set_autowrap(true);
get_label()->set_custom_minimum_size(Size2(750 * EDSCALE, 0));
}

View File

@ -1,126 +0,0 @@
/**************************************************************************/
/* uid_upgrade_tool.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "uid_upgrade_tool.h"
#include "editor/editor_file_system.h"
#include "editor/editor_log.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/gui/editor_scene_tabs.h"
#include "editor/gui/editor_toaster.h"
#include "editor/themes/editor_scale.h"
#include "servers/rendering_server.h"
void UIDUpgradeTool::_add_files(EditorFileSystemDirectory *p_dir, Vector<String> &r_resave_paths) {
for (int i = 0; i < p_dir->get_subdir_count(); i++) {
_add_files(p_dir->get_subdir(i), r_resave_paths);
}
for (int i = 0; i < p_dir->get_file_count(); i++) {
if (p_dir->get_file_type(i) == "PackedScene" || p_dir->get_file_type(i) == "Resource") {
r_resave_paths.append(p_dir->get_file_path(i));
}
}
}
void UIDUpgradeTool::prepare_upgrade() {
EditorSettings::get_singleton()->set_project_metadata(META_UID_UPGRADE_TOOL, META_RUN_ON_RESTART, true);
Vector<String> resave_paths;
_add_files(EditorFileSystem::get_singleton()->get_filesystem(), resave_paths);
EditorSettings::get_singleton()->set_project_metadata(META_UID_UPGRADE_TOOL, META_RESAVE_PATHS, resave_paths);
// Delay to avoid deadlocks, since this dialog can be triggered by loading a scene.
callable_mp(EditorNode::get_singleton(), &EditorNode::restart_editor).call_deferred(false);
}
void UIDUpgradeTool::begin_upgrade() {
EditorSettings::get_singleton()->set_project_metadata(META_UID_UPGRADE_TOOL, META_RUN_ON_RESTART, false);
}
void UIDUpgradeTool::finish_upgrade() {
EditorNode::get_singleton()->trigger_menu_option(EditorSceneTabs::SCENE_CLOSE_ALL, true);
Vector<String> resave_paths = EditorSettings::get_singleton()->get_project_metadata(META_UID_UPGRADE_TOOL, META_RESAVE_PATHS, Variant());
EditorProgress ep("uid_upgrade_resave", TTR("Updating Script UIDs"), resave_paths.size());
int step = 0;
for (const String &file_path : resave_paths) {
Ref<Resource> res = ResourceLoader::load(file_path, "", ResourceFormatLoader::CACHE_MODE_REPLACE);
ep.step(TTR("Attempting to re-save ") + file_path, step++);
if (res.is_valid()) {
ResourceSaver::save(res);
}
}
EditorSettings::get_singleton()->set_project_metadata(META_UID_UPGRADE_TOOL, META_RESAVE_PATHS, Vector<String>());
emit_signal(SNAME(UPGRADE_FINISHED));
}
void UIDUpgradeTool::_bind_methods() {
ADD_SIGNAL(MethodInfo(UPGRADE_FINISHED));
}
UIDUpgradeTool::UIDUpgradeTool() {
singleton = this;
}
UIDUpgradeTool::~UIDUpgradeTool() {
singleton = nullptr;
}
void UIDUpgradeDialog::popup_on_demand() {
const String confirmation_message = TTR("As of Godot 4.4, scenes and resources use UIDs to reference scripts and shaders.\n\nNormally, this update is applied to a single scene or resource once you save it in Godot 4.4 for the first time. If you have a lot of scenes and/or resources, doing this manually may be time-consuming. This tool will update all of the project's scenes and resources at once.\n\nClick \"Restart & Upgrade\" to restart the editor and update all of the scenes and resources in this project. Depending on the project size, it may take several minutes.\n\nNote: Please make sure you have your project backed up before running the tool, to avoid the possibility of data loss. Additionally, make sure to commit all .uid files into version control (and do not add them to ignore-lists like .gitignore).");
set_text(confirmation_message);
get_ok_button()->set_text("Restart & Upgrade");
popup_centered(Size2(750 * EDSCALE, 0));
}
void UIDUpgradeDialog::_on_custom_action(const String &p_action) {
if (p_action == UID_UPGRADE_LEARN_MORE) {
OS::get_singleton()->shell_open("https://godotengine.org/article/uid-changes-coming-to-godot-4-4/");
}
}
void UIDUpgradeDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY:
connect(SceneStringName(confirmed), callable_mp(UIDUpgradeTool::get_singleton(), &UIDUpgradeTool::prepare_upgrade));
connect(SNAME("custom_action"), callable_mp(this, &UIDUpgradeDialog::_on_custom_action));
break;
}
}
UIDUpgradeDialog::UIDUpgradeDialog() {
set_autowrap(true);
get_label()->set_custom_minimum_size(Size2(750 * EDSCALE, 0));
learn_more_button = add_button(TTR("Learn More"), true, UID_UPGRADE_LEARN_MORE);
}

View File

@ -1,79 +0,0 @@
/**************************************************************************/
/* uid_upgrade_tool.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#pragma once
#include "scene/gui/dialogs.h"
class EditorFileSystemDirectory;
class UIDUpgradeTool : public Object {
GDCLASS(UIDUpgradeTool, Object);
inline static UIDUpgradeTool *singleton = nullptr;
static constexpr const char *UPGRADE_FINISHED = "upgrade_finished";
static constexpr const char *META_RESAVE_PATHS = "resave_paths";
void _add_files(EditorFileSystemDirectory *p_dir, Vector<String> &r_resave_paths);
protected:
static void _bind_methods();
public:
static constexpr const char *META_UID_UPGRADE_TOOL = "uid_upgrade_tool";
static constexpr const char *META_RUN_ON_RESTART = "run_on_restart";
static UIDUpgradeTool *get_singleton() { return singleton; }
void prepare_upgrade();
void begin_upgrade();
void finish_upgrade();
UIDUpgradeTool();
~UIDUpgradeTool();
};
class UIDUpgradeDialog : public ConfirmationDialog {
GDCLASS(UIDUpgradeDialog, ConfirmationDialog);
static constexpr const char *UID_UPGRADE_LEARN_MORE = "uid_upgrade_learn_more";
Button *learn_more_button = nullptr;
protected:
void _on_custom_action(const String &p_action);
void _notification(int p_what);
public:
void popup_on_demand();
UIDUpgradeDialog();
};