Make custom 3-choice dialogs always have a default button

This commit is contained in:
2014-04-14 00:18:56 -04:00
parent fccc1a8c54
commit 44044929cc
3 changed files with 13 additions and 0 deletions

View File

@@ -1060,6 +1060,10 @@ void cDialog::setBg(short n){
bg = n;
}
void cDialog::setDefBtn(std::string defBtn) {
defaultButton = defBtn;
}
void cDialog::setDefTextClr(sf::Color clr){
defTextClr = clr;
}

View File

@@ -55,6 +55,7 @@ public:
template<class type> void setResult(const type& val);
void setBg(short n);
void setDefTextClr(sf::Color clr);
void setDefBtn(std::string defBtn);
sf::Color getDefTextClr();
bool toast();
cControl& getControl(std::string id);

View File

@@ -297,6 +297,8 @@ void cThreeChoice::init_buttons(cBasicButtonType btn1, cBasicButtonType btn2, cB
if(btn2) btns[1] = btn2;
if(btn3) btns[2] = btn3;
cDialog* me = operator->();
// TODO: Is it correct for the first button to always be the default?
bool haveDefault = false;
for(int i = 0; i < 3; i++){
if(!btns[i]) continue;
std::ostringstream sout;
@@ -346,6 +348,12 @@ void cThreeChoice::init_buttons(cBasicButtonType btn1, cBasicButtonType btn2, cB
}
me->add(btn, cur_btn_rect, sout.str());
cur_btn_rect.right = cur_btn_rect.left - 4;
if(!haveDefault) {
me->setDefBtn(sout.str());
haveDefault = true;
} else if(btns[i]->label == "OK") {
me->setDefBtn(sout.str());
}
}
}