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 3 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( true ) )
, 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( true ) ),
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( true );

if( has_near( zone_type_id( "LOOT_CUSTOM" ), where, range ) ) {
if( !get_near( zone_type_id( "LOOT_CUSTOM" ), where, range, &it ).empty() ) {
Expand Down
11 changes: 9 additions & 2 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 @@ -8415,10 +8416,16 @@ void item::set_snippet( const snippet_id &id )
snip_id = id;
}

const item_category &item::get_category() const
const item_category &item::get_category( bool insides ) const
{
static item_category null_category;
return type->category_force.is_valid() ? type->category_force.obj() : null_category;
if( insides && type->category_force == item_category_container &&
contents.num_item_stacks() == 1 ) {
const item &ci = contents.only_item();
return ci.type->category_force.is_valid() ? ci.type->category_force.obj() : null_category;
EvgenijM86 marked this conversation as resolved.
Show resolved Hide resolved
} else {
return type->category_force.is_valid() ? type->category_force.obj() : null_category;
}
}

iteminfo::iteminfo( const std::string &Type, const std::string &Name, const std::string &Fmt,
Expand Down
3 changes: 2 additions & 1 deletion src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ class item : public visitable<item>
bool burn( fire_data &frd );

// Returns the category of this item.
const item_category &get_category() const;
// If (insides == true) returns the category of item inside this item. I.e. "can of meat" would be food, instead of container.
const item_category &get_category( bool insides = false ) const;
EvgenijM86 marked this conversation as resolved.
Show resolved Hide resolved

class reload_option
{
Expand Down