]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add SharedPopupSystem.PopupPredicted (#25811)
authorTayrtahn <tayrtahn@gmail.com>
Wed, 6 Mar 2024 01:59:05 +0000 (20:59 -0500)
committerGitHub <noreply@github.com>
Wed, 6 Mar 2024 01:59:05 +0000 (02:59 +0100)
* Added SharedPopupSystem.PopupPredicted

* Documentation improvement

Content.Client/Popups/PopupSystem.cs
Content.Server/Popups/PopupSystem.cs
Content.Shared/Popups/SharedPopupSystem.cs

index 2c923ae3a71cc0dc513a8d06de785e3a7563e266..cf96c41241a1215ecc744c1df15ca4214e563ca7 100644 (file)
@@ -150,7 +150,7 @@ namespace Content.Client.Popups
                 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.LocalSession))
                 return;
@@ -170,6 +170,12 @@ namespace Content.Client.Popups
                 PopupMessage(message, type, transform.Coordinates, uid, true);
         }
 
+        public override void PopupPredicted(string? message, EntityUid uid, EntityUid? recipient, PopupType type = PopupType.Small)
+        {
+            if (recipient != null && _timing.IsFirstTimePredicted)
+                PopupEntity(message, uid, recipient.Value, type);
+        }
+
         #endregion
 
         #region Network Event Handlers
index 4d9a9f3bf5b1fbb5c906ca4f52a6d4fbae4e4b1d..c5eb3819b54a0ef06ccec021a81900d352f144f4 100644 (file)
@@ -18,7 +18,7 @@ namespace Content.Server.Popups
             // 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;
@@ -75,11 +75,11 @@ namespace Content.Server.Popups
             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);
         }
 
-        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;
@@ -108,5 +108,23 @@ namespace Content.Server.Popups
 
             RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), filter, recordReplay);
         }
+
+        public override void PopupPredicted(string? message, EntityUid uid, EntityUid? recipient, PopupType type = PopupType.Small)
+        {
+            if (message == null)
+                return;
+
+            if (recipient != null)
+            {
+                // Don't send to recipient, since they predicted it locally
+                var filter = Filter.PvsExcept(recipient.Value, entityManager: EntityManager);
+                RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), filter);
+            }
+            else
+            {
+                // With no recipient, send to everyone (in PVS range)
+                RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)));
+            }
+        }
     }
 }
index f8e07e5df5e147ef39ac248d135a29856089cd7c..aeb85de2f5971cca5d98daf84abdd4ca4b88da38 100644 (file)
@@ -83,10 +83,17 @@ namespace Content.Shared.Popups
         public abstract void PopupEntity(string? message, EntityUid uid, Filter filter, bool recordReplay, PopupType type = PopupType.Small);
 
         /// <summary>
-        /// Variant of <see cref="PopupEnity(string, EntityUid, EntityUid, PopupType)"/> that only runs on the client, outside of prediction.
+        /// Variant of <see cref="PopupEntity(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.
         /// </summary>
         public abstract void PopupClient(string? message, EntityUid uid, EntityUid recipient, PopupType type = PopupType.Small);
+
+        /// <summary>
+        /// Variant of <see cref="PopupEntity(string, EntityUid, EntityUid, PopupType)"/> for use with prediction. The local client will show
+        /// 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.
+        /// </summary>
+        public abstract void PopupPredicted(string? message, EntityUid uid, EntityUid? recipient, PopupType type = PopupType.Small);
     }
 
     /// <summary>