New special nodes:

- Town set attitude for affecting single creature, adapted from Windows code; technically redundant, but maybe handy
- If numeric response
- Print nums (for debugging)
- SDF arithmetic - add, subtract, multiply, divide, exponentiate
- Store random to SDF (adapted from Windows code)
- Display picture (inspired by Windows code, but the implementation is completely different and totally incompatible)
This commit is contained in:
2014-12-10 19:48:53 -05:00
parent 76ccb66786
commit c0110adb40
8 changed files with 303 additions and 11 deletions

View File

@@ -1147,6 +1147,29 @@ short custom_choice_dialog(std::array<std::string, 6>& strs,short pic_num,ePicTy
return -1;
}
void custom_pic_dialog(std::string title, pic_num_t bigpic) {
cDialog pic_dlg("show-map.xml");
cControl& okay = pic_dlg["okay"];
cControl& text = pic_dlg["title"];
okay.attachClickHandler(std::bind(&cDialog::toast, &pic_dlg, false));
text.setText(title);
cPict& map = dynamic_cast<cPict&>(pic_dlg["map"]);
// We don't provide a way to use non-custom full sheets - why would you want to show standard help graphics?
map.setPict(bigpic, PIC_CUSTOM_FULL);
// Now we need to adjust the size to ensure that everything fits correctly.
map.recalcRect();
RECT mapBounds = map.getBounds();
RECT btnBounds = okay.getBounds();
RECT txtBounds = text.getBounds();
btnBounds.offset(-btnBounds.left, -btnBounds.top);
btnBounds.offset(mapBounds.right - btnBounds.width(), mapBounds.bottom + 10);
okay.setBounds(btnBounds);
txtBounds.right = mapBounds.right;
text.setBounds(txtBounds);
pic_dlg.recalcRect();
pic_dlg.run();
}
//short fancy_choice_dialog(short which_dlog,short parent)
//// ignore parent in Mac version
//{
@@ -1471,4 +1494,30 @@ std::string get_text_response(std::string prompt, pic_num_t pic) {
return result;
}
short get_num_response(short min, short max, std::string prompt) {
std::ostringstream sout(prompt);
make_cursor_sword();
cDialog numPanel("get-num.xml");
numPanel.attachClickHandlers(get_num_of_items_event_filter, {"okay"});
sout << " (" << min << '-' << max << ')';
numPanel["prompt"].setText(sout.str());
numPanel["number"].setTextToNum(0);
if(min < max)
numPanel["number"].attachFocusHandler([min,max](cDialog& me,std::string,bool losing) -> bool {
if(!losing) return true;
int val = me["number"].getTextAsNum();
if(val < min || val > max) {
giveError("Number out of range!");
return false;
}
return true;
});
numPanel.run();
return numPanel.getResult<int>();
}