From 5699ecc01c310ec2a22ee116ffc89dd8c08cbc3e Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 6 Apr 2022 23:21:47 -0400 Subject: [PATCH] Better diagonal placement system for nodes --- core/assets/bundles/bundle.properties | 2 +- core/src/mindustry/input/InputHandler.java | 4 ++-- core/src/mindustry/world/Block.java | 7 +++++++ core/src/mindustry/world/blocks/power/BeamNode.java | 7 +++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index fd0a9460f0..0d9df4f24b 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -617,7 +617,7 @@ sectors.rename = Rename Sector sectors.enemybase = [scarlet]Enemy Base sectors.vulnerable = [scarlet]Vulnerable sectors.underattack = [scarlet]Under attack! [accent]{0}% damaged -sectors.underattack.nodamage = [scarlet]Enemy Present +sectors.underattack.nodamage = [scarlet]Uncaptured sectors.survives = [accent]Survives {0} waves sectors.go = Go sector.curcapture = Sector Captured diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index c121ad4cf4..6cc5bc95d5 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -1475,7 +1475,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ int endRotation = -1; var start = world.build(startX, startY); var end = world.build(endX, endY); - if(diagonal){ + if(diagonal && (block == null || block.allowDiagonal)){ if(block != null && start instanceof ChainedBuilding && end instanceof ChainedBuilding && block.canReplace(end.block) && block.canReplace(start.block)){ points = Placement.upgradeLine(startX, startY, endX, endY); @@ -1493,7 +1493,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ } if(block != null){ - block.changePlacementPath(points, rotation); + block.changePlacementPath(points, rotation, diagonal); } float angle = Angles.angle(startX, startY, endX, endY); diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 465950c38f..3536b83e81 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -201,6 +201,8 @@ public class Block extends UnlockableContent implements Senseable{ public boolean sync; /** Whether this block uses conveyor-type placement mode. */ public boolean conveyorPlacement; + /** If false, diagonal placement (ctrl) for this block is not allowed. */ + public boolean allowDiagonal = true; /** Whether to swap the diagonal placement modes. */ public boolean swapDiagonalPlacement; /** Build queue priority in schematics. */ @@ -610,6 +612,11 @@ public class Block extends UnlockableContent implements Senseable{ return this; } + /** Mutates the given list of points used during line placement. */ + public void changePlacementPath(Seq points, int rotation, boolean diagonalOn){ + changePlacementPath(points, rotation); + } + /** Mutates the given list of points used during line placement. */ public void changePlacementPath(Seq points, int rotation){ diff --git a/core/src/mindustry/world/blocks/power/BeamNode.java b/core/src/mindustry/world/blocks/power/BeamNode.java index 0cda217dd2..8afaa13623 100644 --- a/core/src/mindustry/world/blocks/power/BeamNode.java +++ b/core/src/mindustry/world/blocks/power/BeamNode.java @@ -34,6 +34,7 @@ public class BeamNode extends PowerBlock{ consumesPower = outputsPower = false; drawDisabled = false; envEnabled |= Env.space; + allowDiagonal = false; } @Override @@ -82,8 +83,10 @@ public class BeamNode extends PowerBlock{ } @Override - public void changePlacementPath(Seq points, int rotation){ - Placement.calculateNodes(points, this, rotation, (point, other) -> Math.max(Math.abs(point.x - other.x), Math.abs(point.y - other.y)) <= range); + public void changePlacementPath(Seq points, int rotation, boolean diagonal){ + if(!diagonal){ + Placement.calculateNodes(points, this, rotation, (point, other) -> Math.max(Math.abs(point.x - other.x), Math.abs(point.y - other.y)) <= range); + } } public class BeamNodeBuild extends Building{