Convert StorageSystem comp messages into network events (#7351)
This commit is contained in:
@@ -14,13 +14,7 @@ using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Players;
|
||||
using static Robust.Client.UserInterface.Control;
|
||||
using static Robust.Client.UserInterface.Controls.BaseButton;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
@@ -86,35 +80,11 @@ namespace Content.Client.Storage
|
||||
_storedEntities = state.StoredEntities.ToList();
|
||||
}
|
||||
|
||||
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
|
||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null)
|
||||
{
|
||||
base.HandleNetworkMessage(message, channel, session);
|
||||
|
||||
switch (message)
|
||||
{
|
||||
//Updates what we are storing for the UI
|
||||
case StorageHeldItemsMessage msg:
|
||||
HandleStorageMessage(msg);
|
||||
break;
|
||||
//Opens the UI
|
||||
case OpenStorageUIMessage _:
|
||||
ToggleUI();
|
||||
break;
|
||||
case CloseStorageUIMessage _:
|
||||
CloseUI();
|
||||
break;
|
||||
case AnimateInsertingEntitiesMessage msg:
|
||||
HandleAnimatingInsertingEntities(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies received values from server about contents of storage container
|
||||
/// </summary>
|
||||
/// <param name="storageState"></param>
|
||||
private void HandleStorageMessage(StorageHeldItemsMessage storageState)
|
||||
public void HandleStorageMessage(StorageHeldItemsEvent storageState)
|
||||
{
|
||||
_storedEntities = storageState.StoredEntities.ToList();
|
||||
StorageSizeUsed = storageState.StorageSizeUsed;
|
||||
@@ -126,7 +96,7 @@ namespace Content.Client.Storage
|
||||
/// Animate the newly stored entities in <paramref name="msg"/> flying towards this storage's position
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
private void HandleAnimatingInsertingEntities(AnimateInsertingEntitiesMessage msg)
|
||||
public void HandleAnimatingInsertingEntities(AnimateInsertingEntitiesEvent msg)
|
||||
{
|
||||
for (var i = 0; msg.StoredEntities.Count > i; i++)
|
||||
{
|
||||
@@ -143,7 +113,7 @@ namespace Content.Client.Storage
|
||||
/// <summary>
|
||||
/// Opens the storage UI if closed. Closes it if opened.
|
||||
/// </summary>
|
||||
private void ToggleUI()
|
||||
public void ToggleUI()
|
||||
{
|
||||
var window = GetOrCreateWindow();
|
||||
|
||||
@@ -153,7 +123,7 @@ namespace Content.Client.Storage
|
||||
window.OpenCentered();
|
||||
}
|
||||
|
||||
private void CloseUI()
|
||||
public void CloseUI()
|
||||
{
|
||||
_window?.Close();
|
||||
}
|
||||
@@ -162,13 +132,11 @@ namespace Content.Client.Storage
|
||||
/// Function for clicking one of the stored entity buttons in the UI, tells server to remove that entity
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
private void Interact(ButtonEventArgs args, EntityUid entity)
|
||||
public void Interact(ButtonEventArgs args, EntityUid entity)
|
||||
{
|
||||
if (args.Event.Function == EngineKeyFunctions.UIClick)
|
||||
{
|
||||
#pragma warning disable 618
|
||||
SendNetworkMessage(new RemoveEntityMessage(entity));
|
||||
#pragma warning restore 618
|
||||
_entityManager.EntityNetManager?.SendSystemNetworkMessage(new RemoveEntityEvent(Owner, entity));
|
||||
args.Event.Handle();
|
||||
}
|
||||
else if (_entityManager.EntityExists(entity))
|
||||
@@ -191,7 +159,7 @@ namespace Content.Client.Storage
|
||||
/// <summary>
|
||||
/// Button created for each entity that represents that item in the storage UI, with a texture, and name and size label
|
||||
/// </summary>
|
||||
private void GenerateButton(EntityUid entity, EntityContainerButton button)
|
||||
public void GenerateButton(EntityUid entity, EntityContainerButton button)
|
||||
{
|
||||
if (!_entityManager.EntityExists(entity))
|
||||
return;
|
||||
@@ -269,9 +237,7 @@ namespace Content.Client.Storage
|
||||
|
||||
if (entities.HasComponent<HandsComponent>(controlledEntity))
|
||||
{
|
||||
#pragma warning disable 618
|
||||
StorageEntity.SendNetworkMessage(new InsertEntityMessage());
|
||||
#pragma warning restore 618
|
||||
entities.EntityNetManager?.SendSystemNetworkMessage(new InsertEntityEvent(storageEntity.Owner));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -306,9 +272,7 @@ namespace Content.Client.Storage
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
#pragma warning disable 618
|
||||
StorageEntity.SendNetworkMessage(new CloseStorageUIMessage());
|
||||
#pragma warning restore 618
|
||||
IoCManager.Resolve<IEntityManager>().EntityNetManager?.SendSystemNetworkMessage(new CloseStorageUIEvent(StorageEntity.Owner));
|
||||
base.Close();
|
||||
}
|
||||
|
||||
|
||||
49
Content.Client/Storage/StorageSystem.cs
Normal file
49
Content.Client/Storage/StorageSystem.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Content.Shared.Storage;
|
||||
|
||||
namespace Content.Client.Storage;
|
||||
|
||||
// TODO kill this is all horrid.
|
||||
public sealed class StorageSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeNetworkEvent<StorageHeldItemsEvent>(OnStorageHeldItems);
|
||||
SubscribeNetworkEvent<OpenStorageUIEvent>(OnOpenStorageUI);
|
||||
SubscribeNetworkEvent<CloseStorageUIEvent>(OnCloseStorageUI);
|
||||
SubscribeNetworkEvent<AnimateInsertingEntitiesEvent>(OnAnimateInsertingEntities);
|
||||
}
|
||||
|
||||
private void OnStorageHeldItems(StorageHeldItemsEvent ev)
|
||||
{
|
||||
if (TryComp<ClientStorageComponent>(ev.Storage, out var storage))
|
||||
{
|
||||
storage.HandleStorageMessage(ev);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnOpenStorageUI(OpenStorageUIEvent ev)
|
||||
{
|
||||
if (TryComp<ClientStorageComponent>(ev.Storage, out var storage))
|
||||
{
|
||||
storage.ToggleUI();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCloseStorageUI(CloseStorageUIEvent ev)
|
||||
{
|
||||
if (TryComp<ClientStorageComponent>(ev.Storage, out var storage))
|
||||
{
|
||||
storage.CloseUI();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnimateInsertingEntities(AnimateInsertingEntitiesEvent ev)
|
||||
{
|
||||
if (TryComp<ClientStorageComponent>(ev.Storage, out var storage))
|
||||
{
|
||||
storage.HandleAnimatingInsertingEntities(ev);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -302,9 +302,7 @@ namespace Content.Server.Storage.Components
|
||||
Logger.DebugS(LoggerName, $"Storage (UID {Owner}) \"used\" by player session (UID {userSession.AttachedEntity}).");
|
||||
|
||||
SubscribeSession(userSession);
|
||||
#pragma warning disable 618
|
||||
SendNetworkMessage(new OpenStorageUIMessage(), userSession.ConnectedClient);
|
||||
#pragma warning restore 618
|
||||
_entityManager.EntityNetManager?.SendSystemNetworkMessage(new OpenStorageUIEvent(Owner), userSession.ConnectedClient);
|
||||
UpdateClientInventory(userSession);
|
||||
}
|
||||
|
||||
@@ -349,9 +347,7 @@ namespace Content.Server.Storage.Components
|
||||
|
||||
var stored = StoredEntities.Select(e => e).ToArray();
|
||||
|
||||
#pragma warning disable 618
|
||||
SendNetworkMessage(new StorageHeldItemsMessage(stored, StorageUsed, StorageCapacityMax), session.ConnectedClient);
|
||||
#pragma warning restore 618
|
||||
_entityManager.EntityNetManager?.SendSystemNetworkMessage(new StorageHeldItemsEvent(Owner, StorageCapacityMax,StorageUsed, stored), session.ConnectedClient);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -385,9 +381,8 @@ namespace Content.Server.Storage.Components
|
||||
Logger.DebugS(LoggerName, $"Storage (UID {Owner}) unsubscribed player session (UID {session.AttachedEntity}).");
|
||||
|
||||
SubscribedSessions.Remove(session);
|
||||
#pragma warning disable 618
|
||||
SendNetworkMessage(new CloseStorageUIMessage(), session.ConnectedClient);
|
||||
#pragma warning restore 618
|
||||
_entityManager.EntityNetManager?.SendSystemNetworkMessage(new CloseStorageUIEvent(Owner),
|
||||
session.ConnectedClient);
|
||||
}
|
||||
|
||||
CloseNestedInterfaces(session);
|
||||
@@ -444,25 +439,13 @@ namespace Content.Server.Storage.Components
|
||||
EnsureInitialCalculated();
|
||||
}
|
||||
|
||||
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
|
||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null)
|
||||
{
|
||||
base.HandleNetworkMessage(message, channel, session);
|
||||
|
||||
if (session == null)
|
||||
{
|
||||
throw new ArgumentException(nameof(session));
|
||||
}
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case RemoveEntityMessage remove:
|
||||
public void HandleRemoveEntity(RemoveEntityEvent remove, ICommonSession session)
|
||||
{
|
||||
EnsureInitialCalculated();
|
||||
|
||||
if (session.AttachedEntity is not {Valid: true} player)
|
||||
{
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
var ownerTransform = _entityManager.GetComponent<TransformComponent>(Owner);
|
||||
@@ -471,46 +454,42 @@ namespace Content.Server.Storage.Components
|
||||
if (!playerTransform.Coordinates.InRange(_entityManager, ownerTransform.Coordinates, 2) ||
|
||||
Owner.IsInContainer() && !playerTransform.ContainsEntity(ownerTransform))
|
||||
{
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!remove.EntityUid.Valid || Storage?.Contains(remove.EntityUid) == false)
|
||||
{
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
_sysMan.GetEntitySystem<SharedHandsSystem>().TryPickupAnyHand(player, remove.EntityUid);
|
||||
break;
|
||||
}
|
||||
case InsertEntityMessage _:
|
||||
|
||||
public void HandleInsertEntity(ICommonSession session)
|
||||
{
|
||||
EnsureInitialCalculated();
|
||||
|
||||
if (session.AttachedEntity is not {Valid: true} player)
|
||||
{
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(player, Owner, popup: true))
|
||||
{
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerInsertHeldEntity(player);
|
||||
|
||||
break;
|
||||
}
|
||||
case CloseStorageUIMessage _:
|
||||
|
||||
public void HandleCloseUI(ICommonSession session)
|
||||
{
|
||||
if (session is not IPlayerSession playerSession)
|
||||
{
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
UnsubscribeSession(playerSession);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -604,14 +583,8 @@ namespace Content.Server.Storage.Components
|
||||
if (successfullyInserted.Count > 0)
|
||||
{
|
||||
PlaySoundCollection();
|
||||
#pragma warning disable 618
|
||||
SendNetworkMessage(
|
||||
#pragma warning restore 618
|
||||
new AnimateInsertingEntitiesMessage(
|
||||
successfullyInserted,
|
||||
successfullyInsertedPositions
|
||||
)
|
||||
);
|
||||
_entityManager.EntityNetManager?.SendSystemNetworkMessage(
|
||||
new AnimateInsertingEntitiesEvent(Owner, successfullyInserted, successfullyInsertedPositions));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -632,12 +605,9 @@ namespace Content.Server.Storage.Components
|
||||
_entityManager.GetComponent<TransformComponent>(target).MapPosition);
|
||||
if (PlayerInsertEntityInWorld(eventArgs.User, target))
|
||||
{
|
||||
#pragma warning disable 618
|
||||
SendNetworkMessage(new AnimateInsertingEntitiesMessage(
|
||||
#pragma warning restore 618
|
||||
_entityManager.EntityNetManager?.SendSystemNetworkMessage(new AnimateInsertingEntitiesEvent(Owner,
|
||||
new List<EntityUid> { target },
|
||||
new List<EntityCoordinates> {position}
|
||||
));
|
||||
new List<EntityCoordinates> { position }));
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.Disposal.Unit.Components;
|
||||
using Content.Server.Disposal.Unit.EntitySystems;
|
||||
@@ -6,6 +5,7 @@ using Content.Server.Hands.Components;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Movement;
|
||||
using Content.Shared.Storage;
|
||||
using Content.Shared.Verbs;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -40,6 +40,34 @@ namespace Content.Server.Storage.EntitySystems
|
||||
SubscribeLocalEvent<ServerStorageComponent, GetVerbsEvent<UtilityVerb>>(AddTransferVerbs);
|
||||
|
||||
SubscribeLocalEvent<StorageFillComponent, MapInitEvent>(OnStorageFillMapInit);
|
||||
|
||||
SubscribeNetworkEvent<RemoveEntityEvent>(OnRemoveEntity);
|
||||
SubscribeNetworkEvent<InsertEntityEvent>(OnInsertEntity);
|
||||
SubscribeNetworkEvent<CloseStorageUIEvent>(OnCloseStorageUI);
|
||||
}
|
||||
|
||||
private void OnRemoveEntity(RemoveEntityEvent ev, EntitySessionEventArgs args)
|
||||
{
|
||||
if (TryComp<ServerStorageComponent>(ev.Storage, out var storage))
|
||||
{
|
||||
storage.HandleRemoveEntity(ev, args.SenderSession);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInsertEntity(InsertEntityEvent ev, EntitySessionEventArgs args)
|
||||
{
|
||||
if (TryComp<ServerStorageComponent>(ev.Storage, out var storage))
|
||||
{
|
||||
storage.HandleInsertEntity(args.SenderSession);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCloseStorageUI(CloseStorageUIEvent ev, EntitySessionEventArgs args)
|
||||
{
|
||||
if (TryComp<ServerStorageComponent>(ev.Storage, out var storage))
|
||||
{
|
||||
storage.HandleCloseUI(args.SenderSession);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRelayMovement(EntityUid uid, EntityStorageComponent component, RelayMovementEntityEvent args)
|
||||
|
||||
@@ -74,98 +74,96 @@ namespace Content.Shared.Storage
|
||||
/// Updates the client component about what entities this storage is holding
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
#pragma warning disable 618
|
||||
public sealed class StorageHeldItemsMessage : ComponentMessage
|
||||
#pragma warning restore 618
|
||||
public sealed class StorageHeldItemsEvent : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid Storage;
|
||||
public readonly int StorageSizeMax;
|
||||
public readonly int StorageSizeUsed;
|
||||
public readonly EntityUid[] StoredEntities;
|
||||
|
||||
public StorageHeldItemsMessage(EntityUid[] storedEntities, int storageUsed, int storageMaxSize)
|
||||
public StorageHeldItemsEvent(EntityUid storage, int storageSizeMax, int storageSizeUsed, EntityUid[] storedEntities)
|
||||
{
|
||||
Directed = true;
|
||||
StorageSizeMax = storageMaxSize;
|
||||
StorageSizeUsed = storageUsed;
|
||||
Storage = storage;
|
||||
StorageSizeMax = storageSizeMax;
|
||||
StorageSizeUsed = storageSizeUsed;
|
||||
StoredEntities = storedEntities;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Component message for adding an entity to the storage entity.
|
||||
/// Network event for adding an entity to the storage entity.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
#pragma warning disable 618
|
||||
public sealed class InsertEntityMessage : ComponentMessage
|
||||
#pragma warning restore 618
|
||||
public sealed class InsertEntityEvent : EntityEventArgs
|
||||
{
|
||||
public InsertEntityMessage()
|
||||
public readonly EntityUid Storage;
|
||||
|
||||
public InsertEntityEvent(EntityUid storage)
|
||||
{
|
||||
Directed = true;
|
||||
Storage = storage;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Component message for displaying an animation of entities flying into a storage entity
|
||||
/// Network event for displaying an animation of entities flying into a storage entity
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
#pragma warning disable 618
|
||||
public sealed class AnimateInsertingEntitiesMessage : ComponentMessage
|
||||
#pragma warning restore 618
|
||||
public sealed class AnimateInsertingEntitiesEvent : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid Storage;
|
||||
public readonly List<EntityUid> StoredEntities;
|
||||
public readonly List<EntityCoordinates> EntityPositions;
|
||||
public AnimateInsertingEntitiesMessage(List<EntityUid> storedEntities, List<EntityCoordinates> entityPositions)
|
||||
|
||||
public AnimateInsertingEntitiesEvent(EntityUid storage, List<EntityUid> storedEntities, List<EntityCoordinates> entityPositions)
|
||||
{
|
||||
Directed = true;
|
||||
Storage = storage;
|
||||
StoredEntities = storedEntities;
|
||||
EntityPositions = entityPositions;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Component message for removing a contained entity from the storage entity
|
||||
/// Network event for removing a contained entity from the storage entity
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
#pragma warning disable 618
|
||||
public sealed class RemoveEntityMessage : ComponentMessage
|
||||
#pragma warning restore 618
|
||||
public sealed class RemoveEntityEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid Storage;
|
||||
public EntityUid EntityUid;
|
||||
|
||||
public RemoveEntityMessage(EntityUid entityuid)
|
||||
public RemoveEntityEvent(EntityUid storage, EntityUid entityUid)
|
||||
{
|
||||
Directed = true;
|
||||
EntityUid = entityuid;
|
||||
Storage = storage;
|
||||
EntityUid = entityUid;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Component message for opening the storage UI
|
||||
/// Network event for opening the storage UI
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
#pragma warning disable 618
|
||||
public sealed class OpenStorageUIMessage : ComponentMessage
|
||||
#pragma warning restore 618
|
||||
public sealed class OpenStorageUIEvent : EntityEventArgs
|
||||
{
|
||||
public OpenStorageUIMessage()
|
||||
public readonly EntityUid Storage;
|
||||
|
||||
public OpenStorageUIEvent(EntityUid storage)
|
||||
{
|
||||
Directed = true;
|
||||
Storage = storage;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Component message for closing the storage UI.
|
||||
/// Network event for closing the storage UI.
|
||||
/// E.g when the player moves too far away from the container.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
#pragma warning disable 618
|
||||
public sealed class CloseStorageUIMessage : ComponentMessage
|
||||
#pragma warning restore 618
|
||||
public sealed class CloseStorageUIEvent : EntityEventArgs
|
||||
{
|
||||
public CloseStorageUIMessage()
|
||||
public readonly EntityUid Storage;
|
||||
|
||||
public CloseStorageUIEvent(EntityUid storage)
|
||||
{
|
||||
Directed = true;
|
||||
Storage = storage;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user