Skip to content

Commit

Permalink
Fixed pocket contents displaying each item seperately (#64170)
Browse files Browse the repository at this point in the history
* Fixed pocket contents displaying each item seperately

* remove use of auto

* fixed comment

* Swap to using display_stacked_with instead of string matching

* Removed unused include
  • Loading branch information
Skrassh authored Mar 17, 2023
1 parent 735cf64 commit e1d0179
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/item_pocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,7 @@ void item_pocket::contents_info( std::vector<iteminfo> &info, int pocket_number,

// ablative pockets have their contents displayed earlier in the UI
if( !is_ablative() ) {
std::vector<std::pair<item const *, int>> counted_contents;
bool contents_header = false;
for( const item &contents_item : contents ) {
if( !contents_header ) {
Expand All @@ -1223,8 +1224,27 @@ void item_pocket::contents_info( std::vector<iteminfo> &info, int pocket_number,
contents_item.color_in_inventory() ) );
info.emplace_back( vol_to_info( cont_type_str, desc + space, contents_item.volume() ) );
} else {
info.emplace_back( "DESCRIPTION", colorize( space + contents_item.display_name(),
contents_item.color_in_inventory() ) );
bool found = false;
for( std::pair<item const *, int> &content : counted_contents ) {
if( content.first->display_stacked_with( contents_item ) ) {
content.second += 1;
found = true;
}
}
if( !found ) {
std::pair<item const *, int> new_content( &contents_item, 1 );
counted_contents.push_back( new_content );
}
}
}
for( std::pair<item const *, int> content : counted_contents ) {
if( content.second > 1 ) {
info.emplace_back( "DESCRIPTION",
space + std::to_string( content.second ) + " " + colorize( content.first->display_name(
content.second ), content.first->color_in_inventory() ) );
} else {
info.emplace_back( "DESCRIPTION", space + colorize( content.first->display_name(),
content.first->color_in_inventory() ) );
}
}
}
Expand Down

0 comments on commit e1d0179

Please sign in to comment.