add Choose button for monster special loot item (#731)

This commit is contained in:
2025-05-25 22:05:48 -05:00
parent 05989810d4
commit 49b5841d0f
7 changed files with 89 additions and 65 deletions

View File

@@ -854,67 +854,6 @@ 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::vector<std::string> choice_names, boost::optional<short> cancel_value, short initial_value, std::string extra_led, bool* led_output) {
std::ostringstream sout;
sout << prompt;
set_cursor(sword_curs);
cDialog numPanel(*ResMgr::dialogs.get("get-num"));
numPanel.attachClickHandlers(get_num_of_items_event_filter, {"okay"});
if(extra_led.empty()){
numPanel["extra-led"].hide();
}else{
numPanel["extra-led"].setText(extra_led);
numPanel["extra-led"].recalcRect();
if(led_output != nullptr)
dynamic_cast<cLed&>(numPanel["extra-led"]).setState(*led_output ? led_red : led_off);
}
sout << " (" << min << '-' << max << ')';
numPanel["prompt"].setText(sout.str());
numPanel["number"].setTextToNum(initial_value);
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;
int val = me["number"].getTextAsNum();
if(val < min || val > max) {
showError("Number out of range!");
return false;
}
return true;
});
bool cancel_clicked = false;
if(cancel_value){
numPanel["cancel"].attachClickHandler([cancel_value, &cancel_clicked](cDialog& me,std::string,eKeyMod) -> bool {
cancel_clicked = true;
me.setResult<int>(*cancel_value);
me.toast(false);
return true;
});
}else{
numPanel["cancel"].hide();
}
numPanel.run();
if(!cancel_clicked && led_output != nullptr){
*led_output = dynamic_cast<cLed&>(numPanel["extra-led"]).getState() == led_red;
}
return numPanel.getResult<int>();
}
static bool select_pc_event_filter (cDialog& me, std::string item_hit, eKeyMod) {
me.toast(true);
if(item_hit == "pick-all"){

View File

@@ -35,10 +35,6 @@ 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);
// Prompt the player for a number, which might be an index in a given list of strings.
// Specify cancel_value to show a cancel button, which will return the given value (for example, -1)
// Specify extra_led and led_output to show a labeled LED which will assign led_output with its status unless the dialog is canceled
short get_num_response(short min, short max, std::string prompt, std::vector<std::string> choice_names = {}, boost::optional<short> cancel_value = boost::none, short initial_value = 0, std::string extra_led = "", bool* led_output = nullptr);
enum class eSelectPC {
ANY,

View File

@@ -28,6 +28,7 @@
#include "dialogxml/dialogs/strdlog.hpp"
#include "dialogxml/dialogs/choicedlog.hpp"
#include "dialogxml/dialogs/3choice.hpp"
#include "dialogxml/dialogs/strchoice.hpp"
#include "fileio/fileio.hpp"
#include <array>
#include "spell.hpp"