(99feac023) Unstable 0.9.704.0

This commit is contained in:
Joonas Rikkonen
2020-02-07 20:47:03 +02:00
parent 590619459b
commit 6754b9d5a2
104 changed files with 2224 additions and 1091 deletions
@@ -11,7 +11,7 @@ using System.Xml.Linq;
namespace Barotrauma
{
partial class CharacterInventory : Inventory
{
{
public enum Layout
{
Default,
@@ -35,13 +35,18 @@ namespace Barotrauma
}
private static Dictionary<InvSlotType, Sprite> limbSlotIcons;
private static Sprite inventoryBackgroundSprite, inventoryExtendButton, inventoryExtendUpArrow, inventoryExtendDownArrow;
public Rectangle InventoryToggleArea;
public bool InventoryToggleContains = false;
private Vector2 inventoryExtendButtonOffset, inventoryArrowOffset;
private int inventoryOpeningOffset;
public const InvSlotType PersonalSlots = InvSlotType.Card | InvSlotType.Headset | InvSlotType.InnerClothes | InvSlotType.OuterClothes | InvSlotType.Head;
private Point screenResolution;
public Vector2[] SlotPositions;
private Vector2 bgScale;
private Layout layout;
public Layout CurrentLayout
{
@@ -50,7 +55,7 @@ namespace Barotrauma
{
if (layout == value) return;
layout = value;
SetSlotPositions(layout);
SetSlotPositions();
}
}
public bool Hidden { get; set; }
@@ -59,6 +64,8 @@ namespace Barotrauma
private float hidePersonalSlotsState;
private GUIButton hideButton;
private Rectangle personalSlotArea;
private bool inventoryOpen = false;
private bool wasInventoryToggledAutomatically = false;
public bool HidePersonalSlots
{
@@ -103,10 +110,17 @@ namespace Barotrauma
limbSlotIcons.Add(InvSlotType.LeftHand, new Sprite("Content/UI/InventoryUIAtlas.png", new Rectangle(634, 0, 128, 128)));
limbSlotIcons.Add(InvSlotType.RightHand, new Sprite("Content/UI/InventoryUIAtlas.png", new Rectangle(762, 0, 128, 128)));
limbSlotIcons.Add(InvSlotType.OuterClothes, new Sprite("Content/UI/MainIconsAtlas.png", new Rectangle(256 + margin, 128 + margin, 128 - margin * 2, 128 - margin * 2)));
inventoryBackgroundSprite = new Sprite("Content/UI/InventoryUIAtlas.png", new Rectangle(252, 317, 263, 197));
inventoryExtendButton = new Sprite("Content/UI/InventoryUIAtlas.png", new Rectangle(533, 300, 96, 19));
inventoryExtendUpArrow = new Sprite("Content/UI/InventoryUIAtlas.png", new Rectangle(640, 310, 10, 10));
inventoryExtendDownArrow = new Sprite("Content/UI/InventoryUIAtlas.png", new Rectangle(668, 310, 10, 10));
}
SlotPositions = new Vector2[SlotTypes.Length];
CurrentLayout = Layout.Default;
SetSlotPositions(layout);
SetSlotPositions();
GameMain.Instance.OnResolutionChanged += SetSlotPositions;
}
protected override ItemInventory GetActiveEquippedSubInventory(int slotIndex)
@@ -193,31 +207,54 @@ namespace Barotrauma
}
}
screenResolution = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
CalculateBackgroundFrame();
}
protected override void CalculateBackgroundFrame()
{
Rectangle frame = Rectangle.Empty;
int firstSlotLocationY = 0;
int lastSlotLocationY = 0;
for (int i = 0; i < capacity; i++)
{
if (HideSlot(i)) continue;
if (PersonalSlots.HasFlag(SlotTypes[i])) continue;
if (IsHandSlot(SlotTypes[i])) continue;
if (frame == Rectangle.Empty)
{
firstSlotLocationY = slots[i].Rect.Location.Y;
frame = slots[i].Rect;
continue;
}
frame = Rectangle.Union(frame, slots[i].Rect);
lastSlotLocationY = slots[i].Rect.Location.Y;
}
frame.Inflate(10, 30);
frame.Location -= new Point(0, 25);
frame.Inflate(25f * UIScale, 25f * UIScale);
if (layout == Layout.Default)
{
inventoryOpeningOffset = firstSlotLocationY - lastSlotLocationY;
bgScale = new Vector2((float)frame.Width / (float)inventoryBackgroundSprite.SourceRect.Width, (float)frame.Height / (float)inventoryBackgroundSprite.SourceRect.Height);
inventoryExtendButtonOffset = new Vector2(inventoryExtendButton.size.X * UIScale * 1.5f / 2f, inventoryExtendButton.size.Y * UIScale * 1.5f / 2f + UIScale * 6);
inventoryArrowOffset = new Vector2(inventoryExtendUpArrow.size.X * UIScale * 1.25f / 2f, inventoryExtendUpArrow.size.Y * UIScale * 1.25f / 2f);
InventoryToggleArea = new Rectangle(new Point(frame.Center.X, frame.Top) - inventoryExtendButtonOffset.ToPoint(), inventoryExtendButton.size.ToPoint() + new Point(0, (int)(UIScale * 6f)));
if (!inventoryOpen)
{
frame.Offset(0, inventoryOpeningOffset);
InventoryToggleArea.Offset(0, inventoryOpeningOffset);
}
}
BackgroundFrame = frame;
}
protected override bool HideSlot(int i)
{
if (slots[i].Disabled || (hideEmptySlot[i] && Items[i] == null)) return true;
if (slots[i].Disabled) return true;
if (layout == Layout.Default)
{
@@ -230,19 +267,17 @@ namespace Barotrauma
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)
protected override bool IsSlotHiddenDueToToggleState(int i)
{
return layout == Layout.Default && !inventoryOpen && slots[i].QuickUseKey == Keys.None && SlotTypes[i] == InvSlotType.Any;
}
private void SetSlotPositions()
{
Layout layout = CurrentLayout;
int spacing = (int)(10 * UIScale);
Point slotSize = (SlotSpriteSmall.size * UIScale).ToPoint();
int bottomOffset = slotSize.Y + spacing * 2 + ContainedIndicatorHeight;
@@ -258,27 +293,47 @@ namespace Barotrauma
int personalSlotCount = SlotTypes.Count(s => PersonalSlots.HasFlag(s));
int normalSlotCount = SlotTypes.Count(s => !PersonalSlots.HasFlag(s));
int x = GameMain.GraphicsWidth / 2 - normalSlotCount * (slotSize.X + spacing) / 2;
int upperX = GameMain.GraphicsWidth - slotSize.X * 2;
int firstRowSlotCount = hotkeyCount > normalSlotCount ? normalSlotCount : hotkeyCount;
int startX = GameMain.GraphicsWidth / 2 - firstRowSlotCount * (slotSize.X + spacing) / 2;
int x = startX;
int equipmentX = GameMain.GraphicsWidth - slotSize.X * 2;
int buttonIndex = 0;
int startY = GameMain.GraphicsHeight - bottomOffset;
int y = startY;
int handIndex = 1;
//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);
x -= Math.Max(x + firstRowSlotCount * (slotSize.X + spacing) - (equipmentX - personalSlotCount * (slotSize.X + spacing)), 0);
int hideButtonSlotIndex = -1;
for (int i = 0; i < SlotPositions.Length; i++)
{
if (PersonalSlots.HasFlag(SlotTypes[i]))
{
SlotPositions[i] = new Vector2(upperX, GameMain.GraphicsHeight - bottomOffset);
upperX -= slotSize.X + spacing;
SlotPositions[i] = new Vector2(equipmentX, startY);
equipmentX -= slotSize.X + spacing;
personalSlotArea = (hideButtonSlotIndex == -1) ?
new Rectangle(SlotPositions[i].ToPoint(), slotSize) :
Rectangle.Union(personalSlotArea, new Rectangle(SlotPositions[i].ToPoint(), slotSize));
hideButtonSlotIndex = i;
}
else if (IsHandSlot(SlotTypes[i]))
{
SlotPositions[i] = new Vector2(startX - (slotSize.X + spacing * 4) - (slotSize.X + spacing) * handIndex, startY);
handIndex--;
}
else
{
SlotPositions[i] = new Vector2(x, GameMain.GraphicsHeight - bottomOffset);
if (buttonIndex >= hotkeyCount)
{
y -= bottomOffset;
buttonIndex = 0;
x = startX;
}
buttonIndex++;
SlotPositions[i] = new Vector2(x, y);
x += slotSize.X + spacing;
}
}
@@ -296,7 +351,6 @@ namespace Barotrauma
break;
case Layout.Right:
{
int extraOffset = 0;
int x = HUDLayoutSettings.InventoryAreaLower.Right;
int personalSlotX = HUDLayoutSettings.InventoryAreaLower.Right - slotSize.X - spacing;
for (int i = 0; i < slots.Length; i++)
@@ -307,24 +361,35 @@ namespace Barotrauma
//upperX -= slotSize.X + spacing;
}
else
{
x -= slotSize.X + spacing;
{
if (i < slots.Length - 5)
{
x -= slotSize.X + spacing;
}
}
}
int lowerX = x;
int y = GameMain.GraphicsHeight - bottomOffset;
for (int i = 0; i < SlotPositions.Length; i++)
{
if (HideSlot(i)) continue;
if (PersonalSlots.HasFlag(SlotTypes[i]))
{
SlotPositions[i] = new Vector2(personalSlotX, GameMain.GraphicsHeight - bottomOffset * 2 - extraOffset - spacing * 2);
SlotPositions[i] = new Vector2(personalSlotX, y - bottomOffset);
personalSlotX -= slots[i].Rect.Width + spacing;
}
else
{
SlotPositions[i] = new Vector2(x, GameMain.GraphicsHeight - bottomOffset - extraOffset);
SlotPositions[i] = new Vector2(x, y);
x += slots[i].Rect.Width + spacing;
if (i == SlotPositions.Length - 6)
{
x = lowerX + (slots[i].Rect.Width + spacing) * 2;
y -= bottomOffset;
}
}
}
@@ -333,28 +398,37 @@ namespace Barotrauma
{
if (!HideSlot(i)) continue;
x -= slots[i].Rect.Width + spacing;
SlotPositions[i] = new Vector2(x, GameMain.GraphicsHeight - bottomOffset - extraOffset);
SlotPositions[i] = new Vector2(x, y);
}
}
break;
case Layout.Left:
{
int x = HUDLayoutSettings.InventoryAreaLower.X;
int x = HUDLayoutSettings.InventoryAreaLower.Left;
int y = GameMain.GraphicsHeight - bottomOffset;
int personalSlotX = x;
for (int i = 0; i < SlotPositions.Length; i++)
{
if (HideSlot(i)) continue;
if (PersonalSlots.HasFlag(SlotTypes[i]))
{
SlotPositions[i] = new Vector2(personalSlotX, GameMain.GraphicsHeight - bottomOffset * 2 - spacing * 2);
SlotPositions[i] = new Vector2(personalSlotX, y - bottomOffset);
personalSlotX += slots[i].Rect.Width + spacing;
}
else
{
SlotPositions[i] = new Vector2(x, GameMain.GraphicsHeight - bottomOffset);
SlotPositions[i] = new Vector2(x, y);
x += slots[i].Rect.Width + spacing;
if (i == SlotPositions.Length - 7)
{
x -= (slots[i].Rect.Width + spacing) * 6;
y -= bottomOffset;
}
}
}
for (int i = 0; i < SlotPositions.Length; i++)
{
if (!HideSlot(i)) continue;
@@ -406,7 +480,11 @@ namespace Barotrauma
{
HUDLayoutSettings.InventoryTopY = slots[0].EquipButtonRect.Y - (int)(15 * GUI.Scale);
}
}
private bool IsHandSlot(InvSlotType slotType)
{
return slotType == InvSlotType.LeftHand || slotType == InvSlotType.RightHand;
}
protected override void ControlInput(Camera cam)
@@ -419,6 +497,32 @@ namespace Barotrauma
}
}
public void ToggleInventory(bool automaticToggle = false)
{
if (Character.Controlled == null || !Character.Controlled.IsHuman || wasInventoryToggledAutomatically || inventoryOpen && automaticToggle) return;
inventoryOpen = !inventoryOpen;
if (inventoryOpen)
{
wasInventoryToggledAutomatically = automaticToggle;
BackgroundFrame.Offset(0, -inventoryOpeningOffset);
InventoryToggleArea.Offset(0, -inventoryOpeningOffset);
}
else
{
BackgroundFrame.Offset(0, inventoryOpeningOffset);
InventoryToggleArea.Offset(0, inventoryOpeningOffset);
}
}
private void HandleAutomaticInventoryState()
{
if (wasInventoryToggledAutomatically && inventoryOpen && Character.Controlled.SelectedConstruction == null && Character.Controlled.SelectedCharacter == null)
{
wasInventoryToggledAutomatically = false;
ToggleInventory();
}
}
public override void Update(float deltaTime, Camera cam, bool isSubInventory = false)
{
if (!AccessibleWhenAlive && !character.IsDead)
@@ -427,6 +531,8 @@ namespace Barotrauma
return;
}
HandleAutomaticInventoryState();
base.Update(deltaTime, cam);
bool hoverOnInventory = GUI.MouseOn == null &&
@@ -460,7 +566,7 @@ namespace Barotrauma
for (int i = 0; i < capacity; i++)
{
if (Items[i] != null && Items[i] != draggingItem && Character.Controlled?.Inventory == this &&
GUI.KeyboardDispatcher.Subscriber == null &&
GUI.KeyboardDispatcher.Subscriber == null && !CrewManager.IsCommandInterfaceOpen &&
slots[i].QuickUseKey != Keys.None && PlayerInput.KeyHit(slots[i].QuickUseKey))
{
QuickUseItem(Items[i], true, false, true);
@@ -608,7 +714,10 @@ namespace Barotrauma
private void HandleButtonEquipStates(Item item, InventorySlot slot, float deltaTime)
{
slot.EquipButtonState = slot.EquipButtonRect.Contains(PlayerInput.MousePosition) ?
Rectangle modifiedRect = slot.EquipButtonRect;
modifiedRect.Width = slot.InteractRect.Width;
slot.EquipButtonState = modifiedRect.Contains(PlayerInput.MousePosition) ?
GUIComponent.ComponentState.Hover : GUIComponent.ComponentState.None;
if (PlayerInput.LeftButtonHeld() && PlayerInput.RightButtonHeld())
{
@@ -682,6 +791,8 @@ namespace Barotrauma
continue;
}
if (num > hotkeyCount) break;
if (SlotTypes[i] == InvSlotType.Any)
{
slots[i].QuickUseKey = Keys.D0 + num % 10;
@@ -827,7 +938,7 @@ namespace Barotrauma
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);
success = character.SelectedCharacter.Inventory.TryPutItem(item, Character.Controlled, item.AllowedSlots, true, true);
}
break;
case QuickUseAction.PutToContainer:
@@ -843,7 +954,7 @@ namespace Barotrauma
character.SelectedBy.Inventory != null)
{
//item is in the inventory of another character -> attempt to get the item from there
success = character.SelectedBy.Inventory.TryPutItemWithAutoEquipCheck(item, Character.Controlled, item.AllowedSlots, true);
success = character.SelectedBy.Inventory.TryPutItemWithAutoEquipCheck(item, Character.Controlled, item.AllowedSlots, true, true);
}
break;
case QuickUseAction.TakeFromContainer:
@@ -862,7 +973,7 @@ namespace Barotrauma
// No subinventory found or placing unsuccessful -> attempt to put in the character's inventory
if (!success)
{
success = TryPutItemWithAutoEquipCheck(item, Character.Controlled, item.AllowedSlots, true);
success = TryPutItemWithAutoEquipCheck(item, Character.Controlled, item.AllowedSlots, true, true);
}
break;
case QuickUseAction.PutToEquippedItem:
@@ -894,107 +1005,87 @@ namespace Barotrauma
GUI.PlayUISound(success ? GUISoundType.PickItem : GUISoundType.PickItemFail);
}
public void DrawOwn(SpriteBatch spriteBatch)
public void DrawThis(SpriteBatch spriteBatch)
{
if (!AccessibleWhenAlive && !character.IsDead) return;
if (slots == null) CreateSlots();
if (GameMain.GraphicsWidth != screenResolution.X ||
GameMain.GraphicsHeight != screenResolution.Y ||
prevUIScale != UIScale ||
prevHUDScale != GUI.Scale)
{
SetSlotPositions(layout);
prevUIScale = UIScale;
prevHUDScale = GUI.Scale;
}
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);
}
for (int i = 0; i < capacity; i++)
{
if (HideSlot(i)) continue;
Rectangle interactRect = slots[i].InteractRect;
interactRect.Location += slots[i].DrawOffset.ToPoint();
//don't draw the item if it's being dragged out of the slot
bool drawItem = draggingItem == null || draggingItem != Items[i] || interactRect.Contains(PlayerInput.MousePosition);
DrawSlot(spriteBatch, this, slots[i], Items[i], i, drawItem, SlotTypes[i]);
}
if (hideButton != null && hideButton.Visible && !Locked)
{
hideButton.DrawManually(spriteBatch, alsoChildren: true);
}
if (layout == Layout.Default)
{
inventoryBackgroundSprite.Draw(spriteBatch, BackgroundFrame.Location.ToVector2(), Color.White, Vector2.Zero, rotate: 0, scale: bgScale);
Vector2 backgroundFrameCenter = new Vector2(BackgroundFrame.Center.X, BackgroundFrame.Top);
inventoryExtendButton.Draw(spriteBatch, backgroundFrameCenter - inventoryExtendButtonOffset, Color.White, scale: UIScale * 1.5f);
Vector2 arrowPosition = backgroundFrameCenter - inventoryArrowOffset;
if (inventoryOpen)
{
inventoryExtendDownArrow.Draw(spriteBatch, arrowPosition, Color.White, scale: UIScale * 1.25f);
}
else
{
inventoryExtendUpArrow.Draw(spriteBatch, arrowPosition, Color.White, scale: UIScale * 1.25f);
}
GUI.DrawString(spriteBatch, arrowPosition + new Vector2(UIScale * 25, -3 * UIScale), GameMain.Config.KeyBindText(InputType.ToggleInventory), Color.White, font: GUI.HotkeyFont);
InventoryToggleContains = InventoryToggleArea.Contains(PlayerInput.MousePosition);
if (InventoryToggleContains && PlayerInput.PrimaryMouseButtonClicked())
{
ToggleInventory();
}
}
InventorySlot highlightedQuickUseSlot = null;
for (int i = 0; i < capacity; i++)
{
if (HideSlot(i)) continue;
if (IsSlotHiddenDueToToggleState(i)) continue;
if (Items[i] == null ||
(draggingItem == Items[i] && !slots[i].InteractRect.Contains(PlayerInput.MousePosition)) ||
!Items[i].AllowedSlots.Any(a => a != InvSlotType.Any))
InventorySlot slot = slots[i];
Item item = Items[i];
InvSlotType slotType = SlotTypes[i];
Rectangle interactRect = slot.InteractRect;
interactRect.Location += slot.DrawOffset.ToPoint();
//don't draw the item if it's being dragged out of the slot
bool drawItem = draggingItem == null || draggingItem != item || interactRect.Contains(PlayerInput.MousePosition);
DrawSlot(spriteBatch, this, slot, item, i, drawItem, slotType);
if (item == null || (draggingItem == item && !slot.InteractRect.Contains(PlayerInput.MousePosition)) || !item.AllowedSlots.Any(a => a != InvSlotType.Any))
{
//draw limb icons on empty slots
if (limbSlotIcons.ContainsKey(SlotTypes[i]))
if (limbSlotIcons.ContainsKey(slotType))
{
var icon = limbSlotIcons[SlotTypes[i]];
icon.Draw(spriteBatch, slots[i].Rect.Center.ToVector2() + slots[i].DrawOffset, GUIColorSettings.EquipmentSlotIconColor, origin: icon.size / 2, scale: slots[i].Rect.Width / icon.size.X);
var icon = limbSlotIcons[slotType];
icon.Draw(spriteBatch, slot.Rect.Center.ToVector2() + slot.DrawOffset, GUIColorSettings.EquipmentSlotIconColor, origin: icon.size / 2, scale: slot.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) + slots[i].DrawOffset, 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) + slots[i].DrawOffset, 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];
}
if (Locked) { color *= 0.3f; }
// Draw always on hotkeys
if (slot.QuickUseKey != Keys.None)
{
DrawIndicatorAndHotkey(spriteBatch, slot, slot.EquipButtonState == GUIComponent.ComponentState.Hover);
}
if (!Items[i].AllowedSlots.Any(a => a == InvSlotType.Any))
{
continue;
}
EquipIndicator.Draw(spriteBatch, slots[i].EquipButtonRect.Center.ToVector2(), color, EquipIndicator.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]))
{
EquipIndicatorHighlight.Draw(spriteBatch, slots[i].EquipButtonRect.Center.ToVector2(), color * 0.9f, EquipIndicatorHighlight.Origin, 0, UIScale * 0.85f);
}
if (draggingItem == item && !slot.IsHighlighted) continue;
bool hover = slot.EquipButtonState == GUIComponent.ComponentState.Hover;
if (hover) highlightedQuickUseSlot = slot;
if (!item.AllowedSlots.Any(a => a == InvSlotType.Any)) continue;
DrawIndicatorAndHotkey(spriteBatch, slot, hover);
}
if (highlightedQuickUseSlot != null && !string.IsNullOrEmpty(highlightedQuickUseSlot.QuickUseButtonToolTip))
@@ -1002,5 +1093,30 @@ namespace Barotrauma
GUIComponent.DrawToolTip(spriteBatch, highlightedQuickUseSlot.QuickUseButtonToolTip, highlightedQuickUseSlot.EquipButtonRect);
}
}
private void DrawIndicatorAndHotkey(SpriteBatch spriteBatch, InventorySlot slot, bool hover)
{
Color indicatorColor = (hover) ? Color.White : Color.White * 0.8f;
/*if (character.HasEquippedItem(item))
{
indicatorColor = hover ? GUIColorSettings.InventorySlotEquippedColor : GUIColorSettings.InventorySlotEquippedColor * 0.8f;
}
else
{
indicatorColor = hover ? GUIColorSettings.InventorySlotColor : GUIColorSettings.InventorySlotColor * 0.8f;
}*/
if (Locked) indicatorColor *= 0.3f;
Rectangle equipRect = slot.EquipButtonRect;
EquipIndicator.Draw(spriteBatch, new Vector2(equipRect.Center.X, equipRect.Bottom), indicatorColor, EquipIndicator.Origin, 0, UIScale * 0.6f);
if (slot.QuickUseKey != Keys.None)
{
GUI.DrawString(spriteBatch, new Vector2(slot.Rect.Center.X - 2, slot.Rect.Top), slot.QuickUseKey.ToString().Substring(1, 1), Color.Black, font: GUI.HotkeyFont);
}
}
}
}
@@ -114,7 +114,7 @@ namespace Barotrauma.Items.Components
shakeTimer -= deltaTime;
Vector2 noisePos = new Vector2((float)PerlinNoise.CalculatePerlin(shakeTimer * 10.0f, shakeTimer * 10.0f, 0) - 0.5f, (float)PerlinNoise.CalculatePerlin(shakeTimer * 10.0f, shakeTimer * 10.0f, 0.5f) - 0.5f);
shakePos = noisePos * shake * 2.0f;
shake = Math.Min(shake, shakeTimer);
shake = Math.Min(shake, shakeTimer * 10.0f);
}
else
{
@@ -36,7 +36,7 @@ namespace Barotrauma.Items.Components
var paddedFrame = new GUILayoutGroup(new RectTransform(new Vector2(0.90f, 0.80f), GuiFrame.RectTransform, Anchor.Center), childAnchor: Anchor.TopCenter)
{
Stretch = true,
RelativeSpacing = 0.02f
RelativeSpacing = 0.08f
};
var topFrame = new GUIFrame(new RectTransform(new Vector2(1f, 0.5f), paddedFrame.RectTransform), style: null);
@@ -51,15 +51,15 @@ namespace Barotrauma.Items.Components
inputLabel.RectTransform.Resize(new Point((int) inputLabel.Font.MeasureString(inputLabel.Text).X, inputLabel.RectTransform.Rect.Height));
new GUIFrame(new RectTransform(Vector2.One, inputLabelArea.RectTransform), style: "HorizontalLine");
var inputArea = new GUILayoutGroup(new RectTransform(new Vector2(1f, 1.2f), topFrame.RectTransform, Anchor.CenterLeft), childAnchor: Anchor.BottomLeft, isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f };
var inputArea = new GUILayoutGroup(new RectTransform(new Vector2(1f, 1f), topFrame.RectTransform, Anchor.CenterLeft), childAnchor: Anchor.BottomLeft, isHorizontal: true) { Stretch = true, RelativeSpacing = 0.05f };
// === INPUT SLOTS === //
inputInventoryHolder = new GUIFrame(new RectTransform(new Vector2(0.7f, 1f), inputArea.RectTransform), style: null);
inputInventoryOverlay = new GUICustomComponent(new RectTransform(Vector2.One, inputInventoryHolder.RectTransform), DrawOverLay, null) { CanBeFocused = false };
// === ACTIVATE BUTTON === //
var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.4f, 0.75f), inputArea.RectTransform), childAnchor: Anchor.CenterLeft);
activateButton = new GUIButton(new RectTransform(new Vector2(0.95f, 0.65f), buttonContainer.RectTransform), TextManager.Get("DeconstructorDeconstruct"), style: "DeviceButton")
var buttonContainer = new GUILayoutGroup(new RectTransform(new Vector2(0.4f, 0.7f), inputArea.RectTransform), childAnchor: Anchor.CenterLeft);
activateButton = new GUIButton(new RectTransform(new Vector2(0.95f, 0.8f), buttonContainer.RectTransform), TextManager.Get("DeconstructorDeconstruct"), style: "DeviceButton")
{
TextBlock = { AutoScaleHorizontal = true },
OnClicked = ToggleActive
@@ -87,7 +87,7 @@ namespace Barotrauma.Items.Components
new GUIFrame(new RectTransform(Vector2.One, outputLabelArea.RectTransform), style: "HorizontalLine");
// === OUTPUT SLOTS === //
outputInventoryHolder = new GUIFrame(new RectTransform(new Vector2(1f, 1.2f), bottomFrame.RectTransform, Anchor.CenterLeft), style: null);
outputInventoryHolder = new GUIFrame(new RectTransform(new Vector2(1f, 1f), bottomFrame.RectTransform, Anchor.CenterLeft), style: null);
}
public override bool Select(Character character)
@@ -299,6 +299,11 @@ namespace Barotrauma.Items.Components
foreach (FabricationRecipe.RequiredItem requiredItem in missingItems)
{
while (slotIndex < inputContainer.Capacity && inputContainer.Inventory.Items[slotIndex] != null)
{
slotIndex++;
}
//highlight suitable ingredients in linked inventories
foreach (Item item in availableIngredients)
{
@@ -311,26 +316,24 @@ namespace Barotrauma.Items.Components
{
if (item.ParentInventory.slots[availableSlotIndex].HighlightTimer <= 0.0f)
{
item.ParentInventory.slots[availableSlotIndex].ShowBorderHighlight(GUI.Style.Green * 0.5f, 0.5f, 0.5f);
item.ParentInventory.slots[availableSlotIndex].ShowBorderHighlight(GUI.Style.Green, 0.5f, 0.5f);
if (slotIndex < inputContainer.Capacity)
{
inputContainer.Inventory.slots[slotIndex].ShowBorderHighlight(GUI.Style.Green, 0.5f, 0.5f);
}
}
}
}
}
while (slotIndex < inputContainer.Capacity && inputContainer.Inventory.Items[slotIndex] != null)
{
slotIndex++;
}
if (slotIndex >= inputContainer.Capacity) { break; }
var itemIcon = requiredItem.ItemPrefab.InventoryIcon ?? requiredItem.ItemPrefab.sprite;
Rectangle slotRect = inputContainer.Inventory.slots[slotIndex].Rect;
itemIcon.Draw(
spriteBatch,
slotRect.Center.ToVector2(),
color: requiredItem.ItemPrefab.InventoryIconColor * (availableIngredients.Any(i => IsItemValidIngredient(i, requiredItem)) ? 1.0f : 0.3f),
color: requiredItem.ItemPrefab.InventoryIconColor * 0.3f,
scale: Math.Min(slotRect.Width / itemIcon.size.X, slotRect.Height / itemIcon.size.Y));
if (slotRect.Contains(PlayerInput.MousePosition))
@@ -59,7 +59,7 @@ namespace Barotrauma.Items.Components
public override void AddToGUIUpdateList()
{
base.AddToGUIUpdateList();
hullInfoFrame.AddToGUIUpdateList();
hullInfoFrame.AddToGUIUpdateList(order: 1);
}
public override void OnMapLoaded()
@@ -257,8 +257,11 @@ namespace Barotrauma.Items.Components
}
if (mouseOnHull == hull)
{
{
hullInfoFrame.RectTransform.ScreenSpaceOffset = hullFrame.Rect.Center;
if (hullInfoFrame.Rect.Right > GameMain.GraphicsWidth) { hullInfoFrame.RectTransform.ScreenSpaceOffset -= new Point(hullInfoFrame.Rect.Width, 0); }
if (hullInfoFrame.Rect.Bottom > GameMain.GraphicsHeight) { hullInfoFrame.RectTransform.ScreenSpaceOffset -= new Point(0, hullInfoFrame.Rect.Height); }
hullInfoFrame.Visible = true;
hullNameText.Text = hull.DisplayName;
@@ -236,7 +236,6 @@ namespace Barotrauma.Items.Components
var directionalModeSwitchText = new GUITextBlock(new RectTransform(new Vector2(0.7f, 1), directionalModeFrame.RectTransform, Anchor.CenterRight),
TextManager.Get("SonarDirectionalPing"), GUI.Style.TextColor, GUI.SubHeadingFont, Alignment.CenterLeft);
signalWarningText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.15f), paddedControlContainer.RectTransform), "", warningColor, textAlignment: Alignment.Center);
GuiFrame.CanBeFocused = false;
@@ -245,11 +244,14 @@ namespace Barotrauma.Items.Components
sonarView = new GUICustomComponent(new RectTransform(Vector2.One * 0.7f, GuiFrame.RectTransform, Anchor.BottomRight, scaleBasis: ScaleBasis.BothHeight),
(spriteBatch, guiCustomComponent) => { DrawSonar(spriteBatch, guiCustomComponent.Rect); }, null);
signalWarningText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.25f), sonarView.RectTransform, Anchor.Center, Pivot.BottomCenter),
"", warningColor, GUI.LargeFont, Alignment.Center);
// Setup layout for nav terminal
if (isConnectedToSteering)
{
controlContainer.RectTransform.SetPosition(Anchor.TopLeft);
controlContainer.RectTransform.RelativeOffset = controlBoxOffset;
controlContainer.RectTransform.SetPosition(Anchor.TopLeft);
sonarView.RectTransform.ScaleBasis = ScaleBasis.Smallest;
sonarView.RectTransform.SetPosition(Anchor.CenterRight);
sonarView.RectTransform.Resize(Vector2.One * GUI.RelativeHorizontalAspectRatio * sonarAreaSize);
@@ -108,10 +108,7 @@ namespace Barotrauma.Items.Components
private void CreateGUI()
{
controlContainer = new GUIFrame(new RectTransform(new Vector2(Sonar.controlBoxSize.X, Sonar.controlBoxSize.Y + 0.02f), GuiFrame.RectTransform, Anchor.CenterLeft)
{
RelativeOffset = new Vector2(0, 0) // The y offset should be based on the relative size difference of the steering and the status windows
}, "ItemUI");
controlContainer = new GUIFrame(new RectTransform(new Vector2(Sonar.controlBoxSize.X, 1 - Sonar.controlBoxSize.Y * 2), GuiFrame.RectTransform, Anchor.CenterLeft), "ItemUI");
var paddedControlContainer = new GUIFrame(new RectTransform(controlContainer.Rect.Size - GUIStyle.ItemFrameMargin, controlContainer.RectTransform, Anchor.Center)
{
AbsoluteOffset = GUIStyle.ItemFrameOffset
@@ -120,7 +117,7 @@ namespace Barotrauma.Items.Components
var steeringModeArea = new GUIFrame(new RectTransform(new Vector2(1, 0.4f), paddedControlContainer.RectTransform, Anchor.TopLeft), style: null);
steeringModeSwitch = new GUIButton(new RectTransform(new Vector2(0.2f, 1), steeringModeArea.RectTransform), string.Empty, style: "SwitchVertical")
{
Selected = false,
Selected = autoPilot,
Enabled = true,
OnClicked = (button, data) =>
{
@@ -141,34 +138,26 @@ namespace Barotrauma.Items.Components
manualPilotIndicator = new GUITickBox(new RectTransform(new Vector2(1, 0.45f), steeringModeRightSide.RectTransform, Anchor.TopLeft),
TextManager.Get("SteeringManual"), font: GUI.SubHeadingFont, style: "IndicatorLightRedSmall")
{
Selected = true,
Selected = !autoPilot,
Enabled = false
};
autopilotIndicator = new GUITickBox(new RectTransform(new Vector2(1, 0.45f), steeringModeRightSide.RectTransform, Anchor.BottomLeft),
TextManager.Get("SteeringAutoPilot"), font: GUI.SubHeadingFont, style: "IndicatorLightRedSmall")
{
Selected = false,
Selected = autoPilot,
Enabled = false
};
manualPilotIndicator.TextBlock.OverrideTextColor(GUI.Style.TextColor);
autopilotIndicator.TextBlock.OverrideTextColor(GUI.Style.TextColor);
GUITextBlock.AutoScaleAndNormalize(manualPilotIndicator.TextBlock, autopilotIndicator.TextBlock);
var autoPilotControls = new GUIFrame(new RectTransform(new Vector2(0.8f, 0.6f), paddedControlContainer.RectTransform, Anchor.BottomCenter)
{
RelativeOffset = new Vector2(0, 0.02f)
}, "OutlineFrame");
var paddedAutoPilotControls = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.85f), autoPilotControls.RectTransform, Anchor.Center))
{
Stretch = true,
RelativeSpacing = 0.03f,
ChildAnchor = Anchor.TopLeft
};
var autoPilotControls = new GUIFrame(new RectTransform(new Vector2(0.75f, 0.62f), paddedControlContainer.RectTransform, Anchor.BottomCenter), "OutlineFrame");
var paddedAutoPilotControls = new GUIFrame(new RectTransform(new Vector2(0.92f, 0.88f), autoPilotControls.RectTransform, Anchor.Center), style: null);
maintainPosTickBox = new GUITickBox(new RectTransform(new Vector2(1, 0.3f), paddedAutoPilotControls.RectTransform),
maintainPosTickBox = new GUITickBox(new RectTransform(new Vector2(1, 0.333f), paddedAutoPilotControls.RectTransform, Anchor.TopCenter),
TextManager.Get("SteeringMaintainPos"), font: GUI.SmallFont, style: "GUIRadioButton")
{
Enabled = false,
Enabled = autoPilot,
Selected = maintainPos,
OnSelected = tickBox =>
{
@@ -200,12 +189,12 @@ namespace Barotrauma.Items.Components
return true;
}
};
levelStartTickBox = new GUITickBox(new RectTransform(new Vector2(1, 0.3f), paddedAutoPilotControls.RectTransform),
GameMain.GameSession?.StartLocation == null ? "" : ToolBox.LimitString(GameMain.GameSession.StartLocation.Name, 30),
int textLimit = (int)(MathHelper.Clamp(25 * GUI.xScale, 15, 35));
levelStartTickBox = new GUITickBox(new RectTransform(new Vector2(1, 0.333f), paddedAutoPilotControls.RectTransform, Anchor.Center),
GameMain.GameSession?.StartLocation == null ? "" : ToolBox.LimitString(GameMain.GameSession.StartLocation.Name, textLimit),
font: GUI.SmallFont, style: "GUIRadioButton")
{
Enabled = false,
Enabled = autoPilot,
Selected = levelStartSelected,
OnSelected = tickBox =>
{
@@ -228,11 +217,11 @@ namespace Barotrauma.Items.Components
}
};
levelEndTickBox = new GUITickBox(new RectTransform(new Vector2(1, 0.3f), paddedAutoPilotControls.RectTransform),
GameMain.GameSession?.EndLocation == null ? "" : ToolBox.LimitString(GameMain.GameSession.EndLocation.Name, 30),
levelEndTickBox = new GUITickBox(new RectTransform(new Vector2(1, 0.333f), paddedAutoPilotControls.RectTransform, Anchor.BottomCenter),
GameMain.GameSession?.EndLocation == null ? "" : ToolBox.LimitString(GameMain.GameSession.EndLocation.Name, textLimit),
font: GUI.SmallFont, style: "GUIRadioButton")
{
Enabled = false,
Enabled = autoPilot,
Selected = levelEndSelected,
OnSelected = tickBox =>
{
@@ -254,14 +243,14 @@ namespace Barotrauma.Items.Components
return true;
}
};
GUITextBlock.AutoScaleAndNormalize(maintainPosTickBox.TextBlock, levelStartTickBox.TextBlock, levelEndTickBox.TextBlock);
maintainPosTickBox.RectTransform.IsFixedSize = levelStartTickBox.RectTransform.IsFixedSize = levelEndTickBox.RectTransform.IsFixedSize = false;
maintainPosTickBox.RectTransform.MaxSize = levelStartTickBox.RectTransform.MaxSize = levelEndTickBox.RectTransform.MaxSize =
new Point(int.MaxValue, paddedAutoPilotControls.Rect.Height / 3);
maintainPosTickBox.RectTransform.MinSize = levelStartTickBox.RectTransform.MinSize = levelEndTickBox.RectTransform.MinSize =
Point.Zero;
GUITextBlock.AutoScaleAndNormalize(scaleHorizontal: false, scaleVertical: true, maintainPosTickBox.TextBlock, levelStartTickBox.TextBlock, levelEndTickBox.TextBlock);
GUIRadioButtonGroup destinations = new GUIRadioButtonGroup();
destinations.AddRadioButton((int)Destination.MaintainPos, maintainPosTickBox);
destinations.AddRadioButton((int)Destination.LevelStart, levelStartTickBox);
@@ -401,11 +390,12 @@ namespace Barotrauma.Items.Components
(spriteBatch, guiCustomComponent) => { DrawHUD(spriteBatch, guiCustomComponent.Rect); }, null);
steerRadius = steerArea.Rect.Width / 2;
// Tooltip/helper text
pressureWarningText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.25f), paddedStatusContainer.RectTransform), TextManager.Get("SteeringDepthWarning"), GUI.Style.Red)
pressureWarningText = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.25f), steerArea.RectTransform, Anchor.Center, Pivot.TopCenter),
TextManager.Get("SteeringDepthWarning"), Color.Red, GUI.LargeFont, Alignment.Center)
{
Visible = false
};
// Tooltip/helper text
tipContainer = new GUITextBlock(new RectTransform(new Vector2(0.5f, 0.1f), steerArea.RectTransform, Anchor.BottomCenter, Pivot.TopCenter)
, "", font: GUI.Font, wrap: true, style: "GUIToolTip", textAlignment: Alignment.Center)
{
@@ -423,6 +413,7 @@ namespace Barotrauma.Items.Components
{
GuiFrame.ClearChildren();
CreateGUI();
UpdateGUIElements();
}
/// <summary>
@@ -152,7 +152,10 @@ namespace Barotrauma.Items.Components
DraggingConnected.Connections[1]?.ConnectionPanel == panel)
{
DraggingConnected.RemoveConnection(panel.Item);
panel.DisconnectedWires.Add(DraggingConnected);
if (DraggingConnected.Item.ParentInventory == null)
{
panel.DisconnectedWires.Add(DraggingConnected);
}
}
}
@@ -134,46 +134,57 @@ namespace Barotrauma.Items.Components
}
if (IsActive && item.ParentInventory?.Owner is Character user && user == Character.Controlled)// && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
{
Vector2 gridPos = Character.Controlled.Position;
Vector2 roundedGridPos = new Vector2(
MathUtils.RoundTowardsClosest(Character.Controlled.Position.X, Submarine.GridSize.X),
MathUtils.RoundTowardsClosest(Character.Controlled.Position.Y, Submarine.GridSize.Y));
//Vector2 attachPos = GetAttachPosition(user);
if (item.Submarine == null)
if (user.CanInteract)
{
Structure attachTarget = Structure.GetAttachTarget(item.WorldPosition);
if (attachTarget != null)
Vector2 gridPos = Character.Controlled.Position;
Vector2 roundedGridPos = new Vector2(
MathUtils.RoundTowardsClosest(Character.Controlled.Position.X, Submarine.GridSize.X),
MathUtils.RoundTowardsClosest(Character.Controlled.Position.Y, Submarine.GridSize.Y));
//Vector2 attachPos = GetAttachPosition(user);
if (item.Submarine == null)
{
if (attachTarget.Submarine != null)
Structure attachTarget = Structure.GetAttachTarget(item.WorldPosition);
if (attachTarget != null)
{
//set to submarine-relative position
gridPos += attachTarget.Submarine.Position;
roundedGridPos += attachTarget.Submarine.Position;
if (attachTarget.Submarine != null)
{
//set to submarine-relative position
gridPos += attachTarget.Submarine.Position;
roundedGridPos += attachTarget.Submarine.Position;
}
}
}
else
{
gridPos += item.Submarine.Position;
roundedGridPos += item.Submarine.Position;
}
Submarine.DrawGrid(spriteBatch, 14, gridPos, roundedGridPos, alpha: 0.7f);
WireSection.Draw(
spriteBatch, this,
new Vector2(nodes[nodes.Count - 1].X, nodes[nodes.Count - 1].Y) + drawOffset,
new Vector2(newNodePos.X, newNodePos.Y) + drawOffset,
item.Color, 0.0f, 0.3f);
WireSection.Draw(
spriteBatch, this,
new Vector2(newNodePos.X, newNodePos.Y) + drawOffset,
item.DrawPosition,
item.Color, itemDepth, 0.3f);
GUI.DrawRectangle(spriteBatch, new Vector2(newNodePos.X + drawOffset.X, -(newNodePos.Y + drawOffset.Y)) - Vector2.One * 3, Vector2.One * 6, item.Color);
}
else
{
gridPos += item.Submarine.Position;
roundedGridPos += item.Submarine.Position;
WireSection.Draw(
spriteBatch, this,
new Vector2(nodes[nodes.Count - 1].X, nodes[nodes.Count - 1].Y) + drawOffset,
item.DrawPosition,
item.Color, 0.0f, 0.3f);
}
Submarine.DrawGrid(spriteBatch, 14, gridPos, roundedGridPos, alpha: 0.7f);
WireSection.Draw(
spriteBatch, this,
new Vector2(nodes[nodes.Count - 1].X, nodes[nodes.Count - 1].Y) + drawOffset,
new Vector2(newNodePos.X, newNodePos.Y) + drawOffset,
item.Color, 0.0f, 0.3f);
WireSection.Draw(
spriteBatch, this,
new Vector2(newNodePos.X, newNodePos.Y) + drawOffset,
item.DrawPosition,
item.Color, itemDepth, 0.3f);
GUI.DrawRectangle(spriteBatch, new Vector2(newNodePos.X + drawOffset.X, -(newNodePos.Y + drawOffset.Y)) - Vector2.One * 3, Vector2.One * 6, item.Color);
}
}
@@ -53,14 +53,10 @@ namespace Barotrauma
{
int buttonDir = Math.Sign(SubInventoryDir);
Vector2 equipIndicatorPos = new Vector2(
Rect.Center.X - Inventory.EquipIndicator.size.X / 2 * Inventory.UIScale,
Rect.Center.Y + (Rect.Height / 2 + 25 * Inventory.UIScale) * buttonDir - Inventory.EquipIndicator.size.Y / 2 * Inventory.UIScale);
Vector2 equipIndicatorPos = new Vector2(Rect.Left, Rect.Top);
equipIndicatorPos += DrawOffset;
return new Rectangle(
(int)(equipIndicatorPos.X), (int)(equipIndicatorPos.Y),
(int)(Inventory.EquipIndicator.size.X * Inventory.UIScale), (int)(Inventory.EquipIndicator.size.Y * Inventory.UIScale));
return new Rectangle((int)equipIndicatorPos.X, (int)equipIndicatorPos.Y, Rect.Width, (int)(Inventory.EquipIndicator.size.Y * Inventory.UIScale));
}
}
@@ -132,11 +128,27 @@ namespace Barotrauma
protected Point prevScreenResolution;
protected static Sprite slotHotkeySprite;
public static Sprite SlotSpriteSmall;
public static Sprite EquipIndicator, EquipIndicatorHighlight;
private static Sprite slotSpriteSmall;
public static Sprite SlotSpriteSmall
{
get
{
if (slotSpriteSmall == null)
{
//TODO: define these in xml
slotSpriteSmall = new Sprite("Content/UI/InventoryUIAtlas.png", new Rectangle(12, 9, 115, 115), null, 0);
slotSpriteSmall.size = new Vector2(SlotSpriteSmall.SourceRect.Width * 0.682f, SlotSpriteSmall.SourceRect.Height * 0.682f);
}
return slotSpriteSmall;
}
}
public static Sprite DraggableIndicator;
public static Sprite EquipIndicator;
public static Inventory DraggingInventory;
public Rectangle BackgroundFrame { get; protected set; }
public Rectangle BackgroundFrame;
private ushort[] receivedItemIDs;
private CoroutineHandle syncItemsCoroutine;
@@ -151,6 +163,8 @@ namespace Barotrauma
private Point savedPosition, originalPos;
private bool canMove = false;
private bool positionUpdateQueued = false;
private Vector2 draggableIndicatorOffset;
private float draggableIndicatorScale;
public class SlotReference
{
@@ -291,7 +305,7 @@ namespace Barotrauma
int columns = Math.Min(slotsPerRow, capacity);
Vector2 spacing = new Vector2(5.0f * UIScale);
spacing.Y += (this is CharacterInventory) ? EquipIndicator.size.Y * UIScale : ContainedIndicatorHeight;
spacing.Y += (this is CharacterInventory) ? EquipIndicator.size.Y : ContainedIndicatorHeight;
Vector2 rectSize = new Vector2(60.0f * UIScale);
padding = new Vector4(spacing.X, spacing.Y, spacing.X, spacing.X);
@@ -370,7 +384,12 @@ namespace Barotrauma
protected virtual bool HideSlot(int i)
{
return slots[i].Disabled || (hideEmptySlot[i] && Items[i] == null);
return slots[i].Disabled;
}
protected virtual bool IsSlotHiddenDueToToggleState(int i)
{
return false;
}
public virtual void Update(float deltaTime, Camera cam, bool subInventory = false)
@@ -386,7 +405,7 @@ namespace Barotrauma
{
for (int i = 0; i < capacity; i++)
{
if (HideSlot(i)) { continue; }
if (HideSlot(i) || IsSlotHiddenDueToToggleState(i)) { continue; }
UpdateSlot(slots[i], i, Items[i], subInventory);
}
if (!isSubInventory)
@@ -516,6 +535,9 @@ namespace Barotrauma
{
if (PlayerInput.PrimaryMouseButtonDown())
{
// Prevent us from dragging an item
draggingItem = null;
draggingSlot = null;
DraggingInventory = subInventory;
}
}
@@ -535,7 +557,7 @@ namespace Barotrauma
var slot = slots[slotIndex];
int dir = slot.SubInventoryDir;
Rectangle subRect = slot.Rect;
Vector2 spacing = new Vector2(10 * UIScale, (10 + EquipIndicator.size.Y) * UIScale);
Vector2 spacing = new Vector2(10 * UIScale, (10 * UIScale + EquipIndicator.size.Y));
int columns = (int)Math.Max(Math.Floor(Math.Sqrt(itemCapacity)), 1);
while (itemCapacity / columns * (subRect.Height + spacing.Y) > GameMain.GraphicsHeight * 0.5f)
@@ -631,18 +653,24 @@ namespace Barotrauma
/// Is the mouse on any inventory element (slot, equip button, subinventory...)
/// </summary>
/// <returns></returns>
public static bool IsMouseOnInventory()
public static bool IsMouseOnInventory(bool ignoreDrag = false)
{
if (Character.Controlled == null) return false;
if (draggingItem != null || DraggingInventory != null) return true;
if (!ignoreDrag && draggingItem != null || DraggingInventory != null) return true;
if (Character.Controlled.Inventory != null)
{
var inv = Character.Controlled.Inventory;
if (inv.BackgroundFrame.Contains(PlayerInput.MousePosition) || inv.InventoryToggleContains) return true;
for (var i = 0; i < inv.slots.Length; i++)
{
var slot = inv.slots[i];
if (inv.HideSlot(i) || inv.IsSlotHiddenDueToToggleState(i)) continue;
if (slot.InteractRect.Contains(PlayerInput.MousePosition))
{
return true;
@@ -715,6 +743,11 @@ namespace Barotrauma
if (inv == null) { return CursorState.Default; }
if (inv.InventoryToggleContains)
{
return CursorState.Hand;
}
foreach (var item in inv.Items)
{
var container = item?.GetComponent<ItemContainer>();
@@ -765,8 +798,12 @@ namespace Barotrauma
}
}
foreach (var slot in inv.slots)
for (int i = 0; i < inv.slots.Length; i++)
{
InventorySlot slot = inv.slots[i];
if (inv.IsSlotHiddenDueToToggleState(i)) continue;
if (slot.EquipButtonRect.Contains(PlayerInput.MousePosition))
{
return CursorState.Hand;
@@ -783,6 +820,7 @@ namespace Barotrauma
}
}
}
return CursorState.Default;
}
@@ -850,6 +888,12 @@ namespace Barotrauma
{
if (positionUpdateQueued) // Wait a frame before updating the positioning of the container after a resolution change to have everything working
{
int height = (int)(movableFrameRectHeight * UIScale);
CreateSlots();
container.Inventory.movableFrameRect = new Rectangle(container.Inventory.BackgroundFrame.X, container.Inventory.BackgroundFrame.Y - height, container.Inventory.BackgroundFrame.Width, height);
draggableIndicatorScale = 1.25f * UIScale;
draggableIndicatorOffset = DraggableIndicator.size * draggableIndicatorScale / 2f;
draggableIndicatorOffset += new Vector2(height / 2f - draggableIndicatorOffset.Y);
container.Inventory.originalPos = container.Inventory.savedPosition = container.Inventory.movableFrameRect.Center;
positionUpdateQueued = false;
}
@@ -862,12 +906,13 @@ namespace Barotrauma
prevScreenResolution = new Point(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
prevUIScale = UIScale;
prevHUDScale = GUI.Scale;
int height = (int)(movableFrameRectHeight * UIScale);
container.Inventory.movableFrameRect = new Rectangle(container.Inventory.BackgroundFrame.X, container.Inventory.BackgroundFrame.Y - height, container.Inventory.BackgroundFrame.Width, height);
positionUpdateQueued = true;
}
GUI.DrawRectangle(spriteBatch, container.Inventory.movableFrameRect, movableFrameRectColor, true);
else
{
GUI.DrawRectangle(spriteBatch, container.Inventory.movableFrameRect, movableFrameRectColor, true);
DraggableIndicator.Draw(spriteBatch, container.Inventory.movableFrameRect.Location.ToVector2() + draggableIndicatorOffset, 0, draggableIndicatorScale);
}
}
}
@@ -886,17 +931,20 @@ namespace Barotrauma
if (selectedSlot == null)
{
if (DraggingItemToWorld &&
Character.Controlled.FocusedItem?.OwnInventory != null &&
Character.Controlled.FocusedItem.OwnInventory.CanBePut(draggingItem) &&
Character.Controlled.FocusedItem.OwnInventory.TryPutItem(draggingItem, Character.Controlled))
if (!IsMouseOnInventory(true))
{
GUI.PlayUISound(GUISoundType.PickItem);
}
else
{
GUI.PlayUISound(GUISoundType.DropItem);
draggingItem.Drop(Character.Controlled);
if (DraggingItemToWorld &&
Character.Controlled.FocusedItem?.OwnInventory != null &&
Character.Controlled.FocusedItem.OwnInventory.CanBePut(draggingItem) &&
Character.Controlled.FocusedItem.OwnInventory.TryPutItem(draggingItem, Character.Controlled))
{
GUI.PlayUISound(GUISoundType.PickItem);
}
else
{
GUI.PlayUISound(GUISoundType.DropItem);
draggingItem.Drop(Character.Controlled);
}
}
}
else if (selectedSlot.ParentInventory.Items[selectedSlot.SlotIndex] != draggingItem)
@@ -1028,7 +1076,7 @@ namespace Barotrauma
bool mouseOnHealthInterface = CharacterHealth.OpenHealthWindow != null && CharacterHealth.OpenHealthWindow.MouseOnElement;
if ((GUI.MouseOn == null || mouseOnHealthInterface) && selectedSlot == null)
if ((GUI.MouseOn == null || mouseOnHealthInterface) && selectedSlot == null && !IsMouseOnInventory(true))
{
var shadowSprite = GUI.Style.GetComponentStyle("OuterGlow").Sprites[GUIComponent.ComponentState.None][0];
string toolTip = mouseOnHealthInterface ? TextManager.Get("QuickUseAction.UseTreatment") :
@@ -1053,7 +1101,7 @@ namespace Barotrauma
}
}
if (selectedSlot != null && selectedSlot.Item != null)
if (selectedSlot != null && selectedSlot.Item != null && selectedSlot.Slot.EquipButtonState != GUIComponent.ComponentState.Hover)
{
Rectangle slotRect = selectedSlot.Slot.Rect;
slotRect.Location += selectedSlot.Slot.DrawOffset.ToPoint();
@@ -1091,11 +1139,26 @@ namespace Barotrauma
if (inventory != null && (CharacterInventory.PersonalSlots.HasFlag(type) || (inventory.isSubInventory && (inventory.Owner as Item) != null
&& (inventory.Owner as Item).AllowedSlots.Any(a => CharacterInventory.PersonalSlots.HasFlag(a)))))
{
slotColor = slot.IsHighlighted ? GUIColorSettings.EquipmentSlotColor : GUIColorSettings.EquipmentSlotColor * 0.8f;
if (item == null)
{
slotColor = slot.IsHighlighted ? GUIColorSettings.EquipmentSlotEmptyColor : GUIColorSettings.EquipmentSlotEmptyColor * 0.8f;
}
else
{
slotColor = slot.IsHighlighted ? GUIColorSettings.EquipmentSlotColor : GUIColorSettings.EquipmentSlotColor * 0.8f;
}
}
else
{
slotColor = slot.IsHighlighted ? GUIColorSettings.InventorySlotColor : GUIColorSettings.InventorySlotColor * 0.8f;
if (item != null && Character.Controlled.HasEquippedItem(item))
{
slotColor = slot.IsHighlighted ? GUIColorSettings.InventorySlotEquippedColor : GUIColorSettings.InventorySlotEquippedColor * 0.8f;
}
else
{
slotColor = slot.IsHighlighted ? GUIColorSettings.InventorySlotColor : GUIColorSettings.InventorySlotColor * 0.8f;
}
}
if (inventory != null && inventory.Locked) { slotColor = Color.Gray * 0.5f; }
@@ -1210,7 +1273,7 @@ namespace Barotrauma
if (GameMain.DebugDraw)
{
GUI.DrawRectangle(spriteBatch, rect, Color.White, false, 0, 1);
GUI.DrawRectangle(spriteBatch, slot.EquipButtonRect, Color.White, false, 0, 1);
GUI.DrawRectangle(spriteBatch, slot.EquipButtonRect, Color.Red, false, 0, 1);
}
if (slot.HighlightColor != Color.Transparent)
@@ -1221,8 +1284,11 @@ namespace Barotrauma
if (item != null && drawItem)
{
Sprite sprite = item.Prefab.InventoryIcon ?? item.Sprite;
float scale = Math.Min(Math.Min((rect.Width - 10) / sprite.size.X, (rect.Height - 10) / sprite.size.Y), 2.0f);
Vector2 itemPos = rect.Center.ToVector2();
float equipButtonHeightAdjustment = inventory == Character.Controlled?.Inventory ? slot.EquipButtonRect.Height : 0;
float scale = Math.Min(Math.Min((rect.Width - 10) / sprite.size.X, (rect.Height - 5 - equipButtonHeightAdjustment) / sprite.size.Y), 2.0f);
Vector2 itemPos = rect.Center.ToVector2() + new Vector2(0, equipButtonHeightAdjustment / 2f);
if (itemPos.Y > GameMain.GraphicsHeight)
{
itemPos.Y -= Math.Min(
@@ -1248,15 +1314,6 @@ namespace Barotrauma
}
sprite.Draw(spriteBatch, itemPos, spriteColor, rotation, scale);
}
if (inventory != null &&
!inventory.Locked &&
Character.Controlled?.Inventory == inventory &&
slot.QuickUseKey != Keys.None)
{
spriteBatch.Draw(slotHotkeySprite.Texture, rect.ScaleSize(1.25f), slotHotkeySprite.SourceRect, slotColor);
GUI.DrawString(spriteBatch, rect.Location.ToVector2() + new Vector2(1, -2), slot.QuickUseKey.ToString().Substring(1, 1), Color.Black, font: GUI.SmallFont);
}
}
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
@@ -1273,7 +1330,7 @@ namespace Barotrauma
//prevents the inventory from briefly reverting to an old state if items are moved around in quick succession
//also delay if we're still midround syncing, some of the items in the inventory may not exist yet
if (syncItemsDelay > 0.0f || GameMain.Client.MidRoundSyncing)
if (syncItemsDelay > 0.0f || GameMain.Client.MidRoundSyncing || NetIdUtils.IdMoreRecent(lastEventID, GameMain.Client.EntityEventManager.LastReceivedID))
{
if (syncItemsCoroutine != null) CoroutineManager.StopCoroutines(syncItemsCoroutine);
syncItemsCoroutine = CoroutineManager.StartCoroutine(SyncItemsAfterDelay(lastEventID));
@@ -698,16 +698,19 @@ namespace Barotrauma
//reset positions first
List<GUIComponent> elementsToMove = new List<GUIComponent>();
if (editingHUD != null && editingHUD.UserData == this)
if (editingHUD != null && editingHUD.UserData == this &&
((HasInGameEditableProperties && Character.Controlled?.SelectedConstruction == this) || Screen.Selected == GameMain.SubEditorScreen))
{
elementsToMove.Add(editingHUD);
}
}
debugInitialHudPositions.Clear();
foreach (ItemComponent ic in activeHUDs)
{
if (ic.GuiFrame == null || ic.AllowUIOverlap || ic.GetLinkUIToComponent() != null) continue;
if (ic.GuiFrame == null || ic.AllowUIOverlap || ic.GetLinkUIToComponent() != null) { continue; }
ic.GuiFrame.RectTransform.ScreenSpaceOffset = Point.Zero;
elementsToMove.Add(ic.GuiFrame);
debugInitialHudPositions.Add(ic.GuiFrame.Rect);
}
List<Rectangle> disallowedAreas = new List<Rectangle>();
@@ -728,18 +731,22 @@ namespace Barotrauma
foreach (ItemComponent ic in activeHUDs)
{
if (ic.GuiFrame == null) continue;
if (ic.GuiFrame == null) { continue; }
var linkUIToComponent = ic.GetLinkUIToComponent();
if (linkUIToComponent == null) continue;
if (linkUIToComponent == null) { continue; }
ic.GuiFrame.RectTransform.ScreenSpaceOffset = linkUIToComponent.GuiFrame.RectTransform.ScreenSpaceOffset;
}
}
private readonly List<Rectangle> debugInitialHudPositions = new List<Rectangle>();
public void UpdateHUD(Camera cam, Character character, float deltaTime)
{
bool editingHUDCreated = false;
if (HasInGameEditableProperties ||
if ((HasInGameEditableProperties && character.SelectedConstruction == this) ||
Screen.Selected == GameMain.SubEditorScreen)
{
GUIComponent prevEditingHUD = editingHUD;
@@ -850,6 +857,23 @@ namespace Barotrauma
ic.DrawHUD(spriteBatch, character);
}
}
if (GameMain.DebugDraw)
{
int i = 0;
foreach (ItemComponent ic in activeHUDs)
{
if (i >= debugInitialHudPositions.Count) { break; }
if (activeHUDs[i].GuiFrame == null) { continue; }
if (ic.GuiFrame == null || ic.AllowUIOverlap || ic.GetLinkUIToComponent() != null) { continue; }
GUI.DrawRectangle(spriteBatch, debugInitialHudPositions[i], Color.Orange);
GUI.DrawRectangle(spriteBatch, ic.GuiFrame.Rect, Color.LightGreen);
GUI.DrawLine(spriteBatch, debugInitialHudPositions[i].Location.ToVector2(), ic.GuiFrame.Rect.Location.ToVector2(), Color.Orange);
i++;
}
}
}
readonly List<ColoredText> texts = new List<ColoredText>();
@@ -1249,10 +1273,9 @@ namespace Barotrauma
{
inventory = container.Inventory;
}
}
}
}
var item = new Item(itemPrefab, pos, sub)
{
ID = itemId
@@ -1262,8 +1285,8 @@ namespace Barotrauma
{
wifiComponent.TeamID = (Character.TeamType)teamID;
}
if (descriptionChanged) item.Description = itemDesc;
if (tagsChanged) item.Tags = tags;
if (descriptionChanged) { item.Description = itemDesc; }
if (tagsChanged) { item.Tags = tags; }
if (sub != null)
{
@@ -1276,7 +1299,7 @@ namespace Barotrauma
if (inventorySlotIndex >= 0 && inventorySlotIndex < 255 &&
inventory.TryPutItem(item, inventorySlotIndex, false, false, null, false))
{
return null;
return item;
}
inventory.TryPutItem(item, null, item.AllowedSlots, false);
}
@@ -11,6 +11,12 @@ namespace Barotrauma
{
base.ControlInput(cam);
cam.OffsetAmount = 0;
if (Character.Controlled?.Inventory != null)
{
Character.Controlled.Inventory.ToggleInventory(true);
}
//if this is used, we need to implement syncing this inventory with the server
/*Character.DisableControls = true;
if (Character.Controlled != null)
@@ -19,7 +25,7 @@ namespace Barotrauma
{
Character.Controlled.SelectedConstruction = null;
}
}*/
}*/
}
protected override void CalculateBackgroundFrame()