]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
PopupOnTrigger (#39913)
authorāda <ss.adasts@gmail.com>
Wed, 10 Sep 2025 17:01:03 +0000 (12:01 -0500)
committerGitHub <noreply@github.com>
Wed, 10 Sep 2025 17:01:03 +0000 (20:01 +0300)
* 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>
Content.Shared/Popups/SharedPopupSystem.cs
Content.Shared/Trigger/Components/Effects/PopupOnTriggerComponent.cs [new file with mode: 0644]
Content.Shared/Trigger/Systems/PopupOnTriggerSystem.cs [new file with mode: 0644]

index b57ed6659e825f48e19c17d37c79dbbf7458eaaf..b2be7509f5b3cbbfa7059d7cb75b80a89137b242 100644 (file)
@@ -73,7 +73,7 @@ namespace Content.Shared.Popups
         /// <summary>
         ///    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
-        //     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>
         public abstract void PopupPredictedCoordinates(string? message, EntityCoordinates coordinates, EntityUid? recipient, PopupType type = PopupType.Small);
 
diff --git a/Content.Shared/Trigger/Components/Effects/PopupOnTriggerComponent.cs b/Content.Shared/Trigger/Components/Effects/PopupOnTriggerComponent.cs
new file mode 100644 (file)
index 0000000..0f85da8
--- /dev/null
@@ -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;
+}
diff --git a/Content.Shared/Trigger/Systems/PopupOnTriggerSystem.cs b/Content.Shared/Trigger/Systems/PopupOnTriggerSystem.cs
new file mode 100644 (file)
index 0000000..65ed216
--- /dev/null
@@ -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);
+    }
+}