SubInventories return "back to normal" if removed from the parent inventory (e.g. crate inventories aren't drawn above the hand slots after dropping the crate)
This commit is contained in:
@@ -311,7 +311,7 @@ namespace Barotrauma
|
|||||||
MergeSlots();
|
MergeSlots();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(float deltaTime)
|
public override void Update(float deltaTime, bool subInventory = false)
|
||||||
{
|
{
|
||||||
base.Update(deltaTime);
|
base.Update(deltaTime);
|
||||||
|
|
||||||
|
|||||||
@@ -63,9 +63,10 @@ namespace Barotrauma
|
|||||||
protected int selectedSlot = -1;
|
protected int selectedSlot = -1;
|
||||||
|
|
||||||
protected InventorySlot[] slots;
|
protected InventorySlot[] slots;
|
||||||
|
|
||||||
public Item[] Items;
|
public Item[] Items;
|
||||||
|
|
||||||
|
private bool isSubInventory;
|
||||||
|
|
||||||
public bool Locked;
|
public bool Locked;
|
||||||
|
|
||||||
public Vector2 CenterPos
|
public Vector2 CenterPos
|
||||||
@@ -234,9 +235,13 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Update(float deltaTime)
|
public virtual void Update(float deltaTime, bool subInventory = false)
|
||||||
{
|
{
|
||||||
if (slots == null) CreateSlots();
|
if (slots == null || isSubInventory != subInventory)
|
||||||
|
{
|
||||||
|
CreateSlots();
|
||||||
|
isSubInventory = subInventory;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < capacity; i++)
|
for (int i = 0; i < capacity; i++)
|
||||||
{
|
{
|
||||||
@@ -261,17 +266,17 @@ namespace Barotrauma
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Draw(SpriteBatch spriteBatch)
|
public virtual void Draw(SpriteBatch spriteBatch, bool subInventory = false)
|
||||||
{
|
{
|
||||||
string toolTip = "";
|
string toolTip = "";
|
||||||
|
|
||||||
if (slots == null) CreateSlots();
|
if (slots == null || isSubInventory != subInventory) return;
|
||||||
|
|
||||||
for (int i = 0; i < capacity; i++)
|
for (int i = 0; i < capacity; i++)
|
||||||
{
|
{
|
||||||
if (slots[i].Disabled) continue;
|
if (slots[i].Disabled) continue;
|
||||||
|
|
||||||
//don't draw the slot if dragged an item out of it
|
//don't draw the item if it's being dragged out of the slot
|
||||||
bool drawItem = draggingItem == null || draggingItem != Items[i] || slots[i].IsHighlighted;
|
bool drawItem = draggingItem == null || draggingItem != Items[i] || slots[i].IsHighlighted;
|
||||||
|
|
||||||
DrawSlot(spriteBatch, slots[i], Items[i], drawItem);
|
DrawSlot(spriteBatch, slots[i], Items[i], drawItem);
|
||||||
@@ -373,9 +378,26 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (container.Inventory.slots == null) container.Inventory.CreateSlots();
|
if (container.Inventory.slots == null) container.Inventory.CreateSlots();
|
||||||
|
|
||||||
|
int itemCapacity = container.Capacity;
|
||||||
|
|
||||||
|
var slot = slots[slotIndex];
|
||||||
|
Rectangle containerRect = new Rectangle(slot.Rect.X - 5, slot.Rect.Y - (40 + 10) * itemCapacity - 5,
|
||||||
|
slot.Rect.Width + 10, slot.Rect.Height + (40 + 10) * itemCapacity + 10);
|
||||||
|
|
||||||
|
Rectangle subRect = slot.Rect;
|
||||||
|
subRect.Height = 40;
|
||||||
|
|
||||||
|
for (int i = 0; i < itemCapacity; i++)
|
||||||
|
{
|
||||||
|
subRect.Y = subRect.Y - subRect.Height - 10;
|
||||||
|
container.Inventory.slots[i].Rect = subRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
container.Inventory.isSubInventory = true;
|
||||||
|
|
||||||
slots[slotIndex].State = GUIComponent.ComponentState.Hover;
|
slots[slotIndex].State = GUIComponent.ComponentState.Hover;
|
||||||
|
|
||||||
container.Inventory.Update(deltaTime);
|
container.Inventory.Update(deltaTime, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawSubInventory(SpriteBatch spriteBatch, int slotIndex)
|
public void DrawSubInventory(SpriteBatch spriteBatch, int slotIndex)
|
||||||
@@ -386,8 +408,7 @@ namespace Barotrauma
|
|||||||
var container = item.GetComponent<ItemContainer>();
|
var container = item.GetComponent<ItemContainer>();
|
||||||
if (container == null) return;
|
if (container == null) return;
|
||||||
|
|
||||||
if (container.Inventory.slots == null) container.Inventory.CreateSlots();
|
if (container.Inventory.slots == null || !container.Inventory.isSubInventory) return;
|
||||||
|
|
||||||
|
|
||||||
int itemCapacity = container.Capacity;
|
int itemCapacity = container.Capacity;
|
||||||
|
|
||||||
@@ -400,20 +421,11 @@ namespace Barotrauma
|
|||||||
var slot = slots[slotIndex];
|
var slot = slots[slotIndex];
|
||||||
Rectangle containerRect = new Rectangle(slot.Rect.X - 5, slot.Rect.Y - (40 + 10) * itemCapacity - 5,
|
Rectangle containerRect = new Rectangle(slot.Rect.X - 5, slot.Rect.Y - (40 + 10) * itemCapacity - 5,
|
||||||
slot.Rect.Width + 10, slot.Rect.Height + (40 + 10) * itemCapacity + 10);
|
slot.Rect.Width + 10, slot.Rect.Height + (40 + 10) * itemCapacity + 10);
|
||||||
|
|
||||||
Rectangle subRect = slot.Rect;
|
|
||||||
subRect.Height = 40;
|
|
||||||
|
|
||||||
GUI.DrawRectangle(spriteBatch, new Rectangle(containerRect.X, containerRect.Y, containerRect.Width, containerRect.Height - slot.Rect.Height - 5), Color.Black * 0.8f, true);
|
GUI.DrawRectangle(spriteBatch, new Rectangle(containerRect.X, containerRect.Y, containerRect.Width, containerRect.Height - slot.Rect.Height - 5), Color.Black * 0.8f, true);
|
||||||
GUI.DrawRectangle(spriteBatch, containerRect, Color.White);
|
GUI.DrawRectangle(spriteBatch, containerRect, Color.White);
|
||||||
|
|
||||||
for (int i = 0; i < itemCapacity; i++)
|
container.Inventory.Draw(spriteBatch, true);
|
||||||
{
|
|
||||||
subRect.Y = subRect.Y - subRect.Height - 10;
|
|
||||||
container.Inventory.slots[i].Rect = subRect;
|
|
||||||
}
|
|
||||||
|
|
||||||
container.Inventory.Draw(spriteBatch);
|
|
||||||
|
|
||||||
if (!containerRect.Contains(PlayerInput.MousePosition))
|
if (!containerRect.Contains(PlayerInput.MousePosition))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user