New Health Analyzer UI (#30834)

* WIP: first prototype

* Change text slightly

* Allow names to wrap

* Add label for the scan mode

* Remove ugly text

* Readd bleeding message

* Update code

* Allow for the Health Analyzer UI to grow vertically
This commit is contained in:
Thomas
2024-08-27 09:57:36 -05:00
committed by GitHub
parent 8ffae8d313
commit 250628f805
4 changed files with 147 additions and 116 deletions

View File

@@ -17,6 +17,7 @@ namespace Content.Client.HealthAnalyzer.UI
protected override void Open() protected override void Open()
{ {
base.Open(); base.Open();
_window = this.CreateWindow<HealthAnalyzerWindow>(); _window = this.CreateWindow<HealthAnalyzerWindow>();
_window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName; _window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;

View File

@@ -1,48 +1,64 @@
<controls:FancyWindow <controls:FancyWindow
xmlns="https://spacestation14.io" xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
SetSize="250 100"> MaxHeight="525"
MinWidth="300">
<ScrollContainer <ScrollContainer
Margin="5 5 5 5"
ReturnMeasure="True"
VerticalExpand="True"> VerticalExpand="True">
<BoxContainer <BoxContainer
Name="RootContainer" Name="RootContainer"
VerticalExpand="True"
Orientation="Vertical"> Orientation="Vertical">
<Label <Label
Name="NoPatientDataText" Name="NoPatientDataText"
Text="{Loc health-analyzer-window-no-patient-data-text}" /> Text="{Loc health-analyzer-window-no-patient-data-text}" />
<BoxContainer <BoxContainer
Name="PatientDataContainer" Name="PatientDataContainer"
Orientation="Vertical" Margin="0 0 0 5"
Margin="0 0 5 10"> Orientation="Vertical">
<BoxContainer Name="ScanModePanel" HorizontalExpand="True" Visible="False" Margin="0 5 0 0"> <BoxContainer Orientation="Horizontal" Margin="0 0 0 5">
<Label <SpriteView OverrideDirection="South" Scale="2 2" Name="SpriteView" Access="Public" SetSize="64 64" />
Name="ScanMode" <BoxContainer Margin="5 0 0 0" Orientation="Vertical" VerticalAlignment="Top">
Align="Left" <RichTextLabel Name="NameLabel" SetWidth="150" />
Text="{Loc health-analyzer-window-scan-mode-text}"/> <Label Name="SpeciesLabel" VerticalAlignment="Top" StyleClasses="LabelSubText" />
<Label
Name="ScanModeText"
Align="Right"
HorizontalExpand="True"/>
</BoxContainer> </BoxContainer>
<Label <Label Margin="0 0 5 0" HorizontalExpand="True" HorizontalAlignment="Right" VerticalExpand="True"
Name="PatientName"/> VerticalAlignment="Top" Name="ScanModeLabel"
<Label Text="{Loc 'health-analyzer-window-entity-unknown-text'}" />
Name="Temperature"
Margin="0 5 0 0"/>
<Label
Name="BloodLevel"
Margin="0 5 0 0"/>
<Label
Name="Bleeding"
Margin="0 5 0 0"/>
<Label
Name="patientDamageAmount"
Margin="0 15 0 0"/>
</BoxContainer> </BoxContainer>
<PanelContainer StyleClasses="LowDivider" />
<GridContainer Margin="0 5 0 0" Columns="2">
<Label Text="{Loc 'health-analyzer-window-entity-status-text'}" />
<Label Name="StatusLabel" />
<Label Text="{Loc 'health-analyzer-window-entity-temperature-text'}" />
<Label Name="TemperatureLabel" />
<Label Text="{Loc 'health-analyzer-window-entity-blood-level-text'}" />
<Label Name="BloodLabel" />
<Label Text="{Loc 'health-analyzer-window-entity-damage-total-text'}" />
<Label Name="DamageLabel" />
</GridContainer>
</BoxContainer>
<PanelContainer Name="AlertsDivider" Visible="False" StyleClasses="LowDivider" />
<BoxContainer Name="AlertsContainer" Visible="False" Margin="0 5" Orientation="Horizontal"
HorizontalExpand="True" HorizontalAlignment="Center">
</BoxContainer>
<PanelContainer StyleClasses="LowDivider" />
<BoxContainer <BoxContainer
Name="GroupsContainer" Name="GroupsContainer"
Margin="0 5 0 5"
Orientation="Vertical"> Orientation="Vertical">
</BoxContainer> </BoxContainer>
</BoxContainer> </BoxContainer>
</ScrollContainer> </ScrollContainer>
</controls:FancyWindow> </controls:FancyWindow>

View File

@@ -1,12 +1,20 @@
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using Content.Client.Message;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Controls;
using Content.Shared.Alert;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes; using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.IdentityManagement; using Content.Shared.IdentityManagement;
using Content.Shared.Inventory;
using Content.Shared.MedicalScanner; using Content.Shared.MedicalScanner;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Nutrition.Components; using Content.Shared.Nutrition.Components;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
@@ -28,9 +36,6 @@ namespace Content.Client.HealthAnalyzer.UI
private readonly IPrototypeManager _prototypes; private readonly IPrototypeManager _prototypes;
private readonly IResourceCache _cache; private readonly IResourceCache _cache;
private const int AnalyzerHeight = 430;
private const int AnalyzerWidth = 300;
public HealthAnalyzerWindow() public HealthAnalyzerWindow()
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
@@ -44,8 +49,6 @@ namespace Content.Client.HealthAnalyzer.UI
public void Populate(HealthAnalyzerScannedUserMessage msg) public void Populate(HealthAnalyzerScannedUserMessage msg)
{ {
GroupsContainer.RemoveAllChildren();
var target = _entityManager.GetEntity(msg.TargetEntity); var target = _entityManager.GetEntity(msg.TargetEntity);
if (target == null if (target == null
@@ -57,82 +60,96 @@ namespace Content.Client.HealthAnalyzer.UI
NoPatientDataText.Visible = false; NoPatientDataText.Visible = false;
string entityName = Loc.GetString("health-analyzer-window-entity-unknown-text"); // Scan Mode
if (_entityManager.HasComponent<MetaDataComponent>(target.Value))
{
entityName = Identity.Name(target.Value, _entityManager);
}
if (msg.ScanMode.HasValue) ScanModeLabel.Text = msg.ScanMode.HasValue
{ ? msg.ScanMode.Value
ScanModePanel.Visible = true; ? Loc.GetString("health-analyzer-window-scan-mode-active")
ScanModeText.Text = Loc.GetString(msg.ScanMode.Value ? "health-analyzer-window-scan-mode-active" : "health-analyzer-window-scan-mode-inactive"); : Loc.GetString("health-analyzer-window-scan-mode-inactive")
ScanModeText.FontColorOverride = msg.ScanMode.Value ? Color.Green : Color.Red; : Loc.GetString("health-analyzer-window-entity-unknown-text");
}
else
{
ScanModePanel.Visible = false;
}
PatientName.Text = Loc.GetString( ScanModeLabel.FontColorOverride = msg.ScanMode.HasValue && msg.ScanMode.Value ? Color.Green : Color.Red;
"health-analyzer-window-entity-health-text",
("entityName", entityName)
);
Temperature.Text = Loc.GetString("health-analyzer-window-entity-temperature-text", // Patient Information
("temperature", float.IsNaN(msg.Temperature) ? "N/A" : $"{msg.Temperature - Atmospherics.T0C:F1} °C ({msg.Temperature:F1} K)")
);
BloodLevel.Text = Loc.GetString("health-analyzer-window-entity-blood-level-text", SpriteView.SetEntity(target.Value);
("bloodLevel", float.IsNaN(msg.BloodLevel) ? "N/A" : $"{msg.BloodLevel * 100:F1} %")
); var name = new FormattedMessage();
name.PushColor(Color.White);
name.AddText(_entityManager.HasComponent<MetaDataComponent>(target.Value)
? Identity.Name(target.Value, _entityManager)
: Loc.GetString("health-analyzer-window-entity-unknown-text"));
NameLabel.SetMessage(name);
SpeciesLabel.Text =
_entityManager.TryGetComponent<HumanoidAppearanceComponent>(target.Value,
out var humanoidAppearanceComponent)
? Loc.GetString(_prototypes.Index<SpeciesPrototype>(humanoidAppearanceComponent.Species).Name)
: Loc.GetString("health-analyzer-window-entity-unknown-species-text");
// Basic Diagnostic
TemperatureLabel.Text = !float.IsNaN(msg.Temperature)
? $"{msg.Temperature - Atmospherics.T0C:F1} °C ({msg.Temperature:F1} K)"
: Loc.GetString("health-analyzer-window-entity-unknown-value-text");
BloodLabel.Text = !float.IsNaN(msg.BloodLevel)
? $"{msg.BloodLevel * 100:F1} %"
: Loc.GetString("health-analyzer-window-entity-unknown-value-text");
StatusLabel.Text =
_entityManager.TryGetComponent<MobStateComponent>(target.Value, out var mobStateComponent)
? GetStatus(mobStateComponent.CurrentState)
: Loc.GetString("health-analyzer-window-entity-unknown-text");
// Total Damage
DamageLabel.Text = damageable.TotalDamage.ToString();
// Alerts
AlertsDivider.Visible = msg.Bleeding == true;
AlertsContainer.Visible = msg.Bleeding == true;
if (msg.Bleeding == true) if (msg.Bleeding == true)
{ {
Bleeding.Text = Loc.GetString("health-analyzer-window-entity-bleeding-text"); AlertsContainer.DisposeAllChildren();
Bleeding.FontColorOverride = Color.Red; AlertsContainer.AddChild(new Label
}
else
{ {
Bleeding.Text = string.Empty; // Clear the text Text = Loc.GetString("health-analyzer-window-entity-bleeding-text"),
FontColorOverride = Color.Red,
});
} }
patientDamageAmount.Text = Loc.GetString( // Damage Groups
"health-analyzer-window-entity-damage-total-text",
("amount", damageable.TotalDamage)
);
var damageSortedGroups = var damageSortedGroups =
damageable.DamagePerGroup.OrderBy(damage => damage.Value) damageable.DamagePerGroup.OrderByDescending(damage => damage.Value)
.ToDictionary(x => x.Key, x => x.Value); .ToDictionary(x => x.Key, x => x.Value);
IReadOnlyDictionary<string, FixedPoint2> damagePerType = damageable.Damage.DamageDict; IReadOnlyDictionary<string, FixedPoint2> damagePerType = damageable.Damage.DamageDict;
DrawDiagnosticGroups(damageSortedGroups, damagePerType); DrawDiagnosticGroups(damageSortedGroups, damagePerType);
if (_entityManager.TryGetComponent(target, out HungerComponent? hunger)
&& hunger.StarvationDamage != null
&& hunger.CurrentThreshold <= HungerThreshold.Starving)
{
var box = new Control { Margin = new Thickness(0, 0, 0, 15) };
box.AddChild(CreateDiagnosticGroupTitle(
Loc.GetString("health-analyzer-window-malnutrition"),
"malnutrition"));
GroupsContainer.AddChild(box);
} }
SetHeight = AnalyzerHeight; private static string GetStatus(MobState mobState)
SetWidth = AnalyzerWidth; {
return mobState switch
{
MobState.Alive => Loc.GetString("health-analyzer-window-entity-alive-text"),
MobState.Critical => Loc.GetString("health-analyzer-window-entity-critical-text"),
MobState.Dead => Loc.GetString("health-analyzer-window-entity-dead-text"),
_ => Loc.GetString("health-analyzer-window-entity-unknown-text"),
};
} }
private void DrawDiagnosticGroups( private void DrawDiagnosticGroups(
Dictionary<string, FixedPoint2> groups, IReadOnlyDictionary<string, FixedPoint2> damageDict) Dictionary<string, FixedPoint2> groups,
IReadOnlyDictionary<string, FixedPoint2> damageDict)
{ {
HashSet<string> shownTypes = new(); GroupsContainer.RemoveAllChildren();
// Show the total damage and type breakdown for each damage group. foreach (var (damageGroupId, damageAmount) in groups)
foreach (var (damageGroupId, damageAmount) in groups.Reverse())
{ {
if (damageAmount == 0) if (damageAmount == 0)
continue; continue;
@@ -145,7 +162,6 @@ namespace Content.Client.HealthAnalyzer.UI
var groupContainer = new BoxContainer var groupContainer = new BoxContainer
{ {
Margin = new Thickness(0, 0, 0, 15),
Align = BoxContainer.AlignMode.Begin, Align = BoxContainer.AlignMode.Begin,
Orientation = BoxContainer.LayoutOrientation.Vertical, Orientation = BoxContainer.LayoutOrientation.Vertical,
}; };
@@ -159,23 +175,16 @@ namespace Content.Client.HealthAnalyzer.UI
foreach (var type in group.DamageTypes) foreach (var type in group.DamageTypes)
{ {
if (damageDict.TryGetValue(type, out var typeAmount) && typeAmount > 0) if (!damageDict.TryGetValue(type, out var typeAmount) || typeAmount <= 0)
{
// If damage types are allowed to belong to more than one damage group,
// they may appear twice here. Mark them as duplicate.
if (shownTypes.Contains(type))
continue; continue;
shownTypes.Add(type);
var damageString = Loc.GetString( var damageString = Loc.GetString(
"health-analyzer-window-damage-type-text", "health-analyzer-window-damage-type-text",
("damageType", _prototypes.Index<DamageTypePrototype>(type).LocalizedName), ("damageType", _prototypes.Index<DamageTypePrototype>(type).LocalizedName),
("amount", typeAmount) ("amount", typeAmount)
); );
groupContainer.AddChild(CreateDiagnosticItemLabel(damageString.Insert(0, "- "))); groupContainer.AddChild(CreateDiagnosticItemLabel(damageString.Insert(0, " · ")));
}
} }
} }
} }
@@ -198,7 +207,6 @@ namespace Content.Client.HealthAnalyzer.UI
{ {
return new Label return new Label
{ {
Margin = new Thickness(2, 2),
Text = text, Text = text,
}; };
} }
@@ -207,13 +215,13 @@ namespace Content.Client.HealthAnalyzer.UI
{ {
var rootContainer = new BoxContainer var rootContainer = new BoxContainer
{ {
Margin = new Thickness(0, 6, 0, 0),
VerticalAlignment = VAlignment.Bottom, VerticalAlignment = VAlignment.Bottom,
Orientation = BoxContainer.LayoutOrientation.Horizontal Orientation = BoxContainer.LayoutOrientation.Horizontal,
}; };
rootContainer.AddChild(new TextureRect rootContainer.AddChild(new TextureRect
{ {
Margin = new Thickness(0, 3),
SetSize = new Vector2(30, 30), SetSize = new Vector2(30, 30),
Texture = GetTexture(id.ToLower()) Texture = GetTexture(id.ToLower())
}); });

View File

@@ -1,18 +1,24 @@
health-analyzer-window-no-patient-data-text = No patient data. health-analyzer-window-no-patient-data-text = No patient data.
health-analyzer-window-entity-unknown-text = unknown health-analyzer-window-entity-unknown-text = Unknown
health-analyzer-window-entity-health-text = {$entityName}'s health: health-analyzer-window-entity-unknown-species-text = Non-Humanoid
health-analyzer-window-entity-temperature-text = Temperature: {$temperature} health-analyzer-window-entity-unknown-value-text = N/A
health-analyzer-window-entity-blood-level-text = Blood Level: {$bloodLevel}
health-analyzer-window-entity-bleeding-text = Patient is bleeding! health-analyzer-window-entity-alive-text = Alive
health-analyzer-window-entity-damage-total-text = Total Damage: {$amount} health-analyzer-window-entity-dead-text = Dead
health-analyzer-window-entity-critical-text = Critical
health-analyzer-window-entity-temperature-text = Temperature:
health-analyzer-window-entity-blood-level-text = Blood Level:
health-analyzer-window-entity-status-text = Status:
health-analyzer-window-entity-damage-total-text = Total Damage:
health-analyzer-window-damage-group-text = {$damageGroup}: {$amount} health-analyzer-window-damage-group-text = {$damageGroup}: {$amount}
health-analyzer-window-damage-type-text = {$damageType}: {$amount} health-analyzer-window-damage-type-text = {$damageType}: {$amount}
health-analyzer-window-damage-type-duplicate-text = {$damageType}: {$amount} (duplicate)
health-analyzer-window-entity-bleeding-text = Patient is bleeding!
health-analyzer-window-scan-mode-text = Scan Mode: health-analyzer-window-scan-mode-text = Scan Mode:
health-analyzer-window-scan-mode-active = ACTIVE health-analyzer-window-scan-mode-active = Active
health-analyzer-window-scan-mode-inactive = INACTIVE health-analyzer-window-scan-mode-inactive = Inactive
health-analyzer-window-malnutrition = Severely malnourished
health-analyzer-popup-scan-target = {CAPITALIZE(THE($user))} is trying to scan you! health-analyzer-popup-scan-target = {CAPITALIZE(THE($user))} is trying to scan you!