* Use new Subs.CVar helper Removes manual config OnValueChanged calls, removes need to remember to manually unsubscribe. This both reduces boilerplate and fixes many issues where subscriptions weren't removed on entity system shutdown. * Fix a bunch of warnings * More warning fixes * Use new DateTime serializer to get rid of ISerializationHooks in changelog code. * Get rid of some more ISerializationHooks for enums * And a little more * Apply suggestions from code review Co-authored-by: 0x6273 <0x40@keemail.me> --------- Co-authored-by: 0x6273 <0x40@keemail.me>
66 lines
1.8 KiB
C#
66 lines
1.8 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)
|
|
{
|
|
var entity = GetEntity(msg.NetEntity);
|
|
var data = new CharacterData(entity, msg.JobTitle, msg.Objectives, msg.Briefing, 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,
|
|
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;
|
|
}
|
|
}
|