diff --git a/Subsurface/Content/Map/TutorialSub.sub b/Subsurface/Content/Map/TutorialSub.sub index d2d8b438d..3385b8c3d 100644 Binary files a/Subsurface/Content/Map/TutorialSub.sub and b/Subsurface/Content/Map/TutorialSub.sub differ diff --git a/Subsurface/Source/GUI/GUI.cs b/Subsurface/Source/GUI/GUI.cs index b94bed623..6fe2dda61 100644 --- a/Subsurface/Source/GUI/GUI.cs +++ b/Subsurface/Source/GUI/GUI.cs @@ -264,10 +264,11 @@ namespace Barotrauma } 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, 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.Width - thickness * 2, 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.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); } } diff --git a/Subsurface/Source/Items/CharacterInventory.cs b/Subsurface/Source/Items/CharacterInventory.cs index a9bebe31f..e6be4a82d 100644 --- a/Subsurface/Source/Items/CharacterInventory.cs +++ b/Subsurface/Source/Items/CharacterInventory.cs @@ -168,7 +168,7 @@ namespace Barotrauma if (allowedSlot.HasFlag(limbSlots[i]) && Items[i]!=null && Items[i]!=item) { free = false; - break; + if (slots != null) slots[i].ShowBorderHighlight(Color.Red, 0.1f, 0.9f); } } @@ -238,9 +238,8 @@ namespace Barotrauma TryPutItem(item, currentIndex, false); TryPutItem(existingItem, index, false); } - } - + return combined; } @@ -292,17 +291,21 @@ namespace Barotrauma protected override void CreateSlots() { - slots = new InventorySlot[capacity]; + if (slots == null) slots = new InventorySlot[capacity]; int rectWidth = 40, rectHeight = 40; Rectangle slotRect = new Rectangle(0, 0, rectWidth, rectHeight); for (int i = 0; i < capacity; i++) { + if (slots[i] == null) slots[i] = new InventorySlot(slotRect); + + slots[i].Disabled = false; + slotRect.X = (int)(SlotPositions[i].X + DrawOffset.X); 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; } diff --git a/Subsurface/Source/Items/Components/Door.cs b/Subsurface/Source/Items/Components/Door.cs index 1b56f16f1..3cfc48c47 100644 --- a/Subsurface/Source/Items/Components/Door.cs +++ b/Subsurface/Source/Items/Components/Door.cs @@ -378,7 +378,12 @@ namespace Barotrauma.Items.Components { base.RemoveComponentSpecific(); - GameMain.World.RemoveBody(body.FarseerBody); + if (body != null) + { + body.Remove(); + body = null; + } + if (linkedGap!=null) linkedGap.Remove(); diff --git a/Subsurface/Source/Items/Inventory.cs b/Subsurface/Source/Items/Inventory.cs index 5c1712b03..435ebea3f 100644 --- a/Subsurface/Source/Items/Inventory.cs +++ b/Subsurface/Source/Items/Inventory.cs @@ -28,6 +28,9 @@ namespace Barotrauma public Color Color; + public Color BorderHighlightColor; + private CoroutineHandle BorderHighlightCoroutine; + public InventorySlot(Rectangle rect) { Rect = rect; @@ -36,6 +39,33 @@ namespace Barotrauma 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 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 @@ -163,6 +193,7 @@ namespace Barotrauma } else { + if (slots != null) slots[i].ShowBorderHighlight(Color.Red, 0.1f, 0.9f); return false; } } @@ -179,6 +210,9 @@ namespace Barotrauma Items[i] = item; item.ParentInventory = this; + + if (slots != null) slots[i].ShowBorderHighlight(Color.White, 0.1f, 0.4f); + if (item.body != null) { item.body.Enabled = false; @@ -321,7 +355,7 @@ namespace Barotrauma Vector2 rectSize = textSize * 1.2f; 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; GUI.DrawRectangle(spriteBatch, pos, rectSize, Color.Black * 0.8f, true); @@ -368,10 +402,20 @@ namespace Barotrauma doubleClickedItem = item; } - //selectedSlot = slotIndex; - TryPutItem(draggingItem, slotIndex, true); - draggingItem = null; - draggingSlot = null; + if (draggingItem != Items[slotIndex]) + { + //selectedSlot = slotIndex; + if (TryPutItem(draggingItem, slotIndex, 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; + } } } } @@ -469,6 +513,14 @@ namespace Barotrauma 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; item.Sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), item.Color); diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index c4dc90d53..62e52ea6c 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -1770,14 +1770,17 @@ namespace Barotrauma int index = components.IndexOf(ic); } - public override void Remove() + public override void Remove() { base.Remove(); Removed = true; - //sprite.Remove(); - //if (body != null) body.Remove(); + if (parentInventory != null) + { + parentInventory.RemoveItem(this); + parentInventory = null; + } foreach (ItemComponent ic in components) { @@ -1785,14 +1788,20 @@ namespace Barotrauma } ItemList.Remove(this); + if (body != null) + { + body.Remove(); + body = null; + } + foreach (Item it in ItemList) { if (it.linkedTo.Contains(this)) { it.linkedTo.Remove(this); } - } + } } } -} +} \ No newline at end of file diff --git a/Subsurface/Submarines/Nehalennia.sub b/Subsurface/Submarines/Nehalennia.sub index 2f0998ed3..21f66d536 100644 Binary files a/Subsurface/Submarines/Nehalennia.sub and b/Subsurface/Submarines/Nehalennia.sub differ diff --git a/Subsurface/Submarines/TutorialSub.sub b/Subsurface/Submarines/TutorialSub.sub index e67996854..3385b8c3d 100644 Binary files a/Subsurface/Submarines/TutorialSub.sub and b/Subsurface/Submarines/TutorialSub.sub differ diff --git a/Subsurface/Submarines/Vellamo.sub b/Subsurface/Submarines/Vellamo.sub index 210ca0dfe..d0789b22a 100644 Binary files a/Subsurface/Submarines/Vellamo.sub and b/Subsurface/Submarines/Vellamo.sub differ