Add extension method to popup a message for the source and everyone else around it (#2063)
* Add extension method to popup a message for the source and everyone around * Add IPlayerManager as a parameter
This commit is contained in:
@@ -13,12 +13,17 @@ namespace Content.Server.Utility
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">The entity on which to popup the message.</param>
|
/// <param name="source">The entity on which to popup the message.</param>
|
||||||
/// <param name="message">The message to show.</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">
|
/// <param name="range">
|
||||||
/// The range in which to search for players, defaulting to one screen.
|
/// The range in which to search for players, defaulting to one screen.
|
||||||
/// </param>
|
/// </param>
|
||||||
public static void PopupMessageOtherClients(this IEntity source, string message, int range = 15)
|
public static void PopupMessageOtherClients(this IEntity source, string message, IPlayerManager playerManager = null, int range = 15)
|
||||||
{
|
{
|
||||||
var playerManager = IoCManager.Resolve<IPlayerManager>();
|
playerManager ??= IoCManager.Resolve<IPlayerManager>();
|
||||||
|
|
||||||
var viewers = playerManager.GetPlayersInRange(source.Transform.Coordinates, range);
|
var viewers = playerManager.GetPlayersInRange(source.Transform.Coordinates, range);
|
||||||
|
|
||||||
foreach (var viewer in viewers)
|
foreach (var viewer in viewers)
|
||||||
@@ -33,5 +38,24 @@ namespace Content.Server.Utility
|
|||||||
source.PopupMessage(viewer.AttachedEntity, message);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user