Make popups nullable (#24802)

This standardises it with audio and whatever. Me when I sprinkle nullchecks everywhere.

Was 50/50 on making new non-nullable methods but figured it would bloat too hard and you can't access strings by .Value anyway.
This commit is contained in:
metalgearsloth
2024-02-02 15:25:58 +11:00
committed by GitHub
parent dfa86fbff8
commit 606c5a8c8b
3 changed files with 81 additions and 46 deletions

View File

@@ -55,8 +55,11 @@ namespace Content.Client.Popups
.RemoveOverlay<PopupOverlay>(); .RemoveOverlay<PopupOverlay>();
} }
private void PopupMessage(string message, PopupType type, EntityCoordinates coordinates, EntityUid? entity, bool recordReplay) private void PopupMessage(string? message, PopupType type, EntityCoordinates coordinates, EntityUid? entity, bool recordReplay)
{ {
if (message == null)
return;
if (recordReplay && _replayRecording.IsRecording) if (recordReplay && _replayRecording.IsRecording)
{ {
if (entity != null) if (entity != null)
@@ -75,25 +78,28 @@ namespace Content.Client.Popups
} }
#region Abstract Method Implementations #region Abstract Method Implementations
public override void PopupCoordinates(string message, EntityCoordinates coordinates, PopupType type = PopupType.Small) public override void PopupCoordinates(string? message, EntityCoordinates coordinates, PopupType type = PopupType.Small)
{ {
PopupMessage(message, type, coordinates, null, true); PopupMessage(message, type, coordinates, null, true);
} }
public override void PopupCoordinates(string message, EntityCoordinates coordinates, ICommonSession recipient, PopupType type = PopupType.Small) public override void PopupCoordinates(string? message, EntityCoordinates coordinates, ICommonSession recipient, PopupType type = PopupType.Small)
{ {
if (_playerManager.LocalPlayer?.Session == recipient) if (_playerManager.LocalSession == recipient)
PopupMessage(message, type, coordinates, null, true); PopupMessage(message, type, coordinates, null, true);
} }
public override void PopupCoordinates(string message, EntityCoordinates coordinates, EntityUid recipient, PopupType type = PopupType.Small) public override void PopupCoordinates(string? message, EntityCoordinates coordinates, EntityUid recipient, PopupType type = PopupType.Small)
{ {
if (_playerManager.LocalPlayer?.ControlledEntity == recipient) if (_playerManager.LocalEntity == recipient)
PopupMessage(message, type, coordinates, null, true); PopupMessage(message, type, coordinates, null, true);
} }
private void PopupCursorInternal(string message, PopupType type, bool recordReplay) private void PopupCursorInternal(string? message, PopupType type, bool recordReplay)
{ {
if (message == null)
return;
if (recordReplay && _replayRecording.IsRecording) if (recordReplay && _replayRecording.IsRecording)
_replayRecording.RecordClientMessage(new PopupCursorEvent(message, type)); _replayRecording.RecordClientMessage(new PopupCursorEvent(message, type));
@@ -106,53 +112,53 @@ namespace Content.Client.Popups
_aliveCursorLabels.Add(label); _aliveCursorLabels.Add(label);
} }
public override void PopupCursor(string message, PopupType type = PopupType.Small) public override void PopupCursor(string? message, PopupType type = PopupType.Small)
=> PopupCursorInternal(message, type, true); => PopupCursorInternal(message, type, true);
public override void PopupCursor(string message, ICommonSession recipient, PopupType type = PopupType.Small) public override void PopupCursor(string? message, ICommonSession recipient, PopupType type = PopupType.Small)
{ {
if (_playerManager.LocalPlayer?.Session == recipient) if (_playerManager.LocalSession == recipient)
PopupCursor(message, type); PopupCursor(message, type);
} }
public override void PopupCursor(string message, EntityUid recipient, PopupType type = PopupType.Small) public override void PopupCursor(string? message, EntityUid recipient, PopupType type = PopupType.Small)
{ {
if (_playerManager.LocalPlayer?.ControlledEntity == recipient) if (_playerManager.LocalEntity == recipient)
PopupCursor(message, type); PopupCursor(message, type);
} }
public override void PopupCoordinates(string message, EntityCoordinates coordinates, Filter filter, bool replayRecord, PopupType type = PopupType.Small) public override void PopupCoordinates(string? message, EntityCoordinates coordinates, Filter filter, bool replayRecord, PopupType type = PopupType.Small)
{ {
PopupCoordinates(message, coordinates, type); PopupCoordinates(message, coordinates, type);
} }
public override void PopupEntity(string message, EntityUid uid, EntityUid recipient, PopupType type = PopupType.Small) public override void PopupEntity(string? message, EntityUid uid, EntityUid recipient, PopupType type = PopupType.Small)
{ {
if (_playerManager.LocalPlayer?.ControlledEntity == recipient) if (_playerManager.LocalEntity == recipient)
PopupEntity(message, uid, type); PopupEntity(message, uid, type);
} }
public override void PopupEntity(string message, EntityUid uid, ICommonSession recipient, PopupType type = PopupType.Small) public override void PopupEntity(string? message, EntityUid uid, ICommonSession recipient, PopupType type = PopupType.Small)
{ {
if (_playerManager.LocalPlayer?.Session == recipient) if (_playerManager.LocalSession == recipient)
PopupEntity(message, uid, type); PopupEntity(message, uid, type);
} }
public override void PopupEntity(string message, EntityUid uid, Filter filter, bool recordReplay, PopupType type=PopupType.Small) public override void PopupEntity(string? message, EntityUid uid, Filter filter, bool recordReplay, PopupType type=PopupType.Small)
{ {
if (!filter.Recipients.Contains(_playerManager.LocalPlayer?.Session)) if (!filter.Recipients.Contains(_playerManager.LocalSession))
return; return;
PopupEntity(message, uid, type); PopupEntity(message, uid, type);
} }
public override void PopupClient(string message, EntityUid uid, EntityUid recipient, PopupType type = PopupType.Small) public override void PopupClient(string? message, EntityUid uid, EntityUid recipient, PopupType type = PopupType.Small)
{ {
if (_timing.IsFirstTimePredicted) if (_timing.IsFirstTimePredicted)
PopupEntity(message, uid, recipient, type); PopupEntity(message, uid, recipient, type);
} }
public override void PopupEntity(string message, EntityUid uid, PopupType type = PopupType.Small) public override void PopupEntity(string? message, EntityUid uid, PopupType type = PopupType.Small)
{ {
if (TryComp(uid, out TransformComponent? transform)) if (TryComp(uid, out TransformComponent? transform))
PopupMessage(message, type, transform.Coordinates, uid, true); PopupMessage(message, type, transform.Coordinates, uid, true);

View File

@@ -13,70 +13,99 @@ namespace Content.Server.Popups
[Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly TransformSystem _xform = default!; [Dependency] private readonly TransformSystem _xform = default!;
public override void PopupCursor(string message, PopupType type = PopupType.Small) public override void PopupCursor(string? message, PopupType type = PopupType.Small)
{ {
// No local user. // No local user.
} }
public override void PopupCursor(string message, ICommonSession recipient, PopupType type=PopupType.Small) public override void PopupCursor(string? message, ICommonSession recipient, PopupType type=PopupType.Small)
{ {
if (message == null)
return;
RaiseNetworkEvent(new PopupCursorEvent(message, type), recipient); RaiseNetworkEvent(new PopupCursorEvent(message, type), recipient);
} }
public override void PopupCursor(string message, EntityUid recipient, PopupType type = PopupType.Small) public override void PopupCursor(string? message, EntityUid recipient, PopupType type = PopupType.Small)
{ {
if (message == null)
return;
if (TryComp(recipient, out ActorComponent? actor)) if (TryComp(recipient, out ActorComponent? actor))
RaiseNetworkEvent(new PopupCursorEvent(message, type), actor.PlayerSession); RaiseNetworkEvent(new PopupCursorEvent(message, type), actor.PlayerSession);
} }
public override void PopupCoordinates(string message, EntityCoordinates coordinates, Filter filter, bool replayRecord, PopupType type = PopupType.Small) public override void PopupCoordinates(string? message, EntityCoordinates coordinates, Filter filter, bool replayRecord, PopupType type = PopupType.Small)
{ {
if (message == null)
return;
RaiseNetworkEvent(new PopupCoordinatesEvent(message, type, GetNetCoordinates(coordinates)), filter, replayRecord); RaiseNetworkEvent(new PopupCoordinatesEvent(message, type, GetNetCoordinates(coordinates)), filter, replayRecord);
} }
public override void PopupCoordinates(string message, EntityCoordinates coordinates, PopupType type = PopupType.Small) public override void PopupCoordinates(string? message, EntityCoordinates coordinates, PopupType type = PopupType.Small)
{ {
if (message == null)
return;
var mapPos = coordinates.ToMap(EntityManager, _xform); var mapPos = coordinates.ToMap(EntityManager, _xform);
var filter = Filter.Empty().AddPlayersByPvs(mapPos, entManager: EntityManager, playerMan: _player, cfgMan: _cfg); var filter = Filter.Empty().AddPlayersByPvs(mapPos, entManager: EntityManager, playerMan: _player, cfgMan: _cfg);
RaiseNetworkEvent(new PopupCoordinatesEvent(message, type, GetNetCoordinates(coordinates)), filter); RaiseNetworkEvent(new PopupCoordinatesEvent(message, type, GetNetCoordinates(coordinates)), filter);
} }
public override void PopupCoordinates(string message, EntityCoordinates coordinates, ICommonSession recipient, PopupType type = PopupType.Small) public override void PopupCoordinates(string? message, EntityCoordinates coordinates, ICommonSession recipient, PopupType type = PopupType.Small)
{ {
if (message == null)
return;
RaiseNetworkEvent(new PopupCoordinatesEvent(message, type, GetNetCoordinates(coordinates)), recipient); RaiseNetworkEvent(new PopupCoordinatesEvent(message, type, GetNetCoordinates(coordinates)), recipient);
} }
public override void PopupCoordinates(string message, EntityCoordinates coordinates, EntityUid recipient, PopupType type = PopupType.Small) public override void PopupCoordinates(string? message, EntityCoordinates coordinates, EntityUid recipient, PopupType type = PopupType.Small)
{ {
if (message == null)
return;
if (TryComp(recipient, out ActorComponent? actor)) if (TryComp(recipient, out ActorComponent? actor))
RaiseNetworkEvent(new PopupCoordinatesEvent(message, type, GetNetCoordinates(coordinates)), actor.PlayerSession); RaiseNetworkEvent(new PopupCoordinatesEvent(message, type, GetNetCoordinates(coordinates)), actor.PlayerSession);
} }
public override void PopupEntity(string message, EntityUid uid, PopupType type = PopupType.Small) public override void PopupEntity(string? message, EntityUid uid, PopupType type = PopupType.Small)
{ {
if (message == null)
return;
var filter = Filter.Empty().AddPlayersByPvs(uid, entityManager:EntityManager, playerMan: _player, cfgMan: _cfg); var filter = Filter.Empty().AddPlayersByPvs(uid, entityManager:EntityManager, playerMan: _player, cfgMan: _cfg);
RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), filter); RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), filter);
} }
public override void PopupEntity(string message, EntityUid uid, EntityUid recipient, PopupType type=PopupType.Small) public override void PopupEntity(string? message, EntityUid uid, EntityUid recipient, PopupType type=PopupType.Small)
{ {
if (message == null)
return;
if (TryComp(recipient, out ActorComponent? actor)) if (TryComp(recipient, out ActorComponent? actor))
RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), actor.PlayerSession); RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), actor.PlayerSession);
} }
public override void PopupClient(string message, EntityUid uid, EntityUid recipient, PopupType type = PopupType.Small) public override void PopupClient(string? message, EntityUid uid, EntityUid recipient, PopupType type = PopupType.Small)
{ {
// do nothing duh its for client only // do nothing duh its for client only
} }
public override void PopupEntity(string? message, EntityUid uid, ICommonSession recipient, PopupType type = PopupType.Small)
public override void PopupEntity(string message, EntityUid uid, ICommonSession recipient, PopupType type = PopupType.Small)
{ {
if (message == null)
return;
RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), recipient); RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), recipient);
} }
public override void PopupEntity(string message, EntityUid uid, Filter filter, bool recordReplay, PopupType type = PopupType.Small) public override void PopupEntity(string? message, EntityUid uid, Filter filter, bool recordReplay, PopupType type = PopupType.Small)
{ {
if (message == null)
return;
RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), filter, recordReplay); RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), filter, recordReplay);
} }
} }

View File

@@ -14,7 +14,7 @@ namespace Content.Shared.Popups
/// </summary> /// </summary>
/// <param name="message">The message to display.</param> /// <param name="message">The message to display.</param>
/// <param name="type">Used to customize how this popup should appear visually.</param> /// <param name="type">Used to customize how this popup should appear visually.</param>
public abstract void PopupCursor(string message, PopupType type = PopupType.Small); public abstract void PopupCursor(string? message, PopupType type = PopupType.Small);
/// <summary> /// <summary>
/// Shows a popup at a users' cursor. /// Shows a popup at a users' cursor.
@@ -22,7 +22,7 @@ namespace Content.Shared.Popups
/// <param name="message">The message to display.</param> /// <param name="message">The message to display.</param>
/// <param name="recipient">Client that will see this popup.</param> /// <param name="recipient">Client that will see this popup.</param>
/// <param name="type">Used to customize how this popup should appear visually.</param> /// <param name="type">Used to customize how this popup should appear visually.</param>
public abstract void PopupCursor(string message, ICommonSession recipient, PopupType type = PopupType.Small); public abstract void PopupCursor(string? message, ICommonSession recipient, PopupType type = PopupType.Small);
/// <summary> /// <summary>
/// Shows a popup at a users' cursor. /// Shows a popup at a users' cursor.
@@ -30,7 +30,7 @@ namespace Content.Shared.Popups
/// <param name="message">The message to display.</param> /// <param name="message">The message to display.</param>
/// <param name="recipient">Client that will see this popup.</param> /// <param name="recipient">Client that will see this popup.</param>
/// <param name="type">Used to customize how this popup should appear visually.</param> /// <param name="type">Used to customize how this popup should appear visually.</param>
public abstract void PopupCursor(string message, EntityUid recipient, PopupType type = PopupType.Small); public abstract void PopupCursor(string? message, EntityUid recipient, PopupType type = PopupType.Small);
/// <summary> /// <summary>
/// Shows a popup at a world location to every entity in PVS range. /// Shows a popup at a world location to every entity in PVS range.
@@ -38,7 +38,7 @@ namespace Content.Shared.Popups
/// <param name="message">The message to display.</param> /// <param name="message">The message to display.</param>
/// <param name="coordinates">The coordinates where to display the message.</param> /// <param name="coordinates">The coordinates where to display the message.</param>
/// <param name="type">Used to customize how this popup should appear visually.</param> /// <param name="type">Used to customize how this popup should appear visually.</param>
public abstract void PopupCoordinates(string message, EntityCoordinates coordinates, PopupType type = PopupType.Small); public abstract void PopupCoordinates(string? message, EntityCoordinates coordinates, PopupType type = PopupType.Small);
/// <summary> /// <summary>
/// Filtered variant of <see cref="PopupCoordinates(string, EntityCoordinates, PopupType)"/>, which should only be used /// Filtered variant of <see cref="PopupCoordinates(string, EntityCoordinates, PopupType)"/>, which should only be used
@@ -46,17 +46,17 @@ namespace Content.Shared.Popups
/// </summary> /// </summary>
/// <param name="filter">Filter for the players that will see the popup.</param> /// <param name="filter">Filter for the players that will see the popup.</param>
/// <param name="recordReplay">If true, this pop-up will be considered as a globally visible pop-up that gets shown during replays.</param> /// <param name="recordReplay">If true, this pop-up will be considered as a globally visible pop-up that gets shown during replays.</param>
public abstract void PopupCoordinates(string message, EntityCoordinates coordinates, Filter filter, bool recordReplay, PopupType type = PopupType.Small); public abstract void PopupCoordinates(string? message, EntityCoordinates coordinates, Filter filter, bool recordReplay, PopupType type = PopupType.Small);
/// <summary> /// <summary>
/// Variant of <see cref="PopupCoordinates(string, EntityCoordinates, PopupType)"/> that sends a pop-up to the player attached to some entity. /// Variant of <see cref="PopupCoordinates(string, EntityCoordinates, PopupType)"/> that sends a pop-up to the player attached to some entity.
/// </summary> /// </summary>
public abstract void PopupCoordinates(string message, EntityCoordinates coordinates, EntityUid recipient, PopupType type = PopupType.Small); public abstract void PopupCoordinates(string? message, EntityCoordinates coordinates, EntityUid recipient, PopupType type = PopupType.Small);
/// <summary> /// <summary>
/// Variant of <see cref="PopupCoordinates(string, EntityCoordinates, PopupType)"/> that sends a pop-up to a specific player. /// Variant of <see cref="PopupCoordinates(string, EntityCoordinates, PopupType)"/> that sends a pop-up to a specific player.
/// </summary> /// </summary>
public abstract void PopupCoordinates(string message, EntityCoordinates coordinates, ICommonSession recipient, PopupType type = PopupType.Small); public abstract void PopupCoordinates(string? message, EntityCoordinates coordinates, ICommonSession recipient, PopupType type = PopupType.Small);
/// <summary> /// <summary>
/// Shows a popup above an entity for every player in pvs range. /// Shows a popup above an entity for every player in pvs range.
@@ -64,29 +64,29 @@ namespace Content.Shared.Popups
/// <param name="message">The message to display.</param> /// <param name="message">The message to display.</param>
/// <param name="uid">The UID of the entity.</param> /// <param name="uid">The UID of the entity.</param>
/// <param name="type">Used to customize how this popup should appear visually.</param> /// <param name="type">Used to customize how this popup should appear visually.</param>
public abstract void PopupEntity(string message, EntityUid uid, PopupType type=PopupType.Small); public abstract void PopupEntity(string? message, EntityUid uid, PopupType type=PopupType.Small);
/// <summary> /// <summary>
/// Variant of <see cref="PopupEntity(string, EntityUid, PopupType)"/> that shows the popup only to some specific client. /// Variant of <see cref="PopupEntity(string, EntityUid, PopupType)"/> that shows the popup only to some specific client.
/// </summary> /// </summary>
public abstract void PopupEntity(string message, EntityUid uid, EntityUid recipient, PopupType type = PopupType.Small); public abstract void PopupEntity(string? message, EntityUid uid, EntityUid recipient, PopupType type = PopupType.Small);
/// <summary> /// <summary>
/// Variant of <see cref="PopupEntity(string, EntityUid, PopupType)"/> that shows the popup only to some specific client. /// Variant of <see cref="PopupEntity(string, EntityUid, PopupType)"/> that shows the popup only to some specific client.
/// </summary> /// </summary>
public abstract void PopupEntity(string message, EntityUid uid, ICommonSession recipient, PopupType type = PopupType.Small); public abstract void PopupEntity(string? message, EntityUid uid, ICommonSession recipient, PopupType type = PopupType.Small);
/// <summary> /// <summary>
/// Filtered variant of <see cref="PopupEntity(string, EntityUid, PopupType)"/>, which should only be used /// Filtered variant of <see cref="PopupEntity(string, EntityUid, PopupType)"/>, which should only be used
/// if the filtering has to be more specific than simply PVS range based. /// if the filtering has to be more specific than simply PVS range based.
/// </summary> /// </summary>
public abstract void PopupEntity(string message, EntityUid uid, Filter filter, bool recordReplay, PopupType type = PopupType.Small); public abstract void PopupEntity(string? message, EntityUid uid, Filter filter, bool recordReplay, PopupType type = PopupType.Small);
/// <summary> /// <summary>
/// Variant of <see cref="PopupEnity(string, EntityUid, EntityUid, PopupType)"/> that only runs on the client, outside of prediction. /// Variant of <see cref="PopupEnity(string, EntityUid, EntityUid, PopupType)"/> that only runs on the client, outside of prediction.
/// Useful for shared code that is always ran by both sides to avoid duplicate popups. /// Useful for shared code that is always ran by both sides to avoid duplicate popups.
/// </summary> /// </summary>
public abstract void PopupClient(string message, EntityUid uid, EntityUid recipient, PopupType type = PopupType.Small); public abstract void PopupClient(string? message, EntityUid uid, EntityUid recipient, PopupType type = PopupType.Small);
} }
/// <summary> /// <summary>