[Code included] Nudging selected items in the submarine editor by individual pixels

#1
Previously posted this on the discord channel, though it missed the latest update, so might as well post it here.

Code: Select all

Vector2 nudgeVector = Vector2.Zero;
if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.Up) && PlayerInput.GetOldKeyboardState.IsKeyUp(Keys.Up)){
    nudgeVector.Y = 1f;
}
if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.Down) && PlayerInput.GetOldKeyboardState.IsKeyUp(Keys.Down)){
    nudgeVector.Y = -1f;
}
if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.Left) && PlayerInput.GetOldKeyboardState.IsKeyUp(Keys.Left)){
    nudgeVector.X = -1f;
}
if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.Right) && PlayerInput.GetOldKeyboardState.IsKeyUp(Keys.Right)){
    nudgeVector.X = 1f;
}
if (nudgeVector != Vector2.Zero && MapEntity.selectedList.Count > 0){
    foreach (MapEntity entityToNudge in MapEntity.selectedList){
        entityToNudge.Move(nudgeVector);
    }
}
Adding this code to Barotrauma.MapEntity:UpdateSelecting should allow parts to be moved by a single pixel at a time by using the arrow keys.