* 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>
This commit is contained in:
@@ -47,7 +47,7 @@ public abstract partial class InventorySystem
|
|||||||
|
|
||||||
private void OnEntRemoved(EntityUid uid, InventoryComponent component, EntRemovedFromContainerMessage args)
|
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;
|
return;
|
||||||
|
|
||||||
var unequippedEvent = new DidUnequipEvent(uid, args.Entity, slotDef);
|
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)
|
private void OnEntInserted(EntityUid uid, InventoryComponent component, EntInsertedIntoContainerMessage args)
|
||||||
{
|
{
|
||||||
if(!TryGetSlot(uid, args.Container.ID, out var slotDef, inventory: component))
|
if (!TryGetSlot(uid, args.Container.ID, out var slotDef, inventory: component))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var equippedEvent = new DidEquipEvent(uid, args.Entity, slotDef);
|
var equippedEvent = new DidEquipEvent(uid, args.Entity, slotDef);
|
||||||
RaiseLocalEvent(uid, equippedEvent, true);
|
RaiseLocalEvent(uid, equippedEvent, true);
|
||||||
@@ -118,7 +118,7 @@ public abstract partial class InventorySystem
|
|||||||
|
|
||||||
RaiseLocalEvent(held.Value, new HandDeselectedEvent(actor));
|
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,
|
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,
|
ClothingComponent? clothing = null,
|
||||||
bool reparent = true,
|
bool reparent = true,
|
||||||
bool checkDoafter = false)
|
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;
|
removedItem = null;
|
||||||
|
|
||||||
@@ -423,17 +442,27 @@ public abstract partial class InventorySystem
|
|||||||
return false;
|
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)
|
foreach (var slotDef in inventory.Slots)
|
||||||
{
|
{
|
||||||
if (slotDef != slotDefinition && slotDef.DependsOn == slotDefinition.Name)
|
if (slotDef != slotDefinition && slotDef.DependsOn == slotDefinition.Name)
|
||||||
{
|
{
|
||||||
//this recursive call might be risky
|
//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))
|
// we check if any items were dropped, and make a popup if they were.
|
||||||
return false;
|
// 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
|
// TODO: Inventory needs a hot cleanup hoo boy
|
||||||
// Check if something else (AKA toggleable) dumped it into a container.
|
// 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))
|
if ((containerSlot == null || slotDefinition == null) && !TryGetSlotContainer(target, slot, out containerSlot, out slotDefinition, inventory))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (containerSlot.ContainedEntity is not {} itemUid)
|
if (containerSlot.ContainedEntity is not { } itemUid)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!_containerSystem.CanRemove(itemUid, containerSlot))
|
if (!_containerSystem.CanRemove(itemUid, containerSlot))
|
||||||
|
|||||||
@@ -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-equip-does-not-fit = This doesn't fit!
|
||||||
|
|
||||||
inventory-component-can-unequip-cannot = You can't unequip this!
|
inventory-component-can-unequip-cannot = You can't unequip this!
|
||||||
|
|
||||||
|
inventory-component-dropped-from-unequip =
|
||||||
|
You dropped {$items ->
|
||||||
|
[1] an item!
|
||||||
|
*[other] some items!
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user