Inventory slots are highlighted if the cursor is within 5 pixels of the rect. The spacing between inventory slots is 10 px, so now items can't be accidentally dropped by releasing the cursor between slots.
This commit is contained in:
@@ -95,18 +95,15 @@ namespace Barotrauma
|
||||
|
||||
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].Rect = slotRect;
|
||||
Rectangle slotRect = new Rectangle(
|
||||
(int)(SlotPositions[i].X + DrawOffset.X),
|
||||
(int)(SlotPositions[i].Y + DrawOffset.Y),
|
||||
rectWidth, rectHeight);
|
||||
|
||||
slots[i] = new InventorySlot(slotRect);
|
||||
slots[i].Disabled = false;
|
||||
slots[i].Color = limbSlots[i] == InvSlotType.Any ? Color.White * 0.2f : Color.White * 0.4f;
|
||||
}
|
||||
|
||||
@@ -182,7 +179,7 @@ namespace Barotrauma
|
||||
if (rootContainer != null)
|
||||
{
|
||||
rootInventory = rootContainer.ParentInventory != null ?
|
||||
rootContainer.ParentInventory : rootContainer.GetComponent<Items.Components.ItemContainer>().Inventory;
|
||||
rootContainer.ParentInventory : rootContainer.GetComponent<ItemContainer>().Inventory;
|
||||
}
|
||||
|
||||
if (rootInventory != null &&
|
||||
@@ -209,6 +206,7 @@ namespace Barotrauma
|
||||
if (Items[n] == Items[i])
|
||||
{
|
||||
slots[i].Rect = Rectangle.Union(slots[i].Rect, slots[n].Rect);
|
||||
slots[i].InteractRect = Rectangle.Union(slots[i].InteractRect, slots[n].InteractRect);
|
||||
slots[n].Disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace Barotrauma
|
||||
{
|
||||
public Rectangle Rect;
|
||||
|
||||
public Rectangle InteractRect;
|
||||
|
||||
public bool Disabled;
|
||||
|
||||
public GUIComponent.ComponentState State;
|
||||
@@ -30,6 +32,8 @@ namespace Barotrauma
|
||||
public InventorySlot(Rectangle rect)
|
||||
{
|
||||
Rect = rect;
|
||||
InteractRect = rect;
|
||||
InteractRect.Inflate(5, 5);
|
||||
State = GUIComponent.ComponentState.None;
|
||||
Color = Color.White * 0.4f;
|
||||
}
|
||||
@@ -151,7 +155,7 @@ namespace Barotrauma
|
||||
|
||||
|
||||
if (draggingItem != null &&
|
||||
(draggingSlot == null || (!draggingSlot.Rect.Contains(PlayerInput.MousePosition) && draggingItem.ParentInventory == this)))
|
||||
(draggingSlot == null || (!draggingSlot.InteractRect.Contains(PlayerInput.MousePosition) && draggingItem.ParentInventory == this)))
|
||||
{
|
||||
if (!PlayerInput.LeftButtonHeld())
|
||||
{
|
||||
@@ -166,7 +170,7 @@ namespace Barotrauma
|
||||
|
||||
protected void UpdateSlot(InventorySlot slot, int slotIndex, Item item, bool isSubSlot)
|
||||
{
|
||||
bool mouseOn = slot.Rect.Contains(PlayerInput.MousePosition) && !Locked;
|
||||
bool mouseOn = slot.InteractRect.Contains(PlayerInput.MousePosition) && !Locked;
|
||||
|
||||
slot.State = GUIComponent.ComponentState.None;
|
||||
|
||||
@@ -268,7 +272,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
if (draggingItem != null &&
|
||||
(draggingSlot == null || (!draggingSlot.Rect.Contains(PlayerInput.MousePosition) && draggingItem.ParentInventory == this)))
|
||||
(draggingSlot == null || (!draggingSlot.InteractRect.Contains(PlayerInput.MousePosition) && draggingItem.ParentInventory == this)))
|
||||
{
|
||||
Rectangle dragRect = new Rectangle(
|
||||
(int)PlayerInput.MousePosition.X - 10,
|
||||
|
||||
Reference in New Issue
Block a user