[Addons] an addon object isn't passed to the dialog anymore, it is stupid since addons_manager is extern.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6484 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
23143a4018
commit
16b742358c
@ -106,7 +106,7 @@ void AddonsScreen::eventCallback(GUIEngine::Widget* widget, const std::string& n
|
||||
std::string addons = list->getSelectionInternalName();
|
||||
|
||||
addons_manager->SelectId(addons);
|
||||
this->load = new AddonsLoading(addons_manager, 0.8f, 0.8f);
|
||||
this->load = new AddonsLoading(0.8f, 0.8f);
|
||||
}
|
||||
if (name == "category")
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ void AddonsUpdateScreen::eventCallback(GUIEngine::Widget* widget, const std::str
|
||||
std::string addons = list->getSelectionInternalName();
|
||||
|
||||
addons_manager->SelectId(addons);
|
||||
this->load = new AddonsLoading(addons_manager, 0.8f, 0.8f);
|
||||
this->load = new AddonsLoading(0.8f, 0.8f);
|
||||
}
|
||||
else if (name == "category")
|
||||
{
|
||||
|
@ -37,11 +37,10 @@ using namespace irr::gui;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
|
||||
AddonsLoading::AddonsLoading(Addons * id, const float w, const float h) :
|
||||
AddonsLoading::AddonsLoading(const float w, const float h) :
|
||||
ModalDialog(w, h)
|
||||
{
|
||||
loadFromFile("addons_view_dialog.stkgui");
|
||||
this->addons = id;
|
||||
m_can_install = false;
|
||||
m_can_load_icon = false;
|
||||
m_percent_update = false;
|
||||
@ -56,7 +55,7 @@ AddonsLoading::AddonsLoading(Addons * id, const float w, const float h) :
|
||||
|
||||
version = this->getWidget<LabelWidget>("version");
|
||||
|
||||
if(this->addons->IsInstalledAsBool())
|
||||
if(addons_manager->IsInstalledAsBool())
|
||||
{
|
||||
if(addons_manager->GetInstalledVersion() < addons_manager->GetVersion())
|
||||
this->getWidget<ButtonWidget>("install")->setLabel(_("Update"));
|
||||
@ -68,27 +67,18 @@ AddonsLoading::AddonsLoading(Addons * id, const float w, const float h) :
|
||||
}
|
||||
void AddonsLoading::loadInfo()
|
||||
{
|
||||
|
||||
|
||||
/*I think we can wait a little to have the icon ?*/
|
||||
|
||||
|
||||
|
||||
name->setText(StringUtils::insertValues(_("Name: %i"), this->addons->GetName().c_str()));
|
||||
description->setText(StringUtils::insertValues(_("Description: %i"), this->addons->GetDescription().c_str()));
|
||||
version->setText(StringUtils::insertValues(_("Version: %i"), this->addons->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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
void * AddonsLoading::downloadIcon( void * pthis)
|
||||
{
|
||||
AddonsLoading * pt = (AddonsLoading*)pthis;
|
||||
if(download("icon/" + pt->addons->GetIcon(), pt->addons->GetName() + ".png"))
|
||||
if(download("icon/" + addons_manager->GetIcon(), addons_manager->GetName() + ".png"))
|
||||
{
|
||||
pthread_mutex_lock(&(pt->m_mutex_can_install));
|
||||
pt->m_can_load_icon = true;
|
||||
@ -109,12 +99,12 @@ GUIEngine::EventPropagation AddonsLoading::processEvent(const std::string& event
|
||||
}
|
||||
else if(eventSource == "next")
|
||||
{
|
||||
this->addons->NextType(this->addons->GetType());
|
||||
addons_manager->NextType(addons_manager->GetType());
|
||||
this->loadInfo();
|
||||
}
|
||||
else if(eventSource == "previous")
|
||||
{
|
||||
this->addons->PreviousType(this->addons->GetType());
|
||||
addons_manager->PreviousType(addons_manager->GetType());
|
||||
this->loadInfo();
|
||||
}
|
||||
if(eventSource == "install")
|
||||
@ -166,12 +156,12 @@ void AddonsLoading::onUpdate(float delta)
|
||||
}
|
||||
if(m_percent_update)
|
||||
{
|
||||
m_progress->setValue(addons->getDownloadState());
|
||||
m_state->setText(addons->getDownloadStateAsStr().c_str());
|
||||
m_progress->setValue(addons_manager->getDownloadState());
|
||||
m_state->setText(addons_manager->getDownloadStateAsStr().c_str());
|
||||
}
|
||||
if(m_can_load_icon)
|
||||
{
|
||||
icon->setImage(std::string(file_manager->getConfigDir() + "/" + this->addons->GetName() + ".png").c_str(), IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
|
||||
icon->setImage(std::string(file_manager->getConfigDir() + "/" + addons_manager->GetName() + ".png").c_str(), IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
|
||||
}
|
||||
pthread_mutex_unlock(&(m_mutex_can_install));
|
||||
}
|
||||
@ -191,13 +181,13 @@ void AddonsLoading::close()
|
||||
void * AddonsLoading::startInstall(void* pthis)
|
||||
{
|
||||
AddonsLoading * obj = (AddonsLoading*)pthis;
|
||||
if(!obj->addons->IsInstalledAsBool() or obj->addons->NeedUpdate())
|
||||
if(!addons_manager->IsInstalledAsBool() or addons_manager->NeedUpdate())
|
||||
{
|
||||
obj->addons->Install();
|
||||
addons_manager->Install();
|
||||
}
|
||||
else
|
||||
{
|
||||
obj->addons->UnInstall();
|
||||
addons_manager->UnInstall();
|
||||
}
|
||||
pthread_mutex_lock(&(obj->m_mutex_can_install));
|
||||
obj->m_can_install = true;
|
||||
|
@ -41,21 +41,44 @@ private:
|
||||
GUIEngine::IconButtonWidget * icon;
|
||||
GUIEngine::IconButtonWidget * m_next;
|
||||
GUIEngine::IconButtonWidget * m_previous;
|
||||
|
||||
/**
|
||||
* This function is called when the user click on 'Install', 'Uninstall', or
|
||||
* 'Update'. It is started using a thread.
|
||||
* */
|
||||
static void * startInstall(void*);
|
||||
/**
|
||||
* This function handle the downllading of the addons icon.
|
||||
* It is started using a thread. When it is ended, it change the flag
|
||||
* 'm_can_load_icon' and the onUpdate function reload the icon
|
||||
* */
|
||||
static void * downloadIcon(void*);
|
||||
void loadInfo();
|
||||
|
||||
/* These three bool are some flags.
|
||||
* m_can_install : when the installation is finidhed, onUpdate close the
|
||||
* dialog.
|
||||
* m_percent_update : to reload the download percent
|
||||
* m_can_load_icon see above (function downloadIcon)*/
|
||||
bool m_can_install;
|
||||
bool m_percent_update;
|
||||
bool m_can_load_icon;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Creates a modal dialog with given percentage of screen width and height
|
||||
*/
|
||||
pthread_mutex_t m_mutex_can_install;
|
||||
Addons * addons;
|
||||
AddonsLoading(Addons * id, const float percentWidth, const float percentHeight);
|
||||
AddonsLoading(const float percentWidth, const float percentHeight);
|
||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
|
||||
|
||||
/** This function is called by the GUI, all the frame (or somthing like
|
||||
* that). It checks the flags (m_can_install, m_can_load_icon and
|
||||
* m_percent_update) and do the necessary.
|
||||
* */
|
||||
void onUpdate(float delta);
|
||||
|
||||
/** To close the dialog when the (un)installation is finished.*/
|
||||
void close();
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user