select_pc() allow_choose_all argument, eliminate overloaded version

This commit is contained in:
2025-03-17 09:26:55 -05:00
parent 72942efa6a
commit 03e5ee59c6
5 changed files with 26 additions and 21 deletions

View File

@@ -860,7 +860,7 @@ void handle_bash_pick(location destination, bool& did_something, bool& need_redr
if(!adjacent(destination,univ.party.town_loc))
add_string_to_buf(" Must be adjacent.");
else {
short pc = char_select_pc(0, isBash ? "Who will bash?" : "Who will pick the lock?");
short pc = select_pc(0, isBash ? "Who will bash?" : "Who will pick the lock?");
if(pc == 6) {
add_string_to_buf(" Cancelled.");
overall_mode = MODE_TOWN;
@@ -1900,12 +1900,12 @@ void handle_menu_spell(eSpell spell_picked) {
store_mage = spell_picked;
else store_priest = spell_picked;
if(spell_type == eSkill::MAGE_SPELLS && (*spell_picked).need_select != SELECT_NO) {
if((store_spell_target = char_select_pc((*spell_picked).need_select == SELECT_ANY ? 1 : 0,"Cast spell on who?")) == 6)
if((store_spell_target = select_pc((*spell_picked).need_select == SELECT_ANY ? 1 : 0,"Cast spell on who?")) == 6)
return;
}
else {
if(spell_type == eSkill::PRIEST_SPELLS && (*spell_picked).need_select != SELECT_NO)
if((store_spell_target = char_select_pc((*spell_picked).need_select == SELECT_ANY ? 1 : 0,"Cast spell on who?")) == 6)
if((store_spell_target = select_pc((*spell_picked).need_select == SELECT_ANY ? 1 : 0,"Cast spell on who?")) == 6)
return;
}
@@ -3367,7 +3367,7 @@ void handle_drop_pc() {
}else if(is_combat()){
add_string_to_buf("Delete PC: Not in combat.");
}else{
int choice = char_select_pc(1,"Delete who?");
int choice = select_pc(1,"Delete who?");
if(choice < 6) {
std::string confirm = cChoiceDlog("delete-pc-confirm",{"yes","no"}).show();
if(confirm == "no"){
@@ -4044,7 +4044,7 @@ void handle_new_pc_graphic() {
if(recording){
record_action("handle_new_pc_graphic", "");
}
short choice = char_select_pc(1,"New graphic for who?");
short choice = select_pc(1,"New graphic for who?");
if(choice < 6)
pick_pc_graphic(choice,1,nullptr);
draw_terrain();
@@ -4054,7 +4054,7 @@ void handle_rename_pc() {
if(recording){
record_action("handle_rename_pc", "");
}
short choice = char_select_pc(1,"Rename who?");
short choice = select_pc(1,"Rename who?");
if(choice < 6)
pick_pc_name(choice,nullptr);
put_pc_screen();

View File

@@ -936,7 +936,7 @@ void handle_talk_node(int which_talk_entry) {
save_talk_str2 = "";
break;
case eTalkNode::TRAINING:
if((get_pc = char_select_pc(0,"Train who?")) < 6) {
if((get_pc = select_pc(0,"Train who?")) < 6) {
can_save_talk = false;
spend_xp(get_pc,1, nullptr);
}

View File

@@ -190,7 +190,7 @@ void give_thing(short pc_num, short item_num) {
add_string_to_buf("Give: Item is cursed.");
else {
item_store = univ.party[pc_num].items[item_num];
who_to = char_select_pc(3,"Give item to who?");
who_to = select_pc(3,"Give item to who?");
if((overall_mode == MODE_COMBAT) && !adjacent(univ.party[pc_num].combat_pos,univ.party[who_to].combat_pos)) {
add_string_to_buf("Give: Must be adjacent.");
who_to = 6;
@@ -912,24 +912,28 @@ short get_num_response(short min, short max, std::string prompt, std::vector<std
static bool select_pc_event_filter (cDialog& me, std::string item_hit, eKeyMod) {
me.toast(true);
if(item_hit != "cancel") {
if(item_hit == "pick-all"){
me.setResult<short>(7);
}else if(item_hit != "cancel"){
short which_pc = item_hit[item_hit.length() - 1] - '1';
me.setResult<short>(which_pc);
} else me.setResult<short>(6);
}else me.setResult<short>(6);
return true;
}
// mode determines which PCs can be picked
// 0 - only living pcs, 1 - any pc, 2 - only dead pcs, 3 - only living pcs with inventory space
short char_select_pc(short mode,const char *title) {
short select_pc(short mode, std::string title, bool allow_choose_all) {
short item_hit;
set_cursor(sword_curs);
cDialog selectPc(*ResMgr::dialogs.get("select-pc"));
selectPc.attachClickHandlers(select_pc_event_filter, {"cancel", "pick1", "pick2", "pick3", "pick4", "pick5", "pick6"});
selectPc.attachClickHandlers(select_pc_event_filter, {"cancel", "pick1", "pick2", "pick3", "pick4", "pick5", "pick6", "pick-all"});
selectPc["title"].setText(title);
// The default title is defined in select-pc.xml
if(!title.empty())
selectPc["title"].setText(title);
for(short i = 0; i < 6; i++) {
std::string n = boost::lexical_cast<std::string>(i + 1);
@@ -957,13 +961,14 @@ short char_select_pc(short mode,const char *title) {
selectPc["pc" + n].setText(univ.party[i].name);
}
}
if(!allow_choose_all){
selectPc["pick-all"].hide();
selectPc["all"].hide();
}
selectPc.run();
item_hit = selectPc.getResult<short>();
return item_hit;
}
short select_pc(short mode) {
return char_select_pc(mode,"Select a character:");
}

View File

@@ -41,5 +41,5 @@ std::string get_text_response(std::string prompt = "", pic_num_t pic = 16);
// 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);
// Prompt the player to choose a party member. Returns 0-5 for a pc, 6 for cancel, or 7 for all.
short select_pc(short mode, std::string title="", bool allow_choose_all = false);

View File

@@ -2649,7 +2649,7 @@ void oneshot_spec(const runtime_state& ctx) {
*ctx.ret_a = 1;
} else {
if(!is_combat()) {
dlg_res = char_select_pc(0,"Trap! Who will disarm?");
dlg_res = select_pc(0,"Trap! Who will disarm?");
if(dlg_res == 6){
*ctx.ret_a = 1;
set_sd = false;
@@ -4086,7 +4086,7 @@ void townmode_spec(const runtime_state& ctx) {
check_mess = false;
break;
}
r1 = char_select_pc(0,"Which character goes?");
r1 = select_pc(0,"Which character goes?");
if(ctx.which_mode == eSpecCtx::OUT_MOVE || ctx.which_mode == eSpecCtx::TOWN_MOVE || ctx.which_mode == eSpecCtx::COMBAT_MOVE)
*ctx.ret_a = 1;
if(r1 != 6) {