2023-09-28 16:20:29 -07:00
|
|
|
using Content.Shared.Access;
|
2023-04-08 13:15:52 -07:00
|
|
|
using Content.Shared.Access.Components;
|
2022-05-21 14:19:02 +10:00
|
|
|
using Content.Shared.Access.Systems;
|
2022-03-28 17:03:03 +13:00
|
|
|
using Content.Shared.Containers.ItemSlots;
|
2022-08-08 22:10:01 -07:00
|
|
|
using Content.Shared.CrewManifest;
|
2020-01-19 18:29:49 +01:00
|
|
|
using Robust.Shared.Prototypes;
|
2023-04-08 13:15:52 -07:00
|
|
|
using static Content.Shared.Access.Components.IdCardConsoleComponent;
|
2023-09-11 21:20:46 +10:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Access.UI
|
2019-09-06 08:12:44 +02:00
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class IdCardConsoleBoundUserInterface : BoundUserInterface
|
2019-09-06 08:12:44 +02:00
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
2023-07-08 09:02:17 -07:00
|
|
|
private readonly SharedIdCardConsoleSystem _idCardConsoleSystem = default!;
|
2020-08-24 14:10:28 +02:00
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
private IdCardConsoleWindow? _window;
|
|
|
|
|
|
|
|
|
|
public IdCardConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
2019-09-06 08:12:44 +02:00
|
|
|
{
|
2023-07-08 09:02:17 -07:00
|
|
|
_idCardConsoleSystem = EntMan.System<SharedIdCardConsoleSystem>();
|
2019-09-06 08:12:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Open()
|
|
|
|
|
{
|
|
|
|
|
base.Open();
|
2023-09-28 16:20:29 -07:00
|
|
|
List<ProtoId<AccessLevelPrototype>> accessLevels;
|
2019-09-06 08:12:44 +02:00
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
if (EntMan.TryGetComponent<IdCardConsoleComponent>(Owner, out var idCard))
|
2022-05-21 14:19:02 +10:00
|
|
|
{
|
|
|
|
|
accessLevels = idCard.AccessLevels;
|
|
|
|
|
accessLevels.Sort();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-09-28 16:20:29 -07:00
|
|
|
accessLevels = new List<ProtoId<AccessLevelPrototype>>();
|
2023-07-08 09:02:17 -07:00
|
|
|
_idCardConsoleSystem.Log.Error($"No IdCardConsole component found for {EntMan.ToPrettyString(Owner)}!");
|
2022-05-21 14:19:02 +10:00
|
|
|
}
|
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
_window = new IdCardConsoleWindow(this, _prototypeManager, accessLevels)
|
|
|
|
|
{
|
|
|
|
|
Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName
|
|
|
|
|
};
|
2022-03-28 17:03:03 +13:00
|
|
|
|
2022-08-08 22:10:01 -07:00
|
|
|
_window.CrewManifestButton.OnPressed += _ => SendMessage(new CrewManifestOpenUiMessage());
|
2022-03-28 17:03:03 +13:00
|
|
|
_window.PrivilegedIdButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(PrivilegedIdCardSlotId));
|
|
|
|
|
_window.TargetIdButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(TargetIdCardSlotId));
|
|
|
|
|
|
2019-09-06 08:12:44 +02:00
|
|
|
_window.OnClose += Close;
|
|
|
|
|
_window.OpenCentered();
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-26 16:37:18 +13:00
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(disposing);
|
2023-07-22 21:19:51 -07:00
|
|
|
if (!disposing)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-11-26 16:37:18 +13:00
|
|
|
_window?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 08:12:44 +02:00
|
|
|
protected override void UpdateState(BoundUserInterfaceState state)
|
|
|
|
|
{
|
|
|
|
|
base.UpdateState(state);
|
|
|
|
|
var castState = (IdCardConsoleBoundUserInterfaceState) state;
|
2021-03-10 14:48:29 +01:00
|
|
|
_window?.UpdateState(castState);
|
2019-09-06 08:12:44 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-16 21:03:23 -07:00
|
|
|
public void SubmitData(string newFullName, string newJobTitle, List<string> newAccessList, string newJobPrototype)
|
2019-09-06 08:12:44 +02:00
|
|
|
{
|
2021-10-24 19:28:25 +11:00
|
|
|
if (newFullName.Length > MaxFullNameLength)
|
|
|
|
|
newFullName = newFullName[..MaxFullNameLength];
|
|
|
|
|
|
|
|
|
|
if (newJobTitle.Length > MaxJobTitleLength)
|
|
|
|
|
newJobTitle = newJobTitle[..MaxJobTitleLength];
|
|
|
|
|
|
2019-09-06 08:12:44 +02:00
|
|
|
SendMessage(new WriteToTargetIdMessage(
|
|
|
|
|
newFullName,
|
|
|
|
|
newJobTitle,
|
2022-08-16 21:03:23 -07:00
|
|
|
newAccessList,
|
|
|
|
|
newJobPrototype));
|
2019-09-06 08:12:44 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|