Fixed NullReferenceExceptions when dragging an item that isn't in any slot (i.e. a wire)

This commit is contained in:
Regalis
2016-10-05 15:50:55 +03:00
parent 14ae355f19
commit 9511baeeb8

View File

@@ -237,7 +237,7 @@ namespace Barotrauma
public virtual void Update(float deltaTime) public virtual void Update(float deltaTime)
{ {
if (slots == null) CreateSlots(); if (slots == null) CreateSlots();
for (int i = 0; i < capacity; i++) for (int i = 0; i < capacity; i++)
{ {
if (slots[i].Disabled) continue; if (slots[i].Disabled) continue;
@@ -245,7 +245,8 @@ namespace Barotrauma
} }
if (draggingItem != null && !draggingSlot.Rect.Contains(PlayerInput.MousePosition) && draggingItem.ParentInventory == this) if (draggingItem != null &&
(draggingSlot == null || (!draggingSlot.Rect.Contains(PlayerInput.MousePosition) && draggingItem.ParentInventory == this)))
{ {
if (!PlayerInput.LeftButtonHeld()) if (!PlayerInput.LeftButtonHeld())
{ {
@@ -276,9 +277,8 @@ namespace Barotrauma
DrawSlot(spriteBatch, slots[i], Items[i], drawItem); DrawSlot(spriteBatch, slots[i], Items[i], drawItem);
} }
if (draggingItem != null && if (draggingItem != null &&
!draggingSlot.Rect.Contains(PlayerInput.MousePosition) && (draggingSlot == null || (!draggingSlot.Rect.Contains(PlayerInput.MousePosition) && draggingItem.ParentInventory == this)))
draggingItem.ParentInventory == this)
{ {
Rectangle dragRect = new Rectangle( Rectangle dragRect = new Rectangle(
(int)PlayerInput.MousePosition.X - 10, (int)PlayerInput.MousePosition.X - 10,