mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-25 22:58:47 +07:00
Finish multiline placing
This commit is contained in:
parent
a81f90d140
commit
8205745f9d
@ -383,10 +383,21 @@ public class Control extends Module{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasItems(ItemStack[] items, int scaling){
|
||||
for(ItemStack stack : items)
|
||||
if(!hasItem(stack.item, stack.amount * scaling))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasItem(ItemStack req){
|
||||
return items[req.item.ordinal()] >= req.amount;
|
||||
}
|
||||
|
||||
public boolean hasItem(Item item, int amount){
|
||||
return items[item.ordinal()] >= amount;
|
||||
}
|
||||
|
||||
public void removeItem(ItemStack req){
|
||||
items[req.item.ordinal()] -= req.amount;
|
||||
shouldUpdateItems = true;
|
||||
@ -456,6 +467,7 @@ public class Control extends Module{
|
||||
}
|
||||
|
||||
if(!GameState.is(State.menu)){
|
||||
input.update();
|
||||
|
||||
if(Inputs.keyUp("pause") && !ui.isGameOver() && (GameState.is(State.paused) || GameState.is(State.playing))){
|
||||
GameState.set(GameState.is(State.playing) ? State.paused : State.playing);
|
||||
@ -524,8 +536,6 @@ public class Control extends Module{
|
||||
|
||||
Profiler.end("entityUpdate");
|
||||
}
|
||||
|
||||
input.update();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ 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;
|
||||
@ -21,17 +22,19 @@ import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class Input extends InputHandler{
|
||||
float mousex, mousey;
|
||||
float endx, endy;
|
||||
|
||||
@Override public float getCursorEndX(){ return Gdx.input.getX(); }
|
||||
@Override public float getCursorEndY(){ return Gdx.input.getY(); }
|
||||
@Override public float getCursorX(){ return mousex; }
|
||||
@Override public float getCursorY(){ return mousey; }
|
||||
@Override public float getCursorEndX(){ return endx; }
|
||||
@Override public float getCursorEndY(){ return endy; }
|
||||
@Override public float getCursorX(){ return Graphics.screen(mousex, mousey).x; }
|
||||
@Override public float getCursorY(){ return Gdx.graphics.getHeight() - Graphics.screen(mousex, mousey).y; }
|
||||
|
||||
@Override
|
||||
public boolean touchDown (int screenX, int screenY, int pointer, int button) {
|
||||
public boolean touchDown (int screenX, int screenY, int pointer, int button){
|
||||
if(button == Buttons.LEFT){
|
||||
mousex = screenX;
|
||||
mousey = screenY;
|
||||
Vector2 vec = Graphics.world(screenX, screenY);
|
||||
mousex = vec.x;
|
||||
mousey = vec.y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -46,9 +49,12 @@ public class Input extends InputHandler{
|
||||
if(player.isDead()) return;
|
||||
|
||||
if(!Inputs.buttonDown(Buttons.LEFT)){
|
||||
mousex = Gdx.input.getX();
|
||||
mousey = Gdx.input.getY();
|
||||
Vector2 vec = Graphics.world(Gdx.input.getX(), Gdx.input.getY());
|
||||
mousex = vec.x;
|
||||
mousey = vec.y;
|
||||
}
|
||||
endx = Gdx.input.getX();
|
||||
endy = Gdx.input.getY();
|
||||
|
||||
if(Inputs.scrolled() && Inputs.keyDown("zoom_hold") && !GameState.is(State.menu) && !Vars.ui.onDialog()){
|
||||
Vars.renderer.scaleCamera(Inputs.scroll());
|
||||
|
@ -19,10 +19,10 @@ public abstract class InputHandler extends InputAdapter{
|
||||
public abstract float getCursorY();
|
||||
public abstract float getCursorEndX();
|
||||
public abstract float getCursorEndY();
|
||||
public int getBlockX(){ return Mathf.scl2(Graphics.world(getCursorX(), getCursorY()).x, Vars.tilesize); }
|
||||
public int getBlockY(){ return Mathf.scl2(Graphics.world(getCursorX(), getCursorY()).y, Vars.tilesize); }
|
||||
public int getBlockEndX(){ return Mathf.scl2(Graphics.world(getCursorEndX(), getCursorEndY()).x, Vars.tilesize); }
|
||||
public int getBlockEndY(){ return Mathf.scl2(Graphics.world(getCursorEndX(), getCursorEndY()).y, Vars.tilesize); }
|
||||
public int getBlockX(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).x, Vars.tilesize, round2()); }
|
||||
public int getBlockY(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).y, Vars.tilesize, round2()); }
|
||||
public int getBlockEndX(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).x, Vars.tilesize, round2()); }
|
||||
public int getBlockEndY(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).y, Vars.tilesize, round2()); }
|
||||
public void resetCursor(){}
|
||||
|
||||
public boolean onConfigurable(){
|
||||
@ -50,4 +50,8 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean round2(){
|
||||
return !(player.recipe != null && player.recipe.result.isMultiblock() && player.recipe.result.height % 2 == 0);
|
||||
}
|
||||
}
|
||||
|
@ -49,54 +49,25 @@ public enum PlaceMode{
|
||||
},
|
||||
touch{
|
||||
int maxlen = 10;
|
||||
int tilex;
|
||||
int tiley;
|
||||
int endx;
|
||||
int endy;
|
||||
int rotation;
|
||||
|
||||
{
|
||||
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;
|
||||
x2 = d;
|
||||
}
|
||||
|
||||
if(y2 < y){
|
||||
float d = y;
|
||||
y = y2;
|
||||
y2 = d;
|
||||
}
|
||||
process(tilex, tiley, endx, endy);
|
||||
int tx = tilex, ty = tiley, ex = endx, ey = endy;
|
||||
tilex = this.tilex; tiley = this.tiley;
|
||||
endx = this.endx; endy = this.endy;
|
||||
float x = this.tilex * t, y = this.tiley * t,
|
||||
x2 = this.endx * t, y2 = this.endy * t;
|
||||
|
||||
if(x2 >= x){
|
||||
x -= t/2;
|
||||
@ -117,6 +88,22 @@ public enum PlaceMode{
|
||||
Draw.alpha(0.3f);
|
||||
Draw.crect("blank", x, y, x2 - x, y2 - y);
|
||||
|
||||
Draw.color(Color.RED);
|
||||
|
||||
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(!world.validPlace(px, py, player.recipe.result)
|
||||
|| !control.hasItems(player.recipe.requirements, amount)){
|
||||
Draw.square(px * t, py * t, t/2);
|
||||
}
|
||||
amount ++;
|
||||
}
|
||||
}
|
||||
|
||||
if(player.recipe.result.rotate){
|
||||
float cx = tilex * t, cy = tiley * t;
|
||||
Draw.color(Color.ORANGE);
|
||||
@ -129,7 +116,25 @@ public enum PlaceMode{
|
||||
|
||||
public void tapped(int tilex, int tiley, int endx, int endy){
|
||||
int prev = player.rotation;
|
||||
process(tilex, tiley, endx, endy);
|
||||
//tilex = this.tilex; tiley = this.tiley;
|
||||
//endx = this.endx; endy = this.endy;
|
||||
|
||||
player.rotation = this.rotation;
|
||||
|
||||
for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){
|
||||
for(int y = 0; y <= Math.abs(this.endy - this.tiley); y ++){
|
||||
control.getInput().tryPlaceBlock(
|
||||
tilex + x * Mathf.sign(endx - tilex),
|
||||
tiley + y * Mathf.sign(endy - tiley));
|
||||
}
|
||||
}
|
||||
|
||||
player.rotation = prev;
|
||||
|
||||
}
|
||||
|
||||
void process(int tilex, int tiley, int endx, int endy){
|
||||
if(Math.abs(tilex - endx) > Math.abs(tiley - endy)){
|
||||
endy = tiley;
|
||||
}else{
|
||||
@ -145,13 +150,15 @@ public enum PlaceMode{
|
||||
}
|
||||
|
||||
if(endx > tilex)
|
||||
player.rotation = 0;
|
||||
if(endx < tilex)
|
||||
player.rotation = 2;
|
||||
if(endy > tiley)
|
||||
player.rotation = 1;
|
||||
if(endy < tiley)
|
||||
player.rotation = 3;
|
||||
rotation = 0;
|
||||
else if(endx < tilex)
|
||||
rotation = 2;
|
||||
else if(endy > tiley)
|
||||
rotation = 1;
|
||||
else if(endy < tiley)
|
||||
rotation = 3;
|
||||
else
|
||||
rotation = player.rotation;
|
||||
|
||||
if(endx < tilex){
|
||||
int t = endx;
|
||||
@ -164,14 +171,10 @@ public enum PlaceMode{
|
||||
tiley = t;
|
||||
}
|
||||
|
||||
for(int x = tilex; x <= endx; x ++){
|
||||
for(int y = tiley; y <= endy; y ++){
|
||||
control.getInput().tryPlaceBlock(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
player.rotation = prev;
|
||||
|
||||
this.endx = endx;
|
||||
this.endy = endy;
|
||||
this.tilex = tilex;
|
||||
this.tiley = tiley;
|
||||
}
|
||||
},
|
||||
breaker{
|
||||
|
Loading…
Reference in New Issue
Block a user