get_num_response allow pass choice names

This commit is contained in:
2025-02-08 20:42:15 -06:00
committed by Celtic Minstrel
parent 9b513068bd
commit 392ad5eac0
3 changed files with 13 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?> <?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
<dialog defbtn='okay'> <dialog defbtn='okay'>
<field name="number" type='int' top='33' left='90' width='75' height='16'/> <field name="number" type='int' top='33' left='90' width='75' height='16'/>
<button name='choose' type='regular' relative='pos neg' rel-anchor='prev' top='3' left='5'>Choose</button>
<pict type='dlog' num='2' top='8' left='8'/> <pict type='dlog' num='2' top='8' left='8'/>
<text name='prompt' size='large' top='8' left='49' width='193' height='16'>How many?</text> <text name='prompt' size='large' top='8' left='49' width='193' height='16'>How many?</text>
<button name='okay' type='regular' top='63' left='141'>OK</button> <button name='okay' type='regular' top='63' left='141'>OK</button>

View File

@@ -19,6 +19,7 @@
#include "boe.main.hpp" #include "boe.main.hpp"
#include "mathutil.hpp" #include "mathutil.hpp"
#include "dialogxml/dialogs/strdlog.hpp" #include "dialogxml/dialogs/strdlog.hpp"
#include "dialogxml/dialogs/strchoice.hpp"
#include "dialogxml/dialogs/3choice.hpp" #include "dialogxml/dialogs/3choice.hpp"
#include "dialogxml/widgets/message.hpp" #include "dialogxml/widgets/message.hpp"
#include <array> #include <array>
@@ -866,7 +867,7 @@ std::string get_text_response(std::string prompt, pic_num_t pic) {
return result; return result;
} }
short get_num_response(short min, short max, std::string prompt) { short get_num_response(short min, short max, std::string prompt, std::vector<std::string> choice_names) {
std::ostringstream sout; std::ostringstream sout;
sout << prompt; sout << prompt;
@@ -878,6 +879,15 @@ short get_num_response(short min, short max, std::string prompt) {
sout << " (" << min << '-' << max << ')'; sout << " (" << min << '-' << max << ')';
numPanel["prompt"].setText(sout.str()); numPanel["prompt"].setText(sout.str());
numPanel["number"].setTextToNum(0); numPanel["number"].setTextToNum(0);
if(!choice_names.empty()){
numPanel["choose"].attachClickHandler([&choice_names, &prompt](cDialog& me,std::string,eKeyMod) -> bool {
cStringChoice choose_dlg(choice_names, prompt, &me);
me["number"].setTextToNum(choose_dlg.show(me["number"].getTextAsNum()));
return true;
});
}else{
numPanel["choose"].hide();
}
if(min < max) if(min < max)
numPanel["number"].attachFocusHandler([min,max](cDialog& me,std::string,bool losing) -> bool { numPanel["number"].attachFocusHandler([min,max](cDialog& me,std::string,bool losing) -> bool {
if(!losing) return true; if(!losing) return true;

View File

@@ -32,7 +32,7 @@ void reset_item_max();
short item_val(cItem item); short item_val(cItem item);
void place_treasure(location where,short level,short loot,short mode); void place_treasure(location where,short level,short loot,short mode);
std::string get_text_response(std::string prompt = "", pic_num_t pic = 16); std::string get_text_response(std::string prompt = "", pic_num_t pic = 16);
short get_num_response(short min, short max, std::string prompt); short get_num_response(short min, short max, std::string prompt, std::vector<std::string> choice_names = {});
short char_select_pc(short mode,const char *title); short char_select_pc(short mode,const char *title);
short select_pc(short mode); short select_pc(short mode);