CharacterInfoSystem.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Content.Shared.CharacterInfo;
  2. using Content.Shared.Objectives;
  3. using Robust.Client.Player;
  4. using Robust.Client.UserInterface;
  5. namespace Content.Client.CharacterInfo;
  6. public sealed class CharacterInfoSystem : EntitySystem
  7. {
  8. [Dependency] private readonly IPlayerManager _players = default!;
  9. public event Action<CharacterData>? OnCharacterUpdate;
  10. public override void Initialize()
  11. {
  12. base.Initialize();
  13. SubscribeNetworkEvent<CharacterInfoEvent>(OnCharacterInfoEvent);
  14. }
  15. public void RequestCharacterInfo()
  16. {
  17. var entity = _players.LocalEntity;
  18. if (entity == null)
  19. {
  20. return;
  21. }
  22. RaiseNetworkEvent(new RequestCharacterInfoEvent(GetNetEntity(entity.Value)));
  23. }
  24. private void OnCharacterInfoEvent(CharacterInfoEvent msg, EntitySessionEventArgs args)
  25. {
  26. var entity = GetEntity(msg.NetEntity);
  27. var data = new CharacterData(entity, msg.JobTitle, msg.Objectives, msg.Briefing, Name(entity));
  28. OnCharacterUpdate?.Invoke(data);
  29. }
  30. public List<Control> GetCharacterInfoControls(EntityUid uid)
  31. {
  32. var ev = new GetCharacterInfoControlsEvent(uid);
  33. RaiseLocalEvent(uid, ref ev, true);
  34. return ev.Controls;
  35. }
  36. public readonly record struct CharacterData(
  37. EntityUid Entity,
  38. string Job,
  39. Dictionary<string, List<ObjectiveInfo>> Objectives,
  40. string? Briefing,
  41. string EntityName
  42. );
  43. /// <summary>
  44. /// Event raised to get additional controls to display in the character info menu.
  45. /// </summary>
  46. [ByRefEvent]
  47. public readonly record struct GetCharacterInfoControlsEvent(EntityUid Entity)
  48. {
  49. public readonly List<Control> Controls = new();
  50. public readonly EntityUid Entity = Entity;
  51. }
  52. }