CrayonSystem.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Content.Client.Items;
  2. using Content.Client.Message;
  3. using Content.Client.Stylesheets;
  4. using Content.Shared.Crayon;
  5. using Robust.Client.UserInterface;
  6. using Robust.Client.UserInterface.Controls;
  7. using Robust.Shared.GameObjects;
  8. using Robust.Shared.GameStates;
  9. using Robust.Shared.Localization;
  10. using Robust.Shared.Timing;
  11. namespace Content.Client.Crayon;
  12. public sealed class CrayonSystem : SharedCrayonSystem
  13. {
  14. // Didn't do in shared because I don't think most of the server stuff can be predicted.
  15. public override void Initialize()
  16. {
  17. base.Initialize();
  18. SubscribeLocalEvent<CrayonComponent, ComponentHandleState>(OnCrayonHandleState);
  19. Subs.ItemStatus<CrayonComponent>(ent => new StatusControl(ent));
  20. }
  21. private static void OnCrayonHandleState(EntityUid uid, CrayonComponent component, ref ComponentHandleState args)
  22. {
  23. if (args.Current is not CrayonComponentState state) return;
  24. component.Color = state.Color;
  25. component.SelectedState = state.State;
  26. component.Charges = state.Charges;
  27. component.Capacity = state.Capacity;
  28. component.UIUpdateNeeded = true;
  29. }
  30. private sealed class StatusControl : Control
  31. {
  32. private readonly CrayonComponent _parent;
  33. private readonly RichTextLabel _label;
  34. public StatusControl(CrayonComponent parent)
  35. {
  36. _parent = parent;
  37. _label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
  38. AddChild(_label);
  39. parent.UIUpdateNeeded = true;
  40. }
  41. protected override void FrameUpdate(FrameEventArgs args)
  42. {
  43. base.FrameUpdate(args);
  44. if (!_parent.UIUpdateNeeded)
  45. {
  46. return;
  47. }
  48. _parent.UIUpdateNeeded = false;
  49. _label.SetMarkup(Robust.Shared.Localization.Loc.GetString("crayon-drawing-label",
  50. ("color",_parent.Color),
  51. ("state",_parent.SelectedState),
  52. ("charges", _parent.Charges),
  53. ("capacity",_parent.Capacity)));
  54. }
  55. }
  56. }