From 2632090e5960f47fcd63ed42ff079f7b04f38d68 Mon Sep 17 00:00:00 2001 From: CalKerethi Date: Sat, 12 Feb 2022 14:16:06 -0500 Subject: [PATCH 1/2] Limit items shown when setting pocket filters --- src/item_contents.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/item_contents.cpp b/src/item_contents.cpp index 7a5c4a97d2edb..316b0af849c9f 100644 --- a/src/item_contents.cpp +++ b/src/item_contents.cpp @@ -154,7 +154,10 @@ bool pocket_favorite_callback::key( const input_context &, const input_event &ev cata::flat_set nearby_itypes; selector_menu.title = _( "Select an item from nearby" ); for( const std::list *it_list : get_player_character().crafting_inventory().const_slice() ) { - nearby_itypes.insert( it_list->front().typeId() ); + item it = it_list->front(); + if( !it.is_null() && selected_pocket->is_compatible( it ).success() ) { + nearby_itypes.insert( it.typeId() ); + } } std::vector> listed_names; @@ -182,7 +185,11 @@ bool pocket_favorite_callback::key( const input_context &, const input_event &ev for( const std::pair &it : nearby_names ) { selector_menu.addentry( add_prefix + it.second ); } - selector_menu.query(); + if( selector_menu.entries.empty() ) { + popup( std::string( _( "No nearby items would fit here." ) ), PF_GET_KEY ); + } else { + selector_menu.query(); + } const int selected = selector_menu.ret; itype_id selected_id = itype_id::NULL_ID(); From 32b32acfe6e07941da2923560e8598fc2e090e09 Mon Sep 17 00:00:00 2001 From: CalKerethi Date: Sat, 12 Feb 2022 16:05:38 -0500 Subject: [PATCH 2/2] Call is_compatible later and on a fresh copy This will save some repeated calls and allow showing items that were only excluded because they were full of stuff at the time. --- src/item_contents.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/item_contents.cpp b/src/item_contents.cpp index 316b0af849c9f..241eda735f036 100644 --- a/src/item_contents.cpp +++ b/src/item_contents.cpp @@ -154,10 +154,7 @@ bool pocket_favorite_callback::key( const input_context &, const input_event &ev cata::flat_set nearby_itypes; selector_menu.title = _( "Select an item from nearby" ); for( const std::list *it_list : get_player_character().crafting_inventory().const_slice() ) { - item it = it_list->front(); - if( !it.is_null() && selected_pocket->is_compatible( it ).success() ) { - nearby_itypes.insert( it.typeId() ); - } + nearby_itypes.insert( it_list->front().typeId() ); } std::vector> listed_names; @@ -168,7 +165,7 @@ bool pocket_favorite_callback::key( const input_context &, const input_event &ev listed_names.emplace_back( id, id->nname( 1 ) ); } for( const itype_id &id : nearby_itypes ) { - if( !listed_itypes.count( id ) ) { + if( !listed_itypes.count( id ) && selected_pocket->is_compatible( item( id ) ).success() ) { nearby_names.emplace_back( id, id->nname( 1 ) ); } }