]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix cyborg locking (#21809)
authorthemias <89101928+themias@users.noreply.github.com>
Wed, 22 Nov 2023 17:16:02 +0000 (12:16 -0500)
committerGitHub <noreply@github.com>
Wed, 22 Nov 2023 17:16:02 +0000 (12:16 -0500)
* Fix cyborg locking

* Revert "Fix cyborg locking"

This reverts commit bd5bbbb8b46edb720a9d479772f7931f5f497907.

* create generic component

* update submodules

* Revert "update submodules"

This reverts commit 303200f298f1c56660955d13caa8218b02e306ad.

Content.Server/Lock/Components/ActivatableUIRequiresLockComponent.cs [new file with mode: 0644]
Content.Server/Lock/EntitySystems/ActivatableUIRequiresLockSystem.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml

diff --git a/Content.Server/Lock/Components/ActivatableUIRequiresLockComponent.cs b/Content.Server/Lock/Components/ActivatableUIRequiresLockComponent.cs
new file mode 100644 (file)
index 0000000..dac677c
--- /dev/null
@@ -0,0 +1,15 @@
+namespace Content.Server.Lock.Components;
+
+/// <summary>
+/// This is used for activatable UIs that require the entity to have a lock in a certain state.
+/// </summary>
+[RegisterComponent]
+public sealed partial class ActivatableUIRequiresLockComponent : Component
+{
+    /// <summary>
+    /// TRUE: the lock must be locked to access the UI.
+    /// FALSE: the lock must be unlocked to access the UI.
+    /// </summary>
+    [DataField("requireLocked"), ViewVariables(VVAccess.ReadWrite)]
+    public bool requireLocked = false;
+}
diff --git a/Content.Server/Lock/EntitySystems/ActivatableUIRequiresLockSystem.cs b/Content.Server/Lock/EntitySystems/ActivatableUIRequiresLockSystem.cs
new file mode 100644 (file)
index 0000000..bfb2fbc
--- /dev/null
@@ -0,0 +1,41 @@
+using Content.Server.Lock.Components;
+using Content.Server.Popups;
+using Content.Server.UserInterface;
+using Content.Shared.Lock;
+
+namespace Content.Server.Lock.EntitySystems;
+public sealed class ActivatableUIRequiresLockSystem : EntitySystem
+{
+    [Dependency] private readonly ActivatableUISystem _activatableUI = default!;
+    [Dependency] private readonly PopupSystem _popupSystem = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<ActivatableUIRequiresLockComponent, ActivatableUIOpenAttemptEvent>(OnUIOpenAttempt);
+        SubscribeLocalEvent<ActivatableUIRequiresLockComponent, LockToggledEvent>(LockToggled);
+    }
+
+    private void OnUIOpenAttempt(EntityUid uid, ActivatableUIRequiresLockComponent component, ActivatableUIOpenAttemptEvent args)
+    {
+        if (args.Cancelled)
+            return;
+
+        if (TryComp<LockComponent>(uid, out var lockComp) && lockComp.Locked != component.requireLocked)
+        {
+            args.Cancel();
+            if (lockComp.Locked)
+                _popupSystem.PopupEntity(Loc.GetString("entity-storage-component-locked-message"), uid, args.User);
+        }
+    }
+
+    private void LockToggled(EntityUid uid, ActivatableUIRequiresLockComponent component, LockToggledEvent args)
+    {
+        if (!TryComp<LockComponent>(uid, out var lockComp) || lockComp.Locked == component.requireLocked)
+            return;
+
+        _activatableUI.CloseAll(uid);
+    }
+}
+
index 8b1f61a8c545b547cb10bcf1810849b1506b19f7..ac19ad2f23822ac23fcb2c24bd21d696e19455d9 100644 (file)
     - AllAccess
   - type: Lock
     locked: true
+  - type: ActivatableUIRequiresLock
   - type: AccessReader
     access: [["Command"], ["Research"]]