Addons now show the size of the package to download.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8371 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2011-04-18 07:11:12 +00:00
parent 75209cb1ce
commit a22b948810
4 changed files with 35 additions and 5 deletions

View File

@ -12,6 +12,7 @@
<spacer proportion="1" />
<div width="50%" height="100%" layout="vertical-row" >
<label word_wrap="true" id="description" width="100%" text="Description:" proportion="1" />
<label id="size" width="100%" text="Size:" proportion="1" />
<label id="revision" width="100%" text="Version:" proportion="1" />
</div>
</div>

View File

@ -39,6 +39,7 @@ Addon::Addon(const XMLNode &xml)
m_icon_url = "";
m_icon_basename = "";
m_icon_revision = 0;
m_size = 0;
m_icon_ready = false;
m_type = xml.getName();
@ -52,6 +53,7 @@ Addon::Addon(const XMLNode &xml)
xml.get("description", &m_description );
xml.get("image", &m_icon_url );
xml.get("icon-revision", &m_icon_revision );
xml.get("size", &m_size );
m_icon_basename = StringUtils::getBasename(m_icon_url);
}; // Addon(const XML&)
@ -76,13 +78,14 @@ void Addon::copyInstallData(const Addon &addon)
*/
void Addon::writeXML(std::ofstream *out_stream)
{
(*out_stream) << " <" << m_type
<< " name=\"" << m_name
<< "\" id=\"" << m_id
(*out_stream) << " <" << m_type
<< " name=\"" << m_name
<< "\" id=\"" << m_id
<< "\" installed=\""
<< (m_installed ? "true" : "false" )
<< "\" installed-revision=\"" << m_installed_revision
<<"\" icon-revision=\"" << m_icon_revision
<< "\" installed-revision=\"" << m_installed_revision
<< "\" size=\"" << m_size
<< "\" icon-revision=\"" << m_icon_revision
<< "\"/>\n";
} // writeXML

View File

@ -52,6 +52,8 @@ public:
std::string m_zip_file;
/** True if the addon is installed. */
bool m_installed;
/** Compressed size of the addon package. */
int m_size;
/** Type, must be 'kart' or 'track'. */
std::string m_type;
@ -131,6 +133,9 @@ public:
m_icon_ready=true;
} // setIconReady
// ------------------------------------------------------------------------
/** Returns the size of the compressed package. */
int getSize() const { return m_size; }
// ------------------------------------------------------------------------
/** Returns the directory in which this type of addons is stored (in a
* separate subdirectory). A kart is stored in .../karts/X and tracks in
* .../tracks/X. If further types are added here, make sure that the

View File

@ -71,6 +71,27 @@ AddonsLoading::AddonsLoading(const float w, const float h,
core::stringw revision = _("Version: %d", m_addon.getRevision());
getWidget<LabelWidget>("revision")->setText(revision, false);
int n = m_addon.getSize();
core::stringw unit="";
if(n>1024*1024)
{
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);
}
else if(n>1024)
{
float f = ((int)(n/1024.0f*10.0f+0.5f))/10.0f;
char s[32];
sprintf(s, "%.1f", f);
unit=_("%s KB", s);
}
else
// Anything smaller just let it be 1 KB
unit=_("1 KB");
core::stringw size = _("Size: %s", unit.c_str());
getWidget<LabelWidget>("size")->setText(size, false);
} // AddonsLoading
// ----------------------------------------------------------------------------