dialogs handle hotkeys on controls in containers

This commit is contained in:
2025-03-15 16:05:12 -05:00
parent 0dd57fae4b
commit fc919cc234
3 changed files with 35 additions and 10 deletions

View File

@@ -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<cContainer*>(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++;
}

View File

@@ -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) {

View File

@@ -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.