using Content.Shared.Popups;
using Robust.Server.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.Popups
{
public static class PopupExtensions
{
///
/// Pops up a message for every player around to see,
/// except for itself.
///
/// The entity on which to popup the message.
/// The message to show.
///
/// The instance of player manager to use, will be resolved automatically
/// if null.
///
///
/// The range in which to search for players, defaulting to one screen.
///
public static void PopupMessageOtherClients(this IEntity source, string message, IPlayerManager? playerManager = null, int range = 15)
{
playerManager ??= IoCManager.Resolve();
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);
}
}
///
/// Pops up a message at the given entity's location for everyone,
/// including itself, to see.
///
/// The entity above which to show the message.
/// The message to be seen.
///
/// The instance of player manager to use, will be resolved automatically
/// if null.
///
///
/// The range in which to search for players, defaulting to one screen.
///
public static void PopupMessageEveryone(this IEntity source, string message, IPlayerManager? playerManager = null, int range = 15)
{
source.PopupMessage(message);
source.PopupMessageOtherClients(message, playerManager, range);
}
}
}