1
0

ChemMasterBoundUserInterface.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Content.Shared.Chemistry;
  2. using Content.Shared.Containers.ItemSlots;
  3. using JetBrains.Annotations;
  4. using Robust.Client.GameObjects;
  5. using Robust.Client.UserInterface;
  6. namespace Content.Client.Chemistry.UI
  7. {
  8. /// <summary>
  9. /// Initializes a <see cref="ChemMasterWindow"/> and updates it when new server messages are received.
  10. /// </summary>
  11. [UsedImplicitly]
  12. public sealed class ChemMasterBoundUserInterface : BoundUserInterface
  13. {
  14. [ViewVariables]
  15. private ChemMasterWindow? _window;
  16. public ChemMasterBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  17. {
  18. }
  19. /// <summary>
  20. /// Called each time a chem master UI instance is opened. Generates the window and fills it with
  21. /// relevant info. Sets the actions for static buttons.
  22. /// </summary>
  23. protected override void Open()
  24. {
  25. base.Open();
  26. // Setup window layout/elements
  27. _window = this.CreateWindow<ChemMasterWindow>();
  28. _window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
  29. // Setup static button actions.
  30. _window.InputEjectButton.OnPressed += _ => SendMessage(
  31. new ItemSlotButtonPressedEvent(SharedChemMaster.InputSlotName));
  32. _window.OutputEjectButton.OnPressed += _ => SendMessage(
  33. new ItemSlotButtonPressedEvent(SharedChemMaster.OutputSlotName));
  34. _window.BufferTransferButton.OnPressed += _ => SendMessage(
  35. new ChemMasterSetModeMessage(ChemMasterMode.Transfer));
  36. _window.BufferDiscardButton.OnPressed += _ => SendMessage(
  37. new ChemMasterSetModeMessage(ChemMasterMode.Discard));
  38. _window.CreatePillButton.OnPressed += _ => SendMessage(
  39. new ChemMasterCreatePillsMessage(
  40. (uint) _window.PillDosage.Value, (uint) _window.PillNumber.Value, _window.LabelLine));
  41. _window.CreateBottleButton.OnPressed += _ => SendMessage(
  42. new ChemMasterOutputToBottleMessage(
  43. (uint) _window.BottleDosage.Value, _window.LabelLine));
  44. _window.BufferSortButton.OnPressed += _ => SendMessage(
  45. new ChemMasterSortingTypeCycleMessage());
  46. for (uint i = 0; i < _window.PillTypeButtons.Length; i++)
  47. {
  48. var pillType = i;
  49. _window.PillTypeButtons[i].OnPressed += _ => SendMessage(new ChemMasterSetPillTypeMessage(pillType));
  50. }
  51. _window.OnReagentButtonPressed += (args, button) => SendMessage(new ChemMasterReagentAmountButtonMessage(button.Id, button.Amount, button.IsBuffer));
  52. }
  53. /// <summary>
  54. /// Update the ui each time new state data is sent from the server.
  55. /// </summary>
  56. /// <param name="state">
  57. /// Data of the <see cref="SharedReagentDispenserComponent"/> that this ui represents.
  58. /// Sent from the server.
  59. /// </param>
  60. protected override void UpdateState(BoundUserInterfaceState state)
  61. {
  62. base.UpdateState(state);
  63. var castState = (ChemMasterBoundUserInterfaceState) state;
  64. _window?.UpdateState(castState); // Update window state
  65. }
  66. }
  67. }