From 392ad5eac0767af833a720dc7afe942c9e04a8a5 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 8 Feb 2025 20:42:15 -0600 Subject: [PATCH] get_num_response allow pass choice names --- rsrc/dialogs/get-num.xml | 1 + src/game/boe.items.cpp | 12 +++++++++++- src/game/boe.items.hpp | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/rsrc/dialogs/get-num.xml b/rsrc/dialogs/get-num.xml index af5a88a1..2b8b0ab0 100644 --- a/rsrc/dialogs/get-num.xml +++ b/rsrc/dialogs/get-num.xml @@ -2,6 +2,7 @@ + How many? diff --git a/src/game/boe.items.cpp b/src/game/boe.items.cpp index 0d921dee..9113efcf 100644 --- a/src/game/boe.items.cpp +++ b/src/game/boe.items.cpp @@ -19,6 +19,7 @@ #include "boe.main.hpp" #include "mathutil.hpp" #include "dialogxml/dialogs/strdlog.hpp" +#include "dialogxml/dialogs/strchoice.hpp" #include "dialogxml/dialogs/3choice.hpp" #include "dialogxml/widgets/message.hpp" #include @@ -866,7 +867,7 @@ 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) { +short get_num_response(short min, short max, std::string prompt, std::vector choice_names) { std::ostringstream sout; sout << prompt; @@ -878,6 +879,15 @@ short get_num_response(short min, short max, std::string prompt) { sout << " (" << min << '-' << max << ')'; numPanel["prompt"].setText(sout.str()); 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) numPanel["number"].attachFocusHandler([min,max](cDialog& me,std::string,bool losing) -> bool { if(!losing) return true; diff --git a/src/game/boe.items.hpp b/src/game/boe.items.hpp index a521ea51..7d12525c 100644 --- a/src/game/boe.items.hpp +++ b/src/game/boe.items.hpp @@ -32,7 +32,7 @@ void reset_item_max(); short item_val(cItem item); void place_treasure(location where,short level,short loot,short mode); 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 choice_names = {}); short char_select_pc(short mode,const char *title); short select_pc(short mode);