2 using Microsoft.Xna.Framework;
3 using Microsoft.Xna.Framework.Graphics;
5 using System.Collections.Generic;
11 partial class ItemAssemblyPrefab : MapEntityPrefab
17 float scale = Math.Min(drawArea.Width / (
float)
Bounds.Width, drawArea.Height / (
float)
Bounds.Height) * 0.9f;
24 (
int)(displayEntity.Rect.X * scale) + drawArea.Center.X, (
int)((displayEntity.Rect.Y) * scale) - drawArea.Center.Y,
25 (
int)(displayEntity.Rect.Width * scale), (
int)(displayEntity.Rect.Height * scale));
26 entityPrefab.DrawPlacing(spriteBatch, drawRect, entityPrefab.Scale * scale, rotation: displayEntity.RotationRad);
32 base.DrawPlacing(spriteBatch, cam);
38 public void Draw(SpriteBatch spriteBatch, Vector2 pos)
43 if (entityPrefab ==
null) {
continue; }
45 drawRect.Location += pos.ToPoint();
46 entityPrefab.DrawPlacing(spriteBatch, drawRect, entityPrefab.Scale, rotation: displayEntity.RotationRad);
50 public static XElement
Save(List<MapEntity> entities,
string name,
string description,
bool hideInMenus =
false)
52 XElement element =
new XElement(
"ItemAssembly",
53 new XAttribute(
"name", name),
54 new XAttribute(
"description", description),
55 new XAttribute(
"hideinmenus", hideInMenus));
59 for (
int i = 0; i < assemblyEntities.Count && i < entities.Count; i++)
61 assemblyEntities[i].Layer = entities[i].Layer;
66 List<MapEntity> disabledEntities =
new List<MapEntity>();
67 foreach (
MapEntity mapEntity
in assemblyEntities)
69 if (mapEntity is
Item item)
71 var wire = item.GetComponent<
Wire>();
72 if (item.ParentInventory !=
null ||
73 (wire !=
null && wire.Connections.Any(c => c !=
null)))
75 item.SetTransform(Vector2.Zero, 0.0f);
76 disabledEntities.Add(mapEntity);
81 float minX =
int.MaxValue, maxX =
int.MinValue;
82 float minY =
int.MaxValue, maxY =
int.MinValue;
83 foreach (
MapEntity mapEntity
in assemblyEntities)
85 if (disabledEntities.Contains(mapEntity)) {
continue; }
86 minX = Math.Min(minX, mapEntity.
WorldRect.X);
87 maxX = Math.Max(maxX, mapEntity.
WorldRect.Right);
89 maxY = Math.Max(maxY, mapEntity.
WorldRect.Y);
91 Vector2 center =
new Vector2((minX + maxX) / 2.0f, (minY + maxY) / 2.0f);
94 Vector2 offsetFromGrid =
new Vector2(
101 foreach (
MapEntity mapEntity
in assemblyEntities)
103 mapEntity.
Move(-center - offsetFromGrid);
105 var entityElement = mapEntity.
Save(element);
106 if (disabledEntities.Contains(mapEntity))
108 entityElement.Add(
new XAttribute(
"hideinassemblypreview",
"true"));
GUIComponent that can be used to render custom content on the UI
void DrawIcon(SpriteBatch spriteBatch, GUICustomComponent guiComponent)
static XElement Save(List< MapEntity > entities, string name, string description, bool hideInMenus=false)
override void DrawPlacing(SpriteBatch spriteBatch, Camera cam)
void Draw(SpriteBatch spriteBatch, Vector2 pos)
readonly Rectangle Bounds
readonly ImmutableArray< DisplayEntity > DisplayEntities
static HashSet< MapEntity > SelectedList
static void AddSelection(MapEntity entity)
virtual void Move(Vector2 amount, bool ignoreContacts=true)
static List< MapEntity > CopyEntities(List< MapEntity > entities)
copies a list of entities to the "clipboard" (copiedList)
virtual XElement Save(XElement parentElement)
static MapEntityPrefab FindByIdentifier(Identifier identifier)
static Vector2 placePosition
static Vector2 MouseToWorldGrid(Camera cam, Submarine sub, Vector2? mousePos=null, bool round=false)
Vector2 HiddenSubPosition
static readonly Vector2 GridSize