SpeechBubble occlusion (#8018)

This commit is contained in:
metalgearsloth
2022-05-08 18:54:56 +10:00
committed by GitHub
parent bba26373ea
commit 1ac5df5e4a
5 changed files with 63 additions and 5 deletions

View File

@@ -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<SpeechBubble> bubbles, bool value)
{
foreach (var bubble in bubbles)
{
bubble.Visible = value;
}
}
}

View File

@@ -139,6 +139,8 @@ namespace Content.Client.Chat.Managers
_stateManager.OnStateChanged += _ => UpdateChannelPermissions();
}
public IReadOnlyDictionary<EntityUid, List<SpeechBubble>> GetSpeechBubbles() => _activeSpeechBubbles;
public void PostInject()
{
_adminMgr.AdminStatusUpdated += UpdateChannelPermissions;

View File

@@ -26,6 +26,7 @@ namespace Content.Client.Chat.Managers
/// </summary>
ChatBox? CurrentChatBox { get; }
IReadOnlyDictionary<EntityUid, List<SpeechBubble>> GetSpeechBubbles();
IReadOnlyDictionary<ChatChannel, int> UnreadMessages { get; }
IReadOnlyList<StoredChatMessage> History { get; }
int MaxMessageLength { get; }

View File

@@ -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.
/// </summary>
public sealed class ChatSystem : EntitySystem
public sealed class ChatSystem : SharedChatSystem
{
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly IChatManager _chatManager = default!;

View File

@@ -0,0 +1,3 @@
namespace Content.Shared.Chat;
public abstract class SharedChatSystem : EntitySystem {}