From 0aa4b7a93de422f6d5a9275d2b15a4014ec2c774 Mon Sep 17 00:00:00 2001 From: Regalis Date: Fri, 11 Nov 2016 17:58:14 +0200 Subject: [PATCH] Copy, paste & cut functionality in the editor --- Subsurface/Source/Map/MapEntity.cs | 34 +++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index 789581e0b..3f64cedad 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Xml.Linq; using FarseerPhysics; using Microsoft.Xna.Framework; @@ -16,6 +17,7 @@ namespace Barotrauma //which entities have been selected for editing public static List selectedList = new List(); + private static List copiedList = new List(); protected static GUIComponent editingHUD; @@ -329,10 +331,40 @@ namespace Barotrauma if (PlayerInput.KeyDown(Keys.Delete)) { - foreach (MapEntity e in selectedList) e.Remove(); + selectedList.ForEach(e => e.Remove()); selectedList.Clear(); } + if (PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl)) + { + if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.C) && + PlayerInput.GetOldKeyboardState.IsKeyUp(Keys.C)) + { + copiedList = new List(selectedList); + } + else if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.X) && + PlayerInput.GetOldKeyboardState.IsKeyUp(Keys.X)) + { + copiedList = new List(selectedList); + selectedList.ForEach(e => e.Remove()); + selectedList.Clear(); + } + else if (copiedList.Count > 0 && + PlayerInput.GetKeyboardState.IsKeyDown(Keys.V) && + PlayerInput.GetOldKeyboardState.IsKeyUp(Keys.V)) + { + var clones = Clone(copiedList); + + Vector2 center = Vector2.Zero; + clones.ForEach(c => center += c.WorldPosition); + center /= clones.Count; + + clones.ForEach(c => c.Move(cam.WorldViewCenter - center)); + + selectedList = new List(clones); + } + } + Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition); MapEntity highLightedEntity = null;