@using Sandbox @using Sandbox.UI @using Sasalka @inherits PanelComponent @namespace Sandbox @CurrentAmmo / @TotalInInventory @* (@MaxAmmo - вместимость магазина) *@ @if ( IsReloading ) { } @* *@ @* *@ @* *@ @* @( HasSaveFile ? "Сохранение есть" : "Нет сохранения" ) *@ @* *@ @* *@ @* @if ( HasSaveFile ) *@ @* { *@ @* *@ @* Загрузить *@ @* *@ @* } *@ @* *@ @* *@ @* Сохранить *@ @* *@ @* *@ @* @if ( HasSaveFile ) *@ @* { *@ @* *@ @* Очистить *@ @* *@ @* } *@ @* *@ @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; // Переменные для системы сохранения private bool HasSaveFile { get; set; } = false; private TimeSince _lastCheck = 0f; 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; // Проверяем наличие файла сохранения каждые 2 секунды if ( _lastCheck > 2f ) { CheckSaveFile(); _lastCheck = 0f; } } protected override void OnStart() { CheckSaveFile(); } private void CheckSaveFile() { HasSaveFile = Sasalka.InventorySaveSystem.HasSaveFile(); } private void SaveInventory() { if ( Dedugan.Local?.Inventory != null ) { Sasalka.InventorySaveSystem.SaveInventory( Dedugan.Local.Inventory ); CheckSaveFile(); } } private void LoadInventory() { if ( Dedugan.Local?.Inventory != null ) { Sasalka.InventorySaveSystem.LoadInventory( Dedugan.Local.Inventory ); CheckSaveFile(); } } private void ClearSave() { Sasalka.InventorySaveSystem.DeleteSaveFile(); CheckSaveFile(); } 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 ); hash.Add( HasSaveFile ); return hash.ToHashCode(); } }