using Content.Shared.CCVar; using Content.Shared.Ghost; using Content.Shared.StatusIcon; using Content.Shared.StatusIcon.Components; using Content.Shared.Stealth.Components; using Content.Shared.Whitelist; using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Client.Player; using Robust.Shared.Configuration; using Content.Shared.Overlays; namespace Content.Client.StatusIcon; /// /// This handles rendering gathering and rendering icons on entities. /// public sealed class StatusIconSystem : SharedStatusIconSystem { [Dependency] private readonly IConfigurationManager _configuration = default!; [Dependency] private readonly IOverlayManager _overlay = default!; [Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly EntityWhitelistSystem _entityWhitelist = default!; private bool _globalEnabled; private bool _localEnabled; /// public override void Initialize() { Subs.CVar(_configuration, CCVars.LocalStatusIconsEnabled, OnLocalStatusIconChanged, true); Subs.CVar(_configuration, CCVars.GlobalStatusIconsEnabled, OnGlobalStatusIconChanged, true); } private void OnLocalStatusIconChanged(bool obj) { _localEnabled = obj; UpdateOverlayVisible(); } private void OnGlobalStatusIconChanged(bool obj) { _globalEnabled = obj; UpdateOverlayVisible(); } private void UpdateOverlayVisible() { if (_overlay.RemoveOverlay()) return; if (_globalEnabled && _localEnabled) _overlay.AddOverlay(new StatusIconOverlay()); } public List GetStatusIcons(EntityUid uid, MetaDataComponent? meta = null) { var list = new List(); if (!Resolve(uid, ref meta)) return list; if (meta.EntityLifeStage >= EntityLifeStage.Terminating) return list; var ev = new GetStatusIconsEvent(list); RaiseLocalEvent(uid, ref ev); return ev.StatusIcons; } /// /// For overlay to check if an entity can be seen. /// public bool IsVisible(Entity ent, StatusIconData data) { var viewer = _playerManager.LocalSession?.AttachedEntity; // Always show our icons to our entity if (viewer == ent.Owner) return true; if (data.VisibleToGhosts && HasComp(viewer)) return true; if (data.HideInContainer && (ent.Comp.Flags & MetaDataFlags.InContainer) != 0) return false; if (data.HideOnStealth && TryComp(ent, out var stealth) && stealth.Enabled) return false; if (TryComp(ent, out var requested)) { if (TryComp(viewer, out var requester)) { //only show if on the same faction if (requester.FactionIcon != requested.FactionIcon) { return false; } } } if (TryComp(ent, out var sprite) && !sprite.Visible) return false; //if (data.ShowTo != null && !_entityWhitelist.IsValid(data.ShowTo, viewer)) // return false; return true; } }