Fixed "subinventories" (oxygen tanks inside suits etc) being drawn under the main inventory

This commit is contained in:
Regalis
2016-04-21 18:38:07 +03:00
parent 12dc494e42
commit 510602623a
3 changed files with 63 additions and 46 deletions
+1 -1
View File
@@ -89,7 +89,7 @@ namespace Barotrauma
if (cprButton == null)
{
cprButton = new GUIButton(
new Rectangle(character.SelectedCharacter.Inventory.SlotPositions[0].ToPoint() + new Point(150 + 320, 0), new Point(130, 20)), "Perform CPR", GUI.Style);
new Rectangle(character.SelectedCharacter.Inventory.SlotPositions[0].ToPoint() + new Point(320, -30), new Point(130, 20)), "Perform CPR", GUI.Style);
cprButton.OnClicked = (button, userData) =>
{
+22 -9
View File
@@ -273,8 +273,7 @@ namespace Barotrauma
{
string toolTip = "";
Rectangle highlightedSlot = Rectangle.Empty;
if (doubleClickedItem!=null && doubleClickedItem.ParentInventory!=this)
{
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots, true);
@@ -333,7 +332,7 @@ namespace Barotrauma
if (multiSlot) continue;
if (Items[i] != null && slotRect.Contains(PlayerInput.MousePosition))
if (Items[i] != null && slotRect.Contains(PlayerInput.MousePosition) && (selectedSlot == -1 || selectedSlot == i))
{
if (GameMain.DebugDraw)
{
@@ -347,6 +346,8 @@ namespace Barotrauma
highlightedSlot = slotRect;
}
if (selectedSlot == i) highlightedSlot = slotRect;
UpdateSlot(spriteBatch, slotRect, i, Items[i], false, i>5 ? 0.2f : 0.4f);
if (draggingItem!=null && draggingItem == Items[i]) draggingItemSlot = slotRect;
@@ -355,8 +356,6 @@ namespace Barotrauma
for (int i = 0; i < capacity; i++)
{
//Rectangle multiSlotRect = Rectangle.Empty;
bool multiSlot = false;
//check if the item is in multiple slots
@@ -386,11 +385,13 @@ namespace Barotrauma
if (multiSlot)
{
if (Items[i] != null && slotRect.Contains(PlayerInput.MousePosition))
if (Items[i] != null && slotRect.Contains(PlayerInput.MousePosition) && (selectedSlot==-1 || selectedSlot==i))
{
toolTip = string.IsNullOrEmpty(Items[i].Description) ? Items[i].Name : Items[i].Name + '\n' + Items[i].Description;
highlightedSlot = slotRect;
}
}
if (selectedSlot == i) highlightedSlot = slotRect;
UpdateSlot(spriteBatch, slotRect, i, Items[i], i > 4);
}
@@ -402,10 +403,22 @@ namespace Barotrauma
useOnSelfButton[i - 3].Update(0.016f);
useOnSelfButton[i - 3].Draw(spriteBatch);
}
}
//for (int i = 0; i < capacity; i++)
//{
// slotRect.X = (int)(SlotPositions[i].X + offset.X);
// slotRect.Y = (int)(SlotPositions[i].Y + offset.Y);
// slotRect.Width = 40;
// slotRect.Height = 40;
if (selectedSlot > -1)
{
DrawSubInventory(spriteBatch, highlightedSlot, selectedSlot);
}
//}
slotRect.Width = rectWidth;
slotRect.Height = rectHeight;
+40 -36
View File
@@ -29,7 +29,7 @@ namespace Barotrauma
private Vector2 centerPos;
protected int selectedSlot;
protected int selectedSlot = -1;
public Item[] Items;
@@ -186,6 +186,8 @@ namespace Barotrauma
Rectangle slotRect = new Rectangle(startX, startY, rectWidth, rectHeight);
Rectangle draggingItemSlot = slotRect;
selectedSlot = -1;
for (int i = 0; i < capacity; i++)
{
slotRect.X = startX + (rectWidth + spacing) * (i % slotsPerRow);
@@ -257,9 +259,15 @@ namespace Barotrauma
if (mouseOn)
{
if (!isSubSlot && selectedSlot == -1)
{
selectedSlot = slotIndex;
}
if (draggingItem == null)
{
if (PlayerInput.LeftButtonHeld())
if (PlayerInput.LeftButtonHeld() && selectedSlot == slotIndex)
{
draggingItem = item;
}
@@ -276,56 +284,52 @@ namespace Barotrauma
draggingItem = null;
}
if (!isSubSlot && selectedSlot == -1)
{
selectedSlot = slotIndex;
}
}
if (selectedSlot == slotIndex && !isSubSlot)
{
selectedSlot = -1;
DrawSlot(spriteBatch, rect, (draggingItem == item && !mouseOn) ? null : item, mouseOn && selectedSlot == slotIndex, isSubSlot, alpha, drawItem);
int itemCapacity = item==null ? 0 : item.Capacity;
if (itemCapacity > 0)
{
}
public void DrawSubInventory(SpriteBatch spriteBatch, Rectangle rect, int slotIndex)
{
var item = Items[slotIndex];
selectedSlot = -1;
int itemCapacity = item == null ? 0 : item.Capacity;
if (itemCapacity == 0) return;
#if DEBUG
System.Diagnostics.Debug.Assert(slotIndex >= 0 && slotIndex < Items.Length);
System.Diagnostics.Debug.Assert(slotIndex >= 0 && slotIndex < Items.Length);
#else
if (slotIndex < 0 || slotIndex >= Items.Length) return;
if (slotIndex < 0 || slotIndex >= Items.Length) return;
#endif
Rectangle containerRect = new Rectangle(rect.X - 5, rect.Y - (40 + 10) * itemCapacity - 5,
rect.Width + 10, rect.Height + (40 + 10) * itemCapacity + 10);
Rectangle containerRect = new Rectangle(rect.X - 5, rect.Y - (40 + 10) * itemCapacity - 5,
rect.Width + 10, rect.Height + (40 + 10) * itemCapacity + 10);
Rectangle subRect = rect;
subRect.Height = 40;
Rectangle subRect = rect;
subRect.Height = 40;
selectedSlot = containerRect.Contains(PlayerInput.MousePosition) && !Locked ? slotIndex : -1;
selectedSlot = containerRect.Contains(PlayerInput.MousePosition) && !Locked ? slotIndex : -1;
GUI.DrawRectangle(spriteBatch, containerRect, Color.Black * 0.8f, true);
GUI.DrawRectangle(spriteBatch, containerRect, Color.White);
GUI.DrawRectangle(spriteBatch, containerRect, Color.Black * 0.8f, true);
GUI.DrawRectangle(spriteBatch, containerRect, Color.White);
Item[] containedItems = null;
if (Items[slotIndex] != null) containedItems = Items[slotIndex].ContainedItems;
Item[] containedItems = null;
if (Items[slotIndex] != null) containedItems = Items[slotIndex].ContainedItems;
if (containedItems != null)
{
for (int i = 0; i < itemCapacity; i++)
{
subRect.Y = subRect.Y - subRect.Height - 10;
UpdateSlot(spriteBatch, subRect, selectedSlot, i < containedItems.Count() ? containedItems[i] : null, true);
}
}
if (containedItems != null)
{
for (int i = 0; i < itemCapacity; i++)
{
subRect.Y = subRect.Y - subRect.Height - 10;
UpdateSlot(spriteBatch, subRect, selectedSlot, i < containedItems.Count() ? containedItems[i] : null, true);
}
}
DrawSlot(spriteBatch, rect, (draggingItem == item && !mouseOn) ? null : item, mouseOn, isSubSlot, alpha, drawItem);
}
protected void DrawSlot(SpriteBatch spriteBatch, Rectangle rect, Item item, bool isHighLighted, bool isSubSlot, float alpha=0.4f, bool drawItem=true)