1
0

CrayonBoundUserInterface.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Linq;
  2. using Content.Shared.Crayon;
  3. using Content.Shared.Decals;
  4. using Robust.Client.GameObjects;
  5. using Robust.Client.UserInterface;
  6. using Robust.Shared.Prototypes;
  7. namespace Content.Client.Crayon.UI
  8. {
  9. public sealed class CrayonBoundUserInterface : BoundUserInterface
  10. {
  11. [Dependency] private readonly IPrototypeManager _protoManager = default!;
  12. [ViewVariables]
  13. private CrayonWindow? _menu;
  14. public CrayonBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  15. {
  16. }
  17. protected override void Open()
  18. {
  19. base.Open();
  20. _menu = this.CreateWindowCenteredLeft<CrayonWindow>();
  21. _menu.OnColorSelected += SelectColor;
  22. _menu.OnSelected += Select;
  23. PopulateCrayons();
  24. }
  25. private void PopulateCrayons()
  26. {
  27. var crayonDecals = _protoManager.EnumeratePrototypes<DecalPrototype>().Where(x => x.Tags.Contains("crayon"));
  28. _menu?.Populate(crayonDecals.ToList());
  29. }
  30. public override void OnProtoReload(PrototypesReloadedEventArgs args)
  31. {
  32. base.OnProtoReload(args);
  33. if (!args.WasModified<DecalPrototype>())
  34. return;
  35. PopulateCrayons();
  36. }
  37. protected override void ReceiveMessage(BoundUserInterfaceMessage message)
  38. {
  39. base.ReceiveMessage(message);
  40. if (_menu is null || message is not CrayonUsedMessage crayonMessage)
  41. return;
  42. _menu.AdvanceState(crayonMessage.DrawnDecal);
  43. }
  44. protected override void UpdateState(BoundUserInterfaceState state)
  45. {
  46. base.UpdateState(state);
  47. _menu?.UpdateState((CrayonBoundUserInterfaceState) state);
  48. }
  49. public void Select(string state)
  50. {
  51. SendMessage(new CrayonSelectMessage(state));
  52. }
  53. public void SelectColor(Color color)
  54. {
  55. SendMessage(new CrayonColorMessage(color));
  56. }
  57. }
  58. }