Files
tbd-station-14/Content.Client/StatusIcon/StatusIconSystem.cs
Pieter-Jan Briers 68ce53ae17 Random spontaneous cleanup PR (#25131)
* Use new Subs.CVar helper

Removes manual config OnValueChanged calls, removes need to remember to manually unsubscribe.

This both reduces boilerplate and fixes many issues where subscriptions weren't removed on entity system shutdown.

* Fix a bunch of warnings

* More warning fixes

* Use new DateTime serializer to get rid of ISerializationHooks in changelog code.

* Get rid of some more ISerializationHooks for enums

* And a little more

* Apply suggestions from code review

Co-authored-by: 0x6273 <0x40@keemail.me>

---------

Co-authored-by: 0x6273 <0x40@keemail.me>
2024-02-13 16:48:39 -05:00

64 lines
1.8 KiB
C#

using Content.Shared.CCVar;
using Content.Shared.StatusIcon;
using Content.Shared.StatusIcon.Components;
using Robust.Client.Graphics;
using Robust.Shared.Configuration;
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!;
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 inContainer = (meta.Flags & MetaDataFlags.InContainer) != 0;
var ev = new GetStatusIconsEvent(list, inContainer);
RaiseLocalEvent(uid, ref ev);
return ev.StatusIcons;
}
}