Merge branch 'master' into moStuff

This commit is contained in:
Joonas Rikkonen
2018-01-09 10:38:06 +02:00
committed by GitHub
179 changed files with 116633 additions and 3529 deletions
@@ -2,6 +2,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma
{
@@ -119,7 +120,7 @@ namespace Barotrauma
}
public override void Update(float deltaTime, bool subInventory = false)
public override void Update(float deltaTime, bool isSubInventory = false)
{
base.Update(deltaTime);
@@ -161,19 +162,39 @@ namespace Barotrauma
}
}
draggingItem = null;
GUI.PlayUISound(wasPut ? GUISoundType.PickItem : GUISoundType.PickItemFail);
}
if (selectedSlot > -1)
if (highlightedSubInventorySlot != null)
{
UpdateSubInventory(deltaTime, selectedSlot);
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;
}
}
}
if (character == Character.Controlled)
{
for (int i = 0; i < capacity; i++)
{
if (selectedSlot != 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)
@@ -224,7 +245,7 @@ namespace Barotrauma
}
}
selectedSlot = -1;
selectedSlot = null;
}
public void DrawOwn(SpriteBatch spriteBatch)
@@ -274,7 +295,7 @@ namespace Barotrauma
{
for (int i = 0; i < capacity; i++)
{
if (selectedSlot != i &&
if ((selectedSlot == null || selectedSlot.SlotIndex != i) &&
Items[i] != null && Items[i].CanUseOnSelf && character.HasSelectedItem(Items[i]))
{
useOnSelfButton[i - 3].Draw(spriteBatch);
@@ -282,15 +303,11 @@ namespace Barotrauma
}
}
if (selectedSlot > -1)
for (int i = 0; i < capacity; i++)
{
DrawSubInventory(spriteBatch, selectedSlot);
if (selectedSlot > -1 &&
!slots[selectedSlot].IsHighlighted &&
(draggingItem == null || draggingItem.Container != Items[selectedSlot]))
if (slots[i].IsHighlighted)
{
selectedSlot = -1;
DrawSubInventory(spriteBatch, i);
}
}
}
@@ -90,7 +90,7 @@ namespace Barotrauma.Items.Components
GuiFrame.Draw(spriteBatch);
if (voltage < minVoltage && powerConsumption > 0.0f) return;
if (voltage < minVoltage && currPowerConsumption > 0.0f) return;
Rectangle velRect = new Rectangle(x + 20, y + 20, width - 40, height - 40);
//GUI.DrawRectangle(spriteBatch, velRect, Color.White, false);
@@ -136,6 +136,8 @@ namespace Barotrauma.Items.Components
public override void UpdateHUD(Character character)
{
GuiFrame.Update(1.0f / 60.0f);
if (voltage < minVoltage && currPowerConsumption > 0.0f) return;
if (Vector2.Distance(PlayerInput.MousePosition, new Vector2(GuiFrame.Rect.Center.X, GuiFrame.Rect.Center.Y)) < 200.0f)
{
@@ -182,8 +182,8 @@ namespace Barotrauma.Items.Components
GameServer.Log(Character.Controlled.LogName + " connected a wire from " +
Item.Name + " (" + Name + ") to " + otherConnection.item.Name + " (" + otherConnection.Name + ")", ServerLog.MessageType.ItemInteraction);
}
Wires[index] = draggingConnected;
AddLink(index, draggingConnected);
}
}
}
@@ -3,6 +3,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma.Items.Components
{
@@ -36,6 +37,12 @@ namespace Barotrauma.Items.Components
}
}
private static Sprite wireSprite;
private static Wire draggingWire;
private static int? selectedNodeIndex;
private static int? highlightedNodeIndex;
public void Draw(SpriteBatch spriteBatch, bool editing)
{
if (sections.Count == 0 && !IsActive)
@@ -69,7 +76,7 @@ namespace Barotrauma.Items.Components
foreach (WireSection section in sections)
{
section.Draw(spriteBatch, item.Color, drawOffset, depth, 0.3f);
section.Draw(spriteBatch, item.Submarine == null ? Color.Green : item.Color, drawOffset, depth, 0.3f);
}
if (IsActive && nodes.Count > 0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
@@ -91,14 +98,15 @@ namespace Barotrauma.Items.Components
if (item.Submarine != null) drawPos += item.Submarine.Position + item.Submarine.HiddenSubPosition;
drawPos.Y = -drawPos.Y;
if ((highlightedNodeIndex == i && item.IsHighlighted) || (selectedNodeIndex == i && item.IsSelected))
{
GUI.DrawRectangle(spriteBatch, drawPos + new Vector2(-10, -10), new Vector2(20, 20), Color.Red, false, 0.0f);
}
if (item.IsSelected)
{
GUI.DrawRectangle(spriteBatch, drawPos + new Vector2(-5, -5), new Vector2(10, 10), item.Color, true, 0.0f);
if (highlightedNodeIndex == i)
{
GUI.DrawRectangle(spriteBatch, drawPos + new Vector2(-10, -10), new Vector2(20, 20), Color.Red, false, 0.0f);
}
}
else
{
@@ -196,28 +204,36 @@ namespace Barotrauma.Items.Components
//check which wire is highlighted with the cursor
Wire highlighted = null;
float closestDist = 0.0f;
float closestDist = float.PositiveInfinity;
foreach (Wire w in wires)
{
Vector2 mousePos = GameMain.SubEditorScreen.Cam.ScreenToWorld(PlayerInput.MousePosition);
if (w.item.Submarine != null) mousePos -= (w.item.Submarine.Position + w.item.Submarine.HiddenSubPosition);
float dist = 0.0f;
if (w.GetClosestNodeIndex(mousePos, highlighted == null ? nodeSelectDist : closestDist, out dist) > -1)
int highlightedNode = w.GetClosestNodeIndex(mousePos, highlighted == null ? nodeSelectDist : closestDist, out dist);
if (highlightedNode > -1)
{
highlighted = w;
closestDist = dist;
if (dist < closestDist)
{
highlightedNodeIndex = highlightedNode;
highlighted = w;
closestDist = dist;
}
}
if (w.GetClosestSectionIndex(mousePos, highlighted == null ? sectionSelectDist : closestDist, out dist) > -1)
{
highlighted = w;
closestDist = dist;
//prefer nodes over sections
if (dist + nodeSelectDist * 0.5f < closestDist)
{
highlightedNodeIndex = null;
highlighted = w;
closestDist = dist + nodeSelectDist * 0.5f;
}
}
}
if (highlighted != null)
{
highlighted.item.IsHighlighted = true;
@@ -90,14 +90,26 @@ namespace Barotrauma.Items.Components
GUI.DrawRectangle(spriteBatch, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight),
Color.Green * 0.1f, true);
Character closestCharacter = null;
float closestDist = float.PositiveInfinity;
foreach (Character c in visibleCharacters)
{
if (c == character) continue;
float dist = Vector2.Distance(character.WorldPosition, c.WorldPosition);
DrawCharacterInfo(spriteBatch, c, 1.0f - MathHelper.Max((dist - (Range - FadeOutRange)) / FadeOutRange, 0.0f));
float dist = Vector2.DistanceSquared(GameMain.GameScreen.Cam.ScreenToWorld(PlayerInput.MousePosition), c.WorldPosition);
if (dist < closestDist)
{
closestCharacter = c;
closestDist = dist;
}
}
if (closestCharacter != null)
{
float dist = Vector2.Distance(GameMain.GameScreen.Cam.ScreenToWorld(PlayerInput.MousePosition), closestCharacter.WorldPosition);
DrawCharacterInfo(spriteBatch, closestCharacter, 1.0f - MathHelper.Max((dist - (Range - FadeOutRange)) / FadeOutRange, 0.0f));
}
}
private void DrawCharacterInfo(SpriteBatch spriteBatch, Character target, float alpha = 1.0f)
@@ -49,7 +49,7 @@ namespace Barotrauma
frame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
frame.UserData = item;
new GUITextBlock(new Rectangle(0, 0, 200, 20), "Attempting to fix " + item.Name, "", frame);
new GUITextBlock(new Rectangle(0, 0, 200, 20), TextManager.Get("FixHeader").Replace("[itemname]", item.Name), "", frame);
y = y + 40;
foreach (FixRequirement requirement in item.FixRequirements)
@@ -60,7 +60,7 @@ namespace Barotrauma
reqFrame.UserData = requirement;
var fixButton = new GUIButton(new Rectangle(0, 0, 50, 20), "Fix", "", reqFrame);
var fixButton = new GUIButton(new Rectangle(0, 0, 50, 20), TextManager.Get("Fix"), "", reqFrame);
fixButton.OnClicked = FixButtonPressed;
fixButton.UserData = requirement;
@@ -68,6 +68,22 @@ namespace Barotrauma
partial class Inventory
{
protected class SlotReference
{
public readonly Inventory Inventory;
public readonly InventorySlot Slot;
public readonly int SlotIndex;
public bool IsSubSlot;
public SlotReference(Inventory inventory, InventorySlot slot, int slotIndex, bool isSubSlot)
{
Inventory = inventory;
Slot = slot;
SlotIndex = slotIndex;
IsSubSlot = isSubSlot;
}
}
public static InventorySlot draggingSlot;
public static Item draggingItem;
@@ -80,9 +96,12 @@ namespace Barotrauma
set { slotsPerRow = Math.Max(1, value); }
}
protected int selectedSlot = -1;
protected static SlotReference highlightedSubInventorySlot;
protected static Inventory highlightedSubInventory;
protected InventorySlot[] slots;
protected static SlotReference selectedSlot;
public InventorySlot[] slots;
private Vector2 centerPos;
@@ -135,6 +154,11 @@ namespace Barotrauma
slots[i] = new InventorySlot(slotRect);
}
if (selectedSlot != null && selectedSlot.Inventory == this)
{
selectedSlot = new SlotReference(this, slots[selectedSlot.SlotIndex], selectedSlot.SlotIndex, selectedSlot.IsSubSlot);
}
}
public virtual void Update(float deltaTime, bool subInventory = false)
@@ -150,22 +174,8 @@ namespace Barotrauma
for (int i = 0; i < capacity; i++)
{
if (slots[i].Disabled) continue;
UpdateSlot(slots[i], i, Items[i], false);
UpdateSlot(slots[i], i, Items[i], subInventory);
}
if (draggingItem != null &&
(draggingSlot == null || (!draggingSlot.InteractRect.Contains(PlayerInput.MousePosition) && draggingItem.ParentInventory == this)))
{
if (!PlayerInput.LeftButtonHeld())
{
CreateNetworkEvent();
draggingItem.Drop();
GUI.PlayUISound(GUISoundType.DropItem);
}
}
}
protected void UpdateSlot(InventorySlot slot, int slotIndex, Item item, bool isSubSlot)
@@ -173,20 +183,16 @@ namespace Barotrauma
bool mouseOn = slot.InteractRect.Contains(PlayerInput.MousePosition) && !Locked;
slot.State = GUIComponent.ComponentState.None;
if (!(this is CharacterInventory) && !mouseOn && selectedSlot == slotIndex)
{
selectedSlot = -1;
}
if (mouseOn &&
(draggingItem != null || selectedSlot == slotIndex || selectedSlot == -1))
(draggingItem != null || selectedSlot == null || selectedSlot.Slot == slot) &&
(highlightedSubInventory == null || highlightedSubInventory == this || highlightedSubInventorySlot?.Slot == slot))
{
slot.State = GUIComponent.ComponentState.Hover;
if (!isSubSlot && selectedSlot == -1)
if (selectedSlot == null || (!selectedSlot.IsSubSlot && isSubSlot))
{
selectedSlot = slotIndex;
selectedSlot = new SlotReference(this, slot, slotIndex, isSubSlot);
}
if (draggingItem == null)
@@ -203,38 +209,29 @@ namespace Barotrauma
{
doubleClickedItem = item;
}
if (draggingItem != Items[slotIndex])
{
//selectedSlot = slotIndex;
if (TryPutItem(draggingItem, slotIndex, true, Character.Controlled))
{
if (slots != null) slots[slotIndex].ShowBorderHighlight(Color.White, 0.1f, 0.4f);
GUI.PlayUISound(GUISoundType.PickItem);
}
else
{
if (slots != null) slots[slotIndex].ShowBorderHighlight(Color.Red, 0.1f, 0.9f);
GUI.PlayUISound(GUISoundType.PickItemFail);
}
draggingItem = null;
draggingSlot = null;
}
}
}
}
}
protected Inventory GetSubInventory(int slotIndex)
{
var item = Items[slotIndex];
if (item == null) return null;
var container = item.GetComponent<ItemContainer>();
if (container == null) return null;
return container.Inventory;
}
public void UpdateSubInventory(float deltaTime, int slotIndex)
{
var item = Items[slotIndex];
if (item == null) return;
Inventory subInventory = GetSubInventory(slotIndex);
if (subInventory == null) return;
var container = item.GetComponent<ItemContainer>();
if (container == null) return;
if (subInventory.slots == null) subInventory.CreateSlots();
if (container.Inventory.slots == null) container.Inventory.CreateSlots();
int itemCapacity = container.Capacity;
int itemCapacity = subInventory.Items.Length;
var slot = slots[slotIndex];
new Rectangle(slot.Rect.X - 5, slot.Rect.Y - (40 + 10) * itemCapacity - 5,
@@ -246,17 +243,17 @@ namespace Barotrauma
for (int i = 0; i < itemCapacity; i++)
{
subRect.Y = subRect.Y - subRect.Height - 10;
container.Inventory.slots[i].Rect = subRect;
container.Inventory.slots[i].InteractRect = subRect;
container.Inventory.slots[i].InteractRect.Inflate(5, 5);
subInventory.slots[i].Rect = subRect;
subInventory.slots[i].InteractRect = subRect;
subInventory.slots[i].InteractRect.Inflate(5, 5);
}
container.Inventory.isSubInventory = true;
subInventory.isSubInventory = true;
slots[slotIndex].State = GUIComponent.ComponentState.Hover;
container.Inventory.Update(deltaTime, true);
subInventory.Update(deltaTime, true);
}
@@ -274,17 +271,6 @@ namespace Barotrauma
DrawSlot(spriteBatch, slots[i], Items[i], drawItem);
}
if (draggingItem != null &&
(draggingSlot == null || (!draggingSlot.InteractRect.Contains(PlayerInput.MousePosition) && draggingItem.ParentInventory == this)))
{
Rectangle dragRect = new Rectangle(
(int)PlayerInput.MousePosition.X - 10,
(int)PlayerInput.MousePosition.Y - 10,
40, 40);
DrawSlot(spriteBatch, new InventorySlot(dragRect), draggingItem);
}
for (int i = 0; i < capacity; i++)
{
if (slots[i].InteractRect.Contains(PlayerInput.MousePosition) && !slots[i].Disabled && Items[i] != null)
@@ -373,9 +359,57 @@ namespace Barotrauma
container.Inventory.Draw(spriteBatch, true);
if (!containerRect.Contains(PlayerInput.MousePosition))
}
public static void UpdateDragging()
{
if (draggingItem != null && PlayerInput.LeftButtonReleased())
{
if (draggingItem == null || draggingItem.Container != item) selectedSlot = -1;
if (selectedSlot == null)
{
draggingItem.ParentInventory?.CreateNetworkEvent();
draggingItem.Drop();
GUI.PlayUISound(GUISoundType.DropItem);
}
else if (selectedSlot.Inventory.Items[selectedSlot.SlotIndex] != draggingItem)
{
Inventory selectedInventory = selectedSlot.Inventory;
int slotIndex = selectedSlot.SlotIndex;
if (selectedInventory.TryPutItem(draggingItem, slotIndex, true, Character.Controlled))
{
if (selectedInventory.slots != null) selectedInventory.slots[slotIndex].ShowBorderHighlight(Color.White, 0.1f, 0.4f);
GUI.PlayUISound(GUISoundType.PickItem);
}
else
{
if (selectedInventory.slots != null) selectedInventory.slots[slotIndex].ShowBorderHighlight(Color.Red, 0.1f, 0.9f);
GUI.PlayUISound(GUISoundType.PickItemFail);
}
draggingItem = null;
draggingSlot = null;
}
draggingItem = null;
}
if (selectedSlot != null && !selectedSlot.Slot.InteractRect.Contains(PlayerInput.MousePosition))
{
selectedSlot = null;
}
}
public static void DrawDragging(SpriteBatch spriteBatch)
{
if (draggingItem == null) return;
if (draggingSlot == null || (!draggingSlot.InteractRect.Contains(PlayerInput.MousePosition)))
{
Rectangle dragRect = new Rectangle(
(int)PlayerInput.MousePosition.X - 10,
(int)PlayerInput.MousePosition.Y - 10,
40, 40);
DrawSlot(spriteBatch, new InventorySlot(dragRect), draggingItem);
}
}
@@ -470,7 +470,7 @@ namespace Barotrauma
}
else
{
body.FarseerBody.Enabled = false;
body.Enabled = false;
}
if ((newPosition - SimPosition).Length() > body.LinearVelocity.Length() * 2.0f)