using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Storage; using SS14.Client.GameObjects; using SS14.Client.Interfaces.GameObjects.Components; using SS14.Client.UserInterface; using SS14.Client.UserInterface.Controls; using SS14.Client.UserInterface.CustomControls; using SS14.Shared.GameObjects; using SS14.Shared.Interfaces.GameObjects; using SS14.Shared.Interfaces.Network; using SS14.Shared.IoC; using SS14.Shared.Log; using SS14.Shared.Maths; using SS14.Shared.Utility; using System; using System.Collections.Generic; 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() { StorageEntity = this }; } public override void OnRemove() { Window.Dispose(); base.OnRemove(); } 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: // todo: close window/grey it out 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(); } /// /// 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"); 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