get_num_response debug actions: allow canceling
This commit is contained in:
@@ -2003,7 +2003,8 @@ void debug_fight_encounter(bool wandering) {
|
||||
prompt += "special encounter?";
|
||||
}
|
||||
|
||||
int i = get_num_response(0, 3, prompt);
|
||||
int i = get_num_response(0, 3, prompt, {}, -1);
|
||||
if(i == -1) return;
|
||||
|
||||
cOutdoors::cWandering encounter;
|
||||
if(wandering){
|
||||
@@ -2024,7 +2025,8 @@ void debug_give_item() {
|
||||
for(cItem& item : univ.scenario.scen_items){
|
||||
item_names.push_back(item.full_name);
|
||||
}
|
||||
int i = get_num_response(0, univ.scenario.scen_items.size()-1, "Which item?", item_names);
|
||||
int i = get_num_response(0, univ.scenario.scen_items.size()-1, "Which item?", item_names, -1);
|
||||
if(i == -1) return;
|
||||
bool was_ident = univ.scenario.scen_items[i].ident;
|
||||
univ.scenario.scen_items[i].ident = true;
|
||||
bool given = univ.current_pc().give_item(univ.scenario.scen_items[i], true);
|
||||
@@ -2176,7 +2178,8 @@ void debug_enter_town() {
|
||||
for(cTown* town : univ.scenario.towns){
|
||||
town_names.push_back(town->name);
|
||||
}
|
||||
int town = get_num_response(0, univ.scenario.towns.size() - 1, "Enter Town Number", town_names);
|
||||
int town = get_num_response(0, univ.scenario.towns.size() - 1, "Enter Town Number", town_names, -1);
|
||||
if(town == -1) return;
|
||||
|
||||
if(has_feature_flag("debug-enter-town", "move-outdoors")){
|
||||
end_town_mode(false, {0,0}, true);
|
||||
|
@@ -863,7 +863,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, std::vector<std::string> choice_names) {
|
||||
short get_num_response(short min, short max, std::string prompt, std::vector<std::string> choice_names, boost::optional<short> cancel_value) {
|
||||
std::ostringstream sout;
|
||||
sout << prompt;
|
||||
|
||||
@@ -894,6 +894,17 @@ short get_num_response(short min, short max, std::string prompt, std::vector<std
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if(cancel_value){
|
||||
numPanel["cancel"].attachClickHandler([cancel_value](cDialog& me,std::string,eKeyMod) -> bool {
|
||||
me.setResult<int>(*cancel_value);
|
||||
me.toast(false);
|
||||
return true;
|
||||
});
|
||||
}else{
|
||||
numPanel["cancel"].hide();
|
||||
}
|
||||
|
||||
numPanel.run();
|
||||
|
||||
return numPanel.getResult<int>();
|
||||
|
@@ -37,7 +37,9 @@ 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, std::vector<std::string> choice_names = {});
|
||||
// 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)
|
||||
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 char_select_pc(short mode,const char *title);
|
||||
short select_pc(short mode);
|
||||
|
Reference in New Issue
Block a user