(22e7598d9) Ignore keyboard inputs (delete, arrow keys, copy/paste) in the sub editor when a textbox is selected. Closes #1641
This commit is contained in:
@@ -132,96 +132,97 @@ namespace Barotrauma
|
|||||||
selectedList.Clear();
|
selectedList.Clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (GUI.KeyboardDispatcher.Subscriber == null)
|
||||||
if (PlayerInput.KeyDown(Keys.Delete))
|
|
||||||
{
|
{
|
||||||
selectedList.ForEach(e => e.Remove());
|
if (PlayerInput.KeyDown(Keys.Delete))
|
||||||
selectedList.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl))
|
|
||||||
{
|
|
||||||
if (PlayerInput.KeyHit(Keys.C))
|
|
||||||
{
|
{
|
||||||
CopyEntities(selectedList);
|
|
||||||
}
|
|
||||||
else if (PlayerInput.KeyHit(Keys.X))
|
|
||||||
{
|
|
||||||
CopyEntities(selectedList);
|
|
||||||
|
|
||||||
selectedList.ForEach(e => e.Remove());
|
selectedList.ForEach(e => e.Remove());
|
||||||
selectedList.Clear();
|
selectedList.Clear();
|
||||||
}
|
}
|
||||||
else if (copiedList.Count > 0 && PlayerInput.KeyHit(Keys.V))
|
|
||||||
|
if (PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl))
|
||||||
{
|
{
|
||||||
List<MapEntity> prevEntities = new List<MapEntity>(mapEntityList);
|
if (PlayerInput.KeyHit(Keys.C))
|
||||||
Clone(copiedList);
|
|
||||||
|
|
||||||
var clones = mapEntityList.Except(prevEntities).ToList();
|
|
||||||
|
|
||||||
Vector2 center = Vector2.Zero;
|
|
||||||
clones.ForEach(c => center += c.WorldPosition);
|
|
||||||
center = Submarine.VectorToWorldGrid(center / clones.Count);
|
|
||||||
|
|
||||||
Vector2 moveAmount = Submarine.VectorToWorldGrid(cam.WorldViewCenter - center);
|
|
||||||
|
|
||||||
selectedList = new List<MapEntity>(clones);
|
|
||||||
foreach (MapEntity clone in selectedList)
|
|
||||||
{
|
{
|
||||||
clone.Move(moveAmount);
|
CopyEntities(selectedList);
|
||||||
clone.Submarine = Submarine.MainSub;
|
|
||||||
}
|
}
|
||||||
}
|
else if (PlayerInput.KeyHit(Keys.X))
|
||||||
else if (PlayerInput.KeyHit(Keys.G))
|
|
||||||
{
|
|
||||||
if (selectedList.Any())
|
|
||||||
{
|
{
|
||||||
if (SelectionGroups.ContainsKey(selectedList.Last()))
|
CopyEntities(selectedList);
|
||||||
|
|
||||||
|
selectedList.ForEach(e => e.Remove());
|
||||||
|
selectedList.Clear();
|
||||||
|
}
|
||||||
|
else if (copiedList.Count > 0 && PlayerInput.KeyHit(Keys.V))
|
||||||
|
{
|
||||||
|
List<MapEntity> prevEntities = new List<MapEntity>(mapEntityList);
|
||||||
|
Clone(copiedList);
|
||||||
|
|
||||||
|
var clones = mapEntityList.Except(prevEntities).ToList();
|
||||||
|
|
||||||
|
Vector2 center = Vector2.Zero;
|
||||||
|
clones.ForEach(c => center += c.WorldPosition);
|
||||||
|
center = Submarine.VectorToWorldGrid(center / clones.Count);
|
||||||
|
|
||||||
|
Vector2 moveAmount = Submarine.VectorToWorldGrid(cam.WorldViewCenter - center);
|
||||||
|
|
||||||
|
selectedList = new List<MapEntity>(clones);
|
||||||
|
foreach (MapEntity clone in selectedList)
|
||||||
{
|
{
|
||||||
// Ungroup all selected
|
clone.Move(moveAmount);
|
||||||
selectedList.ForEach(e => SelectionGroups.Remove(e));
|
clone.Submarine = Submarine.MainSub;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
else if (PlayerInput.KeyHit(Keys.G))
|
||||||
|
{
|
||||||
|
if (selectedList.Any())
|
||||||
{
|
{
|
||||||
foreach (var entity in selectedList)
|
if (SelectionGroups.ContainsKey(selectedList.Last()))
|
||||||
{
|
{
|
||||||
// Remove the old group, if any
|
// Ungroup all selected
|
||||||
SelectionGroups.Remove(entity);
|
selectedList.ForEach(e => SelectionGroups.Remove(e));
|
||||||
// Create a group that can be accessed with any member
|
}
|
||||||
SelectionGroups.Add(entity, selectedList);
|
else
|
||||||
|
{
|
||||||
|
foreach (var entity in selectedList)
|
||||||
|
{
|
||||||
|
// Remove the old group, if any
|
||||||
|
SelectionGroups.Remove(entity);
|
||||||
|
// Create a group that can be accessed with any member
|
||||||
|
SelectionGroups.Add(entity, selectedList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (PlayerInput.KeyHit(Keys.Z))
|
||||||
|
{
|
||||||
|
SetPreviousRects(e => e.rectMemento.Undo());
|
||||||
|
}
|
||||||
|
else if (PlayerInput.KeyHit(Keys.R))
|
||||||
|
{
|
||||||
|
SetPreviousRects(e => e.rectMemento.Redo());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetPreviousRects(Func<MapEntity, Rectangle> memoryMethod)
|
||||||
|
{
|
||||||
|
foreach (var e in SelectedList)
|
||||||
|
{
|
||||||
|
if (e.rectMemento != null)
|
||||||
|
{
|
||||||
|
Point diff = memoryMethod(e).Location - e.Rect.Location;
|
||||||
|
// We have to call the move method, because there's a lot more than just storing the rect (in some cases)
|
||||||
|
// We also have to reassign the rect, because the move method does not set the width and height. They might have changed too.
|
||||||
|
// The Rect property is virtual and it's overridden for structs. Setting the rect via the property should automatically recreate the sections for resizable structures.
|
||||||
|
e.Move(diff.ToVector2());
|
||||||
|
e.Rect = e.rectMemento.Current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (PlayerInput.KeyHit(Keys.Z))
|
}
|
||||||
{
|
|
||||||
SetPreviousRects(e => e.rectMemento.Undo());
|
|
||||||
}
|
|
||||||
else if (PlayerInput.KeyHit(Keys.R))
|
|
||||||
{
|
|
||||||
SetPreviousRects(e => e.rectMemento.Redo());
|
|
||||||
}
|
|
||||||
void SetPreviousRects(Func<MapEntity, Rectangle> memoryMethod)
|
|
||||||
{
|
|
||||||
foreach (var e in SelectedList)
|
|
||||||
{
|
|
||||||
if (e.rectMemento != null)
|
|
||||||
{
|
|
||||||
Point diff = memoryMethod(e).Location - e.Rect.Location;
|
|
||||||
// We have to call the move method, because there's a lot more than just storing the rect (in some cases)
|
|
||||||
// We also have to reassign the rect, because the move method does not set the width and height. They might have changed too.
|
|
||||||
// The Rect property is virtual and it's overridden for structs. Setting the rect via the property should automatically recreate the sections for resizable structures.
|
|
||||||
e.Move(diff.ToVector2());
|
|
||||||
e.Rect = e.rectMemento.Current;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);
|
Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||||
|
|
||||||
MapEntity highLightedEntity = null;
|
MapEntity highLightedEntity = null;
|
||||||
|
|
||||||
if (startMovingPos == Vector2.Zero)
|
if (startMovingPos == Vector2.Zero)
|
||||||
{
|
{
|
||||||
List<MapEntity> highlightedEntities = new List<MapEntity>();
|
List<MapEntity> highlightedEntities = new List<MapEntity>();
|
||||||
@@ -282,16 +283,19 @@ namespace Barotrauma
|
|||||||
if (highLightedEntity != null) highLightedEntity.isHighlighted = true;
|
if (highLightedEntity != null) highLightedEntity.isHighlighted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 nudgeAmount = Vector2.Zero;
|
if (GUI.KeyboardDispatcher.Subscriber == null)
|
||||||
if (PlayerInput.KeyHit(Keys.Up)) nudgeAmount.Y = 1f;
|
|
||||||
if (PlayerInput.KeyHit(Keys.Down)) nudgeAmount.Y = -1f;
|
|
||||||
if (PlayerInput.KeyHit(Keys.Left)) nudgeAmount.X = -1f;
|
|
||||||
if (PlayerInput.KeyHit(Keys.Right)) nudgeAmount.X = 1f;
|
|
||||||
if (nudgeAmount != Vector2.Zero)
|
|
||||||
{
|
{
|
||||||
foreach (MapEntity entityToNudge in selectedList)
|
Vector2 nudgeAmount = Vector2.Zero;
|
||||||
|
if (PlayerInput.KeyHit(Keys.Up)) nudgeAmount.Y = 1f;
|
||||||
|
if (PlayerInput.KeyHit(Keys.Down)) nudgeAmount.Y = -1f;
|
||||||
|
if (PlayerInput.KeyHit(Keys.Left)) nudgeAmount.X = -1f;
|
||||||
|
if (PlayerInput.KeyHit(Keys.Right)) nudgeAmount.X = 1f;
|
||||||
|
if (nudgeAmount != Vector2.Zero)
|
||||||
{
|
{
|
||||||
entityToNudge.Move(nudgeAmount);
|
foreach (MapEntity entityToNudge in selectedList)
|
||||||
|
{
|
||||||
|
entityToNudge.Move(nudgeAmount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user