[Fix]: Исправлено отображение урона в УИ анализатора здоровья (#77)

* fix: возвращено отображение урона в сканере здоровья

* add: сканер здоровья только те группы, где есть урон
This commit is contained in:
Remuchi
2024-02-16 01:08:30 +07:00
committed by GitHub
parent 93ec93b5c9
commit fe82255139
3 changed files with 108 additions and 83 deletions

View File

@@ -23,21 +23,34 @@ namespace Content.Client.HealthAnalyzer.UI
{ {
var entities = IoCManager.Resolve<IEntityManager>(); var entities = IoCManager.Resolve<IEntityManager>();
if (msg.TargetEntity != null && if (msg.TargetEntity == null || !entities.TryGetComponent(entities.GetEntity(msg.TargetEntity),
entities.TryGetComponent<DamageableComponent>(entities.GetEntity(msg.TargetEntity), out var damageable)) out DamageableComponent? damageable))
{ {
return;
}
EntityNameLabel.Text = Identity.Name(entities.GetEntity(msg.TargetEntity.Value), entities); 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"; TemperatureLabel.Text = float.IsNaN(msg.Temperature)
BloodLevelLabel.Text = float.IsNaN(msg.BloodLevel) ? Loc.GetString("health-analyzer-window-no-data") : $"{msg.BloodLevel * 100:F1} %"; ? 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(); TotalDamageLabel.Text = damageable.TotalDamage.ToString();
entities.TryGetComponent<MobStateComponent>(entities.GetEntity(msg.TargetEntity), out var mobStateComponent); entities.TryGetComponent<MobStateComponent>(entities.GetEntity(msg.TargetEntity),
out var mobStateComponent);
AliveStatusLabel.Text = mobStateComponent?.CurrentState switch AliveStatusLabel.Text = mobStateComponent?.CurrentState switch
{ {
Shared.Mobs.MobState.Alive => Loc.GetString("health-analyzer-window-entity-current-alive-status-alive-text"), Shared.Mobs.MobState.Alive => Loc.GetString(
Shared.Mobs.MobState.Critical => Loc.GetString("health-analyzer-window-entity-current-alive-status-critical-text"), "health-analyzer-window-entity-current-alive-status-alive-text"),
Shared.Mobs.MobState.Dead => Loc.GetString("health-analyzer-window-entity-current-alive-status-dead-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"), _ => Loc.GetString("health-analyzer-window-no-data"),
}; };
@@ -49,10 +62,16 @@ namespace Content.Client.HealthAnalyzer.UI
// Show the total damage and type breakdown for each damage group. // Show the total damage and type breakdown for each damage group.
foreach (var (damageGroupId, damageAmount) in damagePerGroup) foreach (var (damageGroupId, damageAmount) in damagePerGroup)
{ {
var damageGroupTitle = Loc.GetString("health-analyzer-window-damage-group-" + damageGroupId, ("amount", damageAmount)); if (damageAmount == 0)
{
DamageGroupsContainer.AddChild(new GroupDamageCardComponent(damageGroupTitle, damageGroupId, damagePerType)); continue;
} }
var damageGroupTitle = Loc.GetString("health-analyzer-window-damage-group-" + damageGroupId,
("amount", damageAmount));
DamageGroupsContainer.AddChild(new GroupDamageCardComponent(damageGroupTitle, damageGroupId,
damagePerType));
} }
} }
} }

View File

@@ -11,7 +11,7 @@ namespace Content.Client._White.Medical.BodyScanner
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class GroupDamageCardComponent : Control public sealed partial class GroupDamageCardComponent : Control
{ {
public GroupDamageCardComponent(string title, string damageGroupID, IReadOnlyDictionary<string, FixedPoint2> damagePerType) public GroupDamageCardComponent(string title, string damageGroupId, IReadOnlyDictionary<string, FixedPoint2> damagePerType)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
@@ -19,17 +19,26 @@ namespace Content.Client._White.Medical.BodyScanner
HashSet<string> shownTypes = new(); HashSet<string> shownTypes = new();
var protos = IoCManager.Resolve<IPrototypeManager>(); var protos = IoCManager.Resolve<IPrototypeManager>();
var group = protos.Index<DamageGroupPrototype>(damageGroupID); var group = protos.Index<DamageGroupPrototype>(damageGroupId);
// Show the damage for each type in that group. // Show the damage for each type in that group.
foreach (var type in group.DamageTypes) foreach (var type in group.DamageTypes)
{ {
if (damagePerType.TryGetValue(type, out var typeAmount)) if (!damagePerType.TryGetValue(type, out var typeAmount))
{ {
continue;
}
if (typeAmount == 0)
{
continue;
}
// If damage types are allowed to belong to more than one damage group, they may appear twice here. Mark them as duplicate. // 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)) if (!shownTypes.Add(type))
{ {
shownTypes.Add(type); continue;
}
Label damagePerTypeLabel = new() Label damagePerTypeLabel = new()
{ {
@@ -41,43 +50,40 @@ namespace Content.Client._White.Medical.BodyScanner
DamageLabelsContainer.AddChild(damagePerTypeLabel); DamageLabelsContainer.AddChild(damagePerTypeLabel);
} }
} }
}
}
/// <summary> /// <summary>
/// Sets the color of a label depending on the damage. /// Sets the color of a label depending on the damage.
/// </summary> /// </summary>
/// <param name="label"></param> /// <param name="label"></param>
/// <param name="damage"></param> /// <param name="damage"></param>
private void SetColorLabel(Label label, float damage) private static void SetColorLabel(Label label, float damage)
{ {
var startColor = Color.White; var startColor = Color.White;
var critColor = Color.Yellow; var critColor = Color.Yellow;
var endColor = Color.Red; var endColor = Color.Red;
var startDamage = 0f; const float startDamage = 0f;
var critDamage = 30f; const float critDamage = 30f;
var endDamage = 100f; const float endDamage = 100f;
if (damage <= startDamage) switch (damage)
{ {
case <= startDamage:
label.FontColorOverride = startColor; label.FontColorOverride = startColor;
} break;
else if (damage >= endDamage) case >= endDamage:
{
label.FontColorOverride = endColor; label.FontColorOverride = endColor;
} break;
else if (damage >= startDamage && damage <= critDamage) case >= startDamage and <= critDamage:
{
// We need a number from 0 to 100. // We need a number from 0 to 100.
damage *= 100f / (critDamage - startDamage); damage *= 100f / (critDamage - startDamage);
label.FontColorOverride = GetColorLerp(startColor, critColor, damage); label.FontColorOverride = GetColorLerp(startColor, critColor, damage);
} break;
else if (damage >= critDamage && damage <= endDamage) case >= critDamage and <= endDamage:
{
// We need a number from 0 to 100. // We need a number from 0 to 100.
damage *= 100f / (endDamage - critDamage); damage *= 100f / (endDamage - critDamage);
label.FontColorOverride = GetColorLerp(critColor, endColor, damage); label.FontColorOverride = GetColorLerp(critColor, endColor, damage);
break;
} }
} }
@@ -88,7 +94,7 @@ namespace Content.Client._White.Medical.BodyScanner
/// <param name="endColor"></param> /// <param name="endColor"></param>
/// <param name="percentage"></param> /// <param name="percentage"></param>
/// <returns></returns> /// <returns></returns>
private Color GetColorLerp(Color startColor, Color endColor, float percentage) private static Color GetColorLerp(Color startColor, Color endColor, float percentage)
{ {
var t = percentage / 100f; var t = percentage / 100f;
var r = MathHelper.Lerp(startColor.R, endColor.R, t); var r = MathHelper.Lerp(startColor.R, endColor.R, t);

View File

@@ -11,27 +11,27 @@ 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} (дубликат) health-analyzer-window-damage-type-duplicate-text = {$damageType}: {$amount} (дубликат)
health-analyzer-window-damage-group-Brute = Механические health-analyzer-window-damage-group-Brute = Механические: {$amount}
health-analyzer-window-damage-type-Blunt = Удары health-analyzer-window-damage-type-Blunt = Удары: {$amount}
health-analyzer-window-damage-type-Slash = Разрезы health-analyzer-window-damage-type-Slash = Разрезы: {$amount}
health-analyzer-window-damage-type-Piercing = Уколы health-analyzer-window-damage-type-Piercing = Уколы: {$amount}
health-analyzer-window-damage-group-Burn = Ожоги health-analyzer-window-damage-group-Burn = Ожоги: {$amount}
health-analyzer-window-damage-type-Heat = Термические health-analyzer-window-damage-type-Heat = Термические: {$amount}
health-analyzer-window-damage-type-Laser = Лазерный health-analyzer-window-damage-type-Laser = Лазерный: {$amount}
health-analyzer-window-damage-type-Shock = Электрические health-analyzer-window-damage-type-Shock = Электрические: {$amount}
health-analyzer-window-damage-type-Cold = Обморожение health-analyzer-window-damage-type-Cold = Обморожение: {$amount}
health-analyzer-window-damage-type-Caustic = Кислотные health-analyzer-window-damage-type-Caustic = Кислотные: {$amount}
health-analyzer-window-damage-group-Airloss = Нехватка воздуха health-analyzer-window-damage-group-Airloss = Нехватка воздуха: {$amount}
health-analyzer-window-damage-type-Asphyxiation = Удушение health-analyzer-window-damage-type-Asphyxiation = Удушение: {$amount}
health-analyzer-window-damage-type-Bloodloss = Кровопотеря health-analyzer-window-damage-type-Bloodloss = Кровопотеря: {$amount}
health-analyzer-window-damage-group-Toxin = Токсины health-analyzer-window-damage-group-Toxin = Токсины: {$amount}
health-analyzer-window-damage-type-Poison = Яды health-analyzer-window-damage-type-Poison = Яды: {$amount}
health-analyzer-window-damage-type-Radiation = Радиация health-analyzer-window-damage-type-Radiation = Радиация: {$amount}
health-analyzer-window-damage-group-Genetic = Генетические health-analyzer-window-damage-group-Genetic = Генетические: {$amount}
health-analyzer-window-damage-type-Cellular = Клеточные health-analyzer-window-damage-type-Cellular = Клеточные: {$amount}
health-analyzer-window-malnutrition = Тяжёлое недоедание health-analyzer-window-malnutrition = Тяжёлое недоедание