]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
[#28722 fix] Add notification for dependent wearables being dropped (#33078)
authorSlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>
Thu, 31 Oct 2024 14:12:26 +0000 (15:12 +0100)
committerGitHub <noreply@github.com>
Thu, 31 Oct 2024 14:12:26 +0000 (15:12 +0100)
* add notification for dependent wearables being dropped

* fix dropped item popup redundancy
- did a check to see if any item was dropped, instead of making a notification for each item being dropped.

* change popup to client-only variant

* fix redundant messages, add plural locale string

* fix conventions, fix locale input to be more intuitive

---------

Co-authored-by: Justin <justinbrick1@gmail.com>
Content.Shared/Inventory/InventorySystem.Equip.cs
Resources/Locale/en-US/inventory/components/inventory-component.ftl

index 1d5d91a9e36c355427aaf8a9ea696c44d1e99459..f089dfaf2381f2a92776179e498843049df4d75d 100644 (file)
@@ -47,7 +47,7 @@ public abstract partial class InventorySystem
 
     private void OnEntRemoved(EntityUid uid, InventoryComponent component, EntRemovedFromContainerMessage args)
     {
-        if(!TryGetSlot(uid, args.Container.ID, out var slotDef, inventory: component))
+        if (!TryGetSlot(uid, args.Container.ID, out var slotDef, inventory: component))
             return;
 
         var unequippedEvent = new DidUnequipEvent(uid, args.Entity, slotDef);
@@ -59,8 +59,8 @@ public abstract partial class InventorySystem
 
     private void OnEntInserted(EntityUid uid, InventoryComponent component, EntInsertedIntoContainerMessage args)
     {
-        if(!TryGetSlot(uid, args.Container.ID, out var slotDef, inventory: component))
-           return;
+        if (!TryGetSlot(uid, args.Container.ID, out var slotDef, inventory: component))
+            return;
 
         var equippedEvent = new DidEquipEvent(uid, args.Entity, slotDef);
         RaiseLocalEvent(uid, equippedEvent, true);
@@ -118,7 +118,7 @@ public abstract partial class InventorySystem
 
         RaiseLocalEvent(held.Value, new HandDeselectedEvent(actor));
 
-        TryEquip(actor, actor, held.Value, ev.Slot, predicted: true, inventory: inventory, force: true, checkDoafter:true);
+        TryEquip(actor, actor, held.Value, ev.Slot, predicted: true, inventory: inventory, force: true, checkDoafter: true);
     }
 
     public bool TryEquip(EntityUid uid, EntityUid itemUid, string slot, bool silent = false, bool force = false, bool predicted = false,
@@ -365,6 +365,25 @@ public abstract partial class InventorySystem
         ClothingComponent? clothing = null,
         bool reparent = true,
         bool checkDoafter = false)
+    {
+        var itemsDropped = 0;
+        return TryUnequip(actor, target, slot, out removedItem, ref itemsDropped,
+            silent, force, predicted, inventory, clothing, reparent, checkDoafter);
+    }
+
+    private bool TryUnequip(
+        EntityUid actor,
+        EntityUid target,
+        string slot,
+        [NotNullWhen(true)] out EntityUid? removedItem,
+        ref int itemsDropped,
+        bool silent = false,
+        bool force = false,
+        bool predicted = false,
+        InventoryComponent? inventory = null,
+        ClothingComponent? clothing = null,
+        bool reparent = true,
+        bool checkDoafter = false)
     {
         removedItem = null;
 
@@ -423,17 +442,27 @@ public abstract partial class InventorySystem
             return false;
         }
 
+        if (!_containerSystem.Remove(removedItem.Value, slotContainer, force: force, reparent: reparent))
+            return false;
+
+        // this is in order to keep track of whether this is the first instance of a recursion call
+        var firstRun = itemsDropped == 0;
+        ++itemsDropped;
+
         foreach (var slotDef in inventory.Slots)
         {
             if (slotDef != slotDefinition && slotDef.DependsOn == slotDefinition.Name)
             {
                 //this recursive call might be risky
-                TryUnequip(actor, target, slotDef.Name, true, true, predicted, inventory, reparent: reparent);
+                TryUnequip(actor, target, slotDef.Name, out _, ref itemsDropped, true, true, predicted, inventory, reparent: reparent);
             }
         }
 
-        if (!_containerSystem.Remove(removedItem.Value, slotContainer, force: force, reparent: reparent))
-            return false;
+        // we check if any items were dropped, and make a popup if they were.
+        // the reason we check for > 1 is because the first item is always the one we are trying to unequip,
+        // whereas we only want to notify for extra dropped items.
+        if (!silent && _gameTiming.IsFirstTimePredicted && firstRun && itemsDropped > 1)
+            _popup.PopupClient(Loc.GetString("inventory-component-dropped-from-unequip", ("items", itemsDropped - 1)), target, target);
 
         // TODO: Inventory needs a hot cleanup hoo boy
         // Check if something else (AKA toggleable) dumped it into a container.
@@ -466,7 +495,7 @@ public abstract partial class InventorySystem
         if ((containerSlot == null || slotDefinition == null) && !TryGetSlotContainer(target, slot, out containerSlot, out slotDefinition, inventory))
             return false;
 
-        if (containerSlot.ContainedEntity is not {} itemUid)
+        if (containerSlot.ContainedEntity is not { } itemUid)
             return false;
 
         if (!_containerSystem.CanRemove(itemUid, containerSlot))
index 79943d914eabbec0e5a098e6d3cbf8d698e94c56..1cde6b5943c969307153ae34e12038a0ab60f362 100644 (file)
@@ -2,3 +2,9 @@ inventory-component-can-equip-cannot = You can't equip this!
 inventory-component-can-equip-does-not-fit = This doesn't fit!
 
 inventory-component-can-unequip-cannot = You can't unequip this!
+
+inventory-component-dropped-from-unequip =
+    You dropped {$items ->
+    [1] an item!
+    *[other] some items!
+}