PopupOnTrigger (#39913)

* commit

* comment

* changes

* Update Content.Shared/Trigger/Systems/PopupOnTriggerSystem.cs

---------

Co-authored-by: iaada <iaada@users.noreply.github.com>
Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
āda
2025-09-10 12:01:03 -05:00
committed by GitHub
parent f7e3a2f881
commit b86094eb45
3 changed files with 114 additions and 1 deletions

View File

@@ -73,7 +73,7 @@ namespace Content.Shared.Popups
/// <summary> /// <summary>
/// Variant of <see cref="PopupCoordinates(string, EntityCoordinates, PopupType)"/> for use with prediction. The local client will /// Variant of <see cref="PopupCoordinates(string, EntityCoordinates, PopupType)"/> for use with prediction. The local client will
/// the popup to the recipient, and the server will show it to every other player in PVS range. If recipient is null, the local /// the popup to the recipient, and the server will show it to every other player in PVS range. If recipient is null, the local
// client will do nothing and the server will show the message to every player in PVS range. /// client will do nothing and the server will show the message to every player in PVS range.
/// </summary> /// </summary>
public abstract void PopupPredictedCoordinates(string? message, EntityCoordinates coordinates, EntityUid? recipient, PopupType type = PopupType.Small); public abstract void PopupPredictedCoordinates(string? message, EntityCoordinates coordinates, EntityUid? recipient, PopupType type = PopupType.Small);

View File

@@ -0,0 +1,51 @@
using Content.Shared.Popups;
using Robust.Shared.GameStates;
namespace Content.Shared.Trigger.Components.Effects;
/// <summary>
/// Displays a popup on the target when triggered.
/// Will display the popup on the user when <see cref="BaseXOnTriggerComponent.TargetUser"/> is true.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class PopupOnTriggerComponent : BaseXOnTriggerComponent
{
/// <summary>
/// The text this popup will display to the recipient.
/// </summary>
[DataField(required: true), AutoNetworkedField]
public LocId Text;
/// <summary>
/// The text this popup will display to everything but the recipient.
/// If left null this will reuse <see cref="Text"/>.
/// </summary>
[DataField, AutoNetworkedField]
public LocId? OtherText;
/// <summary>
/// The size and color of the popup.
/// </summary>
[DataField, AutoNetworkedField]
public PopupType PopupType = PopupType.Small;
/// <summary>
/// If true, the user is the recipient of the popup.
/// If false, this entity is the recipient.
/// </summary>
[DataField, AutoNetworkedField]
public bool UserIsRecipient = true;
/// <summary>
/// If true, this popup will only play for the recipient and ignore prediction.
/// </summary>
[DataField, AutoNetworkedField]
public bool Quiet;
/// <summary>
/// Whether to use predicted popups.
/// </summary>
/// <remarks>If false, this will spam any client that causes this trigger.</remarks>
[DataField, AutoNetworkedField]
public bool Predicted = true;
}

View File

@@ -0,0 +1,62 @@
using Content.Shared.Popups;
using Content.Shared.Trigger.Components.Effects;
namespace Content.Shared.Trigger.Systems;
/// <summary>
/// This handles <see cref="PopupOnTriggerComponent"/>
/// </summary>
public sealed class PopupOnTriggerSystem : EntitySystem
{
[Dependency] private readonly SharedPopupSystem _popup = default!;
/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PopupOnTriggerComponent, TriggerEvent>(OnTrigger);
}
private void OnTrigger(Entity<PopupOnTriggerComponent> ent, ref TriggerEvent args)
{
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
return;
var target = ent.Comp.TargetUser ? args.User : ent.Owner;
if (target == null)
return;
// Popups only play for one entity
if (ent.Comp.Quiet)
{
if (ent.Comp.Predicted)
_popup.PopupClient(Loc.GetString(ent.Comp.Text),
target.Value,
ent.Comp.UserIsRecipient ? args.User : ent.Owner,
ent.Comp.PopupType);
else if (args.User != null)
_popup.PopupEntity(Loc.GetString(ent.Comp.OtherText ?? ent.Comp.Text),
target.Value,
args.User.Value,
ent.Comp.PopupType);
return;
}
// Popups play for all entities
if (ent.Comp.Predicted)
_popup.PopupPredicted(Loc.GetString(ent.Comp.Text),
Loc.GetString(ent.Comp.OtherText ?? ent.Comp.Text),
target.Value,
ent.Comp.UserIsRecipient ? args.User : ent.Owner,
ent.Comp.PopupType);
else
_popup.PopupEntity(Loc.GetString(ent.Comp.OtherText ?? ent.Comp.Text),
target.Value,
ent.Comp.PopupType);
}
}