]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix clientsided alerts being overwritten by server (#37033)
authorSlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>
Tue, 29 Apr 2025 13:32:18 +0000 (15:32 +0200)
committerGitHub <noreply@github.com>
Tue, 29 Apr 2025 13:32:18 +0000 (09:32 -0400)
Initial commit

Content.Client/Alerts/ClientAlertsSystem.cs
Content.Shared/Alert/AlertPrototype.cs
Resources/Prototypes/Alerts/alerts.yml

index b77bc9e4bcdc4bea2f77924bedc107e530423bbb..5b658fb07c2ae903caa3192052dca13ed4e9a4fe 100644 (file)
@@ -52,8 +52,24 @@ public sealed class ClientAlertsSystem : AlertsSystem
         if (args.Current is not AlertComponentState cast)
             return;
 
+        // Save all client-sided alerts to later put back in
+        var clientAlerts = new Dictionary<AlertKey, AlertState>();
+        foreach (var alert in alerts.Comp.Alerts)
+        {
+            if (alert.Key.AlertType != null && TryGet(alert.Key.AlertType.Value, out var alertProto))
+            {
+                if (alertProto.ClientHandled)
+                    clientAlerts[alert.Key] = alert.Value;
+            }
+        }
+
         alerts.Comp.Alerts = new(cast.Alerts);
 
+        foreach (var alert in clientAlerts)
+        {
+            alerts.Comp.Alerts[alert.Key] = alert.Value;
+        }
+
         UpdateHud(alerts);
     }
 
index a82cbd3daf6b59adcd713535d8f953ad0c2e3291..998eb4bd4d837a58166c4ab5d7b463569cb4f1a9 100644 (file)
@@ -75,6 +75,12 @@ public sealed partial class AlertPrototype : IPrototype
     /// </summary>
     public bool SupportsSeverity => MaxSeverity != -1;
 
+    /// <summary>
+    /// If true, this alert is being handled by the client and will not be overwritten when handling server -> client states.
+    /// </summary>
+    [DataField]
+    public bool ClientHandled = false;
+
     /// <summary>
     /// Event raised on the user when they click on this alert.
     /// Can be null.
index 859f223730bad56b618561ea02f5e26fcdcf3f30..471ece63ee6e0373aae5b9aeb9e23b7f8d96e006 100644 (file)
     state: walking
   name: alerts-walking-name
   description: alerts-walking-desc
+  clientHandled: true
 
 - type: alert
   id: Stun