Improve reload feature in addons (see #415)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9779 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
53b5758eee
commit
4f3cbae063
@ -28,6 +28,7 @@
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "states_screens/dialogs/addons_loading.hpp"
|
||||
#include "states_screens/dialogs/message_dialog.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/ptr_vector.hpp"
|
||||
|
||||
@ -54,12 +55,15 @@ void AddonsScreen::loadedFromFile()
|
||||
+ "/package-featured.png");
|
||||
video::ITexture* icon5 = irr_driver->getTexture( file_manager->getGUIDir()
|
||||
+ "/no-package-featured.png");
|
||||
video::ITexture* icon6 = irr_driver->getTexture( file_manager->getGUIDir()
|
||||
+ "/loading.png");
|
||||
|
||||
m_icon_bank = new irr::gui::STKModifiedSpriteBank( GUIEngine::getGUIEnv());
|
||||
m_icon_installed = m_icon_bank->addTextureAsSprite(icon1);
|
||||
m_icon_not_installed = m_icon_bank->addTextureAsSprite(icon2);
|
||||
m_icon_bank->addTextureAsSprite(icon4);
|
||||
m_icon_bank->addTextureAsSprite(icon5);
|
||||
m_icon_loading = m_icon_bank->addTextureAsSprite(icon6);
|
||||
m_icon_needs_update = m_icon_bank->addTextureAsSprite(icon3);
|
||||
|
||||
GUIEngine::ListWidget* w_list = getWidget<GUIEngine::ListWidget>("list_addons");
|
||||
@ -83,6 +87,9 @@ void AddonsScreen::beforeAddingWidget()
|
||||
void AddonsScreen::init()
|
||||
{
|
||||
Screen::init();
|
||||
|
||||
m_reloading = false;
|
||||
|
||||
getWidget<GUIEngine::RibbonWidget>("category")->setDeactivated();
|
||||
|
||||
GUIEngine::getFont()->setTabStop(0.66f);
|
||||
@ -272,9 +279,22 @@ void AddonsScreen::eventCallback(GUIEngine::Widget* widget,
|
||||
|
||||
else if (name == "reload")
|
||||
{
|
||||
network_http->insertReInit();
|
||||
new MessageDialog(_("Please wait while addons are updated, or click the button below to reload in the background."),
|
||||
MessageDialog::MESSAGE_DIALOG_OK, this, false);
|
||||
if (!m_reloading)
|
||||
{
|
||||
m_reloading = true;
|
||||
network_http->insertReInit();
|
||||
//new MessageDialog(_("Please wait while addons are updated, or click the button below to reload in the background."),
|
||||
// MessageDialog::MESSAGE_DIALOG_OK, this, false);
|
||||
|
||||
GUIEngine::ListWidget* w_list =
|
||||
getWidget<GUIEngine::ListWidget>("list_addons");
|
||||
w_list->clear();
|
||||
|
||||
w_list->addItem("spacer", L"");
|
||||
w_list->addItem("loading",
|
||||
_("Please wait while addons are updated"),
|
||||
m_icon_loading);
|
||||
}
|
||||
}
|
||||
|
||||
else if (name == "list_addons")
|
||||
@ -311,20 +331,6 @@ void AddonsScreen::eventCallback(GUIEngine::Widget* widget,
|
||||
}
|
||||
} // eventCallback
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Callback function for the MessageDialog opened by the "reload" button.
|
||||
* The network call to reload the addons list will be under way by the time
|
||||
* function is called, so all it has to do is close two screens (the
|
||||
* MessageDialog itself and the AddonsScreen), returning the player to the
|
||||
* main menu to wait for the addons to be reloaded.
|
||||
*/
|
||||
void AddonsScreen::onCancel() {
|
||||
// Close the MessageDialog
|
||||
MessageDialog::dismiss();
|
||||
// Close the AddonsScreen
|
||||
StateManager::get()->popMenu();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Selects the last selected item on the list (which is the item that
|
||||
* is just being installed) again. This function is used from the
|
||||
@ -344,23 +350,24 @@ void AddonsScreen::setLastSelected()
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void AddonsScreen::onDialogUpdate(float delta)
|
||||
void AddonsScreen::onUpdate(float dt, irr::video::IVideoDriver*)
|
||||
{
|
||||
if (GUIEngine::ModalDialog::isADialogActive())
|
||||
if (m_reloading)
|
||||
{
|
||||
if(UserConfigParams::m_internet_status!=NetworkHttp::IPERM_ALLOWED)
|
||||
{
|
||||
// not allowed to access the net. how did you get to this menu in the first place??
|
||||
GUIEngine::ModalDialog::dismiss();
|
||||
loadList();
|
||||
m_reloading = false;
|
||||
}
|
||||
else if (addons_manager->wasError())
|
||||
{
|
||||
GUIEngine::ModalDialog::dismiss();
|
||||
m_reloading = false;
|
||||
new MessageDialog( _("Sorry, an error occurred while contacting the add-ons website. Make sure you are connected to the Internet and that SuperTuxKart is not blocked by a firewall") );
|
||||
}
|
||||
else if (addons_manager->onlineReady())
|
||||
{
|
||||
GUIEngine::ModalDialog::dismiss();
|
||||
m_reloading = false;
|
||||
loadList();
|
||||
}
|
||||
else
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "guiengine/screen.hpp"
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
#include "states_screens/dialogs/addons_loading.hpp"
|
||||
#include "states_screens/dialogs/message_dialog.hpp"
|
||||
|
||||
/* used for the installed/unsinstalled icons*/
|
||||
namespace irr { namespace gui { class STKModifiedSpriteBank; } }
|
||||
@ -35,8 +34,7 @@ namespace GUIEngine { class Widget; }
|
||||
*/
|
||||
class AddonsScreen : public GUIEngine::Screen,
|
||||
public GUIEngine::ScreenSingleton<AddonsScreen>,
|
||||
public GUIEngine::IListWidgetHeaderListener,
|
||||
public MessageDialog::IConfirmDialogListener
|
||||
public GUIEngine::IListWidgetHeaderListener
|
||||
{
|
||||
friend class GUIEngine::ScreenSingleton<AddonsScreen>;
|
||||
private:
|
||||
@ -50,6 +48,9 @@ private:
|
||||
int m_icon_installed;
|
||||
/** Icon for is not installed yet. */
|
||||
int m_icon_not_installed;
|
||||
/** Icon for 'loading' */
|
||||
int m_icon_loading;
|
||||
|
||||
irr::gui::STKModifiedSpriteBank
|
||||
*m_icon_bank;
|
||||
GUIEngine::LabelWidget
|
||||
@ -63,6 +64,9 @@ private:
|
||||
int m_selected_index;
|
||||
|
||||
float m_icon_height;
|
||||
|
||||
bool m_reloading;
|
||||
|
||||
public:
|
||||
|
||||
/** Load the addons into the main list.*/
|
||||
@ -81,11 +85,9 @@ public:
|
||||
|
||||
virtual void init();
|
||||
virtual void tearDown();
|
||||
|
||||
virtual void onCancel();
|
||||
|
||||
/** \brief callback from IConfirmDialogListener */
|
||||
virtual void onDialogUpdate(float dt);
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void onUpdate(float dt, irr::video::IVideoDriver*);
|
||||
|
||||
void setLastSelected();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user