Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Clicking on Health Alerty Now Displays Health State #1139

Merged
merged 2 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading