DoorElectronicsConfigurationMenu.xaml.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Linq;
  2. using Robust.Client.AutoGenerated;
  3. using Robust.Client.UserInterface.Controls;
  4. using Robust.Client.UserInterface.CustomControls;
  5. using Robust.Client.UserInterface.XAML;
  6. using Robust.Shared.Prototypes;
  7. using Content.Client.Access.UI;
  8. using Content.Client.Doors.Electronics;
  9. using Content.Shared.Access;
  10. using Content.Shared.Doors.Electronics;
  11. using FancyWindow = Content.Client.UserInterface.Controls.FancyWindow;
  12. namespace Content.Client.Doors.Electronics;
  13. [GenerateTypedNameReferences]
  14. public sealed partial class DoorElectronicsConfigurationMenu : FancyWindow
  15. {
  16. private readonly AccessLevelControl _buttonsList = new();
  17. public event Action<List<ProtoId<AccessLevelPrototype>>>? OnAccessChanged;
  18. public DoorElectronicsConfigurationMenu()
  19. {
  20. RobustXamlLoader.Load(this);
  21. AccessLevelControlContainer.AddChild(_buttonsList);
  22. }
  23. public void Reset(IPrototypeManager protoManager, List<ProtoId<AccessLevelPrototype>> accessLevels)
  24. {
  25. _buttonsList.Populate(accessLevels, protoManager);
  26. foreach (var button in _buttonsList.ButtonsList.Values)
  27. {
  28. button.OnPressed += _ => OnAccessChanged?.Invoke(_buttonsList.ButtonsList.Where(x => x.Value.Pressed).Select(x => x.Key).ToList());
  29. }
  30. }
  31. public void UpdateState(DoorElectronicsConfigurationState state)
  32. {
  33. _buttonsList.UpdateState(state.AccessList);
  34. }
  35. }