the agent id card interface now remembers the previous fake name and title (#11427)

This commit is contained in:
Mervill
2022-09-22 12:04:01 -07:00
committed by GitHub
parent 7a7bdae08b
commit 365cb96766

View File

@@ -3,7 +3,9 @@ using Content.Server.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Interaction;
using Content.Server.Popups;
using Content.Server.UserInterface;
using Robust.Shared.Player;
using Robust.Server.GameObjects;
namespace Content.Server.Access.Systems
{
@@ -11,15 +13,16 @@ namespace Content.Server.Access.Systems
{
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly IdCardSystem _cardSystem = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AgentIDCardComponent, AfterInteractEvent>(OnAfterInteract);
// BUI
SubscribeLocalEvent<AgentIDCardComponent, AfterActivatableUIOpenEvent>(AfterUIOpen);
SubscribeLocalEvent<AgentIDCardComponent, AgentIDCardNameChangedMessage>(OnNameChanged);
SubscribeLocalEvent<AgentIDCardComponent, AgentIDCardJobChangedMessage> (OnJobChanged);
}
private void OnAfterInteract(EntityUid uid, AgentIDCardComponent component, AfterInteractEvent args)
@@ -47,6 +50,18 @@ namespace Content.Server.Access.Systems
_popupSystem.PopupEntity(Loc.GetString("agent-id-new", ("number", addedLength), ("card", args.Target)), args.Target.Value, Filter.Entities(args.User));
}
private void AfterUIOpen(EntityUid uid, AgentIDCardComponent component, AfterActivatableUIOpenEvent args)
{
if (!_uiSystem.TryGetUi(component.Owner, AgentIDCardUiKey.Key, out var ui))
return;
if (!TryComp<IdCardComponent>(uid, out var idCard))
return;
var state = new AgentIDCardBoundUserInterfaceState(idCard.FullName ?? "", idCard.JobTitle ?? "");
ui.SetState(state, args.Session);
}
private void OnJobChanged(EntityUid uid, AgentIDCardComponent comp, AgentIDCardJobChangedMessage args)
{
if (!TryComp<IdCardComponent>(uid, out var idCard))