Added message dialog to reload button on Addons screen. Added callback functionality to the OK dialog by adding a message dialog type enum and requiring it in the constructor. See #266

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9532 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
coug36 2011-08-16 08:13:43 +00:00
parent b5f62d9401
commit b85ea2ce9a
6 changed files with 43 additions and 22 deletions

View File

@ -1026,7 +1026,9 @@ int main(int argc, char *argv[] )
new MessageDialog(_("SuperTuxKart may connect to a server "
"to download add-ons and notify you of updates. Would you like this feature to be "
"enabled? (To change this setting at a later time, go to options, select tab "
"'User Interface', and edit \"Internet STK news\")."), new ConfirmServer(), true);
"'User Interface', and edit \"Internet STK news\")."),
MessageDialog::MESSAGE_DIALOG_CONFIRM,
new ConfirmServer(), true);
}
}
else

View File

@ -233,7 +233,8 @@ void AddonsScreen::eventCallback(GUIEngine::Widget* widget,
else if (name == "reload")
{
network_http->insertReInit();
StateManager::get()->escapePressed();
new MessageDialog(_("You will be taken back to the Main Menu while an updated list of Addons are downloaded."),
MessageDialog::MESSAGE_DIALOG_OK, this, false);
}
else if (name == "list_addons")
@ -268,10 +269,23 @@ void AddonsScreen::eventCallback(GUIEngine::Widget* widget,
m_type = "arena";
loadList();
}
}
} // 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

View File

@ -22,6 +22,7 @@
#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; } }
@ -34,7 +35,8 @@ namespace GUIEngine { class Widget; }
*/
class AddonsScreen : public GUIEngine::Screen,
public GUIEngine::ScreenSingleton<AddonsScreen>,
public GUIEngine::IListWidgetHeaderListener
public GUIEngine::IListWidgetHeaderListener,
public MessageDialog::IConfirmDialogListener
{
friend class GUIEngine::ScreenSingleton<AddonsScreen>;
private:
@ -79,6 +81,8 @@ public:
virtual void init();
virtual void tearDown();
virtual void onCancel();
void setLastSelected();
};

View File

@ -27,7 +27,7 @@ using namespace GUIEngine;
// ------------------------------------------------------------------------------------------------------
MessageDialog::MessageDialog(irr::core::stringw msg, IConfirmDialogListener* listener, bool own_listener) :
MessageDialog::MessageDialog(irr::core::stringw msg, MessageDialogType type, IConfirmDialogListener* listener, bool own_listener) :
ModalDialog(0.6f, 0.6f)
{
loadFromFile("confirm_dialog.stkgui");
@ -37,27 +37,25 @@ MessageDialog::MessageDialog(irr::core::stringw msg, IConfirmDialogListener* lis
LabelWidget* message = getWidget<LabelWidget>("title");
message->setText( msg.c_str(), false );
// If the dialog is a simple 'OK' dialog, then hide the "Yes" button and
// change "Cancel" to "OK"
if (type == MessageDialog::MESSAGE_DIALOG_OK) {
ButtonWidget* yesbtn = getWidget<ButtonWidget>("confirm");
yesbtn->setVisible(false);
ButtonWidget* cancelbtn = getWidget<ButtonWidget>("cancel");
cancelbtn->setText(_("OK"));
cancelbtn->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
}
}
// ------------------------------------------------------------------------------------------------------
MessageDialog::MessageDialog(irr::core::stringw msg) :
ModalDialog(0.6f, 0.6f)
{
loadFromFile("confirm_dialog.stkgui");
m_listener = NULL;
m_own_listener = false;
LabelWidget* message = getWidget<LabelWidget>("title");
message->setText( msg.c_str(), false );
ButtonWidget* yesbtn = getWidget<ButtonWidget>("confirm");
yesbtn->setVisible(false);
ButtonWidget* cancelbtn = getWidget<ButtonWidget>("cancel");
cancelbtn->setText(_("OK"));
cancelbtn->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
{
MessageDialog(msg, MessageDialog::MESSAGE_DIALOG_OK, NULL, false);
}
// ------------------------------------------------------------------------------------------------------

View File

@ -52,6 +52,8 @@ public:
*/
virtual void onCancel();
};
enum MessageDialogType { MESSAGE_DIALOG_OK, MESSAGE_DIALOG_CONFIRM };
private:
@ -66,7 +68,7 @@ public:
* \param If set to true, 'listener' will be owned by this dialog and deleted
* along with the dialog.
*/
MessageDialog(irr::core::stringw msg, IConfirmDialogListener* listener, bool delete_listener);
MessageDialog(irr::core::stringw msg, MessageDialogType type, IConfirmDialogListener* listener, bool delete_listener);
/**
* Variant of MessageDialog where cancelling is not possible (i.e. just shows a message box with OK)

View File

@ -438,7 +438,8 @@ void OptionsScreenInput2::eventCallback(Widget* widget, const std::string& name,
{
// keyboard configs may be deleted
//I18N: shown before deleting an input configuration
new MessageDialog( _("Are you sure you want to permanently delete this configuration?"), this, false );
new MessageDialog( _("Are you sure you want to permanently delete this configuration?"),
MessageDialog::MESSAGE_DIALOG_CONFIRM, this, false );
}
else
{