* 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>
59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using Content.Shared.Drugs;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.Player;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Content.Client.Drugs;
|
|
|
|
/// <summary>
|
|
/// System to handle drug related overlays.
|
|
/// </summary>
|
|
public sealed class DrugOverlaySystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IPlayerManager _player = default!;
|
|
[Dependency] private readonly IOverlayManager _overlayMan = default!;
|
|
|
|
private RainbowOverlay _overlay = default!;
|
|
|
|
public static string RainbowKey = "SeeingRainbows";
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<SeeingRainbowsComponent, ComponentInit>(OnInit);
|
|
SubscribeLocalEvent<SeeingRainbowsComponent, ComponentShutdown>(OnShutdown);
|
|
|
|
SubscribeLocalEvent<SeeingRainbowsComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
|
|
SubscribeLocalEvent<SeeingRainbowsComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
|
|
|
|
_overlay = new();
|
|
}
|
|
|
|
private void OnPlayerAttached(EntityUid uid, SeeingRainbowsComponent component, LocalPlayerAttachedEvent args)
|
|
{
|
|
_overlayMan.AddOverlay(_overlay);
|
|
}
|
|
|
|
private void OnPlayerDetached(EntityUid uid, SeeingRainbowsComponent component, LocalPlayerDetachedEvent args)
|
|
{
|
|
_overlay.Intoxication = 0;
|
|
_overlayMan.RemoveOverlay(_overlay);
|
|
}
|
|
|
|
private void OnInit(EntityUid uid, SeeingRainbowsComponent component, ComponentInit args)
|
|
{
|
|
if (_player.LocalEntity == uid)
|
|
_overlayMan.AddOverlay(_overlay);
|
|
}
|
|
|
|
private void OnShutdown(EntityUid uid, SeeingRainbowsComponent component, ComponentShutdown args)
|
|
{
|
|
if (_player.LocalEntity == uid)
|
|
{
|
|
_overlay.Intoxication = 0;
|
|
_overlayMan.RemoveOverlay(_overlay);
|
|
}
|
|
}
|
|
}
|