Unstable 1.1.14.0

This commit is contained in:
Markus Isberg
2023-10-02 16:43:54 +03:00
parent 94f5a93a0c
commit cf8f0de659
606 changed files with 21906 additions and 11456 deletions
@@ -25,7 +25,7 @@ namespace Barotrauma
public bool CanAddConnections { get; set; }
public readonly List<NodeConnection> Connections = new List<NodeConnection>();
public readonly List<EventEditorNodeConnection> Connections = new List<EventEditorNodeConnection>();
public readonly List<NodeConnectionType> RemovableTypes = new List<NodeConnectionType>();
@@ -47,7 +47,7 @@ namespace Barotrauma
public XElement SaveConnections()
{
XElement allConnections = new XElement("Connections", new XAttribute("i", ID));
foreach (NodeConnection connection in Connections)
foreach (EventEditorNodeConnection connection in Connections)
{
XElement connectionElement = new XElement("Connection");
connectionElement.Add(new XAttribute("i", connection.ID));
@@ -93,12 +93,12 @@ namespace Barotrauma
if (id < 0) { continue; }
NodeConnection? connection = Connections.Find(c => c.ID == id);
EventEditorNodeConnection? connection = Connections.Find(c => c.ID == id);
if (connection == null)
{
if (string.Equals(connectionType, NodeConnectionType.Option.Label, StringComparison.InvariantCultureIgnoreCase))
{
connection = new NodeConnection(this, NodeConnectionType.Option) { ID = id, EndConversation = endConversation };
connection = new EventEditorNodeConnection(this, NodeConnectionType.Option) { ID = id, EndConversation = endConversation };
Connections.Add(connection);
}
else
@@ -143,7 +143,7 @@ namespace Barotrauma
if (id2 < 0 || node < 0) { continue; }
EditorNode? otherNode = EventEditorScreen.nodeList.Find(editorNode => editorNode.ID == node);
NodeConnection? otherConnection = otherNode?.Connections.Find(c => c.ID == id2);
EventEditorNodeConnection? otherConnection = otherNode?.Connections.Find(c => c.ID == id2);
if (otherConnection != null)
{
connection.ConnectedTo.Add(otherConnection);
@@ -184,20 +184,20 @@ namespace Barotrauma
public void Connect(EditorNode otherNode, NodeConnectionType type)
{
NodeConnection? conn = Connections.Find(connection => connection.Type == type && !connection.ConnectedTo.Any());
NodeConnection? found = otherNode.Connections.Find(connection => connection.Type == NodeConnectionType.Activate);
EventEditorNodeConnection? conn = Connections.Find(connection => connection.Type == type && !connection.ConnectedTo.Any());
EventEditorNodeConnection? found = otherNode.Connections.Find(connection => connection.Type == NodeConnectionType.Activate);
if (found != null)
{
conn?.ConnectedTo.Add(found);
}
}
public void Connect(NodeConnection connection, NodeConnection ownConnection)
public static void Connect(EventEditorNodeConnection connection, EventEditorNodeConnection ownConnection)
{
connection.ConnectedTo.Add(ownConnection);
}
public void Disconnect(NodeConnection conn)
public static void Disconnect(EventEditorNodeConnection conn)
{
foreach (var connection in EventEditorScreen.nodeList.SelectMany(editorNode => editorNode.Connections.Where(connection => connection.ConnectedTo.Contains(conn))))
{
@@ -207,7 +207,7 @@ namespace Barotrauma
public void ClearConnections()
{
foreach (NodeConnection conn in Connections)
foreach (EventEditorNodeConnection conn in Connections)
{
conn.ClearConnections();
}
@@ -218,7 +218,7 @@ namespace Barotrauma
return Rectangle;
}
public NodeConnection? GetConnectionOnMouse(Vector2 mousePos)
public EventEditorNodeConnection? GetConnectionOnMouse(Vector2 mousePos)
{
return Connections.FirstOrDefault(eventNodeConnection => eventNodeConnection.DrawRectangle.Contains(mousePos));
}
@@ -254,7 +254,7 @@ namespace Barotrauma
GUI.DrawRectangle(spriteBatch, bodyRect, outlineColor, isFilled: false, depth: 1.0f, thickness: (int) Math.Max(1, 1.25f / camZoom));
int x = 0, y = 0;
foreach (NodeConnection connection in Connections)
foreach (EventEditorNodeConnection connection in Connections)
{
switch (connection.Type.NodeSide)
{
@@ -275,10 +275,10 @@ namespace Barotrauma
public virtual void AddOption()
{
Connections.Add(new NodeConnection(this, NodeConnectionType.Option));
Connections.Add(new EventEditorNodeConnection(this, NodeConnectionType.Option));
}
public void RemoveOption(NodeConnection connection)
public void RemoveOption(EventEditorNodeConnection connection)
{
int index = Connections.IndexOf(connection);
foreach (var nodeConnection in Connections.Skip(index))
@@ -313,7 +313,7 @@ namespace Barotrauma
foreach (EditorNode editorNode in EventEditorScreen.nodeList)
{
List<NodeConnection> childConnection = editorNode.Connections.Where(connection => connection.Type == NodeConnectionType.Next ||
List<EventEditorNodeConnection> childConnection = editorNode.Connections.Where(connection => connection.Type == NodeConnectionType.Next ||
connection.Type == NodeConnectionType.Option ||
connection.Type == NodeConnectionType.Failure ||
connection.Type == NodeConnectionType.Success ||
@@ -338,18 +338,18 @@ namespace Barotrauma
Size = new Vector2(256, 256);
PropertyInfo[] properties = type.GetProperties().Where(info => info.CustomAttributes.Any(data => data.AttributeType == typeof(Serialize))).ToArray();
Connections.Add(new NodeConnection(this, NodeConnectionType.Activate));
Connections.Add(new NodeConnection(this, NodeConnectionType.Next));
Connections.Add(new EventEditorNodeConnection(this, NodeConnectionType.Activate));
Connections.Add(new EventEditorNodeConnection(this, NodeConnectionType.Next));
foreach (PropertyInfo property in properties)
{
Connections.Add(new NodeConnection(this, NodeConnectionType.Value, property.Name, property.PropertyType, property));
Connections.Add(new EventEditorNodeConnection(this, NodeConnectionType.Value, property.Name, property.PropertyType, property));
}
if (IsInstanceOf(type, typeof(BinaryOptionAction)))
{
Connections.Add(new NodeConnection(this, NodeConnectionType.Success));
Connections.Add(new NodeConnection(this, NodeConnectionType.Failure));
Connections.Add(new EventEditorNodeConnection(this, NodeConnectionType.Success));
Connections.Add(new EventEditorNodeConnection(this, NodeConnectionType.Failure));
}
if (IsInstanceOf(type, typeof(ConversationAction)))
@@ -360,7 +360,7 @@ namespace Barotrauma
if (IsInstanceOf(type, typeof(StatusEffectAction)) || IsInstanceOf(type, typeof(MissionAction)))
{
Connections.Add(new NodeConnection(this, NodeConnectionType.Add));
Connections.Add(new EventEditorNodeConnection(this, NodeConnectionType.Add));
}
}
@@ -395,7 +395,7 @@ namespace Barotrauma
return ScaleRectFromConnections(Connections, Rectangle);
}
public static Rectangle ScaleRectFromConnections(List<NodeConnection> connections, Rectangle baseRect)
public static Rectangle ScaleRectFromConnections(List<EventEditorNodeConnection> connections, Rectangle baseRect)
{
// determine how big this box should get based on how many input/output nodes the sides have
int y = connections.Count(connection => connection.Type.NodeSide == NodeConnectionType.Side.Left),
@@ -409,15 +409,15 @@ namespace Barotrauma
public Tuple<EditorNode?, string?, bool>[] GetOptions()
{
IEnumerable<NodeConnection> myNode = Connections.Where(connection => connection.Type == NodeConnectionType.Option).ToArray();
IEnumerable<EventEditorNodeConnection> myNode = Connections.Where(connection => connection.Type == NodeConnectionType.Option).ToArray();
List<Tuple<EditorNode?, string?, bool>> list = new List<Tuple<EditorNode?, string?, bool>>();
if (myNode != null)
{
foreach (NodeConnection connection in myNode)
foreach (EventEditorNodeConnection connection in myNode)
{
if (connection.ConnectedTo.Any())
{
foreach (NodeConnection nodeConnection in connection.ConnectedTo)
foreach (EventEditorNodeConnection nodeConnection in connection.ConnectedTo)
{
list.Add(Tuple.Create((EditorNode?) nodeConnection.Parent, connection.OptionText, connection.EndConversation));
}
@@ -464,7 +464,7 @@ namespace Barotrauma
Type = type;
Value = type.IsValueType ? Activator.CreateInstance(type) : null;
Size = new Vector2(256, 32);
Connections.Add(new NodeConnection(this, NodeConnectionType.Out, "Output", Type));
Connections.Add(new EventEditorNodeConnection(this, NodeConnectionType.Out, "Output", Type));
}
public override XElement Save()
@@ -564,7 +564,7 @@ namespace Barotrauma
Vector2 pos = GetDrawRectangle().Location.ToVector2() + (GetDrawRectangle().Size.ToVector2() / 2) - (valueTextSize / 2);
Rectangle drawRect = Rectangle;
drawRect.Inflate(-1, -1);
GUI.DrawString(spriteBatch, pos, WrappedText, NodeConnection.GetPropertyColor(Type), font: GUIStyle.SubHeadingFont);
GUI.DrawString(spriteBatch, pos, WrappedText, EventEditorNodeConnection.GetPropertyColor(Type), font: GUIStyle.SubHeadingFont);
}
}
@@ -587,9 +587,9 @@ namespace Barotrauma
{
CanAddConnections = true;
RemovableTypes.Add(NodeConnectionType.Value);
Connections.Add(new NodeConnection(this, NodeConnectionType.Activate));
Connections.Add(new NodeConnection(this, NodeConnectionType.Next));
Connections.Add(new NodeConnection(this, NodeConnectionType.Add));
Connections.Add(new EventEditorNodeConnection(this, NodeConnectionType.Activate));
Connections.Add(new EventEditorNodeConnection(this, NodeConnectionType.Next));
Connections.Add(new EventEditorNodeConnection(this, NodeConnectionType.Add));
}
public CustomNode() : this("Custom")
@@ -605,7 +605,7 @@ namespace Barotrauma
{
Prompt(s =>
{
Connections.Add(new NodeConnection(this, NodeConnectionType.Value, s, typeof(string)));
Connections.Add(new EventEditorNodeConnection(this, NodeConnectionType.Value, s, typeof(string)));
return true;
});
}
@@ -617,7 +617,7 @@ namespace Barotrauma
newElement.Add(new XAttribute("name", Name));
newElement.Add(new XAttribute("xpos", Position.X));
newElement.Add(new XAttribute("ypos", Position.Y));
foreach (NodeConnection connection in Connections.FindAll(connection => connection.Type == NodeConnectionType.Value))
foreach (EventEditorNodeConnection connection in Connections.FindAll(connection => connection.Type == NodeConnectionType.Value))
{
newElement.Add(new XElement("Value", new XAttribute("name", connection.Attribute)));
}
@@ -634,7 +634,7 @@ namespace Barotrauma
newNode.Position = new Vector2(posX, posY);
foreach (XElement valueElement in element.Elements())
{
newNode.Connections.Add(new NodeConnection(newNode, NodeConnectionType.Value, valueElement.GetAttributeString("name", string.Empty), typeof(string)));
newNode.Connections.Add(new EventEditorNodeConnection(newNode, NodeConnectionType.Value, valueElement.GetAttributeString("name", string.Empty), typeof(string)));
}
return newNode;
}
@@ -39,7 +39,7 @@ namespace Barotrauma
}
}
internal class NodeConnection
internal class EventEditorNodeConnection
{
public string Attribute { get; }
@@ -128,7 +128,7 @@ namespace Barotrauma
public readonly EditorNode Parent;
public readonly List<NodeConnection> ConnectedTo = new List<NodeConnection>();
public readonly List<EventEditorNodeConnection> ConnectedTo = new List<EventEditorNodeConnection>();
private readonly Color bgColor = Color.DarkGray * 0.8f;
@@ -163,7 +163,7 @@ namespace Barotrauma
ConnectedTo.Clear();
}
public NodeConnection(EditorNode parent, NodeConnectionType type, string attribute = "", Type? valueType = null, PropertyInfo? propertyInfo = null)
public EventEditorNodeConnection(EditorNode parent, NodeConnectionType type, string attribute = "", Type? valueType = null, PropertyInfo? propertyInfo = null)
{
Type = type;
ValueType = valueType;
@@ -244,7 +244,7 @@ namespace Barotrauma
private void DrawConnections(SpriteBatch spriteBatch, int yOffset, float width = 2, Color? overrideColor = null)
{
foreach (NodeConnection? eventNodeConnection in ConnectedTo)
foreach (EventEditorNodeConnection? eventNodeConnection in ConnectedTo)
{
if (eventNodeConnection != null)
{
@@ -279,37 +279,9 @@ namespace Barotrauma
private void DrawSquareLine(SpriteBatch spriteBatch, Vector2 position, int yOffset, float width = 2, Color? overrideColor = null)
{
// draw a line between 2 nodes using points
// the order of this array is messed up, I know
// order of points is from start node to end node: 0, 4, 1, 2, 5, 3
Vector2[] points = new Vector2[6];
int xOffset = 24 * (yOffset + 1);
points[0] = new Vector2(DrawRectangle.Right, DrawRectangle.Center.Y);
points[3] = position;
points[1] = points[0];
points[2] = points[3];
points[4] = points[1];
points[5] = points[2];
points[1].X += (points[2].X - points[1].X) / 2;
points[1].X = Math.Max(points[1].X, points[0].X + xOffset);
points[2].X = points[1].X;
// if the node is "behind" us do some magic to make the line curve to prevent overlapping
if (points[1].X <= points[0].X + xOffset)
{
points[4].X += xOffset;
points[1].X = points[4].X;
points[1].Y += (points[2].Y - points[1].Y) / 2;
}
if (points[2].X >= points[3].X - xOffset)
{
points[5].X -= xOffset;
points[2].X = points[5].X;
points[2].Y -= points[2].Y - points[1].Y;
}
float knobLength = 24 * (yOffset + 1);
Vector2 start = new Vector2(DrawRectangle.Right, DrawRectangle.Center.Y);
var (points, _) = ToolBox.GetSquareLineBetweenPoints(start, position, knobLength);
Color drawColor = Parent is ValueNode ? GetPropertyColor(ValueType) : GUIStyle.Red;
@@ -318,11 +290,11 @@ namespace Barotrauma
drawColor = overrideColor.Value;
}
GUI.DrawLine(spriteBatch, points[0], points[4], drawColor, width: (int)width);
GUI.DrawLine(spriteBatch, points[4], points[1], drawColor, width: (int)width);
GUI.DrawLine(spriteBatch, points[0], points[1], drawColor, width: (int)width);
GUI.DrawLine(spriteBatch, points[1], points[2], drawColor, width: (int)width);
GUI.DrawLine(spriteBatch, points[2], points[5], drawColor, width: (int)width);
GUI.DrawLine(spriteBatch, points[5], points[3], drawColor, width: (int)width);
GUI.DrawLine(spriteBatch, points[2], points[3], drawColor, width: (int)width);
GUI.DrawLine(spriteBatch, points[3], points[4], drawColor, width: (int)width);
GUI.DrawLine(spriteBatch, points[4], points[5], drawColor, width: (int)width);
}
private static readonly Color defaultColor = new Color(139, 233, 253);
@@ -345,7 +317,7 @@ namespace Barotrauma
return color;
}
public bool CanConnect(NodeConnection otherNode)
public bool CanConnect(EventEditorNodeConnection otherNode)
{
if (otherNode.OverrideValue != null)
{
@@ -25,7 +25,7 @@ namespace Barotrauma
private readonly List<EditorNode> selectedNodes = new List<EditorNode>();
public static Vector2 DraggingPosition = Vector2.Zero;
public static NodeConnection? DraggedConnection;
public static EventEditorNodeConnection? DraggedConnection;
private EditorNode? draggedNode;
private Vector2 dragOffset;
@@ -394,7 +394,7 @@ namespace Barotrauma
newNode = new CustomNode(subElement.Name.ToString()) { Position = new Vector2(ident, 0), ID = CreateID() };
foreach (XAttribute attribute in subElement.Attributes().Where(attribute => !attribute.ToString().StartsWith("_")))
{
newNode.Connections.Add(new NodeConnection(newNode, NodeConnectionType.Value, attribute.Name.ToString(), typeof(string)));
newNode.Connections.Add(new EventEditorNodeConnection(newNode, NodeConnectionType.Value, attribute.Name.ToString(), typeof(string)));
}
}
@@ -414,7 +414,7 @@ namespace Barotrauma
{
if (xElement.Name.ToString().ToLowerInvariant() == "option")
{
NodeConnection optionConnection = new NodeConnection(newNode, NodeConnectionType.Option)
EventEditorNodeConnection optionConnection = new EventEditorNodeConnection(newNode, NodeConnectionType.Option)
{
OptionText = xElement.GetAttributeString("text", string.Empty),
EndConversation = xElement.GetAttributeBool("endconversation", false)
@@ -423,7 +423,7 @@ namespace Barotrauma
}
}
foreach (NodeConnection connection in newNode.Connections)
foreach (EventEditorNodeConnection connection in newNode.Connections)
{
if (connection.Type == NodeConnectionType.Value)
{
@@ -479,8 +479,8 @@ namespace Barotrauma
case "option":
if (parent != null)
{
NodeConnection? activateConnection = newNode.Connections.Find(connection => connection.Type == NodeConnectionType.Activate);
NodeConnection? optionConnection = parent.Connections.FirstOrDefault(connection =>
EventEditorNodeConnection? activateConnection = newNode.Connections.Find(connection => connection.Type == NodeConnectionType.Activate);
EventEditorNodeConnection? optionConnection = parent.Connections.FirstOrDefault(connection =>
connection.Type == NodeConnectionType.Option && string.Equals(connection.OptionText, parentElement.GetAttributeString("text", string.Empty), StringComparison.Ordinal));
if (activateConnection != null)
@@ -671,7 +671,7 @@ namespace Barotrauma
}
}
private void CreateContextMenu(EditorNode node, NodeConnection? connection = null)
private void CreateContextMenu(EditorNode node, EventEditorNodeConnection? connection = null)
{
if (GUIContextMenu.CurrentContextMenu != null) { return; }
@@ -757,7 +757,7 @@ namespace Barotrauma
return true;
}
private static void CreateEditMenu(ValueNode? node, NodeConnection? connection = null)
private static void CreateEditMenu(ValueNode? node, EventEditorNodeConnection? connection = null)
{
object? newValue;
Type? type;
@@ -972,7 +972,7 @@ namespace Barotrauma
{
if (PlayerInput.PrimaryMouseButtonDown())
{
NodeConnection? connection = node.GetConnectionOnMouse(mousePos);
EventEditorNodeConnection? connection = node.GetConnectionOnMouse(mousePos);
if (connection != null && connection.Type.NodeSide == NodeConnectionType.Side.Right)
{
if (connection.Type != NodeConnectionType.Out)
@@ -1019,7 +1019,7 @@ namespace Barotrauma
if (PlayerInput.SecondaryMouseButtonClicked())
{
NodeConnection? connection = node.GetConnectionOnMouse(mousePos);
EventEditorNodeConnection? connection = node.GetConnectionOnMouse(mousePos);
if (node.GetDrawRectangle().Contains(mousePos) || connection != null)
{
CreateContextMenu(node, node.GetConnectionOnMouse(mousePos));
@@ -1088,7 +1088,7 @@ namespace Barotrauma
if (!DraggedConnection.CanConnect(nodeOnMouse)) { continue; }
nodeOnMouse.ClearConnections();
DraggedConnection.Parent.Connect(DraggedConnection, nodeOnMouse);
EditorNode.Connect(DraggedConnection, nodeOnMouse);
break;
}
}