92 lines
2.4 KiB
Plaintext
92 lines
2.4 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;
|
|
var rarityColor = definition?.GetRarityColor() ?? "#ffffff";
|
|
var categoryIcon = definition?.GetCategoryIcon() ?? "📦";
|
|
}
|
|
|
|
<root class="inventory-item @( Item.Equipped ? "equipped" : "" )"
|
|
@onclick="@(() => OnItemClick?.Invoke( Item ))"
|
|
@onrightclick="@( () => OnItemRightClick?.Invoke( Item ) )"
|
|
style="border-left-color: @rarityColor;">
|
|
|
|
<div class="inventory-item__icon">
|
|
@if ( !string.IsNullOrEmpty( imageUrl ) )
|
|
{
|
|
<img src="@imageUrl" alt="@name"/>
|
|
}
|
|
else
|
|
{
|
|
<span class="category-icon">@categoryIcon</span>
|
|
}
|
|
</div>
|
|
|
|
<div class="inventory-item__info">
|
|
<div class="inventory-item__name" style="color: @rarityColor;">@name</div>
|
|
@if ( definition?.Category != ItemCategory.Misc )
|
|
{
|
|
<div class="inventory-item__category">@definition?.Category</div>
|
|
}
|
|
</div>
|
|
|
|
<div class="inventory-item__meta">
|
|
@if ( slot is not null )
|
|
{
|
|
<div class="inventory-item__slot">@GetSlotName( slot.Value )</div>
|
|
}
|
|
|
|
@if ( definition?.MaxCount > 1 )
|
|
{
|
|
<div class="inventory-item__count">@Item?.Count / @definition.MaxCount</div>
|
|
}
|
|
|
|
@* @if ( Item?.Equipped == true ) *@
|
|
@* { *@
|
|
@* <div class="inventory-item__equipped">✓</div> *@
|
|
@* } *@
|
|
</div>
|
|
</root>
|
|
|
|
@code {
|
|
public Sasalka.InventoryItem Item { get; set; }
|
|
public Action<Sasalka.InventoryItem> OnItemClick { get; set; }
|
|
public Action<Sasalka.InventoryItem> OnItemRightClick { get; set; }
|
|
|
|
string GetSlotName( Inventar.InventorySlot slot )
|
|
{
|
|
return slot switch
|
|
{
|
|
Inventar.InventorySlot.LeftHand => "Л.Рука",
|
|
Inventar.InventorySlot.RightHand => "П.Рука",
|
|
Inventar.InventorySlot.Head => "Голова",
|
|
Inventar.InventorySlot.Body => "Тело",
|
|
Inventar.InventorySlot.Hands => "Руки",
|
|
Inventar.InventorySlot.Bottom => "Ноги",
|
|
Inventar.InventorySlot.Feet => "Обувь",
|
|
_ => "Неизвестно"
|
|
};
|
|
}
|
|
|
|
protected override int BuildHash()
|
|
{
|
|
base.BuildHash();
|
|
var hash = new HashCode();
|
|
hash.Add( Item?.Count );
|
|
hash.Add( Item?.Equipped );
|
|
hash.Add( Item?.Definition?.Name );
|
|
return hash.ToHashCode();
|
|
}
|
|
|
|
}
|