Skip to content

Commit

Permalink
Add two travel-related overmap keybinds for a better UX
Browse files Browse the repository at this point in the history
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
  • Loading branch information
strategineer committed Mar 12, 2023
1 parent 8c501c1 commit bcb7469
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 19 deletions.
12 changes: 12 additions & 0 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
76 changes: 57 additions & 19 deletions src/overmap_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down Expand Up @@ -1695,6 +1697,44 @@ static std::vector<tripoint_abs_omt> 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<tripoint_abs_omt> 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() )
{
Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit bcb7469

Please sign in to comment.