From 757173e0e26cd3fc75034370c8422615024fb7e4 Mon Sep 17 00:00:00 2001 From: Etherealxx <64251396+etherealxx@users.noreply.github.com> Date: Mon, 24 Feb 2025 03:37:03 +0700 Subject: [PATCH] Add "Go Online" button on Export Template Manager Godot 4.4 introduces network mode, which by default sets to offline. Some features are disabled on offline mode, including downloading export templates. Newcomers to the engine that has no knowledge about the network mode might be confused on why the Export Template Manager tells them that they're offline, despite them having internet connection. This commit introduces a message that tells the user that online mode is required, and a link button that user can click to enable online mode from the Export Template Manager popup UI. Some code changes also made to make sure that the button and message only shows on official build only. (cherry picked from commit 9cbfeff940cf131376d2c5c6f2916caf8865b23a) --- editor/export/export_template_manager.cpp | 35 +++++++++++++++++++++-- editor/export/export_template_manager.h | 2 ++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/editor/export/export_template_manager.cpp b/editor/export/export_template_manager.cpp index 4b86431678e..a8ea9495961 100644 --- a/editor/export/export_template_manager.cpp +++ b/editor/export/export_template_manager.cpp @@ -43,6 +43,7 @@ #include "editor/progress_dialog.h" #include "editor/themes/editor_scale.h" #include "scene/gui/file_dialog.h" +#include "scene/gui/link_button.h" #include "scene/gui/menu_button.h" #include "scene/gui/separator.h" #include "scene/gui/tree.h" @@ -56,9 +57,6 @@ enum DownloadsAvailability { static DownloadsAvailability _get_downloads_availability() { const int network_mode = EDITOR_GET("network/connection/network_mode"); - if (network_mode == EditorSettings::NETWORK_OFFLINE) { - return DOWNLOADS_NOT_AVAILABLE_IN_OFFLINE_MODE; - } // Downloadable export templates are only available for stable and official alpha/beta/RC builds // (which always have a number following their status, e.g. "alpha1"). @@ -71,6 +69,10 @@ static DownloadsAvailability _get_downloads_availability() { return DOWNLOADS_NOT_AVAILABLE_FOR_DEV_BUILDS; } + if (network_mode == EditorSettings::NETWORK_OFFLINE) { + return DOWNLOADS_NOT_AVAILABLE_IN_OFFLINE_MODE; + } + return DOWNLOADS_AVAILABLE; } @@ -335,6 +337,14 @@ void ExportTemplateManager::_refresh_mirrors_completed(int p_status, int p_code, } } +void ExportTemplateManager::_force_online_mode() { + EditorSettings::get_singleton()->set_setting("network/connection/network_mode", EditorSettings::NETWORK_ONLINE); + EditorSettings::get_singleton()->notify_changes(); + EditorSettings::get_singleton()->save(); + + popup_manager(); +} + bool ExportTemplateManager::_humanize_http_status(HTTPRequest *p_request, String *r_status, int *r_downloaded_bytes, int *r_total_bytes) { *r_status = ""; *r_downloaded_bytes = -1; @@ -694,6 +704,8 @@ void ExportTemplateManager::popup_manager() { if (!is_downloading_templates) { _refresh_mirrors(); } + + enable_online_hb->hide(); } break; case DOWNLOADS_NOT_AVAILABLE_IN_OFFLINE_MODE: { @@ -708,6 +720,8 @@ void ExportTemplateManager::popup_manager() { download_current_button->set_disabled(true); download_current_button->set_tooltip_text(TTR("Template downloading is disabled in offline mode.")); + + enable_online_hb->show(); } break; case DOWNLOADS_NOT_AVAILABLE_FOR_DEV_BUILDS: { @@ -722,6 +736,8 @@ void ExportTemplateManager::popup_manager() { download_current_button->set_disabled(true); download_current_button->set_tooltip_text(TTR("Official export templates aren't available for development builds.")); + + enable_online_hb->hide(); } break; } @@ -1053,6 +1069,19 @@ ExportTemplateManager::ExportTemplateManager() { install_file_hb->add_child(install_file_button); install_file_button->connect(SceneStringName(pressed), callable_mp(this, &ExportTemplateManager::_install_file)); + enable_online_hb = memnew(HBoxContainer); + install_options_vb->add_child(enable_online_hb); + + Label *enable_online_label = memnew(Label); + enable_online_label->set_text(TTR("Online mode is needed to download the templates.")); + enable_online_hb->add_child(enable_online_label); + + LinkButton *enable_online_button = memnew(LinkButton); + enable_online_button->set_v_size_flags(Control::SIZE_SHRINK_CENTER); + enable_online_button->set_text(TTR("Go Online")); + enable_online_hb->add_child(enable_online_button); + enable_online_button->connect(SceneStringName(pressed), callable_mp(this, &ExportTemplateManager::_force_online_mode)); + // Templates are being downloaded; buttons unavailable. download_progress_hb = memnew(HBoxContainer); download_progress_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); diff --git a/editor/export/export_template_manager.h b/editor/export/export_template_manager.h index ccfe568d321..a6e103dc137 100644 --- a/editor/export/export_template_manager.h +++ b/editor/export/export_template_manager.h @@ -68,6 +68,7 @@ class ExportTemplateManager : public AcceptDialog { }; MenuButton *mirror_options_button = nullptr; + HBoxContainer *enable_online_hb = nullptr; HBoxContainer *download_progress_hb = nullptr; ProgressBar *download_progress_bar = nullptr; Label *download_progress_label = nullptr; @@ -96,6 +97,7 @@ class ExportTemplateManager : public AcceptDialog { void _cancel_template_download(); void _refresh_mirrors(); void _refresh_mirrors_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data); + void _force_online_mode(); bool _humanize_http_status(HTTPRequest *p_request, String *r_status, int *r_downloaded_bytes, int *r_total_bytes); void _set_current_progress_status(const String &p_status, bool p_error = false);