From 0b95de1efcf7ce551eae2cb59f18652c907ac7b4 Mon Sep 17 00:00:00 2001 From: chavonadelal <156101927+chavonadelal@users.noreply.github.com> Date: Tue, 30 Jul 2024 14:29:32 +0300 Subject: [PATCH] Adding an AccessReader to a particle accelerator with engineering access (#30394) Adding an AccessReader to a particle accelerator --- .../UI/ParticleAcceleratorControlMenu.xaml.cs | 17 ++++++++++++++--- .../Power/Generation/PA/control_box.yml | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Content.Client/ParticleAccelerator/UI/ParticleAcceleratorControlMenu.xaml.cs b/Content.Client/ParticleAccelerator/UI/ParticleAcceleratorControlMenu.xaml.cs index 9c2b51dcae..8b21e7d94b 100644 --- a/Content.Client/ParticleAccelerator/UI/ParticleAcceleratorControlMenu.xaml.cs +++ b/Content.Client/ParticleAccelerator/UI/ParticleAcceleratorControlMenu.xaml.cs @@ -3,6 +3,7 @@ using Content.Client.Message; using Content.Client.Resources; using Content.Client.UserInterface.Controls; using Content.Shared.Singularity.Components; +using Content.Shared.Access.Systems; using Robust.Client.Animations; using Robust.Client.AutoGenerated; using Robust.Client.Graphics; @@ -13,6 +14,7 @@ using Robust.Client.UserInterface.XAML; using Robust.Shared.Noise; using Robust.Shared.Prototypes; using Robust.Shared.Timing; +using Robust.Client.Player; namespace Content.Client.ParticleAccelerator.UI; @@ -21,6 +23,11 @@ public sealed partial class ParticleAcceleratorControlMenu : FancyWindow { [Dependency] private readonly IResourceCache _cache = default!; + [Dependency] private readonly IEntityManager _entityManager = default!; + [Dependency] private readonly IPlayerManager _player = default!; + + private readonly AccessReaderSystem _accessReader; + private readonly FastNoiseLite _drawNoiseGenerator; private readonly Animation _alarmControlAnimation; @@ -44,6 +51,7 @@ public sealed partial class ParticleAcceleratorControlMenu : FancyWindow RobustXamlLoader.Load(this); IoCManager.InjectDependencies(this); + _accessReader = _entityManager.System(); _drawNoiseGenerator = new(); _drawNoiseGenerator.SetFractalType(FastNoiseLite.FractalType.FBm); _drawNoiseGenerator.SetFrequency(0.5f); @@ -150,7 +158,7 @@ public sealed partial class ParticleAcceleratorControlMenu : FancyWindow private bool StrengthSpinBoxValid(int n) { - return n >= 0 && n <= _maxStrength ; + return n >= 0 && n <= _maxStrength; } protected override DragMode GetDragModeFor(Vector2 relativeMousePos) @@ -201,13 +209,16 @@ public sealed partial class ParticleAcceleratorControlMenu : FancyWindow private void UpdateUI(bool assembled, bool blocked, bool enabled, bool powerBlock) { + bool hasAccess = _player.LocalSession?.AttachedEntity is {} player + && _accessReader.IsAllowed(player, _entity); + OnButton.Pressed = enabled; OffButton.Pressed = !enabled; - var cantUse = !assembled || blocked || powerBlock; + var cantUse = !assembled || blocked || powerBlock || !hasAccess; OnButton.Disabled = cantUse; OffButton.Disabled = cantUse; - ScanButton.Disabled = blocked; + ScanButton.Disabled = blocked || !hasAccess; var cantChangeLevel = !assembled || blocked || !enabled || cantUse; StateSpinBox.SetButtonDisabled(cantChangeLevel); diff --git a/Resources/Prototypes/Entities/Structures/Power/Generation/PA/control_box.yml b/Resources/Prototypes/Entities/Structures/Power/Generation/PA/control_box.yml index 96392ecd00..ae3fc96774 100644 --- a/Resources/Prototypes/Entities/Structures/Power/Generation/PA/control_box.yml +++ b/Resources/Prototypes/Entities/Structures/Power/Generation/PA/control_box.yml @@ -25,6 +25,8 @@ - type: Wires boardName: wires-board-name-pa layoutId: ParticleAccelerator + - type: AccessReader + access: [["Engineering"]] # Unfinished