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:
hikerstk 2010-12-21 22:06:38 +00:00
parent e472d7459c
commit b5837a624b
11 changed files with 328 additions and 295 deletions

View File

@ -44,7 +44,7 @@ Addons* addons_manager = 0;
Addons::Addons()
{
this->index = -1;
m_index = -1;
int download_state = 0;
m_download_state = download_state;
pthread_mutex_init(&m_str_mutex, NULL);
@ -105,30 +105,32 @@ Addons::Addons()
}
addons.type = xml->getNodeName();
addons.installed = false;
this->m_addons_list.push_back(addons);
m_addons_list.push_back(addons);
}
}
}
delete xml;
this->file_installed = file_manager->getConfigDir() + "/" + "addons_installed.xml";
this->GetInstalledAddons();
}
void Addons::resetIndex()
{
this->index = -1;
m_file_installed = file_manager->getConfigDir()
+ "/" + "addons_installed.xml";
getInstalledAddons();
}
// ----------------------------------------------------------------------------
void Addons::GetInstalledAddons()
void Addons::resetIndex()
{
m_index = -1;
}
// ----------------------------------------------------------------------------
void Addons::getInstalledAddons()
{
std::string attribute_name;
int old_index = this->index;
int old_index = m_index;
/* checking for installed addons */
std::cout << "[Addons] Loading an xml file for installed addons: ";
std::cout << this->file_installed << std::endl;
IrrXMLReader* xml = createIrrXMLReader(this->file_installed.c_str());
std::cout << m_file_installed << std::endl;
IrrXMLReader* xml = createIrrXMLReader(m_file_installed.c_str());
// parse the file until end reached
@ -161,10 +163,10 @@ void Addons::GetInstalledAddons()
version = xml->getAttributeValueAsInt("version");
}
}
if(this->SelectId(id))
if(selectId(id))
{
this->m_addons_list[this->index].installed = true;
this->m_addons_list[this->index].installed_version = version;
m_addons_list[m_index].installed = true;
m_addons_list[m_index].installed_version = version;
std::cout << "[Addons] An addon is already installed: " << id << std::endl;
}
else
@ -175,7 +177,7 @@ void Addons::GetInstalledAddons()
addons.installed_version = version;
addons.version = version;
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;
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;
}
this->index = -1;
m_index = -1;
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;
}
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;
}
} // nextType
// ----------------------------------------------------------------------------
bool Addons::Previous()
bool Addons::previous()
{
if(this->index - 1 > 0)
if(m_index - 1 > 0)
{
this->index --;
m_index --;
return true;
}
this->index = this->m_addons_list.size() - 1;
m_index = m_addons_list.size() - 1;
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;
}
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;
}
} // 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 ?
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 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 ?
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 false;
}
} // selectId
// ----------------------------------------------------------------------------
/* 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()
{
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::string Addons::getVersionAsStr() const
{
std::ostringstream os;
os << this->m_addons_list[this->index].id;
os << m_addons_list[m_index].version;
return os.str();
}
} // getVersionAsStr
// ----------------------------------------------------------------------------
int Addons::GetInstalledVersion()
std::string Addons::getIdAsStr() const
{
if(this->m_addons_list[this->index].installed)
return this->m_addons_list[this->index].installed_version;
std::ostringstream os;
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;
}
} // 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;
os << this->m_addons_list[this->index].installed_version;
os << m_addons_list[m_index].installed_version;
return os.str();
}
return "";
}
} // getInstalledVersionAsStr
// ----------------------------------------------------------------------------
void Addons::Install()
void Addons::install()
{
//download of the addons file
@ -327,9 +328,9 @@ void Addons::Install()
m_str_state = "Downloading...";
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,
this->m_addons_list[this->index].name, &m_download_state);
m_addons_list[m_index].name, &m_download_state);
if (!success)
{
@ -338,14 +339,14 @@ void Addons::Install()
return;
}
file_manager->checkAndCreateDirForAddons(this->m_addons_list[this->index].name,
this->m_addons_list[this->index].type + "s/");
file_manager->checkAndCreateDirForAddons(m_addons_list[m_index].name,
m_addons_list[m_index].type + "s/");
//extract the zip in the addons folder called like the addons name
std::string dest_file =file_manager->getAddonsDir() + "/" + "data" + "/" +
this->m_addons_list[this->index].type + "s/" +
this->m_addons_list[this->index].name + "/" ;
std::string from = file_manager->getConfigDir() + "/" + this->m_addons_list[this->index].name;
m_addons_list[m_index].type + "s/" +
m_addons_list[m_index].name + "/" ;
std::string from = file_manager->getConfigDir() + "/" + m_addons_list[m_index].name;
std::string to = dest_file;
pthread_mutex_lock(&m_str_mutex);
@ -360,37 +361,38 @@ void Addons::Install()
return;
}
this->m_addons_list[this->index].installed = true;
this->m_addons_list[this->index].installed_version = this->m_addons_list[this->index].version;
m_addons_list[m_index].installed = true;
m_addons_list[m_index].installed_version = m_addons_list[m_index].version;
pthread_mutex_lock(&m_str_mutex);
m_str_state = "Reloading kart list...";
pthread_mutex_unlock(&m_str_mutex);
this->SaveInstalled();
}
saveInstalled();
} // install
// ----------------------------------------------------------------------------
void Addons::SaveInstalled()
void Addons::saveInstalled()
{
//Put the addons in the xml file
//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
xml_installed << "<?xml version=\"1.0\"?>" << std::endl;
xml_installed << "<addons xmlns='http://stkaddons.tuxfamily.org/'>"
<< 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;
os << this->m_addons_list[i].installed_version;
os << m_addons_list[i].installed_version;
//transform the version (int) in string
xml_installed << "<"+ this->m_addons_list[i].type +" name=\"" +
this->m_addons_list[i].name + "\" id=\"" +
this->m_addons_list[i].id + "\"";
xml_installed << "<"+ m_addons_list[i].type +" name=\"" +
m_addons_list[i].name + "\" id=\"" +
m_addons_list[i].id + "\"";
xml_installed << " version=\"" + os.str() + "\" />" << std::endl;
}
}
@ -398,26 +400,26 @@ void Addons::SaveInstalled()
xml_installed.close();
kart_properties_manager->reLoadAllKarts();
track_manager->loadTrackList();
}
// ----------------------------------------------------------------------------
void Addons::UnInstall()
{
std::cout << "[Addons] Uninstalling <" << this->m_addons_list[this->index].name << ">\n";
} // saveInstalled
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
std::string dest_file = file_manager->getAddonsDir() + "/" + "data" + "/" +
this->m_addons_list[this->index].type + "s/" +
this->m_addons_list[this->index].name + "/";
m_addons_list[m_index].type + "s/" +
m_addons_list[m_index].name + "/";
//remove the addons directory
file_manager->removeDirectory(dest_file.c_str());
this->SaveInstalled();
saveInstalled();
}
} // uninstall
// ----------------------------------------------------------------------------
int Addons::getDownloadState()
{
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);
std::string value = m_str_state;
pthread_mutex_unlock(&m_str_mutex);
return value;
}
} // getDownloadStateAsStr
// ----------------------------------------------------------------------------
bool Addons::NeedUpdate()
bool Addons::needUpdate() const
{
return GetInstalledVersion() < GetVersion();
}
return getInstalledVersion() < getVersion();
} // needUpdate
#endif

View File

@ -41,79 +41,82 @@ class Addons
{
private:
std::vector<addons_prop> m_addons_list;
int index;
std::string file_installed;
void SaveInstalled();
void GetInstalledAddons();
std::string type;
int m_index;
std::string m_file_installed;
void saveInstalled();
void getInstalledAddons();
std::string m_type;
int m_download_state;
pthread_mutex_t m_str_mutex;
mutable pthread_mutex_t m_str_mutex;
std::string m_str_state;
public:
Addons();
/** Select the next addons in the addons list. */
bool Next();
bool next();
/** Select the next addons in the addons list. */
bool Previous();
bool previous();
/** Get all the selected addon parameters. */
addons_prop GetAddons();
addons_prop getAddons();
/** Select an addon with it name. */
bool Select(std::string);
bool select(std::string);
/** Select an addon with it id. */
bool SelectId(std::string);
bool selectId(std::string);
/** 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. */
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. */
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. */
std::string GetVersionAsStr();
std::string getVersionAsStr() const;
/** Get the installed version of the selected addon. */
int GetInstalledVersion();
std::string GetInstalledVersionAsStr();
int getInstalledVersion() const;
std::string getInstalledVersionAsStr() const;
/** 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. */
std::string GetIdAsStr();
std::string getIdAsStr() const;
/** 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. */
void Install();
void install();
/** Uninstall the selected addon. This method will remove all the directory of the addon.*/
void UnInstall();
/** Uninstall the selected addon. This method will remove all the
* directory of the addon.*/
void uninstall();
void resetIndex();
/** 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 IsInstalledAsBool(){ return this->m_addons_list[this->index].installed; };
bool NextType(std::string type);
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...)*/
std::string getDownloadStateAsStr();
std::string getDownloadStateAsStr() const;
};
extern Addons * addons_manager;
extern Addons *addons_manager;
#endif
#endif

View File

@ -77,16 +77,7 @@ void *NetworkHttp::mainLoop(void *obj)
{
NetworkHttp *me=(NetworkHttp*)obj;
me->checkNewServer();
const std::string tmp_str = me->downloadToStr("news");
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));
me->updateNews();
// Allow this thread to be cancelled anytime
// FIXME: this mechanism will later not be necessary anymore!
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
@ -103,14 +94,10 @@ void *NetworkHttp::mainLoop(void *obj)
case HC_QUIT:
pthread_exit(NULL);
break;
case HC_SLEEP: break;
case HC_SLEEP:
break;
case HC_NEWS:
const std::string tmp_str = me->downloadToStr("news");
pthread_mutex_lock(&(me->m_mutex_news));
{
me->m_news_message = tmp_str;
}
pthread_mutex_unlock(&(me->m_mutex_news));
me->updateNews();
break;
} // switch(m_command)
} // while !m_abort
@ -166,6 +153,21 @@ void NetworkHttp::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
* value is available).

View File

@ -59,6 +59,8 @@ private:
static void *mainLoop(void *obj);
void checkNewServer();
void updateNews();
public:
NetworkHttp();
~NetworkHttp();

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Version="9.00"
Name="supertuxkart"
ProjectGUID="{B1BC2764-1A43-4800-A654-788B0D05EDA2}"
RootNamespace="supertuxkart"

View File

@ -18,23 +18,23 @@
#ifdef ADDONS_MANAGER
#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 <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 );
// ------------------------------------------------------------------------------------------------------
@ -49,51 +49,61 @@ void AddonsScreen::loadedFromFile()
{
video::ITexture* icon1 = irr_driver->getTexture( file_manager->getGUIDir()
+ "/package.png" );
+ "/package.png" );
video::ITexture* icon2 = irr_driver->getTexture( file_manager->getGUIDir()
+ "/no-package.png" );
+ "/no-package.png" );
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(icon2);
m_icon_bank->addTextureAsSprite(icon3);
}
// ------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
void AddonsScreen::loadList()
{
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();
addons_manager->resetIndex();
//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;
if(addons_manager->IsInstalledAsBool() && addons_manager->GetInstalledVersion() < addons_manager->GetVersion())
w_list->addItem(addons_manager->GetIdAsStr().c_str(),
addons_manager->GetName().c_str(), 2 /* icon installed */);
else if(addons_manager->IsInstalledAsBool())
w_list->addItem(addons_manager->GetIdAsStr().c_str(),
addons_manager->GetName().c_str(), 0 /* icon installed */);
std::cout << addons_manager->getName() << std::endl;
if(addons_manager->isInstalledAsBool() &&
addons_manager->getInstalledVersion() < addons_manager->getVersion())
{
w_list->addItem(addons_manager->getIdAsStr().c_str(),
addons_manager->getName().c_str(), 2 /* icon installed */);
}
else if(addons_manager->isInstalledAsBool())
{
w_list->addItem(addons_manager->getIdAsStr().c_str(),
addons_manager->getName().c_str(), 0 /* icon installed */);
}
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;
this->getWidget<GUIEngine::RibbonWidget>("category")->setActivated();
this->getWidget<GUIEngine::LabelWidget>("update_status")->setText("");
if(type == "kart")
this->getWidget<GUIEngine::RibbonWidget>("category")->select("tab_kart", PLAYER_ID_GAME_MASTER);
else if(type == "track")
this->getWidget<GUIEngine::RibbonWidget>("category")->select("tab_track", PLAYER_ID_GAME_MASTER);
m_can_load_list = false;
getWidget<GUIEngine::RibbonWidget>("category")->setActivated();
getWidget<GUIEngine::LabelWidget>("update_status")->setText("");
if(m_type == "kart")
getWidget<GUIEngine::RibbonWidget>("category")->select("tab_kart",
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")
{
@ -102,71 +112,77 @@ void AddonsScreen::eventCallback(GUIEngine::Widget* widget, const std::string& n
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();
addons_manager->SelectId(addons);
this->load = new AddonsLoading(0.8f, 0.8f);
addons_manager->selectId(addons);
m_load = new AddonsLoading(0.8f, 0.8f);
}
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;
if (selection == "tab_update") StateManager::get()->replaceTopMostScreen(AddonsUpdateScreen::getInstance());
if (selection == "tab_update")
StateManager::get()->replaceTopMostScreen(AddonsUpdateScreen::getInstance());
else if (selection == "tab_track")
{
this->type = "track";
m_type = "track";
loadList();
}
else if (selection == "tab_kart")
{
this->type = "kart";
m_type = "kart";
loadList();
}
}
}
// ------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
void AddonsScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
{
pthread_mutex_lock(&(this->mutex));
if(this->can_load_list)
pthread_mutex_lock(&m_mutex);
if(m_can_load_list)
{
this->loadList();
loadList();
}
pthread_mutex_unlock(&(this->mutex));
pthread_mutex_unlock(&m_mutex);
}
// ------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
void AddonsScreen::init()
{
Screen::init();
this->getWidget<GUIEngine::RibbonWidget>("category")->setDeactivated();
this->type = "kart";
getWidget<GUIEngine::RibbonWidget>("category")->setDeactivated();
m_type = "kart";
pthread_mutex_init(&(this->mutex), NULL);
std::cout << "[Addons] Using directory <" + file_manager->getAddonsDir() << ">\n";
GUIEngine::ListWidget* w_list = this->getWidget<GUIEngine::ListWidget>("list_addons");
pthread_mutex_init(&m_mutex, NULL);
std::cout << "[Addons] Using directory <" + file_manager->getAddonsDir()
<< ">\n";
GUIEngine::ListWidget* w_list =
getWidget<GUIEngine::ListWidget>("list_addons");
w_list->setIcons(m_icon_bank);
//w_list->clear();
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_create(&thread, NULL, &AddonsScreen::downloadList, this);
}
// ------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
void * AddonsScreen::downloadList( void * pthis)
void *AddonsScreen::downloadList( void *pthis)
{
AddonsScreen * pt = (AddonsScreen*)pthis;
pthread_mutex_lock(&(pt->mutex));
pt->can_load_list = true;
pthread_mutex_unlock(&(pt->mutex));
AddonsScreen *pt = (AddonsScreen*)pthis;
pthread_mutex_lock(&(pt->m_mutex));
pt->m_can_load_list = true;
pthread_mutex_unlock(&(pt->m_mutex));
return NULL;
}

View File

@ -20,12 +20,14 @@
#ifndef 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 "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*/
namespace irr { namespace gui { class STKModifiedSpriteBank; } }
@ -35,23 +37,26 @@ namespace GUIEngine { class Widget; }
* \brief Addons screen
* \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>;
AddonsScreen();
Addons * addons;
AddonsLoading * load;
void loadInformations();
Addons *m_addons;
AddonsLoading *m_load;
void loadInformations();
/** For the addons list, a package when it is installed. */
irr::gui::STKModifiedSpriteBank* m_icon_bank;
GUIEngine::LabelWidget* m_update_status;
irr::gui::STKModifiedSpriteBank
*m_icon_bank;
GUIEngine::LabelWidget
*m_update_status;
public:
bool can_load_list;
pthread_mutex_t mutex;
std::string type;
bool m_can_load_list;
pthread_mutex_t m_mutex;
std::string m_type;
/** Load the addons into the main list.*/
void loadList();
@ -65,10 +70,9 @@ public:
/** \brief implement callback from parent class GUIEngine::Screen */
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...). */
virtual void onUpdate(float delta, irr::video::IVideoDriver*);

View File

@ -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")
{
@ -58,11 +60,11 @@ void AddonsUpdateScreen::eventCallback(GUIEngine::Widget* widget, const std::str
}
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();
addons_manager->SelectId(addons);
this->load = new AddonsLoading(0.8f, 0.8f);
addons_manager->selectId(addons);
m_load = new AddonsLoading(0.8f, 0.8f);
}
else if (name == "category")
{
@ -71,13 +73,13 @@ void AddonsUpdateScreen::eventCallback(GUIEngine::Widget* widget, const std::str
if (selection == "tab_track")
{
StateManager::get()->replaceTopMostScreen(AddonsScreen::getInstance());
AddonsScreen::getInstance()->type = "track";
AddonsScreen::getInstance()->m_type = "track";
AddonsScreen::getInstance()->loadList();
}
else if (selection == "tab_kart")
{
StateManager::get()->replaceTopMostScreen(AddonsScreen::getInstance());
AddonsScreen::getInstance()->type = "kart";
AddonsScreen::getInstance()->m_type = "kart";
AddonsScreen::getInstance()->loadList();
}
}
@ -94,13 +96,14 @@ void AddonsUpdateScreen::init()
w_list->clear();
addons_manager->resetIndex();
//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;
w_list->addItem(addons_manager->GetIdAsStr().c_str(),
addons_manager->GetName().c_str(), 0);
std::cout << addons_manager->getName() << std::endl;
w_list->addItem(addons_manager->getIdAsStr().c_str(),
addons_manager->getName().c_str(), 0);
}
}
}

View File

@ -34,9 +34,9 @@ class AddonsUpdateScreen : public GUIEngine::Screen, public GUIEngine::ScreenSin
{
friend class GUIEngine::ScreenSingleton<AddonsUpdateScreen>;
AddonsUpdateScreen();
Addons * addons;
Addons *m_addons;
/*uneeded*/
AddonsLoading * load;
AddonsLoading *m_load;
void loadInformations();
public:

View File

@ -47,29 +47,32 @@ AddonsLoading::AddonsLoading(const float w, const float h) :
pthread_mutex_init(&m_mutex_can_install, NULL);
/*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())
this->getWidget<ButtonWidget>("install")->setLabel(_("Update"));
if(addons_manager->getInstalledVersion() < addons_manager->getVersion())
getWidget<ButtonWidget>("install")->setLabel(_("Update"));
else
this->getWidget<ButtonWidget>("install")->setLabel(_("Uninstall"));
getWidget<ButtonWidget>("install")->setLabel(_("Uninstall"));
}
this->loadInfo();
loadInfo();
}
void AddonsLoading::loadInfo()
{
name->setText(StringUtils::insertValues(_("Name: %i"), addons_manager->GetName().c_str()));
description->setText(StringUtils::insertValues(_("Description: %i"), addons_manager->GetDescription().c_str()));
version->setText(StringUtils::insertValues(_("Version: %i"), addons_manager->GetVersionAsStr().c_str()));
name->setText(StringUtils::insertValues(_("Name: %i"),
addons_manager->getName().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_create(&thread, NULL, &AddonsLoading::downloadIcon, this);
}
@ -79,8 +82,8 @@ void * AddonsLoading::downloadIcon( void * pthis)
{
AddonsLoading * pt = (AddonsLoading*)pthis;
std::string iconPath = "icon/" + addons_manager->GetIcon();
if (download(iconPath, addons_manager->GetName() + ".png"))
std::string iconPath = "icon/" + addons_manager->getIcon();
if (download(iconPath, addons_manager->getName() + ".png"))
{
pthread_mutex_lock(&(pt->m_mutex_can_install));
pt->m_can_load_icon = true;
@ -105,13 +108,13 @@ GUIEngine::EventPropagation AddonsLoading::processEvent(const std::string& event
}
else if(eventSource == "next")
{
addons_manager->NextType(addons_manager->GetType());
this->loadInfo();
addons_manager->nextType(addons_manager->getType());
loadInfo();
}
else if(eventSource == "previous")
{
addons_manager->PreviousType(addons_manager->GetType());
this->loadInfo();
addons_manager->previousType(addons_manager->getType());
loadInfo();
}
if(eventSource == "install")
{
@ -138,13 +141,13 @@ GUIEngine::EventPropagation AddonsLoading::processEvent(const std::string& event
m_widgets.push_back(m_state);
m_state->add();
this->getWidget<ButtonWidget>("cancel")->setDeactivated();
getWidget<ButtonWidget>("cancel")->setDeactivated();
//FIXME : re-implement this buttons
/*
m_next->setDeactivated();
m_previous->setDeactivated();
*/
this->getWidget<ButtonWidget>("install")->setDeactivated();
getWidget<ButtonWidget>("install")->setDeactivated();
m_percent_update = true;
pthread_t thread;
pthread_create(&thread, NULL, &AddonsLoading::startInstall, this);
@ -158,7 +161,7 @@ void AddonsLoading::onUpdate(float delta)
pthread_mutex_lock(&(m_mutex_can_install));
if(m_can_install)
{
this->close();
close();
}
if(m_percent_update)
{
@ -167,7 +170,9 @@ void AddonsLoading::onUpdate(float delta)
}
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));
}
@ -177,9 +182,9 @@ void AddonsLoading::close()
{
AddonsScreen* curr_screen = AddonsScreen::getInstance();
pthread_mutex_lock(&(((AddonsScreen*)curr_screen)->mutex));
((AddonsScreen*)curr_screen)->can_load_list = true;
pthread_mutex_unlock(&(((AddonsScreen*)curr_screen)->mutex));
pthread_mutex_lock(&(((AddonsScreen*)curr_screen)->m_mutex));
((AddonsScreen*)curr_screen)->m_can_load_list = true;
pthread_mutex_unlock(&(((AddonsScreen*)curr_screen)->m_mutex));
dismiss();
}
// ------------------------------------------------------------------------------------------------------
@ -187,13 +192,13 @@ void AddonsLoading::close()
void * AddonsLoading::startInstall(void* 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
{
addons_manager->UnInstall();
addons_manager->uninstall();
}
pthread_mutex_lock(&(obj->m_mutex_can_install));
obj->m_can_install = true;

View File

@ -19,13 +19,11 @@
#include <iostream>
#include <string>
//#ifdef ADDONS_MANAGER
//# include <pthread.h>
//#endif
#include "guiengine/widgets/ribbon_widget.hpp"
#include "input/device_manager.hpp"
#include "input/input_manager.hpp"
#include "io/file_manager.hpp"
#include "karts/kart_properties_manager.hpp"
#include "main_loop.hpp"
#include "states_screens/challenges.hpp"
@ -35,7 +33,6 @@
#include "states_screens/options_screen_video.hpp"
#include "states_screens/addons_screen.hpp"
#include "states_screens/state_manager.hpp"
#include "io/file_manager.hpp"
//FIXME : remove, temporary tutorial test
#include "states_screens/tutorial_screen.hpp"
@ -100,7 +97,6 @@ void MainMenuScreen::init()
// ------------------------------------------------------------------------------------------------------
void MainMenuScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
{
//FIXME:very bad for performance
LabelWidget* w = this->getWidget<LabelWidget>("info_addons");
const std::string &news_text = network_http->getNewsMessage();
if(news_text == "")