diff --git a/src/dialogxml/dialogs/dialog.cpp b/src/dialogxml/dialogs/dialog.cpp index c32e21e7..61ce1290 100644 --- a/src/dialogxml/dialogs/dialog.cpp +++ b/src/dialogxml/dialogs/dialog.cpp @@ -914,17 +914,30 @@ void cDialog::process_keystroke(cKey keyHit){ ctrlIter iter = controls.begin(); bool enterKeyHit = keyHit.spec && keyHit.k == key_enter; while(iter != controls.end()){ - if((iter->second->isVisible() && iter->second->isClickable()) - && (iter->second->getAttachedKey() == keyHit || (iter->second->isDefault() && enterKeyHit))){ + cControl* ctrl = iter->second; + if(ctrl->isVisible()){ + if(ctrl->isClickable() && + (ctrl->getAttachedKey() == keyHit || (ctrl->isDefault() && enterKeyHit))){ + + ctrl->handleKeyTriggered(*this); + return; + } + if(ctrl->isContainer()){ + cContainer* container = dynamic_cast(ctrl); + std::string child_hit; + container->forEach([&keyHit, &child_hit, enterKeyHit](std::string child_id, cControl& child_ctrl) { + if(child_ctrl.isClickable() && + (child_ctrl.getAttachedKey() == keyHit || (child_ctrl.isDefault() && enterKeyHit))){ + + if(child_hit.empty()) child_hit = child_id; + } + }); + if(!child_hit.empty()) { + findControl(child_hit)->handleKeyTriggered(*this); + return; + } + } - iter->second->setActive(true); - draw(); - iter->second->playClickSound(); - iter->second->setActive(false); - draw(); - sf::sleep(sf::milliseconds(8)); - iter->second->triggerClickHandler(*this,iter->first,mod_none); - return; } iter++; } diff --git a/src/dialogxml/widgets/control.cpp b/src/dialogxml/widgets/control.cpp index 05bf7183..9e291b78 100644 --- a/src/dialogxml/widgets/control.cpp +++ b/src/dialogxml/widgets/control.cpp @@ -291,6 +291,16 @@ bool cControl::handleClick(location, cFramerateLimiter& fps_limiter){ return clicked; } +void cControl::handleKeyTriggered(cDialog& parent) { + setActive(true); + parent.draw(); + playClickSound(); + setActive(false); + parent.draw(); + sf::sleep(sf::milliseconds(8)); + triggerClickHandler(parent,name,mod_none); +} + std::string cControl::getAttachedKeyDescription() const { std::string s; if(key.spec) { diff --git a/src/dialogxml/widgets/control.hpp b/src/dialogxml/widgets/control.hpp index 008328a8..d9507964 100644 --- a/src/dialogxml/widgets/control.hpp +++ b/src/dialogxml/widgets/control.hpp @@ -340,6 +340,8 @@ public: /// should be hilited in some way while pressed and is cancelled by releasing the mouse /// button outside the control's bounds. virtual bool handleClick(location where, cFramerateLimiter& fps_limiter); + /// Animate and play the sound of the control being "clicked", and call its click event + void handleKeyTriggered(cDialog& parent); /// Specifies that another control acts as a label for this one. /// The practical effect of this is that hiding or showing this control automatically hides or shows the label as well. /// @param label A pointer to the control that acts as a label.