From 9107d421bdd2600883780d02d521ebbbec06ac68 Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Sat, 13 Apr 2024 23:42:45 -0400 Subject: [PATCH] Add two-message overload to PopupPredicted (#26907) Added two-message overload to PopupPredicted --- Content.Client/Popups/PopupSystem.cs | 6 ++++++ Content.Server/Popups/PopupSystem.cs | 5 +++++ Content.Shared/Burial/BurialSystem.cs | 5 +++-- Content.Shared/Climbing/Systems/BonkSystem.cs | 6 ++++-- Content.Shared/Climbing/Systems/ClimbSystem.cs | 3 +-- Content.Shared/Popups/SharedPopupSystem.cs | 6 ++++++ Content.Shared/Wieldable/WieldableSystem.cs | 12 ++++++------ 7 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Content.Client/Popups/PopupSystem.cs b/Content.Client/Popups/PopupSystem.cs index fcc8bfc420..3faa392e58 100644 --- a/Content.Client/Popups/PopupSystem.cs +++ b/Content.Client/Popups/PopupSystem.cs @@ -184,6 +184,12 @@ namespace Content.Client.Popups 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) + PopupEntity(recipientMessage, uid, recipient.Value, type); + } + #endregion #region Network Event Handlers diff --git a/Content.Server/Popups/PopupSystem.cs b/Content.Server/Popups/PopupSystem.cs index 237ca33a4d..d1163a2be1 100644 --- a/Content.Server/Popups/PopupSystem.cs +++ b/Content.Server/Popups/PopupSystem.cs @@ -126,5 +126,10 @@ namespace Content.Server.Popups RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid))); } } + + 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/Burial/BurialSystem.cs b/Content.Shared/Burial/BurialSystem.cs index ccf5f1a298..326272cc7d 100644 --- a/Content.Shared/Burial/BurialSystem.cs +++ b/Content.Shared/Burial/BurialSystem.cs @@ -116,8 +116,9 @@ public sealed class BurialSystem : EntitySystem { if (used != null) { - _popupSystem.PopupClient(Loc.GetString("grave-start-digging-user", ("grave", uid), ("tool", used)), user, user); - _popupSystem.PopupEntity(Loc.GetString("grave-start-digging-others", ("user", user), ("grave", uid), ("tool", used)), user, Filter.PvsExcept(user), true); + var selfMessage = Loc.GetString("grave-start-digging-user", ("grave", uid), ("tool", used)); + var othersMessage = Loc.GetString("grave-start-digging-others", ("user", user), ("grave", uid), ("tool", used)); + _popupSystem.PopupPredicted(selfMessage, othersMessage, user, user); component.ActiveShovelDigging = true; Dirty(uid, component); } diff --git a/Content.Shared/Climbing/Systems/BonkSystem.cs b/Content.Shared/Climbing/Systems/BonkSystem.cs index 4fe2661aff..ea4e04c621 100644 --- a/Content.Shared/Climbing/Systems/BonkSystem.cs +++ b/Content.Shared/Climbing/Systems/BonkSystem.cs @@ -57,9 +57,11 @@ public sealed partial class BonkSystem : EntitySystem if (user == source) { // Non-local, non-bonking players - _popupSystem.PopupEntity(Loc.GetString("bonkable-success-message-others", ("user", userName), ("bonkable", bonkableName)), user, Filter.PvsExcept(user), true); + var othersMessage = Loc.GetString("bonkable-success-message-others", ("user", userName), ("bonkable", bonkableName)); // Local, bonking player - _popupSystem.PopupClient(Loc.GetString("bonkable-success-message-user", ("user", userName), ("bonkable", bonkableName)), user, user); + var selfMessage = Loc.GetString("bonkable-success-message-user", ("user", userName), ("bonkable", bonkableName)); + + _popupSystem.PopupPredicted(selfMessage, othersMessage, user, user); } else if (source != null) { diff --git a/Content.Shared/Climbing/Systems/ClimbSystem.cs b/Content.Shared/Climbing/Systems/ClimbSystem.cs index 5471f07250..1bdaecf730 100644 --- a/Content.Shared/Climbing/Systems/ClimbSystem.cs +++ b/Content.Shared/Climbing/Systems/ClimbSystem.cs @@ -307,8 +307,7 @@ public sealed partial class ClimbSystem : VirtualController ("climbable", climbable)); } - _popupSystem.PopupEntity(othersMessage, uid, Filter.PvsExcept(user, entityManager: EntityManager), true); - _popupSystem.PopupClient(selfMessage, uid, user); + _popupSystem.PopupPredicted(selfMessage, othersMessage, uid, user); } /// diff --git a/Content.Shared/Popups/SharedPopupSystem.cs b/Content.Shared/Popups/SharedPopupSystem.cs index b199884afb..10e8ca9be1 100644 --- a/Content.Shared/Popups/SharedPopupSystem.cs +++ b/Content.Shared/Popups/SharedPopupSystem.cs @@ -94,6 +94,12 @@ namespace Content.Shared.Popups /// 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); + + /// + /// Variant of that displays + /// to the recipient and to everyone else in PVS range. + /// + public abstract void PopupPredicted(string? recipientMessage, string? othersMessage, EntityUid uid, EntityUid? recipient, PopupType type = PopupType.Small); } /// diff --git a/Content.Shared/Wieldable/WieldableSystem.cs b/Content.Shared/Wieldable/WieldableSystem.cs index 9fe76c625b..2baed19ef8 100644 --- a/Content.Shared/Wieldable/WieldableSystem.cs +++ b/Content.Shared/Wieldable/WieldableSystem.cs @@ -195,8 +195,9 @@ public sealed class WieldableSystem : EntitySystem && !_delay.TryResetDelay((used, useDelay), true)) return false; - _popupSystem.PopupClient(Loc.GetString("wieldable-component-successful-wield", ("item", used)), user, user); - _popupSystem.PopupEntity(Loc.GetString("wieldable-component-successful-wield-other", ("user", user), ("item", used)), user, Filter.PvsExcept(user), true); + var selfMessage = Loc.GetString("wieldable-component-successful-wield", ("item", used)); + var othersMessage = Loc.GetString("wieldable-component-successful-wield-other", ("user", user), ("item", used)); + _popupSystem.PopupPredicted(selfMessage, othersMessage, user, user); var targEv = new ItemWieldedEvent(); RaiseLocalEvent(used, ref targEv); @@ -239,10 +240,9 @@ public sealed class WieldableSystem : EntitySystem if (component.UnwieldSound != null) _audioSystem.PlayPredicted(component.UnwieldSound, uid, args.User); - _popupSystem.PopupClient(Loc.GetString("wieldable-component-failed-wield", - ("item", uid)), args.User.Value, args.User.Value); - _popupSystem.PopupEntity(Loc.GetString("wieldable-component-failed-wield-other", - ("user", args.User.Value), ("item", uid)), args.User.Value, Filter.PvsExcept(args.User.Value), true); + var selfMessage = Loc.GetString("wieldable-component-failed-wield", ("item", uid)); + var othersMessage = Loc.GetString("wieldable-component-failed-wield-other", ("user", args.User.Value), ("item", uid)); + _popupSystem.PopupPredicted(selfMessage, othersMessage, args.User.Value, args.User.Value); } _appearance.SetData(uid, WieldableVisuals.Wielded, false); -- 2.51.2