Message dialog: set buttons text before layout occurs, so that buttons get the proper size. Fixes #1764

This commit is contained in:
Marianne Gagnon 2014-12-05 21:11:56 -05:00
parent 7367342755
commit 68db893e84
2 changed files with 14 additions and 8 deletions

View File

@ -68,25 +68,28 @@ MessageDialog::~MessageDialog()
// ------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------
void MessageDialog::doInit(MessageDialogType type, void MessageDialog::doInit(MessageDialogType type,
IConfirmDialogListener* listener, bool own_listener) IConfirmDialogListener* listener, bool own_listener)
{ {
if (StateManager::get()->getGameState() == GUIEngine::GAME) if (StateManager::get()->getGameState() == GUIEngine::GAME)
{ {
World::getWorld()->schedulePause(World::IN_GAME_MENU_PHASE); World::getWorld()->schedulePause(World::IN_GAME_MENU_PHASE);
} }
m_type = type;
loadFromFile("confirm_dialog.stkgui");
m_listener = listener; m_listener = listener;
m_own_listener = own_listener; m_own_listener = own_listener;
loadFromFile("confirm_dialog.stkgui");
}
void MessageDialog::loadedFromFile()
{
LabelWidget* message = getWidget<LabelWidget>("title"); LabelWidget* message = getWidget<LabelWidget>("title");
message->setText( m_msg.c_str(), false ); message->setText( m_msg.c_str(), false );
// If the dialog is a simple 'OK' dialog, then hide the "Yes" button and // If the dialog is a simple 'OK' dialog, then hide the "Yes" button and
// change "Cancel" to "OK" // change "Cancel" to "OK"
if (type == MessageDialog::MESSAGE_DIALOG_OK) if (m_type == MessageDialog::MESSAGE_DIALOG_OK)
{ {
ButtonWidget* yesbtn = getWidget<ButtonWidget>("confirm"); ButtonWidget* yesbtn = getWidget<ButtonWidget>("confirm");
yesbtn->setVisible(false); yesbtn->setVisible(false);
@ -95,13 +98,13 @@ void MessageDialog::doInit(MessageDialogType type,
cancelbtn->setText(_("OK")); cancelbtn->setText(_("OK"));
cancelbtn->setFocusForPlayer(PLAYER_ID_GAME_MASTER); cancelbtn->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
} }
else if (type == MessageDialog::MESSAGE_DIALOG_YESNO) else if (m_type == MessageDialog::MESSAGE_DIALOG_YESNO)
{ {
ButtonWidget* cancelbtn = getWidget<ButtonWidget>("cancel"); ButtonWidget* cancelbtn = getWidget<ButtonWidget>("cancel");
cancelbtn->setText(_("No")); cancelbtn->setText(_("No"));
} }
else if (type == MessageDialog::MESSAGE_DIALOG_OK_CANCEL) else if (m_type == MessageDialog::MESSAGE_DIALOG_OK_CANCEL)
{ {
// In case of a OK_CANCEL dialog, change the text from 'Yes' to 'Ok' // In case of a OK_CANCEL dialog, change the text from 'Yes' to 'Ok'
ButtonWidget* yesbtn = getWidget<ButtonWidget>("confirm"); ButtonWidget* yesbtn = getWidget<ButtonWidget>("confirm");
@ -109,7 +112,6 @@ void MessageDialog::doInit(MessageDialogType type,
} }
} }
// ------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------
void MessageDialog::onEnterPressedInternal() void MessageDialog::onEnterPressedInternal()

View File

@ -64,6 +64,8 @@ public:
enum MessageDialogType { MESSAGE_DIALOG_OK, MESSAGE_DIALOG_CONFIRM, enum MessageDialogType { MESSAGE_DIALOG_OK, MESSAGE_DIALOG_CONFIRM,
MESSAGE_DIALOG_OK_CANCEL, MESSAGE_DIALOG_YESNO }; MESSAGE_DIALOG_OK_CANCEL, MESSAGE_DIALOG_YESNO };
MessageDialogType m_type;
private: private:
IConfirmDialogListener* m_listener; IConfirmDialogListener* m_listener;
@ -96,6 +98,8 @@ public:
virtual void load(); virtual void load();
GUIEngine::EventPropagation processEvent(const std::string& eventSource); GUIEngine::EventPropagation processEvent(const std::string& eventSource);
virtual void loadedFromFile();
}; };