[TEST MERGE] Slot-based Storage (#21212)

This commit is contained in:
Nemanja
2023-10-25 18:53:38 -04:00
committed by GitHub
parent 6b04aaf964
commit 41795720da
234 changed files with 1052 additions and 1008 deletions

View File

@@ -1,16 +1,15 @@
using System.Numerics;
using Robust.Client.GameObjects;
using Content.Client.Message;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Controls;
using Content.Shared.IdentityManagement;
using Content.Shared.Item;
using Content.Shared.Stacks;
using Content.Shared.Storage;
using Content.Shared.Storage.EntitySystems;
using Robust.Client.UserInterface;
using Robust.Shared.Containers;
using static Robust.Client.UserInterface.Controls.BoxContainer;
using Direction = Robust.Shared.Maths.Direction;
@@ -23,7 +22,9 @@ namespace Content.Client.Storage.UI
{
private readonly IEntityManager _entityManager;
private readonly Label _information;
private readonly SharedStorageSystem _storage;
private readonly RichTextLabel _information;
public readonly ContainerButton StorageContainerButton;
public readonly ListContainer EntityList;
private readonly StyleBoxFlat _hoveredBox = new() { BackgroundColor = Color.Black.WithAlpha(0.35f) };
@@ -32,6 +33,7 @@ namespace Content.Client.Storage.UI
public StorageWindow(IEntityManager entityManager)
{
_entityManager = entityManager;
_storage = _entityManager.System<SharedStorageSystem>();
SetSize = new Vector2(240, 320);
Title = Loc.GetString("comp-storage-window-title");
RectClipContent = true;
@@ -60,11 +62,14 @@ namespace Content.Client.Storage.UI
StorageContainerButton.AddChild(vBox);
_information = new Label
_information = new RichTextLabel
{
Text = Loc.GetString("comp-storage-window-volume", ("itemCount", 0), ("usedVolume", 0), ("maxVolume", 0)),
VerticalAlignment = VAlignment.Center
};
_information.SetMessage(Loc.GetString("comp-storage-window-volume",
("itemCount", 0),
("maxCount", 0),
("size", SharedItemSystem.GetItemSizeLocale(ItemSize.Normal))));
vBox.AddChild(_information);
@@ -101,15 +106,23 @@ namespace Content.Client.Storage.UI
EntityList.PopulateList(list);
// Sets information about entire storage container current capacity
if (component.StorageCapacityMax != 0)
SetStorageInformation((entity, component));
}
private void SetStorageInformation(Entity<StorageComponent> uid)
{
if (uid.Comp.MaxSlots != uid.Comp.Container.ContainedEntities.Count
&& _storage.GetCumulativeItemSizes(uid, uid.Comp) == _storage.GetMaxTotalWeight((uid, uid.Comp)))
{
_information.Text = Loc.GetString("comp-storage-window-volume", ("itemCount", storedCount),
("usedVolume", component.StorageUsed), ("maxVolume", component.StorageCapacityMax));
_information.SetMarkup(Loc.GetString("comp-storage-window-volume-full",
("size", SharedItemSystem.GetItemSizeLocale(_storage.GetMaxItemSize((uid, uid.Comp))))));
}
else
{
_information.Text = Loc.GetString("comp-storage-window-volume-unlimited", ("itemCount", storedCount));
_information.SetMarkup(Loc.GetString("comp-storage-window-volume",
("itemCount", uid.Comp.Container.ContainedEntities.Count),
("maxCount", uid.Comp.MaxSlots),
("size", SharedItemSystem.GetItemSizeLocale(_storage.GetMaxItemSize((uid, uid.Comp))))));
}
}
@@ -122,10 +135,9 @@ namespace Content.Client.Storage.UI
|| !_entityManager.EntityExists(entity))
return;
_entityManager.TryGetComponent(entity, out ItemComponent? item);
_entityManager.TryGetComponent(entity, out StackComponent? stack);
_entityManager.TryGetComponent(entity, out ItemComponent? item);
var count = stack?.Count ?? 1;
var size = item?.Size;
var spriteView = new SpriteView
{
@@ -147,12 +159,14 @@ namespace Content.Client.Storage.UI
HorizontalExpand = true,
ClipText = true,
Text = _entityManager.GetComponent<MetaDataComponent>(Identity.Entity(entity, _entityManager)).EntityName +
(count > 1 ? $" x {count}" : string.Empty),
(count > 1 ? $" x {count}" : string.Empty)
},
new Label
{
Align = Label.AlignMode.Right,
Text = size.ToString() ?? Loc.GetString("comp-storage-no-item-size"),
Text = item?.Size != null
? SharedItemSystem.GetItemSizeLocale(item.Size)
: Loc.GetString("comp-storage-no-item-size")
}
}
});