1
0

GasMixerWindow.xaml.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.Graphics;
  9. using Robust.Client.UserInterface;
  10. using Robust.Client.UserInterface.Controls;
  11. using Robust.Client.UserInterface.CustomControls;
  12. using Robust.Client.UserInterface.XAML;
  13. using Robust.Shared.Localization;
  14. using Robust.Shared.Maths;
  15. namespace Content.Client.Atmos.UI
  16. {
  17. /// <summary>
  18. /// Client-side UI used to control a gas mixer.
  19. /// </summary>
  20. [GenerateTypedNameReferences]
  21. public sealed partial class GasMixerWindow : DefaultWindow
  22. {
  23. public bool MixerStatus = true;
  24. public event Action? ToggleStatusButtonPressed;
  25. public event Action<string>? MixerOutputPressureChanged;
  26. public event Action<string>? MixerNodePercentageChanged;
  27. public bool NodeOneLastEdited = true;
  28. public GasMixerWindow()
  29. {
  30. RobustXamlLoader.Load(this);
  31. ToggleStatusButton.OnPressed += _ => SetMixerStatus(!MixerStatus);
  32. ToggleStatusButton.OnPressed += _ => ToggleStatusButtonPressed?.Invoke();
  33. MixerPressureOutputInput.OnTextChanged += _ => SetOutputPressureButton.Disabled = false;
  34. SetOutputPressureButton.OnPressed += _ =>
  35. {
  36. MixerOutputPressureChanged?.Invoke(MixerPressureOutputInput.Text ??= "");
  37. SetOutputPressureButton.Disabled = true;
  38. };
  39. SetMaxPressureButton.OnPressed += _ =>
  40. {
  41. MixerPressureOutputInput.Text = Atmospherics.MaxOutputPressure.ToString(CultureInfo.CurrentCulture);
  42. SetOutputPressureButton.Disabled = false;
  43. };
  44. MixerNodeOneInput.OnTextChanged += _ =>
  45. {
  46. SetMixerPercentageButton.Disabled = false;
  47. NodeOneLastEdited = true;
  48. };
  49. MixerNodeTwoInput.OnTextChanged += _ =>
  50. {
  51. SetMixerPercentageButton.Disabled = false;
  52. NodeOneLastEdited = false;
  53. };
  54. SetMixerPercentageButton.OnPressed += _ =>
  55. {
  56. MixerNodePercentageChanged?.Invoke(NodeOneLastEdited ? MixerNodeOneInput.Text ??= "" : MixerNodeTwoInput.Text ??= "");
  57. SetMixerPercentageButton.Disabled = true;
  58. };
  59. }
  60. public void SetOutputPressure(float pressure)
  61. {
  62. MixerPressureOutputInput.Text = pressure.ToString(CultureInfo.CurrentCulture);
  63. }
  64. public void SetNodePercentages(float nodeOne)
  65. {
  66. nodeOne *= 100.0f;
  67. MixerNodeOneInput.Text = nodeOne.ToString("0.##", CultureInfo.CurrentCulture);
  68. float nodeTwo = 100.0f - nodeOne;
  69. MixerNodeTwoInput.Text = nodeTwo.ToString("0.##", CultureInfo.CurrentCulture);
  70. }
  71. public void SetMixerStatus(bool enabled)
  72. {
  73. MixerStatus = enabled;
  74. if (enabled)
  75. {
  76. ToggleStatusButton.Text = Loc.GetString("comp-gas-mixer-ui-status-enabled");
  77. }
  78. else
  79. {
  80. ToggleStatusButton.Text = Loc.GetString("comp-gas-mixer-ui-status-disabled");
  81. }
  82. }
  83. }
  84. }