| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- 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;
- /// <summary>
- /// This handles rendering gathering and rendering icons on entities.
- /// </summary>
- 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;
- /// <inheritdoc/>
- 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<StatusIconOverlay>())
- return;
- if (_globalEnabled && _localEnabled)
- _overlay.AddOverlay(new StatusIconOverlay());
- }
- public List<StatusIconData> GetStatusIcons(EntityUid uid, MetaDataComponent? meta = null)
- {
- var list = new List<StatusIconData>();
- 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;
- }
- /// <summary>
- /// For overlay to check if an entity can be seen.
- /// </summary>
- public bool IsVisible(Entity<MetaDataComponent> 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<GhostComponent>(viewer))
- return true;
- if (data.HideInContainer && (ent.Comp.Flags & MetaDataFlags.InContainer) != 0)
- return false;
- if (data.HideOnStealth && TryComp<StealthComponent>(ent, out var stealth) && stealth.Enabled)
- return false;
- if (TryComp<ShowFactionIconsComponent>(ent, out var requested))
- {
- if (TryComp<ShowFactionIconsComponent>(viewer, out var requester))
- {
- //only show if on the same faction
- if (requester.FactionIcon != requested.FactionIcon)
- {
- return false;
- }
- }
- }
- if (TryComp<SpriteComponent>(ent, out var sprite) && !sprite.Visible)
- return false;
- //if (data.ShowTo != null && !_entityWhitelist.IsValid(data.ShowTo, viewer))
- // return false;
- return true;
- }
- }
|