Merge branch 'master' into new-netcode

Conflicts:
	Subsurface/Properties/AssemblyInfo.cs
	Subsurface/Source/Characters/Animation/HumanoidAnimController.cs
	Subsurface/Source/Characters/Character.cs
	Subsurface/Source/Items/Components/Door.cs
	Subsurface/Source/Items/Components/Power/PowerContainer.cs
	Subsurface/Source/Items/Components/Signal/Wire.cs
	Subsurface/Source/Items/Item.cs
	Subsurface/Source/Networking/ChatMessage.cs
	Subsurface/Source/Networking/GameClient.cs
	Subsurface/Source/Networking/GameServer.cs
	Subsurface/Source/Networking/GameServerLogin.cs
	Subsurface/Source/Networking/GameServerSettings.cs
	Subsurface/Source/Networking/NetworkMember.cs
This commit is contained in:
Regalis
2016-11-24 19:43:45 +02:00
93 changed files with 1872 additions and 683 deletions
@@ -24,7 +24,7 @@ namespace Barotrauma.Items.Components
private Item item;
public readonly bool IsOutput;
private static Wire draggingConnected;
private List<StatusEffect> effects;
@@ -433,8 +433,7 @@ namespace Barotrauma.Items.Components
{
if (mouseOn)
{
item.IsHighlighted = true;
wire.Item.IsHighlighted = true;
ConnectionPanel.HighlightedWire = wire;
if (!wire.Locked)
{
@@ -7,7 +7,9 @@ using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
class ConnectionPanel : ItemComponent
{
{
public static Wire HighlightedWire;
public List<Connection> Connections;
Character user;
@@ -33,15 +35,29 @@ namespace Barotrauma.Items.Components
IsActive = true;
}
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
public override void UpdateHUD(Character character)
{
if (character != Character.Controlled || character != user) return;
if (Screen.Selected != GameMain.EditMapScreen &&
character.IsKeyHit(InputType.Select) &&
character.SelectedConstruction==this.item) character.SelectedConstruction = null;
character.IsKeyHit(InputType.Select) &&
character.SelectedConstruction == this.item) character.SelectedConstruction = null;
if (HighlightedWire != null)
{
HighlightedWire.Item.IsHighlighted = true;
if (HighlightedWire.Connections[0] != null && HighlightedWire.Connections[0].Item != null) HighlightedWire.Connections[0].Item.IsHighlighted = true;
if (HighlightedWire.Connections[1] != null && HighlightedWire.Connections[1].Item != null) HighlightedWire.Connections[1].Item.IsHighlighted = true;
}
}
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
if (character != Character.Controlled || character != user) return;
HighlightedWire = null;
Connection.DrawConnections(spriteBatch, this, character);
}
public override XElement Save(XElement parentElement)
@@ -56,8 +56,7 @@ namespace Barotrauma.Items.Components
static Sprite wireSprite;
public List<Vector2> Nodes;
private List<Vector2> nodes;
private List<WireSection> sections;
Connection[] connections;
@@ -83,7 +82,7 @@ namespace Barotrauma.Items.Components
wireSprite.Depth = 0.85f;
}
Nodes = new List<Vector2>();
nodes = new List<Vector2>();
sections = new List<WireSection>();
connections = new Connection[2];
@@ -159,17 +158,17 @@ namespace Barotrauma.Items.Components
if (newConnection.Item.Submarine == null) continue;
if (Nodes.Count > 0 && Nodes[0] == newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition) break;
if (Nodes.Count > 1 && Nodes[Nodes.Count-1] == newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition) break;
if (nodes.Count > 0 && nodes[0] == newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition) break;
if (nodes.Count > 1 && nodes[nodes.Count-1] == newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition) break;
if (i == 0)
{
Nodes.Insert(0, newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition);
nodes.Insert(0, newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition);
}
else
{
Nodes.Add(newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition);
nodes.Add(newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition);
}
@@ -192,7 +191,7 @@ namespace Barotrauma.Items.Components
CleanNodes();
}
Drawable = Nodes.Any();
Drawable = nodes.Any();
UpdateSections();
return true;
@@ -222,7 +221,7 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
if (Nodes.Count == 0) return;
if (nodes.Count == 0) return;
Submarine sub = null;
if (connections[0] != null && connections[0].Item.Submarine != null) sub = connections[0].Item.Submarine;
@@ -231,7 +230,6 @@ namespace Barotrauma.Items.Components
if (item.Submarine != sub && Screen.Selected != GameMain.EditMapScreen)
{
ClearConnections();
Nodes.Clear();
return;
}
@@ -242,9 +240,9 @@ namespace Barotrauma.Items.Components
{
if (character == Character.Controlled && character.SelectedConstruction != null) return false;
if (newNodePos!= Vector2.Zero && Nodes.Count>0 && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance)
if (newNodePos!= Vector2.Zero && nodes.Count>0 && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
{
Nodes.Add(newNodePos);
nodes.Add(newNodePos);
UpdateSections();
Drawable = true;
@@ -256,13 +254,13 @@ namespace Barotrauma.Items.Components
public override void SecondaryUse(float deltaTime, Character character = null)
{
if (Nodes.Count > 1)
if (nodes.Count > 1)
{
Nodes.RemoveAt(Nodes.Count - 1);
nodes.RemoveAt(nodes.Count - 1);
UpdateSections();
}
Drawable = Nodes.Any();
Drawable = sections.Count > 0;
}
public override bool Pick(Character picker)
@@ -272,19 +270,45 @@ namespace Barotrauma.Items.Components
return true;
}
public override void Move(Vector2 amount)
{
if (item.IsSelected) MoveNodes(amount);
}
public List<Vector2> GetNodes()
{
return new List<Vector2>(nodes);
}
public void SetNodes(List<Vector2> nodes)
{
this.nodes = new List<Vector2>(nodes);
UpdateSections();
}
public void MoveNodes(Vector2 amount)
{
for (int i = 0; i < nodes.Count; i++)
{
nodes[i] += amount;
}
UpdateSections();
}
public void UpdateSections()
{
sections.Clear();
for (int i = 0; i < Nodes.Count-1; i++)
for (int i = 0; i < nodes.Count-1; i++)
{
sections.Add(new WireSection(Nodes[i], Nodes[i + 1]));
sections.Add(new WireSection(nodes[i], nodes[i + 1]));
}
Drawable = sections.Count > 0;
}
private void ClearConnections()
{
Nodes.Clear();
nodes.Clear();
sections.Clear();
for (int i = 0; i < 2; i++)
@@ -298,7 +322,7 @@ namespace Barotrauma.Items.Components
connections[i] = null;
}
Drawable = false;
Drawable = sections.Count > 0;
}
private Vector2 RoundNode(Vector2 position, Hull hull)
@@ -328,14 +352,14 @@ namespace Barotrauma.Items.Components
private void CleanNodes()
{
for (int i = Nodes.Count - 2; i > 0; i--)
for (int i = nodes.Count - 2; i > 0; i--)
{
if ((Nodes[i - 1].X == Nodes[i].X || Nodes[i - 1].Y == Nodes[i].Y) &&
(Nodes[i + 1].X == Nodes[i].X || Nodes[i + 1].Y == Nodes[i].Y))
if ((nodes[i - 1].X == nodes[i].X || nodes[i - 1].Y == nodes[i].Y) &&
(nodes[i + 1].X == nodes[i].X || nodes[i + 1].Y == nodes[i].Y))
{
if (Vector2.Distance(Nodes[i - 1], Nodes[i]) == Vector2.Distance(Nodes[i + 1], Nodes[i]))
if (Vector2.Distance(nodes[i - 1], nodes[i]) == Vector2.Distance(nodes[i + 1], nodes[i]))
{
Nodes.RemoveAt(i);
nodes.RemoveAt(i);
}
}
}
@@ -344,12 +368,12 @@ namespace Barotrauma.Items.Components
do
{
removed = false;
for (int i = Nodes.Count - 2; i > 0; i--)
for (int i = nodes.Count - 2; i > 0; i--)
{
if ((Nodes[i - 1].X == Nodes[i].X && Nodes[i + 1].X == Nodes[i].X)
|| (Nodes[i - 1].Y == Nodes[i].Y && Nodes[i + 1].Y == Nodes[i].Y))
if ((nodes[i - 1].X == nodes[i].X && nodes[i + 1].X == nodes[i].X)
|| (nodes[i - 1].Y == nodes[i].Y && nodes[i + 1].Y == nodes[i].Y))
{
Nodes.RemoveAt(i);
nodes.RemoveAt(i);
removed = true;
}
}
@@ -360,7 +384,7 @@ namespace Barotrauma.Items.Components
public void Draw(SpriteBatch spriteBatch, bool editing)
{
if (!Nodes.Any())
if (sections.Count == 0)
{
Drawable = false;
return;
@@ -378,7 +402,14 @@ namespace Barotrauma.Items.Components
{
foreach (WireSection section in sections)
{
section.Draw(spriteBatch, Color.Gold, drawOffset, depth, 0.5f);
section.Draw(spriteBatch, Color.Gold, drawOffset, depth + 0.00001f, 0.7f);
}
}
else if (item.IsSelected)
{
foreach (WireSection section in sections)
{
section.Draw(spriteBatch, Color.Red, drawOffset, depth + 0.00001f, 0.7f);
}
}
@@ -387,11 +418,11 @@ namespace Barotrauma.Items.Components
section.Draw(spriteBatch, item.Color, drawOffset, depth, 0.3f);
}
if (IsActive && Vector2.Distance(newNodePos, Nodes[Nodes.Count - 1]) > nodeDistance)
if (IsActive && Vector2.Distance(newNodePos, nodes[nodes.Count - 1]) > nodeDistance)
{
WireSection.Draw(
spriteBatch,
new Vector2(Nodes[Nodes.Count - 1].X, Nodes[Nodes.Count - 1].Y) + drawOffset,
new Vector2(nodes[nodes.Count - 1].X, nodes[nodes.Count - 1].Y) + drawOffset,
new Vector2(newNodePos.X, newNodePos.Y) + drawOffset,
item.Color * 0.5f,
depth,
@@ -401,9 +432,9 @@ namespace Barotrauma.Items.Components
if (!editing || !PlayerInput.MouseInsideWindow || !GameMain.EditMapScreen.WiringMode) return;
if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null) return;
for (int i = 0; i < Nodes.Count; i++)
for (int i = 0; i < nodes.Count; i++)
{
Vector2 worldPos = Nodes[i];
Vector2 worldPos = nodes[i];
if (item.Submarine != null) worldPos += item.Submarine.Position + item.Submarine.HiddenSubPosition;
worldPos.Y = -worldPos.Y;
@@ -431,7 +462,7 @@ namespace Barotrauma.Items.Components
}
else if (PlayerInput.RightButtonClicked())
{
Nodes.RemoveAt(i);
nodes.RemoveAt(i);
break;
}
}
@@ -456,7 +487,8 @@ namespace Barotrauma.Items.Components
//if (item.Submarine != null) nodeWorldPos += item.Submarine.Position;
Nodes[(int)selectedNodeIndex] = nodeWorldPos;
nodes[(int)selectedNodeIndex] = nodeWorldPos;
UpdateSections();
MapEntity.SelectEntity(item);
}
@@ -470,23 +502,24 @@ namespace Barotrauma.Items.Components
public override void FlipX()
{
for (int i = 0; i < Nodes.Count; i++)
for (int i = 0; i < nodes.Count; i++)
{
Nodes[i] = new Vector2(-Nodes[i].X, Nodes[i].Y);
}
nodes[i] = new Vector2(-nodes[i].X, nodes[i].Y);
}
UpdateSections();
}
public override XElement Save(XElement parentElement)
{
XElement componentElement = base.Save(parentElement);
if (Nodes == null || Nodes.Count == 0) return componentElement;
if (nodes == null || nodes.Count == 0) return componentElement;
string[] nodeCoords = new string[Nodes.Count * 2];
for (int i = 0; i < Nodes.Count; i++)
string[] nodeCoords = new string[nodes.Count * 2];
for (int i = 0; i < nodes.Count; i++)
{
nodeCoords[i * 2] = Nodes[i].X.ToString(CultureInfo.InvariantCulture);
nodeCoords[i * 2 + 1] = Nodes[i].Y.ToString(CultureInfo.InvariantCulture);
nodeCoords[i * 2] = nodes[i].X.ToString(CultureInfo.InvariantCulture);
nodeCoords[i * 2 + 1] = nodes[i].Y.ToString(CultureInfo.InvariantCulture);
}
componentElement.Add(new XAttribute("nodes", string.Join(";", nodeCoords)));
@@ -518,10 +551,10 @@ namespace Barotrauma.Items.Components
}
catch { y = 0.0f; }
Nodes.Add(new Vector2(x, y));
nodes.Add(new Vector2(x, y));
}
Drawable = Nodes.Any();
Drawable = nodes.Any();
}
@@ -534,26 +567,27 @@ namespace Barotrauma.Items.Components
public void ClientWrite(Lidgren.Network.NetBuffer msg, object[] extraData = null)
{
msg.Write((byte)Math.Min(Nodes.Count, 255));
for (int i = 0; i < Math.Min(Nodes.Count, 255); i++)
msg.Write((byte)Math.Min(nodes.Count, 255));
for (int i = 0; i < Math.Min(nodes.Count, 255); i++)
{
msg.Write(Nodes[i].X);
msg.Write(Nodes[i].Y);
msg.Write(nodes[i].X);
msg.Write(nodes[i].Y);
}
}
public void ServerRead(Lidgren.Network.NetIncomingMessage msg, Barotrauma.Networking.Client c)
{
Nodes.Clear();
nodes.Clear();
int nodeCount = msg.ReadByte();
for (int i = 0; i < nodeCount; i++)
{
Vector2 newNode = new Vector2(msg.ReadFloat(), msg.ReadFloat());
if (MathUtils.IsValid(newNode)) Nodes.Add(newNode);
if (MathUtils.IsValid(newNode)) nodes.Add(newNode);
}
Drawable = Nodes.Any();
UpdateSections();
Drawable = nodes.Any();
}
}