From 55861b4fcfb525113d4c194fd1eac0486ac9fc1a Mon Sep 17 00:00:00 2001 From: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com> Date: Thu, 31 Oct 2024 15:12:26 +0100 Subject: [PATCH] [#28722 fix] Add notification for dependent wearables being dropped (#33078) * 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 --- .../Inventory/InventorySystem.Equip.cs | 45 +++++++++++++++---- .../components/inventory-component.ftl | 6 +++ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/Content.Shared/Inventory/InventorySystem.Equip.cs b/Content.Shared/Inventory/InventorySystem.Equip.cs index 1d5d91a9e3..f089dfaf23 100644 --- a/Content.Shared/Inventory/InventorySystem.Equip.cs +++ b/Content.Shared/Inventory/InventorySystem.Equip.cs @@ -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)) diff --git a/Resources/Locale/en-US/inventory/components/inventory-component.ftl b/Resources/Locale/en-US/inventory/components/inventory-component.ftl index 79943d914e..1cde6b5943 100644 --- a/Resources/Locale/en-US/inventory/components/inventory-component.ftl +++ b/Resources/Locale/en-US/inventory/components/inventory-component.ftl @@ -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! +} -- 2.52.0