Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worldgen: add shortcuts for buttons #59211

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
33 changes: 27 additions & 6 deletions src/worldfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 ) {
Expand Down