From 0738829510d823bf0f22eaf197f6f5cc3744bbc3 Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Tue, 5 Mar 2024 20:59:05 -0500 Subject: [PATCH] Add SharedPopupSystem.PopupPredicted (#25811) * Added SharedPopupSystem.PopupPredicted * Documentation improvement --- Content.Client/Popups/PopupSystem.cs | 8 +++++++- Content.Server/Popups/PopupSystem.cs | 24 +++++++++++++++++++--- Content.Shared/Popups/SharedPopupSystem.cs | 9 +++++++- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Content.Client/Popups/PopupSystem.cs b/Content.Client/Popups/PopupSystem.cs index 2c923ae3a7..cf96c41241 100644 --- a/Content.Client/Popups/PopupSystem.cs +++ b/Content.Client/Popups/PopupSystem.cs @@ -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 diff --git a/Content.Server/Popups/PopupSystem.cs b/Content.Server/Popups/PopupSystem.cs index 4d9a9f3bf5..c5eb3819b5 100644 --- a/Content.Server/Popups/PopupSystem.cs +++ b/Content.Server/Popups/PopupSystem.cs @@ -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))); + } + } } } diff --git a/Content.Shared/Popups/SharedPopupSystem.cs b/Content.Shared/Popups/SharedPopupSystem.cs index f8e07e5df5..aeb85de2f5 100644 --- a/Content.Shared/Popups/SharedPopupSystem.cs +++ b/Content.Shared/Popups/SharedPopupSystem.cs @@ -83,10 +83,17 @@ namespace Content.Shared.Popups public abstract void PopupEntity(string? message, EntityUid uid, Filter filter, bool recordReplay, PopupType type = PopupType.Small); /// - /// Variant of that only runs on the client, outside of prediction. + /// Variant of that only runs on the client, outside of prediction. /// Useful for shared code that is always ran by both sides to avoid duplicate popups. /// public abstract void PopupClient(string? message, EntityUid uid, EntityUid recipient, PopupType type = PopupType.Small); + + /// + /// Variant of 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. + /// + public abstract void PopupPredicted(string? message, EntityUid uid, EntityUid? recipient, PopupType type = PopupType.Small); } /// -- 2.51.2