2021-11-22 23:11:48 -08:00
|
|
|
using Content.Shared.Popups;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.Player;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-11-22 23:11:48 -08:00
|
|
|
using Robust.Shared.Player;
|
2020-08-30 11:28:46 +02:00
|
|
|
|
2021-09-26 15:18:45 +02:00
|
|
|
namespace Content.Server.Popups
|
2020-08-30 11:28:46 +02:00
|
|
|
{
|
2021-09-26 15:18:45 +02:00
|
|
|
public static class PopupExtensions
|
2020-08-30 11:28:46 +02:00
|
|
|
{
|
|
|
|
|
/// <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>
|
2021-12-04 14:14:22 +01:00
|
|
|
public static void PopupMessageOtherClients(this EntityUid source, string message)
|
2020-08-30 11:28:46 +02:00
|
|
|
{
|
2021-11-22 23:11:48 -08:00
|
|
|
var viewers = Filter.Empty()
|
|
|
|
|
.AddPlayersByPvs(source)
|
|
|
|
|
.Recipients;
|
2020-08-30 11:28:46 +02:00
|
|
|
|
|
|
|
|
foreach (var viewer in viewers)
|
|
|
|
|
{
|
2021-12-06 00:52:58 +01:00
|
|
|
if (viewer.AttachedEntity is not {Valid: true} viewerEntity || source == viewerEntity || viewer.AttachedEntity == null)
|
2020-08-30 11:28:46 +02:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 00:52:58 +01:00
|
|
|
source.PopupMessage(viewerEntity, message);
|
2020-08-30 11:28:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-12 15:48:22 +02:00
|
|
|
|
|
|
|
|
/// <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>
|
2021-12-04 14:14:22 +01:00
|
|
|
public static void PopupMessageEveryone(this EntityUid source, string message, IPlayerManager? playerManager = null, int range = 15)
|
2020-09-12 15:48:22 +02:00
|
|
|
{
|
|
|
|
|
source.PopupMessage(message);
|
2021-11-22 23:11:48 -08:00
|
|
|
source.PopupMessageOtherClients(message);
|
2020-09-12 15:48:22 +02:00
|
|
|
}
|
2020-08-30 11:28:46 +02:00
|
|
|
}
|
|
|
|
|
}
|