Items/structures can be copied by holding ctrl in the editor
This commit is contained in:
@@ -413,6 +413,28 @@ namespace Barotrauma
|
|||||||
ItemList.Add(this);
|
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>()
|
public T GetComponent<T>()
|
||||||
{
|
{
|
||||||
foreach (ItemComponent ic in components)
|
foreach (ItemComponent ic in components)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ using System.Collections.ObjectModel;
|
|||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
class MapEntity : Entity
|
abstract class MapEntity : Entity
|
||||||
{
|
{
|
||||||
public static List<MapEntity> mapEntityList = new List<MapEntity>();
|
public static List<MapEntity> mapEntityList = new List<MapEntity>();
|
||||||
|
|
||||||
@@ -149,7 +149,11 @@ namespace Barotrauma
|
|||||||
if (aiTarget == null) return 0.0f;
|
if (aiTarget == null) return 0.0f;
|
||||||
return aiTarget.SoundRange;
|
return aiTarget.SoundRange;
|
||||||
}
|
}
|
||||||
set { aiTarget.SoundRange = value; }
|
set
|
||||||
|
{
|
||||||
|
if (aiTarget == null) return;
|
||||||
|
aiTarget.SoundRange = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public float SightRange
|
public float SightRange
|
||||||
@@ -203,6 +207,22 @@ namespace Barotrauma
|
|||||||
return (Submarine.RectContains(WorldRect, position));
|
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()
|
protected void InsertToList()
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -341,22 +361,30 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
//started moving selected entities
|
//started moving selected entities
|
||||||
if (startMovingPos != Vector2.Zero)
|
if (startMovingPos != Vector2.Zero && PlayerInput.LeftButtonReleased())
|
||||||
{
|
{
|
||||||
if (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;
|
selectedList = clones;
|
||||||
moveAmount = Submarine.VectorToWorldGrid(moveAmount);
|
}
|
||||||
|
else // move
|
||||||
if (moveAmount != Vector2.Zero)
|
|
||||||
{
|
{
|
||||||
foreach (MapEntity e in selectedList) e.Move(moveAmount);
|
foreach (MapEntity e in selectedList) e.Move(moveAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
startMovingPos = Vector2.Zero;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startMovingPos = Vector2.Zero;
|
||||||
}
|
}
|
||||||
//started dragging a "selection rectangle"
|
//started dragging a "selection rectangle"
|
||||||
else if (selectionPos != Vector2.Zero)
|
else if (selectionPos != Vector2.Zero)
|
||||||
|
|||||||
@@ -256,7 +256,6 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (prefab.CastShadow)
|
if (prefab.CastShadow)
|
||||||
{
|
{
|
||||||
GenerateConvexHull();
|
GenerateConvexHull();
|
||||||
@@ -265,6 +264,11 @@ namespace Barotrauma
|
|||||||
InsertToList();
|
InsertToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override MapEntity Clone()
|
||||||
|
{
|
||||||
|
return new Structure(rect, prefab, Submarine);
|
||||||
|
}
|
||||||
|
|
||||||
private void CreateStairBodies()
|
private void CreateStairBodies()
|
||||||
{
|
{
|
||||||
bodies = new List<Body>();
|
bodies = new List<Body>();
|
||||||
|
|||||||
@@ -816,13 +816,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (GUIComponent.MouseOn == null)
|
if (GUIComponent.MouseOn == null)
|
||||||
{
|
{
|
||||||
//if (nameBox.Selected && PlayerInput.LeftButtonClicked())
|
|
||||||
//{
|
|
||||||
// ChangeSubName(nameBox, nameBox.Text);
|
|
||||||
//}
|
|
||||||
|
|
||||||
cam.MoveCamera((float)deltaTime);
|
cam.MoveCamera((float)deltaTime);
|
||||||
//cam.Zoom = MathHelper.Clamp(cam.Zoom + (PlayerInput.ScrollWheelSpeed / 1000.0f)*cam.Zoom, 0.1f, 2.0f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (characterMode || wiringMode)
|
if (characterMode || wiringMode)
|
||||||
@@ -854,7 +848,6 @@ namespace Barotrauma
|
|||||||
dummyCharacter.Submarine = Submarine.MainSub;
|
dummyCharacter.Submarine = Submarine.MainSub;
|
||||||
|
|
||||||
cam.TargetPos = Vector2.Zero;
|
cam.TargetPos = Vector2.Zero;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -907,9 +900,10 @@ namespace Barotrauma
|
|||||||
foreach (Item item in dummyCharacter.SelectedItems)
|
foreach (Item item in dummyCharacter.SelectedItems)
|
||||||
{
|
{
|
||||||
if (item == null) continue;
|
if (item == null) continue;
|
||||||
item.SetTransform(dummyCharacter.SimPosition, 0.0f);
|
|
||||||
|
|
||||||
|
item.SetTransform(dummyCharacter.SimPosition, 0.0f);
|
||||||
item.Update(cam, (float)deltaTime);
|
item.Update(cam, (float)deltaTime);
|
||||||
|
item.SetTransform(item.body.SimPosition, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dummyCharacter.SelectedConstruction != null)
|
if (dummyCharacter.SelectedConstruction != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user