From 3be539ba2de6862cd2fdd32ae19975929e12f5e9 Mon Sep 17 00:00:00 2001 From: Remuchi Date: Thu, 24 Oct 2024 13:07:48 +0700 Subject: [PATCH 1/2] feat: clicking on health icon now displays health state Signed-off-by: Remuchi --- Content.Server/Alert/Click/CheckHealth.cs | 44 +++++++++++++++++++ .../HealthExaminableSystem.cs | 24 +++++----- .../health-examinable-comp.ftl | 2 + .../health-examinable-silicon.ftl | 2 +- Resources/Prototypes/Alerts/alerts.yml | 1 + 5 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 Content.Server/Alert/Click/CheckHealth.cs diff --git a/Content.Server/Alert/Click/CheckHealth.cs b/Content.Server/Alert/Click/CheckHealth.cs new file mode 100644 index 00000000000..31beff69c29 --- /dev/null +++ b/Content.Server/Alert/Click/CheckHealth.cs @@ -0,0 +1,44 @@ +using Content.Server.Chat.Managers; +using Content.Shared.Alert; +using Content.Shared.Chat; +using Content.Shared.Damage; +using Content.Shared.HealthExaminable; +using JetBrains.Annotations; +using Robust.Server.Player; +using Robust.Shared.Player; + +namespace Content.Server.Alert.Click; + +[UsedImplicitly] +[DataDefinition] +public sealed partial class CheckHealth : IAlertClick +{ + public void AlertClicked(EntityUid player) + { + var chatManager = IoCManager.Resolve(); + var entityManager = IoCManager.Resolve(); + var playerManager = IoCManager.Resolve(); + + var healthExaminableSystem = entityManager.System(); + + if (!entityManager.TryGetComponent(player, out HealthExaminableComponent? healthExaminable) || + !entityManager.TryGetComponent(player, out DamageableComponent? damageable) || + !playerManager.TryGetSessionByEntity(player, out var session)) + return; + + var baseMsg = Loc.GetString("health-alert-start"); + SendMessage(chatManager, baseMsg, session); + var markup = healthExaminableSystem.GetMarkup(player, (player, healthExaminable), damageable).ToMarkup(); + SendMessage(chatManager, markup, session); + } + + private static void SendMessage(IChatManager chatManager, string msg, ICommonSession session) + { + chatManager.ChatMessageToOne(ChatChannel.Emotes, + msg, + msg, + EntityUid.Invalid, + false, + session.Channel); + } +} diff --git a/Content.Shared/HealthExaminable/HealthExaminableSystem.cs b/Content.Shared/HealthExaminable/HealthExaminableSystem.cs index 39addfc9410..1c08ceda96c 100644 --- a/Content.Shared/HealthExaminable/HealthExaminableSystem.cs +++ b/Content.Shared/HealthExaminable/HealthExaminableSystem.cs @@ -30,30 +30,34 @@ private void OnGetExamineVerbs(EntityUid uid, HealthExaminableComponent componen var detailsRange = _examineSystem.IsInDetailsRange(args.User, uid); - var verb = new ExamineVerb() + var verb = new ExamineVerb { Act = () => { - FormattedMessage markup; - if (uid == args.User - && TryComp(uid, out var selfAware)) - markup = CreateMarkupSelfAware(uid, selfAware, component, damage); - else - markup = CreateMarkup(uid, component, damage); - + var markup = GetMarkup(args.User, (uid, component), damage); _examineSystem.SendExamineTooltip(args.User, uid, markup, false, false); }, Text = Loc.GetString("health-examinable-verb-text"), Category = VerbCategory.Examine, Disabled = !detailsRange, Message = detailsRange ? null : Loc.GetString("health-examinable-verb-disabled"), - Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/rejuvenate.svg.192dpi.png")) + Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/VerbIcons/rejuvenate.svg.192dpi.png")) }; args.Verbs.Add(verb); } - public FormattedMessage CreateMarkup(EntityUid uid, HealthExaminableComponent component, DamageableComponent damage) + public FormattedMessage GetMarkup(EntityUid examiner, + Entity examinable, + DamageableComponent damageable) + { + if (examiner == examinable.Owner && TryComp(examinable, out var selfAware)) + return CreateMarkupSelfAware(examinable, selfAware, examinable.Comp, damageable); + + return CreateMarkup(examinable, examinable.Comp, damageable); + } + + private FormattedMessage CreateMarkup(EntityUid uid, HealthExaminableComponent component, DamageableComponent damage) { var msg = new FormattedMessage(); diff --git a/Resources/Locale/en-US/health-examinable/health-examinable-comp.ftl b/Resources/Locale/en-US/health-examinable/health-examinable-comp.ftl index af31837ab84..60204eb2bd3 100644 --- a/Resources/Locale/en-US/health-examinable/health-examinable-comp.ftl +++ b/Resources/Locale/en-US/health-examinable/health-examinable-comp.ftl @@ -1,2 +1,4 @@ health-examinable-verb-text = Health health-examinable-verb-disabled = Perform a basic health examination in close range. + +health-alert-start = [font size=12][color=green]Health:[/color][/font] diff --git a/Resources/Locale/en-US/health-examinable/health-examinable-silicon.ftl b/Resources/Locale/en-US/health-examinable/health-examinable-silicon.ftl index 03eaf07a3b7..1608d8511d1 100644 --- a/Resources/Locale/en-US/health-examinable/health-examinable-silicon.ftl +++ b/Resources/Locale/en-US/health-examinable/health-examinable-silicon.ftl @@ -1,4 +1,4 @@ -health-examinable-silicon-none = There is no obvious damage to be seen. +health-examinable-silicon-none = [color=green]There is no obvious damage to be seen.[/color] health-examinable-silicon-Blunt-25 = [color=red]{ CAPITALIZE(SUBJECT($target)) } { CONJUGATE-HAVE($target) } minor dents on { POSS-ADJ($target) } chassis.[/color] health-examinable-silicon-Blunt-50 = [color=crimson]{ CAPITALIZE(POSS-ADJ($target)) } chassis is severely dented![/color] diff --git a/Resources/Prototypes/Alerts/alerts.yml b/Resources/Prototypes/Alerts/alerts.yml index bb0c47f48fb..e32eea3cc93 100644 --- a/Resources/Prototypes/Alerts/alerts.yml +++ b/Resources/Prototypes/Alerts/alerts.yml @@ -192,6 +192,7 @@ - type: alert id: HumanHealth category: Health + onClick: !type:CheckHealth { } icons: - sprite: /Textures/Interface/Alerts/human_alive.rsi state: health0 From 9c0b0b96ab7bee6f2930301c944ea7e3a2f78b28 Mon Sep 17 00:00:00 2001 From: Remuchi Date: Sat, 26 Oct 2024 13:26:02 +0700 Subject: [PATCH 2/2] review fixes Signed-off-by: Remuchi --- Content.Shared/HealthExaminable/HealthExaminableSystem.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Content.Shared/HealthExaminable/HealthExaminableSystem.cs b/Content.Shared/HealthExaminable/HealthExaminableSystem.cs index 1c08ceda96c..091176a3cb1 100644 --- a/Content.Shared/HealthExaminable/HealthExaminableSystem.cs +++ b/Content.Shared/HealthExaminable/HealthExaminableSystem.cs @@ -51,10 +51,9 @@ public FormattedMessage GetMarkup(EntityUid examiner, Entity examinable, DamageableComponent damageable) { - if (examiner == examinable.Owner && TryComp(examinable, out var selfAware)) - return CreateMarkupSelfAware(examinable, selfAware, examinable.Comp, damageable); - - return CreateMarkup(examinable, examinable.Comp, damageable); + return examiner == examinable.Owner && TryComp(examinable, out var selfAware) + ? CreateMarkupSelfAware(examinable, selfAware, examinable.Comp, damageable) + : CreateMarkup(examinable, examinable.Comp, damageable); } private FormattedMessage CreateMarkup(EntityUid uid, HealthExaminableComponent component, DamageableComponent damage)