90 lines
3.1 KiB
C#
90 lines
3.1 KiB
C#
using Content.Shared.Examine;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.Player;
|
|
using Robust.Client.ResourceManagement;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.Enums;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Physics;
|
|
|
|
namespace Content.Client.Suspicion
|
|
{
|
|
public class TraitorOverlay : Overlay
|
|
{
|
|
private readonly IEntityManager _entityManager;
|
|
private readonly IEyeManager _eyeManager;
|
|
private readonly IPlayerManager _playerManager;
|
|
|
|
public override OverlaySpace Space => OverlaySpace.ScreenSpace;
|
|
private readonly Font _font;
|
|
|
|
private readonly string _traitorText = Loc.GetString("traitor-overlay-traitor-text");
|
|
|
|
public TraitorOverlay(
|
|
IEntityManager entityManager,
|
|
IResourceCache resourceCache,
|
|
IEyeManager eyeManager)
|
|
{
|
|
_playerManager = IoCManager.Resolve<IPlayerManager>();
|
|
|
|
_entityManager = entityManager;
|
|
_eyeManager = eyeManager;
|
|
|
|
_font = new VectorFont(resourceCache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Regular.ttf"), 10);
|
|
}
|
|
|
|
protected override void Draw(in OverlayDrawArgs args)
|
|
{
|
|
var viewport = _eyeManager.GetWorldViewport();
|
|
|
|
var ent = _playerManager.LocalPlayer?.ControlledEntity;
|
|
if (ent == default || _entityManager.TryGetComponent(ent.Value, out SuspicionRoleComponent? sus) != true)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var (_, ally) in sus.Allies)
|
|
{
|
|
// Otherwise the entity can not exist yet
|
|
if (!_entityManager.EntityExists(ally))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (!_entityManager.TryGetComponent(ally, out IPhysBody? physics))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var entPosition = _entityManager.GetComponent<TransformComponent>(ent.Value).MapPosition;
|
|
var allyPosition = _entityManager.GetComponent<TransformComponent>(ally).MapPosition;
|
|
if (!ExamineSystemShared.InRangeUnOccluded(entPosition, allyPosition, 15,
|
|
entity => entity == ent || entity == ally))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// if not on the same map, continue
|
|
if (_entityManager.GetComponent<TransformComponent>(physics.Owner).MapID != _eyeManager.CurrentMap || physics.Owner.IsInContainer())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var worldBox = physics.GetWorldAABB();
|
|
|
|
// if not on screen, or too small, continue
|
|
if (!worldBox.Intersects(in viewport) || worldBox.IsEmpty())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var screenCoordinates = args.ViewportControl!.WorldToScreen(physics.GetWorldAABB().TopLeft + (0, 0.5f));
|
|
args.ScreenHandle.DrawString(_font, screenCoordinates, _traitorText, Color.OrangeRed);
|
|
}
|
|
}
|
|
}
|
|
}
|