1
0

BarSignSystem.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Content.Client.BarSign.Ui;
  2. using Content.Shared.BarSign;
  3. using Content.Shared.Power;
  4. using Robust.Client.GameObjects;
  5. using Robust.Shared.Prototypes;
  6. namespace Content.Client.BarSign;
  7. public sealed class BarSignSystem : VisualizerSystem<BarSignComponent>
  8. {
  9. [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
  10. [Dependency] private readonly UserInterfaceSystem _ui = default!;
  11. public override void Initialize()
  12. {
  13. base.Initialize();
  14. SubscribeLocalEvent<BarSignComponent, AfterAutoHandleStateEvent>(OnAfterAutoHandleState);
  15. }
  16. private void OnAfterAutoHandleState(EntityUid uid, BarSignComponent component, ref AfterAutoHandleStateEvent args)
  17. {
  18. if (_ui.TryGetOpenUi<BarSignBoundUserInterface>(uid, BarSignUiKey.Key, out var bui))
  19. bui.Update(component.Current);
  20. UpdateAppearance(uid, component);
  21. }
  22. protected override void OnAppearanceChange(EntityUid uid, BarSignComponent component, ref AppearanceChangeEvent args)
  23. {
  24. UpdateAppearance(uid, component, args.Component, args.Sprite);
  25. }
  26. private void UpdateAppearance(EntityUid id, BarSignComponent sign, AppearanceComponent? appearance = null, SpriteComponent? sprite = null)
  27. {
  28. if (!Resolve(id, ref appearance, ref sprite))
  29. return;
  30. AppearanceSystem.TryGetData<bool>(id, PowerDeviceVisuals.Powered, out var powered, appearance);
  31. if (powered
  32. && sign.Current != null
  33. && _prototypeManager.TryIndex(sign.Current, out var proto))
  34. {
  35. sprite.LayerSetSprite(0, proto.Icon);
  36. sprite.LayerSetShader(0, "unshaded");
  37. }
  38. else
  39. {
  40. sprite.LayerSetState(0, "empty");
  41. sprite.LayerSetShader(0, null, null);
  42. }
  43. }
  44. }