From 20443571bd3755187f2c21514615bc9a99ecaf63 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 1 May 2021 10:49:44 -0700 Subject: [PATCH] Store: Retain cancel/speed on resize or switch. --- Core/Util/GameManager.cpp | 6 ++++++ Core/Util/GameManager.h | 1 + UI/Store.cpp | 17 +++++++++++------ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Core/Util/GameManager.cpp b/Core/Util/GameManager.cpp index fa911f34d4..7063cf0a8d 100644 --- a/Core/Util/GameManager.cpp +++ b/Core/Util/GameManager.cpp @@ -82,6 +82,12 @@ bool GameManager::DownloadAndInstall(std::string storeFileUrl) { return true; } +bool GameManager::IsDownloading(std::string storeZipUrl) { + if (curDownload_) + return curDownload_->url() == storeZipUrl; + return false; +} + bool GameManager::CancelDownload() { if (!curDownload_) return false; diff --git a/Core/Util/GameManager.h b/Core/Util/GameManager.h index 54c685c1c2..a13939c56e 100644 --- a/Core/Util/GameManager.h +++ b/Core/Util/GameManager.h @@ -43,6 +43,7 @@ public: // This starts off a background process. bool DownloadAndInstall(std::string storeZipUrl); + bool IsDownloading(std::string storeZipUrl); bool Uninstall(std::string name); // Cancels the download in progress, if any. diff --git a/UI/Store.cpp b/UI/Store.cpp index 9c13934dbe..cd50c7269a 100644 --- a/UI/Store.cpp +++ b/UI/Store.cpp @@ -222,6 +222,7 @@ private: bool IsGameInstalled() { return g_GameManager.IsGameInstalled(entry_.file); } + std::string DownloadURL(); StoreEntry entry_; UI::Button *installButton_ = nullptr; @@ -244,6 +245,7 @@ void ProductView::CreateViews() { auto st = GetI18NCategory("Store"); auto di = GetI18NCategory("Dialog"); wasInstalled_ = IsGameInstalled(); + bool isDownloading = g_GameManager.IsDownloading(DownloadURL()); if (!wasInstalled_) { launchButton_ = nullptr; LinearLayout *progressDisplay = new LinearLayout(ORIENT_HORIZONTAL); @@ -251,7 +253,7 @@ void ProductView::CreateViews() { installButton_->OnClick.Handle(this, &ProductView::OnInstall); speedView_ = progressDisplay->Add(new TextView("")); - speedView_->SetVisibility(V_GONE); + speedView_->SetVisibility(isDownloading ? V_VISIBLE : V_GONE); Add(progressDisplay); } else { installButton_ = nullptr; @@ -264,7 +266,7 @@ void ProductView::CreateViews() { cancelButton_ = Add(new Button(di->T("Cancel"))); cancelButton_->OnClick.Handle(this, &ProductView::OnCancel); - cancelButton_->SetVisibility(V_GONE); + cancelButton_->SetVisibility(isDownloading ? V_VISIBLE : V_GONE); // Add star rating, comments etc? Add(new TextView(entry_.description, ALIGN_LEFT | FLAG_WRAP_TEXT, false)); @@ -299,18 +301,21 @@ void ProductView::Update() { View::Update(); } -UI::EventReturn ProductView::OnInstall(UI::EventParams &e) { - std::string fileUrl; +std::string ProductView::DownloadURL() { if (entry_.downloadURL.empty()) { // Construct the URL, easy to predict from our server std::string shortName = entry_.file; if (shortName.find('.') == std::string::npos) shortName += ".zip"; - fileUrl = storeBaseUrl + "files/" + shortName; + return storeBaseUrl + "files/" + shortName; } else { // Use the provided URL, for external hosting. - fileUrl = entry_.downloadURL; + return entry_.downloadURL; } +} + +UI::EventReturn ProductView::OnInstall(UI::EventParams &e) { + std::string fileUrl = DownloadURL(); if (installButton_) { installButton_->SetEnabled(false); }