From a81f90d1403b83a7e390834ec0a107156f784ac5 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 14 Dec 2017 01:17:10 -0500 Subject: [PATCH] Implement slightly better multi-place --- core/src/io/anuke/mindustry/input/Input.java | 5 -- .../io/anuke/mindustry/input/PlaceMode.java | 65 ++++++++++++++++++- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/core/src/io/anuke/mindustry/input/Input.java b/core/src/io/anuke/mindustry/input/Input.java index 3f1eb2e6ae..0f60475bc1 100644 --- a/core/src/io/anuke/mindustry/input/Input.java +++ b/core/src/io/anuke/mindustry/input/Input.java @@ -5,7 +5,6 @@ import static io.anuke.mindustry.Vars.*; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Buttons; import com.badlogic.gdx.Input.Keys; -import com.badlogic.gdx.math.Vector2; import io.anuke.mindustry.Vars; import io.anuke.mindustry.core.GameState; @@ -126,10 +125,6 @@ public class Input extends InputHandler{ } } } - - public boolean cursorNear(){ - return Vector2.dst(player.x, player.y, tilex() * tilesize, tiley() * tilesize) <= placerange; - } public int tilex(){ return (player.recipe != null && player.recipe.result.isMultiblock() && diff --git a/core/src/io/anuke/mindustry/input/PlaceMode.java b/core/src/io/anuke/mindustry/input/PlaceMode.java index 798eab6705..bf1731855f 100644 --- a/core/src/io/anuke/mindustry/input/PlaceMode.java +++ b/core/src/io/anuke/mindustry/input/PlaceMode.java @@ -13,6 +13,7 @@ import io.anuke.ucore.core.Draw; import io.anuke.ucore.core.Inputs; import io.anuke.ucore.core.Timers; import io.anuke.ucore.scene.utils.Cursors; +import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Tmp; public enum PlaceMode{ @@ -47,17 +48,44 @@ public enum PlaceMode{ } }, touch{ + int maxlen = 10; { lockCamera = true; } public void draw(int tilex, int tiley, int endx, int endy){ + int maxlen = this.maxlen * Vars.tilesize; float t = Vars.tilesize; float x = tilex * t, y = tiley * t, x2 = endx * t, y2 = endy * t; + if(Math.abs(x - x2) > Math.abs(y2 - y)){ + y2 = y; + }else{ + x2 = x; + } + + if(Math.abs(x2 - x) > maxlen){ + x2 = Mathf.sign(x2 - x) * maxlen + x; + } + + if(Math.abs(y2 - y) > maxlen){ + y2 = Mathf.sign(y2 - y) * maxlen + y; + } + + int rotation = 0; + + if(x2 > x) + rotation = 0; + if(x2 < x) + rotation = 2; + if(y2 > y) + rotation = 1; + if(y2 < y) + rotation = 3; + if(x2 < x){ float d = x; x = x2; @@ -83,15 +111,48 @@ public enum PlaceMode{ if(tilex == endx && tiley == endy){ cursor.draw(tilex, tiley, endx, endy); }else{ - Draw.color(Color.GREEN); + Draw.thick(2f); + Draw.color(control.getInput().cursorNear() ? Color.PURPLE : Color.RED); Draw.linerect(x, y, x2 - x, y2 - y); Draw.alpha(0.3f); Draw.crect("blank", x, y, x2 - x, y2 - y); + + if(player.recipe.result.rotate){ + float cx = tilex * t, cy = tiley * t; + Draw.color(Color.ORANGE); + Tmp.v1.set(7, 0).rotate(rotation * 90); + Draw.line(cx, cy, cx + Tmp.v1.x, cy + Tmp.v1.y); + } Draw.reset(); } } public void tapped(int tilex, int tiley, int endx, int endy){ + int prev = player.rotation; + + if(Math.abs(tilex - endx) > Math.abs(tiley - endy)){ + endy = tiley; + }else{ + endx = tilex; + } + + if(Math.abs(endx - tilex) > maxlen){ + endx = Mathf.sign(endx - tilex) * maxlen + tilex; + } + + if(Math.abs(endy - tiley) > maxlen){ + endy = Mathf.sign(endy - tiley) * maxlen + tiley; + } + + if(endx > tilex) + player.rotation = 0; + if(endx < tilex) + player.rotation = 2; + if(endy > tiley) + player.rotation = 1; + if(endy < tiley) + player.rotation = 3; + if(endx < tilex){ int t = endx; endx = tilex; @@ -109,6 +170,8 @@ public enum PlaceMode{ } } + player.rotation = prev; + } }, breaker{