From f68abb08fe397648ce331c60bda5d17c8c4a49dd Mon Sep 17 00:00:00 2001 From: Roy Berube Date: Sun, 27 Mar 2022 12:55:57 -0600 Subject: [PATCH] Prevent container item appearing twice in AIM (#56335) --- src/advanced_inv.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/advanced_inv.cpp b/src/advanced_inv.cpp index a33715b4d20cc..e703b7a954f97 100644 --- a/src/advanced_inv.cpp +++ b/src/advanced_inv.cpp @@ -628,12 +628,12 @@ void advanced_inventory::recalc_pane( side p ) advanced_inventory_pane &pane = panes[p]; pane.recalc = false; pane.items.clear(); + advanced_inventory_pane &there = panes[-p + 1]; + advanced_inv_area &other = squares[there.get_area()]; // Add items from the source location or in case of all 9 surrounding squares, // add items from several locations. if( pane.get_area() == AIM_ALL ) { advanced_inv_area &alls = squares[AIM_ALL]; - advanced_inventory_pane &there = panes[-p + 1]; - advanced_inv_area &other = squares[there.get_area()]; alls.volume = 0_ml; alls.weight = 0_gram; for( advanced_inv_area &s : squares ) { @@ -668,6 +668,30 @@ void advanced_inventory::recalc_pane( side p ) } else { pane.add_items_from_area( squares[pane.get_area()] ); } + + // Prevent same container item appearing in this pane when other pane is the container view. + if( there.get_area() == AIM_CONTAINER ) { + item_location loc = other.get_container(); + std::vector::iterator outer_iter = pane.items.begin(); + while( outer_iter != pane.items.end() ) { + if( !outer_iter->items.empty() ) { + std::vector::iterator iter = outer_iter->items.begin(); + while( iter != outer_iter->items.end() ) { + if( loc == *iter ) { + iter = outer_iter->items.erase( iter ); + } else { + iter++; + } + } + } + if( outer_iter->items.empty() ) { + outer_iter = pane.items.erase( outer_iter ); + } else { + outer_iter++; + } + } + } + // Sort all items std::stable_sort( pane.items.begin(), pane.items.end(), advanced_inv_sorter( pane.sortby ) ); }