38f1ddb...178a853: v0.8.9.1, removed content folder
This commit is contained in:
@@ -1,91 +1,78 @@
|
||||
using Barotrauma.Items.Components;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
partial class CharacterInventory : Inventory
|
||||
{
|
||||
private static Texture2D icons;
|
||||
{
|
||||
public enum Layout
|
||||
{
|
||||
Default,
|
||||
Left,
|
||||
Right,
|
||||
Center
|
||||
}
|
||||
|
||||
private enum QuickUseAction
|
||||
{
|
||||
None,
|
||||
Equip,
|
||||
Unequip,
|
||||
Drop,
|
||||
TakeFromContainer,
|
||||
TakeFromCharacter,
|
||||
PutToContainer,
|
||||
PutToCharacter,
|
||||
UseTreatment
|
||||
}
|
||||
|
||||
private static Dictionary<InvSlotType, Sprite> limbSlotIcons;
|
||||
|
||||
private Point screenResolution;
|
||||
|
||||
public Vector2[] SlotPositions;
|
||||
|
||||
private GUIButton[] useOnSelfButton;
|
||||
|
||||
partial void InitProjSpecific()
|
||||
|
||||
private Layout layout;
|
||||
public Layout CurrentLayout
|
||||
{
|
||||
useOnSelfButton = new GUIButton[2];
|
||||
|
||||
if (icons == null) icons = TextureLoader.FromFile("Content/UI/inventoryIcons.png");
|
||||
|
||||
SlotPositions = new Vector2[limbSlots.Length];
|
||||
|
||||
int rectWidth = 40, rectHeight = 40;
|
||||
int spacing = 10;
|
||||
for (int i = 0; i < SlotPositions.Length; i++)
|
||||
get { return layout; }
|
||||
set
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
//head, torso, legs
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
SlotPositions[i] = new Vector2(
|
||||
spacing,
|
||||
GameMain.GraphicsHeight - (spacing + rectHeight) * (3 - i));
|
||||
break;
|
||||
//lefthand, righthand
|
||||
case 3:
|
||||
case 4:
|
||||
SlotPositions[i] = new Vector2(
|
||||
spacing * 2 + rectWidth + (spacing + rectWidth) * (i - 1),
|
||||
GameMain.GraphicsHeight - (spacing + rectHeight) * 3);
|
||||
|
||||
useOnSelfButton[i - 3] = new GUIButton(
|
||||
new Rectangle((int)SlotPositions[i].X, (int)(SlotPositions[i].Y - spacing - rectHeight),
|
||||
rectWidth, rectHeight), TextManager.Get("UseItemButton"), "")
|
||||
{
|
||||
UserData = i,
|
||||
OnClicked = UseItemOnSelf
|
||||
};
|
||||
|
||||
|
||||
break;
|
||||
//face
|
||||
case 5:
|
||||
SlotPositions[i] = new Vector2(
|
||||
spacing * 2 + rectWidth + (spacing + rectWidth) * (i - 5),
|
||||
GameMain.GraphicsHeight - (spacing + rectHeight) * 3);
|
||||
|
||||
break;
|
||||
//id card
|
||||
case 6:
|
||||
SlotPositions[i] = new Vector2(
|
||||
spacing * 2 + rectWidth + (spacing + rectWidth) * (i - 5),
|
||||
GameMain.GraphicsHeight - (spacing + rectHeight) * 3);
|
||||
|
||||
break;
|
||||
default:
|
||||
SlotPositions[i] = new Vector2(
|
||||
spacing * 2 + rectWidth + (spacing + rectWidth) * ((i - 7) % 5),
|
||||
GameMain.GraphicsHeight - (spacing + rectHeight) * ((i > 11) ? 2 : 1));
|
||||
break;
|
||||
}
|
||||
if (layout == value) return;
|
||||
layout = value;
|
||||
SetSlotPositions(layout);
|
||||
}
|
||||
}
|
||||
public bool Hidden { get; set; }
|
||||
|
||||
private bool UseItemOnSelf(GUIButton button, object obj)
|
||||
partial void InitProjSpecific(XElement element)
|
||||
{
|
||||
if (!(obj is int)) return false;
|
||||
Hidden = true;
|
||||
|
||||
int slotIndex = (int)obj;
|
||||
if (limbSlotIcons == null)
|
||||
{
|
||||
limbSlotIcons = new Dictionary<InvSlotType, Sprite>();
|
||||
|
||||
return UseItemOnSelf(slotIndex);
|
||||
int margin = 2;
|
||||
limbSlotIcons.Add(InvSlotType.Headset, new Sprite("Content/UI/IconAtlas.png", new Rectangle(384 + margin, 128 + margin, 128 - margin * 2, 128 - margin * 2)));
|
||||
limbSlotIcons.Add(InvSlotType.InnerClothes, new Sprite("Content/UI/IconAtlas.png", new Rectangle(512 + margin, 128 + margin, 128 - margin * 2, 128 - margin * 2)));
|
||||
limbSlotIcons.Add(InvSlotType.Card, new Sprite("Content/UI/IconAtlas.png", new Rectangle(640 + margin, 128 + margin, 128 - margin * 2, 128 - margin * 2)));
|
||||
limbSlotIcons.Add(InvSlotType.Head, new Sprite("Content/UI/IconAtlas.png", new Rectangle(896 + margin, 128 + margin, 128 - margin * 2, 128 - margin * 2)));
|
||||
limbSlotIcons.Add(InvSlotType.LeftHand, new Sprite("Content/UI/IconAtlas.png", new Rectangle(640 + margin, 383 + margin, 128 - margin * 2, 128 - margin * 2)));
|
||||
limbSlotIcons.Add(InvSlotType.RightHand, new Sprite("Content/UI/IconAtlas.png", new Rectangle(768 + margin, 383 + margin, 128 - margin * 2, 128 - margin * 2)));
|
||||
}
|
||||
|
||||
SlotPositions = new Vector2[SlotTypes.Length];
|
||||
CurrentLayout = Layout.Default;
|
||||
SetSlotPositions(layout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override void PutItem(Item item, int i, Character user, bool removeItem = true, bool createNetworkEvent = true)
|
||||
{
|
||||
base.PutItem(item, i, user, removeItem, createNetworkEvent);
|
||||
@@ -98,127 +85,400 @@ namespace Barotrauma
|
||||
CreateSlots();
|
||||
}
|
||||
|
||||
protected override void CreateSlots()
|
||||
public override void CreateSlots()
|
||||
{
|
||||
if (slots == null) slots = new InventorySlot[capacity];
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
InventorySlot prevSlot = slots[i];
|
||||
|
||||
Sprite slotSprite = slotSpriteSmall;
|
||||
Rectangle slotRect = new Rectangle(
|
||||
(int)(SlotPositions[i].X),
|
||||
(int)(SlotPositions[i].Y),
|
||||
(int)(slotSprite.size.X * UIScale), (int)(slotSprite.size.Y * UIScale));
|
||||
|
||||
int rectWidth = 40, rectHeight = 40;
|
||||
if (Items[i] != null)
|
||||
{
|
||||
ItemContainer itemContainer = Items[i].GetComponent<ItemContainer>();
|
||||
if (itemContainer != null)
|
||||
{
|
||||
if (itemContainer.InventoryTopSprite != null) slotRect.Width = Math.Max(slotRect.Width, (int)(itemContainer.InventoryTopSprite.size.X * UIScale));
|
||||
if (itemContainer.InventoryBottomSprite != null) slotRect.Width = Math.Max(slotRect.Width, (int)(itemContainer.InventoryBottomSprite.size.X * UIScale));
|
||||
}
|
||||
}
|
||||
|
||||
slots[i] = new InventorySlot(slotRect)
|
||||
{
|
||||
SubInventoryDir = Math.Sign(HUDLayoutSettings.InventoryAreaUpper.Bottom - slotRect.Center.Y),
|
||||
Disabled = false,
|
||||
SlotSprite = slotSprite,
|
||||
Color = SlotTypes[i] == InvSlotType.Any ? Color.White * 0.2f : Color.White * 0.4f
|
||||
};
|
||||
if (prevSlot != null)
|
||||
{
|
||||
slots[i].DrawOffset = prevSlot.DrawOffset;
|
||||
slots[i].Color = prevSlot.Color;
|
||||
}
|
||||
|
||||
if (selectedSlot?.ParentInventory == this && selectedSlot.SlotIndex == i)
|
||||
{
|
||||
selectedSlot = new SlotReference(this, slots[i], i, selectedSlot.IsSubSlot, selectedSlot.Inventory);
|
||||
}
|
||||
}
|
||||
|
||||
AssignQuickUseNumKeys();
|
||||
|
||||
highlightedSubInventorySlots.Clear();
|
||||
|
||||
screenResolution = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||
CalculateBackgroundFrame();
|
||||
}
|
||||
|
||||
protected override void CalculateBackgroundFrame()
|
||||
{
|
||||
Rectangle frame = Rectangle.Empty;
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (HideSlot(i)) continue;
|
||||
if (frame == Rectangle.Empty)
|
||||
{
|
||||
frame = slots[i].Rect;
|
||||
continue;
|
||||
}
|
||||
frame = Rectangle.Union(frame, slots[i].Rect);
|
||||
}
|
||||
frame.Inflate(10, 30);
|
||||
frame.Location -= new Point(0, 25);
|
||||
BackgroundFrame = frame;
|
||||
}
|
||||
|
||||
protected override bool HideSlot(int i)
|
||||
{
|
||||
if (slots[i].Disabled || (hideEmptySlot[i] && Items[i] == null)) return true;
|
||||
|
||||
//no need to draw the right hand slot if the item is in both hands
|
||||
if (Items[i] != null && SlotTypes[i] == InvSlotType.RightHand && IsInLimbSlot(Items[i], InvSlotType.LeftHand))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//don't show the equip slot if the item is also in the default inventory
|
||||
if (SlotTypes[i] != InvSlotType.Any && Items[i] != null)
|
||||
{
|
||||
for (int j = 0; j < capacity; j++)
|
||||
{
|
||||
if (SlotTypes[j] == InvSlotType.Any && Items[j] == Items[i]) return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void SetSlotPositions(Layout layout)
|
||||
{
|
||||
int spacing = (int)(10 * UIScale);
|
||||
Point slotSize = (slotSpriteSmall.size * UIScale).ToPoint();
|
||||
int bottomOffset = slotSize.Y + spacing * 2 + ContainedIndicatorHeight;
|
||||
|
||||
if (slots == null) CreateSlots();
|
||||
|
||||
var upperSlots = InvSlotType.Card | InvSlotType.Headset | InvSlotType.InnerClothes | InvSlotType.Head;
|
||||
|
||||
switch (layout)
|
||||
{
|
||||
case Layout.Default:
|
||||
{
|
||||
int personalSlotCount = SlotTypes.Count(s => upperSlots.HasFlag(s));
|
||||
int normalSlotCount = SlotTypes.Count(s => !upperSlots.HasFlag(s));
|
||||
|
||||
int x = GameMain.GraphicsWidth / 2 - normalSlotCount * (slotSize.X + spacing) / 2;
|
||||
int upperX = HUDLayoutSettings.PortraitArea.X - slotSize.X;
|
||||
|
||||
//make sure the rightmost normal slot doesn't overlap with the personal slots
|
||||
x -= Math.Max((x + normalSlotCount * (slotSize.X + spacing)) - (upperX - personalSlotCount * (slotSize.X + spacing)), 0);
|
||||
|
||||
for (int i = 0; i < SlotPositions.Length; i++)
|
||||
{
|
||||
if (upperSlots.HasFlag(SlotTypes[i]))
|
||||
{
|
||||
SlotPositions[i] = new Vector2(upperX, GameMain.GraphicsHeight - bottomOffset);
|
||||
upperX -= slotSize.X + spacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
SlotPositions[i] = new Vector2(x, GameMain.GraphicsHeight - bottomOffset);
|
||||
x += slotSize.X + spacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Layout.Right:
|
||||
{
|
||||
int extraOffset = 0;
|
||||
int x = HUDLayoutSettings.InventoryAreaLower.Right;
|
||||
int upperX = HUDLayoutSettings.InventoryAreaLower.Right;
|
||||
for (int i = 0; i < slots.Length; i++)
|
||||
{
|
||||
if (HideSlot(i)) continue;
|
||||
if (upperSlots.HasFlag(SlotTypes[i]))
|
||||
{
|
||||
upperX -= slotSize.X + spacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
x -= slotSize.X + spacing;
|
||||
}
|
||||
}
|
||||
|
||||
int lowerX = x;
|
||||
for (int i = 0; i < SlotPositions.Length; i++)
|
||||
{
|
||||
if (HideSlot(i)) continue;
|
||||
if (upperSlots.HasFlag(SlotTypes[i]))
|
||||
{
|
||||
SlotPositions[i] = new Vector2(upperX, GameMain.GraphicsHeight - bottomOffset * 2 - extraOffset - spacing * 2);
|
||||
upperX += slots[i].Rect.Width + spacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
SlotPositions[i] = new Vector2(x, GameMain.GraphicsHeight - bottomOffset - extraOffset);
|
||||
x += slots[i].Rect.Width + spacing;
|
||||
}
|
||||
}
|
||||
|
||||
x = lowerX;
|
||||
for (int i = 0; i < SlotPositions.Length; i++)
|
||||
{
|
||||
if (!HideSlot(i)) continue;
|
||||
x -= slots[i].Rect.Width + spacing;
|
||||
SlotPositions[i] = new Vector2(x, GameMain.GraphicsHeight - bottomOffset - extraOffset);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Layout.Left:
|
||||
{
|
||||
int x = HUDLayoutSettings.InventoryAreaLower.X;
|
||||
int upperX = x;
|
||||
for (int i = 0; i < SlotPositions.Length; i++)
|
||||
{
|
||||
if (HideSlot(i)) continue;
|
||||
if (upperSlots.HasFlag(SlotTypes[i]))
|
||||
{
|
||||
SlotPositions[i] = new Vector2(upperX, GameMain.GraphicsHeight - bottomOffset * 2 - spacing * 2);
|
||||
upperX += slots[i].Rect.Width + spacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
SlotPositions[i] = new Vector2(x, GameMain.GraphicsHeight - bottomOffset);
|
||||
x += slots[i].Rect.Width + spacing;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < SlotPositions.Length; i++)
|
||||
{
|
||||
if (!HideSlot(i)) continue;
|
||||
SlotPositions[i] = new Vector2(x, GameMain.GraphicsHeight - bottomOffset);
|
||||
x += slots[i].Rect.Width + spacing;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Layout.Center:
|
||||
{
|
||||
int columns = 5;
|
||||
int startX = (GameMain.GraphicsWidth / 2) - (slotSize.X * columns + spacing * (columns - 1)) / 2;
|
||||
int startY = GameMain.GraphicsHeight / 2 - (slotSize.Y * 2);
|
||||
int x = startX, y = startY;
|
||||
for (int i = 0; i < SlotPositions.Length; i++)
|
||||
{
|
||||
if (HideSlot(i)) continue;
|
||||
if (SlotTypes[i] == InvSlotType.Card || SlotTypes[i] == InvSlotType.Headset || SlotTypes[i] == InvSlotType.InnerClothes)
|
||||
{
|
||||
SlotPositions[i] = new Vector2(x, y);
|
||||
x += slots[i].Rect.Width + spacing;
|
||||
}
|
||||
}
|
||||
y += slots[0].Rect.Height + spacing + ContainedIndicatorHeight + slots[0].EquipButtonRect.Height;
|
||||
x = startX;
|
||||
int n = 0;
|
||||
for (int i = 0; i < SlotPositions.Length; i++)
|
||||
{
|
||||
if (HideSlot(i)) continue;
|
||||
if (SlotTypes[i] != InvSlotType.Card && SlotTypes[i] != InvSlotType.Headset && SlotTypes[i] != InvSlotType.InnerClothes)
|
||||
{
|
||||
SlotPositions[i] = new Vector2(x, y);
|
||||
x += slots[i].Rect.Width + spacing;
|
||||
n++;
|
||||
if (n >= columns)
|
||||
{
|
||||
x = startX;
|
||||
y += slots[i].Rect.Height + spacing + ContainedIndicatorHeight + slots[i].EquipButtonRect.Height;
|
||||
n = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
CreateSlots();
|
||||
if (layout == Layout.Default)
|
||||
{
|
||||
HUDLayoutSettings.InventoryTopY = slots[0].EquipButtonRect.Y - (int)(15 * GUI.Scale);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override void ControlInput(Camera cam)
|
||||
{
|
||||
base.ControlInput(cam);
|
||||
// Ignore the background frame of this object in purpose, because it encompasses half of the screen.
|
||||
if (highlightedSubInventorySlots.Any(i => i.Inventory != null && i.Inventory.BackgroundFrame.Contains(PlayerInput.MousePosition)))
|
||||
{
|
||||
cam.Freeze = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam, bool isSubInventory = false)
|
||||
{
|
||||
if (!AccessibleWhenAlive && !character.IsDead)
|
||||
{
|
||||
syncItemsDelay = Math.Max(syncItemsDelay - deltaTime, 0.0f);
|
||||
return;
|
||||
}
|
||||
|
||||
base.Update(deltaTime, cam);
|
||||
|
||||
bool hoverOnInventory = GUI.MouseOn == null &&
|
||||
((selectedSlot != null && selectedSlot.IsSubSlot) || (draggingItem != null && (draggingSlot == null || !draggingSlot.MouseOn())));
|
||||
if (CharacterHealth.OpenHealthWindow != null) hoverOnInventory = true;
|
||||
|
||||
if (hoverOnInventory) HideTimer = 0.5f;
|
||||
if (HideTimer > 0.0f) HideTimer -= deltaTime;
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
MergeSlots();
|
||||
}
|
||||
|
||||
|
||||
public override void Update(float deltaTime, bool isSubInventory = false)
|
||||
{
|
||||
base.Update(deltaTime);
|
||||
|
||||
if (doubleClickedItem != null)
|
||||
{
|
||||
bool wasPut = false;
|
||||
if (doubleClickedItem.ParentInventory != this)
|
||||
if (Items[i] != null && Items[i] != draggingItem && Character.Controlled?.Inventory == this &&
|
||||
GUI.KeyboardDispatcher.Subscriber == null &&
|
||||
slots[i].QuickUseKey != Keys.None && PlayerInput.KeyHit(slots[i].QuickUseKey))
|
||||
{
|
||||
wasPut = TryPutItem(doubleClickedItem, Character.Controlled, doubleClickedItem.AllowedSlots, true);
|
||||
QuickUseItem(Items[i], true, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
List<SlotReference> hideSubInventories = new List<SlotReference>();
|
||||
foreach (var highlightedSubInventorySlot in highlightedSubInventorySlots)
|
||||
{
|
||||
if (highlightedSubInventorySlot.ParentInventory == this)
|
||||
{
|
||||
UpdateSubInventory(deltaTime, highlightedSubInventorySlot.SlotIndex, cam);
|
||||
}
|
||||
|
||||
Rectangle hoverArea = GetSubInventoryHoverArea(highlightedSubInventorySlot);
|
||||
if (highlightedSubInventorySlot.Inventory?.slots == null || (!hoverArea.Contains(PlayerInput.MousePosition)))
|
||||
{
|
||||
hideSubInventories.Add(highlightedSubInventorySlot);
|
||||
}
|
||||
else
|
||||
{
|
||||
var selectedContainer = character.SelectedConstruction?.GetComponent<ItemContainer>();
|
||||
if (selectedContainer != null && selectedContainer.Inventory != null)
|
||||
highlightedSubInventorySlot.Inventory.HideTimer = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
if (doubleClickedItem != null)
|
||||
{
|
||||
QuickUseItem(doubleClickedItem, true, true, true);
|
||||
}
|
||||
|
||||
//activate the subinventory of the currently selected slot
|
||||
if (selectedSlot?.ParentInventory == this)
|
||||
{
|
||||
var subInventory = GetSubInventory(selectedSlot.SlotIndex);
|
||||
if (subInventory != null)
|
||||
{
|
||||
selectedSlot.Inventory = subInventory;
|
||||
if (!highlightedSubInventorySlots.Any(s => s.Inventory == subInventory))
|
||||
{
|
||||
wasPut = selectedContainer.Inventory.TryPutItem(doubleClickedItem, Character.Controlled, doubleClickedItem.AllowedSlots, true);
|
||||
}
|
||||
else if (character.SelectedCharacter != null && character.SelectedCharacter.Inventory != null)
|
||||
{
|
||||
wasPut = character.SelectedCharacter.Inventory.TryPutItem(doubleClickedItem, Character.Controlled, doubleClickedItem.AllowedSlots, true);
|
||||
}
|
||||
else if (character.SelectedBy != null && Character.Controlled == character.SelectedBy && character.SelectedBy.Inventory != null)
|
||||
{
|
||||
wasPut = character.SelectedBy.Inventory.TryPutItem(doubleClickedItem, Character.Controlled, doubleClickedItem.AllowedSlots, true);
|
||||
}
|
||||
else //doubleclicked and no other inventory is selected
|
||||
{
|
||||
//not equipped -> attempt to equip
|
||||
if (IsInLimbSlot(doubleClickedItem, InvSlotType.Any))
|
||||
var slot = selectedSlot;
|
||||
highlightedSubInventorySlots.Add(selectedSlot);
|
||||
UpdateSubInventory(deltaTime, selectedSlot.SlotIndex, cam);
|
||||
|
||||
//hide previously opened subinventories if this one overlaps with them
|
||||
Rectangle hoverArea = GetSubInventoryHoverArea(slot);
|
||||
foreach (SlotReference highlightedSubInventorySlot in highlightedSubInventorySlots)
|
||||
{
|
||||
for (int i = 0; i < capacity; i++)
|
||||
if (highlightedSubInventorySlot == slot) continue;
|
||||
if (hoverArea.Intersects(GetSubInventoryHoverArea(highlightedSubInventorySlot)))
|
||||
{
|
||||
if (limbSlots[i] == InvSlotType.Any || !doubleClickedItem.AllowedSlots.Any(a => a.HasFlag(limbSlots[i]))) continue;
|
||||
wasPut = TryPutItem(doubleClickedItem, i, true, false, Character.Controlled, true);
|
||||
if (wasPut) break;
|
||||
hideSubInventories.Add(highlightedSubInventorySlot);
|
||||
highlightedSubInventorySlot.Inventory.HideTimer = 0.0f;
|
||||
}
|
||||
}
|
||||
//equipped -> attempt to unequip
|
||||
else if (doubleClickedItem.AllowedSlots.Contains(InvSlotType.Any))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var subInventorySlot in hideSubInventories)
|
||||
{
|
||||
if (subInventorySlot.Inventory == null) continue;
|
||||
subInventorySlot.Inventory.HideTimer -= deltaTime;
|
||||
if (subInventorySlot.Inventory.HideTimer <= 0.0f)
|
||||
{
|
||||
highlightedSubInventorySlots.Remove(subInventorySlot);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (Items[i] != null && Items[i].AllowedSlots.Any(a => a != InvSlotType.Any))
|
||||
{
|
||||
slots[i].EquipButtonState = slots[i].EquipButtonRect.Contains(PlayerInput.MousePosition) ?
|
||||
GUIComponent.ComponentState.Hover : GUIComponent.ComponentState.None;
|
||||
if (PlayerInput.LeftButtonHeld() && PlayerInput.RightButtonHeld())
|
||||
{
|
||||
slots[i].EquipButtonState = GUIComponent.ComponentState.None;
|
||||
}
|
||||
|
||||
if (slots[i].EquipButtonState != GUIComponent.ComponentState.Hover)
|
||||
{
|
||||
slots[i].QuickUseTimer = Math.Max(0.0f, slots[i].QuickUseTimer - deltaTime * 5.0f);
|
||||
continue;
|
||||
}
|
||||
|
||||
var quickUseAction = GetQuickUseAction(Items[i], allowEquip: true, allowInventorySwap: false, allowApplyTreatment: false);
|
||||
slots[i].QuickUseButtonToolTip = quickUseAction == QuickUseAction.None ?
|
||||
"" : TextManager.Get("QuickUseAction." + quickUseAction.ToString());
|
||||
|
||||
//equipped item that can't be put in the inventory, use delayed dropping
|
||||
if (quickUseAction == QuickUseAction.Drop)
|
||||
{
|
||||
slots[i].QuickUseButtonToolTip = "Hold to unequip";
|
||||
if (PlayerInput.LeftButtonHeld())
|
||||
{
|
||||
wasPut = TryPutItem(doubleClickedItem, Character.Controlled, new List<InvSlotType>() { InvSlotType.Any }, true);
|
||||
slots[i].QuickUseTimer = Math.Max(0.1f, slots[i].QuickUseTimer + deltaTime);
|
||||
if (slots[i].QuickUseTimer >= 1.0f)
|
||||
{
|
||||
CreateNetworkEvent();
|
||||
Items[i].Drop(Character.Controlled);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
slots[i].QuickUseTimer = Math.Max(0.0f, slots[i].QuickUseTimer - deltaTime * 5.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wasPut)
|
||||
{
|
||||
for (int i = 0; i < capacity; i++)
|
||||
else
|
||||
{
|
||||
if (Items[i] == doubleClickedItem) slots[i].ShowBorderHighlight(Color.Green, 0.1f, 0.9f);
|
||||
}
|
||||
}
|
||||
|
||||
draggingItem = null;
|
||||
GUI.PlayUISound(wasPut ? GUISoundType.PickItem : GUISoundType.PickItemFail);
|
||||
}
|
||||
|
||||
|
||||
if (highlightedSubInventorySlot != null)
|
||||
{
|
||||
if (highlightedSubInventorySlot.Inventory == this)
|
||||
{
|
||||
UpdateSubInventory(deltaTime, highlightedSubInventorySlot.SlotIndex);
|
||||
}
|
||||
|
||||
if (highlightedSubInventory.slots == null ||
|
||||
(!highlightedSubInventorySlot.Slot.InteractRect.Contains(PlayerInput.MousePosition) && !highlightedSubInventory.slots.Any(s => s.InteractRect.Contains(PlayerInput.MousePosition))))
|
||||
{
|
||||
highlightedSubInventory = null;
|
||||
highlightedSubInventorySlot = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (selectedSlot?.Inventory == this)
|
||||
{
|
||||
var subInventory = GetSubInventory(selectedSlot.SlotIndex);
|
||||
if (subInventory != null)
|
||||
{
|
||||
highlightedSubInventory = subInventory;
|
||||
highlightedSubInventorySlot = selectedSlot;
|
||||
UpdateSubInventory(deltaTime, highlightedSubInventorySlot.SlotIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (character == Character.Controlled)
|
||||
{
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if ((selectedSlot == null || selectedSlot.SlotIndex != i) &&
|
||||
Items[i] != null && Items[i].CanUseOnSelf && character.HasSelectedItem(Items[i]))
|
||||
{
|
||||
//-3 because selected items are in slots 3 and 4 (hands)
|
||||
useOnSelfButton[i - 3].Update(deltaTime);
|
||||
if (PlayerInput.LeftButtonDown()) slots[i].EquipButtonState = GUIComponent.ComponentState.Pressed;
|
||||
if (PlayerInput.LeftButtonClicked())
|
||||
{
|
||||
QuickUseItem(Items[i], allowEquip: true, allowInventorySwap: false, allowApplyTreatment: false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//cancel dragging if too far away from the container of the dragged item
|
||||
if (draggingItem != null)
|
||||
@@ -228,8 +488,7 @@ namespace Barotrauma
|
||||
|
||||
if (rootContainer != null)
|
||||
{
|
||||
rootInventory = rootContainer.ParentInventory != null ?
|
||||
rootContainer.ParentInventory : rootContainer.GetComponent<ItemContainer>().Inventory;
|
||||
rootInventory = rootContainer.ParentInventory ?? rootContainer.GetComponent<ItemContainer>().Inventory;
|
||||
}
|
||||
|
||||
if (rootInventory != null &&
|
||||
@@ -237,98 +496,268 @@ namespace Barotrauma
|
||||
rootInventory.Owner != Character.Controlled.SelectedConstruction &&
|
||||
rootInventory.Owner != Character.Controlled.SelectedCharacter)
|
||||
{
|
||||
draggingItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
doubleClickedItem = null;
|
||||
}
|
||||
|
||||
private void MergeSlots()
|
||||
{
|
||||
for (int i = 0; i < capacity - 1; i++)
|
||||
{
|
||||
slots[i].State = GUIComponent.ComponentState.None;
|
||||
if (slots[i].Disabled || Items[i] == null) continue;
|
||||
|
||||
for (int n = i + 1; n < capacity; n++)
|
||||
{
|
||||
if (Items[n] == Items[i])
|
||||
//allow interacting if the container is linked to the item the character is interacting with
|
||||
if (!(rootContainer != null &&
|
||||
rootContainer.DisplaySideBySideWhenLinked &&
|
||||
Character.Controlled.SelectedConstruction != null &&
|
||||
rootContainer.linkedTo.Contains(Character.Controlled.SelectedConstruction)))
|
||||
{
|
||||
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;
|
||||
draggingItem = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
highlightedSubInventory = null;
|
||||
highlightedSubInventorySlot = null;
|
||||
selectedSlot = null;
|
||||
doubleClickedItem = null;
|
||||
}
|
||||
|
||||
private void AssignQuickUseNumKeys()
|
||||
{
|
||||
int num = 1;
|
||||
for (int i = 0; i < slots.Length; i++)
|
||||
{
|
||||
if (HideSlot(i))
|
||||
{
|
||||
slots[i].QuickUseKey = Keys.None;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (SlotTypes[i] == InvSlotType.Any)
|
||||
{
|
||||
slots[i].QuickUseKey = Keys.D0 + num % 10;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private QuickUseAction GetQuickUseAction(Item item, bool allowEquip, bool allowInventorySwap, bool allowApplyTreatment)
|
||||
{
|
||||
if (allowApplyTreatment && CharacterHealth.OpenHealthWindow != null)
|
||||
{
|
||||
return QuickUseAction.UseTreatment;
|
||||
}
|
||||
|
||||
if (item.ParentInventory != this)
|
||||
{
|
||||
//in another inventory -> attempt to place in the character's inventory
|
||||
if (allowInventorySwap)
|
||||
{
|
||||
return item.ParentInventory is CharacterInventory ?
|
||||
QuickUseAction.TakeFromCharacter : QuickUseAction.TakeFromContainer;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var selectedContainer = character.SelectedConstruction?.GetComponent<ItemContainer>();
|
||||
if (selectedContainer != null && selectedContainer.Inventory != null && allowInventorySwap)
|
||||
{
|
||||
//player has selected the inventory of another item -> attempt to move the item there
|
||||
return QuickUseAction.PutToContainer;
|
||||
}
|
||||
else if (character.SelectedCharacter != null && character.SelectedCharacter.Inventory != null && allowInventorySwap)
|
||||
{
|
||||
//player has selected the inventory of another character -> attempt to move the item there
|
||||
return QuickUseAction.PutToCharacter;
|
||||
}
|
||||
else if (character.SelectedBy != null && Character.Controlled == character.SelectedBy &&
|
||||
character.SelectedBy.Inventory != null && allowInventorySwap)
|
||||
{
|
||||
return QuickUseAction.TakeFromCharacter;
|
||||
}
|
||||
else if (allowEquip) //doubleclicked and no other inventory is selected
|
||||
{
|
||||
//not equipped -> attempt to equip
|
||||
if (!character.HasEquippedItem(item))
|
||||
{
|
||||
return QuickUseAction.Equip;
|
||||
}
|
||||
//equipped -> attempt to unequip
|
||||
else if (item.AllowedSlots.Contains(InvSlotType.Any))
|
||||
{
|
||||
return QuickUseAction.Unequip;
|
||||
}
|
||||
else
|
||||
{
|
||||
return QuickUseAction.Drop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QuickUseAction.None;
|
||||
}
|
||||
|
||||
private void QuickUseItem(Item item, bool allowEquip, bool allowInventorySwap, bool allowApplyTreatment)
|
||||
{
|
||||
var quickUseAction = GetQuickUseAction(item, allowEquip, allowInventorySwap, allowApplyTreatment);
|
||||
bool success = false;
|
||||
switch (quickUseAction)
|
||||
{
|
||||
case QuickUseAction.Equip:
|
||||
//attempt to put in a free slot first
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (Items[i] != null) continue;
|
||||
if (SlotTypes[i] == InvSlotType.Any || !item.AllowedSlots.Any(a => a.HasFlag(SlotTypes[i]))) continue;
|
||||
success = TryPutItem(item, i, true, false, Character.Controlled, true);
|
||||
if (success) break;
|
||||
}
|
||||
|
||||
if (!success)
|
||||
{
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (SlotTypes[i] == InvSlotType.Any || !item.AllowedSlots.Any(a => a.HasFlag(SlotTypes[i]))) continue;
|
||||
//something else already equipped in the slot, attempt to unequip it
|
||||
if (Items[i] != null && Items[i].AllowedSlots.Contains(InvSlotType.Any))
|
||||
{
|
||||
TryPutItem(Items[i], Character.Controlled, new List<InvSlotType>() { InvSlotType.Any }, true);
|
||||
}
|
||||
success = TryPutItem(item, i, true, false, Character.Controlled, true);
|
||||
if (success) break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QuickUseAction.Unequip:
|
||||
if (item.AllowedSlots.Contains(InvSlotType.Any))
|
||||
{
|
||||
success = TryPutItem(item, Character.Controlled, new List<InvSlotType>() { InvSlotType.Any }, true);
|
||||
}
|
||||
break;
|
||||
case QuickUseAction.UseTreatment:
|
||||
CharacterHealth.OpenHealthWindow?.OnItemDropped(item, ignoreMousePos: true);
|
||||
return;
|
||||
case QuickUseAction.Drop:
|
||||
//do nothing, the item is dropped after a delay
|
||||
return;
|
||||
case QuickUseAction.PutToCharacter:
|
||||
if (character.SelectedCharacter != null && character.SelectedCharacter.Inventory != null)
|
||||
{
|
||||
//player has selected the inventory of another character -> attempt to move the item there
|
||||
success = character.SelectedCharacter.Inventory.TryPutItem(item, Character.Controlled, item.AllowedSlots, true);
|
||||
}
|
||||
break;
|
||||
case QuickUseAction.PutToContainer:
|
||||
var selectedContainer = character.SelectedConstruction?.GetComponent<ItemContainer>();
|
||||
if (selectedContainer != null && selectedContainer.Inventory != null)
|
||||
{
|
||||
//player has selected the inventory of another item -> attempt to move the item there
|
||||
success = selectedContainer.Inventory.TryPutItem(item, Character.Controlled, item.AllowedSlots, true);
|
||||
}
|
||||
break;
|
||||
case QuickUseAction.TakeFromCharacter:
|
||||
if (character.SelectedBy != null && Character.Controlled == character.SelectedBy &&
|
||||
character.SelectedBy.Inventory != null)
|
||||
{
|
||||
//item is in the inventory of another character -> attempt to get the item from there
|
||||
success = character.SelectedBy.Inventory.TryPutItem(item, Character.Controlled, item.AllowedSlots, true);
|
||||
}
|
||||
break;
|
||||
case QuickUseAction.TakeFromContainer:
|
||||
success = TryPutItem(item, Character.Controlled, item.AllowedSlots, true);
|
||||
break;
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (Items[i] == item) slots[i].ShowBorderHighlight(Color.Green, 0.1f, 0.4f);
|
||||
}
|
||||
}
|
||||
|
||||
draggingItem = null;
|
||||
GUI.PlayUISound(success ? GUISoundType.PickItem : GUISoundType.PickItemFail);
|
||||
}
|
||||
|
||||
public void DrawOwn(SpriteBatch spriteBatch)
|
||||
{
|
||||
if (!AccessibleWhenAlive && !character.IsDead) return;
|
||||
if (slots == null) CreateSlots();
|
||||
|
||||
Rectangle slotRect = new Rectangle(0, 0, 40, 40);
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
if (GameMain.GraphicsWidth != screenResolution.X ||
|
||||
GameMain.GraphicsHeight != screenResolution.Y ||
|
||||
prevUIScale != UIScale ||
|
||||
prevHUDScale != GUI.Scale)
|
||||
{
|
||||
slotRect.X = (int)(SlotPositions[i].X + DrawOffset.X);
|
||||
slotRect.Y = (int)(SlotPositions[i].Y + DrawOffset.Y);
|
||||
SetSlotPositions(layout);
|
||||
prevUIScale = UIScale;
|
||||
prevHUDScale = GUI.Scale;
|
||||
}
|
||||
|
||||
if (i == 1) //head
|
||||
{
|
||||
spriteBatch.Draw(icons, new Vector2(slotRect.Center.X, slotRect.Center.Y),
|
||||
new Rectangle(0, 0, 56, 128), Color.White * 0.7f, 0.0f,
|
||||
new Vector2(28.0f, 64.0f), Vector2.One,
|
||||
SpriteEffects.None, 0.1f);
|
||||
}
|
||||
else if (i == 3 || i == 4)
|
||||
{
|
||||
spriteBatch.Draw(icons, new Vector2(slotRect.Center.X, slotRect.Center.Y),
|
||||
new Rectangle(92, 41 * (4 - i), 36, 40), Color.White * 0.7f, 0.0f,
|
||||
new Vector2(18.0f, 20.0f), Vector2.One,
|
||||
SpriteEffects.None, 0.1f);
|
||||
}
|
||||
else if (i == 5)
|
||||
{
|
||||
spriteBatch.Draw(icons, new Vector2(slotRect.Center.X, slotRect.Center.Y),
|
||||
new Rectangle(57, 0, 31, 32), Color.White * 0.7f, 0.0f,
|
||||
new Vector2(15.0f, 16.0f), Vector2.One,
|
||||
SpriteEffects.None, 0.1f);
|
||||
}
|
||||
else if (i == 6)
|
||||
{
|
||||
spriteBatch.Draw(icons, new Vector2(slotRect.Center.X, slotRect.Center.Y),
|
||||
new Rectangle(62, 36, 22, 18), Color.White * 0.7f, 0.0f,
|
||||
new Vector2(11.0f, 9.0f), Vector2.One,
|
||||
SpriteEffects.None, 0.1f);
|
||||
}
|
||||
if (layout == Layout.Center)
|
||||
{
|
||||
CalculateBackgroundFrame();
|
||||
GUI.DrawRectangle(spriteBatch, BackgroundFrame, Color.Black * 0.8f, true);
|
||||
GUI.DrawString(spriteBatch,
|
||||
new Vector2((int)(BackgroundFrame.Center.X - GUI.Font.MeasureString(character.Name).X / 2), (int)BackgroundFrame.Y + 5),
|
||||
character.Name, Color.White * 0.9f);
|
||||
}
|
||||
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
if (character == Character.Controlled)
|
||||
InventorySlot highlightedQuickUseSlot = null;
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
for (int i = 0; i < capacity; i++)
|
||||
if (HideSlot(i)) continue;
|
||||
|
||||
if (Items[i] == null ||
|
||||
(draggingItem == Items[i] && !slots[i].InteractRect.Contains(PlayerInput.MousePosition)) ||
|
||||
!Items[i].AllowedSlots.Any(a => a != InvSlotType.Any))
|
||||
{
|
||||
if ((selectedSlot == null || selectedSlot.SlotIndex != i) &&
|
||||
Items[i] != null && Items[i].CanUseOnSelf && character.HasSelectedItem(Items[i]))
|
||||
//draw limb icons on empty slots
|
||||
if (limbSlotIcons.ContainsKey(SlotTypes[i]))
|
||||
{
|
||||
useOnSelfButton[i - 3].Draw(spriteBatch);
|
||||
var icon = limbSlotIcons[SlotTypes[i]];
|
||||
icon.Draw(spriteBatch, slots[i].Rect.Center.ToVector2(), Color.White * 0.3f, origin: icon.size / 2, scale: slots[i].Rect.Width / icon.size.X);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (draggingItem == Items[i] && !slots[i].IsHighlighted) continue;
|
||||
|
||||
//draw hand icons if the item is equipped in a hand slot
|
||||
if (IsInLimbSlot(Items[i], InvSlotType.LeftHand))
|
||||
{
|
||||
var icon = limbSlotIcons[InvSlotType.LeftHand];
|
||||
icon.Draw(spriteBatch, new Vector2(slots[i].Rect.X, slots[i].Rect.Bottom), Color.White * 0.6f, origin: new Vector2(icon.size.X * 0.35f, icon.size.Y * 0.75f), scale: slots[i].Rect.Width / icon.size.X * 0.7f);
|
||||
}
|
||||
if (IsInLimbSlot(Items[i], InvSlotType.RightHand))
|
||||
{
|
||||
var icon = limbSlotIcons[InvSlotType.RightHand];
|
||||
icon.Draw(spriteBatch, new Vector2(slots[i].Rect.Right, slots[i].Rect.Bottom), Color.White * 0.6f, origin: new Vector2(icon.size.X * 0.65f, icon.size.Y * 0.75f), scale: slots[i].Rect.Width / icon.size.X * 0.7f);
|
||||
}
|
||||
|
||||
Color color = slots[i].EquipButtonState == GUIComponent.ComponentState.Pressed ? Color.Gray : Color.White * 0.8f;
|
||||
if (slots[i].EquipButtonState == GUIComponent.ComponentState.Hover)
|
||||
{
|
||||
color = Color.White;
|
||||
highlightedQuickUseSlot = slots[i];
|
||||
}
|
||||
|
||||
var quickUseIndicator = Items[i].AllowedSlots.Any(a => a == InvSlotType.Any) ?
|
||||
EquipIndicator : DropIndicator;
|
||||
var quickUseHighlight = Items[i].AllowedSlots.Any(a => a == InvSlotType.Any) ?
|
||||
EquipIndicatorHighlight : DropIndicatorHighlight;
|
||||
|
||||
quickUseIndicator.Draw(spriteBatch, slots[i].EquipButtonRect.Center.ToVector2(), color, quickUseIndicator.Origin, 0, UIScale);
|
||||
slots[i].QuickUseTimer = Math.Min(slots[i].QuickUseTimer, 1.0f);
|
||||
if (slots[i].QuickUseTimer > 0.0f)
|
||||
{
|
||||
float indicatorFillAmount = character.HasEquippedItem(Items[i]) ? 1.0f - slots[i].QuickUseTimer : slots[i].QuickUseTimer;
|
||||
quickUseHighlight.DrawTiled(spriteBatch,
|
||||
slots[i].EquipButtonRect.Center.ToVector2() - quickUseHighlight.Origin * UIScale * 0.85f,
|
||||
new Vector2(quickUseIndicator.SourceRect.Width * indicatorFillAmount, quickUseIndicator.SourceRect.Height) * UIScale * 0.85f,
|
||||
null,
|
||||
color * 0.9f,
|
||||
null,
|
||||
Vector2.One * UIScale * 0.85f);
|
||||
}
|
||||
else if (character.HasEquippedItem(Items[i]))
|
||||
{
|
||||
quickUseHighlight.Draw(spriteBatch, slots[i].EquipButtonRect.Center.ToVector2(), color * 0.9f, quickUseHighlight.Origin, 0, UIScale * 0.85f);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
if (highlightedQuickUseSlot != null && !string.IsNullOrEmpty(highlightedQuickUseSlot.QuickUseButtonToolTip))
|
||||
{
|
||||
if (slots[i].IsHighlighted)
|
||||
{
|
||||
DrawSubInventory(spriteBatch, i);
|
||||
}
|
||||
GUIComponent.DrawToolTip(spriteBatch, highlightedQuickUseSlot.QuickUseButtonToolTip, highlightedQuickUseSlot.EquipButtonRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user