sasalka/Code/Inventory/Ui/InventoryItem.razor
2025-06-26 01:56:08 +03:00

50 lines
1.2 KiB
Plaintext

@using Sandbox.UI
@using Sasalka
@inherits Sandbox.UI.Panel
@namespace Sasalka.Ui
@{
var definition = Item?.Definition;
var name = definition?.Name;
var slot = Item?.Equipped == true ? definition?.GetSlot() : null;
var imageUrl = definition?.ImageTexture.IsValid() == true
? definition.ImageTexture.ResourcePath
: !string.IsNullOrWhiteSpace( definition?.ImageUrl )
? definition.ImageUrl
: null;
}
<root class="inventory-item @( Item.Equipped ? "equipped" : "" )" @onclick="@(() => OnItemClick?.Invoke( Item ))" @onrightclick=@( () => OnItemRightClick?.Invoke( Item ) )>
@if ( slot is not null )
{
<div class="inventory-item__slot">@slot</div>
}
@if ( !string.IsNullOrEmpty( imageUrl ) )
{
<img src="@imageUrl" alt="@name"/>
}
<div class="inventory-item__name">@name</div>
@if ( definition?.MaxCount > 1 )
{
<div class="inventory-item__count">@Item?.Count / @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; }
protected override int BuildHash()
{
base.BuildHash();
var hash = new HashCode();
hash.Add( Item?.Count );
return hash.ToHashCode();
}
}