Trash bag visualizer (#7199)
This commit is contained in:
@@ -73,9 +73,9 @@ namespace Content.Server.Storage.Components
|
||||
private EntityWhitelist? _whitelist = null;
|
||||
|
||||
private bool _storageInitialCalculated;
|
||||
private int _storageUsed;
|
||||
public int StorageUsed;
|
||||
[DataField("capacity")]
|
||||
private int _storageCapacityMax = 10000;
|
||||
public int StorageCapacityMax = 10000;
|
||||
public readonly HashSet<IPlayerSession> SubscribedSessions = new();
|
||||
|
||||
[DataField("storageSoundCollection")]
|
||||
@@ -123,7 +123,7 @@ namespace Content.Server.Storage.Components
|
||||
|
||||
private void RecalculateStorageUsed()
|
||||
{
|
||||
_storageUsed = 0;
|
||||
StorageUsed = 0;
|
||||
_sizeCache.Clear();
|
||||
|
||||
if (Storage == null)
|
||||
@@ -134,7 +134,7 @@ namespace Content.Server.Storage.Components
|
||||
foreach (var entity in Storage.ContainedEntities)
|
||||
{
|
||||
var item = _entityManager.GetComponent<SharedItemComponent>(entity);
|
||||
_storageUsed += item.Size;
|
||||
StorageUsed += item.Size;
|
||||
_sizeCache.Add(entity, item.Size);
|
||||
}
|
||||
}
|
||||
@@ -149,13 +149,13 @@ namespace Content.Server.Storage.Components
|
||||
EnsureInitialCalculated();
|
||||
|
||||
if (_entityManager.TryGetComponent(entity, out ServerStorageComponent? storage) &&
|
||||
storage._storageCapacityMax >= _storageCapacityMax)
|
||||
storage.StorageCapacityMax >= StorageCapacityMax)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_entityManager.TryGetComponent(entity, out SharedItemComponent? store) &&
|
||||
store.Size > _storageCapacityMax - _storageUsed)
|
||||
store.Size > StorageCapacityMax - StorageUsed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -205,7 +205,7 @@ namespace Content.Server.Storage.Components
|
||||
if (_entityManager.TryGetComponent(message.Entity, out SharedItemComponent? storable))
|
||||
size = storable.Size;
|
||||
|
||||
_storageUsed += size;
|
||||
StorageUsed += size;
|
||||
_sizeCache[message.Entity] = size;
|
||||
|
||||
UpdateClientInventories();
|
||||
@@ -230,7 +230,7 @@ namespace Content.Server.Storage.Components
|
||||
return;
|
||||
}
|
||||
|
||||
_storageUsed -= size;
|
||||
StorageUsed -= size;
|
||||
|
||||
UpdateClientInventories();
|
||||
}
|
||||
@@ -350,7 +350,7 @@ namespace Content.Server.Storage.Components
|
||||
var stored = StoredEntities.Select(e => e).ToArray();
|
||||
|
||||
#pragma warning disable 618
|
||||
SendNetworkMessage(new StorageHeldItemsMessage(stored, _storageUsed, _storageCapacityMax), session.ConnectedClient);
|
||||
SendNetworkMessage(new StorageHeldItemsMessage(stored, StorageUsed, StorageCapacityMax), session.ConnectedClient);
|
||||
#pragma warning restore 618
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Rounding;
|
||||
using Content.Shared.Storage.Components;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Server.Storage.EntitySystems;
|
||||
|
||||
public sealed class StorageFillVisualizerSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<StorageFillVisualizerComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<StorageFillVisualizerComponent, EntInsertedIntoContainerMessage>(OnInserted);
|
||||
SubscribeLocalEvent<StorageFillVisualizerComponent, EntRemovedFromContainerMessage>(OnRemoved);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, StorageFillVisualizerComponent component, ComponentInit args)
|
||||
{
|
||||
UpdateAppearance(uid, component: component);
|
||||
}
|
||||
|
||||
private void OnInserted(EntityUid uid, StorageFillVisualizerComponent component, EntInsertedIntoContainerMessage args)
|
||||
{
|
||||
UpdateAppearance(uid, component: component);
|
||||
}
|
||||
|
||||
private void OnRemoved(EntityUid uid, StorageFillVisualizerComponent component, EntRemovedFromContainerMessage args)
|
||||
{
|
||||
UpdateAppearance(uid, component: component);
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EntityUid uid, ServerStorageComponent? storage = null, AppearanceComponent? appearance = null,
|
||||
StorageFillVisualizerComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref storage, ref appearance, ref component, false))
|
||||
return;
|
||||
|
||||
var level = ContentHelpers.RoundToEqualLevels(storage.StorageUsed, storage.StorageCapacityMax, component.MaxFillLevels);
|
||||
appearance.SetData(StorageFillVisuals.FillLevel, level);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user