diff --git a/Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs b/Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs
index d7e7069ae8..a1491a0a7a 100644
--- a/Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs
+++ b/Content.Client/GameObjects/Components/Storage/ClientStorageComponent.cs
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using Content.Shared.GameObjects.Components.Storage;
+using Content.Client.Interfaces.GameObjects;
using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
+using Robust.Client.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Network;
@@ -99,6 +101,7 @@ namespace Content.Client.GameObjects.Components.Storage
private Control VSplitContainer;
private VBoxContainer EntityList;
private Label Information;
+ private Button AddItemButton;
public ClientStorageComponent StorageEntity;
protected override Vector2? CustomSize => (180, 320);
@@ -129,6 +132,16 @@ namespace Content.Client.GameObjects.Components.Storage
};
listScrollContainer.AddChild(EntityList);
VSplitContainer.AddChild(listScrollContainer);
+
+ AddItemButton = new Button
+ {
+ Text = "Add Item",
+ ToggleMode = false,
+ SizeFlagsHorizontal = SizeFlags.FillExpand
+ };
+ AddItemButton.OnPressed += OnAddItemButtonPressed;
+ VSplitContainer.AddChild(AddItemButton);
+
Contents.AddChild(VSplitContainer);
}
@@ -191,6 +204,19 @@ namespace Content.Client.GameObjects.Components.Storage
args.Button.Pressed = false;
StorageEntity.Interact(control.EntityuID);
}
+
+ ///
+ /// Function assigned to button that adds items to the storage entity.
+ ///
+ private void OnAddItemButtonPressed(BaseButton.ButtonEventArgs args)
+ {
+ var controlledEntity = IoCManager.Resolve().LocalPlayer.ControlledEntity;
+
+ if (controlledEntity.TryGetComponent(out IHandsComponent hands))
+ {
+ StorageEntity.SendNetworkMessage(new InsertEntityMessage());
+ }
+ }
}
///
diff --git a/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs
index 77fe298f07..0b0f0c35fe 100644
--- a/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs
+++ b/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs
@@ -3,6 +3,7 @@ using System.Linq;
using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.EntitySystems;
+using Content.Server.Interfaces.GameObjects;
using Content.Shared.GameObjects.Components.Storage;
using Content.Shared.Interfaces;
using Robust.Server.GameObjects;
@@ -146,25 +147,8 @@ namespace Content.Server.GameObjects
return false;
}
- if (!eventArgs.User.TryGetComponent(out HandsComponent hands))
- {
- return false;
- }
-
- //Check that we can drop the item from our hands first otherwise we obviously cant put it inside
- if (CanInsert(hands.GetActiveHand.Owner) && hands.Drop(hands.ActiveIndex))
- {
- if (Insert(eventArgs.AttackWith))
- {
- return true;
- }
- }
- else
- {
- Owner.PopupMessage(eventArgs.User, "Can't insert.");
- }
- return false;
- }
+ return PlayerInsertEntity(eventArgs.User);
+ }
///
/// Sends a message to open the storage UI
@@ -309,6 +293,22 @@ namespace Content.Server.GameObjects
}
break;
}
+ case InsertEntityMessage _:
+ {
+ _ensureInitialCalculated();
+ var playerEntity = _playerManager.GetSessionByChannel(netChannel).AttachedEntity;
+ var storageTransform = Owner.GetComponent();
+ var playerTransform = playerEntity.GetComponent();
+ // TODO: Replace by proper entity range check once it is implemented.
+ if (playerTransform.GridPosition.InRange(_mapManager,
+ storageTransform.GridPosition,
+ InteractionSystem.InteractionRange))
+ {
+ PlayerInsertEntity(playerEntity);
+ }
+
+ break;
+ }
case CloseStorageUIMessage _:
{
var session = _playerManager.GetSessionByChannel(netChannel);
@@ -356,5 +356,31 @@ namespace Content.Server.GameObjects
Remove(entity);
}
}
+
+ ///
+ /// Inserts an entity into the storage component from the players active hand.
+ ///
+ private bool PlayerInsertEntity(IEntity player)
+ {
+ if (!player.TryGetComponent(out IHandsComponent hands) || hands.GetActiveHand == null)
+ return false;
+
+ var toInsert = hands.GetActiveHand;
+
+ if (hands.Drop(toInsert.Owner))
+ {
+ if (Insert(toInsert.Owner))
+ {
+ return true;
+ }
+ else
+ {
+ hands.PutInHand(toInsert);
+ }
+ }
+
+ Owner.PopupMessage(player, "Can't insert.");
+ return false;
+ }
}
}
diff --git a/Content.Shared/GameObjects/Components/Storage/SharedStorageComponent.cs b/Content.Shared/GameObjects/Components/Storage/SharedStorageComponent.cs
index ae68d21a2f..b992670ab2 100644
--- a/Content.Shared/GameObjects/Components/Storage/SharedStorageComponent.cs
+++ b/Content.Shared/GameObjects/Components/Storage/SharedStorageComponent.cs
@@ -30,6 +30,18 @@ namespace Content.Shared.GameObjects.Components.Storage
}
}
+ ///
+ /// Component message for adding an entity to the storage entity.
+ ///
+ [Serializable, NetSerializable]
+ public class InsertEntityMessage : ComponentMessage
+ {
+ public InsertEntityMessage()
+ {
+ Directed = true;
+ }
+ }
+
///
/// Component message for removing a contained entity from the storage entity
///