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:
@@ -6,5 +6,5 @@
|
||||
This item will be gone forever. Still drop it?
|
||||
</text>
|
||||
<button name='cancel' type='regular' def-key='esc' top='42' left='238'>Cancel</button>
|
||||
<button name='okay' type='regular' def-key='enter' top='42' left='169'>OK</button>
|
||||
<button name='okay' type='regular' top='42' left='169'>OK</button>
|
||||
</dialog>
|
||||
|
||||
@@ -100,7 +100,7 @@
|
||||
<field name='map' top='62' left='495' width='80' height='16'/>
|
||||
<button name='pickmap' type='regular' top='86' left='495'>Choose</button>
|
||||
<text top='110' left='431' height='32' width='157'>(Enter -1 to scale down the large picture)</text>
|
||||
<button name='done' type='regular' def-key='enter' top='455' left='517'>OK</button>
|
||||
<button name='done' type='regular' top='455' left='517'>OK</button>
|
||||
<button name='cancel' type='regular' def-key='esc' top='455' left='451'>Cancel</button>
|
||||
<button name='left' type='left' top='455' left='11'/>
|
||||
<button name='right' type='right' top='455' left='74'/>
|
||||
|
||||
@@ -38,5 +38,5 @@
|
||||
TODO: Originally had top=242; if it doesn't work right in-game, try reverting to that.
|
||||
-->
|
||||
<pict type='full' num='1300' top='232' left='284' width='275' height='100'/>
|
||||
<button name='okay' type='regular' top='403' left='500' def-key='enter'>OK</button>
|
||||
<button name='okay' type='regular' top='403' left='500'>OK</button>
|
||||
</dialog>
|
||||
|
||||
@@ -78,5 +78,5 @@
|
||||
Very dangerous.
|
||||
</text>
|
||||
<pict type='field' num='14' top='265' left='250'/>
|
||||
<button name='okay' type='regular' top='391' left='441' def-key='enter'>OK</button>
|
||||
<button name='okay' type='regular' top='391' left='441'>OK</button>
|
||||
</dialog>
|
||||
|
||||
@@ -31,5 +31,5 @@
|
||||
When you register, the documentation comes with a hint book
|
||||
for the 3 Blades of Exile scenarios!
|
||||
</text>
|
||||
<button name='okay' type='regular' top='242' left='471' def-key='enter'>OK</button>
|
||||
<button name='okay' type='regular' top='242' left='471'>OK</button>
|
||||
</dialog>
|
||||
|
||||
@@ -52,5 +52,5 @@
|
||||
Press the number of the character to cast, the button by the spell,
|
||||
and then the target button by the PC to cast the spell on (if needed).
|
||||
</text>
|
||||
<button name='okay' type='regular' top='391' left='441' def-key='enter'>OK</button>
|
||||
<button name='okay' type='regular' top='391' left='441'>OK</button>
|
||||
</dialog>
|
||||
|
||||
@@ -35,5 +35,5 @@
|
||||
<!-- TODO: Originally this had top=78 and height=360; if it doesn't work right in-game, try reverting to that.
|
||||
-->
|
||||
<pict type='full' num='1400' top='68' left='118' width='320' height='125'/>
|
||||
<button name='okay' type='regular' top='381' left='424' def-key='enter'>OK</button>
|
||||
<button name='okay' type='regular' top='381' left='424'>OK</button>
|
||||
</dialog>
|
||||
|
||||
@@ -33,5 +33,5 @@
|
||||
TODO: Originally had width=340 and height=100; if it doesn't work right in-game, try reverting to that.
|
||||
-->
|
||||
<pict type='full' num='1402' top='87' left='107' width='320' height='125'/>
|
||||
<button name='okay' type='regular' top='388' left='432' def-key='enter'>OK</button>
|
||||
<button name='okay' type='regular' top='388' left='432'>OK</button>
|
||||
</dialog>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
|
||||
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
|
||||
<dialog>
|
||||
<dialog defbtn='okay'>
|
||||
<pict type='dlog' num='2' left='8' top='8'/>
|
||||
<text left='52' top='4' width='255' height='18'>No room in your inventory.</text>
|
||||
<button name='okay' type='regular' def-key='enter' left='249' top='30'>OK</button>
|
||||
<button name='okay' type='regular' left='249' top='30'>OK</button>
|
||||
</dialog>
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
<dialog defbtn='okay'>
|
||||
<pict name='ter' type='ter' num='0' top='10' left='9'/>
|
||||
<text name='sign' framed='true' top='9' left='47' width='273' height='77'>Fred</text>
|
||||
<button name='okay' type='done' def-key='enter' top='93' left='260'/>
|
||||
<button name='okay' type='done' top='93' left='260'/>
|
||||
</dialog>
|
||||
|
||||
@@ -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 "";
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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}},
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user