diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 119e684f1e8f..6012ff1f70a1 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -3048,6 +3048,9 @@ void EditorNode::_tool_menu_option(int p_idx) { case TOOLS_ORPHAN_RESOURCES: { orphan_resources->show(); } break; + case TOOLS_SURFACE_UPGRADE: { + surface_upgrade_dialog->popup_centered(Size2(750 * EDSCALE, 0)); + } break; case TOOLS_CUSTOM: { if (tool_menu->get_item_submenu(p_idx) == "") { Callable callback = tool_menu->get_item_metadata(p_idx); @@ -4671,6 +4674,10 @@ Error EditorNode::export_preset(const String &p_preset, const String &p_path, bo return OK; } +bool EditorNode::is_project_exporting() const { + return project_export && project_export->is_exporting(); +} + void EditorNode::show_accept(const String &p_text, const String &p_title) { current_menu_option = -1; if (accept) { @@ -7429,6 +7436,7 @@ EditorNode::EditorNode() { project_menu->add_child(tool_menu); project_menu->add_submenu_item(TTR("Tools"), "Tools"); tool_menu->add_item(TTR("Orphan Resource Explorer..."), TOOLS_ORPHAN_RESOURCES); + tool_menu->add_item(TTR("Upgrade Mesh Surfaces..."), TOOLS_SURFACE_UPGRADE); project_menu->add_separator(); project_menu->add_shortcut(ED_SHORTCUT("editor/reload_current_project", TTR("Reload Current Project")), RELOAD_CURRENT_PROJECT); @@ -7768,6 +7776,9 @@ EditorNode::EditorNode() { orphan_resources = memnew(OrphanResourcesDialog); gui_base->add_child(orphan_resources); + surface_upgrade_dialog = memnew(SurfaceUpgradeDialog); + gui_base->add_child(surface_upgrade_dialog); + confirmation = memnew(ConfirmationDialog); gui_base->add_child(confirmation); confirmation->connect("confirmed", callable_mp(this, &EditorNode::_menu_confirm_current)); diff --git a/editor/editor_node.h b/editor/editor_node.h index 0ee2330927c8..d4a8fc9aa8b3 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -114,6 +114,7 @@ class RunSettingsDialog; class SceneImportSettings; class ScriptCreateDialog; class SurfaceUpgradeTool; +class SurfaceUpgradeDialog; class WindowWrapper; class EditorNode : public Node { @@ -192,6 +193,7 @@ class EditorNode : public Node { EDIT_RELOAD_SAVED_SCENE, TOOLS_ORPHAN_RESOURCES, TOOLS_BUILD_PROFILE_MANAGER, + TOOLS_SURFACE_UPGRADE, TOOLS_CUSTOM, RESOURCE_SAVE, RESOURCE_SAVE_AS, @@ -496,6 +498,7 @@ class EditorNode : public Node { HashMap> icon_type_cache; SurfaceUpgradeTool *surface_upgrade_tool = nullptr; + SurfaceUpgradeDialog *surface_upgrade_dialog = nullptr; bool run_surface_upgrade_tool = false; static EditorBuildCallback build_callbacks[MAX_BUILD_CALLBACKS]; @@ -875,6 +878,7 @@ class EditorNode : public Node { void _copy_warning(const String &p_str); Error export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only); + bool is_project_exporting() const; Control *get_gui_base() { return gui_base; } diff --git a/editor/export/project_export.cpp b/editor/export/project_export.cpp index 05f012e5fb0c..719c3114f4b9 100644 --- a/editor/export/project_export.cpp +++ b/editor/export/project_export.cpp @@ -1076,11 +1076,13 @@ void ProjectExportDialog::_export_project_to_path(const String &p_path) { EditorSettings::get_singleton()->set_project_metadata("export_options", "default_filename", default_filename); Ref current = get_current_preset(); - ERR_FAIL_COND(current.is_null()); + ERR_FAIL_COND_MSG(current.is_null(), "Failed to start the export: current preset is invalid."); Ref platform = current->get_platform(); - ERR_FAIL_COND(platform.is_null()); + ERR_FAIL_COND_MSG(platform.is_null(), "Failed to start the export: current preset has no valid platform."); current->set_export_path(p_path); + exporting = true; + platform->clear_messages(); Error err = platform->export_project(current, export_debug->is_pressed(), current->get_export_path(), 0); result_dialog_log->clear(); @@ -1089,6 +1091,8 @@ void ProjectExportDialog::_export_project_to_path(const String &p_path) { result_dialog->popup_centered_ratio(0.5); } } + + exporting = false; } void ProjectExportDialog::_export_all_dialog() { @@ -1108,19 +1112,29 @@ void ProjectExportDialog::_export_all(bool p_debug) { String export_target = p_debug ? TTR("Debug") : TTR("Release"); EditorProgress ep("exportall", TTR("Exporting All") + " " + export_target, EditorExport::get_singleton()->get_export_preset_count(), true); + exporting = true; + bool show_dialog = false; result_dialog_log->clear(); for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) { Ref preset = EditorExport::get_singleton()->get_export_preset(i); - ERR_FAIL_COND(preset.is_null()); + if (preset.is_null()) { + exporting = false; + ERR_FAIL_MSG("Failed to start the export: one of the presets is invalid."); + } + Ref platform = preset->get_platform(); - ERR_FAIL_COND(platform.is_null()); + if (platform.is_null()) { + exporting = false; + ERR_FAIL_MSG("Failed to start the export: one of the presets has no valid platform."); + } ep.step(preset->get_name(), i); platform->clear_messages(); Error err = platform->export_project(preset, p_debug, preset->get_export_path(), 0); if (err == ERR_SKIP) { + exporting = false; return; } bool has_messages = platform->fill_log_messages(result_dialog_log, err); @@ -1129,6 +1143,8 @@ void ProjectExportDialog::_export_all(bool p_debug) { if (show_dialog) { result_dialog->popup_centered_ratio(0.5); } + + exporting = false; } void ProjectExportDialog::_bind_methods() { diff --git a/editor/export/project_export.h b/editor/export/project_export.h index 219f45f59b3d..30f6812acbdd 100644 --- a/editor/export/project_export.h +++ b/editor/export/project_export.h @@ -70,7 +70,6 @@ class ProjectExportTextureFormatError : public HBoxContainer { class ProjectExportDialog : public ConfirmationDialog { GDCLASS(ProjectExportDialog, ConfirmationDialog); -private: TabContainer *sections = nullptr; MenuButton *add_preset = nullptr; @@ -118,6 +117,8 @@ class ProjectExportDialog : public ConfirmationDialog { String default_filename; + bool exporting = false; + void _runnable_pressed(); void _update_parameters(const String &p_edited_property); void _name_changed(const String &p_string); @@ -199,6 +200,8 @@ class ProjectExportDialog : public ConfirmationDialog { Ref get_current_preset() const; + bool is_exporting() const { return exporting; }; + ProjectExportDialog(); ~ProjectExportDialog(); }; diff --git a/editor/surface_upgrade_tool.cpp b/editor/surface_upgrade_tool.cpp index 2294ff22e58e..cd202ade6c33 100644 --- a/editor/surface_upgrade_tool.cpp +++ b/editor/surface_upgrade_tool.cpp @@ -32,6 +32,7 @@ #include "editor/editor_file_system.h" #include "editor/editor_node.h" +#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "scene/scene_string_names.h" #include "servers/rendering_server.h" @@ -75,30 +76,38 @@ void SurfaceUpgradeTool::_try_show_popup() { void SurfaceUpgradeTool::_show_popup() { MutexLock lock(mutex); + if (EditorNode::get_singleton()->is_project_exporting()) { + return; // We suppress the tool during the export routine, because the immediate dialog breaks everything. + } if (!show_requested || popped_up) { return; } show_requested = false; popped_up = true; - bool accepted = EditorNode::immediate_confirmation_dialog(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.\n\nPress 'Restart & Upgrade' to run the surface upgrade tool which will update and re-save all meshes and scenes. This update will restart the editor and may take several minutes. Upgrading will make the meshes incompatible with previous versions of Godot.\n\nPress 'Upgrade Only' to continue opening the scene as normal. 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."), TTR("Restart & Upgrade"), TTR("Upgrade Only"), 500); + 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.\n\nPress 'Restart & Upgrade' to run the surface upgrade tool which will update and re-save all meshes and scenes. This update will restart the editor and may take several minutes. Upgrading will make the meshes incompatible with previous versions of Godot.\n\nPress 'Upgrade Only' to continue opening the scene as normal. 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."); + bool accepted = EditorNode::immediate_confirmation_dialog(confirmation_message, TTR("Restart & Upgrade"), TTR("Upgrade Only"), 500); if (accepted) { - EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "run_on_restart", true); - - Vector reimport_paths; - Vector 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. - MessageQueue::get_singleton()->push_callable(callable_mp(EditorNode::get_singleton(), &EditorNode::restart_editor)); + prepare_upgrade(); } else { RS::get_singleton()->set_warn_on_surface_upgrade(true); } } +void SurfaceUpgradeTool::prepare_upgrade() { + EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "run_on_restart", true); + + Vector reimport_paths; + Vector 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. + MessageQueue::get_singleton()->push_callable(callable_mp(EditorNode::get_singleton(), &EditorNode::restart_editor)); +} + // Ensure that the warnings and popups are skipped. void SurfaceUpgradeTool::begin_upgrade() { EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "run_on_restart", false); @@ -162,3 +171,19 @@ SurfaceUpgradeTool::SurfaceUpgradeTool() { } SurfaceUpgradeTool::~SurfaceUpgradeTool() {} + +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("confirmed", callable_mp(SurfaceUpgradeTool::get_singleton(), &SurfaceUpgradeTool::prepare_upgrade)); + break; + } +} + +SurfaceUpgradeDialog::SurfaceUpgradeDialog() { + 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); + set_autowrap(true); + get_label()->set_custom_minimum_size(Size2(750 * EDSCALE, 0)); +} diff --git a/editor/surface_upgrade_tool.h b/editor/surface_upgrade_tool.h index 70e07c58a122..ae2b90decd83 100644 --- a/editor/surface_upgrade_tool.h +++ b/editor/surface_upgrade_tool.h @@ -31,7 +31,7 @@ #ifndef SURFACE_UPGRADE_TOOL_H #define SURFACE_UPGRADE_TOOL_H -#include "scene/main/node.h" +#include "scene/gui/dialogs.h" class EditorFileSystemDirectory; @@ -57,6 +57,7 @@ class SurfaceUpgradeTool : public Object { bool is_show_requested() const { return show_requested; }; void show_popup() { _show_popup(); } + void prepare_upgrade(); void begin_upgrade(); void finish_upgrade(); @@ -64,4 +65,14 @@ class SurfaceUpgradeTool : public Object { ~SurfaceUpgradeTool(); }; +class SurfaceUpgradeDialog : public ConfirmationDialog { + GDCLASS(SurfaceUpgradeDialog, ConfirmationDialog); + +protected: + void _notification(int p_what); + +public: + SurfaceUpgradeDialog(); +}; + #endif // SURFACE_UPGRADE_TOOL_H