CatStation/Content.Client/CharacterInfo/CharacterInfoSystem.cs
Oleksandr 1c680180a9
Fix highlights don't work for other languages (#41062)
* Update base system

* Update highlights.ftl

* Update highlights.ftl

* Fix some mistakes

* Fix lawyer and libriab hightlight... Arghhg

* Change string jobId to JobPrototype. Remove JobName from CharacterData

* Fix to use ProtoId<JobPrototype>

* Fixes for qrwas!

* fix using

* fix integration tests

* Update ChatHighlightTest.cs

---------

Co-authored-by: SlamBamActionman <slambamactionman@gmail.com>
2026-07-30 14:57:59 +00:00

67 lines
1.9 KiB
C#

using Content.Shared.CharacterInfo;
using Content.Shared.Objectives;
using Content.Shared.Roles;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
namespace Content.Client.CharacterInfo;
public sealed partial class CharacterInfoSystem : EntitySystem
{
[Dependency] private IPlayerManager _players = default!;
public event Action<CharacterData>? OnCharacterUpdate;
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<CharacterInfoEvent>(OnCharacterInfoEvent);
}
public void RequestCharacterInfo()
{
var entity = _players.LocalEntity;
if (entity == null)
{
return;
}
RaiseNetworkEvent(new RequestCharacterInfoEvent(GetNetEntity(entity.Value)));
}
private void OnCharacterInfoEvent(CharacterInfoEvent msg, EntitySessionEventArgs args)
{
var entity = GetEntity(msg.NetEntity);
var data = new CharacterData(entity, msg.Objectives, msg.Briefing, msg.Job, Name(entity));
OnCharacterUpdate?.Invoke(data);
}
public List<Control> GetCharacterInfoControls(EntityUid uid)
{
var ev = new GetCharacterInfoControlsEvent(uid);
RaiseLocalEvent(uid, ref ev, true);
return ev.Controls;
}
public readonly record struct CharacterData(
EntityUid Entity,
Dictionary<string, List<ObjectiveInfo>> Objectives,
string? Briefing,
ProtoId<JobPrototype>? JobId,
string EntityName
);
/// <summary>
/// Event raised to get additional controls to display in the character info menu.
/// </summary>
[ByRefEvent]
public readonly record struct GetCharacterInfoControlsEvent(EntityUid Entity)
{
public readonly List<Control> Controls = new();
public readonly EntityUid Entity = Entity;
}
}