ReagentDispenserBoundUserInterface.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Content.Client.Guidebook.Components;
  2. using Content.Shared.Chemistry;
  3. using Content.Shared.Containers.ItemSlots;
  4. using JetBrains.Annotations;
  5. using Robust.Client.GameObjects;
  6. using Robust.Client.UserInterface;
  7. namespace Content.Client.Chemistry.UI
  8. {
  9. /// <summary>
  10. /// Initializes a <see cref="ReagentDispenserWindow"/> and updates it when new server messages are received.
  11. /// </summary>
  12. [UsedImplicitly]
  13. public sealed class ReagentDispenserBoundUserInterface : BoundUserInterface
  14. {
  15. [ViewVariables]
  16. private ReagentDispenserWindow? _window;
  17. public ReagentDispenserBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  18. {
  19. }
  20. /// <summary>
  21. /// Called each time a dispenser UI instance is opened. Generates the dispenser window and fills it with
  22. /// relevant info. Sets the actions for static buttons.
  23. /// <para>Buttons which can change like reagent dispense buttons have their actions set in <see cref="UpdateReagentsList"/>.</para>
  24. /// </summary>
  25. protected override void Open()
  26. {
  27. base.Open();
  28. // Setup window layout/elements
  29. _window = this.CreateWindow<ReagentDispenserWindow>();
  30. _window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
  31. _window.HelpGuidebookIds = EntMan.GetComponent<GuideHelpComponent>(Owner).Guides;
  32. // Setup static button actions.
  33. _window.EjectButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(SharedReagentDispenser.OutputSlotName));
  34. _window.ClearButton.OnPressed += _ => SendMessage(new ReagentDispenserClearContainerSolutionMessage());
  35. _window.AmountGrid.OnButtonPressed += s => SendMessage(new ReagentDispenserSetDispenseAmountMessage(s));
  36. _window.OnDispenseReagentButtonPressed += (id) => SendMessage(new ReagentDispenserDispenseReagentMessage(id));
  37. _window.OnEjectJugButtonPressed += (id) => SendMessage(new ItemSlotButtonPressedEvent(id));
  38. }
  39. /// <summary>
  40. /// Update the UI each time new state data is sent from the server.
  41. /// </summary>
  42. /// <param name="state">
  43. /// Data of the <see cref="ReagentDispenserComponent"/> that this UI represents.
  44. /// Sent from the server.
  45. /// </param>
  46. protected override void UpdateState(BoundUserInterfaceState state)
  47. {
  48. base.UpdateState(state);
  49. var castState = (ReagentDispenserBoundUserInterfaceState) state;
  50. _window?.UpdateState(castState); //Update window state
  51. }
  52. }
  53. }