diff --git a/Subsurface/Source/Items/Components/Signal/Wire.cs b/Subsurface/Source/Items/Components/Signal/Wire.cs index fe70388d7..7fe3c3529 100644 --- a/Subsurface/Source/Items/Components/Signal/Wire.cs +++ b/Subsurface/Source/Items/Components/Signal/Wire.cs @@ -267,7 +267,7 @@ namespace Barotrauma.Items.Components item.NewComponentEvent(this, true, true); } - Drawable = Nodes.Any(); + Drawable = sections.Count > 0; } public override bool Pick(Character picker) @@ -277,6 +277,20 @@ namespace Barotrauma.Items.Components return true; } + public override void Move(Vector2 amount) + { + if (item.IsSelected) MoveNodes(amount); + } + + public void MoveNodes(Vector2 amount) + { + for (int i = 0; i < Nodes.Count; i++) + { + Nodes[i] += amount; + } + UpdateSections(); + } + public void UpdateSections() { sections.Clear(); @@ -285,6 +299,7 @@ namespace Barotrauma.Items.Components { sections.Add(new WireSection(Nodes[i], Nodes[i + 1])); } + Drawable = sections.Count > 0; } private void ClearConnections() @@ -303,7 +318,7 @@ namespace Barotrauma.Items.Components connections[i] = null; } - Drawable = false; + Drawable = sections.Count > 0; } private Vector2 RoundNode(Vector2 position, Hull hull) @@ -365,7 +380,7 @@ namespace Barotrauma.Items.Components public void Draw(SpriteBatch spriteBatch, bool editing) { - if (!Nodes.Any()) + if (sections.Count == 0) { Drawable = false; return; @@ -386,6 +401,13 @@ namespace Barotrauma.Items.Components section.Draw(spriteBatch, Color.Gold, drawOffset, depth, 0.5f); } } + else if (item.IsSelected) + { + foreach (WireSection section in sections) + { + section.Draw(spriteBatch, Color.Red, drawOffset, depth, 0.5f); + } + } foreach (WireSection section in sections) { diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 9e226240f..aeecfc1f3 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -423,12 +423,21 @@ namespace Barotrauma clone.properties[property.Key].TrySetValue(property.Value.GetValue()); } - if (ContainedItems!=null) + for (int i = 0; i < components.Count; i++) + { + foreach (KeyValuePair property in components[i].properties) + { + if (!property.Value.Attributes.OfType().Any()) continue; + clone.components[i].properties[property.Key].TrySetValue(property.Value.GetValue()); + } + } + + if (ContainedItems != null) { foreach (Item containedItem in ContainedItems) { var containedClone = containedItem.Clone(); - clone.ownInventory.TryPutItem(containedItem); + clone.ownInventory.TryPutItem(containedClone as Item); } } @@ -880,7 +889,7 @@ namespace Barotrauma public override void Draw(SpriteBatch spriteBatch, bool editing, bool back = true) { if (!Visible) return; - Color color = (isSelected && editing) ? color = Color.Red : spriteColor; + Color color = (IsSelected && editing) ? color = Color.Red : spriteColor; if (isHighlighted) color = Color.Orange; SpriteEffects oldEffects = prefab.sprite.effects; @@ -943,7 +952,7 @@ namespace Barotrauma return; } - if (isSelected || isHighlighted) + if (IsSelected || isHighlighted) { GUI.DrawRectangle(spriteBatch, new Vector2(DrawPosition.X - rect.Width / 2, -(DrawPosition.Y+rect.Height/2)), new Vector2(rect.Width, rect.Height), Color.Green,false,0,(int)Math.Max((1.5f/GameScreen.Selected.Cam.Zoom),1.0f)); diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index 784c8359d..1d7a76708 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -609,7 +609,7 @@ namespace Barotrauma } - if ((isSelected || isHighlighted) && editing) + if ((IsSelected || isHighlighted) && editing) { GUI.DrawRectangle(spriteBatch, new Vector2(drawRect.X + 5, -drawRect.Y + 5), diff --git a/Subsurface/Source/Map/LinkedSubmarine.cs b/Subsurface/Source/Map/LinkedSubmarine.cs index b17c76116..856a65f65 100644 --- a/Subsurface/Source/Map/LinkedSubmarine.cs +++ b/Subsurface/Source/Map/LinkedSubmarine.cs @@ -111,7 +111,7 @@ namespace Barotrauma if (!editing || wallVertices == null) return; Color color = (isHighlighted) ? Color.Orange : Color.Green; - if (isSelected) color = Color.Red; + if (IsSelected) color = Color.Red; Vector2 pos = Position; diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index 5cc7560ae..69f2475b5 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -8,6 +8,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using System.Collections.ObjectModel; +using Barotrauma.Items.Components; namespace Barotrauma { @@ -16,7 +17,7 @@ namespace Barotrauma public static List mapEntityList = new List(); //which entities have been selected for editing - public static List selectedList = new List(); + private static List selectedList = new List(); private static List copiedList = new List(); protected static GUIComponent editingHUD; @@ -39,7 +40,7 @@ namespace Barotrauma //is the mouse inside the rect protected bool isHighlighted; - protected bool isSelected; + //protected bool isSelected; private static bool disableSelect; public static bool DisableSelect @@ -175,8 +176,7 @@ namespace Barotrauma public bool IsSelected { - get { return isSelected; } - set { isSelected = value; } + get { return selectedList.Contains(this); } } protected bool ResizeHorizontal @@ -219,7 +219,43 @@ namespace Barotrauma List clones = new List(); foreach (MapEntity e in entitiesToClone) { + Debug.Assert(e != null); clones.Add(e.Clone()); + Debug.Assert(clones.Last() != null); + } + + Debug.Assert(clones.Count == entitiesToClone.Count); + + //connect clone wires to the clone items + for (int i = 0; i < clones.Count; i++) + { + var cloneItem = clones[i] as Item; + if (cloneItem == null) continue; + + var cloneWire = cloneItem.GetComponent(); + if (cloneWire == null) continue; + + var originalWire = ((Item)entitiesToClone[i]).GetComponent(); + + cloneWire.Nodes = new List(originalWire.Nodes); + cloneWire.UpdateSections(); + + for (int n = 0; n < 2; n++) + { + if (originalWire.Connections[n] == null) continue; + + var connectedItem = originalWire.Connections[n].Item; + if (connectedItem == null) continue; + + //index of the item the wire is connected to + int itemIndex = entitiesToClone.IndexOf(connectedItem); + //index of the connection in the connectionpanel of the target item + int connectionIndex = connectedItem.Connections.IndexOf(originalWire.Connections[n]); + + (clones[itemIndex] as Item).GetComponent().Connections[connectionIndex].TryAddLink(cloneWire); + cloneWire.Connect((clones[itemIndex] as Item).Connections[connectionIndex], false); + + } } return clones; @@ -311,7 +347,6 @@ namespace Barotrauma foreach (MapEntity e in mapEntityList) { e.isHighlighted = false; - e.isSelected = false; } if (DisableSelect) @@ -359,9 +394,8 @@ namespace Barotrauma clones.ForEach(c => center += c.WorldPosition); center /= clones.Count; - clones.ForEach(c => c.Move(cam.WorldViewCenter - center)); - selectedList = new List(clones); + selectedList.ForEach(c => c.Move(cam.WorldViewCenter - center)); } } @@ -380,18 +414,12 @@ namespace Barotrauma { if (e.IsMouseOn(position)) highLightedEntity = e; } - e.isSelected = false; } if (highLightedEntity != null) highLightedEntity.isHighlighted = true; } - - foreach (MapEntity e in selectedList) - { - e.isSelected = true; - } - + //started moving selected entities if (startMovingPos != Vector2.Zero && PlayerInput.LeftButtonReleased()) { @@ -406,9 +434,8 @@ namespace Barotrauma if (PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl)) { var clones = Clone(selectedList); - clones.ForEach(c => c.Move(moveAmount)); - selectedList = clones; + selectedList.ForEach(c => c.Move(moveAmount)); } else // move { @@ -463,6 +490,25 @@ namespace Barotrauma { selectedList = newSelection; } + + //select wire if both items it's connected to are selected + var selectedItems = selectedList.Where(e => e is Item).Cast().ToList(); + foreach (Item item in selectedItems) + { + if (item.Connections == null) continue; + foreach (Connection c in item.Connections) + { + foreach (Wire w in c.Wires) + { + if (w == null || selectedList.Contains(w.Item)) continue; + + if (w.OtherConnection(c) != null && selectedList.Contains(w.OtherConnection(c).Item)) + { + selectedList.Add(w.Item); + } + } + } + } selectionPos = Vector2.Zero; selectionSize = Vector2.Zero; @@ -471,7 +517,6 @@ namespace Barotrauma //default, not doing anything specific yet else { - if (PlayerInput.LeftButtonHeld() && PlayerInput.KeyUp(Keys.Space)) { @@ -483,12 +528,10 @@ namespace Barotrauma selectionPos = position; } - - - } - + } } + /// /// Draw the "selection rectangle" and outlines of entities that are being dragged (if any) /// @@ -565,10 +608,6 @@ namespace Barotrauma public static void DeselectAll() { - foreach (MapEntity e in selectedList) - { - e.isSelected = false; - } selectedList.Clear(); } @@ -577,7 +616,6 @@ namespace Barotrauma { DeselectAll(); - entity.isSelected = true; selectedList.Add(entity); } diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index a9fbc4022..966bff8c9 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -495,7 +495,7 @@ namespace Barotrauma if (prefab.sprite == null) return; Color color = (isHighlighted) ? Color.Orange : Color.White; - if (isSelected && editing) + if (IsSelected && editing) { color = Color.Red; diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index bf2ba494f..28018729f 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -1080,13 +1080,7 @@ namespace Barotrauma if (item.Submarine != this) continue; var wire = item.GetComponent(); - if (wire == null) continue; - - for (int i = 0; i < wire.Nodes.Count; i++) - { - wire.Nodes[i] -= center; - } - wire.UpdateSections(); + if (wire != null) wire.MoveNodes(-center); } for (int i = 0; i < MapEntity.mapEntityList.Count; i++) diff --git a/Subsurface/Source/Map/WayPoint.cs b/Subsurface/Source/Map/WayPoint.cs index 665ecf948..38da4ef63 100644 --- a/Subsurface/Source/Map/WayPoint.cs +++ b/Subsurface/Source/Map/WayPoint.cs @@ -144,7 +144,7 @@ namespace Barotrauma drawPos.Y = -drawPos.Y; Color clr = currentHull == null ? Color.Blue : Color.White; - if (isSelected) clr = Color.Red; + if (IsSelected) clr = Color.Red; if (isHighlighted) clr = Color.DarkRed; int iconX = iconIndices[(int)spawnType]*IconSize % iconTexture.Width; diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs index 45e6f5229..9d5544727 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -602,7 +602,6 @@ namespace Barotrauma foreach (MapEntity me in MapEntity.mapEntityList) { me.IsHighlighted = false; - me.IsSelected = false; } return true;