using Content.Shared.GameObjects.Components.Storage; using Robust.Client.Interfaces.GameObjects.Components; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Network; using Robust.Shared.IoC; using Robust.Shared.Utility; using System; using System.Collections.Generic; using Robust.Client.Interfaces.Graphics; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; namespace Content.Client.GameObjects.Components.Storage { /// /// Client version of item storage containers, contains a UI which displays stored entities and their size /// public class ClientStorageComponent : SharedStorageComponent { private Dictionary StoredEntities { get; set; } = new Dictionary(); private int StorageSizeUsed; private int StorageCapacityMax; private StorageWindow Window; public override void OnAdd() { base.OnAdd(); Window = new StorageWindow(IoCManager.Resolve()) { StorageEntity = this }; } public override void OnRemove() { Window.Dispose(); base.OnRemove(); } public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); } public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null) { switch (message) { //Updates what we are storing for the UI case StorageHeldItemsMessage msg: HandleStorageMessage(msg); break; //Opens the UI case OpenStorageUIMessage msg: OpenUI(); break; case CloseStorageUIMessage msg: CloseUI(); break; } } /// /// Copies received values from server about contents of storage container /// /// private void HandleStorageMessage(StorageHeldItemsMessage storagestate) { StoredEntities = new Dictionary(storagestate.StoredEntities); StorageSizeUsed = storagestate.StorageSizeUsed; StorageCapacityMax = storagestate.StorageSizeMax; Window.BuildEntityList(); } /// /// Opens the storage UI /// private void OpenUI() { Window.AddToScreen(); Window.Open(); } private void CloseUI() { Window.Close(); } /// /// Function for clicking one of the stored entity buttons in the UI, tells server to remove that entity /// /// private void Interact(EntityUid entityuid) { SendNetworkMessage(new RemoveEntityMessage(entityuid)); } /// /// GUI class for client storage component /// private class StorageWindow : SS14Window { private Control VSplitContainer; private VBoxContainer EntityList; private Label Information; public ClientStorageComponent StorageEntity; protected override ResourcePath ScenePath => new ResourcePath("/Scenes/Storage/Storage.tscn"); public StorageWindow(IDisplayManager displayMan) : base(displayMan) { } protected override void Initialize() { base.Initialize(); HideOnClose = true; // Get all the controls. VSplitContainer = Contents.GetChild("VSplitContainer"); EntityList = VSplitContainer.GetChild("ListScrollContainer").GetChild("EntityList"); Information = VSplitContainer.GetChild