From c33c227d95775fdc8768c5b9cb70a48ec296a870 Mon Sep 17 00:00:00 2001 From: clusterfack Date: Wed, 25 Apr 2018 06:42:35 -0500 Subject: [PATCH] Inventories (#61) * Bully the fuck out of inventory shit Inventory Stuff Inventories technically work It works technicaly speaking Yeah this part too Lets do it! Inventories completed Motherfucker * Remove unnecessary usings and fix one thing * Submodule update * Adds a bunch of various clothing prototypes for each current inventory slot --- Content.Client/Content.Client.csproj | 1 + Content.Client/EntryPoint.cs | 3 +- .../Inventory/ClientInventoryComponent.cs | 231 +++++++++++++++ .../Components/Items/ClientHandsComponent.cs | 5 +- Content.Server/Content.Server.csproj | 10 +- Content.Server/EntryPoint.cs | 4 +- .../Components/GUI/InventoryComponent.cs | 273 ++++++++++++++++++ .../{Items => GUI}/ServerHandsComponent.cs | 116 ++++---- .../Items/Clothing/ClothingComponent.cs | 29 ++ .../Components/Items/InventoryComponent.cs | 167 ----------- .../Components/Items/Storage/ItemComponent.cs | 26 +- .../Items/Storage/ServerStorageComponent.cs | 6 +- .../Items/Storage/StoreableComponent.cs | 1 + Content.Server/GameObjects/ContainerSlot.cs | 51 ++++ .../Components/Items/IHandsComponent.cs | 19 +- .../Components/Items/IInventoryComponent.cs | 101 ------- .../Components/Items/IItemComponent.cs | 22 -- Content.Shared/Content.Shared.csproj | 3 + .../Inventory/EquipmentSlotDefinitions.cs | 100 +++++++ .../Inventory/InventoryTemplates.cs | 25 ++ .../Inventory/SharedInventoryComponent.cs | 54 ++++ .../Storage/SharedStorageComponent.cs | 2 +- Content.Shared/GameObjects/ContentNetIDs.cs | 1 + Resources/Prototypes/Entities/Clothing.yml | 149 +++++++++- .../Scenes/Inventory/HumanInventory.tscn | 79 +++++ Resources/Scenes/Inventory/StorageSlot.tres | 31 ++ Resources/Scenes/Inventory/StorageSlot.tscn | 89 ++++++ Resources/textures/Clothing/armorvest.png | Bin 0 -> 251 bytes Resources/textures/Clothing/backpack.png | Bin 0 -> 241 bytes Resources/textures/Clothing/belt_utility.png | Bin 0 -> 256 bytes Resources/textures/Clothing/ears_headset.png | Bin 0 -> 191 bytes Resources/textures/Clothing/gasmask.png | Bin 0 -> 581 bytes Resources/textures/Clothing/glasses_meson.png | Bin 0 -> 199 bytes Resources/textures/Clothing/gloves_yellow.png | Bin 0 -> 205 bytes Resources/textures/Clothing/helmet_sec.png | Bin 0 -> 234 bytes .../textures/Clothing/idcard_standard.png | Bin 0 -> 650 bytes engine | 2 +- 37 files changed, 1205 insertions(+), 395 deletions(-) create mode 100644 Content.Client/GameObjects/Components/Inventory/ClientInventoryComponent.cs create mode 100644 Content.Server/GameObjects/Components/GUI/InventoryComponent.cs rename Content.Server/GameObjects/Components/{Items => GUI}/ServerHandsComponent.cs (68%) create mode 100644 Content.Server/GameObjects/Components/Items/Clothing/ClothingComponent.cs delete mode 100644 Content.Server/GameObjects/Components/Items/InventoryComponent.cs create mode 100644 Content.Server/GameObjects/ContainerSlot.cs delete mode 100644 Content.Server/Interfaces/GameObjects/Components/Items/IInventoryComponent.cs delete mode 100644 Content.Server/Interfaces/GameObjects/Components/Items/IItemComponent.cs create mode 100644 Content.Shared/GameObjects/Components/Inventory/EquipmentSlotDefinitions.cs create mode 100644 Content.Shared/GameObjects/Components/Inventory/InventoryTemplates.cs create mode 100644 Content.Shared/GameObjects/Components/Inventory/SharedInventoryComponent.cs create mode 100644 Resources/Scenes/Inventory/HumanInventory.tscn create mode 100644 Resources/Scenes/Inventory/StorageSlot.tres create mode 100644 Resources/Scenes/Inventory/StorageSlot.tscn create mode 100644 Resources/textures/Clothing/armorvest.png create mode 100644 Resources/textures/Clothing/backpack.png create mode 100644 Resources/textures/Clothing/belt_utility.png create mode 100644 Resources/textures/Clothing/ears_headset.png create mode 100644 Resources/textures/Clothing/gasmask.png create mode 100644 Resources/textures/Clothing/glasses_meson.png create mode 100644 Resources/textures/Clothing/gloves_yellow.png create mode 100644 Resources/textures/Clothing/helmet_sec.png create mode 100644 Resources/textures/Clothing/idcard_standard.png diff --git a/Content.Client/Content.Client.csproj b/Content.Client/Content.Client.csproj index 9027e22d6f..3db55c508d 100644 --- a/Content.Client/Content.Client.csproj +++ b/Content.Client/Content.Client.csproj @@ -69,6 +69,7 @@ + diff --git a/Content.Client/EntryPoint.cs b/Content.Client/EntryPoint.cs index 4a9ecf740c..c15a0700ee 100644 --- a/Content.Client/EntryPoint.cs +++ b/Content.Client/EntryPoint.cs @@ -13,7 +13,6 @@ namespace Content.Client { var factory = IoCManager.Resolve(); - factory.RegisterIgnore("Inventory"); factory.RegisterIgnore("Item"); factory.RegisterIgnore("Interactable"); factory.RegisterIgnore("Damageable"); @@ -38,12 +37,14 @@ namespace Content.Client factory.RegisterIgnore("MeleeWeapon"); factory.RegisterIgnore("Storeable"); + factory.RegisterIgnore("Clothing"); factory.Register(); factory.RegisterReference(); factory.Register(); factory.Register(); + factory.Register(); } } } diff --git a/Content.Client/GameObjects/Components/Inventory/ClientInventoryComponent.cs b/Content.Client/GameObjects/Components/Inventory/ClientInventoryComponent.cs new file mode 100644 index 0000000000..1ff7a11e75 --- /dev/null +++ b/Content.Client/GameObjects/Components/Inventory/ClientInventoryComponent.cs @@ -0,0 +1,231 @@ +using Content.Shared.GameObjects; +using SS14.Client.GameObjects; +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.GameObjects.Serialization; +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.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 + public event EventHandler OnCharacterMenuKey; + + public override void ExposeData(EntitySerializer serializer) + { + base.ExposeData(serializer); + + Window = new InventoryWindow(this); + serializer.DataField(ref TemplateName, "Template", "HumanInventory"); + Window.CreateInventory(TemplateName); + } + + public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null) + { + 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; + } + } + + /// + /// Register a hotkey to open the character menu with + /// + public override void Initialize() + { + base.Initialize(); + OnCharacterMenuKey += OpenMenu; + IoCManager.Resolve().SubscribeEvent(OnCharacterMenuKey, this); + } + + /// + /// Hotkey opens the character menu window + /// + /// + /// + private void OpenMenu(object sender, BoundKeyChangedMessage message) + { + if(message.Function == BoundKeyFunctions.OpenCharacterMenu && message.State == BoundKeyState.Down) + { + Window.AddToScreen(); + Window.Open(); + } + } + + 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