Many more coding style adjustments.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7134 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
e472d7459c
commit
b5837a624b
@ -44,7 +44,7 @@ Addons* addons_manager = 0;
|
|||||||
|
|
||||||
Addons::Addons()
|
Addons::Addons()
|
||||||
{
|
{
|
||||||
this->index = -1;
|
m_index = -1;
|
||||||
int download_state = 0;
|
int download_state = 0;
|
||||||
m_download_state = download_state;
|
m_download_state = download_state;
|
||||||
pthread_mutex_init(&m_str_mutex, NULL);
|
pthread_mutex_init(&m_str_mutex, NULL);
|
||||||
@ -105,30 +105,32 @@ Addons::Addons()
|
|||||||
}
|
}
|
||||||
addons.type = xml->getNodeName();
|
addons.type = xml->getNodeName();
|
||||||
addons.installed = false;
|
addons.installed = false;
|
||||||
this->m_addons_list.push_back(addons);
|
m_addons_list.push_back(addons);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete xml;
|
delete xml;
|
||||||
|
|
||||||
this->file_installed = file_manager->getConfigDir() + "/" + "addons_installed.xml";
|
m_file_installed = file_manager->getConfigDir()
|
||||||
this->GetInstalledAddons();
|
+ "/" + "addons_installed.xml";
|
||||||
}
|
getInstalledAddons();
|
||||||
void Addons::resetIndex()
|
|
||||||
{
|
|
||||||
this->index = -1;
|
|
||||||
}
|
}
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void Addons::GetInstalledAddons()
|
void Addons::resetIndex()
|
||||||
|
{
|
||||||
|
m_index = -1;
|
||||||
|
}
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
void Addons::getInstalledAddons()
|
||||||
{
|
{
|
||||||
std::string attribute_name;
|
std::string attribute_name;
|
||||||
int old_index = this->index;
|
int old_index = m_index;
|
||||||
|
|
||||||
/* checking for installed addons */
|
/* checking for installed addons */
|
||||||
|
|
||||||
std::cout << "[Addons] Loading an xml file for installed addons: ";
|
std::cout << "[Addons] Loading an xml file for installed addons: ";
|
||||||
std::cout << this->file_installed << std::endl;
|
std::cout << m_file_installed << std::endl;
|
||||||
IrrXMLReader* xml = createIrrXMLReader(this->file_installed.c_str());
|
IrrXMLReader* xml = createIrrXMLReader(m_file_installed.c_str());
|
||||||
|
|
||||||
// parse the file until end reached
|
// parse the file until end reached
|
||||||
|
|
||||||
@ -161,10 +163,10 @@ void Addons::GetInstalledAddons()
|
|||||||
version = xml->getAttributeValueAsInt("version");
|
version = xml->getAttributeValueAsInt("version");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(this->SelectId(id))
|
if(selectId(id))
|
||||||
{
|
{
|
||||||
this->m_addons_list[this->index].installed = true;
|
m_addons_list[m_index].installed = true;
|
||||||
this->m_addons_list[this->index].installed_version = version;
|
m_addons_list[m_index].installed_version = version;
|
||||||
std::cout << "[Addons] An addon is already installed: " << id << std::endl;
|
std::cout << "[Addons] An addon is already installed: " << id << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -175,7 +177,7 @@ void Addons::GetInstalledAddons()
|
|||||||
addons.installed_version = version;
|
addons.installed_version = version;
|
||||||
addons.version = version;
|
addons.version = version;
|
||||||
addons.installed = true;
|
addons.installed = true;
|
||||||
this->m_addons_list.push_back(addons);
|
m_addons_list.push_back(addons);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,142 +186,141 @@ void Addons::GetInstalledAddons()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete xml;
|
delete xml;
|
||||||
this->index = old_index;
|
m_index = old_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
bool Addons::Next()
|
bool Addons::next()
|
||||||
{
|
{
|
||||||
if(this->index + 1 < (int)this->m_addons_list.size())
|
if(m_index + 1 < (int)m_addons_list.size())
|
||||||
{
|
{
|
||||||
this->index ++;
|
m_index ++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
this->index = -1;
|
m_index = -1;
|
||||||
return false;
|
return false;
|
||||||
}
|
} // next
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
bool Addons::NextType(std::string type)
|
bool Addons::nextType(std::string type)
|
||||||
{
|
{
|
||||||
while(this->Next())
|
while(next())
|
||||||
{
|
{
|
||||||
if(this->m_addons_list[this->index].type == type)
|
if(m_addons_list[m_index].type == type)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
while(this->Next())
|
while(next())
|
||||||
{
|
{
|
||||||
if(this->m_addons_list[this->index].type == type)
|
if(m_addons_list[m_index].type == type)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
} // nextType
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
bool Addons::Previous()
|
bool Addons::previous()
|
||||||
{
|
{
|
||||||
if(this->index - 1 > 0)
|
if(m_index - 1 > 0)
|
||||||
{
|
{
|
||||||
this->index --;
|
m_index --;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
this->index = this->m_addons_list.size() - 1;
|
m_index = m_addons_list.size() - 1;
|
||||||
return false;
|
return false;
|
||||||
}
|
} // previous
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
bool Addons::PreviousType(std::string type)
|
bool Addons::previousType(std::string type)
|
||||||
{
|
{
|
||||||
while(this->Previous())
|
while(previous())
|
||||||
{
|
{
|
||||||
if(this->m_addons_list[this->index].type == type)
|
if(m_addons_list[m_index].type == type)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
while(this->Previous())
|
while(previous())
|
||||||
{
|
{
|
||||||
if(this->m_addons_list[this->index].type == type)
|
if(m_addons_list[m_index].type == type)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
} // previousType
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
bool Addons::Select(std::string name)
|
bool Addons::select(std::string name)
|
||||||
{
|
{
|
||||||
//the unsigned is to remove the compiler warnings, maybe it is a bad idea ?
|
//the unsigned is to remove the compiler warnings, maybe it is a bad idea ?
|
||||||
for(unsigned int i = 0; i < this->m_addons_list.size(); i++)
|
for(unsigned int i = 0; i < m_addons_list.size(); i++)
|
||||||
{
|
{
|
||||||
if(this->m_addons_list[i].name == name)
|
if(m_addons_list[i].name == name)
|
||||||
{
|
{
|
||||||
this->index = i;
|
m_index = i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
} // select
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
bool Addons::SelectId(std::string id)
|
bool Addons::selectId(std::string id)
|
||||||
{
|
{
|
||||||
//the unsigned is to remove the compiler warnings, maybe it is a bad idea ?
|
//the unsigned is to remove the compiler warnings, maybe it is a bad idea ?
|
||||||
for(unsigned int i = 0; i < this->m_addons_list.size(); i++)
|
for(unsigned int i = 0; i < m_addons_list.size(); i++)
|
||||||
{
|
{
|
||||||
if(this->m_addons_list[i].id == id)
|
if(m_addons_list[i].id == id)
|
||||||
{
|
{
|
||||||
this->index = i;
|
m_index = i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
} // selectId
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/* FIXME : remove this function */
|
/* FIXME : remove this function */
|
||||||
addons_prop Addons::GetAddons()
|
addons_prop Addons::getAddons()
|
||||||
{
|
{
|
||||||
return this->m_addons_list[this->index];
|
return m_addons_list[m_index];
|
||||||
}
|
} // getAddons
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
std::string Addons::IsInstalled()
|
std::string Addons::getVersionAsStr() const
|
||||||
{
|
|
||||||
if(this->m_addons_list[this->index].installed)
|
|
||||||
{
|
|
||||||
return "yes";
|
|
||||||
}
|
|
||||||
return "no";
|
|
||||||
}
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
std::string Addons::GetVersionAsStr()
|
|
||||||
{
|
|
||||||
//maybe it is dirty, FIXME ?
|
|
||||||
std::ostringstream os;
|
|
||||||
os << this->m_addons_list[this->index].version;
|
|
||||||
return os.str();
|
|
||||||
}
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
std::string Addons::GetIdAsStr()
|
|
||||||
{
|
{
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << this->m_addons_list[this->index].id;
|
os << m_addons_list[m_index].version;
|
||||||
return os.str();
|
return os.str();
|
||||||
}
|
} // getVersionAsStr
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
int Addons::GetInstalledVersion()
|
std::string Addons::getIdAsStr() const
|
||||||
{
|
{
|
||||||
if(this->m_addons_list[this->index].installed)
|
std::ostringstream os;
|
||||||
return this->m_addons_list[this->index].installed_version;
|
os << m_addons_list[m_index].id;
|
||||||
|
return os.str();
|
||||||
|
} // getIdAsStr
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
int Addons::getInstalledVersion() const
|
||||||
|
{
|
||||||
|
if(m_addons_list[m_index].installed)
|
||||||
|
return m_addons_list[m_index].installed_version;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} // getInstalledVersion
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
std::string Addons::GetInstalledVersionAsStr()
|
std::string Addons::getInstalledVersionAsStr() const
|
||||||
{
|
{
|
||||||
if(this->m_addons_list[this->index].installed)
|
if(m_addons_list[m_index].installed)
|
||||||
{
|
{
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << this->m_addons_list[this->index].installed_version;
|
os << m_addons_list[m_index].installed_version;
|
||||||
return os.str();
|
return os.str();
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
} // getInstalledVersionAsStr
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void Addons::Install()
|
void Addons::install()
|
||||||
{
|
{
|
||||||
//download of the addons file
|
//download of the addons file
|
||||||
|
|
||||||
@ -327,9 +328,9 @@ void Addons::Install()
|
|||||||
m_str_state = "Downloading...";
|
m_str_state = "Downloading...";
|
||||||
pthread_mutex_unlock(&m_str_mutex);
|
pthread_mutex_unlock(&m_str_mutex);
|
||||||
|
|
||||||
std::string file = "file/" + this->m_addons_list[this->index].file;
|
std::string file = "file/" + m_addons_list[m_index].file;
|
||||||
bool success = download(file,
|
bool success = download(file,
|
||||||
this->m_addons_list[this->index].name, &m_download_state);
|
m_addons_list[m_index].name, &m_download_state);
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
@ -338,14 +339,14 @@ void Addons::Install()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
file_manager->checkAndCreateDirForAddons(this->m_addons_list[this->index].name,
|
file_manager->checkAndCreateDirForAddons(m_addons_list[m_index].name,
|
||||||
this->m_addons_list[this->index].type + "s/");
|
m_addons_list[m_index].type + "s/");
|
||||||
|
|
||||||
//extract the zip in the addons folder called like the addons name
|
//extract the zip in the addons folder called like the addons name
|
||||||
std::string dest_file =file_manager->getAddonsDir() + "/" + "data" + "/" +
|
std::string dest_file =file_manager->getAddonsDir() + "/" + "data" + "/" +
|
||||||
this->m_addons_list[this->index].type + "s/" +
|
m_addons_list[m_index].type + "s/" +
|
||||||
this->m_addons_list[this->index].name + "/" ;
|
m_addons_list[m_index].name + "/" ;
|
||||||
std::string from = file_manager->getConfigDir() + "/" + this->m_addons_list[this->index].name;
|
std::string from = file_manager->getConfigDir() + "/" + m_addons_list[m_index].name;
|
||||||
std::string to = dest_file;
|
std::string to = dest_file;
|
||||||
|
|
||||||
pthread_mutex_lock(&m_str_mutex);
|
pthread_mutex_lock(&m_str_mutex);
|
||||||
@ -360,37 +361,38 @@ void Addons::Install()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->m_addons_list[this->index].installed = true;
|
m_addons_list[m_index].installed = true;
|
||||||
this->m_addons_list[this->index].installed_version = this->m_addons_list[this->index].version;
|
m_addons_list[m_index].installed_version = m_addons_list[m_index].version;
|
||||||
|
|
||||||
pthread_mutex_lock(&m_str_mutex);
|
pthread_mutex_lock(&m_str_mutex);
|
||||||
m_str_state = "Reloading kart list...";
|
m_str_state = "Reloading kart list...";
|
||||||
pthread_mutex_unlock(&m_str_mutex);
|
pthread_mutex_unlock(&m_str_mutex);
|
||||||
this->SaveInstalled();
|
saveInstalled();
|
||||||
}
|
} // install
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void Addons::SaveInstalled()
|
void Addons::saveInstalled()
|
||||||
{
|
{
|
||||||
//Put the addons in the xml file
|
//Put the addons in the xml file
|
||||||
//Manually because the irrlicht xml writer doesn't seem finished, FIXME ?
|
//Manually because the irrlicht xml writer doesn't seem finished, FIXME ?
|
||||||
std::ofstream xml_installed(this->file_installed.c_str());
|
std::ofstream xml_installed(m_file_installed.c_str());
|
||||||
|
|
||||||
//write the header of the xml file
|
//write the header of the xml file
|
||||||
xml_installed << "<?xml version=\"1.0\"?>" << std::endl;
|
xml_installed << "<?xml version=\"1.0\"?>" << std::endl;
|
||||||
xml_installed << "<addons xmlns='http://stkaddons.tuxfamily.org/'>"
|
xml_installed << "<addons xmlns='http://stkaddons.tuxfamily.org/'>"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
for(unsigned int i = 0; i < this->m_addons_list.size(); i++)
|
for(unsigned int i = 0; i < m_addons_list.size(); i++)
|
||||||
{
|
{
|
||||||
if(this->m_addons_list[i].installed)
|
if(m_addons_list[i].installed)
|
||||||
{
|
{
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << this->m_addons_list[i].installed_version;
|
os << m_addons_list[i].installed_version;
|
||||||
|
|
||||||
//transform the version (int) in string
|
//transform the version (int) in string
|
||||||
xml_installed << "<"+ this->m_addons_list[i].type +" name=\"" +
|
xml_installed << "<"+ m_addons_list[i].type +" name=\"" +
|
||||||
this->m_addons_list[i].name + "\" id=\"" +
|
m_addons_list[i].name + "\" id=\"" +
|
||||||
this->m_addons_list[i].id + "\"";
|
m_addons_list[i].id + "\"";
|
||||||
xml_installed << " version=\"" + os.str() + "\" />" << std::endl;
|
xml_installed << " version=\"" + os.str() + "\" />" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -398,26 +400,26 @@ void Addons::SaveInstalled()
|
|||||||
xml_installed.close();
|
xml_installed.close();
|
||||||
kart_properties_manager->reLoadAllKarts();
|
kart_properties_manager->reLoadAllKarts();
|
||||||
track_manager->loadTrackList();
|
track_manager->loadTrackList();
|
||||||
}
|
} // saveInstalled
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
void Addons::UnInstall()
|
|
||||||
{
|
|
||||||
std::cout << "[Addons] Uninstalling <" << this->m_addons_list[this->index].name << ">\n";
|
|
||||||
|
|
||||||
this->m_addons_list[this->index].installed = false;
|
// ----------------------------------------------------------------------------
|
||||||
|
void Addons::uninstall()
|
||||||
|
{
|
||||||
|
std::cout << "[Addons] Uninstalling <" << m_addons_list[m_index].name << ">\n";
|
||||||
|
|
||||||
|
m_addons_list[m_index].installed = false;
|
||||||
//write the xml file with the informations about installed karts
|
//write the xml file with the informations about installed karts
|
||||||
std::string dest_file = file_manager->getAddonsDir() + "/" + "data" + "/" +
|
std::string dest_file = file_manager->getAddonsDir() + "/" + "data" + "/" +
|
||||||
this->m_addons_list[this->index].type + "s/" +
|
m_addons_list[m_index].type + "s/" +
|
||||||
this->m_addons_list[this->index].name + "/";
|
m_addons_list[m_index].name + "/";
|
||||||
|
|
||||||
//remove the addons directory
|
//remove the addons directory
|
||||||
file_manager->removeDirectory(dest_file.c_str());
|
file_manager->removeDirectory(dest_file.c_str());
|
||||||
this->SaveInstalled();
|
saveInstalled();
|
||||||
|
|
||||||
}
|
} // uninstall
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
int Addons::getDownloadState()
|
int Addons::getDownloadState()
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&download_mutex);
|
pthread_mutex_lock(&download_mutex);
|
||||||
@ -428,18 +430,18 @@ int Addons::getDownloadState()
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
std::string Addons::getDownloadStateAsStr()
|
std::string Addons::getDownloadStateAsStr() const
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&m_str_mutex);
|
pthread_mutex_lock(&m_str_mutex);
|
||||||
std::string value = m_str_state;
|
std::string value = m_str_state;
|
||||||
pthread_mutex_unlock(&m_str_mutex);
|
pthread_mutex_unlock(&m_str_mutex);
|
||||||
return value;
|
return value;
|
||||||
}
|
} // getDownloadStateAsStr
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool Addons::NeedUpdate()
|
bool Addons::needUpdate() const
|
||||||
{
|
{
|
||||||
return GetInstalledVersion() < GetVersion();
|
return getInstalledVersion() < getVersion();
|
||||||
}
|
} // needUpdate
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,79 +41,82 @@ class Addons
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::vector<addons_prop> m_addons_list;
|
std::vector<addons_prop> m_addons_list;
|
||||||
int index;
|
int m_index;
|
||||||
std::string file_installed;
|
std::string m_file_installed;
|
||||||
void SaveInstalled();
|
void saveInstalled();
|
||||||
void GetInstalledAddons();
|
void getInstalledAddons();
|
||||||
std::string type;
|
std::string m_type;
|
||||||
int m_download_state;
|
int m_download_state;
|
||||||
pthread_mutex_t m_str_mutex;
|
mutable pthread_mutex_t m_str_mutex;
|
||||||
std::string m_str_state;
|
std::string m_str_state;
|
||||||
public:
|
public:
|
||||||
Addons();
|
Addons();
|
||||||
|
|
||||||
/** Select the next addons in the addons list. */
|
/** Select the next addons in the addons list. */
|
||||||
bool Next();
|
bool next();
|
||||||
/** Select the next addons in the addons list. */
|
/** Select the next addons in the addons list. */
|
||||||
bool Previous();
|
bool previous();
|
||||||
|
|
||||||
/** Get all the selected addon parameters. */
|
/** Get all the selected addon parameters. */
|
||||||
addons_prop GetAddons();
|
addons_prop getAddons();
|
||||||
|
|
||||||
/** Select an addon with it name. */
|
/** Select an addon with it name. */
|
||||||
bool Select(std::string);
|
bool select(std::string);
|
||||||
|
|
||||||
/** Select an addon with it id. */
|
/** Select an addon with it id. */
|
||||||
bool SelectId(std::string);
|
bool selectId(std::string);
|
||||||
|
|
||||||
/** Get the name of the selected addon. */
|
/** Get the name of the selected addon. */
|
||||||
std::string GetName(){ return this->m_addons_list[this->index].name; };
|
const std::string &getName() const
|
||||||
|
{ return m_addons_list[m_index].name; };
|
||||||
|
|
||||||
/** Get the version of the selected addon. */
|
/** Get the version of the selected addon. */
|
||||||
int GetVersion(){ return this->m_addons_list[this->index].version; };
|
int getVersion() const { return m_addons_list[m_index].version; };
|
||||||
|
|
||||||
/** Get the path of the addon icon. */
|
/** Get the path of the addon icon. */
|
||||||
std::string GetIcon() { return this->m_addons_list[this->index].icon; };
|
const std::string &getIcon() const
|
||||||
|
{ return m_addons_list[m_index].icon; };
|
||||||
|
|
||||||
/** Get the version of the selected addon as a string. */
|
/** Get the version of the selected addon as a string. */
|
||||||
std::string GetVersionAsStr();
|
std::string getVersionAsStr() const;
|
||||||
|
|
||||||
/** Get the installed version of the selected addon. */
|
/** Get the installed version of the selected addon. */
|
||||||
int GetInstalledVersion();
|
int getInstalledVersion() const;
|
||||||
std::string GetInstalledVersionAsStr();
|
std::string getInstalledVersionAsStr() const;
|
||||||
|
|
||||||
/** Return a simple bool to know if the addon needs to be updated */
|
/** Return a simple bool to know if the addon needs to be updated */
|
||||||
bool NeedUpdate();
|
bool needUpdate() const;
|
||||||
|
|
||||||
/** Get the installed version of the selected addon. */
|
/** Get the installed version of the selected addon. */
|
||||||
std::string GetIdAsStr();
|
std::string getIdAsStr() const;
|
||||||
|
|
||||||
/** Get the description of the selected addons. */
|
/** Get the description of the selected addons. */
|
||||||
std::string GetDescription(){ return this->m_addons_list[this->index].description; };
|
const std::string &getDescription() const
|
||||||
|
{ return m_addons_list[m_index].description; };
|
||||||
|
|
||||||
std::string GetType(){ return this->m_addons_list[this->index].type; };
|
const std::string &getType() const
|
||||||
|
{ return m_addons_list[m_index].type; };
|
||||||
/** Install or upgrade the selected addon. */
|
/** Install or upgrade the selected addon. */
|
||||||
void Install();
|
void install();
|
||||||
|
|
||||||
/** Uninstall the selected addon. This method will remove all the directory of the addon.*/
|
/** Uninstall the selected addon. This method will remove all the
|
||||||
void UnInstall();
|
* directory of the addon.*/
|
||||||
|
void uninstall();
|
||||||
|
|
||||||
void resetIndex();
|
void resetIndex();
|
||||||
|
|
||||||
/** Get the state of the addon: if it is installed or not.*/
|
/** Get the state of the addon: if it is installed or not.*/
|
||||||
std::string IsInstalled();
|
bool isInstalledAsBool() const
|
||||||
|
{ return m_addons_list[m_index].installed; };
|
||||||
|
|
||||||
/** Get the state of the addon: if it is installed or not.*/
|
bool nextType(std::string type);
|
||||||
bool IsInstalledAsBool(){ return this->m_addons_list[this->index].installed; };
|
bool previousType(std::string type);
|
||||||
|
int getDownloadState();
|
||||||
bool NextType(std::string type);
|
|
||||||
bool PreviousType(std::string type);
|
|
||||||
int getDownloadState();
|
|
||||||
|
|
||||||
/** Get the install state (if it is the download, unzip...)*/
|
/** Get the install state (if it is the download, unzip...)*/
|
||||||
std::string getDownloadStateAsStr();
|
std::string getDownloadStateAsStr() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
extern Addons * addons_manager;
|
extern Addons *addons_manager;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -77,16 +77,7 @@ void *NetworkHttp::mainLoop(void *obj)
|
|||||||
{
|
{
|
||||||
NetworkHttp *me=(NetworkHttp*)obj;
|
NetworkHttp *me=(NetworkHttp*)obj;
|
||||||
me->checkNewServer();
|
me->checkNewServer();
|
||||||
const std::string tmp_str = me->downloadToStr("news");
|
me->updateNews();
|
||||||
|
|
||||||
pthread_mutex_lock(&(me->m_mutex_news));
|
|
||||||
{
|
|
||||||
printf("tmp %s\n", tmp_str.c_str());
|
|
||||||
// Only lock the actual assignment, not the downloading!
|
|
||||||
me->m_news_message = tmp_str;
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&(me->m_mutex_news));
|
|
||||||
|
|
||||||
// Allow this thread to be cancelled anytime
|
// Allow this thread to be cancelled anytime
|
||||||
// FIXME: this mechanism will later not be necessary anymore!
|
// FIXME: this mechanism will later not be necessary anymore!
|
||||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||||
@ -103,14 +94,10 @@ void *NetworkHttp::mainLoop(void *obj)
|
|||||||
case HC_QUIT:
|
case HC_QUIT:
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
break;
|
break;
|
||||||
case HC_SLEEP: break;
|
case HC_SLEEP:
|
||||||
|
break;
|
||||||
case HC_NEWS:
|
case HC_NEWS:
|
||||||
const std::string tmp_str = me->downloadToStr("news");
|
me->updateNews();
|
||||||
pthread_mutex_lock(&(me->m_mutex_news));
|
|
||||||
{
|
|
||||||
me->m_news_message = tmp_str;
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&(me->m_mutex_news));
|
|
||||||
break;
|
break;
|
||||||
} // switch(m_command)
|
} // switch(m_command)
|
||||||
} // while !m_abort
|
} // while !m_abort
|
||||||
@ -166,6 +153,21 @@ void NetworkHttp::checkNewServer()
|
|||||||
}
|
}
|
||||||
} // checkNewServer
|
} // checkNewServer
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
/** Updates the 'news' string to be displayed in the main menu.
|
||||||
|
*/
|
||||||
|
void NetworkHttp::updateNews()
|
||||||
|
{
|
||||||
|
const std::string tmp_str = downloadToStr("news");
|
||||||
|
|
||||||
|
pthread_mutex_lock(&m_mutex_news);
|
||||||
|
{
|
||||||
|
// Only lock the actual assignment, not the downloading!
|
||||||
|
m_news_message = tmp_str;
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&m_mutex_news);
|
||||||
|
} // updateNews
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** Returns the last loaded news message (using mutex to make sure a valid
|
/** Returns the last loaded news message (using mutex to make sure a valid
|
||||||
* value is available).
|
* value is available).
|
||||||
|
@ -59,6 +59,8 @@ private:
|
|||||||
static void *mainLoop(void *obj);
|
static void *mainLoop(void *obj);
|
||||||
void checkNewServer();
|
void checkNewServer();
|
||||||
|
|
||||||
|
void updateNews();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NetworkHttp();
|
NetworkHttp();
|
||||||
~NetworkHttp();
|
~NetworkHttp();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="Windows-1252"?>
|
<?xml version="1.0" encoding="Windows-1252"?>
|
||||||
<VisualStudioProject
|
<VisualStudioProject
|
||||||
ProjectType="Visual C++"
|
ProjectType="Visual C++"
|
||||||
Version="9,00"
|
Version="9.00"
|
||||||
Name="supertuxkart"
|
Name="supertuxkart"
|
||||||
ProjectGUID="{B1BC2764-1A43-4800-A654-788B0D05EDA2}"
|
ProjectGUID="{B1BC2764-1A43-4800-A654-788B0D05EDA2}"
|
||||||
RootNamespace="supertuxkart"
|
RootNamespace="supertuxkart"
|
||||||
|
@ -18,23 +18,23 @@
|
|||||||
#ifdef ADDONS_MANAGER
|
#ifdef ADDONS_MANAGER
|
||||||
|
|
||||||
#include "states_screens/addons_screen.hpp"
|
#include "states_screens/addons_screen.hpp"
|
||||||
#include "states_screens/addons_update_screen.hpp"
|
|
||||||
#include "states_screens/dialogs/addons_loading.hpp"
|
|
||||||
|
|
||||||
#include "guiengine/widget.hpp"
|
|
||||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
|
||||||
#include "guiengine/widgets.hpp"
|
|
||||||
#include "states_screens/state_manager.hpp"
|
|
||||||
#include "addons/network.hpp"
|
|
||||||
#include "guiengine/CGUISpriteBank.h"
|
|
||||||
#include "addons/addons.hpp"
|
|
||||||
#include "io/file_manager.hpp"
|
|
||||||
|
|
||||||
#include "irrlicht.h"
|
|
||||||
/*pthread aren't supported natively by windows. Here a port: http://sourceware.org/pthreads-win32/ */
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "irrlicht.h"
|
||||||
|
|
||||||
|
#include "addons/addons.hpp"
|
||||||
|
#include "addons/network.hpp"
|
||||||
|
#include "guiengine/widget.hpp"
|
||||||
|
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||||
|
#include "guiengine/CGUISpriteBank.h"
|
||||||
|
#include "io/file_manager.hpp"
|
||||||
|
#include "states_screens/addons_update_screen.hpp"
|
||||||
|
#include "states_screens/dialogs/addons_loading.hpp"
|
||||||
|
#include "states_screens/state_manager.hpp"
|
||||||
|
|
||||||
|
|
||||||
DEFINE_SCREEN_SINGLETON( AddonsScreen );
|
DEFINE_SCREEN_SINGLETON( AddonsScreen );
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------------
|
||||||
@ -49,51 +49,61 @@ void AddonsScreen::loadedFromFile()
|
|||||||
{
|
{
|
||||||
|
|
||||||
video::ITexture* icon1 = irr_driver->getTexture( file_manager->getGUIDir()
|
video::ITexture* icon1 = irr_driver->getTexture( file_manager->getGUIDir()
|
||||||
+ "/package.png" );
|
+ "/package.png" );
|
||||||
video::ITexture* icon2 = irr_driver->getTexture( file_manager->getGUIDir()
|
video::ITexture* icon2 = irr_driver->getTexture( file_manager->getGUIDir()
|
||||||
+ "/no-package.png" );
|
+ "/no-package.png" );
|
||||||
video::ITexture* icon3 = irr_driver->getTexture( file_manager->getGUIDir()
|
video::ITexture* icon3 = irr_driver->getTexture( file_manager->getGUIDir()
|
||||||
+ "/package-update.png" );
|
+ "/package-update.png" );
|
||||||
|
|
||||||
m_icon_bank = new irr::gui::STKModifiedSpriteBank( GUIEngine::getGUIEnv() );
|
m_icon_bank = new irr::gui::STKModifiedSpriteBank( GUIEngine::getGUIEnv());
|
||||||
m_icon_bank->addTextureAsSprite(icon1);
|
m_icon_bank->addTextureAsSprite(icon1);
|
||||||
m_icon_bank->addTextureAsSprite(icon2);
|
m_icon_bank->addTextureAsSprite(icon2);
|
||||||
m_icon_bank->addTextureAsSprite(icon3);
|
m_icon_bank->addTextureAsSprite(icon3);
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void AddonsScreen::loadList()
|
void AddonsScreen::loadList()
|
||||||
{
|
{
|
||||||
std::cout << "load list" << std::endl;
|
std::cout << "load list" << std::endl;
|
||||||
GUIEngine::ListWidget* w_list = this->getWidget<GUIEngine::ListWidget>("list_addons");
|
GUIEngine::ListWidget* w_list =
|
||||||
|
getWidget<GUIEngine::ListWidget>("list_addons");
|
||||||
w_list->clear();
|
w_list->clear();
|
||||||
addons_manager->resetIndex();
|
addons_manager->resetIndex();
|
||||||
//w_list->addItem("kart", _("Karts:"), -1 /* no icon */);
|
//w_list->addItem("kart", _("Karts:"), -1 /* no icon */);
|
||||||
while(addons_manager->NextType(this->type))
|
while(addons_manager->nextType(m_type))
|
||||||
{
|
{
|
||||||
std::cout << addons_manager->GetName() << std::endl;
|
std::cout << addons_manager->getName() << std::endl;
|
||||||
if(addons_manager->IsInstalledAsBool() && addons_manager->GetInstalledVersion() < addons_manager->GetVersion())
|
if(addons_manager->isInstalledAsBool() &&
|
||||||
w_list->addItem(addons_manager->GetIdAsStr().c_str(),
|
addons_manager->getInstalledVersion() < addons_manager->getVersion())
|
||||||
addons_manager->GetName().c_str(), 2 /* icon installed */);
|
{
|
||||||
else if(addons_manager->IsInstalledAsBool())
|
w_list->addItem(addons_manager->getIdAsStr().c_str(),
|
||||||
w_list->addItem(addons_manager->GetIdAsStr().c_str(),
|
addons_manager->getName().c_str(), 2 /* icon installed */);
|
||||||
addons_manager->GetName().c_str(), 0 /* icon installed */);
|
}
|
||||||
|
else if(addons_manager->isInstalledAsBool())
|
||||||
|
{
|
||||||
|
w_list->addItem(addons_manager->getIdAsStr().c_str(),
|
||||||
|
addons_manager->getName().c_str(), 0 /* icon installed */);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
w_list->addItem(addons_manager->GetIdAsStr().c_str(),
|
{
|
||||||
addons_manager->GetName().c_str(), 1 /* icon unsinstalled*/);
|
w_list->addItem(addons_manager->getIdAsStr().c_str(),
|
||||||
|
addons_manager->getName().c_str(), 1 /* icon unsinstalled*/);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->can_load_list = false;
|
m_can_load_list = false;
|
||||||
this->getWidget<GUIEngine::RibbonWidget>("category")->setActivated();
|
getWidget<GUIEngine::RibbonWidget>("category")->setActivated();
|
||||||
this->getWidget<GUIEngine::LabelWidget>("update_status")->setText("");
|
getWidget<GUIEngine::LabelWidget>("update_status")->setText("");
|
||||||
if(type == "kart")
|
if(m_type == "kart")
|
||||||
this->getWidget<GUIEngine::RibbonWidget>("category")->select("tab_kart", PLAYER_ID_GAME_MASTER);
|
getWidget<GUIEngine::RibbonWidget>("category")->select("tab_kart",
|
||||||
else if(type == "track")
|
PLAYER_ID_GAME_MASTER);
|
||||||
this->getWidget<GUIEngine::RibbonWidget>("category")->select("tab_track", PLAYER_ID_GAME_MASTER);
|
else if(m_type == "track")
|
||||||
|
getWidget<GUIEngine::RibbonWidget>("category")->select("tab_track",
|
||||||
|
PLAYER_ID_GAME_MASTER);
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void AddonsScreen::eventCallback(GUIEngine::Widget* widget, const std::string& name, const int playerID)
|
void AddonsScreen::eventCallback(GUIEngine::Widget* widget,
|
||||||
|
const std::string& name, const int playerID)
|
||||||
{
|
{
|
||||||
if (name == "back")
|
if (name == "back")
|
||||||
{
|
{
|
||||||
@ -102,71 +112,77 @@ void AddonsScreen::eventCallback(GUIEngine::Widget* widget, const std::string& n
|
|||||||
|
|
||||||
else if (name == "list_addons")
|
else if (name == "list_addons")
|
||||||
{
|
{
|
||||||
GUIEngine::ListWidget* list = this->getWidget<GUIEngine::ListWidget>("list_addons");
|
GUIEngine::ListWidget* list =
|
||||||
|
getWidget<GUIEngine::ListWidget>("list_addons");
|
||||||
std::string addons = list->getSelectionInternalName();
|
std::string addons = list->getSelectionInternalName();
|
||||||
|
|
||||||
addons_manager->SelectId(addons);
|
addons_manager->selectId(addons);
|
||||||
this->load = new AddonsLoading(0.8f, 0.8f);
|
m_load = new AddonsLoading(0.8f, 0.8f);
|
||||||
}
|
}
|
||||||
if (name == "category")
|
if (name == "category")
|
||||||
{
|
{
|
||||||
std::string selection = ((GUIEngine::RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER).c_str();
|
std::string selection = ((GUIEngine::RibbonWidget*)widget)
|
||||||
|
->getSelectionIDString(PLAYER_ID_GAME_MASTER).c_str();
|
||||||
std::cout << selection << std::endl;
|
std::cout << selection << std::endl;
|
||||||
if (selection == "tab_update") StateManager::get()->replaceTopMostScreen(AddonsUpdateScreen::getInstance());
|
if (selection == "tab_update")
|
||||||
|
StateManager::get()->replaceTopMostScreen(AddonsUpdateScreen::getInstance());
|
||||||
else if (selection == "tab_track")
|
else if (selection == "tab_track")
|
||||||
{
|
{
|
||||||
this->type = "track";
|
m_type = "track";
|
||||||
loadList();
|
loadList();
|
||||||
}
|
}
|
||||||
else if (selection == "tab_kart")
|
else if (selection == "tab_kart")
|
||||||
{
|
{
|
||||||
this->type = "kart";
|
m_type = "kart";
|
||||||
loadList();
|
loadList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void AddonsScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
|
void AddonsScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&(this->mutex));
|
pthread_mutex_lock(&m_mutex);
|
||||||
if(this->can_load_list)
|
if(m_can_load_list)
|
||||||
{
|
{
|
||||||
this->loadList();
|
loadList();
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&(this->mutex));
|
pthread_mutex_unlock(&m_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void AddonsScreen::init()
|
void AddonsScreen::init()
|
||||||
{
|
{
|
||||||
Screen::init();
|
Screen::init();
|
||||||
this->getWidget<GUIEngine::RibbonWidget>("category")->setDeactivated();
|
getWidget<GUIEngine::RibbonWidget>("category")->setDeactivated();
|
||||||
this->type = "kart";
|
m_type = "kart";
|
||||||
|
|
||||||
pthread_mutex_init(&(this->mutex), NULL);
|
pthread_mutex_init(&m_mutex, NULL);
|
||||||
std::cout << "[Addons] Using directory <" + file_manager->getAddonsDir() << ">\n";
|
std::cout << "[Addons] Using directory <" + file_manager->getAddonsDir()
|
||||||
GUIEngine::ListWidget* w_list = this->getWidget<GUIEngine::ListWidget>("list_addons");
|
<< ">\n";
|
||||||
|
GUIEngine::ListWidget* w_list =
|
||||||
|
getWidget<GUIEngine::ListWidget>("list_addons");
|
||||||
w_list->setIcons(m_icon_bank);
|
w_list->setIcons(m_icon_bank);
|
||||||
//w_list->clear();
|
//w_list->clear();
|
||||||
std::cout << "icon bank" << std::endl;
|
std::cout << "icon bank" << std::endl;
|
||||||
this->can_load_list = false;
|
m_can_load_list = false;
|
||||||
|
|
||||||
this->getWidget<GUIEngine::LabelWidget>("update_status")->setText(_("Updating the list..."));
|
getWidget<GUIEngine::LabelWidget>("update_status")
|
||||||
|
->setText(_("Updating the list..."));
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
pthread_create(&thread, NULL, &AddonsScreen::downloadList, this);
|
pthread_create(&thread, NULL, &AddonsScreen::downloadList, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void * AddonsScreen::downloadList( void * pthis)
|
void *AddonsScreen::downloadList( void *pthis)
|
||||||
{
|
{
|
||||||
AddonsScreen * pt = (AddonsScreen*)pthis;
|
AddonsScreen *pt = (AddonsScreen*)pthis;
|
||||||
pthread_mutex_lock(&(pt->mutex));
|
pthread_mutex_lock(&(pt->m_mutex));
|
||||||
pt->can_load_list = true;
|
pt->m_can_load_list = true;
|
||||||
pthread_mutex_unlock(&(pt->mutex));
|
pthread_mutex_unlock(&(pt->m_mutex));
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,14 @@
|
|||||||
#ifndef HEADER_ADDONS_SCREEN_HPP
|
#ifndef HEADER_ADDONS_SCREEN_HPP
|
||||||
#define HEADER_ADDONS_SCREEN_HPP
|
#define HEADER_ADDONS_SCREEN_HPP
|
||||||
|
|
||||||
#include "guiengine/screen.hpp"
|
|
||||||
#include "states_screens/dialogs/addons_loading.hpp"
|
|
||||||
#include "addons/addons.hpp"
|
|
||||||
#include "guiengine/widgets/label_widget.hpp"
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "irrlicht.h"
|
#include "irrlicht.h"
|
||||||
|
|
||||||
|
#include "addons/addons.hpp"
|
||||||
|
#include "guiengine/screen.hpp"
|
||||||
|
#include "guiengine/widgets/label_widget.hpp"
|
||||||
|
#include "states_screens/dialogs/addons_loading.hpp"
|
||||||
|
|
||||||
/* used for the installed/unsinstalled icons*/
|
/* used for the installed/unsinstalled icons*/
|
||||||
namespace irr { namespace gui { class STKModifiedSpriteBank; } }
|
namespace irr { namespace gui { class STKModifiedSpriteBank; } }
|
||||||
|
|
||||||
@ -35,23 +37,26 @@ namespace GUIEngine { class Widget; }
|
|||||||
* \brief Addons screen
|
* \brief Addons screen
|
||||||
* \ingroup states_screens
|
* \ingroup states_screens
|
||||||
*/
|
*/
|
||||||
class AddonsScreen : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<AddonsScreen>
|
class AddonsScreen : public GUIEngine::Screen,
|
||||||
|
public GUIEngine::ScreenSingleton<AddonsScreen>
|
||||||
{
|
{
|
||||||
friend class GUIEngine::ScreenSingleton<AddonsScreen>;
|
friend class GUIEngine::ScreenSingleton<AddonsScreen>;
|
||||||
|
|
||||||
AddonsScreen();
|
AddonsScreen();
|
||||||
Addons * addons;
|
Addons *m_addons;
|
||||||
AddonsLoading * load;
|
AddonsLoading *m_load;
|
||||||
void loadInformations();
|
void loadInformations();
|
||||||
/** For the addons list, a package when it is installed. */
|
/** For the addons list, a package when it is installed. */
|
||||||
irr::gui::STKModifiedSpriteBank* m_icon_bank;
|
irr::gui::STKModifiedSpriteBank
|
||||||
GUIEngine::LabelWidget* m_update_status;
|
*m_icon_bank;
|
||||||
|
GUIEngine::LabelWidget
|
||||||
|
*m_update_status;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bool can_load_list;
|
bool m_can_load_list;
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t m_mutex;
|
||||||
std::string type;
|
std::string m_type;
|
||||||
|
|
||||||
/** Load the addons into the main list.*/
|
/** Load the addons into the main list.*/
|
||||||
void loadList();
|
void loadList();
|
||||||
@ -65,10 +70,9 @@ public:
|
|||||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||||
virtual void init();
|
virtual void init();
|
||||||
|
|
||||||
friend void * startInstall(void *);
|
friend void *startInstall(void *);
|
||||||
|
|
||||||
/** This function is used to download a text from the server to show the news. */
|
static void *downloadList(void *);
|
||||||
static void * downloadList(void *);
|
|
||||||
|
|
||||||
/** This function is used to handle the thread (load the new list, etc...). */
|
/** This function is used to handle the thread (load the new list, etc...). */
|
||||||
virtual void onUpdate(float delta, irr::video::IVideoDriver*);
|
virtual void onUpdate(float delta, irr::video::IVideoDriver*);
|
||||||
|
@ -50,7 +50,9 @@ void AddonsUpdateScreen::loadedFromFile()
|
|||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
void AddonsUpdateScreen::eventCallback(GUIEngine::Widget* widget, const std::string& name, const int playerID)
|
void AddonsUpdateScreen::eventCallback(GUIEngine::Widget* widget,
|
||||||
|
const std::string& name,
|
||||||
|
const int playerID)
|
||||||
{
|
{
|
||||||
if (name == "back")
|
if (name == "back")
|
||||||
{
|
{
|
||||||
@ -58,11 +60,11 @@ void AddonsUpdateScreen::eventCallback(GUIEngine::Widget* widget, const std::str
|
|||||||
}
|
}
|
||||||
else if (name == "list_addons")
|
else if (name == "list_addons")
|
||||||
{
|
{
|
||||||
GUIEngine::ListWidget* list = this->getWidget<GUIEngine::ListWidget>("list_addons");
|
GUIEngine::ListWidget* list = getWidget<GUIEngine::ListWidget>("list_addons");
|
||||||
std::string addons = list->getSelectionInternalName();
|
std::string addons = list->getSelectionInternalName();
|
||||||
|
|
||||||
addons_manager->SelectId(addons);
|
addons_manager->selectId(addons);
|
||||||
this->load = new AddonsLoading(0.8f, 0.8f);
|
m_load = new AddonsLoading(0.8f, 0.8f);
|
||||||
}
|
}
|
||||||
else if (name == "category")
|
else if (name == "category")
|
||||||
{
|
{
|
||||||
@ -71,13 +73,13 @@ void AddonsUpdateScreen::eventCallback(GUIEngine::Widget* widget, const std::str
|
|||||||
if (selection == "tab_track")
|
if (selection == "tab_track")
|
||||||
{
|
{
|
||||||
StateManager::get()->replaceTopMostScreen(AddonsScreen::getInstance());
|
StateManager::get()->replaceTopMostScreen(AddonsScreen::getInstance());
|
||||||
AddonsScreen::getInstance()->type = "track";
|
AddonsScreen::getInstance()->m_type = "track";
|
||||||
AddonsScreen::getInstance()->loadList();
|
AddonsScreen::getInstance()->loadList();
|
||||||
}
|
}
|
||||||
else if (selection == "tab_kart")
|
else if (selection == "tab_kart")
|
||||||
{
|
{
|
||||||
StateManager::get()->replaceTopMostScreen(AddonsScreen::getInstance());
|
StateManager::get()->replaceTopMostScreen(AddonsScreen::getInstance());
|
||||||
AddonsScreen::getInstance()->type = "kart";
|
AddonsScreen::getInstance()->m_type = "kart";
|
||||||
AddonsScreen::getInstance()->loadList();
|
AddonsScreen::getInstance()->loadList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,13 +96,14 @@ void AddonsUpdateScreen::init()
|
|||||||
w_list->clear();
|
w_list->clear();
|
||||||
addons_manager->resetIndex();
|
addons_manager->resetIndex();
|
||||||
//w_list->addItem("kart", _("Karts:"), -1 /* no icon */);
|
//w_list->addItem("kart", _("Karts:"), -1 /* no icon */);
|
||||||
while(addons_manager->Next())
|
while(addons_manager->next())
|
||||||
{
|
{
|
||||||
if(addons_manager->IsInstalledAsBool() && addons_manager->GetInstalledVersion() < addons_manager->GetVersion())
|
if(addons_manager->isInstalledAsBool() &&
|
||||||
|
addons_manager->getInstalledVersion() < addons_manager->getVersion())
|
||||||
{
|
{
|
||||||
std::cout << addons_manager->GetName() << std::endl;
|
std::cout << addons_manager->getName() << std::endl;
|
||||||
w_list->addItem(addons_manager->GetIdAsStr().c_str(),
|
w_list->addItem(addons_manager->getIdAsStr().c_str(),
|
||||||
addons_manager->GetName().c_str(), 0);
|
addons_manager->getName().c_str(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,9 +34,9 @@ class AddonsUpdateScreen : public GUIEngine::Screen, public GUIEngine::ScreenSin
|
|||||||
{
|
{
|
||||||
friend class GUIEngine::ScreenSingleton<AddonsUpdateScreen>;
|
friend class GUIEngine::ScreenSingleton<AddonsUpdateScreen>;
|
||||||
AddonsUpdateScreen();
|
AddonsUpdateScreen();
|
||||||
Addons * addons;
|
Addons *m_addons;
|
||||||
/*uneeded*/
|
/*uneeded*/
|
||||||
AddonsLoading * load;
|
AddonsLoading *m_load;
|
||||||
void loadInformations();
|
void loadInformations();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -47,29 +47,32 @@ AddonsLoading::AddonsLoading(const float w, const float h) :
|
|||||||
pthread_mutex_init(&m_mutex_can_install, NULL);
|
pthread_mutex_init(&m_mutex_can_install, NULL);
|
||||||
|
|
||||||
/*Init the icon here to be able to load a single image*/
|
/*Init the icon here to be able to load a single image*/
|
||||||
icon = this->getWidget<IconButtonWidget>("icon");
|
icon = getWidget<IconButtonWidget>("icon");
|
||||||
|
|
||||||
name = this->getWidget<LabelWidget>("name");
|
name = getWidget<LabelWidget>("name");
|
||||||
|
|
||||||
description = this->getWidget<LabelWidget>("description");
|
description = getWidget<LabelWidget>("description");
|
||||||
|
|
||||||
version = this->getWidget<LabelWidget>("version");
|
version = getWidget<LabelWidget>("version");
|
||||||
|
|
||||||
if(addons_manager->IsInstalledAsBool())
|
if(addons_manager->isInstalledAsBool())
|
||||||
{
|
{
|
||||||
if(addons_manager->GetInstalledVersion() < addons_manager->GetVersion())
|
if(addons_manager->getInstalledVersion() < addons_manager->getVersion())
|
||||||
this->getWidget<ButtonWidget>("install")->setLabel(_("Update"));
|
getWidget<ButtonWidget>("install")->setLabel(_("Update"));
|
||||||
else
|
else
|
||||||
this->getWidget<ButtonWidget>("install")->setLabel(_("Uninstall"));
|
getWidget<ButtonWidget>("install")->setLabel(_("Uninstall"));
|
||||||
}
|
}
|
||||||
|
|
||||||
this->loadInfo();
|
loadInfo();
|
||||||
}
|
}
|
||||||
void AddonsLoading::loadInfo()
|
void AddonsLoading::loadInfo()
|
||||||
{
|
{
|
||||||
name->setText(StringUtils::insertValues(_("Name: %i"), addons_manager->GetName().c_str()));
|
name->setText(StringUtils::insertValues(_("Name: %i"),
|
||||||
description->setText(StringUtils::insertValues(_("Description: %i"), addons_manager->GetDescription().c_str()));
|
addons_manager->getName().c_str()));
|
||||||
version->setText(StringUtils::insertValues(_("Version: %i"), addons_manager->GetVersionAsStr().c_str()));
|
description->setText(StringUtils::insertValues(_("Description: %i"),
|
||||||
|
addons_manager->getDescription().c_str()));
|
||||||
|
version->setText(StringUtils::insertValues(_("Version: %i"),
|
||||||
|
addons_manager->getVersionAsStr().c_str()));
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
pthread_create(&thread, NULL, &AddonsLoading::downloadIcon, this);
|
pthread_create(&thread, NULL, &AddonsLoading::downloadIcon, this);
|
||||||
}
|
}
|
||||||
@ -79,8 +82,8 @@ void * AddonsLoading::downloadIcon( void * pthis)
|
|||||||
{
|
{
|
||||||
AddonsLoading * pt = (AddonsLoading*)pthis;
|
AddonsLoading * pt = (AddonsLoading*)pthis;
|
||||||
|
|
||||||
std::string iconPath = "icon/" + addons_manager->GetIcon();
|
std::string iconPath = "icon/" + addons_manager->getIcon();
|
||||||
if (download(iconPath, addons_manager->GetName() + ".png"))
|
if (download(iconPath, addons_manager->getName() + ".png"))
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&(pt->m_mutex_can_install));
|
pthread_mutex_lock(&(pt->m_mutex_can_install));
|
||||||
pt->m_can_load_icon = true;
|
pt->m_can_load_icon = true;
|
||||||
@ -105,13 +108,13 @@ GUIEngine::EventPropagation AddonsLoading::processEvent(const std::string& event
|
|||||||
}
|
}
|
||||||
else if(eventSource == "next")
|
else if(eventSource == "next")
|
||||||
{
|
{
|
||||||
addons_manager->NextType(addons_manager->GetType());
|
addons_manager->nextType(addons_manager->getType());
|
||||||
this->loadInfo();
|
loadInfo();
|
||||||
}
|
}
|
||||||
else if(eventSource == "previous")
|
else if(eventSource == "previous")
|
||||||
{
|
{
|
||||||
addons_manager->PreviousType(addons_manager->GetType());
|
addons_manager->previousType(addons_manager->getType());
|
||||||
this->loadInfo();
|
loadInfo();
|
||||||
}
|
}
|
||||||
if(eventSource == "install")
|
if(eventSource == "install")
|
||||||
{
|
{
|
||||||
@ -138,13 +141,13 @@ GUIEngine::EventPropagation AddonsLoading::processEvent(const std::string& event
|
|||||||
m_widgets.push_back(m_state);
|
m_widgets.push_back(m_state);
|
||||||
m_state->add();
|
m_state->add();
|
||||||
|
|
||||||
this->getWidget<ButtonWidget>("cancel")->setDeactivated();
|
getWidget<ButtonWidget>("cancel")->setDeactivated();
|
||||||
//FIXME : re-implement this buttons
|
//FIXME : re-implement this buttons
|
||||||
/*
|
/*
|
||||||
m_next->setDeactivated();
|
m_next->setDeactivated();
|
||||||
m_previous->setDeactivated();
|
m_previous->setDeactivated();
|
||||||
*/
|
*/
|
||||||
this->getWidget<ButtonWidget>("install")->setDeactivated();
|
getWidget<ButtonWidget>("install")->setDeactivated();
|
||||||
m_percent_update = true;
|
m_percent_update = true;
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
pthread_create(&thread, NULL, &AddonsLoading::startInstall, this);
|
pthread_create(&thread, NULL, &AddonsLoading::startInstall, this);
|
||||||
@ -158,7 +161,7 @@ void AddonsLoading::onUpdate(float delta)
|
|||||||
pthread_mutex_lock(&(m_mutex_can_install));
|
pthread_mutex_lock(&(m_mutex_can_install));
|
||||||
if(m_can_install)
|
if(m_can_install)
|
||||||
{
|
{
|
||||||
this->close();
|
close();
|
||||||
}
|
}
|
||||||
if(m_percent_update)
|
if(m_percent_update)
|
||||||
{
|
{
|
||||||
@ -167,7 +170,9 @@ void AddonsLoading::onUpdate(float delta)
|
|||||||
}
|
}
|
||||||
if(m_can_load_icon)
|
if(m_can_load_icon)
|
||||||
{
|
{
|
||||||
icon->setImage(std::string(file_manager->getConfigDir() + "/" + addons_manager->GetName() + ".png").c_str(), IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
|
icon->setImage( (file_manager->getConfigDir() + "/"
|
||||||
|
+ addons_manager->getName() + ".png").c_str(),
|
||||||
|
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&(m_mutex_can_install));
|
pthread_mutex_unlock(&(m_mutex_can_install));
|
||||||
}
|
}
|
||||||
@ -177,9 +182,9 @@ void AddonsLoading::close()
|
|||||||
{
|
{
|
||||||
|
|
||||||
AddonsScreen* curr_screen = AddonsScreen::getInstance();
|
AddonsScreen* curr_screen = AddonsScreen::getInstance();
|
||||||
pthread_mutex_lock(&(((AddonsScreen*)curr_screen)->mutex));
|
pthread_mutex_lock(&(((AddonsScreen*)curr_screen)->m_mutex));
|
||||||
((AddonsScreen*)curr_screen)->can_load_list = true;
|
((AddonsScreen*)curr_screen)->m_can_load_list = true;
|
||||||
pthread_mutex_unlock(&(((AddonsScreen*)curr_screen)->mutex));
|
pthread_mutex_unlock(&(((AddonsScreen*)curr_screen)->m_mutex));
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------------
|
||||||
@ -187,13 +192,13 @@ void AddonsLoading::close()
|
|||||||
void * AddonsLoading::startInstall(void* pthis)
|
void * AddonsLoading::startInstall(void* pthis)
|
||||||
{
|
{
|
||||||
AddonsLoading * obj = (AddonsLoading*)pthis;
|
AddonsLoading * obj = (AddonsLoading*)pthis;
|
||||||
if(!addons_manager->IsInstalledAsBool() || addons_manager->NeedUpdate())
|
if(!addons_manager->isInstalledAsBool() || addons_manager->needUpdate())
|
||||||
{
|
{
|
||||||
addons_manager->Install();
|
addons_manager->install();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
addons_manager->UnInstall();
|
addons_manager->uninstall();
|
||||||
}
|
}
|
||||||
pthread_mutex_lock(&(obj->m_mutex_can_install));
|
pthread_mutex_lock(&(obj->m_mutex_can_install));
|
||||||
obj->m_can_install = true;
|
obj->m_can_install = true;
|
||||||
|
@ -19,13 +19,11 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
//#ifdef ADDONS_MANAGER
|
|
||||||
//# include <pthread.h>
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||||
#include "input/device_manager.hpp"
|
#include "input/device_manager.hpp"
|
||||||
#include "input/input_manager.hpp"
|
#include "input/input_manager.hpp"
|
||||||
|
#include "io/file_manager.hpp"
|
||||||
#include "karts/kart_properties_manager.hpp"
|
#include "karts/kart_properties_manager.hpp"
|
||||||
#include "main_loop.hpp"
|
#include "main_loop.hpp"
|
||||||
#include "states_screens/challenges.hpp"
|
#include "states_screens/challenges.hpp"
|
||||||
@ -35,7 +33,6 @@
|
|||||||
#include "states_screens/options_screen_video.hpp"
|
#include "states_screens/options_screen_video.hpp"
|
||||||
#include "states_screens/addons_screen.hpp"
|
#include "states_screens/addons_screen.hpp"
|
||||||
#include "states_screens/state_manager.hpp"
|
#include "states_screens/state_manager.hpp"
|
||||||
#include "io/file_manager.hpp"
|
|
||||||
|
|
||||||
//FIXME : remove, temporary tutorial test
|
//FIXME : remove, temporary tutorial test
|
||||||
#include "states_screens/tutorial_screen.hpp"
|
#include "states_screens/tutorial_screen.hpp"
|
||||||
@ -100,7 +97,6 @@ void MainMenuScreen::init()
|
|||||||
// ------------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------------
|
||||||
void MainMenuScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
|
void MainMenuScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
|
||||||
{
|
{
|
||||||
//FIXME:very bad for performance
|
|
||||||
LabelWidget* w = this->getWidget<LabelWidget>("info_addons");
|
LabelWidget* w = this->getWidget<LabelWidget>("info_addons");
|
||||||
const std::string &news_text = network_http->getNewsMessage();
|
const std::string &news_text = network_http->getNewsMessage();
|
||||||
if(news_text == "")
|
if(news_text == "")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user