Skip to content

Commit

Permalink
Volume and length details for containers is a menu option (#53848)
Browse files Browse the repository at this point in the history
  • Loading branch information
bombasticSlacks authored Dec 30, 2021
1 parent 24e295c commit 3c154af
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
49 changes: 28 additions & 21 deletions src/inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,27 +400,34 @@ std::string inventory_selector_preset::get_cell_text( const inventory_entry &ent
} else if( entry.is_item() ) {
std::string text = cells[cell_index].get_text( entry );
const item &actual_item = *entry.locations.front();
if( cell_index == 0 && !text.empty() &&
entry.get_category_ptr()->get_id() == item_category_ITEMS_WORN &&
actual_item.is_worn_by_player() &&
actual_item.is_container() && actual_item.has_unrestricted_pockets() ) {
const units::volume total_capacity = actual_item.get_total_capacity( true );
const units::mass total_capacity_weight = actual_item.get_total_weight_capacity( true );
const units::length max_containable_length = actual_item.max_containable_length( true );

const units::volume actual_capacity = actual_item.get_total_contained_volume( true );
const units::mass actual_capacity_weight = actual_item.get_total_contained_weight( true );

container_data container_data = {
actual_capacity,
total_capacity,
actual_capacity_weight,
total_capacity_weight,
max_containable_length
};
std::string formatted_string = container_data.to_formatted_string( false );

text = text + string_format( " %s", formatted_string );
const std::string info_display = get_option<std::string>( "DETAILED_CONTAINERS" );
// if we want no additional info skip this
if( info_display != "NONE" ) {
// if we want additional info for all items or it is worn then add the additional info
if( info_display == "ALL" || ( info_display == "WORN" &&
entry.get_category_ptr()->get_id() == item_category_ITEMS_WORN &&
actual_item.is_worn_by_player() ) ) {
if( cell_index == 0 && !text.empty() &&
actual_item.is_container() && actual_item.has_unrestricted_pockets() ) {
const units::volume total_capacity = actual_item.get_total_capacity( true );
const units::mass total_capacity_weight = actual_item.get_total_weight_capacity( true );
const units::length max_containable_length = actual_item.max_containable_length( true );

const units::volume actual_capacity = actual_item.get_total_contained_volume( true );
const units::mass actual_capacity_weight = actual_item.get_total_contained_weight( true );

container_data container_data = {
actual_capacity,
total_capacity,
actual_capacity_weight,
total_capacity_weight,
max_containable_length
};
std::string formatted_string = container_data.to_formatted_string( false );

text = text + string_format( " %s", formatted_string );
}
}
}
return text;
} else if( cell_index != 0 ) {
Expand Down
8 changes: 8 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,14 @@ void options_manager::add_options_interface()
to_translation( "If true, the default ammo is added to weapon and magazine names. For example \"Mosin-Nagant M44 (4/5)\" becomes \"Mosin-Nagant M44 (4/5 7.62x54mm)\"." ),
true
);
add( "DETAILED_CONTAINERS", "interface", to_translation( "Detailed Containers" ),
to_translation( "All: every container has detailed remaining volume info - Worn: only worn containers have detailed remaining volume info - None: no additional info is provided" ),
{
{ "ALL", to_translation( "All" ) },
{ "WORN", to_translation( "Worn" ) },
{ "NONE", to_translation( "None" ) }
},
"WORN" );

add_empty_line();

Expand Down

0 comments on commit 3c154af

Please sign in to comment.