Skip to content

Commit

Permalink
v menu rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
mqrause committed Feb 23, 2022
1 parent 919d0fc commit 590cff8
Show file tree
Hide file tree
Showing 13 changed files with 1,519 additions and 204 deletions.
33 changes: 20 additions & 13 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2721,22 +2721,29 @@
},
{
"type": "keybinding",
"id": "SCROLL_ITEM_INFO_UP",
"category": "LIST_ITEMS",
"category": "LIST_SURROUNDINGS",
"id": "FILTER",
"name": "Filter",
"bindings": [ { "input_method": "keyboard_any", "key": "/" }, { "input_method": "keyboard_code", "key": "KEYPAD_DIVIDE" } ]
},
{
"type": "keybinding",
"id": "SCROLL_SURROUNDINGS_INFO_UP",
"category": "LIST_SURROUNDINGS",
"name": "Scroll item info up",
"bindings": [ { "input_method": "keyboard_char", "key": "<" }, { "input_method": "keyboard_code", "key": ",", "mod": [ "shift" ] } ]
},
{
"type": "keybinding",
"id": "SCROLL_ITEM_INFO_DOWN",
"category": "LIST_ITEMS",
"id": "SCROLL_SURROUNDINGS_INFO_DOWN",
"category": "LIST_SURROUNDINGS",
"name": "Scroll item info down",
"bindings": [ { "input_method": "keyboard_char", "key": ">" }, { "input_method": "keyboard_code", "key": ".", "mod": [ "shift" ] } ]
},
{
"type": "keybinding",
"id": "COMPARE",
"category": "LIST_ITEMS",
"category": "LIST_SURROUNDINGS",
"name": "Compare",
"bindings": [
{ "input_method": "keyboard_char", "key": "I" },
Expand All @@ -2749,7 +2756,7 @@
{
"type": "keybinding",
"id": "EXAMINE",
"category": "LIST_ITEMS",
"category": "LIST_SURROUNDINGS",
"name": "Examine",
"bindings": [
{ "input_method": "keyboard_any", "key": "e" },
Expand All @@ -2760,7 +2767,7 @@
{
"type": "keybinding",
"id": "PRIORITY_INCREASE",
"category": "LIST_ITEMS",
"category": "LIST_SURROUNDINGS",
"name": "Increase priority",
"bindings": [
{ "input_method": "keyboard_char", "key": "+" },
Expand All @@ -2771,14 +2778,14 @@
{
"type": "keybinding",
"id": "PRIORITY_DECREASE",
"category": "LIST_ITEMS",
"category": "LIST_SURROUNDINGS",
"name": "Decrease priority",
"bindings": [ { "input_method": "keyboard_any", "key": "-" }, { "input_method": "keyboard_code", "key": "KEYPAD_MINUS" } ]
},
{
"type": "keybinding",
"id": "SORT",
"category": "LIST_ITEMS",
"category": "LIST_SURROUNDINGS",
"name": "Change sort order",
"bindings": [
{ "input_method": "keyboard_any", "key": "s" },
Expand All @@ -2789,28 +2796,28 @@
{
"type": "keybinding",
"id": "SAFEMODE_BLACKLIST_ADD",
"category": "LIST_MONSTERS",
"category": "LIST_SURROUNDINGS",
"name": "Add to safemode blacklist",
"bindings": [ { "input_method": "keyboard_any", "key": "a" } ]
},
{
"type": "keybinding",
"id": "SAFEMODE_BLACKLIST_REMOVE",
"category": "LIST_MONSTERS",
"category": "LIST_SURROUNDINGS",
"name": "Remove from safemode blacklist",
"bindings": [ { "input_method": "keyboard_any", "key": "r" } ]
},
{
"type": "keybinding",
"id": "look",
"category": "LIST_MONSTERS",
"category": "LIST_SURROUNDINGS",
"name": "look around",
"bindings": [ { "input_method": "keyboard_any", "key": "x" } ]
},
{
"type": "keybinding",
"id": "fire",
"category": "LIST_MONSTERS",
"category": "LIST_SURROUNDINGS",
"name": { "ctxt": "verb", "str": "fire" },
"bindings": [ { "input_method": "keyboard_any", "key": "f" } ]
},
Expand Down
183 changes: 74 additions & 109 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6886,7 +6886,7 @@ look_around_result game::look_around( const bool show_window, tripoint &center,
action = ctxt.handle_input();
}
if( action == "LIST_ITEMS" ) {
list_items_monsters();
show_surroundings_menu();
} else if( action == "TOGGLE_FAST_SCROLL" ) {
fast_scroll = !fast_scroll;
} else if( action == "toggle_pixel_minimap" ) {
Expand Down Expand Up @@ -7051,41 +7051,41 @@ look_around_result game::look_around( look_around_params looka_params )
looka_params.select_zone, looka_params.peeking );
}

std::vector<map_item_stack> game::find_nearby_items( int iRadius )
{
std::map<std::string, map_item_stack> temp_items;
std::vector<map_item_stack> ret;
std::vector<std::string> item_order;

if( u.is_blind() ) {
return ret;
}

for( auto &points_p_it : closest_points_first( u.pos(), iRadius ) ) {
if( points_p_it.y >= u.posy() - iRadius && points_p_it.y <= u.posy() + iRadius &&
u.sees( points_p_it ) &&
m.sees_some_items( points_p_it, u ) ) {

for( item &elem : m.i_at( points_p_it ) ) {
const std::string name = elem.tname();
const tripoint relative_pos = points_p_it - u.pos();

if( std::find( item_order.begin(), item_order.end(), name ) == item_order.end() ) {
item_order.push_back( name );
temp_items[name] = map_item_stack( &elem, relative_pos );
} else {
temp_items[name].add_at_pos( &elem, relative_pos );
}
}
}
}

for( auto &elem : item_order ) {
ret.push_back( temp_items[elem] );
}

return ret;
}
//std::vector<map_item_stack> game::find_nearby_items( int iRadius )
//{
// std::map<std::string, map_item_stack> temp_items;
// std::vector<map_item_stack> ret;
// std::vector<std::string> item_order;
//
// if( u.is_blind() ) {
// return ret;
// }
//
// for( auto &points_p_it : closest_points_first( u.pos(), iRadius ) ) {
// if( points_p_it.y >= u.posy() - iRadius && points_p_it.y <= u.posy() + iRadius &&
// u.sees( points_p_it ) &&
// m.sees_some_items( points_p_it, u ) ) {
//
// for( item &elem : m.i_at( points_p_it ) ) {
// const std::string name = elem.tname();
// const tripoint relative_pos = points_p_it - u.pos();
//
// if( std::find( item_order.begin(), item_order.end(), name ) == item_order.end() ) {
// item_order.push_back( name );
// temp_items[name] = map_item_stack( &elem, relative_pos );
// } else {
// temp_items[name].add_at_pos( &elem, relative_pos );
// }
// }
// }
// }
//
// for( auto &elem : item_order ) {
// ret.push_back( temp_items[elem] );
// }
//
// return ret;
//}

void draw_trail( const tripoint &start, const tripoint &end, const bool bDrawX )
{
Expand Down Expand Up @@ -7123,49 +7123,6 @@ void game::draw_trail_to_square( const tripoint &t, bool bDrawX )
::draw_trail( u.pos(), u.pos() + t, bDrawX );
}

static void centerlistview( const tripoint &active_item_position, int ui_width )
{
Character &u = get_avatar();
if( get_option<std::string>( "SHIFT_LIST_ITEM_VIEW" ) != "false" ) {
u.view_offset.z = active_item_position.z;
if( get_option<std::string>( "SHIFT_LIST_ITEM_VIEW" ) == "centered" ) {
u.view_offset.x = active_item_position.x;
u.view_offset.y = active_item_position.y;
} else {
point pos( active_item_position.xy() + point( POSX, POSY ) );

// item/monster list UI is on the right, so get the difference between its width
// and the width of the sidebar on the right (if any)
int sidebar_right_adjusted = ui_width - panel_manager::get_manager().get_width_right();
// if and only if that difference is greater than zero, use that as offset
int right_offset = sidebar_right_adjusted > 0 ? sidebar_right_adjusted : 0;

// Convert offset to tile counts, calculate adjusted terrain window width
// This lets us account for possible differences in terrain width between
// the normal sidebar and the list-all-whatever display.
to_map_font_dim_width( right_offset );
int terrain_width = TERRAIN_WINDOW_WIDTH - right_offset;

if( pos.x < 0 ) {
u.view_offset.x = pos.x;
} else if( pos.x >= terrain_width ) {
u.view_offset.x = pos.x - ( terrain_width - 1 );
} else {
u.view_offset.x = 0;
}

if( pos.y < 0 ) {
u.view_offset.y = pos.y;
} else if( pos.y >= TERRAIN_WINDOW_HEIGHT ) {
u.view_offset.y = pos.y - ( TERRAIN_WINDOW_HEIGHT - 1 );
} else {
u.view_offset.y = 0;
}
}
}

}

#if defined(TILES)
static constexpr int MAXIMUM_ZOOM_LEVEL = 4;
#endif
Expand Down Expand Up @@ -7367,25 +7324,17 @@ void game::reset_item_list_state( const catacurses::window &window, int height,
}
}

void game::list_items_monsters()
void game::show_surroundings_menu()
{
// Search whole reality bubble because each function internally verifies
// the visibilty of the items / monsters in question.
std::vector<Creature *> mons = u.get_visible_creatures( 60 );
const std::vector<map_item_stack> items = find_nearby_items( 60 );
const std::vector<map_entity_stack<item>> items;// = find_nearby_items(60);

if( mons.empty() && items.empty() ) {
/*if( mons.empty() && items.empty() ) {
add_msg( m_info, _( "You don't see any items or monsters around you!" ) );
return;
}

std::sort( mons.begin(), mons.end(), [&]( const Creature * lhs, const Creature * rhs ) {
const Creature::Attitude att_lhs = lhs->attitude_to( u );
const Creature::Attitude att_rhs = rhs->attitude_to( u );

return att_lhs < att_rhs || ( att_lhs == att_rhs
&& rl_dist( u.pos(), lhs->pos() ) < rl_dist( u.pos(), rhs->pos() ) );
} );
}*/

// If the current list is empty, switch to the non-empty list
if( uistate.vmenu_show_items ) {
Expand All @@ -7397,23 +7346,39 @@ void game::list_items_monsters()
}

temp_exit_fullscreen();
game::vmenu_ret ret;
while( true ) {
ret = uistate.vmenu_show_items ? list_items( items ) : list_monsters( mons );
if( ret == game::vmenu_ret::CHANGE_TAB ) {
uistate.vmenu_show_items = !uistate.vmenu_show_items;

cata::optional<tripoint> path_start = u.pos();
cata::optional<tripoint> path_end = cata::nullopt;
surroundings_menu vmenu(
u,
m,
path_end,
[&]( bool z_in ) {
if( z_in ) {
zoom_in();
} else {
break;
zoom_out();
}
}
mark_main_ui_adaptor_resize();
},
[&]() {
invalidate_main_ui_adaptor();
},
[&]() {
look_around();
} );

shared_ptr_fast<draw_callback_t> trail_cb = create_trail_callback( path_start, path_end, true );
add_draw_callback( trail_cb );

if( ret == game::vmenu_ret::FIRE ) {
if( vmenu.execute() == surroundings_menu_ret::fire ) {
avatar_action::fire_wielded_weapon( u );
}

reenter_fullscreen();
}

game::vmenu_ret game::list_items( const std::vector<map_item_stack> &item_list )
/*vmenu_ret game::list_items(const std::vector<map_item_stack>& item_list)
{
std::vector<map_item_stack> ground_items = item_list;
int iInfoHeight = 0;
Expand Down Expand Up @@ -7858,7 +7823,7 @@ game::vmenu_ret game::list_items( const std::vector<map_item_stack> &item_list )
mark_main_ui_adaptor_resize();
} else if( action == "NEXT_TAB" || action == "PREV_TAB" ) {
u.view_offset = stored_view_offset;
return game::vmenu_ret::CHANGE_TAB;
return vmenu_ret::nexttab;
}

active_pos = tripoint_zero;
Expand Down Expand Up @@ -7897,10 +7862,10 @@ game::vmenu_ret game::list_items( const std::vector<map_item_stack> &item_list )
} while( action != "QUIT" );

u.view_offset = stored_view_offset;
return game::vmenu_ret::QUIT;
}
return vmenu_ret::quit;
}*/

game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list )
surroundings_menu_ret game::list_monsters( const std::vector<Creature *> &monster_list )
{
const int iInfoHeight = 15;
const int width = 55;
Expand Down Expand Up @@ -7935,7 +7900,7 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
TERMY - iInfoHeight ) );

if( cCurMon ) {
centerlistview( iActivePos, width );
//centerlistview( iActivePos, width );
}

ui.position( point( offsetX, 0 ), point( width, TERMY ) );
Expand Down Expand Up @@ -8190,7 +8155,7 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
}
} else if( action == "NEXT_TAB" || action == "PREV_TAB" ) {
u.view_offset = stored_view_offset;
return game::vmenu_ret::CHANGE_TAB;
return surroundings_menu_ret::nexttab;
} else if( action == "zoom_in" ) {
zoom_in();
mark_main_ui_adaptor_resize();
Expand Down Expand Up @@ -8223,14 +8188,14 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list
u.last_target = shared_from( *cCurMon );
u.recoil = MAX_RECOIL;
u.view_offset = stored_view_offset;
return game::vmenu_ret::FIRE;
return surroundings_menu_ret::fire;
}
}

if( iActive >= 0 && static_cast<size_t>( iActive ) < monster_list.size() ) {
cCurMon = monster_list[iActive];
iActivePos = cCurMon->pos() - u.pos();
centerlistview( iActivePos, width );
//centerlistview( iActivePos, width );
trail_start = u.pos();
trail_end = cCurMon->pos();
// Actually accessed from the terrain overlay callback `trail_cb` in the
Expand All @@ -8252,7 +8217,7 @@ game::vmenu_ret game::list_monsters( const std::vector<Creature *> &monster_list

u.view_offset = stored_view_offset;

return game::vmenu_ret::QUIT;
return surroundings_menu_ret::quit;
}

void game::unload_container()
Expand Down
Loading

0 comments on commit 590cff8

Please sign in to comment.