diff --git a/src/guiengine/event_handler.cpp b/src/guiengine/event_handler.cpp index abb0eb37e..b46674430 100644 --- a/src/guiengine/event_handler.cpp +++ b/src/guiengine/event_handler.cpp @@ -381,6 +381,11 @@ void EventHandler::navigateUp(const int playerID, Input::InputType type, const b } } + // don't allow navigating to any widget when a dialog is shown; only navigate to widgets in the dialog + if (ModalDialog::isADialogActive() && !ModalDialog::getCurrent()->isMyChild(el)) + { + el = NULL; + } // find closest widget if (el != NULL && el->getTabGroup() != NULL && @@ -413,7 +418,7 @@ void EventHandler::navigateUp(const int playerID, Input::InputType type, const b if (ModalDialog::isADialogActive()) { - // TODO : select last widget in modal dialogs + w = ModalDialog::getCurrent()->getLastWidget(); } else { @@ -487,6 +492,11 @@ void EventHandler::navigateDown(const int playerID, Input::InputType type, const } } + // don't allow navigating to any widget when a dialog is shown; only navigate to widgets in the dialog + if (ModalDialog::isADialogActive() && !ModalDialog::getCurrent()->isMyChild(el)) + { + el = NULL; + } if (el != NULL && el->getTabGroup() != NULL && el->getTabGroup()->getNextElement(el->getTabOrder(), false, false, first, closest)) @@ -521,7 +531,8 @@ void EventHandler::navigateDown(const int playerID, Input::InputType type, const if (ModalDialog::isADialogActive()) { - // TODO : select first widget in modal dialogs + std::cout << "w = ModalDialog::getCurrent()->getFirstWidget();\n"; + w = ModalDialog::getCurrent()->getFirstWidget(); } else { diff --git a/src/guiengine/modaldialog.cpp b/src/guiengine/modaldialog.cpp index a7020eb56..b95bb3f82 100644 --- a/src/guiengine/modaldialog.cpp +++ b/src/guiengine/modaldialog.cpp @@ -115,4 +115,36 @@ void ModalDialog::onEnterPressedInternal() { } +Widget* ModalDialog::getLastWidget() +{ + const int childrenCount = m_children.size(); + + for (int i=childrenCount-1; i>=0; i--) + { + if (m_children[i].getIrrlichtElement() == NULL || m_children[i].getIrrlichtElement()->getTabOrder() == -1 || + m_children[i].getIrrlichtElement()->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */) + { + continue; + } + return m_children.get(i); + + } + return NULL; +} +Widget* ModalDialog::getFirstWidget() +{ + const int childrenCount = m_children.size(); + + for (int i=0; igetTabOrder() == -1 || + m_children[i].getIrrlichtElement()->getTabOrder() >= 1000 /* non-tabbing items are given such IDs */) + { + continue; + } + return m_children.get(i); + } + return NULL; +} + } diff --git a/src/guiengine/modaldialog.hpp b/src/guiengine/modaldialog.hpp index 929615ce0..34e4f4b7e 100644 --- a/src/guiengine/modaldialog.hpp +++ b/src/guiengine/modaldialog.hpp @@ -60,7 +60,11 @@ public: virtual EventPropagation processEvent(std::string& eventSource){ return EVENT_LET; } bool isMyChild(Widget* widget) const { return m_children.contains(widget); } - + bool isMyChild(irr::gui::IGUIElement* widget) const { return m_irrlicht_window->isMyChild(widget); } + + Widget* getFirstWidget(); + Widget* getLastWidget(); + irr::gui::IGUIWindow* getIrrlichtElement() { return m_irrlicht_window;