diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_export.cpp | 114 | ||||
-rw-r--r-- | editor/editor_export.h | 59 | ||||
-rw-r--r-- | editor/editor_node.cpp | 17 | ||||
-rw-r--r-- | editor/editor_run_native.cpp | 17 | ||||
-rw-r--r-- | editor/editor_run_native.h | 5 | ||||
-rw-r--r-- | editor/project_export.cpp | 46 | ||||
-rw-r--r-- | editor/project_export.h | 3 |
7 files changed, 213 insertions, 48 deletions
diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index f4a81521df..bb9d930cf5 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -46,6 +46,7 @@ #include "editor/editor_file_system.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" +#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/plugins/script_editor_plugin.h" #include "scene/resources/resource_format_text.h" @@ -252,6 +253,83 @@ String EditorExportPreset::get_script_encryption_key() const { /////////////////////////////////// +bool EditorExportPlatform::fill_log_messages(RichTextLabel *p_log, Error p_err) { + bool has_messages = false; + + int msg_count = get_message_count(); + + p_log->add_text(TTR("Project export for platform:") + " "); + p_log->add_image(get_logo(), 16 * EDSCALE, 16 * EDSCALE, Color(1.0, 1.0, 1.0), INLINE_ALIGNMENT_CENTER); + p_log->add_text(" "); + p_log->add_text(get_name()); + p_log->add_text(" - "); + if (p_err == OK) { + if (get_worst_message_type() >= EditorExportPlatform::EXPORT_MESSAGE_WARNING) { + p_log->add_image(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons")), 16 * EDSCALE, 16 * EDSCALE, Color(1.0, 1.0, 1.0), INLINE_ALIGNMENT_CENTER); + p_log->add_text(" "); + p_log->add_text(TTR("Completed with errors.")); + has_messages = true; + } else { + p_log->add_image(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("StatusSuccess"), SNAME("EditorIcons")), 16 * EDSCALE, 16 * EDSCALE, Color(1.0, 1.0, 1.0), INLINE_ALIGNMENT_CENTER); + p_log->add_text(" "); + p_log->add_text(TTR("Completed sucessfully.")); + if (msg_count > 0) { + has_messages = true; + } + } + } else { + p_log->add_image(EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("StatusError"), SNAME("EditorIcons")), 16 * EDSCALE, 16 * EDSCALE, Color(1.0, 1.0, 1.0), INLINE_ALIGNMENT_CENTER); + p_log->add_text(" "); + p_log->add_text(TTR("Failed.")); + has_messages = true; + } + p_log->add_newline(); + + if (msg_count) { + p_log->push_table(2); + p_log->set_table_column_expand(0, false); + p_log->set_table_column_expand(1, true); + for (int m = 0; m < msg_count; m++) { + EditorExportPlatform::ExportMessage msg = get_message(m); + Color color = EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("font_color"), SNAME("Label")); + Ref<Texture> icon; + + switch (msg.msg_type) { + case EditorExportPlatform::EXPORT_MESSAGE_INFO: { + color = EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("font_color"), SNAME("Editor")) * Color(1, 1, 1, 0.6); + } break; + case EditorExportPlatform::EXPORT_MESSAGE_WARNING: { + icon = EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Warning"), SNAME("EditorIcons")); + color = EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("warning_color"), SNAME("Editor")); + } break; + case EditorExportPlatform::EXPORT_MESSAGE_ERROR: { + icon = EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("Error"), SNAME("EditorIcons")); + color = EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("error_color"), SNAME("Editor")); + } break; + default: + break; + } + + p_log->push_cell(); + p_log->add_text("\t"); + if (icon.is_valid()) { + p_log->add_image(icon); + } + p_log->pop(); + + p_log->push_cell(); + p_log->push_color(color); + p_log->add_text(vformat("[%s]: %s", msg.category, msg.text)); + p_log->pop(); + p_log->pop(); + } + p_log->pop(); + p_log->add_newline(); + } + p_log->add_newline(); + return has_messages; +} + void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags) { String host = EditorSettings::get_singleton()->get("network/debug/remote_host"); int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); @@ -1134,7 +1212,10 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b String tmppath = EditorPaths::get_singleton()->get_cache_dir().plus_file("packtmp"); Ref<FileAccess> ftmp = FileAccess::open(tmppath, FileAccess::WRITE); - ERR_FAIL_COND_V_MSG(ftmp.is_null(), ERR_CANT_CREATE, "Cannot create file '" + tmppath + "'."); + if (ftmp.is_null()) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Save PCK"), vformat(TTR("Cannot create file \"%s\"."), tmppath)); + return ERR_CANT_CREATE; + } PackData pd; pd.ep = &ep; @@ -1149,7 +1230,7 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b if (err != OK) { DirAccess::remove_file_or_error(tmppath); - ERR_PRINT("Failed to export project files"); + add_message(EXPORT_MESSAGE_ERROR, TTR("Save PCK"), TTR("Failed to export project files.")); return err; } @@ -1162,14 +1243,16 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b f = FileAccess::open(p_path, FileAccess::WRITE); if (f.is_null()) { DirAccess::remove_file_or_error(tmppath); - ERR_FAIL_V(ERR_CANT_CREATE); + add_message(EXPORT_MESSAGE_ERROR, TTR("Save PCK"), vformat(TTR("Can't open file to read from path \"%s\"."), tmppath)); + return ERR_CANT_CREATE; } } else { // Append to executable f = FileAccess::open(p_path, FileAccess::READ_WRITE); if (f.is_null()) { DirAccess::remove_file_or_error(tmppath); - ERR_FAIL_V(ERR_FILE_CANT_OPEN); + add_message(EXPORT_MESSAGE_ERROR, TTR("Save PCK"), vformat(TTR("Can't open executable file from path \"%s\"."), tmppath)); + return ERR_FILE_CANT_OPEN; } f->seek_end(); @@ -1245,10 +1328,16 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b } } fae.instantiate(); - ERR_FAIL_COND_V(fae.is_null(), ERR_SKIP); + if (fae.is_null()) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Save PCK"), TTR("Can't create encrypted file.")); + return ERR_CANT_CREATE; + } err = fae->open_and_parse(f, key, FileAccessEncrypted::MODE_WRITE_AES256, false); - ERR_FAIL_COND_V(err != OK, ERR_SKIP); + if (err != OK) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Save PCK"), TTR("Can't open encrypted file to write.")); + return ERR_CANT_CREATE; + } fhead = fae; } @@ -1293,7 +1382,8 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b ftmp = FileAccess::open(tmppath, FileAccess::READ); if (ftmp.is_null()) { DirAccess::remove_file_or_error(tmppath); - ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't open file to read from path '" + String(tmppath) + "'."); + add_message(EXPORT_MESSAGE_ERROR, TTR("Save PCK"), vformat(TTR("Can't open file to read from path \"%s\"."), tmppath)); + return ERR_CANT_CREATE; } const int bufsize = 16384; @@ -1344,7 +1434,7 @@ Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, bo Error err = export_project_files(p_preset, p_debug, _save_zip_file, &zd); if (err != OK && err != ERR_SKIP) { - ERR_PRINT("Failed to export project files"); + add_message(EXPORT_MESSAGE_ERROR, TTR("Save ZIP"), TTR("Failed to export project files.")); } zipClose(zip, nullptr); @@ -1835,6 +1925,7 @@ Error EditorExportPlatformPC::export_project(const Ref<EditorExportPreset> &p_pr Error EditorExportPlatformPC::prepare_template(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) { if (!DirAccess::exists(p_path.get_base_dir())) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Template"), TTR("The given export path doesn't exist.")); return ERR_FILE_BAD_PATH; } @@ -1850,13 +1941,16 @@ Error EditorExportPlatformPC::prepare_template(const Ref<EditorExportPreset> &p_ } if (!template_path.is_empty() && !FileAccess::exists(template_path)) { - EditorNode::get_singleton()->show_warning(TTR("Template file not found:") + "\n" + template_path); + add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Template"), vformat(TTR("Template file not found: \"%s\"."), template_path)); return ERR_FILE_NOT_FOUND; } Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); da->make_dir_recursive(p_path.get_base_dir()); Error err = da->copy(template_path, p_path, get_chmod_flags()); + if (err != OK) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Template"), TTR("Failed to copy export template.")); + } return err; } @@ -1876,7 +1970,7 @@ Error EditorExportPlatformPC::export_project_data(const Ref<EditorExportPreset> Error err = save_pack(p_preset, p_debug, pck_path, &so_files, p_preset->get("binary_format/embed_pck"), &embedded_pos, &embedded_size); if (err == OK && p_preset->get("binary_format/embed_pck")) { if (embedded_size >= 0x100000000 && !p_preset->get("binary_format/64_bits")) { - EditorNode::get_singleton()->show_warning(TTR("On 32-bit exports the embedded PCK cannot be bigger than 4 GiB.")); + add_message(EXPORT_MESSAGE_ERROR, TTR("PCK Embedding"), TTR("On 32-bit exports the embedded PCK cannot be bigger than 4 GiB.")); return ERR_INVALID_PARAMETER; } diff --git a/editor/editor_export.h b/editor/editor_export.h index daf6d8ef23..6f41736d2d 100644 --- a/editor/editor_export.h +++ b/editor/editor_export.h @@ -33,6 +33,7 @@ #include "core/io/dir_access.h" #include "core/io/resource.h" +#include "scene/gui/rich_text_label.h" #include "scene/main/node.h" #include "scene/main/timer.h" #include "scene/resources/texture.h" @@ -170,6 +171,19 @@ public: typedef Error (*EditorExportSaveFunction)(void *p_userdata, const String &p_path, const Vector<uint8_t> &p_data, int p_file, int p_total, const Vector<String> &p_enc_in_filters, const Vector<String> &p_enc_ex_filters, const Vector<uint8_t> &p_key); typedef Error (*EditorExportSaveSharedObject)(void *p_userdata, const SharedObject &p_so); + enum ExportMessageType { + EXPORT_MESSAGE_NONE, + EXPORT_MESSAGE_INFO, + EXPORT_MESSAGE_WARNING, + EXPORT_MESSAGE_ERROR, + }; + + struct ExportMessage { + ExportMessageType msg_type; + String category; + String text; + }; + private: struct SavedData { uint64_t ofs = 0; @@ -200,6 +214,8 @@ private: Vector<String> features_pv; }; + Vector<ExportMessage> messages; + void _export_find_resources(EditorFileSystemDirectory *p_dir, HashSet<String> &p_paths); void _export_find_dependencies(const String &p_path, HashSet<String> &p_paths); @@ -240,6 +256,47 @@ public: virtual Ref<EditorExportPreset> create_preset(); + virtual void clear_messages() { messages.clear(); } + virtual void add_message(ExportMessageType p_type, const String &p_category, const String &p_message) { + ExportMessage msg; + msg.category = p_category; + msg.text = p_message; + msg.msg_type = p_type; + messages.push_back(msg); + switch (p_type) { + case EXPORT_MESSAGE_INFO: { + print_line(vformat("%s: %s\n", msg.category, msg.text)); + } break; + case EXPORT_MESSAGE_WARNING: { + WARN_PRINT(vformat("%s: %s\n", msg.category, msg.text)); + } break; + case EXPORT_MESSAGE_ERROR: { + ERR_PRINT(vformat("%s: %s\n", msg.category, msg.text)); + } break; + default: + break; + } + } + + virtual int get_message_count() const { + return messages.size(); + } + + virtual ExportMessage get_message(int p_index) const { + ERR_FAIL_INDEX_V(p_index, messages.size(), ExportMessage()); + return messages[p_index]; + } + + virtual ExportMessageType get_worst_message_type() const { + ExportMessageType worst_type = EXPORT_MESSAGE_NONE; + for (int i = 0; i < messages.size(); i++) { + worst_type = MAX(worst_type, messages[i].msg_type); + } + return worst_type; + } + + virtual bool fill_log_messages(RichTextLabel *p_log, Error p_err); + virtual void get_export_options(List<ExportOption> *r_options) = 0; virtual bool should_update_export_options() { return false; } virtual bool get_export_option_visibility(const String &p_option, const HashMap<StringName, Variant> &p_options) const { return true; } @@ -459,7 +516,7 @@ public: int get_chmod_flags() const; void set_chmod_flags(int p_flags); - virtual Error fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size) const { + virtual Error fixup_embedded_pck(const String &p_path, int64_t p_embedded_start, int64_t p_embedded_size) { return Error::OK; } }; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index e23c36c1d4..61f8ab1936 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -968,21 +968,14 @@ void EditorNode::_fs_changed() { ERR_PRINT(vformat("Cannot export project with preset \"%s\" due to configuration errors:\n%s", preset_name, config_error)); err = missing_templates ? ERR_FILE_NOT_FOUND : ERR_UNCONFIGURED; } else { + platform->clear_messages(); err = platform->export_project(export_preset, export_defer.debug, export_path); } } - switch (err) { - case OK: - break; - case ERR_FILE_NOT_FOUND: - export_error = vformat("Project export failed for preset \"%s\". The export template appears to be missing.", preset_name); - break; - case ERR_FILE_BAD_PATH: - export_error = vformat("Project export failed for preset \"%s\". The target path \"%s\" appears to be invalid.", preset_name, export_path); - break; - default: - export_error = vformat("Project export failed with error code %d for preset \"%s\".", (int)err, preset_name); - break; + if (err != OK) { + export_error = vformat("Project export for preset \"%s\" failed.", preset_name); + } else if (platform->get_worst_message_type() >= EditorExportPlatform::EXPORT_MESSAGE_WARNING) { + export_error = vformat("Project export for preset \"%s\" completed with errors.", preset_name); } } } diff --git a/editor/editor_run_native.cpp b/editor/editor_run_native.cpp index 5db7b8673f..6ce9e5fa6f 100644 --- a/editor/editor_run_native.cpp +++ b/editor/editor_run_native.cpp @@ -151,7 +151,13 @@ Error EditorRunNative::run_native(int p_idx, int p_platform) { flags |= EditorExportPlatform::DEBUG_FLAG_VIEW_NAVIGATION; } - return eep->run(preset, p_idx, flags); + eep->clear_messages(); + Error err = eep->run(preset, p_idx, flags); + result_dialog_log->clear(); + if (eep->fill_log_messages(result_dialog_log, err)) { + result_dialog->popup_centered_ratio(0.5); + } + return err; } void EditorRunNative::resume_run_native() { @@ -167,6 +173,15 @@ bool EditorRunNative::is_deploy_debug_remote_enabled() const { } EditorRunNative::EditorRunNative() { + result_dialog = memnew(AcceptDialog); + result_dialog->set_title(TTR("Project Run")); + result_dialog_log = memnew(RichTextLabel); + result_dialog_log->set_custom_minimum_size(Size2(300, 80) * EDSCALE); + result_dialog->add_child(result_dialog_log); + + add_child(result_dialog); + result_dialog->hide(); + set_process(true); resume_idx = 0; resume_platform = 0; diff --git a/editor/editor_run_native.h b/editor/editor_run_native.h index 798a0371a4..66d9b0402a 100644 --- a/editor/editor_run_native.h +++ b/editor/editor_run_native.h @@ -32,11 +32,16 @@ #define EDITOR_RUN_NATIVE_H #include "scene/gui/box_container.h" +#include "scene/gui/dialogs.h" #include "scene/gui/menu_button.h" +#include "scene/gui/rich_text_label.h" class EditorRunNative : public HBoxContainer { GDCLASS(EditorRunNative, HBoxContainer); + RichTextLabel *result_dialog_log = nullptr; + AcceptDialog *result_dialog = nullptr; + HashMap<int, MenuButton *> menus; bool first = true; diff --git a/editor/project_export.cpp b/editor/project_export.cpp index 70627d5e82..b77ab179fb 100644 --- a/editor/project_export.cpp +++ b/editor/project_export.cpp @@ -928,17 +928,13 @@ void ProjectExportDialog::_export_project_to_path(const String &p_path) { ERR_FAIL_COND(platform.is_null()); current->set_export_path(p_path); + platform->clear_messages(); Error err = platform->export_project(current, export_debug->is_pressed(), p_path, 0); - if (err != OK && err != ERR_SKIP) { - if (err == ERR_FILE_NOT_FOUND) { - error_dialog->set_text(vformat(TTR("Failed to export the project for platform '%s'.\nExport templates seem to be missing or invalid."), platform->get_name())); - } else { // Assume misconfiguration. FIXME: Improve error handling and preset config validation. - error_dialog->set_text(vformat(TTR("Failed to export the project for platform '%s'.\nThis might be due to a configuration issue in the export preset or your export settings."), platform->get_name())); + result_dialog_log->clear(); + if (err != ERR_SKIP) { + if (platform->fill_log_messages(result_dialog_log, err)) { + result_dialog->popup_centered_ratio(0.5); } - - ERR_PRINT(vformat("Failed to export the project for platform '%s'.", platform->get_name())); - error_dialog->show(); - error_dialog->popup_centered(Size2(300, 80)); } } @@ -957,6 +953,8 @@ void ProjectExportDialog::_export_all(bool p_debug) { String mode = p_debug ? TTR("Debug") : TTR("Release"); EditorProgress ep("exportall", TTR("Exporting All") + " " + mode, EditorExport::get_singleton()->get_export_preset_count(), true); + bool show_dialog = false; + result_dialog_log->clear(); for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) { Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(i); ERR_FAIL_COND(preset.is_null()); @@ -965,17 +963,16 @@ void ProjectExportDialog::_export_all(bool p_debug) { ep.step(preset->get_name(), i); + platform->clear_messages(); Error err = platform->export_project(preset, p_debug, preset->get_export_path(), 0); - if (err != OK && err != ERR_SKIP) { - if (err == ERR_FILE_BAD_PATH) { - error_dialog->set_text(TTR("The given export path doesn't exist:") + "\n" + preset->get_export_path().get_base_dir()); - } else { - error_dialog->set_text(TTR("Export templates for this platform are missing/corrupted:") + " " + platform->get_name()); - } - error_dialog->show(); - error_dialog->popup_centered(Size2(300, 80)); - ERR_PRINT("Failed to export project"); + if (err == ERR_SKIP) { + return; } + bool has_messages = platform->fill_log_messages(result_dialog_log, err); + show_dialog = show_dialog || has_messages; + } + if (show_dialog) { + result_dialog->popup_centered_ratio(0.5); } } @@ -1248,11 +1245,14 @@ ProjectExportDialog::ProjectExportDialog() { export_error2->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("error_color"), SNAME("Editor"))); export_error2->set_text(String::utf8("• ") + TTR("Export templates for this platform are missing:") + " "); - error_dialog = memnew(AcceptDialog); - error_dialog->set_title(TTR("Error")); - error_dialog->set_text(TTR("Export templates for this platform are missing/corrupted:") + " "); - main_vb->add_child(error_dialog); - error_dialog->hide(); + result_dialog = memnew(AcceptDialog); + result_dialog->set_title(TTR("Project Export")); + result_dialog_log = memnew(RichTextLabel); + result_dialog_log->set_custom_minimum_size(Size2(300, 80) * EDSCALE); + result_dialog->add_child(result_dialog_log); + + main_vb->add_child(result_dialog); + result_dialog->hide(); LinkButton *download_templates = memnew(LinkButton); download_templates->set_text(TTR("Manage Export Templates")); diff --git a/editor/project_export.h b/editor/project_export.h index 4d1719d6eb..6b10642495 100644 --- a/editor/project_export.h +++ b/editor/project_export.h @@ -73,7 +73,8 @@ private: Button *button_export = nullptr; bool updating = false; - AcceptDialog *error_dialog = nullptr; + RichTextLabel *result_dialog_log = nullptr; + AcceptDialog *result_dialog = nullptr; ConfirmationDialog *delete_confirm = nullptr; OptionButton *export_filter = nullptr; |