Merge branch 'master' of https://github.com/Anuken/Mindustry into 4.0

# Conflicts:
#	core/assets-raw/sprites/blocks/chainturret-icon.png
#	core/assets-raw/sprites/blocks/chainturret.png
#	core/assets-raw/sprites/blocks/titancannon-icon.png
#	core/assets-raw/sprites/blocks/titancannon.png
#	core/assets/sprites/sprites.atlas
#	core/assets/sprites/sprites.png
#	core/assets/version.properties
#	core/src/io/anuke/mindustry/entities/effect/TeslaOrb.java
#	core/src/io/anuke/mindustry/graphics/BlockRenderer.java
#	core/src/io/anuke/mindustry/input/InputHandler.java
#	core/src/io/anuke/mindustry/input/PlaceMode.java
This commit is contained in:
Anuken
2018-04-21 18:47:43 -04:00
21 changed files with 759 additions and 46 deletions

View File

@@ -47,7 +47,7 @@ public class GestureHandler extends GestureAdapter{
if(control.showCursor() && !Inputs.keyDown("select")) return false;
if(!control.showCursor() && !(control.input().recipe != null
&& control.input().placeMode.lockCamera) &&
&& control.input().placeMode.lockCamera && state.inventory.hasItems(control.input().recipe.requirements)) &&
!(control.input().recipe == null && control.input().breakMode.lockCamera)){
float dx = deltaX*Core.camera.zoom/Core.cameraScale, dy = deltaY*Core.camera.zoom/Core.cameraScale;
player.x -= dx;

View File

@@ -129,9 +129,10 @@ public abstract class InputHandler extends InputAdapter{
}
}
}
public boolean cursorNear(){
return Vector2.dst(player.x, player.y, getBlockX() * tilesize, getBlockY() * tilesize) <= placerange || debug;
return Vector2.dst(player.x, player.y, getBlockX() * tilesize, getBlockY() * tilesize) <= placerange ||
state.mode.infiniteResources || debug;
}
public boolean tryPlaceBlock(int x, int y, boolean sound){

View File

@@ -34,15 +34,17 @@ public enum PlaceMode{
float si = MathUtils.sin(Timers.time() / 6f) + 1.5f;
renderer.getBlocks().handlePreview(control.input().recipe.result, control.input().recipe.result.rotate ? control.input().rotation * 90 : 0f, x + offset.x, y + offset.y, tilex, tiley);
Draw.color(valid ? Colors.get("place") : Colors.get("placeInvalid"));
Lines.stroke(2f);
Lines.crect(x + offset.x, y + offset.y, tilesize * control.input().recipe.result.size + si,
tilesize * control.input().recipe.result.size + si);
control.input().recipe.result.drawPlace(tilex, tiley, control.input().rotation, valid);
Lines.stroke(2f);
if(control.input().recipe.result.rotate){
Draw.color(Colors.get("placeRotate"));
tr.trns(control.input().rotation * 90, 7, 0);
Lines.line(x, y, x + tr.x, y + tr.y);
@@ -126,9 +128,9 @@ public enum PlaceMode{
process(tilex, tiley, endx, endy);
tilex = this.tilex; tiley = this.tiley;
tilex = this.tilex; tiley = this.tiley;
endx = this.endx; endy = this.endy;
float x = this.tilex * t, y = this.tiley * t,
float x = this.tilex * t, y = this.tiley * t,
x2 = this.endx * t, y2 = this.endy * t;
if(x2 >= x){
@@ -150,7 +152,7 @@ public enum PlaceMode{
tile = tile.getLinked();
if(tile != null && control.input().validBreak(tile.x, tile.y)){
Lines.crect(tile.drawx(), tile.drawy(),
tile.block().size* t, tile.block().size * t);
tile.block().size * t, tile.block().size * t);
}
}
}
@@ -165,7 +167,7 @@ public enum PlaceMode{
public void released(int tilex, int tiley, int endx, int endy){
process(tilex, tiley, endx, endy);
tilex = this.tilex; tiley = this.tiley;
tilex = this.tilex; tiley = this.tiley;
endx = this.endx; endy = this.endy;
if(android){
@@ -237,16 +239,16 @@ public enum PlaceMode{
if(android && !Gdx.input.isTouched(0) && !control.showCursor()){
return;
}
float t = tilesize;
Block block = control.input().recipe.result;
Vector2 offset = block.getPlaceOffset();
process(tilex, tiley, endx, endy);
int tx = tilex, ty = tiley, ex = endx, ey = endy;
tilex = this.tilex; tiley = this.tiley;
tilex = this.tilex; tiley = this.tiley;
endx = this.endx; endy = this.endy;
float x = this.tilex * t, y = this.tiley * t,
float x = this.tilex * t, y = this.tiley * t,
x2 = this.endx * t, y2 = this.endy * t;
if(x2 >= x){
@@ -268,29 +270,55 @@ public enum PlaceMode{
cursor.draw(tilex, tiley, endx, endy);
}else{
Lines.stroke(2f);
Draw.color(control.input().cursorNear() ? Colors.get("place") : Colors.get("placeInvalid"));
Draw.color(control.input().cursorNear() ? "place" : "placeInvalid");
Lines.rect(x, y, x2 - x, y2 - y);
Draw.alpha(0.3f);
Draw.crect("blank", x, y, x2 - x, y2 - y);
Draw.color(Colors.get("placeInvalid"));
int amount = 1;
for(int cx = 0; cx <= Math.abs(endx - tilex); cx ++){
for(int cy = 0; cy <= Math.abs(endy - tiley); cy ++){
int px = tx + cx * Mathf.sign(ex - tx),
py = ty + cy * Mathf.sign(ey - ty);
if(!control.input().validPlace(px, py, control.input().recipe.result)
|| !state.inventory.hasItems(control.input().recipe.requirements, amount)){
Lines.crect(px * t + offset.x, py * t + offset.y, t*block.size, t*block.size);
boolean isX = Math.abs(endx - tilex) >= Math.abs(endy - tiley);
for(int cx = 0; cx <= Math.abs(endx - tilex); cx += (isX ? 0 : 1)){
for(int cy = 0; cy <= Math.abs(endy - tiley); cy += (isX ? 1 : 0)){
int px = tx + cx * Mathf.sign(ex - tx),
py = ty + cy * Mathf.sign(ey - ty);
//step by the block size if it's valid
if(control.input().validPlace(px, py, control.input().recipe.result) && state.inventory.hasItems(control.input().recipe.requirements, amount)){
renderer.getBlocks().handlePreview(control.input().recipe.result, block.rotate ? rotation * 90 : 0f, px * t + offset.x, py * t + offset.y, px, py);
if(isX){
cx += block.size;
}else{
cy += block.size;
}
amount ++;
}else{ //otherwise, step by 1 until it is valid
if(control.input().cursorNear()){
Lines.stroke(2f);
Draw.color("placeInvalid");
Lines.crect(
px * t + (isX ? 0 : offset.x) + (ex < tx && isX ? t : 0) - (block.size == 3 && ex > tx && isX ? t : 0),
py * t + (isX ? offset.y : 0) + (ey < ty && !isX ? t : 0) - (block.size == 3 && ey > ty && !isX ? t : 0),
t*(isX ? 1 : block.size),
t*(isX ? block.size : 1));
Draw.color("place");
}
if(isX){
cx += 1;
}else{
cy += 1;
}
}
amount ++;
}
}
if(control.input().recipe.result.rotate){
float cx = tx * t, cy = ty * t;
Lines.stroke(2f);
Draw.color(Colors.get("placeRotate"));
tr.trns(rotation * 90, 7, 0);
Lines.line(cx, cy, cx + tr.x, cy + tr.y);
@@ -308,7 +336,7 @@ public enum PlaceMode{
for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){
for(int y = 0; y <= Math.abs(this.endy - this.tiley); y ++){
if(control.input().tryPlaceBlock(
tilex + x * Mathf.sign(endx - tilex),
tilex + x * Mathf.sign(endx - tilex),
tiley + y * Mathf.sign(endy - tiley), first)){
first = false;
}
@@ -340,7 +368,7 @@ public enum PlaceMode{
rotation = 1;
else if(endy < tiley)
rotation = 3;
else
else
rotation = control.input().rotation;
if(endx < tilex){
@@ -371,19 +399,19 @@ public enum PlaceMode{
private static final Translator tr = new Translator();
public void draw(int tilex, int tiley, int endx, int endy){
}
public void released(int tilex, int tiley, int endx, int endy){
}
public void tapped(int x, int y){
}
@Override
public String toString(){
return Bundles.get("placemode."+name().toLowerCase()+".name");
}
}
}