From b97de9d603bd92c70afb383b4191af6fc32fdd3a Mon Sep 17 00:00:00 2001 From: Milon Date: Wed, 26 Mar 2025 12:45:29 +0100 Subject: [PATCH] add predicted popups with PVS filtering (#36092) add --- Content.Client/Popups/PopupSystem.cs | 6 ++++++ Content.Server/Popups/PopupSystem.cs | 14 ++++++++++++++ Content.Shared/Popups/SharedPopupSystem.cs | 13 +++++++++++++ 3 files changed, 33 insertions(+) diff --git a/Content.Client/Popups/PopupSystem.cs b/Content.Client/Popups/PopupSystem.cs index 38cad2d59c..b0a3d9b21e 100644 --- a/Content.Client/Popups/PopupSystem.cs +++ b/Content.Client/Popups/PopupSystem.cs @@ -237,6 +237,12 @@ namespace Content.Client.Popups PopupEntity(message, uid, recipient.Value, type); } + public override void PopupPredicted(string? message, EntityUid uid, EntityUid? recipient, Filter filter, bool recordReplay, PopupType type = PopupType.Small) + { + if (recipient != null && _timing.IsFirstTimePredicted) + PopupEntity(message, uid, recipient.Value, type); + } + public override void PopupPredicted(string? recipientMessage, string? othersMessage, EntityUid uid, EntityUid? recipient, PopupType type = PopupType.Small) { if (recipient != null && _timing.IsFirstTimePredicted) diff --git a/Content.Server/Popups/PopupSystem.cs b/Content.Server/Popups/PopupSystem.cs index 22e4ae483a..9338d81b92 100644 --- a/Content.Server/Popups/PopupSystem.cs +++ b/Content.Server/Popups/PopupSystem.cs @@ -149,6 +149,20 @@ namespace Content.Server.Popups } } + public override void PopupPredicted(string? message, EntityUid uid, EntityUid? recipient, Filter filter, bool recordReplay, PopupType type = PopupType.Small) + { + if (message == null) + return; + + if (recipient != null) + { + // Don't send to recipient, since they predicted it locally + filter = filter.RemovePlayerByAttachedEntity(recipient.Value); + } + + RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), filter, recordReplay); + } + public override void PopupPredicted(string? recipientMessage, string? othersMessage, EntityUid uid, EntityUid? recipient, PopupType type = PopupType.Small) { PopupPredicted(othersMessage, uid, recipient, type); diff --git a/Content.Shared/Popups/SharedPopupSystem.cs b/Content.Shared/Popups/SharedPopupSystem.cs index 1ce8efcdf1..66f901c59f 100644 --- a/Content.Shared/Popups/SharedPopupSystem.cs +++ b/Content.Shared/Popups/SharedPopupSystem.cs @@ -114,6 +114,19 @@ namespace Content.Shared.Popups /// public abstract void PopupPredicted(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 players in the filter. + /// If recipient is null, the local client will do nothing and the server will show the message to players in the filter. + /// + /// The message to display. + /// The entity to display the popup above. + /// The client that will see this popup locally during prediction. + /// Filter for players that will see the popup from the server. + /// If true, this pop-up will be considered as a globally visible pop-up that gets shown during replays. + /// Used to customize how this popup should appear visually. See: . + public abstract void PopupPredicted(string? message, EntityUid uid, EntityUid? recipient, Filter filter, bool recordReplay, PopupType type = PopupType.Small); + /// /// Variant of that displays /// to the recipient and to everyone else in PVS range.