From 7f299869c5da45fb18f1dac7f16408eabad8117a Mon Sep 17 00:00:00 2001 From: Synray <31429825+Synray@users.noreply.github.com> Date: Sat, 21 Sep 2019 15:03:05 -0700 Subject: [PATCH] Add ability to rotate each block in a line (#688) * Add ability to rotate each block in a line * New behavior only when placing straight lines * Code style --- core/src/io/anuke/mindustry/input/DesktopInput.java | 9 +++++++++ core/src/io/anuke/mindustry/input/InputHandler.java | 12 ++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/src/io/anuke/mindustry/input/DesktopInput.java b/core/src/io/anuke/mindustry/input/DesktopInput.java index ca2925ab62..acef76ac47 100644 --- a/core/src/io/anuke/mindustry/input/DesktopInput.java +++ b/core/src/io/anuke/mindustry/input/DesktopInput.java @@ -236,6 +236,15 @@ public class DesktopInput extends InputHandler{ selectY = tileY(Core.input.mouseY()); } + if (mode == placing && block != null){ + if (!overrideLineRotation && !Core.input.keyDown(Binding.diagonal_placement) && (selectX != cursorX || selectY != cursorY) && ((int) Core.input.axisTap(Binding.rotate) != 0)){ + rotation = ((int)((Angles.angle(selectX, selectY, cursorX, cursorY) + 45) / 90f)) % 4; + overrideLineRotation = true; + } + }else{ + overrideLineRotation = false; + } + if(Core.input.keyRelease(Binding.break_block) || Core.input.keyRelease(Binding.select)){ if(mode == placing && block != null){ //touch up while placing, place everything in selection diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index d33292af45..c976eb7570 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -38,6 +38,7 @@ public abstract class InputHandler implements InputProcessor{ public final OverlayFragment frag = new OverlayFragment(); public Block block; + public boolean overrideLineRotation; public int rotation; public boolean droppingItem; @@ -380,7 +381,10 @@ public abstract class InputHandler implements InputProcessor{ } float angle = Angles.angle(startX, startY, endX, endY); - int baseRotation = (startX == endX && startY == endY) ? rotation : ((int)((angle + 45) / 90f)) % 4; + int baseRotation = rotation; + if (!overrideLineRotation || diagonal){ + baseRotation = (startX == endX && startY == endY) ? rotation : ((int)((angle + 45) / 90f)) % 4; + } Tmp.r3.set(-1, -1, 0, 0); @@ -394,7 +398,11 @@ public abstract class InputHandler implements InputProcessor{ Point2 next = i == points.size - 1 ? null : points.get(i + 1); line.x = point.x; line.y = point.y; - line.rotation = next != null ? Tile.relativeTo(point.x, point.y, next.x, next.y) : baseRotation; + if (!overrideLineRotation || diagonal){ + line.rotation = next != null ? Tile.relativeTo(point.x, point.y, next.x, next.y) : baseRotation; + }else{ + line.rotation = rotation; + } line.last = next == null; cons.accept(line);