1
0

GasVolumePumpWindow.xaml.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using Content.Client.Atmos.EntitySystems;
  5. using Content.Shared.Atmos;
  6. using Content.Shared.Atmos.Prototypes;
  7. using Robust.Client.AutoGenerated;
  8. using Robust.Client.UserInterface.Controls;
  9. using Robust.Client.UserInterface.CustomControls;
  10. using Robust.Client.UserInterface.XAML;
  11. using Robust.Shared.Localization;
  12. namespace Content.Client.Atmos.UI
  13. {
  14. /// <summary>
  15. /// Client-side UI used to control a gas volume pump.
  16. /// </summary>
  17. [GenerateTypedNameReferences]
  18. public sealed partial class GasVolumePumpWindow : DefaultWindow
  19. {
  20. public bool PumpStatus = true;
  21. public event Action? ToggleStatusButtonPressed;
  22. public event Action<string>? PumpTransferRateChanged;
  23. public GasVolumePumpWindow()
  24. {
  25. RobustXamlLoader.Load(this);
  26. ToggleStatusButton.OnPressed += _ => SetPumpStatus(!PumpStatus);
  27. ToggleStatusButton.OnPressed += _ => ToggleStatusButtonPressed?.Invoke();
  28. PumpTransferRateInput.OnTextChanged += _ => SetTransferRateButton.Disabled = false;
  29. SetTransferRateButton.OnPressed += _ =>
  30. {
  31. PumpTransferRateChanged?.Invoke(PumpTransferRateInput.Text ??= "");
  32. SetTransferRateButton.Disabled = true;
  33. };
  34. SetMaxRateButton.OnPressed += _ =>
  35. {
  36. PumpTransferRateInput.Text = Atmospherics.MaxTransferRate.ToString(CultureInfo.CurrentCulture);
  37. SetTransferRateButton.Disabled = false;
  38. };
  39. }
  40. public void SetTransferRate(float rate)
  41. {
  42. PumpTransferRateInput.Text = rate.ToString(CultureInfo.CurrentCulture);
  43. }
  44. public void SetPumpStatus(bool enabled)
  45. {
  46. PumpStatus = enabled;
  47. if (enabled)
  48. {
  49. ToggleStatusButton.Text = Loc.GetString("comp-gas-pump-ui-status-enabled");
  50. }
  51. else
  52. {
  53. ToggleStatusButton.Text = Loc.GetString("comp-gas-pump-ui-status-disabled");
  54. }
  55. }
  56. }
  57. }