v1.0.20.1 (summer patch)
This commit is contained in:
@@ -21,7 +21,8 @@ namespace Barotrauma.Items.Components
|
||||
public float FlashTimer { get; private set; }
|
||||
public static Wire DraggingConnected { get; private set; }
|
||||
|
||||
public static void DrawConnections(SpriteBatch spriteBatch, ConnectionPanel panel, Rectangle dragArea, Character character)
|
||||
public static void DrawConnections(SpriteBatch spriteBatch, ConnectionPanel panel, Rectangle dragArea, Character character,
|
||||
out (Vector2 tooltipPos, LocalizedString text) tooltip)
|
||||
{
|
||||
if (DraggingConnected?.Item?.Removed ?? true)
|
||||
{
|
||||
@@ -64,6 +65,8 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
tooltip = (Vector2.Zero, string.Empty);
|
||||
|
||||
//two passes: first the connector, then the wires to get the wires to render in front
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
@@ -97,6 +100,42 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 position = c.IsOutput ? rightPos : leftPos;
|
||||
Color highlightColor = Color.Transparent;
|
||||
if (ConnectionPanel.ShouldDebugDrawWiring)
|
||||
{
|
||||
if (c.IsPower)
|
||||
{
|
||||
highlightColor = VisualizeSignal(0.0f, highlightColor, Color.Red);
|
||||
}
|
||||
else
|
||||
{
|
||||
highlightColor = VisualizeSignal(c.LastReceivedSignal.TimeSinceCreated, highlightColor, Color.LightGreen);
|
||||
highlightColor = VisualizeSignal(c.LastSentSignal.TimeSinceCreated, highlightColor, Color.Orange);
|
||||
}
|
||||
bool mouseOn = Vector2.DistanceSquared(position, PlayerInput.MousePosition) < MathUtils.Pow2(35 * GUI.Scale);
|
||||
|
||||
LocalizedString toolTipText = c.GetToolTip();
|
||||
if (mouseOn) { tooltip = (position, toolTipText); }
|
||||
if (!toolTipText.IsNullOrEmpty())
|
||||
{
|
||||
var glowSprite = GUIStyle.UIGlowCircular.Value.Sprite;
|
||||
glowSprite.Draw(spriteBatch, position, highlightColor, glowSprite.size / 2,
|
||||
scale: 45.0f / glowSprite.size.X * panel.Scale);
|
||||
}
|
||||
}
|
||||
|
||||
static Color VisualizeSignal(double timeSinceCreated, Color defaultColor, Color color)
|
||||
{
|
||||
if (timeSinceCreated < 1.0f)
|
||||
{
|
||||
float pulseAmount = (MathF.Sin((float)Timing.TotalTimeUnpaused * 10.0f) + 3.0f) / 4.0f;
|
||||
Color targetColor = Color.Lerp(defaultColor, color, pulseAmount);
|
||||
return Color.Lerp(targetColor, defaultColor, (float)timeSinceCreated);
|
||||
}
|
||||
return defaultColor;
|
||||
}
|
||||
|
||||
//outputs are drawn at the right side of the panel, inputs at the left
|
||||
if (c.IsOutput)
|
||||
{
|
||||
@@ -127,7 +166,6 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (DraggingConnected != null)
|
||||
{
|
||||
if (mouseInRect)
|
||||
@@ -225,7 +263,9 @@ namespace Barotrauma.Items.Components
|
||||
GUI.DrawString(spriteBatch, labelPos, text, GUIStyle.TextColorBright, font: GUIStyle.SmallFont);
|
||||
|
||||
float connectorSpriteScale = (35.0f / connectionSprite.SourceRect.Width) * panel.Scale;
|
||||
|
||||
connectionSprite.Draw(spriteBatch, position, scale: connectorSpriteScale);
|
||||
|
||||
}
|
||||
|
||||
private void DrawWires(SpriteBatch spriteBatch, ConnectionPanel panel, Vector2 position, Vector2 wirePosition, bool mouseIn, Wire equippedWire, float wireInterval)
|
||||
@@ -259,7 +299,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
bool alreadyConnected = DraggingConnected.IsConnectedTo(panel.Item);
|
||||
DraggingConnected.RemoveConnection(panel.Item);
|
||||
if (DraggingConnected.Connect(this, !alreadyConnected, true))
|
||||
if (DraggingConnected.TryConnect(this, !alreadyConnected, true))
|
||||
{
|
||||
var otherConnection = DraggingConnected.OtherConnection(this);
|
||||
ConnectWire(DraggingConnected);
|
||||
@@ -307,6 +347,63 @@ namespace Barotrauma.Items.Components
|
||||
FlashTimer -= deltaTime;
|
||||
}
|
||||
|
||||
private (string signal, LocalizedString tooltip) lastSignalToolTip;
|
||||
private (int powerValue, LocalizedString tooltip) lastPowerToolTip;
|
||||
|
||||
private LocalizedString GetToolTip()
|
||||
{
|
||||
if (LastReceivedSignal.TimeSinceCreated < 1.0f)
|
||||
{
|
||||
return getSignalTooltip(LastReceivedSignal, "receivedsignal");
|
||||
}
|
||||
else if (LastSentSignal.TimeSinceCreated < 1.0f)
|
||||
{
|
||||
return getSignalTooltip(LastSentSignal, "sentsignal");
|
||||
}
|
||||
|
||||
LocalizedString getSignalTooltip(Signal signal, string textTag)
|
||||
{
|
||||
if (lastSignalToolTip.signal == signal.value && !lastSignalToolTip.tooltip.IsNullOrEmpty()) { return lastSignalToolTip.tooltip; }
|
||||
lastSignalToolTip = (signal.value, TextManager.GetWithVariable(textTag, "[signal]", signal.value));
|
||||
return lastSignalToolTip.tooltip;
|
||||
}
|
||||
|
||||
if (IsPower)
|
||||
{
|
||||
if (item.GetComponent<Powered>() is Powered powered)
|
||||
{
|
||||
if (IsOutput)
|
||||
{
|
||||
if (powered.CurrPowerConsumption < 0)
|
||||
{
|
||||
return getPowerTooltip(-(int)powered.CurrPowerConsumption, "reactoroutput");
|
||||
}
|
||||
else if (powered is PowerTransfer || powered is PowerContainer)
|
||||
{
|
||||
return getPowerTooltip((int)(Grid?.Power ?? 0), "reactoroutput");
|
||||
}
|
||||
}
|
||||
else if (!IsOutput)
|
||||
{
|
||||
float powerConsumption = powered.GetCurrentPowerConsumption(this);
|
||||
if (!MathUtils.NearlyEqual((int)powerConsumption, 0.0f))
|
||||
{
|
||||
return getPowerTooltip((int)powerConsumption, "reactorload");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LocalizedString getPowerTooltip(int powerValue, string textTag)
|
||||
{
|
||||
if (lastPowerToolTip.powerValue == powerValue && !lastPowerToolTip.tooltip.IsNullOrEmpty()) { return lastPowerToolTip.tooltip; }
|
||||
lastPowerToolTip = (powerValue, TextManager.GetWithVariable(textTag, "[kw]", powerValue.ToString()));
|
||||
return lastPowerToolTip.tooltip;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void DrawWire(SpriteBatch spriteBatch, Wire wire, Vector2 end, Vector2 start, Wire equippedWire, ConnectionPanel panel, LocalizedString label)
|
||||
{
|
||||
int textX = (int)start.X;
|
||||
|
||||
+10
-3
@@ -10,6 +10,10 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class ConnectionPanel : ItemComponent, IServerSerializable, IClientSerializable
|
||||
{
|
||||
public static bool DebugWiringMode;
|
||||
public static double DebugWiringEnabledUntil;
|
||||
public static bool ShouldDebugDrawWiring => DebugWiringMode || Timing.TotalTimeUnpaused < DebugWiringEnabledUntil;
|
||||
|
||||
//how long the rewiring sound plays after doing changes to the wiring
|
||||
const float RewireSoundDuration = 5.0f;
|
||||
|
||||
@@ -120,12 +124,15 @@ namespace Barotrauma.Items.Components
|
||||
if (user != Character.Controlled || user == null) { return; }
|
||||
|
||||
HighlightedWire = null;
|
||||
Connection.DrawConnections(spriteBatch, this, dragArea.Rect, user);
|
||||
|
||||
Connection.DrawConnections(spriteBatch, this, dragArea.Rect, user, out (Vector2 tooltipPos, LocalizedString text) tooltip);
|
||||
foreach (UISprite sprite in GUIStyle.GetComponentStyle("ConnectionPanelFront").Sprites[GUIComponent.ComponentState.None])
|
||||
{
|
||||
sprite.Draw(spriteBatch, GuiFrame.Rect, Color.White, SpriteEffects.None);
|
||||
}
|
||||
if (!tooltip.text.IsNullOrEmpty())
|
||||
{
|
||||
GUIComponent.DrawToolTip(spriteBatch, tooltip.text, tooltip.tooltipPos);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckForLabelOverlap()
|
||||
@@ -225,7 +232,7 @@ namespace Barotrauma.Items.Components
|
||||
foreach (var wire in newWires.Where(w => !connection.Wires.Contains(w)).ToArray())
|
||||
{
|
||||
connection.ConnectWire(wire);
|
||||
wire.Connect(connection, false);
|
||||
wire.TryConnect(connection, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
@@ -119,6 +118,13 @@ namespace Barotrauma.Items.Components
|
||||
get { return sectionExtents; }
|
||||
}
|
||||
|
||||
public readonly record struct VisualSignal(
|
||||
float TimeSent,
|
||||
Color Color,
|
||||
int Direction);
|
||||
|
||||
private VisualSignal lastReceivedSignal;
|
||||
|
||||
public static Wire DraggingWire
|
||||
{
|
||||
get => draggingWire;
|
||||
@@ -126,13 +132,11 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public static Sprite ExtractWireSprite(ContentXElement element)
|
||||
{
|
||||
if (defaultWireSprite == null)
|
||||
{
|
||||
defaultWireSprite = new Sprite("Content/Items/Electricity/signalcomp.png", new Rectangle(970, 47, 14, 16), new Vector2(0.5f, 0.5f))
|
||||
defaultWireSprite ??=
|
||||
new Sprite("Content/Items/Electricity/signalcomp.png", new Rectangle(970, 47, 14, 16), new Vector2(0.5f, 0.5f))
|
||||
{
|
||||
Depth = 0.855f
|
||||
};
|
||||
}
|
||||
|
||||
Sprite overrideSprite = null;
|
||||
foreach (var subElement in element.Elements())
|
||||
@@ -153,6 +157,35 @@ namespace Barotrauma.Items.Components
|
||||
if (wireSprite != defaultWireSprite) { overrideSprite = wireSprite; }
|
||||
}
|
||||
|
||||
public void RegisterSignal(Signal signal, Connection source)
|
||||
{
|
||||
lastReceivedSignal = new VisualSignal(
|
||||
(float)Timing.TotalTimeUnpaused,
|
||||
GetSignalColor(signal),
|
||||
Direction: source == connections[0] ? 1 : -1);
|
||||
}
|
||||
|
||||
private static readonly Color[] dataSignalColors = new Color[] { Color.White, Color.LightBlue, Color.CornflowerBlue, Color.Blue, Color.BlueViolet, Color.Violet };
|
||||
|
||||
private static Color GetSignalColor(Signal signal)
|
||||
{
|
||||
if (signal.value == "0")
|
||||
{
|
||||
return Color.Red;
|
||||
}
|
||||
else if (signal.value == "1")
|
||||
{
|
||||
return Color.LightGreen;
|
||||
}
|
||||
else if (float.TryParse(signal.value, out float floatValue))
|
||||
{
|
||||
//convert numeric values to a color (guessing the value might be somewhere in the range of 0-200)
|
||||
//so a player with a keen eye can get some info out of the color of the signal
|
||||
return ToolBox.GradientLerp(Math.Abs(floatValue / 200.0f), dataSignalColors);
|
||||
}
|
||||
return Color.LightBlue;
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth = -1)
|
||||
{
|
||||
Draw(spriteBatch, editing, Vector2.Zero, itemDepth);
|
||||
@@ -166,20 +199,7 @@ namespace Barotrauma.Items.Components
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 drawOffset = Vector2.Zero;
|
||||
Submarine sub = item.Submarine;
|
||||
if (IsActive && sub == null) // currently being rewired, we need to get the sub from the connections in case the wire has been taken outside
|
||||
{
|
||||
if (connections[0] != null && connections[0].Item.Submarine != null) { sub = connections[0].Item.Submarine; }
|
||||
if (connections[1] != null && connections[1].Item.Submarine != null) { sub = connections[1].Item.Submarine; }
|
||||
}
|
||||
|
||||
if (sub != null)
|
||||
{
|
||||
drawOffset = sub.DrawPosition + sub.HiddenSubPosition;
|
||||
}
|
||||
|
||||
drawOffset += offset;
|
||||
Vector2 drawOffset = GetDrawOffset() + offset;
|
||||
|
||||
float baseDepth = UseSpriteDepth ? item.SpriteDepth : wireSprite.Depth;
|
||||
float depth = item.IsSelected ? 0.0f : SubEditorScreen.IsWiringMode() ? 0.02f : baseDepth + (item.ID % 100) * 0.000001f;// item.GetDrawDepth(wireSprite.Depth, wireSprite);
|
||||
@@ -188,7 +208,9 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
foreach (WireSection section in sections)
|
||||
{
|
||||
section.Draw(spriteBatch, wireSprite, Screen.Selected == GameMain.GameScreen ? higlightColor : editorHighlightColor, drawOffset, depth + 0.00001f, Width * 2.0f);
|
||||
section.Draw(spriteBatch, wireSprite,
|
||||
Screen.Selected == GameMain.GameScreen ? higlightColor : editorHighlightColor,
|
||||
drawOffset, depth + 0.00001f, Width * 2.0f);
|
||||
}
|
||||
}
|
||||
else if (item.IsSelected)
|
||||
@@ -270,6 +292,12 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ConnectionPanel.ShouldDebugDrawWiring)
|
||||
{
|
||||
DebugDraw(spriteBatch, alpha: 0.2f);
|
||||
}
|
||||
|
||||
if (!editing || !GameMain.SubEditorScreen.WiringMode) { return; }
|
||||
|
||||
for (int i = 0; i < nodes.Count; i++)
|
||||
@@ -295,6 +323,102 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
public void DebugDraw(SpriteBatch spriteBatch, float alpha = 1.0f)
|
||||
{
|
||||
if (sections.Count == 0 || Hidden)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const float PowerPulseSpeedLow = 5.0f;
|
||||
const float PowerPulseSpeedHigh = 10.0f;
|
||||
const float PowerHighlightScaleLow = 1.5f;
|
||||
const float PowerHighlightScaleHigh = 2.5f;
|
||||
|
||||
const float SignalIndicatorInterval = 15.0f;
|
||||
const float SignalIndicatorSpeed = 100.0f;
|
||||
|
||||
Vector2 drawOffset = GetDrawOffset();
|
||||
|
||||
Color currentHighlightColor = Color.Transparent;
|
||||
float highlightScale = 0.0f;
|
||||
if (connections[0] != null && connections[1] != null)
|
||||
{
|
||||
float voltage = Math.Max(GetVoltage(0), GetVoltage(1));
|
||||
float GetVoltage(int connectionIndex)
|
||||
{
|
||||
var connection1 = connections[connectionIndex];
|
||||
var connection2 = connections[1 - connectionIndex];
|
||||
if (connection1.IsOutput && connection1.Grid is { Power: > 0.01f } grid1)
|
||||
{
|
||||
if (connection2.Item.GetComponent<Powered>() is Powered powered &&
|
||||
(powered.GetCurrentPowerConsumption(connection2) > 0 || powered is PowerTransfer))
|
||||
{
|
||||
return grid1.Voltage;
|
||||
}
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
if (voltage > 0.0f)
|
||||
{
|
||||
//pulse faster when there's overvoltage
|
||||
float pulseSpeed = voltage > 1.2f ? PowerPulseSpeedHigh : PowerPulseSpeedLow;
|
||||
float pulseAmount = (MathF.Sin((float)Timing.TotalTimeUnpaused * pulseSpeed) + 1.5f) / 2.5f;
|
||||
voltage = Math.Min(voltage, 1.0f);
|
||||
highlightScale = MathHelper.Lerp(PowerHighlightScaleLow, PowerHighlightScaleHigh, voltage);
|
||||
currentHighlightColor = Color.Red * voltage * pulseAmount;
|
||||
}
|
||||
}
|
||||
if (highlightScale > 0.0f)
|
||||
{
|
||||
foreach (WireSection section in sections)
|
||||
{
|
||||
section.Draw(spriteBatch, wireSprite, currentHighlightColor * alpha, drawOffset, 0.0f, Width * highlightScale);
|
||||
}
|
||||
}
|
||||
|
||||
float signalDuration = (float)Timing.TotalTimeUnpaused - lastReceivedSignal.TimeSent;
|
||||
if (ConnectionPanel.ShouldDebugDrawWiring && signalDuration < 1.0f)
|
||||
{
|
||||
//make some wires "off sync" so it's easier to differentiate signals on overlapping wires
|
||||
float offset = item.ID % 2 == 1 ? SignalIndicatorInterval / 2 : 0.0f;
|
||||
float signalProgress = ((float)(Timing.TotalTimeUnpaused * SignalIndicatorSpeed + offset) % SignalIndicatorInterval) * lastReceivedSignal.Direction;
|
||||
foreach (WireSection section in sections)
|
||||
{
|
||||
for (float x = 0; x < section.Length; x += SignalIndicatorInterval)
|
||||
{
|
||||
Vector2 dir = (section.End - section.Start) / section.Length;
|
||||
float posOnSection = x + signalProgress;
|
||||
if (posOnSection < 0 || posOnSection > section.Length) { continue; }
|
||||
Vector2 signalPos = section.Start + drawOffset + dir * posOnSection;
|
||||
float a = 1.0f - Vector2.Distance(Screen.Selected.Cam.WorldViewCenter, signalPos) / 500.0f;
|
||||
if (a < 0) { continue; }
|
||||
signalPos.Y = -signalPos.Y;
|
||||
GUI.DrawRectangle(spriteBatch, signalPos - Vector2.One * 2.5f, Vector2.One * 5, lastReceivedSignal.Color * a * (1.0f - signalDuration) * alpha, isFilled: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 GetDrawOffset()
|
||||
{
|
||||
Submarine sub = item.Submarine;
|
||||
if (IsActive && sub == null) // currently being rewired, we need to get the sub from the connections in case the wire has been taken outside
|
||||
{
|
||||
if (connections[0] != null && connections[0].Item.Submarine != null) { sub = connections[0].Item.Submarine; }
|
||||
if (connections[1] != null && connections[1].Item.Submarine != null) { sub = connections[1].Item.Submarine; }
|
||||
}
|
||||
|
||||
if (sub == null)
|
||||
{
|
||||
return Vector2.Zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
return sub.DrawPosition + sub.HiddenSubPosition;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawHangingWire(SpriteBatch spriteBatch, Vector2 start, float depth)
|
||||
{
|
||||
float angle = (float)Math.Sin(GameMain.GameScreen.GameTime * 2.0f + item.ID) * 0.2f;
|
||||
|
||||
Reference in New Issue
Block a user