AdminFaxWindow.xaml.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using Content.Shared.Fax;
  2. using Robust.Client.AutoGenerated;
  3. using Robust.Client.ResourceManagement;
  4. using Robust.Client.UserInterface.Controls;
  5. using Robust.Client.UserInterface.CustomControls;
  6. using Robust.Client.UserInterface.XAML;
  7. using Robust.Shared.ContentPack;
  8. using Robust.Shared.Utility;
  9. namespace Content.Client.Fax.AdminUI;
  10. [GenerateTypedNameReferences]
  11. public sealed partial class AdminFaxWindow : DefaultWindow
  12. {
  13. private const string StampsRsiPath = "/Textures/Objects/Misc/bureaucracy.rsi";
  14. public Action<(NetEntity entity, string title, string stampedBy, string message, string stampSprite, Color stampColor, bool locked)>? OnMessageSend;
  15. public Action<NetEntity>? OnFollowFax;
  16. [Dependency] private readonly IResourceCache _resCache = default!;
  17. public AdminFaxWindow()
  18. {
  19. RobustXamlLoader.Load(this);
  20. IoCManager.InjectDependencies(this);
  21. PopulateStamps();
  22. FaxSelector.OnItemSelected += args => FaxSelector.SelectId(args.Id);
  23. StampSelector.OnItemSelected += args => StampSelector.SelectId(args.Id);
  24. FollowButton.OnPressed += FollowFax;
  25. SendButton.OnPressed += SendMessage;
  26. // Don't use this, but ColorSelectorSliders requires it:
  27. // what the fok
  28. StampColorSelector.OnColorChanged += (color) => {};
  29. var loc = IoCManager.Resolve<ILocalizationManager>();
  30. MessageEdit.Placeholder = new Rope.Leaf(loc.GetString("admin-fax-message-placeholder")); // TextEdit work only with Nodes
  31. }
  32. public void PopulateFaxes(List<AdminFaxEntry> faxes)
  33. {
  34. for (var i = 0; i < faxes.Count; i++)
  35. {
  36. var fax = faxes[i];
  37. FaxSelector.AddItem($"{fax.Name} ({fax.Address})", i);
  38. FaxSelector.SetItemMetadata(i, fax.Uid);
  39. }
  40. }
  41. private void PopulateStamps()
  42. {
  43. var rsi = _resCache.GetResource<RSIResource>(StampsRsiPath).RSI;
  44. using (var enumerator = rsi.GetEnumerator())
  45. {
  46. var i = 0;
  47. while (enumerator.MoveNext())
  48. {
  49. var state = enumerator.Current;
  50. var stateName = state.StateId.Name!;
  51. if (!stateName.StartsWith("paper_stamp-"))
  52. continue;
  53. StampSelector.AddItem(stateName, i);
  54. StampSelector.SetItemMetadata(i, stateName);
  55. i++;
  56. }
  57. }
  58. }
  59. private void FollowFax(BaseButton.ButtonEventArgs obj)
  60. {
  61. var faxEntity = (NetEntity?) FaxSelector.SelectedMetadata;
  62. if (faxEntity == null)
  63. return;
  64. OnFollowFax?.Invoke(faxEntity.Value);
  65. }
  66. private void SendMessage(BaseButton.ButtonEventArgs obj)
  67. {
  68. var faxEntity = (NetEntity?) FaxSelector.SelectedMetadata;
  69. if (faxEntity == null)
  70. return;
  71. var stamp = (string?) StampSelector.SelectedMetadata;
  72. if (stamp == null)
  73. return;
  74. var title = TitleEdit.Text;
  75. if (string.IsNullOrEmpty(title))
  76. return;
  77. var message = Rope.Collapse(MessageEdit.TextRope);
  78. if (string.IsNullOrEmpty(message))
  79. return;
  80. var from = FromEdit.Text;
  81. var stampColor = StampColorSelector.Color;
  82. var locked = LockPageCheckbox.Pressed;
  83. OnMessageSend?.Invoke((faxEntity.Value, title, from, message, stamp, stampColor, locked));
  84. }
  85. }