Skip to content

Commit

Permalink
Fixed some issues with displaying item's mods counter (#3338)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vollch authored Oct 2, 2023
1 parent ca42b1e commit 9d34b99
Showing 1 changed file with 40 additions and 29 deletions.
69 changes: 40 additions & 29 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4651,43 +4651,54 @@ std::string item::tname( unsigned int quantity, bool with_prefix, unsigned int t
std::string maintext;
if( is_corpse() || typeId() == itype_blood || item_vars.find( "name" ) != item_vars.end() ) {
maintext = type_name( quantity );
} else if( is_gun() || is_tool() || is_magazine() ) {
int amt = 0;
maintext = label( quantity );
for( const item *mod : is_gun() ? gunmods() : toolmods() ) {
if( !type->gun || !type->gun->built_in_mods.count( mod->typeId() ) ) {
amt++;
}
}
if( amt ) {
maintext += string_format( "+%d", amt );
}
} else if( is_armor() && has_clothing_mod() ) {
maintext = label( quantity ) + "+1";
} else if( is_craft() ) {
maintext = string_format( _( "in progress %s" ), craft_data_->making->result_name() );
if( charges > 1 ) {
maintext += string_format( " (%d)", charges );
}
const int percent_progress = item_counter / 100000;
maintext += string_format( " (%d%%)", percent_progress );
} else if( contents.num_item_stacks() == 1 ) {
const item &contents_item = contents.front();
const unsigned contents_count =
( ( contents_item.made_of( LIQUID ) || contents_item.is_food() ) &&
contents_item.charges > 1 )
? contents_item.charges
: quantity;
maintext = string_format( pgettext( "item name", "%2$s (%1$s)" ), label( quantity ),
contents_item.tname( contents_count, with_prefix ) );
} else if( !contents.empty() ) {
maintext = string_format( vpgettext( "item name",
//~ %1$s: item name, %2$zd: content size
"%1$s with %2$zd item",
"%1$s with %2$zd items", contents.num_item_stacks() ),
label( quantity ), contents.num_item_stacks() );
} else {
maintext = label( quantity );
std::string labeltext = label( quantity );

int modamt = 0;
if( is_tool() ) {
modamt += toolmods().size();
}
if( is_gun() ) {
for( const item *mod : gunmods() ) {
if( !type->gun->built_in_mods.count( mod->typeId() ) ) {
modamt++;
}
}
}
if( is_armor() && has_clothing_mod() ) {
modamt++;
}
if( modamt ) {
labeltext += string_format( "+%d", modamt );
}

if( is_gun() || is_tool() || is_magazine() ) {
maintext = labeltext;
} else if( contents.num_item_stacks() == 1 ) {
const item &contents_item = contents.front();
const unsigned contents_count =
( ( contents_item.made_of( LIQUID ) || contents_item.is_food() ) &&
contents_item.charges > 1 )
? contents_item.charges
: quantity;
maintext = string_format( pgettext( "item name", "%2$s (%1$s)" ), labeltext,
contents_item.tname( contents_count, with_prefix ) );
} else if( !contents.empty() ) {
maintext = string_format( vpgettext( "item name",
//~ %1$s: item name, %2$zd: content size
"%1$s with %2$zd item",
"%1$s with %2$zd items", contents.num_item_stacks() ),
labeltext, contents.num_item_stacks() );
} else {
maintext = labeltext;
}
}

avatar &you = get_avatar();
Expand Down

0 comments on commit 9d34b99

Please sign in to comment.