diff --git a/src/states_screens/dialogs/add_device_dialog.cpp b/src/states_screens/dialogs/add_device_dialog.cpp index 6cdcae7c5..0c8a10539 100644 --- a/src/states_screens/dialogs/add_device_dialog.cpp +++ b/src/states_screens/dialogs/add_device_dialog.cpp @@ -44,6 +44,79 @@ AddDeviceDialog::AddDeviceDialog() : ModalDialog(0.90f, 0.80f) { doInit(); + core::stringw msg = + _("New gamepads and joysticks will automatically appear in the list " + "when you connect them to this device.\n\nTo add a " + "keyboard config, you can use the button below, HOWEVER please " + "note that most keyboards only support a limited amount of " + "simultaneous keypresses and are thus inappropriate for multiplayer " + "gameplay. (You can, however, connect multiple keyboards to this " + "device. Remember that everyone still needs different keybindings " + "in this case.)"); + m_text = + GUIEngine::getGUIEnv()->addStaticText(msg, + core::rect(0, 0, 1, 1), + /*border*/false , + /*word wrap*/true, + m_irrlicht_window); + m_text->setTabStop(false); + m_text->setText(msg); + +#ifdef ENABLE_WIIUSE + { + ButtonWidget* widget = new ButtonWidget(); + widget->m_properties[PROP_ID] = "addwiimote"; + + //I18N: In the 'add new input device' dialog + widget->setText( _("Add Wiimote") ); + + widget->m_x = 0; + widget->m_y = 0; + widget->m_w = 1; + widget->m_h = 1; + widget->setParent(m_irrlicht_window); + m_widgets.push_back(widget); + widget->add(); + } +#endif // ENABLE_WIIUSE + + { + ButtonWidget* widget = new ButtonWidget(); + widget->m_properties[PROP_ID] = "addkeyboard"; + + //I18N: In the 'add new input device' dialog + widget->setText( _("Add Keyboard Configuration") ); + + widget->m_x = 0; + widget->m_y = 0; + widget->m_w = 1; + widget->m_h = 1; + widget->setParent(m_irrlicht_window); + m_widgets.push_back(widget); + widget->add(); + } + { + ButtonWidget* widget = new ButtonWidget(); + widget->m_properties[PROP_ID] = "cancel"; + widget->setText( _("Cancel") ); + + widget->m_x = 0; + widget->m_y = 0; + widget->m_w = 1; + widget->m_h = 1; + widget->setParent(m_irrlicht_window); + m_widgets.push_back(widget); + widget->add(); + + widget->setFocusForPlayer( PLAYER_ID_GAME_MASTER ); + + } + configDialog(); +} // AddDeviceDialog + +// ---------------------------------------------------------------------------- +void AddDeviceDialog::configDialog() +{ ScalableFont* font = GUIEngine::getFont(); const int textHeight = GUIEngine::getFontHeight(); const int buttonHeight = textHeight + 10; @@ -59,32 +132,12 @@ AddDeviceDialog::AddDeviceDialog() : ModalDialog(0.90f, 0.80f) int cur_y = y_bottom; core::rect text_area( 15, 15, m_area.getWidth()-15, y_bottom-15 ); + m_text->setRelativePosition(text_area); - core::stringw msg = - _("New gamepads and joysticks will automatically appear in the list " - "when you connect them to this device.\n\nTo add a " - "keyboard config, you can use the button below, HOWEVER please " - "note that most keyboards only support a limited amount of " - "simultaneous keypresses and are thus inappropriate for multiplayer " - "gameplay. (You can, however, connect multiple keyboards to this " - "device. Remember that everyone still needs different keybindings " - "in this case.)"); - IGUIStaticText* b = - GUIEngine::getGUIEnv()->addStaticText(msg, - text_area, - /*border*/false , - /*word wrap*/true, - m_irrlicht_window); - b->setTabStop(false); - b->setText(msg); - + auto itr = m_widgets.begin(); #ifdef ENABLE_WIIUSE { - ButtonWidget* widget = new ButtonWidget(); - widget->m_properties[PROP_ID] = "addwiimote"; - - //I18N: In the 'add new input device' dialog - widget->setText( _("Add Wiimote") ); + Widget* widget = *itr; const int textWidth = font->getDimension( widget->getText().c_str() ).Width + 40; @@ -93,19 +146,14 @@ AddDeviceDialog::AddDeviceDialog() : ModalDialog(0.90f, 0.80f) widget->m_y = cur_y; widget->m_w = textWidth; widget->m_h = buttonHeight; - widget->setParent(m_irrlicht_window); - m_widgets.push_back(widget); - widget->add(); + widget->resize(); + itr++; cur_y += y_stride; } #endif // ENABLE_WIIUSE { - ButtonWidget* widget = new ButtonWidget(); - widget->m_properties[PROP_ID] = "addkeyboard"; - - //I18N: In the 'add new input device' dialog - widget->setText( _("Add Keyboard Configuration") ); + Widget* widget = *itr; const int textWidth = font->getDimension( widget->getText().c_str() ).Width + 40; @@ -114,15 +162,12 @@ AddDeviceDialog::AddDeviceDialog() : ModalDialog(0.90f, 0.80f) widget->m_y = cur_y; widget->m_w = textWidth; widget->m_h = buttonHeight; - widget->setParent(m_irrlicht_window); - m_widgets.push_back(widget); - widget->add(); + widget->resize(); + itr++; cur_y += y_stride; } { - ButtonWidget* widget = new ButtonWidget(); - widget->m_properties[PROP_ID] = "cancel"; - widget->setText( _("Cancel") ); + Widget* widget = *itr; const int textWidth = font->getDimension( widget->getText().c_str() ).Width + 40; @@ -131,24 +176,10 @@ AddDeviceDialog::AddDeviceDialog() : ModalDialog(0.90f, 0.80f) widget->m_y = cur_y; widget->m_w = textWidth; widget->m_h = buttonHeight; - widget->setParent(m_irrlicht_window); - m_widgets.push_back(widget); - widget->add(); + widget->resize(); cur_y += y_stride; - - widget->setFocusForPlayer( PLAYER_ID_GAME_MASTER ); - } - -} // AddDeviceDialog - -// ---------------------------------------------------------------------------- - -void AddDeviceDialog::onEnterPressedInternal() -{ -} // onEnterPressedInternal - -// ---------------------------------------------------------------------------- +} // configDialog // ---------------------------------------------------------------------------- GUIEngine::EventPropagation AddDeviceDialog::processEvent diff --git a/src/states_screens/dialogs/add_device_dialog.hpp b/src/states_screens/dialogs/add_device_dialog.hpp index 39858b3cb..4729da3e5 100644 --- a/src/states_screens/dialogs/add_device_dialog.hpp +++ b/src/states_screens/dialogs/add_device_dialog.hpp @@ -21,6 +21,11 @@ #include "guiengine/modaldialog.hpp" +namespace irr +{ + namespace gui { class IGUIStaticText; } +} + /** * \brief Dialog that warns the user about the potential problems of * creating multiple keyboard configs. @@ -28,12 +33,19 @@ */ class AddDeviceDialog : public GUIEngine::ModalDialog { +private: + irr::gui::IGUIStaticText* m_text; + void configDialog(); public: AddDeviceDialog(); - void onEnterPressedInternal(); GUIEngine::EventPropagation processEvent(const std::string& eventSource); + void onResize() + { + GUIEngine::ModalDialog::onResize(); + configDialog(); + } };