Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/CircuitBox/CircuitBoxNode.cs
1 #nullable enable
2 
3 using Microsoft.Xna.Framework;
4 using Microsoft.Xna.Framework.Graphics;
5 
6 namespace Barotrauma
7 {
8  internal partial class CircuitBoxNode
9  {
10  public RectangleF DrawRect;
11  private RectangleF TopDrawRect;
12 
13  protected void UpdateDrawRects()
14  {
15  var drawRect = new RectangleF(Position - Size / 2f, Size);
16  drawRect.Y = -drawRect.Y;
17  drawRect.Y -= drawRect.Height;
18  DrawRect = drawRect;
19 
20  TopDrawRect = new RectangleF(drawRect.X, drawRect.Y - (CircuitBoxSizes.NodeHeaderHeight - 1), drawRect.Width, CircuitBoxSizes.NodeHeaderHeight);
21  }
22 
23  public void OnUICreated()
24  {
25  Size = CalculateSize(Connectors);
26  UpdatePositions();
27  }
28 
29  public virtual void OnResized(RectangleF drawRect) { }
30 
31  public void DrawBackground(SpriteBatch spriteBatch, RectangleF drawRect, RectangleF topDrawRect, Color color)
32  {
33  CircuitBox.NodeFrameSprite?.Draw(spriteBatch, drawRect, color);
34  CircuitBox.NodeTopSprite?.Draw(spriteBatch, topDrawRect, color);
35  }
36 
37  public void Draw(SpriteBatch spriteBatch, Vector2 drawPos, Color color)
38  {
39  RectangleF drawRect = OverrideRectLocation(DrawRect, drawPos, Position),
40  topDrawRect = OverrideRectLocation(TopDrawRect, drawPos, Position);
41 
42  DrawBackground(spriteBatch, drawRect, topDrawRect, color);
43  DrawHeader(spriteBatch, topDrawRect, color);
44  DrawBody(spriteBatch, drawRect, color);
45 
46  DrawConnectors(spriteBatch, drawPos);
47  }
48 
49  public void DrawHUD(SpriteBatch spriteBatch, Camera camera)
50  {
51  foreach (var c in Connectors)
52  {
53  c.DrawHUD(spriteBatch, camera);
54  }
55  }
56 
57  public virtual void DrawHeader(SpriteBatch spriteBatch, RectangleF rect, Color color) { }
58  public virtual void DrawBody(SpriteBatch spriteBatch, RectangleF rect, Color color) { }
59 
60  public void DrawConnectors(SpriteBatch spriteBatch, Vector2 drawPos)
61  {
62  var color = Color.White * Opacity;
63  foreach (var c in Connectors)
64  {
65  c.Draw(spriteBatch, drawPos, Position, color);
66  }
67  }
68 
69  public void DrawSelection(SpriteBatch spriteBatch, Color color)
70  {
71  int pad = GUI.IntScale(8);
72 
73  var rect = Rect;
74  rect.Y = -rect.Y;
75  rect.Y -= rect.Height;
76 
77  rect.Inflate(pad, pad);
78 
79  GUI.DrawFilledRectangle(spriteBatch, rect, color * Opacity);
80  }
81 
85  public static RectangleF OverrideRectLocation(RectangleF rect, Vector2 overridePos, Vector2 originalPos)
86  {
87  rect.Location -= new Vector2(originalPos.X, -originalPos.Y);
88  rect.Location += new Vector2(overridePos.X, -overridePos.Y);
89  return rect;
90  }
91  }
92 }