AtmosAlarmEntryContainer.xaml.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using Content.Client.Stylesheets;
  2. using Content.Shared.Atmos;
  3. using Content.Shared.Atmos.Components;
  4. using Content.Shared.Atmos.Monitor;
  5. using Content.Shared.FixedPoint;
  6. using Content.Shared.Temperature;
  7. using Robust.Client.AutoGenerated;
  8. using Robust.Client.Graphics;
  9. using Robust.Client.ResourceManagement;
  10. using Robust.Client.UserInterface.Controls;
  11. using Robust.Client.UserInterface.XAML;
  12. using Robust.Shared.Map;
  13. using System.Linq;
  14. namespace Content.Client.Atmos.Consoles;
  15. [GenerateTypedNameReferences]
  16. public sealed partial class AtmosAlarmEntryContainer : BoxContainer
  17. {
  18. public NetEntity NetEntity;
  19. public EntityCoordinates? Coordinates;
  20. private readonly IEntityManager _entManager;
  21. private readonly IResourceCache _cache;
  22. private Dictionary<AtmosAlarmType, string> _alarmStrings = new Dictionary<AtmosAlarmType, string>()
  23. {
  24. [AtmosAlarmType.Invalid] = "atmos-alerts-window-invalid-state",
  25. [AtmosAlarmType.Normal] = "atmos-alerts-window-normal-state",
  26. [AtmosAlarmType.Warning] = "atmos-alerts-window-warning-state",
  27. [AtmosAlarmType.Danger] = "atmos-alerts-window-danger-state",
  28. };
  29. public AtmosAlarmEntryContainer(NetEntity uid, EntityCoordinates? coordinates)
  30. {
  31. RobustXamlLoader.Load(this);
  32. _entManager = IoCManager.Resolve<IEntityManager>();
  33. _cache = IoCManager.Resolve<IResourceCache>();
  34. NetEntity = uid;
  35. Coordinates = coordinates;
  36. // Load fonts
  37. var headerFont = new VectorFont(_cache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Bold.ttf"), 11);
  38. var normalFont = new VectorFont(_cache.GetResource<FontResource>("/Fonts/NotoSansDisplay/NotoSansDisplay-Regular.ttf"), 11);
  39. var smallFont = new VectorFont(_cache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Regular.ttf"), 10);
  40. // Set fonts
  41. TemperatureHeaderLabel.FontOverride = headerFont;
  42. PressureHeaderLabel.FontOverride = headerFont;
  43. OxygenationHeaderLabel.FontOverride = headerFont;
  44. GasesHeaderLabel.FontOverride = headerFont;
  45. TemperatureLabel.FontOverride = normalFont;
  46. PressureLabel.FontOverride = normalFont;
  47. OxygenationLabel.FontOverride = normalFont;
  48. NoDataLabel.FontOverride = headerFont;
  49. SilenceCheckBox.Label.FontOverride = smallFont;
  50. SilenceCheckBox.Label.FontColorOverride = Color.DarkGray;
  51. }
  52. public void UpdateEntry(AtmosAlertsComputerEntry entry, bool isFocus, AtmosAlertsFocusDeviceData? focusData = null)
  53. {
  54. NetEntity = entry.NetEntity;
  55. Coordinates = _entManager.GetCoordinates(entry.Coordinates);
  56. // Load fonts
  57. var normalFont = new VectorFont(_cache.GetResource<FontResource>("/Fonts/NotoSansDisplay/NotoSansDisplay-Regular.ttf"), 11);
  58. // Update alarm state
  59. if (!_alarmStrings.TryGetValue(entry.AlarmState, out var alarmString))
  60. alarmString = "atmos-alerts-window-invalid-state";
  61. AlarmStateLabel.Text = Loc.GetString(alarmString);
  62. AlarmStateLabel.FontColorOverride = GetAlarmStateColor(entry.AlarmState);
  63. // Update alarm name
  64. AlarmNameLabel.Text = Loc.GetString("atmos-alerts-window-alarm-label", ("name", entry.EntityName), ("address", entry.Address));
  65. // Focus updates
  66. FocusContainer.Visible = isFocus;
  67. if (isFocus)
  68. SetAsFocus();
  69. else
  70. RemoveAsFocus();
  71. if (isFocus && entry.Group == AtmosAlertsComputerGroup.AirAlarm)
  72. {
  73. MainDataContainer.Visible = (entry.AlarmState != AtmosAlarmType.Invalid);
  74. NoDataLabel.Visible = (entry.AlarmState == AtmosAlarmType.Invalid);
  75. if (focusData != null)
  76. {
  77. // Update temperature
  78. var tempK = (FixedPoint2)focusData.Value.TemperatureData.Item1;
  79. var tempC = (FixedPoint2)TemperatureHelpers.KelvinToCelsius(tempK.Float());
  80. TemperatureLabel.Text = Loc.GetString("atmos-alerts-window-temperature-value", ("valueInC", tempC), ("valueInK", tempK));
  81. TemperatureLabel.FontColorOverride = GetAlarmStateColor(focusData.Value.TemperatureData.Item2);
  82. // Update pressure
  83. PressureLabel.Text = Loc.GetString("atmos-alerts-window-pressure-value", ("value", (FixedPoint2)focusData.Value.PressureData.Item1));
  84. PressureLabel.FontColorOverride = GetAlarmStateColor(focusData.Value.PressureData.Item2);
  85. // Update oxygenation
  86. var oxygenPercent = (FixedPoint2)0f;
  87. var oxygenAlert = AtmosAlarmType.Invalid;
  88. if (focusData.Value.GasData.TryGetValue(Gas.Oxygen, out var oxygenData))
  89. {
  90. oxygenPercent = oxygenData.Item2 * 100f;
  91. oxygenAlert = oxygenData.Item3;
  92. }
  93. OxygenationLabel.Text = Loc.GetString("atmos-alerts-window-oxygenation-value", ("value", oxygenPercent));
  94. OxygenationLabel.FontColorOverride = GetAlarmStateColor(oxygenAlert);
  95. // Update other present gases
  96. GasGridContainer.RemoveAllChildren();
  97. var gasData = focusData.Value.GasData.Where(g => g.Key != Gas.Oxygen);
  98. var keyValuePairs = gasData.ToList();
  99. if (keyValuePairs.Count == 0)
  100. {
  101. // No other gases
  102. var gasLabel = new Label()
  103. {
  104. Text = Loc.GetString("atmos-alerts-window-other-gases-value-nil"),
  105. FontOverride = normalFont,
  106. FontColorOverride = StyleNano.DisabledFore,
  107. HorizontalAlignment = HAlignment.Center,
  108. VerticalAlignment = VAlignment.Center,
  109. HorizontalExpand = true,
  110. Margin = new Thickness(0, 2, 0, 0),
  111. SetHeight = 24f,
  112. };
  113. GasGridContainer.AddChild(gasLabel);
  114. }
  115. else
  116. {
  117. // Add an entry for each gas
  118. foreach ((var gas, (var mol, var percent, var alert)) in keyValuePairs)
  119. {
  120. FixedPoint2 gasPercent = percent * 100f;
  121. var gasAbbreviation = Atmospherics.GasAbbreviations.GetValueOrDefault(gas, Loc.GetString("gas-unknown-abbreviation"));
  122. var gasLabel = new Label()
  123. {
  124. Text = Loc.GetString("atmos-alerts-window-other-gases-value", ("shorthand", gasAbbreviation), ("value", gasPercent)),
  125. FontOverride = normalFont,
  126. FontColorOverride = GetAlarmStateColor(alert),
  127. HorizontalAlignment = HAlignment.Center,
  128. VerticalAlignment = VAlignment.Center,
  129. HorizontalExpand = true,
  130. Margin = new Thickness(0, 2, 0, 0),
  131. SetHeight = 24f,
  132. };
  133. GasGridContainer.AddChild(gasLabel);
  134. }
  135. }
  136. }
  137. }
  138. }
  139. public void SetAsFocus()
  140. {
  141. FocusButton.AddStyleClass(StyleNano.StyleClassButtonColorGreen);
  142. ArrowTexture.TexturePath = "/Textures/Interface/Nano/inverted_triangle.svg.png";
  143. }
  144. public void RemoveAsFocus()
  145. {
  146. FocusButton.RemoveStyleClass(StyleNano.StyleClassButtonColorGreen);
  147. ArrowTexture.TexturePath = "/Textures/Interface/Nano/triangle_right.png";
  148. FocusContainer.Visible = false;
  149. }
  150. private Color GetAlarmStateColor(AtmosAlarmType alarmType)
  151. {
  152. switch (alarmType)
  153. {
  154. case AtmosAlarmType.Normal:
  155. return StyleNano.GoodGreenFore;
  156. case AtmosAlarmType.Warning:
  157. return StyleNano.ConcerningOrangeFore;
  158. case AtmosAlarmType.Danger:
  159. return StyleNano.DangerousRedFore;
  160. }
  161. return StyleNano.DisabledFore;
  162. }
  163. }