From 0c78f715f3f9e19ef58a8ec5de5355a042dd2922 Mon Sep 17 00:00:00 2001 From: OzoneH3 Date: Thu, 8 Oct 2020 21:45:00 +0000 Subject: [PATCH] Display correct item info for each item in V menu. (#44665) --- src/game.cpp | 12 +++++++----- src/map_item_stack.cpp | 11 ++++++----- src/map_item_stack.h | 3 ++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 53f8ea1966e1d..454cdc4ee0d5d 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -7740,7 +7740,7 @@ game::vmenu_ret game::list_items( const std::vector &item_list ) if( iItemNum > 0 && activeItem ) { std::vector vThisItem; std::vector 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; @@ -7758,8 +7758,9 @@ game::vmenu_ret game::list_items( const std::vector &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, " >" ); } @@ -7804,9 +7805,10 @@ game::vmenu_ret game::list_items( const std::vector &item_list ) } else if( action == "EXAMINE" && !filtered_items.empty() && activeItem ) { std::vector vThisItem; std::vector 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; diff --git a/src/map_item_stack.cpp b/src/map_item_stack.cpp index 977d15f3a3d02..8156b9090ea72 100644 --- a/src/map_item_stack.cpp +++ b/src/map_item_stack.cpp @@ -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 ) { } @@ -27,7 +28,7 @@ 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 ) @@ -35,7 +36,7 @@ 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; } diff --git a/src/map_item_stack.h b/src/map_item_stack.h index 9f27c5ac3cd28..4436923ca07d6 100644 --- a/src/map_item_stack.h +++ b/src/map_item_stack.h @@ -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.