SiliconLawBoundUserInterface.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Linq;
  2. using Content.Shared.Silicons.Laws;
  3. using Content.Shared.Silicons.Laws.Components;
  4. using JetBrains.Annotations;
  5. using Robust.Client.UserInterface;
  6. namespace Content.Client.Silicons.Laws.Ui;
  7. [UsedImplicitly]
  8. public sealed class SiliconLawBoundUserInterface : BoundUserInterface
  9. {
  10. [ViewVariables]
  11. private SiliconLawMenu? _menu;
  12. private EntityUid _owner;
  13. private List<SiliconLaw>? _laws;
  14. public SiliconLawBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  15. {
  16. _owner = owner;
  17. }
  18. protected override void Open()
  19. {
  20. base.Open();
  21. _menu = this.CreateWindow<SiliconLawMenu>();
  22. }
  23. protected override void UpdateState(BoundUserInterfaceState state)
  24. {
  25. base.UpdateState(state);
  26. if (state is not SiliconLawBuiState msg)
  27. return;
  28. if (_laws != null && _laws.Count == msg.Laws.Count)
  29. {
  30. var isSame = true;
  31. foreach (var law in msg.Laws)
  32. {
  33. if (_laws.Contains(law))
  34. continue;
  35. isSame = false;
  36. break;
  37. }
  38. if (isSame)
  39. return;
  40. }
  41. _laws = msg.Laws.ToList();
  42. _menu?.Update(_owner, msg);
  43. }
  44. }