Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix zone sorting and category display in advanced inventory UI. #41820

Merged
merged 5 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/advanced_inv_listitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ advanced_inv_listitem::advanced_inv_listitem( item *an_item, int index, int coun
, stacks( count )
, volume( an_item->volume() * stacks )
, weight( an_item->weight() * stacks )
, cat( &an_item->get_category() )
, cat( &an_item->get_category_of_contents() )
, from_vehicle( from_vehicle )
{
items.push_back( an_item );
Expand All @@ -35,7 +35,7 @@ advanced_inv_listitem::advanced_inv_listitem( const std::vector<item *> &list, i
stacks( list.size() ),
volume( list.front()->volume() * stacks ),
weight( list.front()->weight() * stacks ),
cat( &list.front()->get_category() ),
cat( &list.front()->get_category_of_contents() ),
from_vehicle( from_vehicle )
{
assert( stacks >= 1 );
Expand Down
2 changes: 1 addition & 1 deletion src/clzones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ cata::optional<tripoint> zone_manager::get_nearest( const zone_type_id &type, co
zone_type_id zone_manager::get_near_zone_type_for_item( const item &it,
const tripoint &where, int range ) const
{
const item_category &cat = it.get_category();
const item_category &cat = it.get_category_of_contents();

if( has_near( zone_type_id( "LOOT_CUSTOM" ), where, range ) ) {
if( !get_near( zone_type_id( "LOOT_CUSTOM" ), where, range, &it ).empty() ) {
Expand Down
10 changes: 10 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ static const ammotype ammo_plutonium( "plutonium" );
static const item_category_id item_category_drugs( "drugs" );
static const item_category_id item_category_food( "food" );
static const item_category_id item_category_maps( "maps" );
static const item_category_id item_category_container( "container" );

static const efftype_id effect_cig( "cig" );
static const efftype_id effect_shakes( "shakes" );
Expand Down Expand Up @@ -8421,6 +8422,15 @@ const item_category &item::get_category() const
return type->category_force.is_valid() ? type->category_force.obj() : null_category;
}

const item_category &item::get_category_of_contents() const
{
if( type->category_force == item_category_container && contents.num_item_stacks() == 1 ) {
return contents.only_item().get_category();
} else {
return this->get_category();
}
}

iteminfo::iteminfo( const std::string &Type, const std::string &Name, const std::string &Fmt,
flags Flags, double Value )
{
Expand Down
3 changes: 3 additions & 0 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,9 @@ class item : public visitable<item>

// Returns the category of this item.
const item_category &get_category() const;
// Returns the category of item inside this item. I.e. "can of meat" would be food, instead of container.
// If there are multiple items/stacks or none then it defaults to category of this item.
const item_category &get_category_of_contents() const;

class reload_option
{
Expand Down