Highlight New Item in Inventory

Hi there!

I've been messing around with trying to show an exclamation point on newly acquired items in the inventory, but I'm having trouble drilling down to the actual item. I added a gameobject to the ItemView that I'd like to be able to turn on and off based on the ItemInfo:

Screen Shot 2021-11-27 at 1.08.50 PM.png

Currently listening to the OnItemAmountAdded event with:
C#:
Opsive.Shared.Events.EventHandler.RegisterEvent<ItemInfo, ItemStack>(inventory,
                        EventNames.c_Inventory_OnAdd_ItemInfo_ItemStack,
                        OnItemAmountAdded);

What would be the best way to get the item slot that contains that ItemInfo from within the inventory?

Thanks as always for the great support!
 
Interesting, I never thought about this use case.

I would create a custom Item View Module for this.

The problem with checking the ItemViewSlot is that the item might be shown on anoter page or tab, so you would need to check constantly at each redraw of the Inventory UI.

Having a custom ItemViewModule you can check if the ItemInfo you are about to draw is contained in that list of new ItemInfo. Depending on where you are have that list you may need to inherit an interface for your custom ItemViewModule. By default if an Item is not null and is Unique and Mutable then you can get the inventory it is stored in. But many items are not unique or mutable so to get the Inventory in an ItemViewModule you can use the "IInventoryDependent" interface. That will make sure you have a reference to the Inventory (The ItemViewSlotContainer, in your case the Inventory Grid is the one that sets that Inventory value).

There are other interfaces you can inherit from documented here:

From the Inventory component you should be able to get the component that has the list of new ItemInfos. Remember that in the event you are listening to "ItemInfo" is the item that was planned to be added. The "ItemStack" is where the item was added. So if you add 2 apples and you already had 3 apples, ItemInfo will be 2 apples and ItemStack will be 5 apples. To compare with ItemViewModule you'll want the ItemStack (which can be converted to the an ItemInfo if you like)

I hope that helps
 
You would need to keep track of that yourself. There are many ways you could go about it.
Listening to the Add events, similar to the Inventory monitor.
Or you could cache all the items in the Inventory each time it is opened and then compare the previous cached inventory items with the new ones to find out which ones are new.
 
Top