SpaceHeaterWindow.xaml.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Robust.Client.AutoGenerated;
  2. using Robust.Client.UserInterface.Controls;
  3. using Robust.Client.UserInterface.CustomControls;
  4. using Robust.Client.UserInterface.XAML;
  5. using Content.Shared.Atmos;
  6. using Content.Shared.Atmos.Piping.Portable.Components;
  7. namespace Content.Client.Atmos.UI;
  8. /// <summary>
  9. /// Client-side UI used to control a space heater.
  10. /// </summary>
  11. [GenerateTypedNameReferences]
  12. public sealed partial class SpaceHeaterWindow : DefaultWindow
  13. {
  14. // To account for a minimum delta temperature for atmos equalization to trigger we use a fixed step for target temperature increment/decrement
  15. public int TemperatureChangeDelta = 5;
  16. public bool Active;
  17. // Temperatures range bounds in Kelvin (K)
  18. public float MinTemp;
  19. public float MaxTemp;
  20. public RadioOptions<int> PowerLevelSelector;
  21. public SpaceHeaterWindow()
  22. {
  23. RobustXamlLoader.Load(this);
  24. // Add the Mode selector list
  25. foreach (var value in Enum.GetValues<SpaceHeaterMode>())
  26. {
  27. ModeSelector.AddItem(Loc.GetString($"comp-space-heater-mode-{value}"), (int)value);
  28. }
  29. // Add the Power level radio buttons
  30. PowerLevelSelectorHBox.AddChild(PowerLevelSelector = new RadioOptions<int>(RadioOptionsLayout.Horizontal));
  31. PowerLevelSelector.FirstButtonStyle = "OpenRight";
  32. PowerLevelSelector.LastButtonStyle = "OpenLeft";
  33. PowerLevelSelector.ButtonStyle = "OpenBoth";
  34. foreach (var value in Enum.GetValues<SpaceHeaterPowerLevel>())
  35. {
  36. PowerLevelSelector.AddItem(Loc.GetString($"comp-space-heater-ui-{value}-power-consumption"), (int)value);
  37. }
  38. // Only allow temperature increment/decrement of TemperatureChangeDelta
  39. Thermostat.Editable = false;
  40. }
  41. public void SetActive(bool active)
  42. {
  43. Active = active;
  44. ToggleStatusButton.Pressed = active;
  45. if (active)
  46. {
  47. ToggleStatusButton.Text = Loc.GetString("comp-space-heater-ui-status-enabled");
  48. }
  49. else
  50. {
  51. ToggleStatusButton.Text = Loc.GetString("comp-space-heater-ui-status-disabled");
  52. }
  53. }
  54. public void SetTemperature(float targetTemperature)
  55. {
  56. Thermostat.SetText($"{targetTemperature - Atmospherics.T0C} °C");
  57. IncreaseTempRange.Disabled = targetTemperature + TemperatureChangeDelta > MaxTemp;
  58. DecreaseTempRange.Disabled = targetTemperature - TemperatureChangeDelta < MinTemp;
  59. }
  60. }