Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Store: Retain cancel/speed on resize or switch.
  • Loading branch information
unknownbrackets committed May 1, 2021
1 parent 2f08fb6 commit 2044357
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Core/Util/GameManager.cpp
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Core/Util/GameManager.h
Expand Up @@ -43,6 +43,7 @@ class GameManager {

// 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.
Expand Down
17 changes: 11 additions & 6 deletions UI/Store.cpp
Expand Up @@ -222,6 +222,7 @@ class ProductView : public UI::LinearLayout {
bool IsGameInstalled() {
return g_GameManager.IsGameInstalled(entry_.file);
}
std::string DownloadURL();

StoreEntry entry_;
UI::Button *installButton_ = nullptr;
Expand All @@ -244,14 +245,15 @@ 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);
installButton_ = progressDisplay->Add(new Button(st->T("Install")));
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;
Expand All @@ -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));
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 2044357

Please sign in to comment.