Skip to content

Commit

Permalink
[Feature] Clicking on Health Alerty Now Displays Health State (#1139)
Browse files Browse the repository at this point in the history
<!--
This is a semi-strict format, you can add/remove sections as needed but
the order/format should be kept the same
Remove these comments before submitting
-->

# Description

I don't understand why it hasn't been done before tbf.


https://github.com/user-attachments/assets/6ea2a3eb-80ce-4905-b546-7b8902308533

---

# Changelog

:cl:
- add: Clicking on health alert now will print message in chat,
displaying your health state.

---------

Signed-off-by: Remuchi <[email protected]>
  • Loading branch information
Remuchi authored Oct 27, 2024
1 parent 67ad09e commit 7c8937a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 11 deletions.
44 changes: 44 additions & 0 deletions Content.Server/Alert/Click/CheckHealth.cs
Original file line number Diff line number Diff line change
@@ -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<IChatManager>();
var entityManager = IoCManager.Resolve<IEntityManager>();
var playerManager = IoCManager.Resolve<IPlayerManager>();

var healthExaminableSystem = entityManager.System<HealthExaminableSystem>();

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);
}
}
23 changes: 13 additions & 10 deletions Content.Shared/HealthExaminable/HealthExaminableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,33 @@ 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<SelfAwareComponent>(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<HealthExaminableComponent> examinable,
DamageableComponent damageable)
{
return examiner == examinable.Owner && TryComp<SelfAwareComponent>(examinable, out var selfAware)
? CreateMarkupSelfAware(examinable, selfAware, examinable.Comp, damageable)
: CreateMarkup(examinable, examinable.Comp, damageable);
}

private FormattedMessage CreateMarkup(EntityUid uid, HealthExaminableComponent component, DamageableComponent damage)
{
var msg = new FormattedMessage();

Expand Down
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Alerts/alerts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
- type: alert
id: HumanHealth
category: Health
onClick: !type:CheckHealth { }
icons:
- sprite: /Textures/Interface/Alerts/human_alive.rsi
state: health0
Expand Down

0 comments on commit 7c8937a

Please sign in to comment.