UI/InventoryWeapon.razor
@using Sandbox;
@using Sandbox.UI;
@inherits Panel
<root>
<div class="icon">
<div class="inner" @ref="IconPanel"></div>
</div>
@if ( IsActive )
{
<div class="info">
@if ( Weapon.IsValid() && Weapon.UsesAmmo )
{
@if ( Weapon.UsesClips )
{
<span>
<label>@(Weapon.ClipContents)</label>
<label class="small">@(Weapon.Owner.GetAmmoCount(Weapon.AmmoResource))</label>
</span>
}
else
{
<label>@(Weapon.Owner.GetAmmoCount(Weapon.AmmoResource))</label>
}
}
else
{
<label>@Carryable.DisplayName</label>
}
</div>
@if ( Weapon.IsValid() && Weapon.SecondaryAmmoResource.IsValid() )
{
<div class="extra">
@if ( Weapon.SecondaryAmmoResource.Icon.IsValid() )
{
<div @ref="AmmoIconPanel" />
}
<label>@Weapon.Owner.GetAmmoCount(Weapon.SecondaryAmmoResource)</label>
</div>
}
}
</root>
@code
{
public Carryable Carryable { get; set; }
public BaseWeapon Weapon => Carryable as BaseWeapon;
public bool IsActive => Player.Local.Inventory.Current == Carryable;
public bool IsHovered { get; set; }
public bool CanSwitch { get; set; }
Panel AmmoIconPanel { get; set; }
Panel IconPanel { get; set; }
public void ApplyIcon()
{
IconPanel.Style.SetBackgroundImage( Carryable.DisplayIcon );
}
public override void Tick()
{
if ( !Carryable.IsValid() ) return;
SetClass( "active", IsHovered );
SetClass( "selected", IsActive );
SetClass( "switchable", CanSwitch );
if ( AmmoIconPanel.IsValid() )
{
AmmoIconPanel.Style.SetBackgroundImage( Weapon.SecondaryAmmoResource.Icon );
}
ApplyIcon();
}
protected override int BuildHash()
{
return HashCode.Combine( Time.Now );
}
}