diff --git a/src/debug_menu.cpp b/src/debug_menu.cpp index 9cedf56dc52e5..8b5d69d817b40 100644 --- a/src/debug_menu.cpp +++ b/src/debug_menu.cpp @@ -570,6 +570,98 @@ static void monster_ammo_edit( monster &mon ) } } +static std::string query_npctalkvar_new_value() +{ + std::string value; + string_input_popup popup_val; + popup_val + .title( _( "Value" ) ) + .width( 85 ) + .edit( value ); + return value; +} + +static void edit_global_npctalk_vars() +{ + uilist global_var_list; + global_var_list.desc_enabled = true; + global_var_list.title = _( "Edit npctalkvar variables (global)" ); + global_variables &globvars = get_globals(); + // some ordering shennanigans so that i == 0 is the option to add a new var + int i = 1; + std::vector keymap_index = {_( "Add new npctalkvar (global)" )}; + global_var_list.addentry_desc( 0, true, input_event(), keymap_index[0], "" ); + for( std::pair &some_global : globvars.get_global_values() ) { + keymap_index.emplace_back( some_global.first ); + std::string description = string_format( _( "raw var value: %s" ), some_global.second ); + if( std::optional globvar_as_dbl = svtod( some_global.second ); globvar_as_dbl ) { + description += "\n"; + description += string_format( _( "as time_duration: %s" ), + to_string( time_duration::from_turns( *globvar_as_dbl ) ) ); + description += "\n"; + description += string_format( _( "as time_point: %s" ), + to_string( calendar::turn_zero + time_duration::from_turns( *globvar_as_dbl ) ) ); + } + global_var_list.addentry_desc( i, true, input_event(), some_global.first, description ); + i++; + } + global_var_list.query(); + int selected_globvar = global_var_list.ret; + if( selected_globvar == 0 ) { + std::string key; + string_input_popup popup_key; + popup_key + //~This is the title for an input window, where strings like npctalk_var_my_variable are concatenated. The trailing "npctalk_var_" is intended to show that their entry is automatically prepended with that. e.g. if they type "cigar" the resulting var's string is "npctalk_var_cigar" + .title( _( "Key\n npctalk_var_" ) ) + .width( 85 ) + .edit( key ); + globvars.set_global_value( "npctalk_var_" + key, query_npctalkvar_new_value() ); + } else if( selected_globvar > 0 && selected_globvar <= static_cast( keymap_index.size() ) ) { + globvars.set_global_value( keymap_index[selected_globvar], query_npctalkvar_new_value() ); + } +} + +static void edit_character_npctalk_vars( Character &you ) +{ + + uilist char_var_list; + char_var_list.desc_enabled = true; + char_var_list.title = string_format( _( "Edit npctalkvar variables (%s)" ), you.disp_name() ); + std::unordered_map &char_vars = you.get_values(); + // some ordering shennanigans so that i == 0 is the option to add a new var + int i = 1; + std::vector keymap_index = {_( "Add new npctalkvar (local)" )}; + char_var_list.addentry_desc( 0, true, input_event(), keymap_index[0], "" ); + for( std::pair &some_local : char_vars ) { + keymap_index.emplace_back( some_local.first ); + std::string description = string_format( _( "raw var value: %s" ), some_local.second ); + if( std::optional localvar_as_dbl = svtod( some_local.second ); localvar_as_dbl ) { + description += "\n"; + description += string_format( _( "as time_duration: %s" ), + to_string( time_duration::from_turns( *localvar_as_dbl ) ) ); + description += "\n"; + description += string_format( _( "as time_point: %s" ), + to_string( calendar::turn_zero + time_duration::from_turns( *localvar_as_dbl ) ) ); + } + char_var_list.addentry_desc( i, true, input_event(), some_local.first, description ); + i++; + } + char_var_list.query(); + int selected_globvar = char_var_list.ret; + if( selected_globvar == 0 ) { + std::string key; + string_input_popup popup_key; + popup_key + //~This is the title for an input window, where strings like npctalk_var_my_variable are concatenated. The trailing "npctalk_var_" is intended to show that their entry is automatically prepended with that. e.g. if they type "cigar" the resulting var's string is "npctalk_var_cigar" + .title( _( "Key\n npctalk_var_" ) ) + .width( 85 ) + .edit( key ); + you.set_value( "npctalk_var_" + key, query_npctalkvar_new_value() ); + } else if( selected_globvar > 0 && selected_globvar <= static_cast( keymap_index.size() ) ) { + you.set_value( keymap_index[selected_globvar], query_npctalkvar_new_value() ); + } +} + static void run_eoc_menu( Creature *target = nullptr, bool target_as_alpha = false ) { if( !target && target_as_alpha ) { @@ -2583,19 +2675,7 @@ static void character_edit_menu() break; } case D_EDIT_VARS: { - std::string key; - std::string value; - string_input_popup popup_key; - string_input_popup popup_val; - popup_key - .title( _( "Key" ) ) - .width( 85 ) - .edit( key ); - popup_val - .title( _( "Value" ) ) - .width( 85 ) - .edit( value ); - you.set_value( "npctalk_var_" + key, value ); + edit_character_npctalk_vars( you ); break; } case D_FACTION: { @@ -3294,24 +3374,6 @@ static void damage_self() } } -static void edit_global_vars() -{ - std::string key; - std::string value; - string_input_popup popup_key; - string_input_popup popup_val; - popup_key - .title( _( "Key" ) ) - .width( 85 ) - .edit( key ); - popup_val - .title( _( "Value" ) ) - .width( 85 ) - .edit( value ); - global_variables &globvars = get_globals(); - globvars.set_global_value( "npctalk_var_" + key, value ); -} - static void game_report() { // generate a game report, useful for bug reporting. @@ -4146,7 +4208,7 @@ void debug() } break; case debug_menu_index::EDIT_GLOBAL_VARS: - edit_global_vars(); + edit_global_npctalk_vars(); break; case debug_menu_index::SAVE_SCREENSHOT: