# Conflicts:
#	Subsurface/Source/GameSession/GameSession.cs
This commit is contained in:
juanjp600
2016-11-16 21:32:22 -03:00
12 changed files with 112 additions and 67 deletions
+1 -1
View File
@@ -627,7 +627,7 @@ namespace Barotrauma
var wire = item.GetComponent<Wire>(); var wire = item.GetComponent<Wire>();
if (wire == null) continue; if (wire == null) continue;
if (wire.Nodes.Any() && !wire.Connections.Any(c => c != null)) if (wire.GetNodes().Count > 0 && !wire.Connections.Any(c => c != null))
{ {
wire.Item.Drop(null); wire.Item.Drop(null);
DebugConsole.NewMessage("Dropped wire (ID: "+wire.Item.ID+") - attached on wall but no connections found", Color.Orange); DebugConsole.NewMessage("Dropped wire (ID: "+wire.Item.ID+") - attached on wall but no connections found", Color.Orange);
@@ -362,6 +362,8 @@ namespace Barotrauma
public void AddToGUIUpdateList() public void AddToGUIUpdateList()
{ {
if (CrewManager != null) CrewManager.AddToGUIUpdateList();
if (gameMode != null) gameMode.AddToGUIUpdateList(); if (gameMode != null) gameMode.AddToGUIUpdateList();
infoButton.AddToGUIUpdateList(); infoButton.AddToGUIUpdateList();
@@ -56,8 +56,7 @@ namespace Barotrauma.Items.Components
static Sprite wireSprite; static Sprite wireSprite;
public List<Vector2> Nodes; private List<Vector2> nodes;
private List<WireSection> sections; private List<WireSection> sections;
Connection[] connections; Connection[] connections;
@@ -83,7 +82,7 @@ namespace Barotrauma.Items.Components
wireSprite.Depth = 0.85f; wireSprite.Depth = 0.85f;
} }
Nodes = new List<Vector2>(); nodes = new List<Vector2>();
sections = new List<WireSection>(); sections = new List<WireSection>();
connections = new Connection[2]; connections = new Connection[2];
@@ -159,17 +158,17 @@ namespace Barotrauma.Items.Components
if (newConnection.Item.Submarine == null) continue; if (newConnection.Item.Submarine == null) continue;
if (Nodes.Count > 0 && Nodes[0] == 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 (nodes.Count > 1 && nodes[nodes.Count-1] == newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition) break;
if (i == 0) if (i == 0)
{ {
Nodes.Insert(0, newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition); nodes.Insert(0, newConnection.Item.Position - newConnection.Item.Submarine.HiddenSubPosition);
} }
else 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(); CleanNodes();
} }
Drawable = Nodes.Any(); Drawable = nodes.Any();
if (!loading) Item.NewComponentEvent(this, true, true); if (!loading) Item.NewComponentEvent(this, true, true);
@@ -225,7 +224,7 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
{ {
if (Nodes.Count == 0) return; if (nodes.Count == 0) return;
Submarine sub = null; Submarine sub = null;
if (connections[0] != null && connections[0].Item.Submarine != null) sub = connections[0].Item.Submarine; if (connections[0] != null && connections[0].Item.Submarine != null) sub = connections[0].Item.Submarine;
@@ -234,7 +233,6 @@ namespace Barotrauma.Items.Components
if (item.Submarine != sub && Screen.Selected != GameMain.EditMapScreen) if (item.Submarine != sub && Screen.Selected != GameMain.EditMapScreen)
{ {
ClearConnections(); ClearConnections();
Nodes.Clear();
return; return;
} }
@@ -245,9 +243,9 @@ namespace Barotrauma.Items.Components
{ {
if (character == Character.Controlled && character.SelectedConstruction != null) return false; 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(); UpdateSections();
Drawable = true; Drawable = true;
@@ -259,9 +257,9 @@ namespace Barotrauma.Items.Components
public override void SecondaryUse(float deltaTime, Character character = null) 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(); UpdateSections();
item.NewComponentEvent(this, true, true); item.NewComponentEvent(this, true, true);
@@ -282,11 +280,22 @@ namespace Barotrauma.Items.Components
if (item.IsSelected) MoveNodes(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) public void MoveNodes(Vector2 amount)
{ {
for (int i = 0; i < Nodes.Count; i++) for (int i = 0; i < nodes.Count; i++)
{ {
Nodes[i] += amount; nodes[i] += amount;
} }
UpdateSections(); UpdateSections();
} }
@@ -295,16 +304,16 @@ namespace Barotrauma.Items.Components
{ {
sections.Clear(); 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; Drawable = sections.Count > 0;
} }
private void ClearConnections() private void ClearConnections()
{ {
Nodes.Clear(); nodes.Clear();
sections.Clear(); sections.Clear();
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
@@ -348,14 +357,14 @@ namespace Barotrauma.Items.Components
private void CleanNodes() 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) && 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)) (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);
} }
} }
} }
@@ -364,12 +373,12 @@ namespace Barotrauma.Items.Components
do do
{ {
removed = false; 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) 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[i - 1].Y == nodes[i].Y && nodes[i + 1].Y == nodes[i].Y))
{ {
Nodes.RemoveAt(i); nodes.RemoveAt(i);
removed = true; removed = true;
} }
} }
@@ -414,11 +423,11 @@ namespace Barotrauma.Items.Components
section.Draw(spriteBatch, item.Color, drawOffset, depth, 0.3f); 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( WireSection.Draw(
spriteBatch, 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, new Vector2(newNodePos.X, newNodePos.Y) + drawOffset,
item.Color * 0.5f, item.Color * 0.5f,
depth, depth,
@@ -428,9 +437,9 @@ namespace Barotrauma.Items.Components
if (!editing || !PlayerInput.MouseInsideWindow || !GameMain.EditMapScreen.WiringMode) return; if (!editing || !PlayerInput.MouseInsideWindow || !GameMain.EditMapScreen.WiringMode) return;
if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null) 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; if (item.Submarine != null) worldPos += item.Submarine.Position + item.Submarine.HiddenSubPosition;
worldPos.Y = -worldPos.Y; worldPos.Y = -worldPos.Y;
@@ -458,7 +467,7 @@ namespace Barotrauma.Items.Components
} }
else if (PlayerInput.RightButtonClicked()) else if (PlayerInput.RightButtonClicked())
{ {
Nodes.RemoveAt(i); nodes.RemoveAt(i);
break; break;
} }
} }
@@ -483,7 +492,7 @@ namespace Barotrauma.Items.Components
//if (item.Submarine != null) nodeWorldPos += item.Submarine.Position; //if (item.Submarine != null) nodeWorldPos += item.Submarine.Position;
Nodes[(int)selectedNodeIndex] = nodeWorldPos; nodes[(int)selectedNodeIndex] = nodeWorldPos;
UpdateSections(); UpdateSections();
MapEntity.SelectEntity(item); MapEntity.SelectEntity(item);
@@ -498,23 +507,24 @@ namespace Barotrauma.Items.Components
public override void FlipX() 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) public override XElement Save(XElement parentElement)
{ {
XElement componentElement = base.Save(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]; string[] nodeCoords = new string[nodes.Count * 2];
for (int i = 0; i < Nodes.Count; i++) for (int i = 0; i < nodes.Count; i++)
{ {
nodeCoords[i * 2] = Nodes[i].X.ToString(CultureInfo.InvariantCulture); nodeCoords[i * 2] = nodes[i].X.ToString(CultureInfo.InvariantCulture);
nodeCoords[i * 2 + 1] = Nodes[i].Y.ToString(CultureInfo.InvariantCulture); nodeCoords[i * 2 + 1] = nodes[i].Y.ToString(CultureInfo.InvariantCulture);
} }
componentElement.Add(new XAttribute("nodes", string.Join(";", nodeCoords))); componentElement.Add(new XAttribute("nodes", string.Join(";", nodeCoords)));
@@ -546,10 +556,10 @@ namespace Barotrauma.Items.Components
} }
catch { y = 0.0f; } catch { y = 0.0f; }
Nodes.Add(new Vector2(x, y)); nodes.Add(new Vector2(x, y));
} }
Drawable = Nodes.Any(); Drawable = nodes.Any();
} }
@@ -562,11 +572,11 @@ namespace Barotrauma.Items.Components
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message) public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
{ {
message.Write((byte)Math.Min(Nodes.Count, 10)); message.Write((byte)Math.Min(nodes.Count, 10));
for (int i = 0; i < Math.Min(Nodes.Count,10); i++) for (int i = 0; i < Math.Min(nodes.Count,10); i++)
{ {
message.Write(Nodes[i].X); message.Write(nodes[i].X);
message.Write(Nodes[i].Y); message.Write(nodes[i].Y);
} }
return true; return true;
@@ -574,7 +584,7 @@ namespace Barotrauma.Items.Components
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message, float sendingTime) public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message, float sendingTime)
{ {
Nodes.Clear(); nodes.Clear();
List<Vector2> newNodes = new List<Vector2>(); List<Vector2> newNodes = new List<Vector2>();
int nodeCount = message.ReadByte(); int nodeCount = message.ReadByte();
@@ -585,9 +595,8 @@ namespace Barotrauma.Items.Components
newNodes.Add(newNode); newNodes.Add(newNode);
} }
Nodes = newNodes; SetNodes(newNodes);
Drawable = nodes.Any();
Drawable = Nodes.Any();
} }
} }
} }
+1 -2
View File
@@ -251,8 +251,7 @@ namespace Barotrauma
var originalWire = ((Item)entitiesToClone[i]).GetComponent<Wire>(); var originalWire = ((Item)entitiesToClone[i]).GetComponent<Wire>();
cloneWire.Nodes = new List<Vector2>(originalWire.Nodes); cloneWire.SetNodes(originalWire.GetNodes());
cloneWire.UpdateSections();
for (int n = 0; n < 2; n++) for (int n = 0; n < 2; n++)
{ {
+4 -1
View File
@@ -1080,7 +1080,10 @@ namespace Barotrauma
if (item.Submarine != this) continue; if (item.Submarine != this) continue;
var wire = item.GetComponent<Items.Components.Wire>(); var wire = item.GetComponent<Items.Components.Wire>();
if (wire != null) wire.MoveNodes(-center); if (wire != null)
{
wire.MoveNodes(-center);
}
} }
for (int i = 0; i < MapEntity.mapEntityList.Count; i++) for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
@@ -1973,6 +1973,7 @@ namespace Barotrauma.Networking
public override void Disconnect() public override void Disconnect()
{ {
banList.Save(); banList.Save();
SaveSettings();
if (registeredToMaster && restClient != null) if (registeredToMaster && restClient != null)
{ {
@@ -189,7 +189,8 @@ namespace Barotrauma.Networking
{ {
get { return banList; } get { return banList; }
} }
[HasDefaultValue(true, true)]
public bool AllowVoteKick public bool AllowVoteKick
{ {
get; get;
@@ -218,9 +219,16 @@ namespace Barotrauma.Networking
doc.Root.SetAttributeValue("SubSelection", subSelectionMode.ToString()); doc.Root.SetAttributeValue("SubSelection", subSelectionMode.ToString());
doc.Root.SetAttributeValue("ModeSelection", modeSelectionMode.ToString()); doc.Root.SetAttributeValue("ModeSelection", modeSelectionMode.ToString());
doc.Root.SetAttributeValue("TraitorsEnabled", TraitorsEnabled.ToString());
doc.Root.SetAttributeValue("MaxFileTransferDuration", FileStreamSender.MaxTransferDuration.TotalSeconds); doc.Root.SetAttributeValue("MaxFileTransferDuration", FileStreamSender.MaxTransferDuration.TotalSeconds);
if (GameMain.NetLobbyScreen != null && GameMain.NetLobbyScreen.ServerMessage != null)
{
doc.Root.SetAttributeValue("ServerMessage", GameMain.NetLobbyScreen.ServerMessage.Text);
}
XmlWriterSettings settings = new XmlWriterSettings(); XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true; settings.Indent = true;
settings.NewLineOnAttributes = true; settings.NewLineOnAttributes = true;
@@ -253,9 +261,18 @@ namespace Barotrauma.Networking
modeSelectionMode = SelectionMode.Manual; modeSelectionMode = SelectionMode.Manual;
Enum.TryParse<SelectionMode>(ToolBox.GetAttributeString(doc.Root, "ModeSelection", "Manual"), out modeSelectionMode); Enum.TryParse<SelectionMode>(ToolBox.GetAttributeString(doc.Root, "ModeSelection", "Manual"), out modeSelectionMode);
Voting.AllowModeVoting = modeSelectionMode == SelectionMode.Vote; Voting.AllowModeVoting = modeSelectionMode == SelectionMode.Vote;
var traitorsEnabled = TraitorsEnabled;
Enum.TryParse<YesNoMaybe>(ToolBox.GetAttributeString(doc.Root, "TraitorsEnabled", "No"), out traitorsEnabled);
TraitorsEnabled = traitorsEnabled;
GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled);
FileStreamSender.MaxTransferDuration = new TimeSpan(0,0,ToolBox.GetAttributeInt(doc.Root, "MaxFileTransferDuration", 150)); FileStreamSender.MaxTransferDuration = new TimeSpan(0,0,ToolBox.GetAttributeInt(doc.Root, "MaxFileTransferDuration", 150));
if (GameMain.NetLobbyScreen != null && GameMain.NetLobbyScreen.ServerMessage != null)
{
GameMain.NetLobbyScreen.ServerMessage.Text = ToolBox.GetAttributeString(doc.Root, "ServerMessage", "");
}
showLogButton.Visible = SaveServerLogs; showLogButton.Visible = SaveServerLogs;
List<string> monsterNames = Directory.GetDirectories("Content/Characters").ToList(); List<string> monsterNames = Directory.GetDirectories("Content/Characters").ToList();
@@ -343,8 +343,6 @@ namespace Barotrauma.Networking
if (gameStarted && Screen.Selected == GameMain.GameScreen) if (gameStarted && Screen.Selected == GameMain.GameScreen)
{ {
inGameHUD.AddToGUIUpdateList(); inGameHUD.AddToGUIUpdateList();
GameMain.GameSession.CrewManager.AddToGUIUpdateList();
} }
} }
+12 -1
View File
@@ -109,7 +109,18 @@ namespace Barotrauma.Particles
{ {
for (int i = 0; i < particleCount; i++) for (int i = 0; i < particleCount; i++)
{ {
if (!particles[i].Update(deltaTime)) RemoveParticle(i); bool remove = false;
try
{
remove = !particles[i].Update(deltaTime);
}
catch (Exception e)
{
DebugConsole.ThrowError("Particle update failed", e);
remove = true;
}
if (remove) RemoveParticle(i);
} }
} }
+1 -1
View File
@@ -657,7 +657,7 @@ namespace Barotrauma
private GUIFrame CreateWiringPanel() private GUIFrame CreateWiringPanel()
{ {
GUIFrame frame = new GUIFrame(new Rectangle(0,0,50,300), null, Alignment.Right | Alignment.CenterY, GUI.Style); GUIFrame frame = new GUIFrame(new Rectangle(0,0,65,300), null, Alignment.Right | Alignment.CenterY, GUI.Style);
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
GUIListBox listBox = new GUIListBox(Rectangle.Empty, GUI.Style, frame); GUIListBox listBox = new GUIListBox(Rectangle.Empty, GUI.Style, frame);
+3 -2
View File
@@ -91,8 +91,6 @@ namespace Barotrauma
public override void AddToGUIUpdateList() public override void AddToGUIUpdateList()
{ {
if (GameMain.GameSession != null) GameMain.GameSession.AddToGUIUpdateList();
if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null) if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null)
{ {
if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem) if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem)
@@ -100,6 +98,9 @@ namespace Barotrauma
Character.Controlled.SelectedConstruction.AddToGUIUpdateList(); Character.Controlled.SelectedConstruction.AddToGUIUpdateList();
} }
} }
if (GameMain.GameSession != null) GameMain.GameSession.AddToGUIUpdateList();
Character.AddAllToGUIUpdateList(); Character.AddAllToGUIUpdateList();
} }
+6 -2
View File
@@ -51,6 +51,11 @@ namespace Barotrauma
private GUITextBox serverMessage; private GUITextBox serverMessage;
public GUITextBox ServerMessage
{
get { return serverMessage; }
}
public GUIListBox SubList public GUIListBox SubList
{ {
get { return subList; } get { return subList; }
@@ -600,9 +605,8 @@ namespace Barotrauma
return true; return true;
} }
private void SetTraitorsEnabled(YesNoMaybe enabled) public void SetTraitorsEnabled(YesNoMaybe enabled)
{ {
if (GameMain.Server != null) GameMain.Server.TraitorsEnabled = enabled; if (GameMain.Server != null) GameMain.Server.TraitorsEnabled = enabled;
(traitorProbabilityText as GUITextBlock).Text = enabled.ToString(); (traitorProbabilityText as GUITextBlock).Text = enabled.ToString();
} }