v0.13.0.11
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Barotrauma.Networking;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -28,15 +27,7 @@ namespace Barotrauma.Items.Components
|
||||
int x = panelRect.X, y = panelRect.Y;
|
||||
int width = panelRect.Width, height = panelRect.Height;
|
||||
|
||||
Vector2 scale = new Vector2(GUI.Scale);
|
||||
if (panel.GuiFrame.RectTransform.MaxSize.X < int.MaxValue)
|
||||
{
|
||||
scale.X = panel.GuiFrame.RectTransform.MaxSize.X / panel.GuiFrame.Rect.Width;
|
||||
}
|
||||
if (panel.GuiFrame.RectTransform.MaxSize.Y < int.MaxValue)
|
||||
{
|
||||
scale.Y = panel.GuiFrame.RectTransform.MaxSize.Y / panel.GuiFrame.Rect.Height;
|
||||
}
|
||||
Vector2 scale = GetScale(panel.GuiFrame.RectTransform.MaxSize, panel.GuiFrame.Rect.Size);
|
||||
|
||||
bool mouseInRect = panelRect.Contains(PlayerInput.MousePosition);
|
||||
|
||||
@@ -66,15 +57,15 @@ namespace Barotrauma.Items.Components
|
||||
//two passes: first the connector, then the wires to get the wires to render in front
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Vector2 rightPos = new Vector2(x + width - 80 * scale.X, y + 60 * scale.Y);
|
||||
Vector2 leftPos = new Vector2(x + 80 * scale.X, y + 60 * scale.Y);
|
||||
Vector2 rightPos = GetRightPos(x, y, width, scale);
|
||||
Vector2 leftPos = GetLeftPos(x, y, scale);
|
||||
|
||||
Vector2 rightWirePos = new Vector2(x + width - 5 * scale.X, y + 30 * scale.Y);
|
||||
Vector2 leftWirePos = new Vector2(x + 5 * scale.X, y + 30 * scale.Y);
|
||||
|
||||
int wireInterval = (height - (int)(20 * scale.Y)) / Math.Max(totalWireCount, 1);
|
||||
int connectorIntervalLeft = (height - (int)(100 * scale.Y)) / Math.Max(panel.Connections.Count(c => c.IsOutput), 1);
|
||||
int connectorIntervalRight = (height - (int)(100 * scale.Y)) / Math.Max(panel.Connections.Count(c => !c.IsOutput), 1);
|
||||
int connectorIntervalLeft = GetConnectorIntervalLeft(height, scale, panel);
|
||||
int connectorIntervalRight = GetConnectorIntervalRight(height, scale, panel);
|
||||
|
||||
foreach (Connection c in panel.Connections)
|
||||
{
|
||||
@@ -101,15 +92,12 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
c.DrawConnection(spriteBatch, panel, rightPos,
|
||||
new Vector2(rightPos.X - GUI.SmallFont.MeasureString(c.DisplayName.ToUpper()).X - 25 * panel.Scale, rightPos.Y + 5 * panel.Scale),
|
||||
scale);
|
||||
c.DrawConnection(spriteBatch, panel, rightPos, GetOutputLabelPosition(rightPos, panel, c), scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
c.DrawWires(spriteBatch, panel, rightPos, rightWirePos, mouseInRect, equippedWire, wireInterval);
|
||||
}
|
||||
|
||||
rightPos.Y += connectorIntervalLeft;
|
||||
rightWirePos.Y += c.Wires.Count(w => w != null) * wireInterval;
|
||||
}
|
||||
@@ -117,15 +105,12 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
c.DrawConnection(spriteBatch, panel, leftPos,
|
||||
new Vector2(leftPos.X + 25 * panel.Scale, leftPos.Y - 5 * panel.Scale - GUI.SmallFont.MeasureString(c.DisplayName.ToUpper()).Y),
|
||||
scale);
|
||||
c.DrawConnection(spriteBatch, panel, leftPos, GetInputLabelPosition(leftPos, panel, c), scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
c.DrawWires(spriteBatch, panel, leftPos, leftWirePos, mouseInRect, equippedWire, wireInterval);
|
||||
}
|
||||
|
||||
leftPos.Y += connectorIntervalRight;
|
||||
leftWirePos.Y += c.Wires.Count(w => w != null) * wireInterval;
|
||||
}
|
||||
@@ -215,14 +200,11 @@ namespace Barotrauma.Items.Components
|
||||
private void DrawConnection(SpriteBatch spriteBatch, ConnectionPanel panel, Vector2 position, Vector2 labelPos, Vector2 scale)
|
||||
{
|
||||
string text = DisplayName.ToUpper();
|
||||
Vector2 textSize = GUI.SmallFont.MeasureString(text);
|
||||
|
||||
//nasty
|
||||
var labelSprite = GUI.Style.GetComponentStyle("ConnectionPanelLabel")?.Sprites.Values.First().First();
|
||||
if (labelSprite != null)
|
||||
if (GUI.Style.GetComponentStyle("ConnectionPanelLabel")?.Sprites.Values.First().First() is UISprite labelSprite)
|
||||
{
|
||||
Rectangle labelArea = new Rectangle(labelPos.ToPoint(), textSize.ToPoint());
|
||||
labelArea.Inflate(10 * scale.X, 3 * scale.Y);
|
||||
Rectangle labelArea = GetLabelArea(labelPos, text, scale);
|
||||
labelSprite.Draw(spriteBatch, labelArea, IsPower ? GUI.Style.Red : Color.SteelBlue);
|
||||
}
|
||||
|
||||
@@ -256,7 +238,8 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (!PlayerInput.PrimaryMouseButtonHeld())
|
||||
{
|
||||
if (GameMain.NetworkMember != null || panel.CheckCharacterSuccess(Character.Controlled))
|
||||
if ((GameMain.NetworkMember != null || panel.CheckCharacterSuccess(Character.Controlled)) &&
|
||||
Wires.Count(w => w != null) < MaxPlayerConnectableWires)
|
||||
{
|
||||
//find an empty cell for the new connection
|
||||
int index = FindEmptyIndex();
|
||||
@@ -390,5 +373,115 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckConnectionLabelOverlap(ConnectionPanel panel, out Point newRectSize)
|
||||
{
|
||||
Rectangle panelRect = panel.GuiFrame.Rect;
|
||||
int x = panelRect.X, y = panelRect.Y;
|
||||
Vector2 scale = GetScale(panel.GuiFrame.RectTransform.MaxSize, panel.GuiFrame.Rect.Size);
|
||||
Vector2 rightPos = GetRightPos(x, y, panelRect.Width, scale);
|
||||
Vector2 leftPos = GetLeftPos(x, y, scale);
|
||||
int connectorIntervalLeft = GetConnectorIntervalLeft(panelRect.Height, scale, panel);
|
||||
int connectorIntervalRight = GetConnectorIntervalRight(panelRect.Height, scale, panel);
|
||||
newRectSize = panelRect.Size;
|
||||
var labelAreas = new List<Rectangle>();
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
labelAreas.Clear();
|
||||
foreach (var c in panel.Connections)
|
||||
{
|
||||
if (c.IsOutput)
|
||||
{
|
||||
var labelArea = GetLabelArea(GetOutputLabelPosition(rightPos, panel, c), c.DisplayName.ToUpper(), scale);
|
||||
labelAreas.Add(labelArea);
|
||||
rightPos.Y += connectorIntervalLeft;
|
||||
}
|
||||
else
|
||||
{
|
||||
var labelArea = GetLabelArea(GetInputLabelPosition(leftPos, panel, c), c.DisplayName.ToUpper(), scale);
|
||||
labelAreas.Add(labelArea);
|
||||
leftPos.Y += connectorIntervalRight;
|
||||
}
|
||||
}
|
||||
bool foundOverlap = false;
|
||||
for (int j = 0; j < labelAreas.Count; j++)
|
||||
{
|
||||
for (int k = 0; k < labelAreas.Count; k++)
|
||||
{
|
||||
if (k == j) { continue; }
|
||||
if (!labelAreas[j].Intersects(labelAreas[k])) { continue; }
|
||||
newRectSize += new Point(10);
|
||||
Point maxSize = new Point(
|
||||
Math.Max(panel.GuiFrame.RectTransform.MaxSize.X, newRectSize.X),
|
||||
Math.Max(panel.GuiFrame.RectTransform.MaxSize.Y, newRectSize.Y));
|
||||
scale = GetScale(maxSize, newRectSize);
|
||||
rightPos = GetRightPos(x, y, newRectSize.X, scale);
|
||||
leftPos = GetLeftPos(x, y, scale);
|
||||
connectorIntervalLeft = GetConnectorIntervalLeft(newRectSize.Y, scale, panel);
|
||||
connectorIntervalRight = GetConnectorIntervalRight(newRectSize.Y, scale, panel);
|
||||
foundOverlap = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundOverlap) { break; }
|
||||
}
|
||||
return newRectSize.X != panel.GuiFrame.Rect.Width || newRectSize.Y > panel.GuiFrame.Rect.Height;
|
||||
}
|
||||
|
||||
private static Vector2 GetScale(Point maxSize, Point size)
|
||||
{
|
||||
Vector2 scale = new Vector2(GUI.Scale);
|
||||
if (maxSize.X < int.MaxValue)
|
||||
{
|
||||
scale.X = maxSize.X / size.X;
|
||||
}
|
||||
if (maxSize.Y < int.MaxValue)
|
||||
{
|
||||
scale.Y = maxSize.Y / size.Y;
|
||||
}
|
||||
return scale;
|
||||
}
|
||||
|
||||
private static Vector2 GetInputLabelPosition(Vector2 connectorPosition, ConnectionPanel panel, Connection connection)
|
||||
{
|
||||
return new Vector2(
|
||||
connectorPosition.X + 25 * panel.Scale,
|
||||
connectorPosition.Y - 5 * panel.Scale - GUI.SmallFont.MeasureString(connection.DisplayName.ToUpper()).Y);
|
||||
}
|
||||
|
||||
private static Vector2 GetOutputLabelPosition(Vector2 connectorPosition, ConnectionPanel panel, Connection connection)
|
||||
{
|
||||
return new Vector2(
|
||||
connectorPosition.X - 25 * panel.Scale - GUI.SmallFont.MeasureString(connection.DisplayName.ToUpper()).X,
|
||||
connectorPosition.Y + 5 * panel.Scale);
|
||||
}
|
||||
|
||||
private static Rectangle GetLabelArea(Vector2 labelPos, string text, Vector2 scale)
|
||||
{
|
||||
Vector2 textSize = GUI.SmallFont.MeasureString(text);
|
||||
Rectangle labelArea = new Rectangle(labelPos.ToPoint(), textSize.ToPoint());
|
||||
labelArea.Inflate(10 * scale.X, 3 * scale.Y);
|
||||
return labelArea;
|
||||
}
|
||||
|
||||
private static Vector2 GetLeftPos(int x, int y, Vector2 scale)
|
||||
{
|
||||
return new Vector2(x + 80 * scale.X, y + 60 * scale.Y);
|
||||
}
|
||||
|
||||
private static Vector2 GetRightPos(int x, int y, int width, Vector2 scale)
|
||||
{
|
||||
return new Vector2(x + width - 80 * scale.X, y + 60 * scale.Y);
|
||||
}
|
||||
|
||||
private static int GetConnectorIntervalLeft(int height, Vector2 scale, ConnectionPanel panel)
|
||||
{
|
||||
return (height - (int)(100 * scale.Y)) / Math.Max(panel.Connections.Count(c => c.IsOutput), 1);
|
||||
}
|
||||
|
||||
private static int GetConnectorIntervalRight(int height, Vector2 scale, ConnectionPanel panel)
|
||||
{
|
||||
return (height - (int)(100 * scale.Y)) / Math.Max(panel.Connections.Count(c => !c.IsOutput), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+34
-2
@@ -24,9 +24,15 @@ namespace Barotrauma.Items.Components
|
||||
get { return GuiFrame.Rect.Width / 400.0f; }
|
||||
}
|
||||
|
||||
partial void InitProjSpecific(XElement element)
|
||||
private Point originalMaxSize;
|
||||
private Vector2 originalRelativeSize;
|
||||
|
||||
partial void InitProjSpecific()
|
||||
{
|
||||
if (GuiFrame == null) { return; }
|
||||
originalMaxSize = GuiFrame.RectTransform.MaxSize;
|
||||
originalRelativeSize = GuiFrame.RectTransform.RelativeSize;
|
||||
CheckForLabelOverlap();
|
||||
new GUICustomComponent(new RectTransform(Vector2.One, GuiFrame.RectTransform), DrawConnections, null)
|
||||
{
|
||||
UserData = this
|
||||
@@ -40,7 +46,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
partial void UpdateProjSpecific(float deltaTime)
|
||||
{
|
||||
foreach (Wire wire in DisconnectedWires)
|
||||
foreach (var _ in DisconnectedWires)
|
||||
{
|
||||
if (Rand.Range(0.0f, 500.0f) < 1.0f)
|
||||
{
|
||||
@@ -112,6 +118,32 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnResolutionChanged()
|
||||
{
|
||||
base.OnResolutionChanged();
|
||||
if (GuiFrame == null) { return; }
|
||||
CheckForLabelOverlap();
|
||||
}
|
||||
|
||||
private void CheckForLabelOverlap()
|
||||
{
|
||||
GuiFrame.RectTransform.MaxSize = originalMaxSize;
|
||||
GuiFrame.RectTransform.Resize(originalRelativeSize);
|
||||
if (Connection.CheckConnectionLabelOverlap(this, out Point newRectSize))
|
||||
{
|
||||
int xCenter = (int)(GameMain.GraphicsWidth / 2.0f);
|
||||
int maxNewWidth = 2 * Math.Min(xCenter - HUDLayoutSettings.CrewArea.Right, xCenter - HUDLayoutSettings.ChatBoxArea.Right);
|
||||
int yCenter = (int)(GameMain.GraphicsHeight / 2.0f);
|
||||
int maxNewHeight = 2 * Math.Min(yCenter - HUDLayoutSettings.MessageAreaTop.Bottom, HUDLayoutSettings.InventoryTopY - yCenter);
|
||||
// Make sure we don't expand the panel interface too much
|
||||
newRectSize = new Point(Math.Min(newRectSize.X, maxNewWidth), Math.Min(newRectSize.Y, maxNewHeight));
|
||||
GuiFrame.RectTransform.MaxSize = new Point(
|
||||
Math.Max(GuiFrame.RectTransform.MaxSize.X, newRectSize.X),
|
||||
Math.Max(GuiFrame.RectTransform.MaxSize.Y, newRectSize.Y));
|
||||
GuiFrame.RectTransform.Resize(newRectSize);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
|
||||
{
|
||||
if (GameMain.Client.MidRoundSyncing)
|
||||
|
||||
@@ -50,7 +50,8 @@ namespace Barotrauma.Items.Components
|
||||
var textBox = new GUITextBox(new RectTransform(new Vector2(0.5f, 1.0f), layoutGroup.RectTransform), ciElement.Signal, style: "GUITextBoxNoIcon")
|
||||
{
|
||||
OverflowClip = true,
|
||||
UserData = ciElement
|
||||
UserData = ciElement,
|
||||
MaxTextLength = ciElement.MaxTextLength
|
||||
};
|
||||
//reset size restrictions set by the Style to make sure the elements can fit the interface
|
||||
textBox.RectTransform.MinSize = textBox.Frame.RectTransform.MinSize = new Point(0, 0);
|
||||
|
||||
@@ -63,21 +63,23 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
OutputValue = input;
|
||||
item.SendSignal(0, input, "signal_out", null);
|
||||
ShowOnDisplay(input);
|
||||
item.SendSignal(input, "signal_out");
|
||||
}
|
||||
|
||||
partial void ShowOnDisplay(string input)
|
||||
partial void ShowOnDisplay(string input, bool addToHistory = true)
|
||||
{
|
||||
messageHistory.Add(input);
|
||||
while (messageHistory.Count > MaxMessages)
|
||||
if (addToHistory)
|
||||
{
|
||||
messageHistory.RemoveAt(0);
|
||||
}
|
||||
|
||||
while (historyBox.Content.CountChildren > MaxMessages)
|
||||
{
|
||||
historyBox.RemoveChild(historyBox.Content.Children.First());
|
||||
messageHistory.Add(input);
|
||||
while (messageHistory.Count > MaxMessages)
|
||||
{
|
||||
messageHistory.RemoveAt(0);
|
||||
}
|
||||
while (historyBox.Content.CountChildren > MaxMessages)
|
||||
{
|
||||
historyBox.RemoveChild(historyBox.Content.Children.First());
|
||||
}
|
||||
}
|
||||
|
||||
GUITextBlock newBlock = new GUITextBlock(
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace Barotrauma.Items.Components
|
||||
SpriteEffects.None,
|
||||
depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static Sprite defaultWireSprite;
|
||||
private Sprite overrideSprite;
|
||||
private Sprite wireSprite;
|
||||
@@ -156,7 +156,8 @@ namespace Barotrauma.Items.Components
|
||||
drawOffset = sub.DrawPosition + sub.HiddenSubPosition;
|
||||
}
|
||||
|
||||
float depth = item.IsSelected ? 0.0f : SubEditorScreen.IsWiringMode() ? 0.02f : wireSprite.Depth + (item.ID % 100) * 0.000001f;// item.GetDrawDepth(wireSprite.Depth, wireSprite);
|
||||
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);
|
||||
|
||||
if (item.IsHighlighted)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user