Skip to content

Commit

Permalink
Worldgen: add shortcuts for buttons (#59211)
Browse files Browse the repository at this point in the history
dseguin authored Jul 12, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 78efcfd commit 1d66199
Showing 2 changed files with 61 additions and 7 deletions.
35 changes: 34 additions & 1 deletion data/raw/keybindings.json
Original file line number Diff line number Diff line change
@@ -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",
33 changes: 27 additions & 6 deletions src/worldfactory.cpp
Original file line number Diff line number Diff line change
@@ -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<int>( wg_sliders.size() + 1 ) );
nc_color acc_clr2 = get_clr( c_light_green, sel_opt == static_cast<int>( wg_sliders.size() + 1 ) );
nc_color base_clr = get_clr( c_white, sel_opt == static_cast<int>( 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<point>( finish_pos, finish_pos + point( utf8_width( btn_txt, true ), 0 ) ) );
// Reset button
acc_clr = get_clr( c_yellow, sel_opt == static_cast<int>( wg_sliders.size() + 2 ) );
acc_clr2 = get_clr( c_light_green, sel_opt == static_cast<int>( wg_sliders.size() + 2 ) );
base_clr = get_clr( c_white, sel_opt == static_cast<int>( 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<point>( reset_pos, reset_pos + point( utf8_width( btn_txt, true ), 0 ) ) );
// Randomize button
acc_clr = get_clr( c_yellow, sel_opt == static_cast<int>( wg_sliders.size() + 3 ) );
acc_clr2 = get_clr( c_light_green, sel_opt == static_cast<int>( wg_sliders.size() + 3 ) );
base_clr = get_clr( c_white, sel_opt == static_cast<int>( 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 ) {

0 comments on commit 1d66199

Please sign in to comment.