v1.5.7.0 (Summer Update)

This commit is contained in:
Regalis11
2024-06-18 16:49:51 +03:00
parent 4a63dacbce
commit 230d1b6e78
263 changed files with 7792 additions and 2845 deletions
@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System;
using System.Linq;
@@ -75,7 +75,7 @@ namespace Barotrauma
foreach (ItemComponent ic in Item.Components)
{
if (ic is Holdable) { continue; }
if (!ic.AllowInGameEditing) { continue; }
if (!ic.AllowInGameEditing && Screen.Selected is not { IsEditor: true }) { continue; }
if (SerializableProperty.GetProperties<InGameEditable>(ic).Count == 0 &&
!SerializableProperty.GetProperties<ConditionallyEditable>(ic).Any(p => p.GetAttribute<ConditionallyEditable>().IsEditable(ic)))
{
@@ -29,6 +29,12 @@ namespace Barotrauma
Length = Rect.Width + Padding + Label.Size.X;
}
public void SetLabel(LocalizedString label, CircuitBoxNode node)
{
Label = new CircuitBoxLabel(label, GUIStyle.SubHeadingFont);
Length = Rect.Width + Padding + Label.Size.X;
}
public void Draw(SpriteBatch spriteBatch, Vector2 drawPos, Vector2 parentPos, Color color)
{
if (CircuitBox.UI is not { } circuitBoxUi) { return; }
@@ -0,0 +1,84 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.Xna.Framework;
namespace Barotrauma
{
internal sealed partial class CircuitBoxInputOutputNode
{
private const string PromptUserData = "InputOutputEditPrompt";
public void PromptEdit(GUIComponent parent)
{
CircuitBox.UI?.SetMenuVisibility(false);
GUIFrame backgroundBlocker = new(new RectTransform(Vector2.One, parent.RectTransform), style: "GUIBackgroundBlocker")
{
UserData = PromptUserData
};
GUILayoutGroup mainLayout = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 0.8f), backgroundBlocker.RectTransform, Anchor.Center), isHorizontal: false, childAnchor: Anchor.TopCenter);
GUIFrame labelArea = new(new RectTransform(new Vector2(1f, 0.8f), mainLayout.RectTransform, Anchor.Center));
GUILayoutGroup labelLayout = new GUILayoutGroup(new RectTransform(Vector2.One, labelArea.RectTransform), childAnchor: Anchor.Center);
GUIListBox labelList = new GUIListBox(new RectTransform(ToolBox.PaddingSizeParentRelative(labelLayout.RectTransform, 0.9f), labelLayout.RectTransform));
Dictionary<string, GUITextBox> textBoxes = new();
foreach (var conn in Connectors)
{
bool found = ConnectionLabelOverrides.TryGetValue(conn.Name, out string labelOverride);
GUILayoutGroup connLayout = new GUILayoutGroup(new RectTransform(new Vector2(1f, 0.12f), labelList.Content.RectTransform), isHorizontal: true, childAnchor: Anchor.CenterLeft);
new GUITextBlock(new RectTransform(new Vector2(0.4f, 1f), connLayout.RectTransform), text: conn.Connection.DisplayName, font: GUIStyle.SubHeadingFont);
GUITextBox box = GUI.CreateTextBoxWithPlaceholder(new RectTransform(new Vector2(0.6f, 1f), connLayout.RectTransform), text: found ? labelOverride : string.Empty, conn.Connection.DisplayName.Value);
box.MaxTextLength = MaxConnectionLabelLength;
textBoxes.Add(conn.Name, box);
}
new GUIButton(new RectTransform(new Vector2(0.5f, 0.1f), mainLayout.RectTransform), text: TextManager.Get("confirm"))
{
OnClicked = (_, _) =>
{
var newOverrides = textBoxes.ToDictionary(
static pair => pair.Key,
static pair => pair.Value.Text);
foreach (var (key, value) in newOverrides.ToImmutableDictionary())
{
if (ConnectionLabelOverrides.TryGetValue(key, out string newValue))
{
if (newValue == value)
{
newOverrides.Remove(key);
}
}
else if (string.IsNullOrWhiteSpace(value))
{
newOverrides.Remove(key);
}
}
CircuitBox.SetConnectionLabelOverrides(this, newOverrides);
RemoveEditPrompt(parent);
return true;
}
};
new GUIButton(new RectTransform(new Vector2(0.5f, 0.1f), mainLayout.RectTransform), text: TextManager.Get("cancel"))
{
OnClicked = (_, _) =>
{
RemoveEditPrompt(parent);
return true;
}
};
}
public void RemoveEditPrompt(GUIComponent parent)
{
if (parent.FindChild(PromptUserData) is not { } promptParent) { return; }
parent.RemoveChild(promptParent);
}
}
}
@@ -1,5 +1,6 @@
#nullable enable
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
@@ -80,6 +81,18 @@ namespace Barotrauma
return true;
};
var characterLimit = new GUITextBlock(new RectTransform(new Vector2(1f, 0.1f), frame.RectTransform, Anchor.BottomRight) { RelativeOffset = new Vector2(0.03f, 0.02f) }, text: $"{bodyTextBox.Text.Length}/{NetLimitedString.MaxLength}", font: GUIStyle.SmallFont, textAlignment: Alignment.Right);
bodyTextBox.OnTextChanged += (textBox, _) =>
{
textBox.TextColor = textBox.TextBlock.SelectedTextColor = textBox.Text.Length > NetLimitedString.MaxLength
? GUIStyle.Red
: GUIStyle.TextColorNormal;
characterLimit.Text = $"{textBox.Text.Length}/{NetLimitedString.MaxLength}";
return true;
};
static void UpdateLabelColor(GUITextBox box)
{
bool found = TextManager.ContainsTag(box.Text);
@@ -97,8 +110,8 @@ namespace Barotrauma
}
}
bodyTextBox.OnDeselected += (textBox, _) => UpdateLabelColor(textBox);
headerTextBox.OnDeselected += (textBox, _) => UpdateLabelColor(textBox);
bodyTextBox.OnDeselected += static (textBox, _) => UpdateLabelColor(textBox);
headerTextBox.OnDeselected += static (textBox, _) => UpdateLabelColor(textBox);
UpdateLabelColor(bodyTextBox);
UpdateLabelColor(headerTextBox);
@@ -87,6 +87,16 @@ namespace Barotrauma
SnapshotMoveAffectedNodes();
startClick = cursorPos;
}
public void ClearSnapshot()
{
lastNodesUnderCursor = ImmutableHashSet<CircuitBoxNode>.Empty;
lastSelectedComponents = ImmutableHashSet<CircuitBoxNode>.Empty;
moveAffectedComponents = ImmutableHashSet<CircuitBoxNode>.Empty;
LastConnectorUnderCursor = Option.None;
LastWireUnderCursor = Option.None;
LastResizeAffectedNode = Option.None;
}
/// <summary>
/// Finds all connections and gathers them into a single list for easier iteration.
@@ -168,38 +178,36 @@ namespace Barotrauma
LastResizeAffectedNode = FindResizeBorderUnderCursor(lastNodesUnderCursor, cursorPos);
}
private static Option<(CircuitBoxResizeDirection, CircuitBoxNode)> FindResizeBorderUnderCursor(ImmutableHashSet<CircuitBoxNode> nodes, Vector2 cursorPos)
private Option<(CircuitBoxResizeDirection, CircuitBoxNode)> FindResizeBorderUnderCursor(ImmutableHashSet<CircuitBoxNode> nodes, Vector2 cursorPos)
{
foreach (var node in nodes)
if (!nodes.Any()) { return Option.None; }
var node = circuitBoxUi.GetTopmostNode(nodes);
if (node is null || !node.IsResizable) { return Option.None; }
const float borderSize = 32f;
var rect = node.Rect;
RectangleF bottomBorder = new(rect.X, rect.Top, rect.Width, borderSize);
RectangleF rightBorder = new(rect.Right - borderSize, rect.Y, borderSize, rect.Height);
RectangleF leftBorder = new(rect.X, rect.Y, borderSize, rect.Height);
bool hoverBottom = bottomBorder.Contains(cursorPos),
hoverRight = rightBorder.Contains(cursorPos),
hoverLeft = leftBorder.Contains(cursorPos);
var dir = CircuitBoxResizeDirection.None;
if (hoverBottom) { dir |= CircuitBoxResizeDirection.Down; }
if (hoverRight) { dir |= CircuitBoxResizeDirection.Right; }
if (hoverLeft) { dir |= CircuitBoxResizeDirection.Left; }
if (dir is CircuitBoxResizeDirection.None)
{
if (!node.IsResizable) { continue; }
const float borderSize = 32f;
var rect = node.Rect;
RectangleF bottomBorder = new(rect.X, rect.Top, rect.Width, borderSize);
RectangleF rightBorder = new(rect.Right - borderSize, rect.Y, borderSize, rect.Height);
RectangleF leftBorder = new(rect.X, rect.Y, borderSize, rect.Height);
bool hoverBottom = bottomBorder.Contains(cursorPos),
hoverRight = rightBorder.Contains(cursorPos),
hoverLeft = leftBorder.Contains(cursorPos);
var dir = CircuitBoxResizeDirection.None;
if (hoverBottom) { dir |= CircuitBoxResizeDirection.Down; }
if (hoverRight) { dir |= CircuitBoxResizeDirection.Right; }
if (hoverLeft) { dir |= CircuitBoxResizeDirection.Left; }
if (dir is CircuitBoxResizeDirection.None)
{
continue;
}
return Option.Some((dir, node));
return Option.None;
}
return Option.None;
return Option.Some((dir, node));
}
/// <summary>
@@ -281,14 +289,14 @@ namespace Barotrauma
if (circuitBoxUi.Locked) { return; }
bool isDragThresholdExceeded = Vector2.DistanceSquared(startClick, cursorPos) > dragTreshold * dragTreshold;
if (LastResizeAffectedNode.IsSome())
{
IsResizing |= isDragThresholdExceeded;
}
else if (LastConnectorUnderCursor.IsSome())
if (LastConnectorUnderCursor.IsSome())
{
IsWiring |= isDragThresholdExceeded;
}
else if (LastResizeAffectedNode.IsSome())
{
IsResizing |= isDragThresholdExceeded;
}
else
{
IsDragging |= isDragThresholdExceeded;
@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
@@ -350,6 +350,10 @@ namespace Barotrauma
{
component.Sprite.Draw(spriteBatch, PlayerInput.MousePosition);
}
if (PlayerInput.PrimaryMouseButtonHeld() && MouseSnapshotHandler.LastConnectorUnderCursor.IsSome())
{
CircuitBoxWire.SelectedWirePrefab.Sprite.Draw(spriteBatch, PlayerInput.MousePosition, CircuitBoxWire.SelectedWirePrefab.SpriteColor, scale: camera.Zoom);
}
foreach (var c in CircuitBox.Components)
{
@@ -360,11 +364,11 @@ namespace Barotrauma
{
n.DrawHUD(spriteBatch, camera);
}
if (Locked)
{
LocalizedString lockedText = TextManager.Get("CircuitBoxLocked")
.Fallback(TextManager.Get("ConnectionLocked"));
.Fallback(TextManager.Get("ConnectionLocked"), useDefaultLanguageIfFound: false);
Vector2 size = GUIStyle.LargeFont.MeasureString(lockedText);
Vector2 pos = new Vector2(screenRect.Center.X - size.X / 2, screenRect.Top + screenRect.Height * 0.05f);
@@ -579,9 +583,25 @@ namespace Barotrauma
if (isMouseOn)
{
if (CircuitBox.HeldComponent.IsNone() && PlayerInput.PrimaryMouseButtonDown())
if (PlayerInput.PrimaryMouseButtonDown())
{
MouseSnapshotHandler.StartDragging();
if (CircuitBox.HeldComponent.IsNone())
{
MouseSnapshotHandler.StartDragging();
}
else
{
MouseSnapshotHandler.ClearSnapshot();
}
}
if (PlayerInput.DoubleClicked() && MouseSnapshotHandler.FindWireUnderCursor(cursorPos).IsNone())
{
var topmostNode = GetTopmostNode(MouseSnapshotHandler.FindNodesUnderCursor(cursorPos));
if (topmostNode is CircuitBoxLabelNode label && circuitComponent is not null)
{
label.PromptEditText(circuitComponent);
}
}
if (PlayerInput.MidButtonHeld() || (PlayerInput.IsAltDown() && PlayerInput.PrimaryMouseButtonHeld()))
@@ -629,6 +649,7 @@ namespace Barotrauma
if (PlayerInput.PrimaryMouseButtonClicked())
{
bool selectedNode = false;
if (MouseSnapshotHandler.IsResizing && MouseSnapshotHandler.LastResizeAffectedNode.TryUnwrap(out var r))
{
var (dir, node) = r;
@@ -647,7 +668,7 @@ namespace Barotrauma
}
else if (!MouseSnapshotHandler.IsWiring)
{
TrySelectComponentsUnderCursor();
selectedNode = TrySelectComponentsUnderCursor();
}
}
@@ -658,8 +679,15 @@ namespace Barotrauma
CircuitBox.AddWire(one, two);
}
}
CircuitBox.SelectWires(MouseSnapshotHandler.LastWireUnderCursor.TryUnwrap(out var wire) ? ImmutableArray.Create(wire) : ImmutableArray<CircuitBoxWire>.Empty, !PlayerInput.IsShiftDown());
if (MouseSnapshotHandler.LastWireUnderCursor.TryUnwrap(out var wire) && !MouseSnapshotHandler.IsDragging && !selectedNode)
{
CircuitBox.SelectWires(ImmutableArray.Create(wire), !PlayerInput.IsShiftDown());
}
else if (CircuitBox.Wires.Any(static wire => wire.IsSelectedByMe))
{
CircuitBox.SelectWires(ImmutableArray<CircuitBoxWire>.Empty, !PlayerInput.IsShiftDown());
}
CircuitBox.HeldComponent = Option.None;
MouseSnapshotHandler.EndDragging();
@@ -732,11 +760,17 @@ namespace Barotrauma
}
}
private void TrySelectComponentsUnderCursor()
private bool TrySelectComponentsUnderCursor()
{
CircuitBoxNode? foundNode = GetTopmostNode(MouseSnapshotHandler.GetLastComponentsUnderCursor());
if (foundNode is CircuitBoxLabelNode && MouseSnapshotHandler.LastWireUnderCursor.IsSome())
{
foundNode = null;
}
CircuitBox.SelectComponents(foundNode is null ? ImmutableArray<CircuitBoxNode>.Empty : ImmutableArray.Create(foundNode), !PlayerInput.IsShiftDown());
return foundNode is not null;
}
private void OpenContextMenu()
@@ -767,17 +801,26 @@ namespace Barotrauma
var editLabel = new ContextMenuOption(TextManager.Get("circuitboxeditlabel"), isEnabled: nodeOption is CircuitBoxLabelNode && !Locked, () =>
{
if (nodeOption is not CircuitBoxLabelNode label || circuitComponent is null) { return; }
if (circuitComponent is null) { return; }
if (nodeOption is not CircuitBoxLabelNode label) { return; }
label.PromptEditText(circuitComponent);
});
var editConnections = new ContextMenuOption(TextManager.Get("circuitboxrenameconnections"), isEnabled: nodeOption is CircuitBoxInputOutputNode && !Locked, () =>
{
if (circuitComponent is null) { return; }
if (nodeOption is not CircuitBoxInputOutputNode io) { return; }
io.PromptEdit(circuitComponent);
});
var addLabelOption = new ContextMenuOption(TextManager.Get("circuitboxaddlabel"), isEnabled: !Locked, () =>
{
CircuitBox.AddLabel(cursorPos);
});
ContextMenuOption[] allOptions = { addLabelOption, editLabel, option };
ContextMenuOption[] allOptions = { addLabelOption, editLabel, editConnections, option };
// show component name in the header to better indicate what is about to be deleted
if (nodeOption is CircuitBoxComponent comp)