4 using Microsoft.Xna.Framework;
5 using Microsoft.Xna.Framework.Graphics;
9 internal abstract partial class CircuitBoxConnection
13 public CircuitBoxLabel Label {
get;
private set; }
15 private Sprite? knobSprite,
19 private static int Padding => GUI.IntScale(8);
21 private Option<LocalizedString> tooltip = Option.None;
23 private partial
void InitProjSpecific(CircuitBox circuitBox)
26 knobSprite = circuitBox.ConnectionSprite;
27 screwSprite = circuitBox.ConnectionScrewSprite;
28 connectorSprite = circuitBox.WireConnectorSprite;
29 Length = Rect.Width + Padding + Label.Size.X;
32 public void SetLabel(LocalizedString label, CircuitBoxNode node)
34 Label =
new CircuitBoxLabel(label, GUIStyle.SubHeadingFont);
35 Length = Rect.Width + Padding + Label.Size.X;
38 public void Draw(SpriteBatch spriteBatch, Vector2 drawPos, Vector2 parentPos, Color color)
40 if (CircuitBox.UI is not { } circuitBoxUi) {
return; }
41 var drawRect = CircuitBoxNode.OverrideRectLocation(Rect, drawPos, parentPos);
43 Vector2 cursorPos = circuitBoxUi.GetCursorPosition();
44 cursorPos.Y = -cursorPos.Y;
46 bool isMouseOver = drawRect.Contains(cursorPos);
51 xPos = drawRect.Left - Padding - Label.Size.X;
55 xPos = drawRect.Right + Padding;
58 Vector2 stringPos =
new Vector2(xPos, drawRect.Center.Y - Label.Size.Y / 2f);
59 GUI.DrawString(spriteBatch, stringPos, Label.Value, GUIStyle.TextColorNormal, font: Label.Font);
61 if (knobSprite is
null)
63 CircuitBoxUI.DrawRectangleWithBorder(spriteBatch, drawRect, GUIStyle.Blue * 0.3f, GUIStyle.Blue);
67 float scale = drawRect.Height / knobSprite.size.Y;
68 knobSprite?.Draw(spriteBatch, drawRect.Center, color, 0f, scale);
71 bool isScrewed =
this switch
73 CircuitBoxOutputConnection output => output.ExternallyConnectedFrom.Count > 0,
74 CircuitBoxInputConnection input => input.ExternallyConnectedTo.Count > 0,
77 ExternallyConnectedFrom.Count > 0
82 var glowSprite = GUIStyle.UIGlowCircular.Value?.Sprite;
83 if (glowSprite is not
null)
85 float glowScale = 40f / glowSprite.size.X;
90 glowSprite.Draw(spriteBatch, position, GUIStyle.Yellow, glowSprite.size / 2, scale: glowScale);
94 tooltip = Option.None;
99 if (isMouseOver && !tooltipText.IsNullOrEmpty())
101 tooltip = Option.Some(tooltipText);
105 if (!isScrewed) {
return; }
107 if (screwSprite is not
null)
109 float screwScale = drawRect.Height / screwSprite.size.Y;
110 screwSprite.Draw(spriteBatch, drawRect.Center, color, 0f, screwScale);
113 if (connectorSprite is not
null)
115 float screwScale = drawRect.Height / connectorSprite.size.Y * 2f;
116 Vector2 pos = drawRect.Center;
118 connectorSprite.Draw(spriteBatch,
121 origin: connectorSprite.Origin,
122 rotate: MathHelper.Pi / (IsOutput ? -2f : 2f),
124 spriteEffect: SpriteEffects.None);
128 public void DrawHUD(SpriteBatch spriteBatch, Camera camera)
130 if (!tooltip.TryUnwrap(out var text)) {
return; }
132 var drawPos = camera.WorldToScreen(
new Vector2(Rect.Right, -Rect.Bottom));
134 GUIComponent.DrawToolTip(spriteBatch, text, drawPos);
IReadOnlyCollection< Wire > Wires
readonly LocalizedString DisplayName
List< CircuitBoxConnection > CircuitBoxConnections
Circuit box input and output connections that are linked to this connection.
static void DrawConnectionDebugInfo(SpriteBatch spriteBatch, Connection c, Vector2 position, float scale, out LocalizedString tooltip)
static bool ShouldDebugDrawWiring