diff --git a/data/gui/confirm_resolution_dialog.stkgui b/data/gui/confirm_resolution_dialog.stkgui new file mode 100644 index 000000000..9340111f3 --- /dev/null +++ b/data/gui/confirm_resolution_dialog.stkgui @@ -0,0 +1,21 @@ + + +
+ +
+ +
diff --git a/src/guiengine/engine.cpp b/src/guiengine/engine.cpp index cc18649d6..7f8866d04 100644 --- a/src/guiengine/engine.cpp +++ b/src/guiengine/engine.cpp @@ -451,10 +451,8 @@ You can also explore the various methods in GUIEngine::Screen to discover more optional callbacks you can use. - You can also create dialogs by deriving from GUIEngine::ModalDialog. - Unfortunately, it is currently not possible to specify modal dialogs through - XML files (FIXME), so you will need to simulate the init sequence of a GUI - screen, which I admit is not too easy. This is to improve in the future. + You can also create dialogs by deriving from GUIEngine::ModalDialog in a very + similar way. */ diff --git a/src/states_screens/dialogs/confirm_resolution_dialog.cpp b/src/states_screens/dialogs/confirm_resolution_dialog.cpp index 4cca7f522..6f74877c6 100644 --- a/src/states_screens/dialogs/confirm_resolution_dialog.cpp +++ b/src/states_screens/dialogs/confirm_resolution_dialog.cpp @@ -17,13 +17,10 @@ #include "states_screens/dialogs/confirm_resolution_dialog.hpp" -#include "config/player.hpp" #include "graphics/irr_driver.hpp" #include "guiengine/engine.hpp" -#include "guiengine/scalable_font.hpp" -#include "guiengine/widgets/button_widget.hpp" -#include "input/device_manager.hpp" -#include "input/input_manager.hpp" +#include "guiengine/screen.hpp" +#include "guiengine/widgets/label_widget.hpp" #include "states_screens/state_manager.hpp" #include "utils/string_utils.hpp" #include "utils/translation.hpp" @@ -36,63 +33,10 @@ using namespace irr::core; ConfirmResolutionDialog::ConfirmResolutionDialog() : ModalDialog(0.7f, 0.7f) { - m_countdown_message = NULL; - - ScalableFont* font = GUIEngine::getFont(); - const int textHeight = GUIEngine::getFontHeight(); - const int buttonHeight = textHeight + 10; - - const int y_bottom = m_area.getHeight() - 2*(buttonHeight + 10) - 10; - + loadFromFile("confirm_resolution_dialog.stkgui"); m_remaining_time = 10.99f; - // ---- Add label - core::rect text_area( 15, 15, m_area.getWidth()-15, y_bottom-15 ); - - m_countdown_message = GUIEngine::getGUIEnv()->addStaticText( L" ", - text_area, false , true , // border, word warp - m_irrlicht_window); - m_countdown_message->setTabStop(false); - updateMessage(); - - // ---- Add accept button - { - ButtonWidget* widget = new ButtonWidget(); - widget->m_properties[PROP_ID] = "accept"; - - //I18N: In the 'confirm resolution' dialog, that's shown when switching resoluton - widget->m_text = _("Keep this resolution"); - - const int textWidth = font->getDimension( widget->m_text.c_str() ).Width + 40; - - widget->m_x = m_area.getWidth()/2 - textWidth/2; - widget->m_y = y_bottom; - widget->m_w = textWidth; - widget->m_h = buttonHeight; - widget->setParent(m_irrlicht_window); - m_children.push_back(widget); - widget->add(); - } - // ---- Add cancel button - { - ButtonWidget* widget = new ButtonWidget(); - widget->m_properties[PROP_ID] = "cancel"; - widget->m_text = _("Cancel"); - - const int textWidth = font->getDimension( widget->m_text.c_str() ).Width + 40; - - widget->m_x = m_area.getWidth()/2 - textWidth/2; - widget->m_y = y_bottom + buttonHeight + 10; - widget->m_w = textWidth; - widget->m_h = buttonHeight; - widget->setParent(m_irrlicht_window); - m_children.push_back(widget); - widget->add(); - - widget->setFocusForPlayer( PLAYER_ID_GAME_MASTER ); - } - } // ------------------------------------------------------------------------------------------------------ @@ -124,11 +68,13 @@ void ConfirmResolutionDialog::onUpdate(float dt) void ConfirmResolutionDialog::updateMessage() { - assert(m_countdown_message != NULL); + //I18N: In the 'confirm resolution' dialog, that's shown when switching resoluton stringw msg = StringUtils::insertValues(_("Confirm resolution within %i seconds"), (int)m_remaining_time); //std::cout << stringc(msg.c_str()).c_str() << std::endl; - m_countdown_message->setText( msg.c_str() ); + + LabelWidget* countdown_message = (LabelWidget*)Screen::getWidget("title", &m_children); + countdown_message->setText( msg.c_str() ); } // ------------------------------------------------------------------------------------------------------ diff --git a/src/states_screens/dialogs/confirm_resolution_dialog.hpp b/src/states_screens/dialogs/confirm_resolution_dialog.hpp index 2b1da6fd6..0e140725b 100644 --- a/src/states_screens/dialogs/confirm_resolution_dialog.hpp +++ b/src/states_screens/dialogs/confirm_resolution_dialog.hpp @@ -27,9 +27,7 @@ class ConfirmResolutionDialog : public GUIEngine::ModalDialog { /** number of seconds left before resolution is considered unplayable */ float m_remaining_time; - - irr::gui::IGUIStaticText* m_countdown_message; - + /** updates countdown message */ void updateMessage(); public: