using Content.Shared.GameObjects; using Content.Shared.Input; using SS14.Client.GameObjects; using SS14.Client.Interfaces.GameObjects.Components; using SS14.Client.Interfaces.Input; using SS14.Client.UserInterface; using SS14.Client.UserInterface.Controls; using SS14.Client.UserInterface.CustomControls; using SS14.Shared.ContentPack; using SS14.Shared.GameObjects; using SS14.Shared.Input; 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.Serialization; using SS14.Shared.Utility; using System; using System.Collections.Generic; using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines; using static Content.Shared.GameObjects.SharedInventoryComponent.ClientInventoryMessage; using static Content.Shared.GameObjects.SharedInventoryComponent.ServerInventoryMessage; namespace Content.Client.GameObjects { public class ClientInventoryComponent : SharedInventoryComponent { private InventoryWindow Window; private string TemplateName = "HumanInventory"; //stored for serialization purposes private InputCmdHandler _openMenuCmdHandler; public override void OnRemove() { base.OnRemove(); Window.Dispose(); } public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); Window = new InventoryWindow(this); _openMenuCmdHandler = InputCmdHandler.FromDelegate(session => { Window.AddToScreen(); Window.Open(); }); serializer.DataField(ref TemplateName, "Template", "HumanInventory"); Window.CreateInventory(TemplateName); } public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null) { var inputMgr = IoCManager.Resolve(); switch (message) { //Updates what we are storing in UI slots case ServerInventoryMessage msg: if (msg.Updatetype == ServerInventoryUpdate.Addition) { Window.AddToSlot(msg); } else if (msg.Updatetype == ServerInventoryUpdate.Removal) { Window.RemoveFromSlot(msg); } break; case PlayerAttachedMsg _: inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, _openMenuCmdHandler); break; case PlayerDetachedMsg _: inputMgr.SetInputCommand(ContentKeyFunctions.OpenCharacterMenu, null); break; } } public void SendUnequipMessage(Slots slot) { var unequipmessage = new ClientInventoryMessage(slot, ClientInventoryUpdate.Unequip); SendNetworkMessage(unequipmessage); } public void SendEquipMessage(Slots slot) { var equipmessage = new ClientInventoryMessage(slot, ClientInventoryUpdate.Equip); SendNetworkMessage(equipmessage); } /// /// Temporary window to hold the basis for inventory hud /// private class InventoryWindow : SS14Window { private int elements_x; private GridContainer GridContainer; private List IndexedSlots; private Dictionary InventorySlots = new Dictionary(); //ordered dictionary? private ClientInventoryComponent InventoryComponent; protected override ResourcePath ScenePath => new ResourcePath("/Scenes/Inventory/HumanInventory.tscn"); public InventoryWindow(ClientInventoryComponent inventory) { InventoryComponent = inventory; HideOnClose = true; } /// /// Creates a grid container filled with slot buttons loaded from an inventory template /// /// public void CreateInventory(string TemplateName) { Type type = AppDomain.CurrentDomain.GetAssemblyByName("Content.Shared").GetType("Content.Shared.GameObjects." + TemplateName); Inventory inventory = (Inventory)Activator.CreateInstance(type); elements_x = inventory.Columns; GridContainer = (GridContainer)Contents.GetChild("PanelContainer").GetChild("CenterContainer").GetChild("GridContainer"); GridContainer.Columns = elements_x; IndexedSlots = new List(inventory.SlotMasks); foreach (Slots slot in IndexedSlots) { InventoryButton newbutton = new InventoryButton(slot); if (slot == Slots.NONE) { //TODO: Re-enable when godot grid container maintains grid with invisible elements //newbutton.Visible = false; } else { //Store slot button and give it the default onpress behavior for empty elements newbutton.GetChild