Body scanner and new health analyzer UI (#445)
* Body scanner and new health analyzer UI * fix --------- Co-authored-by: XDRmix <xdrmix@mail.ru>
This commit is contained in:
@@ -1,33 +1,26 @@
|
||||
<DefaultWindow xmlns="https://spacestation14.io"
|
||||
SetSize="250 100">
|
||||
<ScrollContainer
|
||||
VerticalExpand="True">
|
||||
<BoxContainer
|
||||
Name="RootContainer"
|
||||
Orientation="Vertical">
|
||||
<Label
|
||||
Name="NoPatientDataText"
|
||||
Text="{Loc health-analyzer-window-no-patient-data-text}" />
|
||||
<BoxContainer
|
||||
Name="PatientDataContainer"
|
||||
Orientation="Vertical"
|
||||
Margin="0 0 5 10">
|
||||
<Label
|
||||
Name="PatientName"/>
|
||||
<Label
|
||||
Name="Temperature"
|
||||
Margin="0 5 0 0"/>
|
||||
<Label
|
||||
Name="BloodLevel"
|
||||
Margin="0 5 0 0"/>
|
||||
<Label
|
||||
Name="patientDamageAmount"
|
||||
Margin="0 15 0 0"/>
|
||||
</BoxContainer>
|
||||
<BoxContainer
|
||||
Name="GroupsContainer"
|
||||
Orientation="Vertical">
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</ScrollContainer>
|
||||
</DefaultWindow>
|
||||
<!-- WD start -->
|
||||
<controls:FancyWindow xmlns="https://spacestation14.io"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
|
||||
Title="{Loc 'gravity-generator-window-title'}"
|
||||
MinSize="260 300">
|
||||
<BoxContainer Margin="4 0" Orientation="Vertical">
|
||||
<controls:StripeBack>
|
||||
<Label Name="EntityNameLabel" Text="N/A" StyleClasses="LabelBig" Align="Center"/>
|
||||
</controls:StripeBack>
|
||||
<GridContainer Columns="2">
|
||||
<Label Text="{Loc 'health-analyzer-window-entity-current-alive-status-text'}" StyleClasses="StatusFieldTitle"/>
|
||||
<Label Name="AliveStatusLabel" Text="{Loc 'health-analyzer-window-no-data'}" Margin="4 0 0 0"/>
|
||||
<Label Text="{Loc 'health-analyzer-window-entity-temperature-text'}" StyleClasses="StatusFieldTitle"/>
|
||||
<Label Name="TemperatureLabel" Text="{Loc 'health-analyzer-window-no-data'}" Margin="4 0 0 0"/>
|
||||
<Label Text="{Loc 'health-analyzer-window-entity-blood-level-text'}" StyleClasses="StatusFieldTitle"/>
|
||||
<Label Name="BloodLevelLabel" Text="{Loc 'health-analyzer-window-no-data'}" Margin="4 0 0 0"/>
|
||||
<Label Text="{Loc 'health-analyzer-window-entity-damage-total-text'}" StyleClasses="StatusFieldTitle"/>
|
||||
<Label Name="TotalDamageLabel" Text="{Loc 'health-analyzer-window-no-data'}" Margin="4 0 0 0"/>
|
||||
</GridContainer>
|
||||
<customControls:HSeparator StyleClasses="LowDivider" Margin="0 0 0 10"/>
|
||||
<!-- Filled by code -->
|
||||
<GridContainer Name="DamageGroupsContainer" Columns="2"/>
|
||||
</BoxContainer>
|
||||
</controls:FancyWindow>
|
||||
<!-- WD end -->
|
||||
|
||||
@@ -1,189 +1,67 @@
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Client.White.Medical.BodyScanner;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.MedicalScanner;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.HealthAnalyzer.UI
|
||||
{
|
||||
// WD start
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class HealthAnalyzerWindow : DefaultWindow
|
||||
public sealed partial class HealthAnalyzerWindow : FancyWindow
|
||||
{
|
||||
private readonly IEntityManager _entityManager;
|
||||
private readonly SpriteSystem _spriteSystem;
|
||||
private readonly IPrototypeManager _prototypes;
|
||||
private readonly IResourceCache _cache;
|
||||
|
||||
private const int AnalyzerHeight = 430;
|
||||
private const int AnalyzerWidth = 300;
|
||||
|
||||
public HealthAnalyzerWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
var dependencies = IoCManager.Instance!;
|
||||
_entityManager = dependencies.Resolve<IEntityManager>();
|
||||
_spriteSystem = _entityManager.System<SpriteSystem>();
|
||||
_prototypes = dependencies.Resolve<IPrototypeManager>();
|
||||
_cache = dependencies.Resolve<IResourceCache>();
|
||||
}
|
||||
|
||||
public void Populate(HealthAnalyzerScannedUserMessage msg)
|
||||
{
|
||||
GroupsContainer.RemoveAllChildren();
|
||||
var entities = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
var target = _entityManager.GetEntity(msg.TargetEntity);
|
||||
|
||||
if (target == null
|
||||
|| !_entityManager.TryGetComponent<DamageableComponent>(target, out var damageable))
|
||||
if (msg.TargetEntity != null &&
|
||||
entities.TryGetComponent<DamageableComponent>(entities.GetEntity(msg.TargetEntity), out var damageable))
|
||||
{
|
||||
NoPatientDataText.Visible = true;
|
||||
return;
|
||||
}
|
||||
EntityNameLabel.Text = Identity.Name(entities.GetEntity(msg.TargetEntity.Value), entities);
|
||||
TemperatureLabel.Text = float.IsNaN(msg.Temperature) ? Loc.GetString("health-analyzer-window-no-data") : $"{msg.Temperature - 273f:F1} \u00B0C";
|
||||
BloodLevelLabel.Text = float.IsNaN(msg.BloodLevel) ? Loc.GetString("health-analyzer-window-no-data") : $"{msg.BloodLevel * 100:F1} %";
|
||||
TotalDamageLabel.Text = damageable.TotalDamage.ToString();
|
||||
|
||||
NoPatientDataText.Visible = false;
|
||||
entities.TryGetComponent<MobStateComponent>(entities.GetEntity(msg.TargetEntity), out var mobStateComponent);
|
||||
|
||||
string entityName = Loc.GetString("health-analyzer-window-entity-unknown-text");
|
||||
if (_entityManager.HasComponent<MetaDataComponent>(target.Value))
|
||||
{
|
||||
entityName = Identity.Name(target.Value, _entityManager);
|
||||
}
|
||||
|
||||
PatientName.Text = Loc.GetString(
|
||||
"health-analyzer-window-entity-health-text",
|
||||
("entityName", entityName)
|
||||
);
|
||||
|
||||
Temperature.Text = Loc.GetString("health-analyzer-window-entity-temperature-text",
|
||||
("temperature", float.IsNaN(msg.Temperature) ? "N/A" : $"{msg.Temperature - 273f:F1} °C")
|
||||
);
|
||||
|
||||
BloodLevel.Text = Loc.GetString("health-analyzer-window-entity-blood-level-text",
|
||||
("bloodLevel", float.IsNaN(msg.BloodLevel) ? "N/A" : $"{msg.BloodLevel * 100:F1} %")
|
||||
);
|
||||
|
||||
patientDamageAmount.Text = Loc.GetString(
|
||||
"health-analyzer-window-entity-damage-total-text",
|
||||
("amount", damageable.TotalDamage)
|
||||
);
|
||||
|
||||
var damageSortedGroups =
|
||||
damageable.DamagePerGroup.OrderBy(damage => damage.Value)
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
IReadOnlyDictionary<string, FixedPoint2> damagePerType = damageable.Damage.DamageDict;
|
||||
|
||||
DrawDiagnosticGroups(damageSortedGroups, damagePerType);
|
||||
|
||||
SetHeight = AnalyzerHeight;
|
||||
SetWidth = AnalyzerWidth;
|
||||
}
|
||||
|
||||
private void DrawDiagnosticGroups(
|
||||
Dictionary<string, FixedPoint2> groups, IReadOnlyDictionary<string, FixedPoint2> damageDict)
|
||||
{
|
||||
HashSet<string> shownTypes = new();
|
||||
|
||||
// Show the total damage and type breakdown for each damage group.
|
||||
foreach (var (damageGroupId, damageAmount) in groups.Reverse())
|
||||
{
|
||||
if (damageAmount == 0)
|
||||
continue;
|
||||
|
||||
var groupTitleText = $"{Loc.GetString(
|
||||
"health-analyzer-window-damage-group-text",
|
||||
("damageGroup", Loc.GetString("health-analyzer-window-damage-group-" + damageGroupId)),
|
||||
("amount", damageAmount)
|
||||
)}";
|
||||
|
||||
var groupContainer = new BoxContainer
|
||||
AliveStatusLabel.Text = mobStateComponent?.CurrentState switch
|
||||
{
|
||||
Margin = new Thickness(0, 0, 0, 15),
|
||||
Align = BoxContainer.AlignMode.Begin,
|
||||
Orientation = BoxContainer.LayoutOrientation.Vertical,
|
||||
Shared.Mobs.MobState.Alive => Loc.GetString("health-analyzer-window-entity-current-alive-status-alive-text"),
|
||||
Shared.Mobs.MobState.Critical => Loc.GetString("health-analyzer-window-entity-current-alive-status-critical-text"),
|
||||
Shared.Mobs.MobState.Dead => Loc.GetString("health-analyzer-window-entity-current-alive-status-dead-text"),
|
||||
_ => Loc.GetString("health-analyzer-window-no-data"),
|
||||
};
|
||||
|
||||
groupContainer.AddChild(CreateDiagnosticGroupTitle(groupTitleText, damageGroupId, damageAmount.Int()));
|
||||
IReadOnlyDictionary<string, FixedPoint2> damagePerGroup = damageable.DamagePerGroup;
|
||||
IReadOnlyDictionary<string, FixedPoint2> damagePerType = damageable.Damage.DamageDict;
|
||||
|
||||
GroupsContainer.AddChild(groupContainer);
|
||||
DamageGroupsContainer.RemoveAllChildren();
|
||||
|
||||
// Show the damage for each type in that group.
|
||||
var group = _prototypes.Index<DamageGroupPrototype>(damageGroupId);
|
||||
|
||||
foreach (var type in group.DamageTypes)
|
||||
// Show the total damage and type breakdown for each damage group.
|
||||
foreach (var (damageGroupId, damageAmount) in damagePerGroup)
|
||||
{
|
||||
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;
|
||||
var damageGroupTitle = Loc.GetString("health-analyzer-window-damage-group-" + damageGroupId, ("amount", damageAmount));
|
||||
|
||||
shownTypes.Add(type);
|
||||
|
||||
var damageString = Loc.GetString(
|
||||
"health-analyzer-window-damage-type-text",
|
||||
("damageType", Loc.GetString("health-analyzer-window-damage-type-" + type)),
|
||||
("amount", typeAmount)
|
||||
);
|
||||
|
||||
groupContainer.AddChild(CreateDiagnosticItemLabel(damageString.Insert(0, "- ")));
|
||||
}
|
||||
DamageGroupsContainer.AddChild(new GroupDamageCardComponent(damageGroupTitle, damageGroupId, damagePerType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Texture GetTexture(string texture)
|
||||
{
|
||||
var rsiPath = new ResPath("/Textures/Objects/Devices/health_analyzer.rsi");
|
||||
var rsiSprite = new SpriteSpecifier.Rsi(rsiPath, texture);
|
||||
|
||||
var rsi = _cache.GetResource<RSIResource>(rsiSprite.RsiPath).RSI;
|
||||
if (!rsi.TryGetState(rsiSprite.RsiState, out var state))
|
||||
{
|
||||
rsiSprite = new SpriteSpecifier.Rsi(rsiPath, "unknown");
|
||||
}
|
||||
|
||||
return _spriteSystem.Frame0(rsiSprite);
|
||||
}
|
||||
|
||||
private static Label CreateDiagnosticItemLabel(string text)
|
||||
{
|
||||
return new Label
|
||||
{
|
||||
Margin = new Thickness(2, 2),
|
||||
Text = text,
|
||||
};
|
||||
}
|
||||
|
||||
private BoxContainer CreateDiagnosticGroupTitle(string text, string id, int damageAmount)
|
||||
{
|
||||
var rootContainer = new BoxContainer
|
||||
{
|
||||
VerticalAlignment = VAlignment.Bottom,
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal
|
||||
};
|
||||
|
||||
rootContainer.AddChild(new TextureRect
|
||||
{
|
||||
Margin = new Thickness(0, 3),
|
||||
SetSize = new Vector2(30, 30),
|
||||
Texture = GetTexture(id.ToLower())
|
||||
});
|
||||
|
||||
rootContainer.AddChild(CreateDiagnosticItemLabel(text));
|
||||
|
||||
return rootContainer;
|
||||
}
|
||||
}
|
||||
// WD end
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user