From 1d66199bf5869380c0c86ae7e779978544be187a Mon Sep 17 00:00:00 2001 From: David Seguin Date: Tue, 12 Jul 2022 17:17:12 -0400 Subject: [PATCH] Worldgen: add shortcuts for buttons (#59211) --- data/raw/keybindings.json | 35 ++++++++++++++++++++++++++++++++++- src/worldfactory.cpp | 33 +++++++++++++++++++++++++++------ 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/data/raw/keybindings.json b/data/raw/keybindings.json index 38c2148eeb2e1..2fe13a4e5adcf 100644 --- a/data/raw/keybindings.json +++ b/data/raw/keybindings.json @@ -908,13 +908,46 @@ "type": "keybinding", "id": "ADVANCED_SETTINGS", "category": "WORLDGEN_CONFIRM_DIALOG", - "name": "Pick random world name", + "name": "View advanced world settings", "bindings": [ { "input_method": "keyboard_any", "key": "s" }, { "input_method": "keyboard_char", "key": "S" }, { "input_method": "keyboard_code", "key": "s", "mod": [ "shift" ] } ] }, + { + "type": "keybinding", + "id": "FINALIZE", + "category": "WORLDGEN_CONFIRM_DIALOG", + "name": "Finalize world creation", + "bindings": [ + { "input_method": "keyboard_any", "key": "f" }, + { "input_method": "keyboard_char", "key": "F" }, + { "input_method": "keyboard_code", "key": "f", "mod": [ "shift" ] } + ] + }, + { + "type": "keybinding", + "id": "RANDOMIZE", + "category": "WORLDGEN_CONFIRM_DIALOG", + "name": "Randomize world settings", + "bindings": [ + { "input_method": "keyboard_any", "key": "a" }, + { "input_method": "keyboard_char", "key": "A" }, + { "input_method": "keyboard_code", "key": "a", "mod": [ "shift" ] } + ] + }, + { + "type": "keybinding", + "id": "RESET", + "category": "WORLDGEN_CONFIRM_DIALOG", + "name": "Reset world settings and mods", + "bindings": [ + { "input_method": "keyboard_any", "key": "r" }, + { "input_method": "keyboard_char", "key": "R" }, + { "input_method": "keyboard_code", "key": "r", "mod": [ "shift" ] } + ] + }, { "type": "keybinding", "id": "QUIT", diff --git a/src/worldfactory.cpp b/src/worldfactory.cpp index 6a74ad1640cd3..5a0b61ebbbdc9 100644 --- a/src/worldfactory.cpp +++ b/src/worldfactory.cpp @@ -1589,6 +1589,9 @@ int worldfactory::show_worldgen_basic( WORLD *world ) ctxt.register_action( "HELP_KEYBINDINGS" ); ctxt.register_action( "PICK_MODS" ); ctxt.register_action( "ADVANCED_SETTINGS" ); + ctxt.register_action( "FINALIZE" ); + ctxt.register_action( "RANDOMIZE" ); + ctxt.register_action( "RESET" ); ctxt.register_action( "SCROLL_UP" ); ctxt.register_action( "SCROLL_DOWN" ); ctxt.register_cardinal(); @@ -1704,27 +1707,33 @@ int worldfactory::show_worldgen_basic( WORLD *world ) if( all_sliders_drawn && y <= content_height ) { // Finish button nc_color acc_clr = get_clr( c_yellow, sel_opt == static_cast( wg_sliders.size() + 1 ) ); + nc_color acc_clr2 = get_clr( c_light_green, sel_opt == static_cast( wg_sliders.size() + 1 ) ); nc_color base_clr = get_clr( c_white, sel_opt == static_cast( wg_sliders.size() + 1 ) ); - std::string btn_txt = string_format( "%s %s %s", colorize( "[", acc_clr ), - _( "Finish" ), colorize( "]", acc_clr ) ); + std::string btn_txt = string_format( "%s%s%s %s %s", colorize( "[", acc_clr ), + colorize( ctxt.get_desc( "FINALIZE", 1U ), acc_clr2 ), + colorize( "][", acc_clr ), _( "Finish" ), colorize( "]", acc_clr ) ); const point finish_pos( win_width / 4 - utf8_width( btn_txt, true ) / 2, y ); print_colored_text( w_confirmation, finish_pos, base_clr, base_clr, btn_txt ); btn_map.emplace( wg_sliders.size() + 1, inclusive_rectangle( finish_pos, finish_pos + point( utf8_width( btn_txt, true ), 0 ) ) ); // Reset button acc_clr = get_clr( c_yellow, sel_opt == static_cast( wg_sliders.size() + 2 ) ); + acc_clr2 = get_clr( c_light_green, sel_opt == static_cast( wg_sliders.size() + 2 ) ); base_clr = get_clr( c_white, sel_opt == static_cast( wg_sliders.size() + 2 ) ); - btn_txt = string_format( "%s %s %s", colorize( "[", acc_clr ), - _( "Reset" ), colorize( "]", acc_clr ) ); + btn_txt = string_format( "%s%s%s %s %s", colorize( "[", acc_clr ), + colorize( ctxt.get_desc( "RESET", 1U ), acc_clr2 ), + colorize( "][", acc_clr ), _( "Reset" ), colorize( "]", acc_clr ) ); const point reset_pos( win_width / 2 - utf8_width( btn_txt, true ) / 2, y ); print_colored_text( w_confirmation, reset_pos, base_clr, base_clr, btn_txt ); btn_map.emplace( wg_sliders.size() + 2, inclusive_rectangle( reset_pos, reset_pos + point( utf8_width( btn_txt, true ), 0 ) ) ); // Randomize button acc_clr = get_clr( c_yellow, sel_opt == static_cast( wg_sliders.size() + 3 ) ); + acc_clr2 = get_clr( c_light_green, sel_opt == static_cast( wg_sliders.size() + 3 ) ); base_clr = get_clr( c_white, sel_opt == static_cast( wg_sliders.size() + 3 ) ); - btn_txt = string_format( "%s %s %s", colorize( "[", acc_clr ), - _( "Randomize" ), colorize( "]", acc_clr ) ); + btn_txt = string_format( "%s%s%s %s %s", colorize( "[", acc_clr ), + colorize( ctxt.get_desc( "RANDOMIZE", 1U ), acc_clr2 ), + colorize( "][", acc_clr ), _( "Randomize" ), colorize( "]", acc_clr ) ); const point rand_pos( ( win_width * 3 ) / 4 - utf8_width( btn_txt, true ) / 2, y++ ); print_colored_text( w_confirmation, rand_pos, base_clr, base_clr, btn_txt ); btn_map.emplace( wg_sliders.size() + 3, @@ -1811,6 +1820,18 @@ int worldfactory::show_worldgen_basic( WORLD *world ) } } + // Button shortcuts + if( action == "FINALIZE" ) { + action = "CONFIRM"; + sel_opt = wg_sliders.size() + 1; + } else if( action == "RESET" ) { + action = "CONFIRM"; + sel_opt = wg_sliders.size() + 2; + } else if( action == "RANDOMIZE" ) { + action = "CONFIRM"; + sel_opt = wg_sliders.size() + 3; + } + // Handle other inputs if( action == "CONFIRM" ) { if( sel_opt == 0 ) {