sasalka/Code/Inventory/Ui/InventoryItem.razor
2025-06-10 23:24:50 +03:00

46 lines
1.2 KiB
Plaintext

@using Sandbox.UI
@using Sasalka
@inherits Sandbox.UI.Panel
@namespace Sasalka.Ui
<root class="inventory-item @( Equipped ? "equipped" : "" )" @onclick="@(() => OnItemClick?.Invoke( Item ))" @onrightclick=@( () => OnItemRightClick?.Invoke( Item ) )>
@* <input type="checkbox" class="equipped-checkbox" checked="@Equipped" disabled/> *@
@if ( Item.Definition.ImageTexture.IsValid() )
{
<img src="@Item.Definition.ImageTexture.ResourcePath" alt="@Item.Definition.Name"/>
}
else if ( Item.Definition.ImageUrl.Length > 0 )
{
<img src="@Item.Definition.ImageUrl" alt="@Item.Definition.Name">
}
<div class="inventory-item__name">@Item?.Definition.Name</div>
@if ( Item?.Definition.MaxCount > 1 )
{
<div class="inventory-item__count">@Item?.Count / @Item?.Definition.MaxCount</div>
}
</root>
@code {
public Sasalka.InventoryItem Item { get; set; }
public Action<Sasalka.InventoryItem> OnItemClick { get; set; }
public Action<Sasalka.InventoryItem> OnItemRightClick { get; set; }
public bool Equipped { get; set; }
protected override int BuildHash()
{
base.BuildHash();
var hash = new HashCode();
hash.Add( Item.Count );
return hash.ToHashCode();
}
}