diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 75a051450..9e226240f 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -413,6 +413,28 @@ namespace Barotrauma ItemList.Add(this); } + public override MapEntity Clone() + { + Item clone = new Item(rect, prefab, Submarine); + + foreach (KeyValuePair property in properties) + { + if (!property.Value.Attributes.OfType().Any()) continue; + clone.properties[property.Key].TrySetValue(property.Value.GetValue()); + } + + if (ContainedItems!=null) + { + foreach (Item containedItem in ContainedItems) + { + var containedClone = containedItem.Clone(); + clone.ownInventory.TryPutItem(containedItem); + } + } + + return clone; + } + public T GetComponent() { foreach (ItemComponent ic in components) diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index 4a614542e..789581e0b 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -10,7 +10,7 @@ using System.Collections.ObjectModel; namespace Barotrauma { - class MapEntity : Entity + abstract class MapEntity : Entity { public static List mapEntityList = new List(); @@ -149,7 +149,11 @@ namespace Barotrauma if (aiTarget == null) return 0.0f; return aiTarget.SoundRange; } - set { aiTarget.SoundRange = value; } + set + { + if (aiTarget == null) return; + aiTarget.SoundRange = value; + } } public float SightRange @@ -202,6 +206,22 @@ namespace Barotrauma { return (Submarine.RectContains(WorldRect, position)); } + + public virtual MapEntity Clone() + { + return null; + } + + public static List Clone(List entitiesToClone) + { + List clones = new List(); + foreach (MapEntity e in entitiesToClone) + { + clones.Add(e.Clone()); + } + + return clones; + } protected void InsertToList() { @@ -341,22 +361,30 @@ namespace Barotrauma } //started moving selected entities - if (startMovingPos != Vector2.Zero) - { - if (PlayerInput.LeftButtonReleased()) + if (startMovingPos != Vector2.Zero && PlayerInput.LeftButtonReleased()) + { + //mouse released -> move the entities to the new position of the mouse + + Vector2 moveAmount = position - startMovingPos; + moveAmount = Submarine.VectorToWorldGrid(moveAmount); + + if (moveAmount != Vector2.Zero) { - //mouse released -> move the entities to the new position of the mouse + //clone + if (PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl)) + { + var clones = Clone(selectedList); + clones.ForEach(c => c.Move(moveAmount)); - Vector2 moveAmount = position - startMovingPos; - moveAmount = Submarine.VectorToWorldGrid(moveAmount); - - if (moveAmount != Vector2.Zero) + selectedList = clones; + } + else // move { foreach (MapEntity e in selectedList) e.Move(moveAmount); } - - startMovingPos = Vector2.Zero; } + + startMovingPos = Vector2.Zero; } //started dragging a "selection rectangle" else if (selectionPos != Vector2.Zero) diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index 12710e677..a9fbc4022 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -256,7 +256,6 @@ namespace Barotrauma } } - if (prefab.CastShadow) { GenerateConvexHull(); @@ -265,6 +264,11 @@ namespace Barotrauma InsertToList(); } + public override MapEntity Clone() + { + return new Structure(rect, prefab, Submarine); + } + private void CreateStairBodies() { bodies = new List(); diff --git a/Subsurface/Source/Screens/EditMapScreen.cs b/Subsurface/Source/Screens/EditMapScreen.cs index 0d5bcd885..f8e2e9e8a 100644 --- a/Subsurface/Source/Screens/EditMapScreen.cs +++ b/Subsurface/Source/Screens/EditMapScreen.cs @@ -816,13 +816,7 @@ namespace Barotrauma if (GUIComponent.MouseOn == null) { - //if (nameBox.Selected && PlayerInput.LeftButtonClicked()) - //{ - // ChangeSubName(nameBox, nameBox.Text); - //} - cam.MoveCamera((float)deltaTime); - //cam.Zoom = MathHelper.Clamp(cam.Zoom + (PlayerInput.ScrollWheelSpeed / 1000.0f)*cam.Zoom, 0.1f, 2.0f); } if (characterMode || wiringMode) @@ -854,7 +848,6 @@ namespace Barotrauma dummyCharacter.Submarine = Submarine.MainSub; cam.TargetPos = Vector2.Zero; - } } else @@ -869,7 +862,7 @@ namespace Barotrauma { if (MapEntityPrefab.Selected != null) MapEntityPrefab.Selected.UpdatePlacing(cam); - MapEntity.UpdateEditor(cam); + MapEntity.UpdateEditor(cam); } leftPanel.Update((float)deltaTime); @@ -907,9 +900,10 @@ namespace Barotrauma foreach (Item item in dummyCharacter.SelectedItems) { if (item == null) continue; - item.SetTransform(dummyCharacter.SimPosition, 0.0f); + item.SetTransform(dummyCharacter.SimPosition, 0.0f); item.Update(cam, (float)deltaTime); + item.SetTransform(item.body.SimPosition, 0.0f); } if (dummyCharacter.SelectedConstruction != null)