Popup ECS Refactor (#4692)

This commit is contained in:
Vera Aguilera Puerto
2021-09-26 15:18:45 +02:00
committed by GitHub
parent 2051970cc1
commit 0767bd3777
142 changed files with 513 additions and 705 deletions

View File

@@ -0,0 +1,61 @@
using Content.Shared.Popups;
using Robust.Server.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.Popups
{
public static class PopupExtensions
{
/// <summary>
/// Pops up a message for every player around <see cref="source"/> to see,
/// except for <see cref="source"/> itself.
/// </summary>
/// <param name="source">The entity on which to popup the message.</param>
/// <param name="message">The message to show.</param>
/// <param name="playerManager">
/// The instance of player manager to use, will be resolved automatically
/// if null.
/// </param>
/// <param name="range">
/// The range in which to search for players, defaulting to one screen.
/// </param>
public static void PopupMessageOtherClients(this IEntity source, string message, IPlayerManager? playerManager = null, int range = 15)
{
playerManager ??= IoCManager.Resolve<IPlayerManager>();
var viewers = playerManager.GetPlayersInRange(source.Transform.Coordinates, range);
foreach (var viewer in viewers)
{
var viewerEntity = viewer.AttachedEntity;
if (viewerEntity == null || source == viewerEntity || viewer.AttachedEntity == null)
{
continue;
}
source.PopupMessage(viewer.AttachedEntity, message);
}
}
/// <summary>
/// Pops up a message at the given entity's location for everyone,
/// including itself, to see.
/// </summary>
/// <param name="source">The entity above which to show the message.</param>
/// <param name="message">The message to be seen.</param>
/// <param name="playerManager">
/// The instance of player manager to use, will be resolved automatically
/// if null.
/// </param>
/// <param name="range">
/// The range in which to search for players, defaulting to one screen.
/// </param>
public static void PopupMessageEveryone(this IEntity source, string message, IPlayerManager? playerManager = null, int range = 15)
{
source.PopupMessage(message);
source.PopupMessageOtherClients(message, playerManager, range);
}
}
}

View File

@@ -0,0 +1,28 @@
using Content.Server.Administration;
using Content.Shared.Administration;
using Content.Shared.Popups;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.Popups
{
[AdminCommand(AdminFlags.Debug)]
public class PopupMsgCommand : IConsoleCommand
{
public string Command => "srvpopupmsg";
public string Description => "";
public string Help => "";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var entityMgr = IoCManager.Resolve<IEntityManager>();
var source = EntityUid.Parse(args[0]);
var viewer = EntityUid.Parse(args[1]);
var msg = args[2];
entityMgr.GetEntity(source).PopupMessage(entityMgr.GetEntity(viewer), msg);
}
}
}

View File

@@ -0,0 +1,32 @@
using Content.Shared.Popups;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Player;
namespace Content.Server.Popups
{
public class PopupSystem : SharedPopupSystem
{
public override void PopupCursor(string message, Filter filter)
{
RaiseNetworkEvent(new PopupCursorEvent(message), filter);
}
public override void PopupCoordinates(string message, EntityCoordinates coordinates, Filter filter)
{
RaiseNetworkEvent(new PopupCoordinatesEvent(message, coordinates), filter);
}
public override void PopupEntity(string message, EntityUid uid, Filter filter)
{
RaiseNetworkEvent(new PopupEntityEvent(message, uid), filter);
}
public override Filter GetFilterFromEntity(IEntity entity)
{
return entity.TryGetComponent(out ActorComponent? actor)
? Filter.SinglePlayer(actor.PlayerSession) : Filter.Empty();
}
}
}