From ea05c593aa90e6c6c962f6bd8d38efeafec4a226 Mon Sep 17 00:00:00 2001 From: clusterfack Date: Sun, 22 Apr 2018 06:11:38 -0500 Subject: [PATCH] Storage Component (toolboxes, backpacks, etc) (#57) * Fix Finish and update submodule Comments code, changes network messages FIXES THE USE INTERACTION SO YOU CAN ACTUALLY ACTIVATE THINGS NOW Need engine commits We'll figure out what to do about this shit later eh mates? Maybe have a script in the build process that automatically moves them over to godot/scenes Changes some prototypes and fixes stuff Fixes some more bugs, makes storage values show up properly Part 3 Part 2 Storage Take 1 * Doneso --- Content.Client/Content.Client.csproj | 1 + Content.Client/EntryPoint.cs | 4 + .../Components/Items/ClientHandsComponent.cs | 5 + .../Storage/ClientStorageComponent.cs | 200 +++++++++++++++++ Content.Client/UserInterface/HandsGui.cs | 82 ++++--- Content.Server/Content.Server.csproj | 4 +- Content.Server/EntryPoint.cs | 6 +- .../Components/Items/ServerHandsComponent.cs | 49 ++++- .../Items/{ => Storage}/ItemComponent.cs | 3 +- .../Items/Storage/ServerStorageComponent.cs | 184 ++++++++++++++++ .../Items/Storage/StoreableComponent.cs | 37 ++++ .../EntitySystems/InteractionSystem.cs | 53 +++-- .../Components/Items/IHandsComponent.cs | 7 +- Content.Shared/Content.Shared.csproj | 1 + .../Components/Items/SharedHandsComponent.cs | 13 ++ .../Storage/SharedStorageComponent.cs | 59 +++++ Content.Shared/GameObjects/ContentNetIDs.cs | 1 + Resources/Prototypes/Entities/Items.yml | 15 ++ .../{HitscanWeapons.yml => Weapons.yml} | 5 + Resources/Scenes/Storage/Storage.tscn | 207 ++++++++++++++++++ Resources/Scenes/Storage/StorageEntity.tscn | 160 ++++++++++++++ engine | 2 +- 22 files changed, 1044 insertions(+), 54 deletions(-) create mode 100644 Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs rename Content.Server/GameObjects/Components/Items/{ => Storage}/ItemComponent.cs (92%) create mode 100644 Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs create mode 100644 Content.Server/GameObjects/Components/Items/Storage/StoreableComponent.cs create mode 100644 Content.Shared/GameObjects/Components/Storage/SharedStorageComponent.cs rename Resources/Prototypes/Entities/{HitscanWeapons.yml => Weapons.yml} (87%) create mode 100644 Resources/Scenes/Storage/Storage.tscn create mode 100644 Resources/Scenes/Storage/StorageEntity.tscn diff --git a/Content.Client/Content.Client.csproj b/Content.Client/Content.Client.csproj index 3bb92d3a11..9027e22d6f 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 4fa5e40b21..4a9ecf740c 100644 --- a/Content.Client/EntryPoint.cs +++ b/Content.Client/EntryPoint.cs @@ -1,4 +1,5 @@ using Content.Client.GameObjects; +using Content.Client.GameObjects.Components.Storage; using Content.Client.Interfaces.GameObjects; using SS14.Shared.ContentPack; using SS14.Shared.Interfaces.GameObjects; @@ -36,8 +37,11 @@ namespace Content.Client factory.RegisterIgnore("Projectile"); factory.RegisterIgnore("MeleeWeapon"); + factory.RegisterIgnore("Storeable"); + factory.Register(); factory.RegisterReference(); + factory.Register(); factory.Register(); } diff --git a/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs b/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs index e6aca6bea2..1762ea3e5b 100644 --- a/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs +++ b/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs @@ -57,5 +57,10 @@ namespace Content.Client.GameObjects { SendNetworkMessage(new ClientChangedHandMsg(index)); } + + public void UseActiveHand() + { + SendNetworkMessage(new ActivateInhandMsg()); + } } } diff --git a/Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs b/Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs new file mode 100644 index 0000000000..ecebe16f24 --- /dev/null +++ b/Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs @@ -0,0 +1,200 @@ +using Content.Shared.GameObjects; +using Content.Shared.GameObjects.Components.Storage; +using SS14.Client.GameObjects; +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; + } + } + + /// + /// 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