Enable all message dialogs to work in the DialogQueue.

This commit is contained in:
hiker 2015-01-18 12:40:06 +11:00
parent 2e14a8fe20
commit a74a20c699
2 changed files with 66 additions and 42 deletions

View File

@ -27,37 +27,77 @@
using namespace GUIEngine;
// ------------------------------------------------------------------------------------------------------
MessageDialog::MessageDialog(const irr::core::stringw &msg, MessageDialogType type,
IConfirmDialogListener* listener, bool own_listener) :
ModalDialog(0.6f, 0.6f)
// ----------------------------------------------------------------------------
/** Complete constructor, which allows setting of listener, type etc.
* \param msg The text to be shown in the dialog.
* \param type The type of dialog (OK, confirm, ok/cancel, ...).
* \param listener An optional listener object.
* \param own_listener If true the dialog will free the listener.
* \param from_queue If the object is placed into the DialogQueue. If so,
* loadFromFile() is not called (it will be called when the dialog
* is finally being removed from the queue and shown).
*/
MessageDialog::MessageDialog(const irr::core::stringw &msg,
MessageDialogType type,
IConfirmDialogListener* listener,
bool own_listener, bool from_queue)
: ModalDialog(0.6f, 0.6f)
{
m_msg = msg;
doInit(type, listener, own_listener);
m_msg = msg;
m_type = type;
m_listener = listener;
m_own_listener = own_listener;
doInit(from_queue);
} // MessageDialog(stringw, type, listener, own_listener)
// ------------------------------------------------------------------------------------------------------
MessageDialog::MessageDialog(const irr::core::stringw &msg, bool from_queue) :
ModalDialog(0.6f, 0.6f)
// ----------------------------------------------------------------------------
/** Simple constructor for a notification message (i.e. only OK button shown).
* \param msg The message to show.
* \param from_queue If the object is placed into the DialogQueue. If so,
* loadFromFile() is not called (it will be called when the dialog
* is finally being removed from the queue and shown).
*/
MessageDialog::MessageDialog(const irr::core::stringw &msg, bool from_queue)
: ModalDialog(0.6f, 0.6f)
{
m_msg = msg;
if(!from_queue) load();
m_msg = msg;
m_type = MessageDialog::MESSAGE_DIALOG_OK;
m_listener = NULL;
m_own_listener = false;
if (!from_queue) doInit(false);
} // MessageDialog(stringw)
// ------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
/** Called from the DialogQueue, used to load the actual xml file and init
* the dialog.
*/
void MessageDialog::load()
{
doInit(MessageDialog::MESSAGE_DIALOG_OK, NULL, false);
doInit(false);
}
// ------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
/** If necessary schedules a pause, and loads the xml file if necessary.
* \param from_queue If the dialog is queued, do not load the xml file,
* this will be done later in the case of a queued dialog.
*/
void MessageDialog::doInit(bool from_queue)
{
if (StateManager::get()->getGameState() == GUIEngine::GAME)
{
World::getWorld()->schedulePause(World::IN_GAME_MENU_PHASE);
}
if (!from_queue)
loadFromFile("confirm_dialog.stkgui");
} // doInit
// ----------------------------------------------------------------------------
MessageDialog::~MessageDialog()
{
if (m_own_listener) delete m_listener; m_listener = NULL;
if (m_own_listener) delete m_listener;
m_listener = NULL;
if (StateManager::get()->getGameState() == GUIEngine::GAME)
{
@ -65,27 +105,11 @@ MessageDialog::~MessageDialog()
}
} // ~MessageDialog
// ------------------------------------------------------------------------------------------------------
void MessageDialog::doInit(MessageDialogType type,
IConfirmDialogListener* listener, bool own_listener)
{
if (StateManager::get()->getGameState() == GUIEngine::GAME)
{
World::getWorld()->schedulePause(World::IN_GAME_MENU_PHASE);
}
m_type = type;
m_listener = listener;
m_own_listener = own_listener;
loadFromFile("confirm_dialog.stkgui");
}
// ----------------------------------------------------------------------------
void MessageDialog::loadedFromFile()
{
LabelWidget* message = getWidget<LabelWidget>("title");
message->setText( m_msg.c_str(), false );
message->setText( m_msg, false );
// If the dialog is a simple 'OK' dialog, then hide the "Yes" button and
// change "Cancel" to "OK"
@ -112,13 +136,13 @@ void MessageDialog::loadedFromFile()
}
}
// ------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
void MessageDialog::onEnterPressedInternal()
{
}
// ------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
GUIEngine::EventPropagation MessageDialog::processEvent(const std::string& eventSource)
{
@ -153,7 +177,7 @@ GUIEngine::EventPropagation MessageDialog::processEvent(const std::string& event
return GUIEngine::EVENT_LET;
}
// ------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
void MessageDialog::onUpdate(float dt)
{

View File

@ -71,8 +71,7 @@ private:
IConfirmDialogListener* m_listener;
bool m_own_listener;
irr::core::stringw m_msg;
void doInit(MessageDialogType type, IConfirmDialogListener* listener,
bool own_listener);
void doInit(bool from_queue);
public:
@ -83,7 +82,8 @@ public:
* along with the dialog.
*/
MessageDialog(const irr::core::stringw &msg, MessageDialogType type,
IConfirmDialogListener* listener, bool delete_listener);
IConfirmDialogListener* listener, bool delete_listener,
bool from_queue=false);
/**
* Variant of MessageDialog where cancelling is not possible (i.e. just shows a message box with OK)