Items/structures can be copied by holding ctrl in the editor

This commit is contained in:
Regalis
2016-11-11 17:37:03 +02:00
parent 96cedd67f1
commit e6b2919877
4 changed files with 70 additions and 22 deletions
+22
View File
@@ -413,6 +413,28 @@ namespace Barotrauma
ItemList.Add(this);
}
public override MapEntity Clone()
{
Item clone = new Item(rect, prefab, Submarine);
foreach (KeyValuePair<string, ObjectProperty> property in properties)
{
if (!property.Value.Attributes.OfType<Editable>().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<T>()
{
foreach (ItemComponent ic in components)
+40 -12
View File
@@ -10,7 +10,7 @@ using System.Collections.ObjectModel;
namespace Barotrauma
{
class MapEntity : Entity
abstract class MapEntity : Entity
{
public static List<MapEntity> mapEntityList = new List<MapEntity>();
@@ -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<MapEntity> Clone(List<MapEntity> entitiesToClone)
{
List<MapEntity> clones = new List<MapEntity>();
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)
+5 -1
View File
@@ -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<Body>();
+3 -9
View File
@@ -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)