From bcb7469138172c26ee2def0dad1438acb28209b0 Mon Sep 17 00:00:00 2001 From: strategineer Date: Sat, 11 Mar 2023 20:08:33 -0500 Subject: [PATCH] Add two travel-related overmap keybinds for a better UX Add two new keybinds GO_TO_DESTINATION and CENTER_ON_DESTINATION that allow the player to: - Move the cursor to the current travel destination. - Go to the current travel destination without the cursor needing to be on it. I was getting annoyed about constantly having to open the overmap and pan over to my destination over and over again when traveling somewhere to resume traveling after enemies showed up --- data/raw/keybindings.json | 12 +++++++ src/overmap_ui.cpp | 76 +++++++++++++++++++++++++++++---------- 2 files changed, 69 insertions(+), 19 deletions(-) diff --git a/data/raw/keybindings.json b/data/raw/keybindings.json index 8230af1f6bd95..c896bcaf530c8 100644 --- a/data/raw/keybindings.json +++ b/data/raw/keybindings.json @@ -1207,6 +1207,18 @@ "name": "Choose destination", "bindings": [ { "input_method": "keyboard_char", "key": "W" }, { "input_method": "keyboard_code", "key": "w", "mod": [ "shift" ] } ] }, + { + "type": "keybinding", + "id": "GO_TO_DESTINATION", + "name": "Go to destination", + "bindings": [ { "input_method": "keyboard_char", "key": "g" }, { "input_method": "keyboard_code", "key": "g" } ] + }, + { + "type": "keybinding", + "id": "CENTER_ON_DESTINATION", + "name": "Center on destination", + "bindings": [ { "input_method": "keyboard_char", "key": "c" }, { "input_method": "keyboard_code", "key": "c" } ] + }, { "type": "keybinding", "id": "FIRE", diff --git a/src/overmap_ui.cpp b/src/overmap_ui.cpp index 706bfd420c9f5..5e431ae9a6b44 100644 --- a/src/overmap_ui.cpp +++ b/src/overmap_ui.cpp @@ -1183,6 +1183,8 @@ static void draw_om_sidebar( print_hint( "LEVEL_UP" ); print_hint( "LEVEL_DOWN" ); print_hint( "CENTER" ); + print_hint( "CENTER_ON_DESTINATION" ); + print_hint( "GO_TO_DESTINATION" ); print_hint( "SEARCH" ); print_hint( "CREATE_NOTE" ); print_hint( "DELETE_NOTE" ); @@ -1695,6 +1697,44 @@ static std::vector get_overmap_path_to( const tripoint_abs_omt static int overmap_zoom_level = DEFAULT_TILESET_ZOOM; +static std::string try_travel_to_destination( avatar &player_character, const tripoint_abs_omt curs, + const bool driving ) +{ + std::vector path = get_overmap_path_to( curs, driving ); + bool same_path_selected = false; + if( path == player_character.omt_path ) { + same_path_selected = true; + } + std::string confirm_msg; + if( !driving && player_character.weight_carried() > player_character.weight_capacity() ) { + confirm_msg = _( "You are overburdened, are you sure you want to travel (it may be painful)?" ); + } else if( !driving && player_character.in_vehicle ) { + confirm_msg = _( "You are in a vehicle but not driving. Are you sure you want to walk?" ); + } else if( driving ) { + if( same_path_selected ) { + confirm_msg = _( "Drive to this point?" ); + } else { + confirm_msg = _( "Drive to your destination?" ); + } + } else { + if( same_path_selected ) { + confirm_msg = _( "Travel to this point?" ); + } else { + confirm_msg = _( "Travel to your destination?" ); + } + } + if( query_yn( confirm_msg ) ) { + if( driving ) { + player_character.assign_activity( player_activity( autodrive_activity_actor() ) ); + } else { + player_character.reset_move_mode(); + player_character.assign_activity( ACT_TRAVELLING ); + } + return "QUIT"; + } + return NULL; +} + static tripoint_abs_omt display( const tripoint_abs_omt &orig, const draw_data_t &data = draw_data_t() ) { @@ -1748,6 +1788,9 @@ static tripoint_abs_omt display( const tripoint_abs_omt &orig, ictxt.register_action( "MOUSE_MOVE" ); ictxt.register_action( "SELECT" ); ictxt.register_action( "CHOOSE_DESTINATION" ); + ictxt.register_action( "CENTER_ON_DESTINATION" ); + ictxt.register_action( "GO_TO_DESTINATION" ); + // Actions whose keys we want to display. ictxt.register_action( "CENTER" ); @@ -1840,6 +1883,19 @@ static tripoint_abs_omt display( const tripoint_abs_omt &orig, curs.x() = p.x(); curs.y() = p.y(); } + } else if( action == "GO_TO_DESTINATION" ) { + avatar &player_character = get_avatar(); + if( !player_character.omt_path.empty() ) { + const bool driving = player_character.in_vehicle && player_character.controlling_vehicle; + action = try_travel_to_destination( player_character, curs, driving ); + } + } else if( action == "CENTER_ON_DESTINATION" ) { + avatar &player_character = get_avatar(); + if( !player_character.omt_path.empty() ) { + tripoint_abs_omt p = player_character.omt_path[0]; + curs.x() = p.x(); + curs.y() = p.y(); + } } else if( action == "CHOOSE_DESTINATION" ) { avatar &player_character = get_avatar(); const bool driving = player_character.in_vehicle && player_character.controlling_vehicle; @@ -1851,25 +1907,7 @@ static tripoint_abs_omt display( const tripoint_abs_omt &orig, player_character.omt_path.swap( path ); } if( same_path_selected && !player_character.omt_path.empty() ) { - std::string confirm_msg; - if( !driving && player_character.weight_carried() > player_character.weight_capacity() ) { - confirm_msg = _( "You are overburdened, are you sure you want to travel (it may be painful)?" ); - } else if( !driving && player_character.in_vehicle ) { - confirm_msg = _( "You are in a vehicle but not driving. Are you sure you want to walk?" ); - } else if( driving ) { - confirm_msg = _( "Drive to this point?" ); - } else { - confirm_msg = _( "Travel to this point?" ); - } - if( query_yn( confirm_msg ) ) { - if( driving ) { - player_character.assign_activity( player_activity( autodrive_activity_actor() ) ); - } else { - player_character.reset_move_mode(); - player_character.assign_activity( ACT_TRAVELLING ); - } - action = "QUIT"; - } + action = try_travel_to_destination( player_character, curs, driving ); } } else if( action == "TOGGLE_BLINKING" ) { uistate.overmap_blinking = !uistate.overmap_blinking;