diff --git a/Content.Client/Chat/ChatSystem.cs b/Content.Client/Chat/ChatSystem.cs new file mode 100644 index 0000000000..d91264eab1 --- /dev/null +++ b/Content.Client/Chat/ChatSystem.cs @@ -0,0 +1,56 @@ +using Content.Client.Chat.Managers; +using Content.Client.Chat.UI; +using Content.Client.Examine; +using Content.Shared.Chat; +using Content.Shared.Examine; +using Robust.Client.Player; +using Robust.Shared.Map; + +namespace Content.Client.Chat; + +public sealed class ChatSystem : SharedChatSystem +{ + [Dependency] private readonly IChatManager _manager = default!; + [Dependency] private readonly IPlayerManager _player = default!; + + public override void FrameUpdate(float frameTime) + { + base.FrameUpdate(frameTime); + + var player = _player.LocalPlayer?.ControlledEntity; + var predicate = static (EntityUid uid, (EntityUid compOwner, EntityUid? attachedEntity) data) + => uid == data.compOwner || uid == data.attachedEntity; + var bubbles = _manager.GetSpeechBubbles(); + var playerPos = player != null ? Transform(player.Value).MapPosition : MapCoordinates.Nullspace; + + foreach (var (ent, bubs) in bubbles) + { + if (ent == player) + { + SetBubbles(bubs, true); + continue; + } + + var otherPos = Transform(ent).MapPosition; + + if (!ExamineSystemShared.InRangeUnOccluded( + playerPos, + otherPos, 0f, + (ent, player), predicate)) + { + SetBubbles(bubs, false); + continue; + } + + SetBubbles(bubs, true); + } + } + + private void SetBubbles(List bubbles, bool value) + { + foreach (var bubble in bubbles) + { + bubble.Visible = value; + } + } +} diff --git a/Content.Client/Chat/Managers/ChatManager.cs b/Content.Client/Chat/Managers/ChatManager.cs index 68779e77bd..f58d0ce363 100644 --- a/Content.Client/Chat/Managers/ChatManager.cs +++ b/Content.Client/Chat/Managers/ChatManager.cs @@ -139,6 +139,8 @@ namespace Content.Client.Chat.Managers _stateManager.OnStateChanged += _ => UpdateChannelPermissions(); } + public IReadOnlyDictionary> GetSpeechBubbles() => _activeSpeechBubbles; + public void PostInject() { _adminMgr.AdminStatusUpdated += UpdateChannelPermissions; diff --git a/Content.Client/Chat/Managers/IChatManager.cs b/Content.Client/Chat/Managers/IChatManager.cs index 2c25b1b7ee..e59de20183 100644 --- a/Content.Client/Chat/Managers/IChatManager.cs +++ b/Content.Client/Chat/Managers/IChatManager.cs @@ -26,6 +26,7 @@ namespace Content.Client.Chat.Managers /// ChatBox? CurrentChatBox { get; } + IReadOnlyDictionary> GetSpeechBubbles(); IReadOnlyDictionary UnreadMessages { get; } IReadOnlyList History { get; } int MaxMessageLength { get; } diff --git a/Content.Server/Chat/ChatSystem.cs b/Content.Server/Chat/ChatSystem.cs index 53c274dae3..72f8a8ed62 100644 --- a/Content.Server/Chat/ChatSystem.cs +++ b/Content.Server/Chat/ChatSystem.cs @@ -3,8 +3,6 @@ using System.Text; using Content.Server.Administration.Logs; using Content.Server.Administration.Managers; using Content.Server.Chat.Managers; -using Content.Server.Disease; -using Content.Server.Disease.Components; using Content.Server.Ghost.Components; using Content.Server.Headset; using Content.Server.Players; @@ -14,9 +12,7 @@ using Content.Shared.ActionBlocker; using Content.Shared.CCVar; using Content.Shared.Chat; using Content.Shared.Database; -using Content.Shared.Disease.Components; using Content.Shared.Inventory; -using Content.Shared.Popups; using Robust.Server.Player; using Robust.Shared.Configuration; using Robust.Shared.Console; @@ -32,7 +28,7 @@ namespace Content.Server.Chat; /// ChatSystem is responsible for in-simulation chat handling, such as whispering, speaking, emoting, etc. /// ChatSystem depends on ChatManager to actually send the messages. /// -public sealed class ChatSystem : EntitySystem +public sealed class ChatSystem : SharedChatSystem { [Dependency] private readonly IConfigurationManager _configurationManager = default!; [Dependency] private readonly IChatManager _chatManager = default!; diff --git a/Content.Shared/Chat/SharedChatSystem.cs b/Content.Shared/Chat/SharedChatSystem.cs new file mode 100644 index 0000000000..d6df55537d --- /dev/null +++ b/Content.Shared/Chat/SharedChatSystem.cs @@ -0,0 +1,3 @@ +namespace Content.Shared.Chat; + +public abstract class SharedChatSystem : EntitySystem {}