Files
tbd-station-14/Content.Shared/Damage/Systems/DamageExamineSystem.cs
KrasnoshchekovPavel 3fcbbc0732 Added localization of groups and types: damage, metabolism (#27368)
* Added localization of groups and types: damage, metabolism (displayed in the guide book). The text for the health analyzer, weapon damage inspection is now taken from damage prototypes

* fix damage tests

* fix damage test yml

* fix damage test prototypes

* Update Content.Shared/Damage/Prototypes/DamageGroupPrototype.cs

* Update Content.Shared/Damage/Prototypes/DamageTypePrototype.cs

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2024-04-28 14:48:19 +10:00

79 lines
2.5 KiB
C#

using Content.Shared.Damage.Components;
using Content.Shared.Damage.Events;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Examine;
using Content.Shared.FixedPoint;
using Content.Shared.Verbs;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Shared.Damage.Systems;
public sealed class DamageExamineSystem : EntitySystem
{
[Dependency] private readonly ExamineSystemShared _examine = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DamageExaminableComponent, GetVerbsEvent<ExamineVerb>>(OnGetExamineVerbs);
}
private void OnGetExamineVerbs(EntityUid uid, DamageExaminableComponent component, GetVerbsEvent<ExamineVerb> args)
{
if (!args.CanInteract || !args.CanAccess)
return;
var ev = new DamageExamineEvent(new FormattedMessage(), args.User);
RaiseLocalEvent(uid, ref ev);
if (!ev.Message.IsEmpty)
{
_examine.AddDetailedExamineVerb(args, component, ev.Message,
Loc.GetString("damage-examinable-verb-text"),
"/Textures/Interface/VerbIcons/smite.svg.192dpi.png",
Loc.GetString("damage-examinable-verb-message")
);
}
}
public void AddDamageExamine(FormattedMessage message, DamageSpecifier damageSpecifier, string? type = null)
{
var markup = GetDamageExamine(damageSpecifier, type);
if (!message.IsEmpty)
{
message.PushNewline();
}
message.AddMessage(markup);
}
/// <summary>
/// Retrieves the damage examine values.
/// </summary>
private FormattedMessage GetDamageExamine(DamageSpecifier damageSpecifier, string? type = null)
{
var msg = new FormattedMessage();
if (string.IsNullOrEmpty(type))
{
msg.AddMarkup(Loc.GetString("damage-examine"));
}
else
{
msg.AddMarkup(Loc.GetString("damage-examine-type", ("type", type)));
}
foreach (var damage in damageSpecifier.DamageDict)
{
if (damage.Value != FixedPoint2.Zero)
{
msg.PushNewline();
msg.AddMarkup(Loc.GetString("damage-value", ("type", _prototype.Index<DamageTypePrototype>(damage.Key).LocalizedName), ("amount", damage.Value)));
}
}
return msg;
}
}