A Blazor-style UI component (Razor) for an inventory panel. It renders a container div and creates an InventoryItemPanel for each InventorySlot in the Slots list, and overrides BuildHash to detect changes by hashing slot count and stored item ids.
@using Sandbox;
@using Sandbox.UI;
@inherits PanelComponent
@namespace Sandbox
<root>
<div class="container">
@foreach(var slot in Slots)
{
<InventoryItemPanel Item="@slot.StoredItem" Type="@slot.SlotType" />
}
</div>
</root>
@code
{
[Property] public List<InventorySlot> Slots { get; set; }
/// <summary>
/// the hash determines if the system should be rebuilt. If it changes, it will be rebuilt
/// </summary>
protected override int BuildHash()
{
var hash = new System.HashCode();
hash.Add(Slots.Count);
foreach (var slot in Slots)
{
hash.Add(slot?.StoredItem?.Id);
}
return hash.ToHashCode();
}
}