Store what access levels are available on the IDCard console (#8259)
Might be better as an accessgroup instead? LMK
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
using Content.Shared.Access.Components;
|
||||
|
||||
namespace Content.Client.Access.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class IdCardConsoleComponent : SharedIdCardConsoleComponent {}
|
||||
@@ -1,3 +1,5 @@
|
||||
using Content.Client.Access.Components;
|
||||
using Content.Shared.Access.Systems;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -19,8 +21,20 @@ namespace Content.Client.Access.UI
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
List<string> accessLevels;
|
||||
|
||||
_window = new IdCardConsoleWindow(this, _prototypeManager) {Title = _entityManager.GetComponent<MetaDataComponent>(Owner.Owner).EntityName};
|
||||
if (_entityManager.TryGetComponent<IdCardConsoleComponent>(Owner.Owner, out var idCard))
|
||||
{
|
||||
accessLevels = idCard.AccessLevels;
|
||||
accessLevels.Sort();
|
||||
}
|
||||
else
|
||||
{
|
||||
accessLevels = new List<string>();
|
||||
Logger.ErrorS(SharedIdCardConsoleSystem.Sawmill, $"No IdCardConsole component found for {_entityManager.ToPrettyString(Owner.Owner)}!");
|
||||
}
|
||||
|
||||
_window = new IdCardConsoleWindow(this, _prototypeManager, accessLevels) {Title = _entityManager.GetComponent<MetaDataComponent>(Owner.Owner).EntityName};
|
||||
|
||||
_window.PrivilegedIdButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(PrivilegedIdCardSlotId));
|
||||
_window.TargetIdButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(TargetIdCardSlotId));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.Access;
|
||||
using Content.Shared.Access.Systems;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
@@ -22,7 +23,7 @@ namespace Content.Client.Access.UI
|
||||
private string? _lastFullName;
|
||||
private string? _lastJobTitle;
|
||||
|
||||
public IdCardConsoleWindow(IdCardConsoleBoundUserInterface owner, IPrototypeManager prototypeManager)
|
||||
public IdCardConsoleWindow(IdCardConsoleBoundUserInterface owner, IPrototypeManager prototypeManager, List<string> accessLevels)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
@@ -42,8 +43,14 @@ namespace Content.Client.Access.UI
|
||||
};
|
||||
JobTitleSaveButton.OnPressed += _ => SubmitData();
|
||||
|
||||
foreach (var accessLevel in prototypeManager.EnumeratePrototypes<AccessLevelPrototype>())
|
||||
foreach (var access in accessLevels)
|
||||
{
|
||||
if (!prototypeManager.TryIndex<AccessLevelPrototype>(access, out var accessLevel))
|
||||
{
|
||||
Logger.ErrorS(SharedIdCardConsoleSystem.Sawmill, $"Unable to find accesslevel for {access}");
|
||||
continue;
|
||||
}
|
||||
|
||||
var newButton = new Button
|
||||
{
|
||||
Text = accessLevel.Name,
|
||||
|
||||
@@ -57,7 +57,6 @@ namespace Content.Client.Entry
|
||||
"ResearchServer",
|
||||
"ResearchPointSource",
|
||||
"ResearchClient",
|
||||
"IdCardConsole",
|
||||
"MimePowers",
|
||||
"Polymorphable",
|
||||
"PolymorphedEntity",
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Access.Systems;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.Access;
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Access.Systems;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Access.Components
|
||||
{
|
||||
@@ -13,7 +11,6 @@ namespace Content.Server.Access.Components
|
||||
[ComponentReference(typeof(SharedIdCardConsoleComponent))]
|
||||
public sealed class IdCardConsoleComponent : SharedIdCardConsoleComponent
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(IdCardConsoleUiKey.Key);
|
||||
@@ -75,7 +72,7 @@ namespace Content.Server.Access.Components
|
||||
cardSystem.TryChangeFullName(targetIdEntity, newFullName);
|
||||
cardSystem.TryChangeJobTitle(targetIdEntity, newJobTitle);
|
||||
|
||||
if (!newAccessList.TrueForAll(x => _prototypeManager.HasIndex<AccessLevelPrototype>(x)))
|
||||
if (!newAccessList.TrueForAll(x => AccessLevels.Contains(x)))
|
||||
{
|
||||
Logger.Warning("Tried to write unknown access tag.");
|
||||
return;
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
|
||||
namespace Content.Shared.Access.Components
|
||||
{
|
||||
[NetworkedComponent]
|
||||
public abstract class SharedIdCardConsoleComponent : Component
|
||||
{
|
||||
public const int MaxFullNameLength = 256;
|
||||
@@ -32,6 +35,42 @@ namespace Content.Shared.Access.Components
|
||||
}
|
||||
}
|
||||
|
||||
// Put this on shared so we just send the state once in PVS range rather than every time the UI updates.
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("accessLevels", customTypeSerializer: typeof(PrototypeIdListSerializer<AccessLevelPrototype>))]
|
||||
public List<string> AccessLevels = new()
|
||||
{
|
||||
"Armory",
|
||||
"Atmospherics",
|
||||
"Bar",
|
||||
"Brig",
|
||||
// "Detective",
|
||||
"Captain",
|
||||
"Cargo",
|
||||
"Chapel",
|
||||
"Chemistry",
|
||||
"ChiefEngineer",
|
||||
"ChiefMedicalOfficer",
|
||||
"Command",
|
||||
"Engineering",
|
||||
"External",
|
||||
"HeadOfPersonnel",
|
||||
"HeadOfSecurity",
|
||||
"Hydroponics",
|
||||
"Janitor",
|
||||
"Kitchen",
|
||||
"Maintenance",
|
||||
"Medical",
|
||||
"Quartermaster",
|
||||
"Research",
|
||||
"ResearchDirector",
|
||||
"Salvage",
|
||||
"Security",
|
||||
"Service",
|
||||
"Theatre",
|
||||
};
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class IdCardConsoleBoundUserInterfaceState : BoundUserInterfaceState
|
||||
{
|
||||
@@ -49,7 +88,9 @@ namespace Content.Shared.Access.Components
|
||||
bool isTargetIdPresent,
|
||||
string? targetIdFullName,
|
||||
string? targetIdJobTitle,
|
||||
string[]? targetIdAccessList, string privilegedIdName, string targetIdName)
|
||||
string[]? targetIdAccessList,
|
||||
string privilegedIdName,
|
||||
string targetIdName)
|
||||
{
|
||||
IsPrivilegedIdPresent = isPrivilegedIdPresent;
|
||||
IsPrivilegedIdAuthorized = isPrivilegedIdAuthorized;
|
||||
@@ -63,7 +104,7 @@ namespace Content.Shared.Access.Components
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum IdCardConsoleUiKey
|
||||
public enum IdCardConsoleUiKey : byte
|
||||
{
|
||||
Key,
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Access.Systems
|
||||
{
|
||||
@@ -9,12 +11,27 @@ namespace Content.Shared.Access.Systems
|
||||
{
|
||||
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
|
||||
|
||||
public const string Sawmill = "idconsole";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SharedIdCardConsoleComponent, ComponentInit>(OnComponentInit);
|
||||
SubscribeLocalEvent<SharedIdCardConsoleComponent, ComponentRemove>(OnComponentRemove);
|
||||
SubscribeLocalEvent<SharedIdCardConsoleComponent, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<SharedIdCardConsoleComponent, ComponentHandleState>(OnHandleState);
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, SharedIdCardConsoleComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not IdCardConsoleComponentState state) return;
|
||||
component.AccessLevels = state.AccessLevels;
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, SharedIdCardConsoleComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new IdCardConsoleComponentState(component.AccessLevels);
|
||||
}
|
||||
|
||||
private void OnComponentInit(EntityUid uid, SharedIdCardConsoleComponent component, ComponentInit args)
|
||||
@@ -28,5 +45,16 @@ namespace Content.Shared.Access.Systems
|
||||
_itemSlotsSystem.RemoveItemSlot(uid, component.PrivilegedIdSlot);
|
||||
_itemSlotsSystem.RemoveItemSlot(uid, component.TargetIdSlot);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class IdCardConsoleComponentState : ComponentState
|
||||
{
|
||||
public List<string> AccessLevels;
|
||||
|
||||
public IdCardConsoleComponentState(List<string> accessLevels)
|
||||
{
|
||||
AccessLevels = accessLevels;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user