Debug give item: allow giving as unidentified

This commit is contained in:
2025-04-09 11:11:03 -05:00
parent 6f02e3128d
commit 3e1c2a9fb1
4 changed files with 24 additions and 5 deletions

View File

@@ -6,6 +6,7 @@
<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'/>
<text name='prompt' size='large' top='8' left='49' width='193' height='16'>How many?</text>
<led name='extra-led' top='70' left='2'></led>
<button name='cancel' type='regular' top='63' left='70'>Cancel</button>
<button name='okay' type='regular' top='63' left='141'>OK</button>
</dialog>

View File

@@ -2033,10 +2033,13 @@ 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, -1);
// By default, pre-identify debug items
bool ident = true;
int i = get_num_response(0, univ.scenario.scen_items.size()-1, "Which item?", item_names, -1, "identified", &ident);
if(i == -1) return;
bool was_ident = univ.scenario.scen_items[i].ident;
univ.scenario.scen_items[i].ident = true;
univ.scenario.scen_items[i].ident = ident;
bool given = univ.current_pc().give_item(univ.scenario.scen_items[i], GIVE_DO_PRINT | GIVE_ALLOW_OVERLOAD) == eBuyStatus::OK;
if(!given){
ASB("Debug: can't give to " + univ.current_pc().name);

View File

@@ -666,6 +666,7 @@ short get_num_of_items(short max_num) {
set_cursor(sword_curs);
cDialog numPanel(*ResMgr::dialogs.get("get-num"));
numPanel["extra-led"].hide();
numPanel.attachClickHandlers(get_num_of_items_event_filter, {"okay"});
numPanel["prompt"].setText("How many? (0-" + std::to_string(max_num) + ") ");
@@ -867,7 +868,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, boost::optional<short> cancel_value) {
short get_num_response(short min, short max, std::string prompt, std::vector<std::string> choice_names, boost::optional<short> cancel_value, std::string extra_led, bool* led_output) {
std::ostringstream sout;
sout << prompt;
@@ -876,6 +877,14 @@ short get_num_response(short min, short max, std::string prompt, std::vector<std
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);
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(0);
@@ -899,8 +908,10 @@ short get_num_response(short min, short max, std::string prompt, std::vector<std
return true;
});
bool cancel_clicked = false;
if(cancel_value){
numPanel["cancel"].attachClickHandler([cancel_value](cDialog& me,std::string,eKeyMod) -> bool {
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;
@@ -910,6 +921,9 @@ short get_num_response(short min, short max, std::string prompt, std::vector<std
}
numPanel.run();
if(!cancel_clicked && led_output != nullptr){
*led_output = dynamic_cast<cLed&>(numPanel["extra-led"]).getState() == led_red;
}
return numPanel.getResult<int>();
}

View File

@@ -39,7 +39,8 @@ 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)
short get_num_response(short min, short max, std::string prompt, std::vector<std::string> choice_names = {}, boost::optional<short> cancel_value = boost::none);
// 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, std::string extra_led = "", bool* led_output = nullptr);
enum class eSelectPC {
ANY,