From: themias <89101928+themias@users.noreply.github.com>
Date: Wed, 22 Nov 2023 17:16:02 +0000 (-0500)
Subject: Fix cyborg locking (#21809)
X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=c7c49df35788ba197b9176247dcfdb5370442586;p=space-station-14.git
Fix cyborg locking (#21809)
* Fix cyborg locking
* Revert "Fix cyborg locking"
This reverts commit bd5bbbb8b46edb720a9d479772f7931f5f497907.
* create generic component
* update submodules
* Revert "update submodules"
This reverts commit 303200f298f1c56660955d13caa8218b02e306ad.
---
diff --git a/Content.Server/Lock/Components/ActivatableUIRequiresLockComponent.cs b/Content.Server/Lock/Components/ActivatableUIRequiresLockComponent.cs
new file mode 100644
index 0000000000..dac677c1c2
--- /dev/null
+++ b/Content.Server/Lock/Components/ActivatableUIRequiresLockComponent.cs
@@ -0,0 +1,15 @@
+namespace Content.Server.Lock.Components;
+
+///
+/// This is used for activatable UIs that require the entity to have a lock in a certain state.
+///
+[RegisterComponent]
+public sealed partial class ActivatableUIRequiresLockComponent : Component
+{
+ ///
+ /// TRUE: the lock must be locked to access the UI.
+ /// FALSE: the lock must be unlocked to access the UI.
+ ///
+ [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
index 0000000000..bfb2fbc6e1
--- /dev/null
+++ b/Content.Server/Lock/EntitySystems/ActivatableUIRequiresLockSystem.cs
@@ -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(OnUIOpenAttempt);
+ SubscribeLocalEvent(LockToggled);
+ }
+
+ private void OnUIOpenAttempt(EntityUid uid, ActivatableUIRequiresLockComponent component, ActivatableUIOpenAttemptEvent args)
+ {
+ if (args.Cancelled)
+ return;
+
+ if (TryComp(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(uid, out var lockComp) || lockComp.Locked == component.requireLocked)
+ return;
+
+ _activatableUI.CloseAll(uid);
+ }
+}
+
diff --git a/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml b/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml
index 8b1f61a8c5..ac19ad2f23 100644
--- a/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml
+++ b/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml
@@ -208,5 +208,6 @@
- AllAccess
- type: Lock
locked: true
+ - type: ActivatableUIRequiresLock
- type: AccessReader
access: [["Command"], ["Research"]]