The InventoryItemPanel is a UI component that displays individual items within an inventory. It shows the item's icon if the item is valid, or displays the item type name if the item is invalid.
@using Sandbox;
@using Sandbox.UI;
@inherits Panel
@namespace Sandbox
<root>
<div class="container @(Selected ? "selected" : "")">
@if ( Item.IsValid() )
{
<img src="@Item.ItemIconPath" />
}
else
{
<div class="title">@Type.ToString()</div>
}
</div>
</root>
@code
{
[Property] public ItemType Type { get; set; }
[Property] public InventoryItem Item { get; set; }
public bool Selected => Item.IsValid() && !Item.IsStowed;
/// <summary>
/// the hash determines if the system should be rebuilt. If it changes, it will be rebuilt
/// </summary>
protected override int BuildHash() => System.HashCode.Combine( Item?.Id, Selected );
}