1
0

ComputerBoundUserInterface.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Robust.Client.GameObjects;
  2. using Robust.Client.UserInterface;
  3. using Robust.Client.UserInterface.CustomControls;
  4. namespace Content.Client.Computer
  5. {
  6. /// <summary>
  7. /// ComputerBoundUserInterface shunts all sorts of responsibilities that are in the BoundUserInterface for architectural reasons into the Window.
  8. /// NOTE: Despite the name, ComputerBoundUserInterface does not and will not care about things like power.
  9. /// </summary>
  10. [Virtual]
  11. public class ComputerBoundUserInterface<TWindow, TState> : ComputerBoundUserInterfaceBase where TWindow : BaseWindow, IComputerWindow<TState>, new() where TState : BoundUserInterfaceState
  12. {
  13. [ViewVariables]
  14. private TWindow? _window;
  15. protected override void Open()
  16. {
  17. base.Open();
  18. _window = this.CreateWindow<TWindow>();
  19. _window.SetupComputerWindow(this);
  20. }
  21. // Alas, this constructor has to be copied to the subclass. :(
  22. public ComputerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  23. {
  24. }
  25. protected override void UpdateState(BoundUserInterfaceState state)
  26. {
  27. base.UpdateState(state);
  28. if (_window == null)
  29. {
  30. return;
  31. }
  32. _window.UpdateState((TState) state);
  33. }
  34. protected override void ReceiveMessage(BoundUserInterfaceMessage message)
  35. {
  36. _window?.ReceiveMessage(message);
  37. }
  38. }
  39. /// <summary>
  40. /// This class is to avoid a lot of &lt;&gt; being written when we just want to refer to SendMessage.
  41. /// We could instead qualify a lot of generics even further, but that is a waste of time.
  42. /// </summary>
  43. [Virtual]
  44. public class ComputerBoundUserInterfaceBase : BoundUserInterface
  45. {
  46. public ComputerBoundUserInterfaceBase(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  47. {
  48. }
  49. public new void SendMessage(BoundUserInterfaceMessage msg)
  50. {
  51. base.SendMessage(msg);
  52. }
  53. }
  54. public interface IComputerWindow<TState>
  55. {
  56. void SetupComputerWindow(ComputerBoundUserInterfaceBase cb)
  57. {
  58. }
  59. void UpdateState(TState state)
  60. {
  61. }
  62. void ReceiveMessage(BoundUserInterfaceMessage message)
  63. {
  64. }
  65. }
  66. }