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;
}
}
}