Files
OldThink/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs
ThereDrD0 cb37ba5714 QoL для ХоПа (#369)
* add: nice job icons ui for HoP console

* Ebanniy rot

* add: Changing id visuals with HoP console

* cleanup

* add: remove drop down list and replace it with icon-buttons

* add: colored and sorted by department buttons

* add: columns

* tweak: nicer colors

* cleanup
2024-06-20 22:29:26 +03:00

91 lines
3.1 KiB
C#

using Content.Shared.Access;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.CrewManifest;
using Robust.Shared.Prototypes;
using static Content.Shared.Access.Components.IdCardConsoleComponent;
namespace Content.Client.Access.UI
{
public sealed class IdCardConsoleBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private readonly SharedIdCardConsoleSystem _idCardConsoleSystem = default!;
private IdCardConsoleWindow? _window;
public IdCardConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
_idCardConsoleSystem = EntMan.System<SharedIdCardConsoleSystem>();
}
protected override void Open()
{
base.Open();
List<List<ProtoId<AccessLevelPrototype>>> accessLevels;
if (EntMan.TryGetComponent<IdCardConsoleComponent>(Owner, out var idCard))
{
accessLevels = idCard.AccessLevelsConsole;
}
else
{
accessLevels = new List<List<ProtoId<AccessLevelPrototype>>>();
_idCardConsoleSystem.Log.Error($"No IdCardConsole component found for {EntMan.ToPrettyString(Owner)}!");
}
_window = new IdCardConsoleWindow(this, _prototypeManager, accessLevels)
{
Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName
};
_window.CrewManifestButton.OnPressed += _ => SendMessage(new CrewManifestOpenUiMessage());
_window.PrivilegedIdButton.OnPressed +=
_ => SendMessage(new ItemSlotButtonPressedEvent(PrivilegedIdCardSlotId));
_window.TargetIdButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(TargetIdCardSlotId));
_window.OnClose += Close;
_window.OpenCentered();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_window?.Dispose();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
var castState = (IdCardConsoleBoundUserInterfaceState) state;
_window?.UpdateState(castState);
}
public void SubmitData(
string newFullName,
string newJobTitle,
List<ProtoId<AccessLevelPrototype>> newAccessList,
string newJobPrototype,
string? newJobIcon)
{
if (newFullName.Length > MaxFullNameLength)
newFullName = newFullName[..MaxFullNameLength];
if (newJobTitle.Length > MaxJobTitleLength)
newJobTitle = newJobTitle[..MaxJobTitleLength];
SendMessage(new WriteToTargetIdMessage(
newFullName,
newJobTitle,
newAccessList,
newJobPrototype,
newJobIcon));
}
}
}