1
0

ConfigurationBoundUserInterface.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Text.RegularExpressions;
  2. using Robust.Client.GameObjects;
  3. using Robust.Client.UserInterface;
  4. using static Content.Shared.Configurable.ConfigurationComponent;
  5. namespace Content.Client.Configurable.UI
  6. {
  7. public sealed class ConfigurationBoundUserInterface : BoundUserInterface
  8. {
  9. [ViewVariables]
  10. private ConfigurationMenu? _menu;
  11. public ConfigurationBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  12. {
  13. }
  14. protected override void Open()
  15. {
  16. base.Open();
  17. _menu = this.CreateWindow<ConfigurationMenu>();
  18. _menu.OnConfiguration += SendConfiguration;
  19. }
  20. protected override void UpdateState(BoundUserInterfaceState state)
  21. {
  22. base.UpdateState(state);
  23. if (state is not ConfigurationBoundUserInterfaceState configurationState)
  24. return;
  25. _menu?.Populate(configurationState);
  26. }
  27. protected override void ReceiveMessage(BoundUserInterfaceMessage message)
  28. {
  29. base.ReceiveMessage(message);
  30. if (_menu == null)
  31. return;
  32. if (message is ValidationUpdateMessage msg)
  33. {
  34. _menu.Validation = new Regex(msg.ValidationString, RegexOptions.Compiled);
  35. }
  36. }
  37. public void SendConfiguration(Dictionary<string, string> config)
  38. {
  39. SendMessage(new ConfigurationUpdatedMessage(config));
  40. }
  41. }
  42. }