Skip to content

Commit

Permalink
Merge pull request #40285 from KorGgenT/fix-consume-menu-again
Browse files Browse the repository at this point in the history
allow consume menu to look in containers
  • Loading branch information
ZhilkinSerg authored May 7, 2020
2 parents 09fc2ae + f794873 commit 4ab8e06
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,10 +1225,16 @@ void inventory_selector::add_items( inventory_column &target_column,
}

void inventory_selector::add_contained_items( item_location container )
{
add_contained_items( container, own_inv_column );
}

void inventory_selector::add_contained_items( item_location container, inventory_column &column )
{
for( item *it : container->contents.all_items_top() ) {
add_item( own_inv_column, item_location( container, it ),
&it->get_category() );
item_location child( container, it );
add_contained_items( child, column );
add_item( column, std::move( child ) );
}
}

Expand All @@ -1250,10 +1256,8 @@ void inventory_selector::add_character_items( Character &character )
return item_location( character, it );
}, restack_items( ( *elem ).begin(), ( *elem ).end(), preset.get_checking_components() ) );
for( item &it_elem : *elem ) {
for( item *it : it_elem.contents.all_items_ptr( item_pocket::pocket_type::CONTAINER ) ) {
add_item( own_inv_column, item_location( item_location( character, &it_elem ), it ),
&it->get_category() );
}
item_location parent( character, &it_elem );
add_contained_items( parent, own_inv_column );
}
}
// this is a little trick; we want the default behavior for contained items to be in own_inv_column
Expand All @@ -1265,13 +1269,18 @@ void inventory_selector::add_character_items( Character &character )
void inventory_selector::add_map_items( const tripoint &target )
{
if( g->m.accessible_items( target ) ) {
const auto items = g->m.i_at( target );
map_stack items = g->m.i_at( target );
const std::string name = to_upper_case( g->m.name( target ) );
const item_category map_cat( name, no_translation( name ), 100 );

add_items( map_column, [ &target ]( item * it ) {
return item_location( target, it );
}, restack_items( items.begin(), items.end(), preset.get_checking_components() ), &map_cat );

for( item &it_elem : items ) {
item_location parent( map_cursor( target ), &it_elem );
add_contained_items( parent, map_column );
}
}
}

Expand All @@ -1283,7 +1292,7 @@ void inventory_selector::add_vehicle_items( const tripoint &target )
}
vehicle *const veh = &vp->vehicle();
const int part = vp->part_index();
const auto items = veh->get_items( part );
vehicle_stack items = veh->get_items( part );
const std::string name = to_upper_case( remove_color_tags( veh->parts[part].name() ) );
const item_category vehicle_cat( name, no_translation( name ), 200 );

Expand All @@ -1292,6 +1301,11 @@ void inventory_selector::add_vehicle_items( const tripoint &target )
add_items( map_column, [ veh, part ]( item * it ) {
return item_location( vehicle_cursor( *veh, part ), it );
}, restack_items( items.begin(), items.end(), check_components ), &vehicle_cat );

for( item &it_elem : items ) {
item_location parent( vehicle_cursor( *veh, part ), &it_elem );
add_contained_items( parent, map_column );
}
}

void inventory_selector::add_nearby_items( int radius )
Expand Down
1 change: 1 addition & 0 deletions src/inventory_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ class inventory_selector
virtual ~inventory_selector();
/** These functions add items from map / vehicles. */
void add_contained_items( item_location container );
void add_contained_items( item_location container, inventory_column &column );
void add_character_items( Character &character );
void add_map_items( const tripoint &target );
void add_vehicle_items( const tripoint &target );
Expand Down

0 comments on commit 4ab8e06

Please sign in to comment.