This commit is contained in:
Oscar
2025-06-29 12:39:23 +03:00
parent eaeb0c45ac
commit db31f362d1
7 changed files with 580 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
@using Sandbox
@using Sandbox.UI
@using Sasalka
@inherits PanelComponent
@namespace Sandbox
@@ -23,6 +24,31 @@
</div>
}
</div>
<!-- Панель управления сохранением инвентаря -->
<div class="save-status">
<div class="save-indicator @( HasSaveFile ? "has-save" : "no-save" )">
<div class="save-text">@( HasSaveFile ? "Сохранение есть" : "Нет сохранения" )</div>
</div>
@if ( HasSaveFile )
{
<button class="load-button" onmousedown="LoadInventory">
<div class="button-text">Загрузить</div>
</button>
}
<button class="save-button" onmousedown="SaveInventory">
<div class="button-text">Сохранить</div>
</button>
@if ( HasSaveFile )
{
<button class="clear-button" onmousedown="ClearSave">
<div class="button-text">Очистить</div>
</button>
}
</div>
</root>
<style>
@@ -98,6 +124,95 @@
.hidden {
display: none;
}
.save-status {
position: absolute;
top: 20px;
right: 20px;
background: rgba(0, 0, 0, 0.8);
border-radius: 8px;
padding: 12px;
display: flex;
flex-direction: column;
gap: 8px;
min-width: 200px;
.save-indicator {
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
border-radius: 4px;
font-size: 14px;
font-weight: 500;
&.has-save {
background: rgba(76, 175, 80, 0.2);
color: #4CAF50;
border: 1px solid #4CAF50;
}
&.no-save {
background: rgba(244, 67, 54, 0.2);
color: #F44336;
border: 1px solid #F44336;
}
.save-text {
font-size: 14px;
font-weight: 500;
}
}
button {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 12px;
border-radius: 4px;
border: none;
cursor: pointer;
font-size: 14px;
font-weight: 500;
transition: all 0.2s ease;
&:hover {
transform: translateY(-1px);
}
&.save-button {
background: #2196F3;
color: white;
&:hover {
background: #1976D2;
}
}
&.load-button {
background: #4CAF50;
color: white;
&:hover {
background: #388E3C;
}
}
&.clear-button {
background: #F44336;
color: white;
&:hover {
background: #D32F2F;
}
}
.button-text {
font-size: 14px;
font-weight: 500;
}
}
}
</style>
@code {
@@ -107,6 +222,10 @@
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()
{
@@ -122,6 +241,47 @@
// Проверяем, есть ли оружие в руках (если 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()
@@ -136,8 +296,8 @@
hash.Add( IsReloading );
hash.Add( ReloadProgress );
hash.Add( HasWeapon );
hash.Add( HasSaveFile );
return hash.ToHashCode();
}
}