<commit_before>﻿using System.Collections.Generic;
using Content.Client.Administration.Managers;
using Content.Shared.Administration.Menu;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Shared.Containers;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Physics;

namespace Content.Client.Administration
{
    internal class AdminNameOverlay : Overlay
    {
        private readonly AdminMenuManager _manager;
        private readonly IEntityManager _entityManager;
        private readonly IEyeManager _eyeManager;
        private readonly IEntityLookup _entityLookup;
        private IReadOnlyList<AdminMenuPlayerListMessage.PlayerInfo>? _playerInfos;
        private readonly Font _font;

        public AdminNameOverlay(AdminMenuManager manager, IEntityManager entityManager, IEyeManager eyeManager, IResourceCache resourceCache, IEntityLookup entityLookup)
        {
            _manager = manager;
            _entityManager = entityManager;
            _eyeManager = eyeManager;
            _entityLookup = entityLookup;
            ZIndex = 200;
            _font = new VectorFont(resourceCache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Regular.ttf"), 10);
        }

        public override OverlaySpace Space => OverlaySpace.ScreenSpace;

        public void UpdatePlayerInfo(List<AdminMenuPlayerListMessage.PlayerInfo> playerInfos)
        {
            _playerInfos = playerInfos;
        }

        protected override void Draw(in OverlayDrawArgs args)
        {
            if (_playerInfos == null)
            {
                return;
            }

            var viewport = _eyeManager.GetWorldViewport();

            foreach (var playerInfo in _playerInfos)
            {
                // Otherwise the entity can not exist yet
                if (!_entityManager.TryGetEntity(playerInfo.EntityUid, out var entity))
                {
                    continue;
                }

                // if not on the same map, continue
                if (entity.Transform.MapID != _eyeManager.CurrentMap)
                {
                    continue;
                }

                var aabb = _entityLookup.GetWorldAabbFromEntity(entity);

                // if not on screen, continue
                if (!aabb.Intersects(in viewport))
                {
                    continue;
                }

                var lineoffset = new Vector2(0, 11f);
                var screenCoordinates = _eyeManager.WorldToScreen(aabb.TopRight + (0, -0.1f));
                if (playerInfo.Antag)
                {
                    args.ScreenHandle.DrawString(_font, screenCoordinates + (lineoffset * 2), "ANTAG", Color.OrangeRed);
                }
                args.ScreenHandle.DrawString(_font, screenCoordinates+(lineoffset), playerInfo.Username, Color.Yellow);
                args.ScreenHandle.DrawString(_font, screenCoordinates, playerInfo.CharacterName, Color.Aquamarine);
            }
        }
    }<commit_msg>makes adminnameoverlay adjust with eyerotation<commit_after>﻿using System.Collections.Generic;
using Content.Client.Administration.Managers;
using Content.Shared.Administration.Menu;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;

namespace Content.Client.Administration
{
    internal class AdminNameOverlay : Overlay
    {
        private readonly AdminMenuManager _manager;
        private readonly IEntityManager _entityManager;
        private readonly IEyeManager _eyeManager;
        private readonly IEntityLookup _entityLookup;
        private IReadOnlyList<AdminMenuPlayerListMessage.PlayerInfo>? _playerInfos;
        private readonly Font _font;

        public AdminNameOverlay(AdminMenuManager manager, IEntityManager entityManager, IEyeManager eyeManager, IResourceCache resourceCache, IEntityLookup entityLookup)
        {
            _manager = manager;
            _entityManager = entityManager;
            _eyeManager = eyeManager;
            _entityLookup = entityLookup;
            ZIndex = 200;
            _font = new VectorFont(resourceCache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Regular.ttf"), 10);
        }

        public override OverlaySpace Space => OverlaySpace.ScreenSpace;

        public void UpdatePlayerInfo(List<AdminMenuPlayerListMessage.PlayerInfo> playerInfos)
        {
            _playerInfos = playerInfos;
        }

        protected override void Draw(in OverlayDrawArgs args)
        {
            if (_playerInfos == null)
            {
                return;
            }

            var viewport = _eyeManager.GetWorldViewport();

            foreach (var playerInfo in _playerInfos)
            {
                // Otherwise the entity can not exist yet
                if (!_entityManager.TryGetEntity(playerInfo.EntityUid, out var entity))
                {
                    continue;
                }

                // if not on the same map, continue
                if (entity.Transform.MapID != _eyeManager.CurrentMap)
                {
                    continue;
                }

                var aabb = _entityLookup.GetWorldAabbFromEntity(entity);

                // if not on screen, continue
                if (!aabb.Intersects(in viewport))
                {
                    continue;
                }

                var lineoffset = new Vector2(0f, 11f);
                var screenCoordinates = _eyeManager.WorldToScreen(aabb.Center +
                                                                  new Angle(-_eyeManager.CurrentEye.Rotation).RotateVec(
                                                                      aabb.TopRight - aabb.Center)) + new Vector2(1f, 7f);
                if (playerInfo.Antag)
                {
                    args.ScreenHandle.DrawString(_font, screenCoordinates + (lineoffset * 2), "ANTAG", Color.OrangeRed);
                }
                args.ScreenHandle.DrawString(_font, screenCoordinates+lineoffset, playerInfo.Username, Color.Yellow);
                args.ScreenHandle.DrawString(_font, screenCoordinates, playerInfo.CharacterName, Color.Aquamarine);
            }
        }
    }
{'fraction_non_alphanumeric': 0.07093096896770108, 'fraction_numerical': 0.004116529449018366, 'mean_word_length': 1.934045517882025, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3131557', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1512, 'n_words': 335}