Show download size for each option of game assets

This commit is contained in:
Benau 2019-07-26 01:19:34 +08:00
parent 722f18a587
commit afa26ccf97
3 changed files with 62 additions and 3 deletions

View File

@ -26,6 +26,7 @@
#include "io/file_manager.hpp"
#include "online/http_request.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/download_assets_size.hpp"
#include "utils/string_utils.hpp"
#include "utils/translation.hpp"
#include "main_loop.hpp"
@ -45,11 +46,26 @@ void DownloadAssets::beforeAddingWidget()
} // beforeAddingWidget
// -----------------------------------------------------------------------------
void DownloadAssets::updateDownloadSize()
{
m_progress->setValue(0);
core::stringw unit="";
unsigned n = getDownloadAssetsSize(m_all_tracks->getState(),
m_hd_textures->getState());
float f = ((int)(n/1024.0f/1024.0f*10.0f+0.5f))/10.0f;
char s[32];
sprintf(s, "%.1f", f);
unit = _("%s MB", s);
// I18N: File size of game assets or addons downloading
core::stringw size = _("Size: %s", unit.c_str());
m_progress->setText(size);
} // updateDownloadSize
// -----------------------------------------------------------------------------
void DownloadAssets::init()
{
m_progress = getWidget<ProgressBarWidget>("progress");
m_progress->setVisible(false);
m_all_tracks = getWidget<CheckBoxWidget>("all-tracks");
m_all_tracks->setActive(true);
m_all_tracks->setVisible(true);
@ -58,6 +74,7 @@ void DownloadAssets::init()
m_hd_textures->setActive(true);
m_hd_textures->setVisible(true);
m_hd_textures->setState(false);
updateDownloadSize();
m_ok = getWidget<IconButtonWidget>("ok");
m_ok->setActive(true);
m_ok->setVisible(true);
@ -89,7 +106,9 @@ void DownloadAssets::eventCallback(Widget* widget, const std::string& name,
{
if (m_downloading_now)
return;
if (name == "buttons")
if (name == "all-tracks" || name == "hd-textures")
updateDownloadSize();
else if (name == "buttons")
{
const std::string& button = getWidget<GUIEngine::RibbonWidget>("buttons")
->getSelectionIDString(PLAYER_ID_GAME_MASTER);
@ -97,8 +116,8 @@ void DownloadAssets::eventCallback(Widget* widget, const std::string& name,
{
m_downloading_now = true;
m_ok->setActive(false);
m_progress->setText("");
m_progress->setValue(0);
m_progress->setVisible(true);
m_all_tracks->setActive(false);
m_hd_textures->setActive(false);
std::string download_url = stk_config->m_assets_download_url;

View File

@ -60,6 +60,8 @@ private:
Online::HTTPRequest* m_download_request;
std::thread m_download_thread;
void updateDownloadSize();
public:
friend class GUIEngine::ScreenSingleton<DownloadAssets>;

View File

@ -0,0 +1,38 @@
// SuperTuxKart - a fun racing game with go-kart
//
// Copyright (C) 2019 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_DOWNLOAD_ASSETS_SIZE_HPP
#define HEADER_DOWNLOAD_ASSETS_SIZE_HPP
/* Return .zip file size in bytes (as in ls -l)
*/
inline unsigned getDownloadAssetsSize(bool is_full, bool is_hd)
{
// Todo: generated from some sed script
unsigned full_hd = 188442091;
unsigned full_nonhd = 83487825;
unsigned nonfull_hd = 166310030;
unsigned nonfull_nonhd = 69282428;
if (is_full && is_hd)
return full_hd;
if (is_full && !is_hd)
return full_nonhd;
if (!is_full && is_hd)
return nonfull_hd;
return nonfull_nonhd;
}
#endif