diff --git a/Subsurface/Source/Items/CharacterInventory.cs b/Subsurface/Source/Items/CharacterInventory.cs index 62aee8a8b..6b24f62ed 100644 --- a/Subsurface/Source/Items/CharacterInventory.cs +++ b/Subsurface/Source/Items/CharacterInventory.cs @@ -311,7 +311,7 @@ namespace Barotrauma MergeSlots(); } - public override void Update(float deltaTime) + public override void Update(float deltaTime, bool subInventory = false) { base.Update(deltaTime); diff --git a/Subsurface/Source/Items/Inventory.cs b/Subsurface/Source/Items/Inventory.cs index bf0616918..0dbd5bcd3 100644 --- a/Subsurface/Source/Items/Inventory.cs +++ b/Subsurface/Source/Items/Inventory.cs @@ -63,9 +63,10 @@ namespace Barotrauma protected int selectedSlot = -1; protected InventorySlot[] slots; - public Item[] Items; + private bool isSubInventory; + public bool Locked; 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++) { @@ -261,17 +266,17 @@ namespace Barotrauma } - public virtual void Draw(SpriteBatch spriteBatch) + public virtual void Draw(SpriteBatch spriteBatch, bool subInventory = false) { string toolTip = ""; - if (slots == null) CreateSlots(); + if (slots == null || isSubInventory != subInventory) return; for (int i = 0; i < capacity; i++) { 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; DrawSlot(spriteBatch, slots[i], Items[i], drawItem); @@ -373,9 +378,26 @@ namespace Barotrauma 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; - container.Inventory.Update(deltaTime); + container.Inventory.Update(deltaTime, true); } public void DrawSubInventory(SpriteBatch spriteBatch, int slotIndex) @@ -386,8 +408,7 @@ namespace Barotrauma var container = item.GetComponent(); 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; @@ -400,20 +421,11 @@ namespace Barotrauma 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; - + 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); - for (int i = 0; i < itemCapacity; i++) - { - subRect.Y = subRect.Y - subRect.Height - 10; - container.Inventory.slots[i].Rect = subRect; - } - - container.Inventory.Draw(spriteBatch); + container.Inventory.Draw(spriteBatch, true); if (!containerRect.Contains(PlayerInput.MousePosition)) {