144 lines
2.9 KiB
Plaintext
144 lines
2.9 KiB
Plaintext
@using Sandbox
|
|
@using Sandbox.UI
|
|
@inherits PanelComponent
|
|
@namespace Sandbox
|
|
|
|
<root>
|
|
<div class="crosshair"></div>
|
|
<div class="@( HasWeapon ? "" : "hidden" )">
|
|
<div class="ammo-counter">
|
|
<div class="ammo-info">
|
|
<div class="current-ammo">@CurrentAmmo</div>
|
|
<div class="separator">/</div>
|
|
<div class="max-ammo">@TotalInInventory</div>
|
|
|
|
@* <div class="inventory-ammo">(@MaxAmmo - вместимость магазина)</div> *@
|
|
</div>
|
|
</div>
|
|
|
|
@if ( IsReloading )
|
|
{
|
|
<div class="reload-progress">
|
|
<div class="reload-bar" style="width: @( ReloadProgress * 100 )%"></div>
|
|
</div>
|
|
}
|
|
</div>
|
|
</root>
|
|
|
|
<style>
|
|
.crosshair {
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 50%;
|
|
width: 4px;
|
|
height: 4px;
|
|
background-color: rgba(255, 255, 255, 0.5);
|
|
border-radius: 50%;
|
|
transform: translate(-50%, -50%);
|
|
pointer-events: none;
|
|
}
|
|
|
|
.ammo-counter {
|
|
position: absolute;
|
|
bottom: 100px;
|
|
right: 50px;
|
|
background: rgba(0, 0, 0, 0.7);
|
|
border-radius: 8px;
|
|
padding: 10px 15px;
|
|
color: white;
|
|
font-family: 'Arial', sans-serif;
|
|
font-weight: bold;
|
|
font-size: 18px;
|
|
min-width: 80px;
|
|
text-align: center;
|
|
|
|
.ammo-info {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
gap: 5px;
|
|
|
|
.current-ammo {
|
|
color: #ff6b6b;
|
|
}
|
|
|
|
.separator {
|
|
color: #666;
|
|
}
|
|
|
|
.max-ammo {
|
|
color: #999;
|
|
}
|
|
|
|
.inventory-ammo {
|
|
color: #4CAF50;
|
|
font-size: 14px;
|
|
margin-left: 8px;
|
|
}
|
|
}
|
|
}
|
|
|
|
.reload-progress {
|
|
position: absolute;
|
|
bottom: 100px;
|
|
right: 50px;
|
|
height: 4px;
|
|
width: 50px;
|
|
background: rgba(255, 255, 255, 0.2);
|
|
border-radius: 2px;
|
|
overflow: hidden;
|
|
|
|
.reload-bar {
|
|
height: 100%;
|
|
background: linear-gradient(90deg, #ff6b6b, #ff8e8e);
|
|
transition: width 0.1s ease;
|
|
}
|
|
}
|
|
|
|
.hidden {
|
|
display: none;
|
|
}
|
|
</style>
|
|
|
|
@code {
|
|
private int CurrentAmmo { get; set; } = 0;
|
|
private int MaxAmmo { get; set; } = 0;
|
|
private bool IsReloading { get; set; } = false;
|
|
private float ReloadProgress { get; set; } = 0f;
|
|
private int TotalInInventory { get; set; } = 0;
|
|
private bool HasWeapon { get; set; } = false;
|
|
|
|
protected override void OnUpdate()
|
|
{
|
|
if ( Dedugan.Local == null ) return;
|
|
|
|
var ammoInfo = Dedugan.Local.GetAmmoInfo();
|
|
CurrentAmmo = ammoInfo.current;
|
|
MaxAmmo = ammoInfo.max;
|
|
TotalInInventory = ammoInfo.totalInInventory;
|
|
|
|
ReloadProgress = Dedugan.Local.GetReloadProgress();
|
|
IsReloading = ReloadProgress < 1f;
|
|
|
|
// Проверяем, есть ли оружие в руках (если MaxAmmo > 0, значит есть оружие)
|
|
HasWeapon = MaxAmmo > 0;
|
|
}
|
|
|
|
protected override int BuildHash()
|
|
{
|
|
if ( Dedugan.Local == null || !HasWeapon )
|
|
return -1;
|
|
|
|
var hash = new System.HashCode();
|
|
hash.Add( CurrentAmmo );
|
|
hash.Add( MaxAmmo );
|
|
hash.Add( TotalInInventory );
|
|
hash.Add( IsReloading );
|
|
hash.Add( ReloadProgress );
|
|
hash.Add( HasWeapon );
|
|
|
|
return hash.ToHashCode();
|
|
}
|
|
|
|
}
|