AtmosMonitoringEntryContainer.xaml.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using Content.Client.Stylesheets;
  2. using Content.Shared.Atmos;
  3. using Content.Shared.Atmos.Components;
  4. using Content.Shared.FixedPoint;
  5. using Content.Shared.Temperature;
  6. using Robust.Client.AutoGenerated;
  7. using Robust.Client.Graphics;
  8. using Robust.Client.ResourceManagement;
  9. using Robust.Client.UserInterface.Controls;
  10. using Robust.Client.UserInterface.XAML;
  11. using System.Linq;
  12. namespace Content.Client.Atmos.Consoles;
  13. [GenerateTypedNameReferences]
  14. public sealed partial class AtmosMonitoringEntryContainer : BoxContainer
  15. {
  16. public AtmosMonitoringConsoleEntry Data;
  17. private readonly IEntityManager _entManager;
  18. private readonly IResourceCache _cache;
  19. public AtmosMonitoringEntryContainer(AtmosMonitoringConsoleEntry data)
  20. {
  21. RobustXamlLoader.Load(this);
  22. _entManager = IoCManager.Resolve<IEntityManager>();
  23. _cache = IoCManager.Resolve<IResourceCache>();
  24. Data = data;
  25. // Modulate colored stripe
  26. NetworkColorStripe.Modulate = data.Color;
  27. // Load fonts
  28. var headerFont = new VectorFont(_cache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Bold.ttf"), 11);
  29. var normalFont = new VectorFont(_cache.GetResource<FontResource>("/Fonts/NotoSansDisplay/NotoSansDisplay-Regular.ttf"), 11);
  30. // Set fonts
  31. TemperatureHeaderLabel.FontOverride = headerFont;
  32. PressureHeaderLabel.FontOverride = headerFont;
  33. TotalMolHeaderLabel.FontOverride = headerFont;
  34. GasesHeaderLabel.FontOverride = headerFont;
  35. TemperatureLabel.FontOverride = normalFont;
  36. PressureLabel.FontOverride = normalFont;
  37. TotalMolLabel.FontOverride = normalFont;
  38. NoDataLabel.FontOverride = headerFont;
  39. }
  40. public void UpdateEntry(AtmosMonitoringConsoleEntry updatedData, bool isFocus)
  41. {
  42. // Load fonts
  43. var normalFont = new VectorFont(_cache.GetResource<FontResource>("/Fonts/NotoSansDisplay/NotoSansDisplay-Regular.ttf"), 11);
  44. // Update name and values
  45. if (!string.IsNullOrEmpty(updatedData.Address))
  46. NetworkNameLabel.Text = Loc.GetString("atmos-alerts-window-alarm-label", ("name", updatedData.EntityName), ("address", updatedData.Address));
  47. else
  48. NetworkNameLabel.Text = Loc.GetString(updatedData.EntityName);
  49. Data = updatedData;
  50. // Modulate colored stripe
  51. NetworkColorStripe.Modulate = Data.Color;
  52. // Focus updates
  53. if (isFocus)
  54. SetAsFocus();
  55. else
  56. RemoveAsFocus();
  57. // Check if powered
  58. if (!updatedData.IsPowered)
  59. {
  60. MainDataContainer.Visible = false;
  61. NoDataLabel.Visible = true;
  62. return;
  63. }
  64. // Set container visibility
  65. MainDataContainer.Visible = true;
  66. NoDataLabel.Visible = false;
  67. // Update temperature
  68. var isNotVacuum = updatedData.TotalMolData > 1e-6f;
  69. var tempK = (FixedPoint2)updatedData.TemperatureData;
  70. var tempC = (FixedPoint2)TemperatureHelpers.KelvinToCelsius(tempK.Float());
  71. TemperatureLabel.Text = isNotVacuum ?
  72. Loc.GetString("atmos-alerts-window-temperature-value", ("valueInC", tempC), ("valueInK", tempK)) :
  73. Loc.GetString("atmos-alerts-window-invalid-value");
  74. TemperatureLabel.FontColorOverride = isNotVacuum ? Color.DarkGray : StyleNano.DisabledFore;
  75. // Update pressure
  76. PressureLabel.Text = Loc.GetString("atmos-alerts-window-pressure-value", ("value", (FixedPoint2)updatedData.PressureData));
  77. PressureLabel.FontColorOverride = isNotVacuum ? Color.DarkGray : StyleNano.DisabledFore;
  78. // Update total mol
  79. TotalMolLabel.Text = Loc.GetString("atmos-alerts-window-total-mol-value", ("value", (FixedPoint2)updatedData.TotalMolData));
  80. TotalMolLabel.FontColorOverride = isNotVacuum ? Color.DarkGray : StyleNano.DisabledFore;
  81. // Update other present gases
  82. GasGridContainer.RemoveAllChildren();
  83. if (updatedData.GasData.Count() == 0)
  84. {
  85. // No gases
  86. var gasLabel = new Label()
  87. {
  88. Text = Loc.GetString("atmos-alerts-window-other-gases-value-nil"),
  89. FontOverride = normalFont,
  90. FontColorOverride = StyleNano.DisabledFore,
  91. HorizontalAlignment = HAlignment.Center,
  92. VerticalAlignment = VAlignment.Center,
  93. HorizontalExpand = true,
  94. Margin = new Thickness(0, 2, 0, 0),
  95. SetHeight = 24f,
  96. };
  97. GasGridContainer.AddChild(gasLabel);
  98. }
  99. else
  100. {
  101. // Add an entry for each gas
  102. foreach (var (gas, percent) in updatedData.GasData)
  103. {
  104. var gasPercent = (FixedPoint2)0f;
  105. gasPercent = percent * 100f;
  106. var gasAbbreviation = Atmospherics.GasAbbreviations.GetValueOrDefault(gas, Loc.GetString("gas-unknown-abbreviation"));
  107. var gasLabel = new Label()
  108. {
  109. Text = Loc.GetString("atmos-alerts-window-other-gases-value", ("shorthand", gasAbbreviation), ("value", gasPercent)),
  110. FontOverride = normalFont,
  111. HorizontalAlignment = HAlignment.Center,
  112. VerticalAlignment = VAlignment.Center,
  113. HorizontalExpand = true,
  114. Margin = new Thickness(0, 2, 0, 0),
  115. SetHeight = 24f,
  116. };
  117. GasGridContainer.AddChild(gasLabel);
  118. }
  119. }
  120. }
  121. public void SetAsFocus()
  122. {
  123. FocusButton.AddStyleClass(StyleNano.StyleClassButtonColorGreen);
  124. ArrowTexture.TexturePath = "/Textures/Interface/Nano/inverted_triangle.svg.png";
  125. FocusContainer.Visible = true;
  126. }
  127. public void RemoveAsFocus()
  128. {
  129. FocusButton.RemoveStyleClass(StyleNano.StyleClassButtonColorGreen);
  130. ArrowTexture.TexturePath = "/Textures/Interface/Nano/triangle_right.png";
  131. FocusContainer.Visible = false;
  132. }
  133. }