I’m trying to make an item shop using the Unity UI Builder. I have a listview of available items and a buy button. There is also an Item class, and a runItemList of extent items. When the buy button is pressed, I mark the Items as owned, remake the list of available items, and then rebuild the ListView. However, I am finding that the listview removes the lowest item from the list, rather than the selected ones. Though this appears just to be a visible bug; if I select an item from the new (reduced) list and buy it, I get the item that would be at that index, if the first purchase had happened correctly.
void BuyButtonPressed()
{
// Mark as owned
shopListView.selectedItems.Cast<Item>().ToList().ForEach(item => item.owned = true);
List<Item> itemList = itemManager.runItemList.itemList.Where(item => !item.owned).ToList();
shopListView.itemsSource = itemList;
shopListView.Rebuild();
}
Ring of QNZ about to be purchased
Item shop post-purchase. Note that the Ring of QNZ has been correctly purchased. If I now try to purchase the bottom item, listed as Shoes of GtL, I instead purchase the Shoes of Bds, the true bottom item of the list but which is not shown, since the Ring of QNZ is still listed (that slot will purchase the Gloves of vyL etc.)
If I change tabs and return, the shop reloads correctly.