SpeechBubble occlusion (#8018)
This commit is contained in:
56
Content.Client/Chat/ChatSystem.cs
Normal file
56
Content.Client/Chat/ChatSystem.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user