Highlighting inventory slots when moving items around, red highlight if an item can't be placed in a slot
This commit is contained in:
@@ -264,10 +264,11 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sb.Draw(t, new Rectangle(rect.X, rect.Y, rect.Width, thickness), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
sb.Draw(t, new Rectangle(rect.X + thickness, rect.Y, rect.Width - thickness * 2, thickness), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
||||||
sb.Draw(t, new Rectangle(rect.X, rect.Y+rect.Height- thickness, rect.Width, thickness), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
sb.Draw(t, new Rectangle(rect.X + thickness, rect.Y + rect.Height - thickness, rect.Width - thickness * 2, thickness), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
||||||
|
|
||||||
sb.Draw(t, new Rectangle(rect.X, rect.Y, thickness, rect.Height), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
sb.Draw(t, new Rectangle(rect.X, rect.Y, thickness, rect.Height), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
||||||
sb.Draw(t, new Rectangle(rect.X+rect.Width- thickness, rect.Y, thickness, rect.Height), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
sb.Draw(t, new Rectangle(rect.X + rect.Width - thickness, rect.Y, thickness, rect.Height), null, clr, 0.0f, Vector2.Zero, SpriteEffects.None, depth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ namespace Barotrauma
|
|||||||
if (allowedSlot.HasFlag(limbSlots[i]) && Items[i]!=null && Items[i]!=item)
|
if (allowedSlot.HasFlag(limbSlots[i]) && Items[i]!=null && Items[i]!=item)
|
||||||
{
|
{
|
||||||
free = false;
|
free = false;
|
||||||
break;
|
if (slots != null) slots[i].ShowBorderHighlight(Color.Red, 0.1f, 0.9f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,7 +239,6 @@ namespace Barotrauma
|
|||||||
TryPutItem(item, currentIndex, false, false);
|
TryPutItem(item, currentIndex, false, false);
|
||||||
TryPutItem(existingItem, index, false, false);
|
TryPutItem(existingItem, index, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return combined;
|
return combined;
|
||||||
@@ -293,17 +292,19 @@ namespace Barotrauma
|
|||||||
|
|
||||||
protected override void CreateSlots()
|
protected override void CreateSlots()
|
||||||
{
|
{
|
||||||
slots = new InventorySlot[capacity];
|
if (slots == null) slots = new InventorySlot[capacity];
|
||||||
|
|
||||||
int rectWidth = 40, rectHeight = 40;
|
int rectWidth = 40, rectHeight = 40;
|
||||||
|
|
||||||
Rectangle slotRect = new Rectangle(0, 0, rectWidth, rectHeight);
|
Rectangle slotRect = new Rectangle(0, 0, rectWidth, rectHeight);
|
||||||
for (int i = 0; i < capacity; i++)
|
for (int i = 0; i < capacity; i++)
|
||||||
{
|
{
|
||||||
|
slots[i].Disabled = false;
|
||||||
|
|
||||||
slotRect.X = (int)(SlotPositions[i].X + DrawOffset.X);
|
slotRect.X = (int)(SlotPositions[i].X + DrawOffset.X);
|
||||||
slotRect.Y = (int)(SlotPositions[i].Y + DrawOffset.Y);
|
slotRect.Y = (int)(SlotPositions[i].Y + DrawOffset.Y);
|
||||||
|
|
||||||
slots[i] = new InventorySlot(slotRect);
|
slots[i].Rect = slotRect;
|
||||||
|
|
||||||
slots[i].Color = limbSlots[i] == InvSlotType.Any ? Color.White * 0.2f : Color.White * 0.4f;
|
slots[i].Color = limbSlots[i] == InvSlotType.Any ? Color.White * 0.2f : Color.White * 0.4f;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public Color Color;
|
public Color Color;
|
||||||
|
|
||||||
|
public Color BorderHighlightColor;
|
||||||
|
private CoroutineHandle BorderHighlightCoroutine;
|
||||||
|
|
||||||
public InventorySlot(Rectangle rect)
|
public InventorySlot(Rectangle rect)
|
||||||
{
|
{
|
||||||
Rect = rect;
|
Rect = rect;
|
||||||
@@ -36,6 +39,33 @@ namespace Barotrauma
|
|||||||
|
|
||||||
Color = Color.White * 0.4f;
|
Color = Color.White * 0.4f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ShowBorderHighlight(Color color, float fadeInDuration, float fadeOutDuration)
|
||||||
|
{
|
||||||
|
if (BorderHighlightCoroutine != null)
|
||||||
|
{
|
||||||
|
BorderHighlightCoroutine = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
BorderHighlightCoroutine = CoroutineManager.StartCoroutine(UpdateBorderHighlight(color, fadeInDuration, fadeOutDuration));
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<object> UpdateBorderHighlight(Color color, float fadeInDuration, float fadeOutDuration)
|
||||||
|
{
|
||||||
|
float t = 0.0f;
|
||||||
|
while (t < fadeInDuration + fadeOutDuration)
|
||||||
|
{
|
||||||
|
BorderHighlightColor = (t < fadeInDuration) ?
|
||||||
|
Color.Lerp(Color.Transparent, color, t / fadeInDuration) :
|
||||||
|
Color.Lerp(color, Color.Transparent, (t - fadeInDuration) / fadeOutDuration);
|
||||||
|
|
||||||
|
t += CoroutineManager.DeltaTime;
|
||||||
|
|
||||||
|
yield return CoroutineStatus.Running;
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return CoroutineStatus.Success;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Inventory
|
class Inventory
|
||||||
@@ -163,6 +193,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (slots != null) slots[i].ShowBorderHighlight(Color.Red, 0.1f, 0.9f);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,6 +210,9 @@ namespace Barotrauma
|
|||||||
|
|
||||||
Items[i] = item;
|
Items[i] = item;
|
||||||
item.ParentInventory = this;
|
item.ParentInventory = this;
|
||||||
|
|
||||||
|
if (slots != null) slots[i].ShowBorderHighlight(Color.White, 0.1f, 0.4f);
|
||||||
|
|
||||||
if (item.body != null)
|
if (item.body != null)
|
||||||
{
|
{
|
||||||
item.body.Enabled = false;
|
item.body.Enabled = false;
|
||||||
@@ -323,7 +357,7 @@ namespace Barotrauma
|
|||||||
Vector2 rectSize = textSize * 1.2f;
|
Vector2 rectSize = textSize * 1.2f;
|
||||||
|
|
||||||
Vector2 pos = new Vector2(highlightedSlot.Right, highlightedSlot.Y-rectSize.Y);
|
Vector2 pos = new Vector2(highlightedSlot.Right, highlightedSlot.Y-rectSize.Y);
|
||||||
pos.X = (int)pos.X;
|
pos.X = (int)(pos.X + 3);
|
||||||
pos.Y = (int)pos.Y;
|
pos.Y = (int)pos.Y;
|
||||||
|
|
||||||
GUI.DrawRectangle(spriteBatch, pos, rectSize, Color.Black * 0.8f, true);
|
GUI.DrawRectangle(spriteBatch, pos, rectSize, Color.Black * 0.8f, true);
|
||||||
@@ -370,10 +404,20 @@ namespace Barotrauma
|
|||||||
doubleClickedItem = item;
|
doubleClickedItem = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
//selectedSlot = slotIndex;
|
if (draggingItem != Items[slotIndex])
|
||||||
TryPutItem(draggingItem, slotIndex, true, true);
|
{
|
||||||
draggingItem = null;
|
//selectedSlot = slotIndex;
|
||||||
draggingSlot = null;
|
if (TryPutItem(draggingItem, slotIndex, true, true))
|
||||||
|
{
|
||||||
|
if (slots != null) slots[slotIndex].ShowBorderHighlight(Color.White, 0.1f, 0.4f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (slots != null) slots[slotIndex].ShowBorderHighlight(Color.Red, 0.1f, 0.9f);
|
||||||
|
}
|
||||||
|
draggingItem = null;
|
||||||
|
draggingSlot = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -471,6 +515,14 @@ namespace Barotrauma
|
|||||||
|
|
||||||
GUI.DrawRectangle(spriteBatch, rect, (slot.IsHighlighted ? Color.Red * 0.4f : slot.Color), false);
|
GUI.DrawRectangle(spriteBatch, rect, (slot.IsHighlighted ? Color.Red * 0.4f : slot.Color), false);
|
||||||
|
|
||||||
|
if (slot.BorderHighlightColor != Color.Transparent)
|
||||||
|
{
|
||||||
|
Rectangle highlightRect = slot.Rect;
|
||||||
|
highlightRect.Inflate(3,3);
|
||||||
|
|
||||||
|
GUI.DrawRectangle(spriteBatch, highlightRect, slot.BorderHighlightColor, false, 0, 5);
|
||||||
|
}
|
||||||
|
|
||||||
if (item == null || !drawItem) return;
|
if (item == null || !drawItem) return;
|
||||||
|
|
||||||
item.Sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), item.Color);
|
item.Sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), item.Color);
|
||||||
|
|||||||
Reference in New Issue
Block a user