Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/Items/Components/Signal/Connection.cs
1 using Microsoft.Xna.Framework;
2 using Microsoft.Xna.Framework.Graphics;
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 
8 {
9  partial class Connection
10  {
11  //private static Texture2D panelTexture;
12  private static Sprite connector;
13  private static Sprite wireVertical;
14  private static Sprite connectionSprite;
15  private static Sprite connectionSpriteHighlight;
16  private static List<Sprite> screwSprites;
17 
18  private Color flashColor;
19  private float flashDuration = 1.5f;
20 
21  public float FlashTimer { get; private set; }
22  public static Wire DraggingConnected { get; private set; }
23 
24  private static float ConnectionSpriteSize => 35.0f * GUI.Scale;
25 
26  public static void DrawConnections(SpriteBatch spriteBatch, ConnectionPanel panel, Rectangle dragArea, Character character,
27  out (Vector2 tooltipPos, LocalizedString text) tooltip)
28  {
29  if (DraggingConnected?.Item?.Removed ?? true)
30  {
31  DraggingConnected = null;
32  }
33 
34  Rectangle panelRect = panel.GuiFrame.Rect;
35  int x = panelRect.X, y = panelRect.Y;
36  int width = panelRect.Width, height = panelRect.Height;
37 
38  bool mouseInRect = panelRect.Contains(PlayerInput.MousePosition);
39 
40  int totalWireCount = 0;
41  foreach (Connection c in panel.Connections)
42  {
43  totalWireCount += c.Wires.Count;
44  }
45 
46  Wire equippedWire = null;
47 
48  bool allowRewiring = GameMain.NetworkMember?.ServerSettings == null || GameMain.NetworkMember.ServerSettings.AllowRewiring || panel.AlwaysAllowRewiring;
49  if (allowRewiring && (!panel.Locked && !panel.TemporarilyLocked || Screen.Selected == GameMain.SubEditorScreen))
50  {
51  //if the Character using the panel has a wire item equipped
52  //and the wire hasn't been connected yet, draw it on the panel
53  foreach (Item item in character.HeldItems)
54  {
55  Wire wireComponent = item.GetComponent<Wire>();
56  if (wireComponent != null)
57  {
58  equippedWire = wireComponent;
59  var connectedEnd = equippedWire.OtherConnection(null);
60  if (connectedEnd?.Item.Submarine != null && panel.Item.Submarine != connectedEnd.Item.Submarine)
61  {
62  equippedWire = null;
63  }
64  }
65  }
66  }
67 
68  tooltip = (Vector2.Zero, string.Empty);
69 
70  //two passes: first the connector, then the wires to get the wires to render in front
71  for (int i = 0; i < 2; i++)
72  {
73  Vector2 rightPos = GetRightPos(x, y, width);
74  Vector2 leftPos = GetLeftPos(x, y);
75 
76  Vector2 rightWirePos = new Vector2(x + width - 5 * GUI.Scale, y + 30 * GUI.Scale);
77  Vector2 leftWirePos = new Vector2(x + 5 * GUI.Scale, y + 30 * GUI.Scale);
78 
79  int wireInterval = (height - (int)(20 * GUI.Scale)) / Math.Max(totalWireCount, 1);
80  int connectorIntervalLeft = GetConnectorIntervalLeft(height, panel);
81  int connectorIntervalRight = GetConnectorIntervalRight(height, panel);
82 
83  foreach (Connection c in panel.Connections)
84  {
85  //if dragging a wire, let the Inventory know so that the wire can be
86  //dropped or dragged from the panel to the players inventory
87  if (DraggingConnected != null && i == 1)
88  {
89  //the wire can only be dragged out if it's not connected to anything at the other end
91  (DraggingConnected.Connections[0] == null && DraggingConnected.Connections[1] == null) ||
92  (DraggingConnected.Connections.Contains(c) && DraggingConnected.Connections.Contains(null)))
93  {
94  var linkedWire = c.FindWireByItem(DraggingConnected.Item);
95  if (linkedWire != null || panel.DisconnectedWires.Contains(DraggingConnected))
96  {
97  Inventory.DraggingItems.Clear();
99  }
100  }
101  }
102 
103  Vector2 position = c.IsOutput ? rightPos : leftPos;
105  {
106  DrawConnectionDebugInfo(spriteBatch, c, position, GUI.Scale, out var tooltipText);
107 
108  if (!tooltipText.IsNullOrEmpty())
109  {
110  bool mouseOn = Vector2.DistanceSquared(position, PlayerInput.MousePosition) < MathUtils.Pow2(35 * GUI.Scale);
111  if (mouseOn)
112  {
113  tooltip = (position, tooltipText);
114  }
115  }
116  }
117 
118  //outputs are drawn at the right side of the panel, inputs at the left
119  if (c.IsOutput)
120  {
121  if (i == 0)
122  {
123  c.DrawConnection(spriteBatch, panel, rightPos, GetOutputLabelPosition(rightPos, panel, c));
124  }
125  else
126  {
127  c.DrawWires(spriteBatch, panel, rightPos, rightWirePos, mouseInRect, equippedWire, wireInterval);
128  }
129  rightPos.Y += connectorIntervalLeft;
130  rightWirePos.Y += c.Wires.Count * wireInterval;
131  }
132  else
133  {
134  if (i == 0)
135  {
136  c.DrawConnection(spriteBatch, panel, leftPos, GetInputLabelPosition(leftPos, panel, c));
137  }
138  else
139  {
140  c.DrawWires(spriteBatch, panel, leftPos, leftWirePos, mouseInRect, equippedWire, wireInterval);
141  }
142  leftPos.Y += connectorIntervalRight;
143  leftWirePos.Y += c.Wires.Count * wireInterval;
144  }
145  }
146  }
147 
148  if (DraggingConnected != null)
149  {
150  if (mouseInRect)
151  {
152  Vector2 wireDragPos = new Vector2(
153  MathHelper.Clamp(PlayerInput.MousePosition.X, dragArea.X, dragArea.Right),
154  MathHelper.Clamp(PlayerInput.MousePosition.Y, dragArea.Y, dragArea.Bottom));
155  DrawWire(spriteBatch, DraggingConnected, wireDragPos, new Vector2(x + width / 2, y + height - 10), null, panel, "");
156  }
157  panel.TriggerRewiringSound();
158 
160  {
161  if (GameMain.NetworkMember != null || panel.CheckCharacterSuccess(character))
162  {
163  if (DraggingConnected.Connections[0]?.ConnectionPanel == panel ||
165  {
168  {
170  }
171  else if (DraggingConnected.Connections[0] == null && DraggingConnected.Connections[1] == null)
172  {
174  }
175  }
176  }
177 
178  if (GameMain.Client != null)
179  {
180  panel.Item.CreateClientEvent(panel);
181  }
182 
183  DraggingConnected = null;
184  }
185  }
186 
187  //if the Character using the panel has a wire item equipped
188  //and the wire hasn't been connected yet, draw it on the panel
189  if (equippedWire != null && (DraggingConnected != equippedWire || !mouseInRect))
190  {
191  if (panel.Connections.Find(c => c.Wires.Contains(equippedWire)) == null)
192  {
193  DrawWire(spriteBatch, equippedWire, new Vector2(x + width / 2, y + height - 150 * GUI.Scale),
194  new Vector2(x + width / 2, y + height),
195  null, panel, "");
196 
197  if (DraggingConnected == equippedWire)
198  {
199  Inventory.DraggingItems.Clear();
200  Inventory.DraggingItems.Add(equippedWire.Item);
201  }
202  }
203  }
204 
205 
206  float step = (width * 0.75f) / panel.DisconnectedWires.Count;
207  x = (int)(x + width / 2 - step * (panel.DisconnectedWires.Count - 1) / 2);
208  foreach (Wire wire in panel.DisconnectedWires)
209  {
210  if (wire == DraggingConnected && mouseInRect) { continue; }
211  if (wire.HiddenInGame && Screen.Selected == GameMain.GameScreen) { continue; }
212 
213  Connection recipient = wire.OtherConnection(null);
214  LocalizedString label = recipient == null ? "" : recipient.item.Name + $" ({recipient.DisplayName})";
215  if (wire.Locked) { label += "\n" + TextManager.Get("ConnectionLocked"); }
216  DrawWire(spriteBatch, wire, new Vector2(x, y + height - 100 * GUI.Scale),
217  new Vector2(x, y + height),
218  null, panel, label);
219  x += (int)step;
220  }
221 
222  //stop dragging a wire item if the cursor is within any connection panel
223  //(so we don't drop the item when dropping the wire on a connection)
224  if (mouseInRect || (GUI.MouseOn?.UserData is ConnectionPanel && GUI.MouseOn.MouseRect.Contains(PlayerInput.MousePosition)))
225  {
226  Inventory.DraggingItems.Clear();
227  }
228  }
229 
230  public static void DrawConnectionDebugInfo(SpriteBatch spriteBatch, Connection c, Vector2 position, float scale, out LocalizedString tooltip)
231  {
232  Color highlightColor = Color.Transparent;
233  if (c.IsPower)
234  {
235  highlightColor = VisualizeSignal(0.0f, highlightColor, Color.Red);
236  }
237  else
238  {
239  highlightColor = VisualizeSignal(c.LastReceivedSignal.TimeSinceCreated, highlightColor, Color.LightGreen);
240  highlightColor = VisualizeSignal(c.LastSentSignal.TimeSinceCreated, highlightColor, Color.Orange);
241  }
242 
243  LocalizedString toolTipText = c.GetToolTip();
244  if (!toolTipText.IsNullOrEmpty())
245  {
246  var glowSprite = GUIStyle.UIGlowCircular.Value.Sprite;
247  glowSprite.Draw(spriteBatch, position, highlightColor, glowSprite.size / 2,
248  scale: 45.0f / glowSprite.size.X * scale);
249  }
250 
251  tooltip = toolTipText;
252 
253  static Color VisualizeSignal(double timeSinceCreated, Color defaultColor, Color color)
254  {
255  if (timeSinceCreated < 1.0f)
256  {
257  float pulseAmount = (MathF.Sin((float)Timing.TotalTimeUnpaused * 10.0f) + 3.0f) / 4.0f;
258  Color targetColor = Color.Lerp(defaultColor, color, pulseAmount);
259  return Color.Lerp(targetColor, defaultColor, (float)timeSinceCreated);
260  }
261  return defaultColor;
262  }
263  }
264 
265  private void DrawConnection(SpriteBatch spriteBatch, ConnectionPanel panel, Vector2 position, Vector2 labelPos)
266  {
267  string text = DisplayName.Value.ToUpperInvariant();
268 
269  //nasty
270  if (GUIStyle.GetComponentStyle("ConnectionPanelLabel")?.Sprites.Values.First().First() is UISprite labelSprite)
271  {
272  Rectangle labelArea = GetLabelArea(labelPos, text);
273  labelSprite.Draw(spriteBatch, labelArea, IsPower ? GUIStyle.Red : Color.SteelBlue);
274  }
275 
276  GUI.DrawString(spriteBatch, labelPos + Vector2.UnitY, text, Color.Black * 0.8f, font: GUIStyle.SmallFont);
277  GUI.DrawString(spriteBatch, labelPos, text, GUIStyle.TextColorBright, font: GUIStyle.SmallFont);
278 
279  float connectorSpriteScale = ConnectionSpriteSize / connectionSprite.SourceRect.Width;
280 
281  connectionSprite.Draw(spriteBatch, position, scale: connectorSpriteScale);
282 
283  }
284 
285  private void DrawWires(SpriteBatch spriteBatch, ConnectionPanel panel, Vector2 position, Vector2 wirePosition, bool mouseIn, Wire equippedWire, float wireInterval)
286  {
287  float connectorSpriteScale = ConnectionSpriteSize / connectionSprite.SourceRect.Width;
288 
289  foreach (var wire in wires)
290  {
291  if (wire.Hidden || (DraggingConnected == wire && (mouseIn || Screen.Selected == GameMain.SubEditorScreen))) { continue; }
292  if (wire.HiddenInGame && Screen.Selected == GameMain.GameScreen) { continue; }
293 
294  Connection recipient = wire.OtherConnection(this);
295  LocalizedString label;
296  if (wire.Item.IsLayerHidden)
297  {
298  label = TextManager.Get("ConnectionLocked");
299  }
300  else
301  {
302  label = recipient == null ? "" : recipient.item.Name + $" ({recipient.DisplayName})";
303  if (wire.Locked) { label += "\n" + TextManager.Get("ConnectionLocked"); }
304  }
305 
306  DrawWire(spriteBatch, wire, position, wirePosition, equippedWire, panel, label);
307 
308  wirePosition.Y += wireInterval;
309  }
310 
311  bool isMouseOn = Vector2.Distance(position, PlayerInput.MousePosition) < (20.0f * GUI.Scale);
312  if (isMouseOn)
313  {
314  connectionSpriteHighlight.Draw(spriteBatch, position, scale: connectorSpriteScale);
315  }
316 
317  if (DraggingConnected != null && isMouseOn)
318  {
319 
320  if (!PlayerInput.PrimaryMouseButtonHeld())
321  {
322  if ((GameMain.NetworkMember != null || panel.CheckCharacterSuccess(Character.Controlled)) &&
324  {
325  //find an empty cell for the new connection
326  if (WireSlotsAvailable() && !Wires.Contains(DraggingConnected))
327  {
328  bool alreadyConnected = DraggingConnected.IsConnectedTo(panel.Item);
330  if (DraggingConnected.TryConnect(this, !alreadyConnected, true))
331  {
332  var otherConnection = DraggingConnected.OtherConnection(this);
334  }
335  }
336  }
337 
338  if (GameMain.Client != null)
339  {
340  panel.Item.CreateClientEvent(panel);
341  }
342  DraggingConnected = null;
343  }
344  }
345 
346  if (FlashTimer > 0.0f)
347  {
348  //the number of flashes depends on the duration, 1 flash per 1 full second
349  int flashCycleCount = (int)Math.Max(flashDuration, 1);
350  float flashCycleDuration = flashDuration / flashCycleCount;
351 
352  //MathHelper.Pi * 0.8f -> the curve goes from 144 deg to 0,
353  //i.e. quickly bumps up from almost full brightness to full and then fades out
354  connectionSpriteHighlight.Draw(spriteBatch, position,
355  flashColor * (float)Math.Sin(FlashTimer % flashCycleDuration / flashCycleDuration * MathHelper.Pi * 0.8f), scale: connectorSpriteScale);
356  }
357 
358  if (Wires.Any(w => w != DraggingConnected && !w.Hidden && (!w.HiddenInGame || Screen.Selected != GameMain.GameScreen)))
359  {
360  int screwIndex = (int)Math.Floor(position.Y / 30.0f) % screwSprites.Count;
361  screwSprites[screwIndex].Draw(spriteBatch, position, scale: connectorSpriteScale);
362  }
363  }
364 
365  public void Flash(Color? color = null, float flashDuration = 1.5f)
366  {
367  FlashTimer = flashDuration;
368  this.flashDuration = flashDuration;
369  flashColor = (color == null) ? GUIStyle.Red : (Color)color;
370  }
371 
372  public void UpdateFlashTimer(float deltaTime)
373  {
374  if (FlashTimer <= 0) return;
375  FlashTimer -= deltaTime;
376  }
377 
378  private (string signal, LocalizedString tooltip) lastSignalToolTip;
379  private (int powerValue, LocalizedString tooltip) lastPowerToolTip;
380 
381  private LocalizedString GetToolTip()
382  {
384  {
385  return getSignalTooltip(LastReceivedSignal, "receivedsignal");
386  }
387  else if (LastSentSignal.TimeSinceCreated < 1.0f)
388  {
389  return getSignalTooltip(LastSentSignal, "sentsignal");
390  }
391 
392  LocalizedString getSignalTooltip(Signal signal, string textTag)
393  {
394  if (lastSignalToolTip.signal == signal.value && !lastSignalToolTip.tooltip.IsNullOrEmpty()) { return lastSignalToolTip.tooltip; }
395  lastSignalToolTip = (signal.value, TextManager.GetWithVariable(textTag, "[signal]", signal.value));
396  return lastSignalToolTip.tooltip;
397  }
398 
399  if (IsPower)
400  {
401  if (item.GetComponent<Powered>() is Powered powered)
402  {
403  if (IsOutput)
404  {
405  if (powered.CurrPowerConsumption < 0)
406  {
407  return getPowerTooltip(-(int)powered.CurrPowerConsumption, "reactoroutput");
408  }
409  else if (powered is PowerTransfer || powered is PowerContainer)
410  {
411  return getPowerTooltip((int)(Grid?.Power ?? 0), "reactoroutput");
412  }
413  }
414  else if (!IsOutput)
415  {
416  float powerConsumption = powered.GetCurrentPowerConsumption(this);
417  if (!MathUtils.NearlyEqual((int)powerConsumption, 0.0f))
418  {
419  return getPowerTooltip((int)powerConsumption, "reactorload");
420  }
421  }
422  }
423  }
424 
425  LocalizedString getPowerTooltip(int powerValue, string textTag)
426  {
427  if (lastPowerToolTip.powerValue == powerValue && !lastPowerToolTip.tooltip.IsNullOrEmpty()) { return lastPowerToolTip.tooltip; }
428  lastPowerToolTip = (powerValue, TextManager.GetWithVariable(textTag, "[kw]", powerValue.ToString()));
429  return lastPowerToolTip.tooltip;
430  }
431 
432  return null;
433  }
434 
435  private static void DrawWire(SpriteBatch spriteBatch, Wire wire, Vector2 end, Vector2 start, Wire equippedWire, ConnectionPanel panel, LocalizedString label)
436  {
437  int textX = (int)start.X;
438  if (start.X < end.X)
439  textX -= 10;
440  else
441  textX += 10;
442 
443  bool canDrag = equippedWire == null || equippedWire == wire;
444 
445  float alpha = canDrag ? 1.0f : 0.5f;
446 
447  bool mouseOn =
448  canDrag &&
449  GUI.MouseOn is not GUIDragHandle &&
450  ((PlayerInput.MousePosition.X > Math.Min(start.X, end.X) &&
451  PlayerInput.MousePosition.X < Math.Max(start.X, end.X) &&
452  MathUtils.LineToPointDistanceSquared(start, end, PlayerInput.MousePosition) < 36) ||
453  Vector2.Distance(end, PlayerInput.MousePosition) < 20.0f ||
454  new Rectangle((start.X < end.X) ? textX - 100 : textX, (int)start.Y - 5, 100, 14).Contains(PlayerInput.MousePosition));
455 
456  if (!label.IsNullOrEmpty())
457  {
458  if (start.Y > panel.GuiFrame.Rect.Bottom - 1.0f)
459  {
460  //wire at the bottom of the panel -> draw the text below the panel, tilted 45 degrees
461  GUIStyle.Font.DrawString(spriteBatch, label, start + Vector2.UnitY * 20 * GUI.Scale, Color.White, 45.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f);
462  }
463  else
464  {
465  GUI.DrawString(spriteBatch,
466  new Vector2(start.X < end.X ? textX - GUIStyle.SmallFont.MeasureString(label).X : textX, start.Y - 5.0f),
467  label,
468  wire.Locked ? GUIStyle.TextColorDim : (mouseOn ? Wire.higlightColor : GUIStyle.TextColorNormal), Color.Black * 0.9f,
469  3, GUIStyle.SmallFont);
470  }
471  }
472 
473  var wireEnd = end + Vector2.Normalize(start - end) * 30.0f * GUI.Scale;
474 
475  float dist = Vector2.Distance(start, wireEnd);
476 
477  float wireWidth = 12 * GUI.Scale;
478  float highlight = 5 * GUI.Scale;
479  if (mouseOn)
480  {
481  spriteBatch.Draw(wireVertical.Texture, new Rectangle(wireEnd.ToPoint(), new Point((int)(wireWidth + highlight), (int)dist)), wireVertical.SourceRect,
482  Wire.higlightColor,
483  MathUtils.VectorToAngle(end - start) + MathHelper.PiOver2,
484  new Vector2(wireVertical.size.X / 2, 0), // point in line about which to rotate
485  SpriteEffects.None,
486  0.0f);
487  }
488  spriteBatch.Draw(wireVertical.Texture, new Rectangle(wireEnd.ToPoint(), new Point((int)wireWidth, (int)dist)), wireVertical.SourceRect,
489  wire.Item.Color * alpha,
490  MathUtils.VectorToAngle(end - start) + MathHelper.PiOver2,
491  new Vector2(wireVertical.size.X / 2, 0), // point in line about which to rotate
492  SpriteEffects.None,
493  0.0f);
494 
495  float connectorScale = wireWidth / (float)wireVertical.SourceRect.Width;
496 
497  connector.Draw(spriteBatch, end, Color.White, connector.Origin, MathUtils.VectorToAngle(end - start) + MathHelper.PiOver2, scale: connectorScale);
498 
499  if (DraggingConnected == null && canDrag)
500  {
501  if (mouseOn)
502  {
504 
505  bool allowRewiring = GameMain.NetworkMember?.ServerSettings == null || GameMain.NetworkMember.ServerSettings.AllowRewiring || panel.AlwaysAllowRewiring;
506  if (allowRewiring && (!wire.Locked && !wire.Item.IsLayerHidden && !panel.Locked && !panel.TemporarilyLocked || Screen.Selected == GameMain.SubEditorScreen))
507  {
508  //start dragging the wire
509  if (PlayerInput.PrimaryMouseButtonHeld()) { DraggingConnected = wire; }
510  }
511  }
512  }
513  }
514 
515  public static bool CheckConnectionLabelOverlap(ConnectionPanel panel, out Point newRectSize)
516  {
517  Rectangle panelRect = panel.GuiFrame.Rect;
518  int x = panelRect.X, y = panelRect.Y;
519  Vector2 rightPos = GetRightPos(x, y, panelRect.Width);
520  Vector2 leftPos = GetLeftPos(x, y);
521  int connectorIntervalLeft = GetConnectorIntervalLeft(panelRect.Height, panel);
522  int connectorIntervalRight = GetConnectorIntervalRight(panelRect.Height, panel);
523  newRectSize = panelRect.Size;
524 
525  //make sure the connection labels don't overlap horizontally
526  float rightMostInput = panelRect.Center.X;
527  float leftMostOutput = panelRect.Center.X;
528  foreach (var c in panel.Connections)
529  {
530  if (c.IsOutput)
531  {
532  var labelArea = GetLabelArea(GetOutputLabelPosition(rightPos, panel, c), c.DisplayName.Value.ToUpperInvariant());
533  leftMostOutput = Math.Min(leftMostOutput, labelArea.X);
534  rightPos.Y += connectorIntervalLeft;
535  }
536  else
537  {
538  var labelArea = GetLabelArea(GetInputLabelPosition(leftPos, panel, c), c.DisplayName.Value.ToUpperInvariant());
539  rightMostInput = Math.Max(rightMostInput, labelArea.Right);
540  leftPos.Y += connectorIntervalRight;
541  }
542  }
543  if (leftMostOutput < rightMostInput)
544  {
545  newRectSize += new Point((int)(rightMostInput - leftMostOutput) + GUI.IntScale(15), 0);
546  }
547 
548  //make sure connection sprites don't overlap vertically
549  while (GetConnectorIntervalLeft(newRectSize.Y, panel) < ConnectionSpriteSize ||
550  GetConnectorIntervalRight(newRectSize.Y, panel) < ConnectionSpriteSize)
551  {
552  newRectSize.Y += 10;
553  }
554  return newRectSize.X != panel.GuiFrame.Rect.Width || newRectSize.Y > panel.GuiFrame.Rect.Height;
555  }
556 
557  private static Vector2 GetInputLabelPosition(Vector2 connectorPosition, ConnectionPanel panel, Connection connection)
558  {
559  return new Vector2(
560  connectorPosition.X + 25 * GUI.Scale,
561  connectorPosition.Y - GUIStyle.SmallFont.MeasureString(connection.DisplayName.ToUpper()).Y / 2);
562  }
563 
564  private static Vector2 GetOutputLabelPosition(Vector2 connectorPosition, ConnectionPanel panel, Connection connection)
565  {
566  return new Vector2(
567  connectorPosition.X - 25 * GUI.Scale - GUIStyle.SmallFont.MeasureString(connection.DisplayName.ToUpper()).X,
568  connectorPosition.Y - GUIStyle.SmallFont.MeasureString(connection.DisplayName.ToUpper()).Y / 2);
569  }
570 
571  private static Rectangle GetLabelArea(Vector2 labelPos, string text)
572  {
573  Vector2 textSize = GUIStyle.SmallFont.MeasureString(text);
574  Rectangle labelArea = new Rectangle(labelPos.ToPoint(), textSize.ToPoint());
575  labelArea.Inflate(GUI.IntScale(10), GUI.IntScale(3));
576  return labelArea;
577  }
578 
579  private static Vector2 GetLeftPos(int x, int y)
580  {
581  return new Vector2(x + 80 * GUI.Scale, y + 60 * GUI.Scale);
582  }
583 
584  private static Vector2 GetRightPos(int x, int y, int width)
585  {
586  return new Vector2(x + width - 80 * GUI.Scale, y + 60 * GUI.Scale);
587  }
588 
589  private static int GetConnectorIntervalLeft(int height, ConnectionPanel panel)
590  {
591  return (height - GUI.IntScale(60)) / Math.Max(panel.Connections.Count(c => c.IsOutput), 1);
592  }
593 
594  private static int GetConnectorIntervalRight(int height, ConnectionPanel panel)
595  {
596  return (height - GUI.IntScale(60)) / Math.Max(panel.Connections.Count(c => !c.IsOutput), 1);
597  }
598  }
599 }
IEnumerable< Item >?? HeldItems
Items the character has in their hand slots. Doesn't return nulls and only returns items held in both...
Submarine Submarine
Definition: Entity.cs:53
virtual Rectangle Rect
static SubEditorScreen SubEditorScreen
Definition: GameMain.cs:68
static GameScreen GameScreen
Definition: GameMain.cs:52
static NetworkMember NetworkMember
Definition: GameMain.cs:190
static GameClient Client
Definition: GameMain.cs:188
static bool CheckConnectionLabelOverlap(ConnectionPanel panel, out Point newRectSize)
static void DrawConnections(SpriteBatch spriteBatch, ConnectionPanel panel, Rectangle dragArea, Character character, out(Vector2 tooltipPos, LocalizedString text) tooltip)
static void DrawConnectionDebugInfo(SpriteBatch spriteBatch, Connection c, Vector2 position, float scale, out LocalizedString tooltip)
Connection(ContentXElement element, ConnectionPanel connectionPanel, IdRemap idRemap)
readonly HashSet< Wire > DisconnectedWires
Wires that have been disconnected from the panel, but not removed completely (visible at the bottom o...
bool AlwaysAllowRewiring
Allows rewiring the connection panel despite rewiring being disabled on a server
bool CheckCharacterSuccess(Character character)
Check if the character manages to succesfully rewire the panel, and if not, apply OnFailure effects
void Draw(SpriteBatch spriteBatch, bool editing, float itemDepth=-1, Color? overrideColor=null)
bool TryConnect(Connection newConnection, bool addNode=true, bool sendNetworkEvent=false)
Tries to add the given connection to this wire. Note that this only affects the wire - adding the wir...
Submarine(SubmarineInfo info, bool showErrorMessages=true, Func< Submarine, List< MapEntity >> loadEntities=null, IdRemap linkedRemap=null)