Files
tbd-station-14/Content.Client/BarSign/BarSignSystem.cs
Nemanja 162913ccd0 Selectable Bar Signs (#29068)
* make bar sign selectable

* ajcm strongest soldier

* AJCM comes down hard for round 2

* good shit

* ok ballin

* bless'ed be the webedit
2024-07-01 02:20:57 +10:00

54 lines
1.8 KiB
C#

using Content.Client.BarSign.Ui;
using Content.Shared.BarSign;
using Content.Shared.Power;
using Robust.Client.GameObjects;
using Robust.Shared.Prototypes;
namespace Content.Client.BarSign;
public sealed class BarSignSystem : VisualizerSystem<BarSignComponent>
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BarSignComponent, AfterAutoHandleStateEvent>(OnAfterAutoHandleState);
}
private void OnAfterAutoHandleState(EntityUid uid, BarSignComponent component, ref AfterAutoHandleStateEvent args)
{
if (_ui.TryGetOpenUi<BarSignBoundUserInterface>(uid, BarSignUiKey.Key, out var bui))
bui.Update(component.Current);
UpdateAppearance(uid, component);
}
protected override void OnAppearanceChange(EntityUid uid, BarSignComponent component, ref AppearanceChangeEvent args)
{
UpdateAppearance(uid, component, args.Component, args.Sprite);
}
private void UpdateAppearance(EntityUid id, BarSignComponent sign, AppearanceComponent? appearance = null, SpriteComponent? sprite = null)
{
if (!Resolve(id, ref appearance, ref sprite))
return;
AppearanceSystem.TryGetData<bool>(id, PowerDeviceVisuals.Powered, out var powered, appearance);
if (powered
&& sign.Current != null
&& _prototypeManager.TryIndex(sign.Current, out var proto))
{
sprite.LayerSetSprite(0, proto.Icon);
sprite.LayerSetShader(0, "unshaded");
}
else
{
sprite.LayerSetState(0, "empty");
sprite.LayerSetShader(0, null, null);
}
}
}