]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
ItemToggle + slots stuff (#31312)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sun, 25 Aug 2024 12:30:28 +0000 (22:30 +1000)
committerGitHub <noreply@github.com>
Sun, 25 Aug 2024 12:30:28 +0000 (22:30 +1000)
* ItemToggle + slots stuff

- Add component for itemslot locks to match LockComponent (surprised this didn't exist).
- Add thing for pointlight to match itemtoggle. In future should be used for PDAs and stuff but need to fix some other stuff first.

* Also this

* grill

Content.Shared/Containers/ItemSlot/ItemSlotsLockComponent.cs [new file with mode: 0644]
Content.Shared/Containers/ItemSlot/ItemSlotsSystem.Lock.cs [new file with mode: 0644]
Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs
Content.Shared/Item/ItemToggle/Components/ItemToggleComponent.cs
Content.Shared/Item/ItemToggle/ItemToggleSystem.cs
Content.Shared/Light/Components/ItemTogglePointLightComponent.cs [new file with mode: 0644]
Content.Shared/Light/EntitySystems/ItemTogglePointLightSystem.cs [new file with mode: 0644]
Content.Shared/Power/Components/ItemSlotRequiresPowerComponent.cs [new file with mode: 0644]
Content.Shared/Power/EntitySystems/ItemSlotRequiresPowerSystem.cs [new file with mode: 0644]
Resources/Locale/en-US/items/toggle.ftl [new file with mode: 0644]

diff --git a/Content.Shared/Containers/ItemSlot/ItemSlotsLockComponent.cs b/Content.Shared/Containers/ItemSlot/ItemSlotsLockComponent.cs
new file mode 100644 (file)
index 0000000..0d89010
--- /dev/null
@@ -0,0 +1,13 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Containers.ItemSlots;
+
+/// <summary>
+/// Updates the relevant ItemSlots locks based on <see cref="LockComponent"/>
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class ItemSlotsLockComponent : Component
+{
+    [DataField(required: true)]
+    public List<string> Slots = new();
+}
diff --git a/Content.Shared/Containers/ItemSlot/ItemSlotsSystem.Lock.cs b/Content.Shared/Containers/ItemSlot/ItemSlotsSystem.Lock.cs
new file mode 100644 (file)
index 0000000..ee5178d
--- /dev/null
@@ -0,0 +1,36 @@
+using Content.Shared.Lock;
+
+namespace Content.Shared.Containers.ItemSlots;
+
+public sealed partial class ItemSlotsSystem
+{
+    private void InitializeLock()
+    {
+        SubscribeLocalEvent<ItemSlotsLockComponent, MapInitEvent>(OnLockMapInit);
+        SubscribeLocalEvent<ItemSlotsLockComponent, LockToggledEvent>(OnLockToggled);
+    }
+
+    private void OnLockMapInit(Entity<ItemSlotsLockComponent> ent, ref MapInitEvent args)
+    {
+        if (!TryComp(ent.Owner, out LockComponent? lockComp))
+            return;
+
+        UpdateLocks(ent, lockComp.Locked);
+    }
+
+    private void OnLockToggled(Entity<ItemSlotsLockComponent> ent, ref LockToggledEvent args)
+    {
+        UpdateLocks(ent, args.Locked);
+    }
+
+    private void UpdateLocks(Entity<ItemSlotsLockComponent> ent, bool value)
+    {
+        foreach (var slot in ent.Comp.Slots)
+        {
+            if (!TryGetSlot(ent.Owner, slot, out var itemSlot))
+                continue;
+
+            SetLock(ent.Owner, itemSlot, value);
+        }
+    }
+}
index 48f4f07cbe1ad56708a7801c3775c74772cd7c34..f41fa2b22d2c53d8c4995dc2d3a6efd64d4e6b6b 100644 (file)
@@ -24,7 +24,7 @@ namespace Content.Shared.Containers.ItemSlots
     ///     Note when using popups on entities with many slots with InsertOnInteract, EjectOnInteract or EjectOnUse:
     ///     A single use will try to insert to/eject from every slot and generate a popup for each that fails.
     /// </remarks>
-    public sealed class ItemSlotsSystem : EntitySystem
+    public sealed partial class ItemSlotsSystem : EntitySystem
     {
         [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
         [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
@@ -38,6 +38,8 @@ namespace Content.Shared.Containers.ItemSlots
         {
             base.Initialize();
 
+            InitializeLock();
+
             SubscribeLocalEvent<ItemSlotsComponent, MapInitEvent>(OnMapInit);
             SubscribeLocalEvent<ItemSlotsComponent, ComponentInit>(Oninitialize);
 
index 46249fdd0defde3734047775ffce9df99e8e15ae..47edec135d8d850b0a38fbc117efeb13c4394b2f 100644 (file)
@@ -19,6 +19,12 @@ public sealed partial class ItemToggleComponent : Component
     [DataField, AutoNetworkedField]
     public bool Activated = false;
 
+    /// <summary>
+    /// Can the entity be activated in the world.
+    /// </summary>
+    [DataField]
+    public bool OnActivate = true;
+
     /// <summary>
     /// If this is set to false then the item can't be toggled by pressing Z.
     /// Use another system to do it then.
@@ -52,12 +58,6 @@ public sealed partial class ItemToggleComponent : Component
     /// </summary>
     [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
     public SoundSpecifier? SoundFailToActivate;
-
-    /// <summary>
-    /// Whether or not to toggle the entity's lights on or off.
-    /// </summary>
-    [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
-    public bool ToggleLight = true;
 }
 
 /// <summary>
index 1cc8699d70c425a374d5e288041f1a5d0bac9b6d..33b88dbaf824e4b76a3fd1ac6c82b7f7f32c6911 100644 (file)
@@ -1,8 +1,10 @@
+using Content.Shared.Interaction;
 using Content.Shared.Interaction.Events;
 using Content.Shared.Item.ItemToggle.Components;
 using Content.Shared.Popups;
 using Content.Shared.Temperature;
 using Content.Shared.Toggleable;
+using Content.Shared.Verbs;
 using Content.Shared.Wieldable;
 using Robust.Shared.Audio;
 using Robust.Shared.Audio.Systems;
@@ -20,7 +22,6 @@ public sealed class ItemToggleSystem : EntitySystem
     [Dependency] private readonly INetManager _netManager = default!;
     [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
     [Dependency] private readonly SharedAudioSystem _audio = default!;
-    [Dependency] private readonly SharedPointLightSystem _light = default!;
     [Dependency] private readonly SharedPopupSystem _popup = default!;
 
     private EntityQuery<ItemToggleComponent> _query;
@@ -36,6 +37,8 @@ public sealed class ItemToggleSystem : EntitySystem
         SubscribeLocalEvent<ItemToggleComponent, ItemUnwieldedEvent>(TurnOffOnUnwielded);
         SubscribeLocalEvent<ItemToggleComponent, ItemWieldedEvent>(TurnOnOnWielded);
         SubscribeLocalEvent<ItemToggleComponent, UseInHandEvent>(OnUseInHand);
+        SubscribeLocalEvent<ItemToggleComponent, GetVerbsEvent<ActivationVerb>>(OnActivateVerb);
+        SubscribeLocalEvent<ItemToggleComponent, ActivateInWorldEvent>(OnActivate);
 
         SubscribeLocalEvent<ItemToggleHotComponent, IsHotEvent>(OnIsHotEvent);
 
@@ -66,6 +69,32 @@ public sealed class ItemToggleSystem : EntitySystem
         Toggle((ent, ent.Comp), args.User, predicted: ent.Comp.Predictable);
     }
 
+    private void OnActivateVerb(Entity<ItemToggleComponent> ent, ref GetVerbsEvent<ActivationVerb> args)
+    {
+        if (!args.CanAccess || !args.CanInteract)
+            return;
+
+        var user = args.User;
+
+        args.Verbs.Add(new ActivationVerb()
+        {
+            Text = !ent.Comp.Activated ? Loc.GetString("item-toggle-activate") : Loc.GetString("item-toggle-deactivate"),
+            Act = () =>
+            {
+                Toggle((ent.Owner, ent.Comp), user, predicted: ent.Comp.Predictable);
+            }
+        });
+    }
+
+    private void OnActivate(Entity<ItemToggleComponent> ent, ref ActivateInWorldEvent args)
+    {
+        if (args.Handled || !ent.Comp.OnActivate)
+            return;
+
+        args.Handled = true;
+        Toggle((ent.Owner, ent.Comp), args.User, predicted: ent.Comp.Predictable);
+    }
+
     /// <summary>
     /// Used when an item is attempted to be toggled.
     /// Sets its state to the opposite of what it is.
@@ -203,16 +232,7 @@ public sealed class ItemToggleSystem : EntitySystem
         if (TryComp(ent, out AppearanceComponent? appearance))
         {
             _appearance.SetData(ent, ToggleVisuals.Toggled, ent.Comp.Activated, appearance);
-
-            if (ent.Comp.ToggleLight)
-                _appearance.SetData(ent, ToggleableLightVisuals.Enabled, ent.Comp.Activated, appearance);
         }
-
-        if (!ent.Comp.ToggleLight)
-            return;
-
-        if (_light.TryGetLight(ent, out var light))
-            _light.SetEnabled(ent, ent.Comp.Activated, light);
     }
 
     /// <summary>
diff --git a/Content.Shared/Light/Components/ItemTogglePointLightComponent.cs b/Content.Shared/Light/Components/ItemTogglePointLightComponent.cs
new file mode 100644 (file)
index 0000000..6ac1bf2
--- /dev/null
@@ -0,0 +1,12 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Light.Components;
+
+/// <summary>
+/// Toggles point light on an entity whenever ItemToggle hits.
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class ItemTogglePointLightComponent : Component
+{
+
+}
diff --git a/Content.Shared/Light/EntitySystems/ItemTogglePointLightSystem.cs b/Content.Shared/Light/EntitySystems/ItemTogglePointLightSystem.cs
new file mode 100644 (file)
index 0000000..7030c53
--- /dev/null
@@ -0,0 +1,29 @@
+using Content.Shared.Item.ItemToggle.Components;
+using Content.Shared.Toggleable;
+using ItemTogglePointLightComponent = Content.Shared.Light.Components.ItemTogglePointLightComponent;
+
+namespace Content.Shared.Light.EntitySystems;
+
+/// <summary>
+/// Handles ItemToggle for PointLight
+/// </summary>
+public sealed class ItemTogglePointLightSystem : EntitySystem
+{
+    [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
+    [Dependency] private readonly SharedPointLightSystem _light = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+        SubscribeLocalEvent<ItemTogglePointLightComponent, ItemToggledEvent>(OnLightToggled);
+    }
+
+    private void OnLightToggled(Entity<ItemTogglePointLightComponent> ent, ref ItemToggledEvent args)
+    {
+        if (!_light.TryGetLight(ent.Owner, out var light))
+            return;
+
+        _appearance.SetData(ent, ToggleableLightVisuals.Enabled, args.Activated);
+        _light.SetEnabled(ent.Owner, args.Activated, comp: light);
+    }
+}
diff --git a/Content.Shared/Power/Components/ItemSlotRequiresPowerComponent.cs b/Content.Shared/Power/Components/ItemSlotRequiresPowerComponent.cs
new file mode 100644 (file)
index 0000000..6e3b9ea
--- /dev/null
@@ -0,0 +1,9 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Power.Components;
+
+[RegisterComponent, NetworkedComponent]
+public sealed partial class ItemSlotRequiresPowerComponent : Component
+{
+
+}
diff --git a/Content.Shared/Power/EntitySystems/ItemSlotRequiresPowerSystem.cs b/Content.Shared/Power/EntitySystems/ItemSlotRequiresPowerSystem.cs
new file mode 100644 (file)
index 0000000..3df8b91
--- /dev/null
@@ -0,0 +1,23 @@
+using Content.Shared.Containers.ItemSlots;
+using Content.Shared.Power.Components;
+
+namespace Content.Shared.Power.EntitySystems;
+
+public sealed class ItemSlotRequiresPowerSystem : EntitySystem
+{
+    [Dependency] private readonly SharedPowerReceiverSystem _receiver = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+        SubscribeLocalEvent<ItemSlotRequiresPowerComponent, ItemSlotInsertAttemptEvent>(OnInsertAttempt);
+    }
+
+    private void OnInsertAttempt(Entity<ItemSlotRequiresPowerComponent> ent, ref ItemSlotInsertAttemptEvent args)
+    {
+        if (!_receiver.IsPowered(ent.Owner))
+        {
+            args.Cancelled = true;
+        }
+    }
+}
diff --git a/Resources/Locale/en-US/items/toggle.ftl b/Resources/Locale/en-US/items/toggle.ftl
new file mode 100644 (file)
index 0000000..bcf5c16
--- /dev/null
@@ -0,0 +1,2 @@
+item-toggle-activate = Activate
+item-toggle-deactivate = Deactivate