From f7948735cc704d9b2d5f82de188a03f40b1b7c58 Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Wed, 6 May 2020 22:16:08 -0400 Subject: [PATCH] allow consume menu to look in containers --- src/inventory_ui.cpp | 30 ++++++++++++++++++++++-------- src/inventory_ui.h | 1 + 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/inventory_ui.cpp b/src/inventory_ui.cpp index 1fc9001082bd2..2b622d1aed365 100644 --- a/src/inventory_ui.cpp +++ b/src/inventory_ui.cpp @@ -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 ) ); } } @@ -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 @@ -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 ); + } } } @@ -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 ); @@ -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 ) diff --git a/src/inventory_ui.h b/src/inventory_ui.h index f51ebeb48eaa9..1d59b135dcc18 100644 --- a/src/inventory_ui.h +++ b/src/inventory_ui.h @@ -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 );