Files
Delta-v/Content.Client/CharacterInfo/CharacterInfoSystem.cs
Tobias BergerandV 788d43ad99 Message highlights (#2990)
* Merge pull request impstation/imp-station-14#468 from hivehum/highlight

Add text highlighting

(cherry picked from commit e442cc4bb20fbb4d5b970275c82cc87508e6f687)

* More cleanly separate auto-generated and manual highlights

Edge case that's not handled: Closing and reopening the game drops the list of auto-generated highlights

* Use LocalizedDatasets to make higlight lists for all jobs

* DeltaV-ification

Since the implementation is now fundamentally incompatible
with the (still open) upstream PR, move to our own cvars

* Try to untroll code

* Untroll

* Untroll for real this time

* Fix wrong count in ChatHighlightBorg

* Escape highlights

Depends on space-wizards/RobustToolbox/pull/5688

* add missing using directive

* Fix failing test

* Rename CVars to avoid clash with previous implementation

* Tidy some stuff up

* Show auto highlights

* Remove redundant check

---------

Co-authored-by: V <97265903+formlessnameless@users.noreply.github.com>
2025-04-04 17:18:19 +01:00

68 lines
2.0 KiB
C#

using Content.Shared.CharacterInfo;
using Content.Shared.Objectives;
using Robust.Client.Player;
using Robust.Client.UserInterface;
namespace Content.Client.CharacterInfo;
public sealed class CharacterInfoSystem : EntitySystem
{
[Dependency] private readonly 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)
{
// DeltaV - Refactored to use TryGetEntity instead of GetEntity because of message highlighting which requests character info too soon and I don't know how to delay it properly
if (!TryGetEntity(msg.NetEntity, out var entity))
return;
var data = new CharacterData(entity.Value, msg.JobTitle, msg.Objectives, msg.Briefing, Name(entity.Value));
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,
string Job,
Dictionary<string, List<ObjectiveInfo>> Objectives,
string? Briefing,
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;
}
}