Skip to content

Commit

Permalink
Merge pull request #76433 from Brambor/toggle-map-look-around
Browse files Browse the repository at this point in the history
Toggle between the map and look around
  • Loading branch information
Maleclypse authored Sep 16, 2024
2 parents ab7c711 + e65c14e commit b7fc6a9
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 1 deletion.
13 changes: 13 additions & 0 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,13 @@
"name": "Mark danger",
"bindings": [ { "input_method": "keyboard_char", "key": "R" }, { "input_method": "keyboard_code", "key": "r", "mod": [ "shift" ] } ]
},
{
"type": "keybinding",
"id": "look",
"category": "OVERMAP",
"name": "Look around",
"bindings": [ { "input_method": "keyboard_any", "key": ";" } ]
},
{
"type": "keybinding",
"id": "DELETE_NOTE",
Expand Down Expand Up @@ -2777,6 +2784,12 @@
"id": "map",
"bindings": [ { "input_method": "keyboard_any", "key": "m" } ]
},
{
"type": "keybinding",
"name": "View map",
"id": "map",
"bindings": [ { "input_method": "keyboard_any", "key": ";" } ]
},
{
"type": "keybinding",
"name": "Look at the sky",
Expand Down
2 changes: 1 addition & 1 deletion doc/POINTS_COORDINATES.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Lastly, these is a system called **segment** (seg) coordinates. These are only
used in saving/loading submaps and you are unlikely to encounter them.

As well as absolute and local coordinates, sometimes we need to use coordinates
relative so some larger scale. For example, when performing mapgen for a
relative to some larger scale. For example, when performing mapgen for a
single overmap, we want to work with coordinates within that overmap. This
will be an overmap terrain-scale point relative to the corner of its containing
overmap, and so typically take `x` and `y` values in the range [0,180).
Expand Down
8 changes: 8 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7420,6 +7420,9 @@ look_around_result game::look_around(
ctxt.register_action( "LEVEL_DOWN" );
}
ctxt.register_action( "TOGGLE_FAST_SCROLL" );
if( !has_first_point && !select_zone && !peeking && !is_moving_zone ) {
ctxt.register_action( "map" );
}
ctxt.register_action( "CHANGE_MONSTER_NAME" );
ctxt.register_action( "EXTENDED_DESCRIPTION" );
ctxt.register_action( "SELECT" );
Expand Down Expand Up @@ -7581,6 +7584,11 @@ look_around_result game::look_around(
list_items_monsters();
} else if( action == "TOGGLE_FAST_SCROLL" ) {
fast_scroll = !fast_scroll;
} else if( action == "map" ) {
uistate.open_menu = [center]() {
ui::omap::look_around_map( get_map().getglobal( center ) );
};
break;
} else if( action == "toggle_pixel_minimap" ) {
toggle_pixel_minimap();

Expand Down
5 changes: 5 additions & 0 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3012,6 +3012,11 @@ bool game::handle_action()
// starts destination activity after the player successfully reached his destination
player_character.start_destination_activity();
return false;
} else if( uistate.open_menu ) {
std::optional<std::function<void()>> open_menu_tmp = std::nullopt;
std::swap( uistate.open_menu, open_menu_tmp );
open_menu_tmp.value()();
return false;
} else {
// No auto-move, ask player for input
ctxt = get_player_input( action );
Expand Down
18 changes: 18 additions & 0 deletions src/overmap_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ static void draw_om_sidebar( ui_adaptor &ui,

print_hint( "LEVEL_UP" );
print_hint( "LEVEL_DOWN" );
print_hint( "look" );
print_hint( "CENTER" );
print_hint( "CENTER_ON_DESTINATION" );
print_hint( "GO_TO_DESTINATION" );
Expand Down Expand Up @@ -1782,6 +1783,7 @@ static tripoint_abs_omt display()
ictxt.register_action( "GO_TO_DESTINATION" );

// Actions whose keys we want to display.
ictxt.register_action( "look" );
ictxt.register_action( "CENTER" );
ictxt.register_action( "CREATE_NOTE" );
ictxt.register_action( "DELETE_NOTE" );
Expand Down Expand Up @@ -1867,6 +1869,14 @@ static tripoint_abs_omt display()
} else if( action == "SELECT" &&
( mouse_pos = ictxt.get_coordinates( g->w_overmap, point_zero, true ) ) ) {
curs += mouse_pos->xy();
} else if( action == "look" ) {
tripoint_abs_ms pos = project_combine( curs, g->overmap_data.origin_remainder );
tripoint pos_rel = get_map().getlocal( pos );
uistate.open_menu = [pos_rel]() {
tripoint pos_cpy = pos_rel;
g->look_around( true, pos_cpy, pos_rel, false, false, false, false, pos_rel );
};
action = "QUIT";
} else if( action == "CENTER" ) {
curs = orig;
} else if( action == "LEVEL_DOWN" && curs.z() > -OVERMAP_DEPTH ) {
Expand Down Expand Up @@ -2282,6 +2292,14 @@ void ui::omap::display()
overmap_ui::display();
}

void ui::omap::look_around_map( tripoint_abs_ms starting_pos )
{
g->overmap_data = overmap_ui::overmap_draw_data_t(); //reset data
std::tie( g->overmap_data.origin_pos,
g->overmap_data.origin_remainder ) = project_remain<coords::omt>( starting_pos );
overmap_ui::display();
}

void ui::omap::display_npc_path( tripoint_abs_omt starting_pos,
const std::vector<tripoint_abs_omt> &display_path )
{
Expand Down
9 changes: 9 additions & 0 deletions src/overmap_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ namespace omap
* Display overmap centered at the player's position.
*/
void display();
/**
* Display overmap centered at starting_pos.
*/
void look_around_map( tripoint_abs_ms starting_pos );
/**
* Display overmap centered at the given NPC's position and visually move across their intended OMT path.
*/
Expand Down Expand Up @@ -117,6 +121,11 @@ struct overmap_draw_data_t {
std::vector<tripoint_abs_omt> display_path = {};
//center of UI view; usually player OMT position
tripoint_abs_omt origin_pos = tripoint_abs_omt( -1, -1, -1 );
/**
* remainder for smooth toggle between map and look_around
* SEEX = SEEY is half of OMT, so point_rel_ms( SEEX, SEEY ) is middle of a tile
*/
point_omt_ms origin_remainder = point_omt_ms( SEEX, SEEY );
//UI view cursor position
tripoint_abs_omt cursor_pos = tripoint_abs_omt( -1, -1, -1 );
//the UI adaptor for the overmap; this can keep the overmap displayed while turns are processed
Expand Down
7 changes: 7 additions & 0 deletions src/uistate.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ class uistatedata
std::vector<std::string> &gethistory( const std::string &id ) {
return input_history[id];
}
/**
* A function pointer to be run before the player's next action.
*
* Useful for opening a menu with passed arguments.
*/
// NOLINTNEXTLINE(cata-serialize)
std::optional<std::function<void()>> open_menu;

// nice little convenience function for serializing an array, regardless of amount. :^)
template<typename T>
Expand Down

0 comments on commit b7fc6a9

Please sign in to comment.