Skip to content

Commit

Permalink
Display correct item info for each item in V menu. (CleverRaven#44665)
Browse files Browse the repository at this point in the history
  • Loading branch information
OzoneH3 authored Oct 8, 2020
1 parent 9b2fd9b commit 0c78f71
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7740,7 +7740,7 @@ game::vmenu_ret game::list_items( const std::vector<map_item_stack> &item_list )
if( iItemNum > 0 && activeItem ) {
std::vector<iteminfo> vThisItem;
std::vector<iteminfo> vDummy;
activeItem->example->info( true, vThisItem );
activeItem->vIG[page_num].it->info( true, vThisItem );

item_info_data dummy( "", "", vThisItem, vDummy, iScrollPos );
dummy.without_getch = true;
Expand All @@ -7758,8 +7758,9 @@ game::vmenu_ret game::list_items( const std::vector<map_item_stack> &item_list )
if( iItemNum > 0 && activeItem ) {
// print info window title: < item name >
mvwprintw( w_item_info, point( 2, 0 ), "< " );
trim_and_print( w_item_info, point( 4, 0 ), width - 8, activeItem->example->color_in_inventory(),
activeItem->example->display_name() );
trim_and_print( w_item_info, point( 4, 0 ), width - 8,
activeItem->vIG[page_num].it->color_in_inventory(),
activeItem->vIG[page_num].it->display_name() );
wprintw( w_item_info, " >" );
}

Expand Down Expand Up @@ -7804,9 +7805,10 @@ game::vmenu_ret game::list_items( const std::vector<map_item_stack> &item_list )
} else if( action == "EXAMINE" && !filtered_items.empty() && activeItem ) {
std::vector<iteminfo> vThisItem;
std::vector<iteminfo> vDummy;
activeItem->example->info( true, vThisItem );
activeItem->vIG[page_num].it->info( true, vThisItem );

item_info_data info_data( activeItem->example->tname(), activeItem->example->type_name(), vThisItem,
item_info_data info_data( activeItem->vIG[page_num].it->tname(),
activeItem->vIG[page_num].it->type_name(), vThisItem,
vDummy );
info_data.handle_scrolling = true;

Expand Down
11 changes: 6 additions & 5 deletions src/map_item_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
#include "item_search.h"
#include "line.h"

map_item_stack::item_group::item_group() : count( 0 )
map_item_stack::item_group::item_group() : count( 0 ), it( nullptr )
{
}

map_item_stack::item_group::item_group( const tripoint &p, const int arg_count ) : pos( p ),
count( arg_count )
map_item_stack::item_group::item_group( const tripoint &p, const int arg_count,
const item *itm ) : pos( p ),
count( arg_count ), it( itm )
{
}

Expand All @@ -27,15 +28,15 @@ map_item_stack::map_item_stack() : example( nullptr ), totalcount( 0 )
map_item_stack::map_item_stack( const item *const it, const tripoint &pos ) : example( it ),
totalcount( it->count() )
{
vIG.emplace_back( pos, totalcount );
vIG.emplace_back( pos, totalcount, it );
}

void map_item_stack::add_at_pos( const item *const it, const tripoint &pos )
{
const int amount = it->count();

if( vIG.empty() || vIG.back().pos != pos ) {
vIG.emplace_back( pos, amount );
vIG.emplace_back( pos, amount, it );
} else {
vIG.back().count += amount;
}
Expand Down
3 changes: 2 additions & 1 deletion src/map_item_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ class map_item_stack
public:
tripoint pos;
int count;
const item *it;

//only expected to be used for things like lists and vectors
item_group();
item_group( const tripoint &p, int arg_count );
item_group( const tripoint &p, int arg_count, const item *itm );
};
public:
const item *example; //an example item for showing stats, etc.
Expand Down

0 comments on commit 0c78f71

Please sign in to comment.