using System.Linq; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; using Robust.Shared.Prototypes; using Content.Shared.Access; using Content.Shared.Access.Systems; namespace Content.Client.Access.UI; [GenerateTypedNameReferences] public sealed partial class AccessLevelControl : GridContainer { public readonly Dictionary, Button> ButtonsList = new(); public readonly List, Button>> ButtonGroups = new (); public AccessLevelControl() { RobustXamlLoader.Load(this); } public void Populate(List> accessLevels, IPrototypeManager prototypeManager) { foreach (var access in accessLevels) { if (!prototypeManager.TryIndex(access, out var accessLevel)) { Logger.Error($"Unable to find accesslevel for {access}"); continue; } var newButton = new Button { Text = accessLevel.GetAccessLevelName(), ToggleMode = true, }; AddChild(newButton); ButtonsList.Add(accessLevel.ID, newButton); } } public void PopulateForConsole(List>> accessLevels, IPrototypeManager prototypeManager) { var departmentColors = new List // Colors from StyleNano.cs { "ButtonColorCommandDepartment", "ButtonColorSecurityDepartment", "ButtonColorMedicalDepartment", "ButtonColorEngineeringDepartment", "ButtonColorScienceDepartment", "ButtonColorCargoDepartment", "ButtonColorCivilianDepartment" }; var currentColorIndex = 0; foreach (var department in accessLevels) { Dictionary, Button> buttons = new(); foreach (var access in department) { if (!prototypeManager.TryIndex(access, out var accessLevel)) { Logger.Error($"Unable to find accesslevel for {access}"); continue; } var newButton = new Button { Text = accessLevel.GetAccessLevelName(), ToggleMode = true, }; newButton.AddStyleClass(departmentColors[currentColorIndex]); buttons.Add(accessLevel.ID, newButton); } ButtonGroups.Add(buttons); currentColorIndex++; } } public void UpdateStateConsole( List> pressedList, List>? enabledList = null) { foreach (var department in ButtonGroups) { foreach (var (accessName, button) in department) { button.Pressed = pressedList.Contains(accessName); button.Disabled = !(enabledList?.Contains(accessName) ?? true); } } } public void UpdateState( List> pressedList, List>? enabledList = null) { foreach (var (accessName, button) in ButtonsList) { button.Pressed = pressedList.Contains(accessName); button.Disabled = !(enabledList?.Contains(accessName) ?? true); } } }