Merge remote-tracking branch 'refs/remotes/barotrauma/master'

Conflicts:
	Subsurface/Properties/AssemblyInfo.cs
	Subsurface/Source/Characters/Character.cs
	Subsurface/Source/GUI/GUI.cs
	Subsurface/Source/GameMain.cs
	Subsurface/Source/GameSettings.cs
	Subsurface/Source/Items/CharacterInventory.cs
	Subsurface/Source/Items/Components/ItemComponent.cs
	Subsurface/Source/Items/Components/Machines/Pump.cs
	Subsurface/Source/Items/Components/Machines/Radar.cs
	Subsurface/Source/Items/Components/Machines/Steering.cs
	Subsurface/Source/Items/Components/Power/PowerContainer.cs
	Subsurface/Source/Items/Inventory.cs
	Subsurface/Source/Items/Item.cs
	Subsurface/Source/Items/ItemSpawner.cs
	Subsurface/Source/Map/Levels/WaterRenderer.cs
	Subsurface/Source/Map/LinkedSubmarine.cs
	Subsurface/Source/Map/Map/Map.cs
	Subsurface/Source/Map/Structure.cs
	Subsurface/Source/Map/Submarine.cs
	Subsurface/Source/Map/WayPoint.cs
	Subsurface/Source/Networking/GameClient.cs
	Subsurface/Source/Networking/GameServer.cs
	Subsurface/Source/Physics/PhysicsBody.cs
	Subsurface/Source/Screens/GameScreen.cs
This commit is contained in:
juanjp600
2016-10-11 20:19:25 -03:00
130 changed files with 4428 additions and 67178 deletions
@@ -310,7 +310,7 @@ namespace Barotrauma
MergeSlots();
}
public override void Update(float deltaTime)
public override void Update(float deltaTime, bool subInventory = false)
{
base.Update(deltaTime);
@@ -339,7 +339,7 @@ namespace Barotrauma
//not equipped -> attempt to equip
if (IsInLimbSlot(doubleClickedItem, InvSlotType.Any))
{
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any));
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any), true);
}
//equipped -> attempt to unequip
else if (doubleClickedItem.AllowedSlots.Contains(InvSlotType.Any))
@@ -467,7 +467,7 @@ namespace Barotrauma
(draggingItem == null || draggingItem.Container != Items[selectedSlot]))
{
selectedSlot = -1;
}
}
}
}
+13 -2
View File
@@ -56,10 +56,15 @@ namespace Barotrauma.Items.Components
get
{
if (linkedGap != null) return linkedGap;
foreach (MapEntity e in item.linkedTo)
{
linkedGap = e as Gap;
if (linkedGap != null) return linkedGap;
linkedGap = e as Gap;
if (linkedGap != null)
{
linkedGap.PassAmbientLight = window != Rectangle.Empty;
return linkedGap;
}
}
Rectangle rect = item.Rect;
if (isHorizontal)
@@ -75,6 +80,7 @@ namespace Barotrauma.Items.Components
linkedGap = new Gap(rect, Item.Submarine);
linkedGap.Submarine = item.Submarine;
linkedGap.PassAmbientLight = window != Rectangle.Empty;
linkedGap.Open = openState;
item.linkedTo.Add(linkedGap);
return linkedGap;
@@ -95,6 +101,11 @@ namespace Barotrauma.Items.Components
}
}
public Rectangle WindowRect
{
get { return window; }
}
[Editable, HasDefaultValue(false, true)]
public bool IsOpen
{
@@ -585,6 +585,8 @@ namespace Barotrauma.Items.Components
return (average+100.0f)/2.0f;
}
public virtual void FlipX() { }
public bool HasRequiredContainedItems(bool addMessage)
{
List<RelatedItem> requiredContained = requiredItems.FindAll(ri=> ri.Type == RelatedItem.RelationType.Contained);
@@ -11,6 +11,12 @@ namespace Barotrauma.Items.Components
{
public LimbType limbType;
public Vector2 position;
public LimbPos(LimbType limbType, Vector2 position)
{
this.limbType = limbType;
this.position = position;
}
}
class Controller : ItemComponent
@@ -243,5 +249,31 @@ namespace Barotrauma.Items.Components
return true;
}
public override void FlipX()
{
if (dir != Direction.None)
{
dir = dir == Direction.Left ? Direction.Right : Direction.Left;
}
if (userPos != 0.0f)
{
float diff = (item.Rect.X + UserPos) - item.Rect.Center.X;
userPos = item.Rect.Center.X - diff - item.Rect.X;
}
for (int i = 0; i < limbPositions.Count; i++)
{
float diff = (item.Rect.X + limbPositions[i].position.X) - item.Rect.Center.X;
Vector2 flippedPos =
new Vector2(
item.Rect.Center.X - diff - item.Rect.X,
limbPositions[i].position.Y);
limbPositions[i] = new LimbPos(limbPositions[i].limbType, flippedPos);
}
}
}
}
@@ -16,7 +16,7 @@ namespace Barotrauma.Items.Components
private float lastUpdate;
private Hull hull1;
public Hull hull1;
private GUITickBox isActiveTickBox;
@@ -21,6 +21,9 @@ namespace Barotrauma.Items.Components
private List<RadarBlip> radarBlips;
private float prevPingRadius;
public static string StartMarker = "Start";
public static string EndMarker = "End";
[HasDefaultValue(10000.0f, false)]
public float Range
{
@@ -100,6 +103,11 @@ namespace Barotrauma.Items.Components
return pingState > 1.0f;
}
public override void UpdateHUD(Character character)
{
GuiFrame.Update((float)Timing.Step);
}
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
GuiFrame.Draw(spriteBatch);
@@ -263,11 +271,11 @@ namespace Barotrauma.Items.Components
DrawMarker(spriteBatch,
(GameMain.GameSession.Map == null) ? "Start" : GameMain.GameSession.Map.CurrentLocation.Name,
(GameMain.GameSession.Map == null) ? StartMarker : GameMain.GameSession.Map.CurrentLocation.Name,
(Level.Loaded.StartPosition - item.WorldPosition), displayScale, center, (rect.Width * 0.5f));
DrawMarker(spriteBatch,
(GameMain.GameSession.Map == null) ? "End" : GameMain.GameSession.Map.SelectedLocation.Name,
(GameMain.GameSession.Map == null) ? EndMarker : GameMain.GameSession.Map.SelectedLocation.Name,
(Level.Loaded.EndPosition - item.WorldPosition), displayScale, center, (rect.Width * 0.5f));
if (GameMain.GameSession.Mission != null)
@@ -284,6 +292,7 @@ namespace Barotrauma.Items.Components
foreach (Submarine sub in Submarine.Loaded)
{
if (!sub.OnRadar) continue;
if (item.Submarine == sub || sub.DockedTo.Contains(item.Submarine)) continue;
if (sub.WorldPosition.Y > Level.Loaded.Size.Y) continue;
@@ -88,6 +88,8 @@ namespace Barotrauma.Items.Components
item.body.CollisionCategories = Physics.CollisionProjectile;
item.body.CollidesWith = Physics.CollisionCharacter | Physics.CollisionWall | Physics.CollisionLevel;
IsActive = true;
if (stickJoint == null || !doesStick) return;
if (stickTarget != null)
@@ -111,6 +113,8 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
if (stickJoint != null && stickJoint.JointTranslation < 0.01f)
{
if (stickTarget != null)
@@ -174,6 +178,8 @@ namespace Barotrauma.Items.Components
ApplyStatusEffects(ActionType.OnUse, 1.0f);
ApplyStatusEffects(ActionType.OnImpact, 1.0f);
IsActive = false;
item.body.FarseerBody.OnCollision -= OnProjectileCollision;
item.body.FarseerBody.IsBullet = false;
@@ -122,7 +122,7 @@ namespace Barotrauma.Items.Components
base.Update(deltaTime, cam);
light.ParentSub = item.Submarine;
ApplyStatusEffects(ActionType.OnActive, deltaTime);
if (item.Container != null)
@@ -7,6 +7,8 @@ namespace Barotrauma.Items.Components
{
private float maxPower;
private float lastReceivedMessage;
[Editable, HasDefaultValue(1000.0f, true)]
public float MaxPower
{
@@ -73,13 +75,43 @@ namespace Barotrauma.Items.Components
}
else if (connection.Name == "toggle")
{
IsOn = !IsOn;
SetState(!IsOn,false,true);
}
else if (connection.Name == "set_state")
{
IsOn = signal != "0";
SetState(signal != "0", false, true);
}
}
public void SetState(bool on, bool isNetworkMessage, bool sendNetworkMessage = false)
{
if (GameMain.Client != null && !isNetworkMessage) return;
IsOn = on;
if (sendNetworkMessage)
{
item.NewComponentEvent(this, false, true);
}
}
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
{
message.Write(IsOn);
return true;
}
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message, float sendingTime)
{
if (sendingTime < lastReceivedMessage) return;
if (GameMain.Server != null)
{
return;
}
lastReceivedMessage = sendingTime;
SetState(message.ReadBoolean(), true);
}
}
}
@@ -470,6 +470,14 @@ namespace Barotrauma.Items.Components
wireSprite.Depth + ((item.ID % 100) * 0.00001f));
}
public override void FlipX()
{
for (int i = 0; i < Nodes.Count; i++)
{
Nodes[i] = new Vector2(-Nodes[i].X, Nodes[i].Y);
}
}
public override XElement Save(XElement parentElement)
{
XElement componentElement = base.Save(parentElement);
@@ -347,6 +347,22 @@ namespace Barotrauma.Items.Components
return projectiles;
}
public override void FlipX()
{
minRotation = (float)Math.PI - minRotation;
maxRotation = (float)Math.PI - maxRotation;
var temp = minRotation;
minRotation = maxRotation;
maxRotation = temp;
while (minRotation < 0)
{
minRotation += MathHelper.TwoPi;
maxRotation += MathHelper.TwoPi;
}
}
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power)
{
+46 -23
View File
@@ -63,9 +63,10 @@ namespace Barotrauma
protected int selectedSlot = -1;
protected InventorySlot[] slots;
public Item[] Items;
private bool isSubInventory;
public bool Locked;
public Vector2 CenterPos
@@ -232,9 +233,13 @@ namespace Barotrauma
}
}
public virtual void Update(float deltaTime)
public virtual void Update(float deltaTime, bool subInventory = false)
{
if (slots == null) CreateSlots();
if (slots == null || isSubInventory != subInventory)
{
CreateSlots();
isSubInventory = subInventory;
}
for (int i = 0; i < capacity; i++)
{
@@ -259,17 +264,15 @@ namespace Barotrauma
}
public virtual void Draw(SpriteBatch spriteBatch)
public virtual void Draw(SpriteBatch spriteBatch, bool subInventory = false)
{
string toolTip = "";
if (slots == null) CreateSlots();
if (slots == null || isSubInventory != subInventory) return;
for (int i = 0; i < capacity; i++)
{
if (slots[i].Disabled) continue;
//don't draw the slot if dragged an item out of it
//don't draw the item if it's being dragged out of the slot
bool drawItem = draggingItem == null || draggingItem != Items[i] || slots[i].IsHighlighted;
DrawSlot(spriteBatch, slots[i], Items[i], drawItem);
@@ -288,8 +291,20 @@ namespace Barotrauma
for (int i = 0; i < capacity; i++)
{
if (slots[i].IsHighlighted && !slots[i].Disabled)
if (slots[i].IsHighlighted && !slots[i].Disabled && Items[i] != null)
{
string toolTip = "";
if (GameMain.DebugDraw)
{
toolTip = Items[i].ToString();
}
else
{
toolTip = string.IsNullOrEmpty(Items[i].Description) ?
Items[i].Name :
Items[i].Name + '\n' + Items[i].Description;
}
DrawToolTip(spriteBatch, toolTip, slots[i].Rect);
break;
}
@@ -371,9 +386,27 @@ namespace Barotrauma
if (container.Inventory.slots == null) container.Inventory.CreateSlots();
int itemCapacity = container.Capacity;
var slot = slots[slotIndex];
Rectangle containerRect = new Rectangle(slot.Rect.X - 5, slot.Rect.Y - (40 + 10) * itemCapacity - 5,
slot.Rect.Width + 10, slot.Rect.Height + (40 + 10) * itemCapacity + 10);
Rectangle subRect = slot.Rect;
subRect.Height = 40;
for (int i = 0; i < itemCapacity; i++)
{
subRect.Y = subRect.Y - subRect.Height - 10;
container.Inventory.slots[i].Rect = subRect;
}
}
container.Inventory.isSubInventory = true;
slots[slotIndex].State = GUIComponent.ComponentState.Hover;
container.Inventory.Update(deltaTime);
container.Inventory.Update(deltaTime, true);
}
public void DrawSubInventory(SpriteBatch spriteBatch, int slotIndex)
@@ -384,8 +417,7 @@ namespace Barotrauma
var container = item.GetComponent<ItemContainer>();
if (container == null) return;
if (container.Inventory.slots == null) container.Inventory.CreateSlots();
if (container.Inventory.slots == null || !container.Inventory.isSubInventory) return;
int itemCapacity = container.Capacity;
@@ -398,20 +430,11 @@ namespace Barotrauma
var slot = slots[slotIndex];
Rectangle containerRect = new Rectangle(slot.Rect.X - 5, slot.Rect.Y - (40 + 10) * itemCapacity - 5,
slot.Rect.Width + 10, slot.Rect.Height + (40 + 10) * itemCapacity + 10);
Rectangle subRect = slot.Rect;
subRect.Height = 40;
GUI.DrawRectangle(spriteBatch, new Rectangle(containerRect.X, containerRect.Y, containerRect.Width, containerRect.Height - slot.Rect.Height - 5), Color.Black * 0.8f, true);
GUI.DrawRectangle(spriteBatch, containerRect, Color.White);
for (int i = 0; i < itemCapacity; i++)
{
subRect.Y = subRect.Y - subRect.Height - 10;
container.Inventory.slots[i].Rect = subRect;
}
container.Inventory.Draw(spriteBatch);
container.Inventory.Draw(spriteBatch, true);
if (!containerRect.Contains(PlayerInput.MousePosition))
{
File diff suppressed because it is too large Load Diff
+56 -9
View File
@@ -58,6 +58,8 @@ namespace Barotrauma
private set;
}
private bool canSpriteFlipX;
//if a matching itemprefab is not found when loading a sub, the game will attempt to find a prefab with a matching alias
//(allows changing item names while keeping backwards compatibility with older sub files)
public string[] Aliases
@@ -116,21 +118,26 @@ namespace Barotrauma
private set;
}
public bool CanSpriteFlipX
{
get { return canSpriteFlipX; }
}
public Vector2 Size
{
get { return size; }
}
public override void UpdatePlacing(SpriteBatch spriteBatch, Camera cam)
public override void UpdatePlacing(Camera cam)
{
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
if (PlayerInput.RightButtonClicked())
{
selected = null;
return;
}
if (!resizeHorizontal && !resizeVertical)
{
if (PlayerInput.LeftButtonClicked())
@@ -138,16 +145,14 @@ namespace Barotrauma
var item = new Item(new Rectangle((int)position.X, (int)position.Y, (int)sprite.size.X, (int)sprite.size.Y), this, Submarine.MainSub);
//constructor.Invoke(lobject);
item.Submarine = Submarine.MainSub;
item.SetTransform(ConvertUnits.ToSimUnits(Submarine.MainSub==null ? item.Position : item.Position - Submarine.MainSub.Position), 0.0f);
item.SetTransform(ConvertUnits.ToSimUnits(Submarine.MainSub == null ? item.Position : item.Position - Submarine.MainSub.Position), 0.0f);
item.FindHull();
placePosition = Vector2.Zero;
// selected = null;
// selected = null;
return;
}
sprite.Draw(spriteBatch, new Vector2(position.X + sprite.size.X / 2.0f, -position.Y + sprite.size.Y / 2.0f), SpriteColor);
}
else
{
@@ -172,17 +177,54 @@ namespace Barotrauma
item.Submarine = Submarine.MainSub;
item.SetTransform(ConvertUnits.ToSimUnits(Submarine.MainSub == null ? item.Position : item.Position - Submarine.MainSub.Position), 0.0f);
item.FindHull();
//selected = null;
return;
}
position = placePosition;
}
}
//if (PlayerInput.GetMouseState.RightButton == ButtonState.Pressed) selected = null;
}
public override void DrawPlacing(SpriteBatch spriteBatch,Camera cam)
{
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
if (PlayerInput.RightButtonClicked())
{
selected = null;
return;
}
if (!resizeHorizontal && !resizeVertical)
{
sprite.Draw(spriteBatch, new Vector2(position.X + sprite.size.X / 2.0f, -position.Y + sprite.size.Y / 2.0f), SpriteColor);
}
else
{
Vector2 placeSize = size;
if (placePosition == Vector2.Zero)
{
if (PlayerInput.LeftButtonHeld()) placePosition = position;
}
else
{
if (resizeHorizontal)
placeSize.X = Math.Max(position.X - placePosition.X, size.X);
if (resizeVertical)
placeSize.Y = Math.Max(placePosition.Y - position.Y, size.Y);
position = placePosition;
}
if (sprite != null) sprite.DrawTiled(spriteBatch, new Vector2(position.X, -position.Y), placeSize, SpriteColor);
}
//if (PlayerInput.GetMouseState.RightButton == ButtonState.Pressed) selected = null;
}
@@ -270,6 +312,9 @@ namespace Barotrauma
DeconstructItems = new List<DeconstructItem>();
DeconstructTime = 1.0f;
tags = new List<string>();
tags.AddRange(ToolBox.GetAttributeString(element, "tags", "").Split(','));
foreach (XElement subElement in element.Elements())
{
switch (subElement.Name.ToString().ToLowerInvariant())
@@ -281,6 +326,8 @@ namespace Barotrauma
spriteFolder = Path.GetDirectoryName(filePath);
}
canSpriteFlipX = ToolBox.GetAttributeBool(subElement, "canflipx", true);
sprite = new Sprite(subElement, spriteFolder);
size = sprite.size;
break;
+53 -34
View File
@@ -6,7 +6,35 @@ namespace Barotrauma
{
class ItemSpawner
{
private readonly Queue<Pair<ItemPrefab, object>> spawnQueue;
class ItemSpawnInfo
{
public readonly ItemPrefab Prefab;
public readonly Vector2 Position;
public readonly Inventory Inventory;
public readonly Submarine Submarine;
public ItemSpawnInfo(ItemPrefab prefab, Vector2 worldPosition)
{
Prefab = prefab;
Position = worldPosition;
}
public ItemSpawnInfo(ItemPrefab prefab, Vector2 position, Submarine sub)
{
Prefab = prefab;
Position = position;
Submarine = sub;
}
public ItemSpawnInfo(ItemPrefab prefab, Inventory inventory)
{
Prefab = prefab;
Inventory = inventory;
}
}
private readonly Queue<ItemSpawnInfo> spawnQueue;
public List<Item> spawnItems = new List<Item>();
@@ -14,37 +42,31 @@ namespace Barotrauma
public ItemSpawner()
{
spawnQueue = new Queue<Pair<ItemPrefab, object>>();
spawnQueue = new Queue<ItemSpawnInfo>();
}
public void QueueItem(ItemPrefab itemPrefab, Vector2 worldPosition, bool isNetworkMessage = false)
{
if (!isNetworkMessage && GameMain.Client != null)
{
//clients aren't allowed to spawn new items unless the server says so
return;
}
//clients aren't allowed to spawn new items unless the server says so
if (!isNetworkMessage && GameMain.Client != null) return;
spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, worldPosition));
}
var itemInfo = new Pair<ItemPrefab, object>();
itemInfo.First = itemPrefab;
itemInfo.Second = worldPosition;
public void QueueItem(ItemPrefab itemPrefab, Vector2 position, Submarine sub, bool isNetworkMessage = false)
{
//clients aren't allowed to spawn new items unless the server says so
if (!isNetworkMessage && GameMain.Client != null) return;
spawnQueue.Enqueue(itemInfo);
spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, position, sub));
}
public void QueueItem(ItemPrefab itemPrefab, Inventory inventory, bool isNetworkMessage = false)
{
if (!isNetworkMessage && GameMain.Client != null)
{
//clients aren't allowed to spawn new items unless the server says so
return;
}
//clients aren't allowed to spawn new items unless the server says so
if (!isNetworkMessage && GameMain.Client != null) return;
var itemInfo = new Pair<ItemPrefab, object>();
itemInfo.First = itemPrefab;
itemInfo.Second = inventory;
spawnQueue.Enqueue(itemInfo);
spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, inventory));
}
public void Update()
@@ -58,23 +80,20 @@ namespace Barotrauma
{
var itemInfo = spawnQueue.Dequeue();
if (itemInfo.Second is Vector2)
Item spawnedItem = null;
if (itemInfo.Inventory != null)
{
var item = new Item(itemInfo.First, (Vector2)itemInfo.Second, null);
AddToSpawnedList(item);
items.Add(item);
spawnedItem = new Item(itemInfo.Prefab, Vector2.Zero, null);
itemInfo.Inventory.TryPutItem(spawnedItem, spawnedItem.AllowedSlots, false);
}
else if (itemInfo.Second is Inventory)
else
{
var item = new Item(itemInfo.First, Vector2.Zero, null);
AddToSpawnedList(item);
var inventory = (Inventory)itemInfo.Second;
inventory.TryPutItem(item, null);
items.Add(item);
spawnedItem = new Item(itemInfo.Prefab, itemInfo.Position, itemInfo.Submarine);
}
AddToSpawnedList(spawnedItem);
items.Add(spawnedItem);
}
}