A UI component (Blazor-style .razor) that renders a single inventory item panel. It shows the item's icon if the InventoryItem is valid and not stowed, otherwise it displays the item type as text, and it marks the panel as selected based on the item's state.
@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 );
}