6 using Microsoft.Xna.Framework;
7 using Microsoft.Xna.Framework.Graphics;
11 internal partial class CircuitBoxComponent
13 public static Option<GUIComponent> EditingHUD = Option.None;
15 private Sprite Sprite =>
Item.Prefab.InventoryIcon ??
Item.Prefab.Sprite;
17 private CircuitBoxLabel? label;
18 private CircuitBoxLabel Label
27 var name = TextManager.Get($
"circuitboxnode.{Item.Prefab.Identifier}").Fallback($
"[FALLBACK] {Item.Name}");
28 label =
new CircuitBoxLabel(name, GUIStyle.LargeFont);
33 public void UpdateEditing(RectTransform parent)
35 if (EditingHUD.TryUnwrap(out var editor))
37 if (editor.UserData ==
this) {
return; }
40 EditingHUD = Option.Some(CreateEditingHUD(parent));
43 public static void RemoveEditingHUD()
45 if (!EditingHUD.TryUnwrap(out var editor)) {
return; }
47 editor.RectTransform.Parent =
null;
48 EditingHUD = Option.None;
51 public GUIComponent CreateEditingHUD(RectTransform parent)
53 GUIFrame frame =
new(
new RectTransform(
new Vector2(0.4f, 0.3f), parent,
Anchor.TopRight))
58 GUIListBox listBox =
new(
new RectTransform(ToolBox.PaddingSizeParentRelative(frame.RectTransform, 0.8f), frame.RectTransform,
Anchor.Center))
60 KeepSpaceForScrollBar =
true,
61 AutoHideScrollBar =
false,
62 CanTakeKeyBoardFocus =
false
65 bool isEditor = Screen.Selected is { IsEditor:
true };
67 GUILayoutGroup titleHolder =
new GUILayoutGroup(
new RectTransform(
new Vector2(1f, 0.3f), listBox.Content.RectTransform));
68 new GUITextBlock(
new RectTransform(Vector2.One, titleHolder.RectTransform),
Item.Prefab.Name, font: GUIStyle.LargeFont)
70 TextColor = Color.White,
79 if (SerializableProperty.GetProperties<
InGameEditable>(ic).Count == 0 &&
85 new GUIFrame(
new RectTransform(
new Vector2(1.0f, 0.02f), listBox.Content.RectTransform), style:
"HorizontalLine");
87 var componentEditor =
new SerializableEntityEditor(listBox.Content.RectTransform, ic, inGame: !isEditor, showName:
false, titleFont: GUIStyle.SubHeadingFont)
89 Readonly = CircuitBox.Locked
91 fieldCount += componentEditor.Fields.Count;
94 componentEditor.Recalculate();
99 frame.Visible =
false;
105 public override void DrawHeader(SpriteBatch spriteBatch, RectangleF drawRect, Color color)
108 Vector2 scale =
new(drawRect.Height / MathF.Min(Sprite.size.X, Sprite.size.Y)),
109 spritePosition =
new(drawRect.Left, drawRect.Top);
111 float spriteWidth = Sprite.size.X * scale.X;
113 Sprite.Draw(spriteBatch, spritePosition, Color.White, Vector2.Zero, 0f, scale);
114 GUI.DrawString(spriteBatch,
new Vector2(spritePosition.X + spriteWidth + CircuitBoxSizes.NodeHeaderTextPadding, drawRect.Center.Y - Label.Size.Y / 2f), Label.Value, GUIStyle.TextColorNormal, font: GUIStyle.LargeFont);
The base class for components holding the different functionalities of the item
virtual void CreateEditingHUD(SerializableEntityEditor editor)
bool IsEditable(ISerializableEntity entity)