Remove all def-key='enter' in favour of defbtn attribute

In addition, the default button is finally properly outlined when specified with the defbtn attribute.
(It would also be outlined if specified with def-key='enter'.)
The following preset buttons (available to special nodes) now respond to the enter key:
- "Leave", "Done", "OK"
This commit is contained in:
2015-10-03 03:35:41 -04:00
parent da58f09fca
commit 8b5396c980
14 changed files with 25 additions and 37 deletions

View File

@@ -174,6 +174,7 @@ cDialog::cDialog(std::string path, cDialog* p) : parent(p) {
extern fs::path progDir;
void cDialog::loadFromFile(std::string path){
static const cKey enterKey = {true, key_enter};
bg = defaultBackground;
fname = path;
fs::path cPath = progDir/"data"/"dialogs"/path;
@@ -184,7 +185,7 @@ void cDialog::loadFromFile(std::string path){
Iterator<Attribute> attr;
Iterator<Element> node;
string type, name, val;
string type, name, val, defaultButton;
xml.FirstChildElement()->GetValue(&type);
if(type != "dialog") throw xBadNode(type,xml.FirstChildElement()->Row(),xml.FirstChildElement()->Column(),fname);
@@ -251,6 +252,11 @@ void cDialog::loadFromFile(std::string path){
//parsed.second->fillTabOrder(specificTabs, reverseTabs);
} else throw xBadNode(type,node->Row(),node->Column(),fname);
}
// Set the default button.
if(hasControl(defaultButton))
getControl(defaultButton).attachKey(enterKey);
// Sort by tab order
// First, fill any gaps that might have been left, using ones that had no specific tab order
// Of course, if there are not enough without a specific tab order, there could still be gaps
@@ -301,6 +307,9 @@ void cDialog::loadFromFile(std::string path){
} catch(xMissingAttr& x){ // Invalid element
std::cerr << x.what();
throw;
} catch(std::exception& x){ // Other uncaught exception
std::cerr << x.what();
throw;
}
dialogNotToast = true;
if(bg == BG_DARK) defTextClr = sf::Color::White;
@@ -601,10 +610,6 @@ short cDialog::getBg() {
return bg;
}
void cDialog::setDefBtn(std::string defBtn) {
defaultButton = defBtn;
}
void cDialog::setDefTextClr(sf::Color clr){
defTextClr = clr;
}
@@ -736,9 +741,6 @@ std::string cDialog::process_keystroke(cKey keyHit){
keyHit.k = key_enter;
return process_keystroke(keyHit);
}
// If nothing was hit and the key was enter, return the default button (if any)
if(keyHit.spec && keyHit.k == key_enter)
return defaultButton;
return "";
}

View File

@@ -116,11 +116,6 @@ public:
/// Set the default text colour applied to new dialogs when loading from a file.
/// @param clr The text colour.
void setDefTextClr(sf::Color clr);
/// Set the default button, which will be drawn outlined and respond to the enter key.
/// @param defBtn The unique key of the default button.
///
/// This function does not check that the default button exists and is a button.
void setDefBtn(std::string defBtn);
/// Get the default text colour applied to new dialogs when loading from a file.
/// @return The text colour.
sf::Color getDefTextClr();
@@ -214,7 +209,6 @@ private:
std::string process_click(location where);
bool dialogNotToast, didAccept;
rectangle winRect;
std::string defaultButton;
boost::any result;
std::string fname;
sf::Clock animTimer, paintTimer;

View File

@@ -21,7 +21,7 @@ size_t available_btns[53] = {
/// A list of preset button types. Many of these are unused.
bbtt basic_buttons[] = {
{BTN_DONE, " ", {false,0,mod_none}}, // Formerly DLG_BTN_REG with "Done " as the string
{BTN_DONE, " ", {false,key_enter,mod_none}}, // Formerly DLG_BTN_REG with "Done " as the string
{BTN_REG, "Ask", {false,0,mod_none}},
{BTN_LEFT, " ", {true,key_left,mod_none}},
{BTN_RIGHT, " ", {true,key_right,mod_none}},
@@ -30,7 +30,7 @@ bbtt basic_buttons[] = {
{BTN_SM, "+", {false,0,mod_none}},
{BTN_SM, "-", {false,0,mod_none}},
{BTN_REG, "Buy", {false,0,mod_none}},
{BTN_REG, "Leave", {false,0,mod_none}},
{BTN_REG, "Leave", {false,key_enter,mod_none}},
//10
{BTN_REG, "Get", {false,'g',mod_none}},
{BTN_REG, "1", {false,'1',mod_none}},
@@ -87,10 +87,10 @@ bbtt basic_buttons[] = {
{BTN_LG, "Bash Door", {false,0,mod_none}},
{BTN_LG, "Pick Lock", {false,0,mod_none}},
//60
{BTN_REG, "Leave", {false,0,mod_none}}, // dupe
{BTN_REG, "Leave", {false,key_enter,mod_none}}, // dupe
{BTN_REG, "Steal", {false,0,mod_none}},
{BTN_REG, "Attack", {false,0,mod_none}},
{BTN_REG, "OK", {false,0,mod_none}},
{BTN_REG, "OK", {false,key_enter,mod_none}},
{BTN_REG, "Yes", {false,'y',mod_none}},
{BTN_REG, "No", {false,'n',mod_none}},
{BTN_LG, "Step In", {false,0,mod_none}},

View File

@@ -384,8 +384,6 @@ 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;
@@ -435,12 +433,6 @@ 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());
}
}
}