浏览代码

Use indeterminate progressbars for downloads (export templates & assets)

Christian Kaiser 1 年之前
父节点
当前提交
edcb581627
共有 2 个文件被更改,包括 15 次插入5 次删除
  1. 7 1
      editor/export/export_template_manager.cpp
  2. 8 4
      editor/plugins/asset_library_editor_plugin.cpp

+ 7 - 1
editor/export/export_template_manager.cpp

@@ -146,6 +146,9 @@ void ExportTemplateManager::_download_template(const String &p_url, bool p_skip_
 
 
 	install_options_vb->hide();
 	install_options_vb->hide();
 	download_progress_hb->show();
 	download_progress_hb->show();
+	download_progress_bar->show();
+	download_progress_bar->set_indeterminate(true);
+
 	_set_current_progress_status(TTR("Starting the download..."));
 	_set_current_progress_status(TTR("Starting the download..."));
 
 
 	download_templates->set_download_file(EditorPaths::get_singleton()->get_cache_dir().path_join("tmp_templates.tpz"));
 	download_templates->set_download_file(EditorPaths::get_singleton()->get_cache_dir().path_join("tmp_templates.tpz"));
@@ -159,6 +162,7 @@ void ExportTemplateManager::_download_template(const String &p_url, bool p_skip_
 	Error err = download_templates->request(p_url);
 	Error err = download_templates->request(p_url);
 	if (err != OK) {
 	if (err != OK) {
 		_set_current_progress_status(TTR("Error requesting URL:") + " " + p_url, true);
 		_set_current_progress_status(TTR("Error requesting URL:") + " " + p_url, true);
+		download_progress_hb->hide();
 		return;
 		return;
 	}
 	}
 
 
@@ -357,10 +361,10 @@ bool ExportTemplateManager::_humanize_http_status(HTTPRequest *p_request, String
 }
 }
 
 
 void ExportTemplateManager::_set_current_progress_status(const String &p_status, bool p_error) {
 void ExportTemplateManager::_set_current_progress_status(const String &p_status, bool p_error) {
-	download_progress_bar->hide();
 	download_progress_label->set_text(p_status);
 	download_progress_label->set_text(p_status);
 
 
 	if (p_error) {
 	if (p_error) {
+		download_progress_bar->hide();
 		download_progress_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
 		download_progress_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
 	} else {
 	} else {
 		download_progress_label->add_theme_color_override("font_color", get_theme_color(SNAME("font_color"), SNAME("Label")));
 		download_progress_label->add_theme_color_override("font_color", get_theme_color(SNAME("font_color"), SNAME("Label")));
@@ -369,6 +373,7 @@ void ExportTemplateManager::_set_current_progress_status(const String &p_status,
 
 
 void ExportTemplateManager::_set_current_progress_value(float p_value, const String &p_status) {
 void ExportTemplateManager::_set_current_progress_value(float p_value, const String &p_status) {
 	download_progress_bar->show();
 	download_progress_bar->show();
+	download_progress_bar->set_indeterminate(false);
 	download_progress_bar->set_value(p_value);
 	download_progress_bar->set_value(p_value);
 	download_progress_label->set_text(p_status);
 	download_progress_label->set_text(p_status);
 }
 }
@@ -955,6 +960,7 @@ ExportTemplateManager::ExportTemplateManager() {
 	download_progress_bar->set_max(1);
 	download_progress_bar->set_max(1);
 	download_progress_bar->set_value(0);
 	download_progress_bar->set_value(0);
 	download_progress_bar->set_step(0.01);
 	download_progress_bar->set_step(0.01);
+	download_progress_bar->set_editor_preview_indeterminate(true);
 	download_progress_hb->add_child(download_progress_bar);
 	download_progress_hb->add_child(download_progress_bar);
 
 
 	download_progress_label = memnew(Label);
 	download_progress_label = memnew(Label);

+ 8 - 4
editor/plugins/asset_library_editor_plugin.cpp

@@ -384,6 +384,10 @@ void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int
 		} break;
 		} break;
 	}
 	}
 
 
+	// Make the progress bar invisible but don't reflow other Controls around it.
+	progress->set_modulate(Color(0, 0, 0, 0));
+	progress->set_indeterminate(false);
+
 	if (!error_text.is_empty()) {
 	if (!error_text.is_empty()) {
 		download_error->set_text(TTR("Asset Download Error:") + "\n" + error_text);
 		download_error->set_text(TTR("Asset Download Error:") + "\n" + error_text);
 		download_error->popup_centered();
 		download_error->popup_centered();
@@ -394,8 +398,6 @@ void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int
 
 
 	install_button->set_disabled(false);
 	install_button->set_disabled(false);
 	status->set_text(TTR("Ready to install!"));
 	status->set_text(TTR("Ready to install!"));
-	// Make the progress bar invisible but don't reflow other Controls around it.
-	progress->set_modulate(Color(0, 0, 0, 0));
 
 
 	set_process(false);
 	set_process(false);
 
 
@@ -436,13 +438,13 @@ void EditorAssetLibraryItemDownload::_notification(int p_what) {
 
 
 			if (cstatus == HTTPClient::STATUS_BODY) {
 			if (cstatus == HTTPClient::STATUS_BODY) {
 				if (download->get_body_size() > 0) {
 				if (download->get_body_size() > 0) {
+					progress->set_indeterminate(false);
 					status->set_text(vformat(
 					status->set_text(vformat(
 							TTR("Downloading (%s / %s)..."),
 							TTR("Downloading (%s / %s)..."),
 							String::humanize_size(download->get_downloaded_bytes()),
 							String::humanize_size(download->get_downloaded_bytes()),
 							String::humanize_size(download->get_body_size())));
 							String::humanize_size(download->get_body_size())));
 				} else {
 				} else {
-					// Total file size is unknown, so it cannot be displayed.
-					progress->set_modulate(Color(0, 0, 0, 0));
+					progress->set_indeterminate(true);
 					status->set_text(vformat(
 					status->set_text(vformat(
 							TTR("Downloading...") + " (%s)",
 							TTR("Downloading...") + " (%s)",
 							String::humanize_size(download->get_downloaded_bytes())));
 							String::humanize_size(download->get_downloaded_bytes())));
@@ -508,6 +510,7 @@ void EditorAssetLibraryItemDownload::_make_request() {
 	if (err != OK) {
 	if (err != OK) {
 		status->set_text(TTR("Error making request"));
 		status->set_text(TTR("Error making request"));
 	} else {
 	} else {
+		progress->set_indeterminate(true);
 		set_process(true);
 		set_process(true);
 	}
 	}
 }
 }
@@ -548,6 +551,7 @@ EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() {
 	status = memnew(Label(TTR("Idle")));
 	status = memnew(Label(TTR("Idle")));
 	vb->add_child(status);
 	vb->add_child(status);
 	progress = memnew(ProgressBar);
 	progress = memnew(ProgressBar);
+	progress->set_editor_preview_indeterminate(true);
 	vb->add_child(progress);
 	vb->add_child(progress);
 
 
 	HBoxContainer *hb2 = memnew(HBoxContainer);
 	HBoxContainer *hb2 = memnew(HBoxContainer);