Equipped items can be swapped by double-clicking, fixed inventories getting messed up when swapping multi-slot items fails (e.g. drag a jumpsuit on an equipped diving suit).
This commit is contained in:
@@ -127,7 +127,6 @@ namespace Barotrauma
|
||||
if (doubleClickedItem != null)
|
||||
{
|
||||
bool wasPut = false;
|
||||
|
||||
if (doubleClickedItem.ParentInventory != this)
|
||||
{
|
||||
wasPut = TryPutItem(doubleClickedItem, Character.Controlled, doubleClickedItem.AllowedSlots, true);
|
||||
@@ -152,7 +151,12 @@ namespace Barotrauma
|
||||
//not equipped -> attempt to equip
|
||||
if (IsInLimbSlot(doubleClickedItem, InvSlotType.Any))
|
||||
{
|
||||
wasPut = TryPutItem(doubleClickedItem, Character.Controlled, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any), true);
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (limbSlots[i] == InvSlotType.Any || !doubleClickedItem.AllowedSlots.Any(a => a.HasFlag(limbSlots[i]))) continue;
|
||||
wasPut = TryPutItem(doubleClickedItem, i, true, false, Character.Controlled, true);
|
||||
if (wasPut) break;
|
||||
}
|
||||
}
|
||||
//equipped -> attempt to unequip
|
||||
else if (doubleClickedItem.AllowedSlots.Contains(InvSlotType.Any))
|
||||
@@ -162,6 +166,14 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
if (wasPut)
|
||||
{
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (Items[i] == doubleClickedItem) slots[i].ShowBorderHighlight(Color.Green, 0.1f, 0.9f);
|
||||
}
|
||||
}
|
||||
|
||||
draggingItem = null;
|
||||
GUI.PlayUISound(wasPut ? GUISoundType.PickItem : GUISoundType.PickItemFail);
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ namespace Barotrauma
|
||||
{
|
||||
Inventory selectedInventory = selectedSlot.Inventory;
|
||||
int slotIndex = selectedSlot.SlotIndex;
|
||||
if (selectedInventory.TryPutItem(draggingItem, slotIndex, true, Character.Controlled))
|
||||
if (selectedInventory.TryPutItem(draggingItem, slotIndex, true, true, Character.Controlled))
|
||||
{
|
||||
if (selectedInventory.slots != null) selectedInventory.slots[slotIndex].ShowBorderHighlight(Color.White, 0.1f, 0.4f);
|
||||
GUI.PlayUISound(GUISoundType.PickItem);
|
||||
|
||||
@@ -936,7 +936,7 @@ namespace Barotrauma
|
||||
existingWire.Remove();
|
||||
}
|
||||
|
||||
dummyCharacter.Inventory.TryPutItem(wire, slotIndex, false, dummyCharacter);
|
||||
dummyCharacter.Inventory.TryPutItem(wire, slotIndex, false, false, dummyCharacter);
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Barotrauma
|
||||
//TODO: make sure the weapon is ready to use (projectiles/batteries loaded)
|
||||
if (!character.SelectedItems.Contains(weapon))
|
||||
{
|
||||
if (character.Inventory.TryPutItem(weapon, 3, false, character))
|
||||
if (character.Inventory.TryPutItem(weapon, 3, false, false, character))
|
||||
{
|
||||
weapon.Equip(character);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace Barotrauma
|
||||
|
||||
if (targetSlot > -1 && character.Inventory.IsInLimbSlot(targetItem, InvSlotType.Any))
|
||||
{
|
||||
character.Inventory.TryPutItem(targetItem, targetSlot, false, character);
|
||||
character.Inventory.TryPutItem(targetItem, targetSlot, false, false, character);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace Barotrauma
|
||||
character.Inventory.Items[i].Drop();
|
||||
}
|
||||
}
|
||||
if (character.Inventory.TryPutItem(component.Item, i, true, character))
|
||||
if (character.Inventory.TryPutItem(component.Item, i, true, false, character))
|
||||
{
|
||||
component.Item.Equip(character);
|
||||
break;
|
||||
|
||||
@@ -657,7 +657,7 @@ namespace Barotrauma
|
||||
if (item == null) continue;
|
||||
|
||||
item.TryInteract(this, true, true, true);
|
||||
inventory.TryPutItem(item, i, false, null, false);
|
||||
inventory.TryPutItem(item, i, false, false, null, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ namespace Barotrauma
|
||||
for (int i = 0; i < character.Inventory.Items.Length; i++)
|
||||
{
|
||||
if (character.Inventory.Items[i] == null) continue;
|
||||
husk.Inventory.TryPutItem(character.Inventory.Items[i], i, true, null);
|
||||
husk.Inventory.TryPutItem(character.Inventory.Items[i], i, true, false, null);
|
||||
}
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace Barotrauma
|
||||
bool free = true;
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (allowedSlot.HasFlag(limbSlots[i]) && Items[i]!=null && Items[i]!=item)
|
||||
if (allowedSlot.HasFlag(limbSlots[i]) && Items[i] != null && Items[i] != item)
|
||||
{
|
||||
free = false;
|
||||
#if CLIENT
|
||||
@@ -144,7 +144,7 @@ namespace Barotrauma
|
||||
return placed;
|
||||
}
|
||||
|
||||
public override bool TryPutItem(Item item, int index, bool allowSwapping, Character user, bool createNetworkEvent = true)
|
||||
public override bool TryPutItem(Item item, int index, bool allowSwapping, bool allowCombine, Character user, bool createNetworkEvent = true)
|
||||
{
|
||||
//there's already an item in the slot
|
||||
if (Items[index] != null)
|
||||
@@ -152,7 +152,7 @@ namespace Barotrauma
|
||||
if (Items[index] == item) return false;
|
||||
|
||||
bool combined = false;
|
||||
if (Items[index].Combine(item))
|
||||
if (allowCombine && Items[index].Combine(item))
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(Items[index] != null);
|
||||
|
||||
@@ -168,25 +168,48 @@ namespace Barotrauma
|
||||
else if (item.ParentInventory == this && allowSwapping)
|
||||
{
|
||||
int currentIndex = Array.IndexOf(Items, item);
|
||||
|
||||
|
||||
Item existingItem = Items[index];
|
||||
|
||||
Items[currentIndex] = null;
|
||||
Items[index] = null;
|
||||
//if the item in the slot can be moved to the slot of the moved item
|
||||
if (TryPutItem(existingItem, currentIndex, false, user, createNetworkEvent) &&
|
||||
TryPutItem(item, index, false, user, createNetworkEvent))
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
|
||||
if (Items[i] == item || Items[i] == existingItem) Items[i] = null;
|
||||
}
|
||||
|
||||
//if the item in the slot can be moved to the slot of the moved item
|
||||
if (TryPutItem(existingItem, currentIndex, false, false, user, createNetworkEvent) &&
|
||||
TryPutItem(item, index, false, false, user, createNetworkEvent))
|
||||
{
|
||||
#if CLIENT
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (Items[i] == item || Items[i] == existingItem)
|
||||
{
|
||||
slots[i].ShowBorderHighlight(Color.Green, 0.1f, 0.9f);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
Items[currentIndex] = null;
|
||||
Items[index] = null;
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (Items[i] == item || Items[i] == existingItem) Items[i] = null;
|
||||
}
|
||||
|
||||
//swapping the items failed -> move them back to where they were
|
||||
TryPutItem(item, currentIndex, false, user, createNetworkEvent);
|
||||
TryPutItem(existingItem, index, false, user, createNetworkEvent);
|
||||
TryPutItem(item, currentIndex, false, false, user, createNetworkEvent);
|
||||
TryPutItem(existingItem, index, false, false, user, createNetworkEvent);
|
||||
#if CLIENT
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (Items[i] == existingItem)
|
||||
{
|
||||
slots[i].ShowBorderHighlight(Color.Red, 0.1f, 0.9f);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace Barotrauma.Items.Components
|
||||
Item item = Entity.FindEntityByID(itemIds[i]) as Item;
|
||||
if (item == null) continue;
|
||||
|
||||
Inventory.TryPutItem(item, i, false, null, false);
|
||||
Inventory.TryPutItem(item, i, false, false, null, false);
|
||||
}
|
||||
|
||||
itemIds = null;
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool TryPutItem(Item item, int i, bool allowSwapping, Character user, bool createNetworkEvent = true)
|
||||
public virtual bool TryPutItem(Item item, int i, bool allowSwapping, bool allowCombine, Character user, bool createNetworkEvent = true)
|
||||
{
|
||||
if (Owner == null) return false;
|
||||
if (CanBePut(item, i))
|
||||
@@ -224,7 +224,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (!item.CanClientAccess(c)) continue;
|
||||
}
|
||||
TryPutItem(item, i, true, c.Character, false);
|
||||
TryPutItem(item, i, true, true, c.Character, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ namespace Barotrauma
|
||||
var item = Entity.FindEntityByID(receivedItemIDs[i]) as Item;
|
||||
if (item == null) continue;
|
||||
|
||||
TryPutItem(item, i, true, null, false);
|
||||
TryPutItem(item, i, true, true, null, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1642,7 +1642,7 @@ namespace Barotrauma
|
||||
if (inventory != null)
|
||||
{
|
||||
if (inventorySlotIndex >= 0 && inventorySlotIndex < 255 &&
|
||||
inventory.TryPutItem(item, inventorySlotIndex, false, null, false))
|
||||
inventory.TryPutItem(item, inventorySlotIndex, false, false, null, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -63,9 +63,9 @@ namespace Barotrauma
|
||||
return wasPut;
|
||||
}
|
||||
|
||||
public override bool TryPutItem(Item item, int i, bool allowSwapping, Character user, bool createNetworkEvent = true)
|
||||
public override bool TryPutItem(Item item, int i, bool allowSwapping, bool allowCombine, Character user, bool createNetworkEvent = true)
|
||||
{
|
||||
bool wasPut = base.TryPutItem(item, i, allowSwapping, user, createNetworkEvent);
|
||||
bool wasPut = base.TryPutItem(item, i, allowSwapping, allowCombine, user, createNetworkEvent);
|
||||
|
||||
if (wasPut)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user