Major bugfix, new incomplete placemodes

This commit is contained in:
Anuken
2017-12-15 01:39:54 -05:00
parent 52a996cf77
commit 64439126a3
22 changed files with 728 additions and 535 deletions

View File

@@ -7,7 +7,6 @@ import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.resource.ItemStack;
@@ -20,9 +19,10 @@ import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Mathf;
public class AndroidInput extends InputHandler{
public float lmousex, lmousey;
public float mousex, mousey;
public boolean brokeBlock = false;
private float lmousex, lmousey;
private boolean placing = true;
private float warmup;
private float warmupDelay = 20;
@@ -34,11 +34,12 @@ public class AndroidInput extends InputHandler{
@Override public float getCursorEndY(){ return Gdx.input.getY(0); }
@Override public float getCursorX(){ return mousex; }
@Override public float getCursorY(){ return mousey; }
@Override public boolean drawPlace(){ return placing; }
@Override
public boolean keyDown(int keycode){
if(keycode == Keys.E){
place();
}
return false;
}
@@ -46,26 +47,43 @@ public class AndroidInput extends InputHandler{
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button){
brokeBlock = false;
if(placing && pointer == 0 && !player.placeMode.pan){
player.placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
placing = false;
}
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button){
if(ui.hasMouse()) return false;
ui.hideTooltip();
if(pointer == 0){
lmousex = screenX;
lmousey = screenY;
lmousex = screenX;
lmousey = screenY;
if(!player.placeMode.pan){
if(pointer == 0){
placing = true;
mousex = screenX;
mousey = screenY;
}else{
placing = false;
}
}
warmup = 0;
if(!GameState.is(State.menu)){
Tile cursor = Vars.world.tile(Mathf.scl2(Graphics.mouseWorld().x, tilesize), Mathf.scl2(Graphics.mouseWorld().y, tilesize));
if(cursor != null && !Vars.ui.hasMouse()){
Tile cursor = world.tile(Mathf.scl2(Graphics.mouseWorld().x, tilesize), Mathf.scl2(Graphics.mouseWorld().y, tilesize));
if(cursor != null && !ui.hasMouse()){
Tile linked = cursor.isLinked() ? cursor.getLinked() : cursor;
if(linked != null && linked.block() instanceof Configurable){
Vars.ui.showConfig(linked);
}else if(!Vars.ui.hasConfigMouse()){
Vars.ui.hideConfig();
ui.showConfig(linked);
}else if(!ui.hasConfigMouse()){
ui.hideConfig();
}
}
}
@@ -85,7 +103,7 @@ public class AndroidInput extends InputHandler{
public Tile selected(){
Vector2 vec = Graphics.world(mousex, mousey);
return Vars.world.tile(Mathf.scl2(vec.x, tilesize), Mathf.scl2(vec.y, tilesize));
return world.tile(Mathf.scl2(vec.x, tilesize), Mathf.scl2(vec.y, tilesize));
}
public void breakBlock(){
@@ -94,23 +112,18 @@ public class AndroidInput extends InputHandler{
if(player.breaktime >= tile.block().breaktime){
brokeBlock = true;
Vars.world.breakBlock(tile.x, tile.y);
breakBlock(tile.x, tile.y);
player.breaktime = 0f;
}
}
public void tryPlaceBlock(int tilex, int tiley){
if(player.recipe != null && control.hasItems(player.recipe.requirements) && validPlace(tilex, tiley, player.recipe.result)){
public void place(){
Vector2 vec = Graphics.world(mousex, mousey);
int tilex = Mathf.scl2(vec.x, tilesize);
int tiley = Mathf.scl2(vec.y, tilesize);
if(player.recipe != null && Vars.control.hasItems(player.recipe.requirements) && Vars.world.validPlace(tilex, tiley, player.recipe.result)){
Vars.world.placeBlock(tilex, tiley, player.recipe.result, player.rotation, true);
placeBlock(tilex, tiley, player.recipe.result, player.rotation, true);
for(ItemStack stack : player.recipe.requirements){
Vars.control.removeItem(stack);
control.removeItem(stack);
}
}
}
@@ -132,7 +145,7 @@ public class AndroidInput extends InputHandler{
if(sel == null)
return;
if(warmup > warmupDelay && Vars.world.validBreak(sel.x, sel.y)){
if(warmup > warmupDelay && validBreak(sel.x, sel.y)){
player.breaktime += Timers.delta();
if(player.breaktime > selected().block().breaktime){
@@ -145,8 +158,6 @@ public class AndroidInput extends InputHandler{
mousey = ly;
}else{
warmup = 0;
//lmousex = Gdx.input.getX(0);
//lmousey = Gdx.input.getY(0);
player.breaktime = 0;
mousex = Mathf.clamp(mousex, 0, Gdx.graphics.getWidth());

View File

@@ -7,7 +7,6 @@ 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;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.resource.ItemStack;
@@ -20,27 +19,27 @@ import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.util.Mathf;
public class Input extends InputHandler{
float mousex, mousey;
float endx, endy;
public class DesktopInput extends InputHandler{
int mousex, mousey;
int endx, endy;
@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 float getCursorX(){ return (int)(Graphics.screen(mousex, mousey).x + 2); }
@Override public float getCursorY(){ return (int)(Gdx.graphics.getHeight() - 1 - Graphics.screen(mousex, mousey).y); }
@Override
public boolean touchDown (int screenX, int screenY, int pointer, int button){
if(button == Buttons.LEFT){
Vector2 vec = Graphics.world(screenX, screenY);
mousex = vec.x;
mousey = vec.y;
mousex = (int)vec.x;
mousey = (int)vec.y;
}
return false;
}
public boolean touchUp(int screenX, int screenY, int pointer, int button){
player.placeMode.tapped(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
player.placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
return false;
}
@@ -49,15 +48,14 @@ public class Input extends InputHandler{
if(player.isDead()) return;
if(!Inputs.buttonDown(Buttons.LEFT)){
Vector2 vec = Graphics.world(Gdx.input.getX(), Gdx.input.getY());
mousex = vec.x;
mousey = vec.y;
mousex = (int)Graphics.mouseWorld().x;
mousey = (int)Graphics.mouseWorld().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());
if(Inputs.scrolled() && Inputs.keyDown("zoom_hold") && !GameState.is(State.menu) && !ui.onDialog()){
renderer.scaleCamera(Inputs.scroll());
}
if(Inputs.scrolled()){
@@ -72,6 +70,12 @@ public class Input extends InputHandler{
player.rotation ++;
}
if(Inputs.keyDown("area_delete_mode")){
player.placeMode = PlaceMode.areaDelete;
}else{
player.placeMode = PlaceMode.hold;
}
player.rotation = Mathf.mod(player.rotation, 4);
for(int i = 0; i < 9; i ++){
@@ -81,19 +85,19 @@ public class Input extends InputHandler{
}
}
Tile cursor = Vars.world.tile(tilex(), tiley());
Tile cursor = world.tile(tilex(), tiley());
if(Inputs.buttonUp(Buttons.LEFT) && cursor != null){
Tile linked = cursor.isLinked() ? cursor.getLinked() : cursor;
if(linked != null && linked.block() instanceof Configurable){
Vars.ui.showConfig(linked);
}else if(!Vars.ui.hasConfigMouse()){
Vars.ui.hideConfig();
ui.showConfig(linked);
}else if(!ui.hasConfigMouse()){
ui.hideConfig();
}
}
if(Inputs.buttonUp(Buttons.RIGHT)){
Vars.ui.hideConfig();
ui.hideConfig();
}
if(player.recipe != null && Inputs.buttonUp(Buttons.RIGHT)){
@@ -102,11 +106,11 @@ public class Input extends InputHandler{
}
//block breaking
if(Inputs.buttonDown(Buttons.RIGHT) && cursor != null && Vars.world.validBreak(tilex(), tiley())){
if(Inputs.buttonDown(Buttons.RIGHT) && cursor != null && validBreak(tilex(), tiley())){
Tile tile = cursor;
player.breaktime += Timers.delta();
if(player.breaktime >= tile.getBreakTime()){
Vars.world.breakBlock(cursor.x, cursor.y);
breakBlock(cursor.x, cursor.y);
player.breaktime = 0f;
}
}else{
@@ -117,16 +121,16 @@ public class Input extends InputHandler{
public void tryPlaceBlock(int x, int y){
if(player.recipe != null &&
Vars.world.validPlace(x, y, player.recipe.result) && !ui.hasMouse() && cursorNear() &&
Vars.control.hasItems(player.recipe.requirements)){
validPlace(x, y, player.recipe.result) && !ui.hasMouse() && cursorNear() &&
control.hasItems(player.recipe.requirements)){
Vars.world.placeBlock(x, y, player.recipe.result, player.rotation, true);
placeBlock(x, y, player.recipe.result, player.rotation, true);
for(ItemStack stack : player.recipe.requirements){
Vars.control.removeItem(stack);
control.removeItem(stack);
}
if(!Vars.control.hasItems(player.recipe.requirements)){
if(!control.hasItems(player.recipe.requirements)){
Cursors.restoreCursor();
}
}

View File

@@ -9,7 +9,6 @@ import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Mathf;
public class GestureHandler extends GestureAdapter{
AndroidInput input;
@@ -29,14 +28,10 @@ public class GestureHandler extends GestureAdapter{
@Override
public boolean tap (float x, float y, int count, int button) {
if(!ui.hasMouse() && player.recipe != null &&
Vars.control.hasItems(player.recipe.requirements) && !Vars.ui.hasMouse() && !input.brokeBlock){
player.placeMode.tapped(Mathf.scl2(x, Vars.tilesize), Mathf.scl2(y, Vars.tilesize), Mathf.scl2(x, Vars.tilesize), Mathf.scl2(y, Vars.tilesize));
if(!player.placeMode.pan){
input.mousex = x;
input.mousey = y;
return true;
player.placeMode.tapped(input.getBlockX(), input.getBlockY());
}
return false;
}

View File

@@ -3,15 +3,29 @@ package io.anuke.mindustry.input;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.effect.Fx;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Recipe;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.SpawnPoint;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.mindustry.world.blocks.types.Configurable;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.core.Sounds;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
public abstract class InputHandler extends InputAdapter{
public abstract void update();
@@ -24,6 +38,7 @@ public abstract class InputHandler extends InputAdapter{
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 drawPlace(){ return true; }
public boolean onConfigurable(){
Tile tile = Vars.world.tile(getBlockX(), getBlockY());
@@ -36,10 +51,10 @@ public abstract class InputHandler extends InputAdapter{
public void tryPlaceBlock(int x, int y){
if(player.recipe != null &&
Vars.world.validPlace(x, y, player.recipe.result) && !ui.hasMouse() && cursorNear() &&
validPlace(x, y, player.recipe.result) && !ui.hasMouse() && cursorNear() &&
Vars.control.hasItems(player.recipe.requirements)){
Vars.world.placeBlock(x, y, player.recipe.result, player.rotation, true);
placeBlock(x, y, player.recipe.result, player.rotation, true);
for(ItemStack stack : player.recipe.requirements){
Vars.control.removeItem(stack);
@@ -51,7 +66,178 @@ public abstract class InputHandler extends InputAdapter{
}
}
public void tryDeleteBlock(int x, int y){
if(cursorNear() && validBreak(x, y)){
breakBlock(x, y);
}
}
public boolean round2(){
return !(player.recipe != null && player.recipe.result.isMultiblock() && player.recipe.result.height % 2 == 0);
}
public boolean validPlace(int x, int y, Block type){
for(SpawnPoint spawn : control.getSpawnPoints()){
if(Vector2.dst(x * tilesize, y * tilesize, spawn.start.worldx(), spawn.start.worldy()) < enemyspawnspace){
return false;
}
}
Tmp.r2.setSize(type.width * Vars.tilesize, type.height * Vars.tilesize);
Vector2 offset = type.getPlaceOffset();
Tmp.r2.setCenter(offset.x + x * Vars.tilesize, offset.y + y * Vars.tilesize);
for(SolidEntity e : Entities.getNearby(control.enemyGroup, x * tilesize, y * tilesize, tilesize * 2f)){
Rectangle rect = e.hitbox.getRect(e.x, e.y);
if(Tmp.r2.overlaps(rect)){
return false;
}
}
if(!Vars.android && Tmp.r2.overlaps(player.hitbox.getRect(player.x, player.y))){
return false;
}
Tile tile = world.tile(x, y);
if(tile == null) return false;
if(!type.isMultiblock() && Vars.control.getTutorial().active() &&
Vars.control.getTutorial().showBlock()){
GridPoint2 point = Vars.control.getTutorial().getPlacePoint();
int rotation = Vars.control.getTutorial().getPlaceRotation();
Block block = Vars.control.getTutorial().getPlaceBlock();
if(type != block || point.x != x - control.getCore().x || point.y != y - control.getCore().y
|| (rotation != -1 && rotation != Vars.player.rotation)){
return false;
}
}else if(Vars.control.getTutorial().active()){
return false;
}
if(type.isMultiblock()){
int offsetx = -(type.width-1)/2;
int offsety = -(type.height-1)/2;
for(int dx = 0; dx < type.width; dx ++){
for(int dy = 0; dy < type.height; dy ++){
Tile other = world.tile(x + dx + offsetx, y + dy + offsety);
if(other == null || other.block() != Blocks.air){
return false;
}
}
}
return true;
}else{
if(tile.block() != type && type.canReplace(tile.block()) && tile.block().isMultiblock() == type.isMultiblock()){
return true;
}
return tile != null && tile.block() == Blocks.air;
}
}
public boolean validBreak(int x, int y){
Tile tile = world.tile(x, y);
if(tile == null || tile.block() == ProductionBlocks.core) return false;
if(tile.isLinked() && tile.getLinked().block() == ProductionBlocks.core){
return false;
}
if(Vars.control.getTutorial().active()){
if(Vars.control.getTutorial().showBlock()){
GridPoint2 point = Vars.control.getTutorial().getPlacePoint();
int rotation = Vars.control.getTutorial().getPlaceRotation();
Block block = Vars.control.getTutorial().getPlaceBlock();
if(block != Blocks.air || point.x != x - control.getCore().x || point.y != y - control.getCore().y
|| (rotation != -1 && rotation != Vars.player.rotation)){
return false;
}
}else{
return false;
}
}
return tile.breakable();
}
public void placeBlock(int x, int y, Block result, int rotation, boolean effects){
Tile tile = world.tile(x, y);
//just in case
if(tile == null)
return;
tile.setBlock(result, rotation);
if(result.isMultiblock()){
int offsetx = -(result.width-1)/2;
int offsety = -(result.height-1)/2;
for(int dx = 0; dx < result.width; dx ++){
for(int dy = 0; dy < result.height; dy ++){
int worldx = dx + offsetx + x;
int worldy = dy + offsety + y;
if(!(worldx == x && worldy == y)){
Tile toplace = world.tile(worldx, worldy);
toplace.setLinked((byte)(dx + offsetx), (byte)(dy + offsety));
}
if(effects) Effects.effect(Fx.place, worldx * Vars.tilesize, worldy * Vars.tilesize);
}
}
}else{
if(effects) Effects.effect(Fx.place, x * Vars.tilesize, y * Vars.tilesize);
}
if(effects) Sounds.play("place");
}
public void breakBlock(int x, int y){
Tile tile = world.tile(x, y);
if(tile == null) return;
Block block = tile.isLinked() ? tile.getLinked().block() : tile.block();
Recipe result = null;
for(Recipe recipe : Recipe.values()){
if(recipe.result == block){
result = recipe;
break;
}
}
if(result != null){
for(ItemStack stack : result.requirements){
Vars.control.addItem(stack.item, (int)(stack.amount * Vars.breakDropAmount));
}
}
if(tile.block().drops != null){
Vars.control.addItem(tile.block().drops.item, tile.block().drops.amount);
}
Effects.shake(3f, 1f, player);
Sounds.play("break");
if(!tile.block().isMultiblock() && !tile.isLinked()){
tile.setBlock(Blocks.air);
Effects.effect(Fx.breakBlock, tile.worldx(), tile.worldy());
}else{
Tile target = tile.isLinked() ? tile.getLinked() : tile;
Array<Tile> removals = target.getLinkedTiles();
for(Tile toremove : removals){
//note that setting a new block automatically unlinks it
toremove.setBlock(Blocks.air);
Effects.effect(Fx.breakBlock, toremove.worldx(), toremove.worldy());
}
}
}
}

View File

@@ -2,12 +2,15 @@ package io.anuke.mindustry.input;
import static io.anuke.mindustry.Vars.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Colors;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Inputs;
@@ -18,25 +21,32 @@ import io.anuke.ucore.util.Tmp;
public enum PlaceMode{
cursor{
{
shown = true;
lockCamera = true;
pan = true;
}
public void draw(int tilex, int tiley, int endx, int endy){
float x = tilex * Vars.tilesize;
float y = tiley * Vars.tilesize;
boolean valid = world.validPlace(tilex, tiley, player.recipe.result) && (android || control.getInput().cursorNear());
boolean valid = control.getInput().validPlace(tilex, tiley, player.recipe.result) && (android || control.getInput().cursorNear());
Vector2 offset = player.recipe.result.getPlaceOffset();
float si = MathUtils.sin(Timers.time() / 6f) + 1;
float si = MathUtils.sin(Timers.time() / 6f) + 1.5f;
Draw.color(valid ? Color.PURPLE : Color.SCARLET);
Draw.color(valid ? Colors.get("place") : Colors.get("placeInvalid"));
Draw.thickness(2f);
Draw.linecrect(x + offset.x, y + offset.y, tilesize * player.recipe.result.width + si, tilesize * player.recipe.result.height + si);
Draw.linecrect(x + offset.x, y + offset.y, tilesize * player.recipe.result.width + si,
tilesize * player.recipe.result.height + si);
player.recipe.result.drawPlace(tilex, tiley, player.rotation, valid);
Draw.thickness(2f);
if(player.recipe.result.rotate){
Draw.color(Color.ORANGE);
Draw.color(Colors.get("placeRotate"));
Tmp.v1.set(7, 0).rotate(player.rotation * 90);
Draw.line(x, y, x + Tmp.v1.x, y + Tmp.v1.y);
}
@@ -46,24 +56,42 @@ public enum PlaceMode{
else
Cursors.restoreCursor();
}
},
public void tapped(int tilex, int tiley){
System.out.println("tap " + tilex + " " + tiley);
control.getInput().tryPlaceBlock(tilex, tiley);
}
},
touch{
{
shown = true;
lockCamera = false;
showRotate = true;
showCancel = true;
}
public void tapped(int x, int y){
control.getInput().tryPlaceBlock(x, y);
}
},
areaDelete{
int maxlen = 10;
int tilex;
int tiley;
int endx;
int endy;
int rotation;
{
shown = true;
lockCamera = true;
delete = true;
}
public void draw(int tilex, int tiley, int endx, int endy){
float t = Vars.tilesize;
float t = tilesize;
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,
@@ -79,16 +107,124 @@ public enum PlaceMode{
y2 += t/2;
}
Draw.color(Colors.get("break"));
Draw.thick(1f);
for(int cx = tilex; cx <= endx; cx ++){
for(int cy = tiley; cy <= endy; cy ++){
Tile tile = Vars.world.tile(cx, cy);
if(tile != null && tile.getLinked() != null)
tile = tile.getLinked();
if(tile != null && control.getInput().validBreak(tile.x, tile.y)){
Vector2 offset = tile.block().getPlaceOffset();
Draw.linecrect(tile.worldx() + offset.x, tile.worldy() + offset.y,
tile.block().width * t, tile.block().height * t);
}
}
}
Draw.thick(2f);
Draw.color(control.getInput().cursorNear() ? Colors.get("break") : Colors.get("breakInvalid"));
Draw.linerect(x, y, x2 - x, y2 - y);
Draw.alpha(0.3f);
Draw.crect("blank", x, y, x2 - x, y2 - y);
Draw.reset();
}
public void released(int tilex, int tiley, int endx, int endy){
process(tilex, tiley, endx, endy);
tilex = this.tilex; tiley = this.tiley;
endx = this.endx; endy = this.endy;
for(int cx = tilex; cx <= endx; cx ++){
for(int cy = tiley; cy <= endy; cy ++){
control.getInput().tryDeleteBlock(cx, cy);
}
}
}
void process(int tilex, int tiley, int endx, int endy){
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){
int t = endx;
endx = tilex;
tilex = t;
}
if(endy < tiley){
int t = endy;
endy = tiley;
tiley = t;
}
this.endx = endx;
this.endy = endy;
this.tilex = tilex;
this.tiley = tiley;
}
},
hold{ //TODO multiblock support!
int maxlen = 10;
int tilex;
int tiley;
int endx;
int endy;
int rotation;
{
lockCamera = true;
shown = true;
showCancel = true;
showRotate = true;
}
public void draw(int tilex, int tiley, int endx, int endy){
if(Vars.android && !Gdx.input.isTouched(0)){
return;
}
float t = Vars.tilesize;
Block block = player.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;
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 -= block.width * t/2;
x2 += block.width * t/2;
}
if(y2 >= y){
y -= block.height * t/2;
y2 += block.height * t/2;
}
x += offset.x;
y += offset.y;
x2 += offset.x;
y2 += offset.y;
if(tilex == endx && tiley == endy){
cursor.draw(tilex, tiley, endx, endy);
}else{
Draw.thick(2f);
Draw.color(control.getInput().cursorNear() ? Color.PURPLE : Color.RED);
Draw.color(control.getInput().cursorNear() ? Colors.get("place") : Colors.get("placeInvalid"));
Draw.linerect(x, y, x2 - x, y2 - y);
Draw.alpha(0.3f);
Draw.crect("blank", x, y, x2 - x, y2 - y);
Draw.color(Color.RED);
Draw.color(Colors.get("placeInvalid"));
int amount = 1;
for(int cx = 0; cx <= Math.abs(endx - tilex); cx ++){
@@ -96,17 +232,17 @@ public enum PlaceMode{
int px = tx + cx * Mathf.sign(ex - tx),
py = ty + cy * Mathf.sign(ey - ty);
if(!world.validPlace(px, py, player.recipe.result)
if(!control.getInput().validPlace(px, py, player.recipe.result)
|| !control.hasItems(player.recipe.requirements, amount)){
Draw.square(px * t, py * t, t/2);
Draw.linecrect(px * t + offset.x, py * t + offset.y, t*block.width, t*block.height);
}
amount ++;
}
}
if(player.recipe.result.rotate){
float cx = tilex * t, cy = tiley * t;
Draw.color(Color.ORANGE);
float cx = tx * t, cy = ty * t;
Draw.color(Colors.get("placeRotate"));
Tmp.v1.set(7, 0).rotate(rotation * 90);
Draw.line(cx, cy, cx + Tmp.v1.x, cy + Tmp.v1.y);
}
@@ -114,11 +250,8 @@ public enum PlaceMode{
}
}
public void tapped(int tilex, int tiley, int endx, int endy){
int prev = player.rotation;
public void released(int tilex, int tiley, int endx, int endy){
process(tilex, tiley, endx, endy);
//tilex = this.tilex; tiley = this.tiley;
//endx = this.endx; endy = this.endy;
player.rotation = this.rotation;
@@ -129,9 +262,6 @@ public enum PlaceMode{
tiley + y * Mathf.sign(endy - tiley));
}
}
player.rotation = prev;
}
void process(int tilex, int tiley, int endx, int endy){
@@ -181,7 +311,7 @@ public enum PlaceMode{
public void draw(int tilex, int tiley, int endx, int endy){
Tile tile = world.tile(tilex, tiley);
if(tile != null && world.validBreak(tilex, tiley)){
if(tile != null && control.getInput().validBreak(tilex, tiley)){
if(tile.isLinked())
tile = tile.getLinked();
Vector2 offset = tile.block().getPlaceOffset();
@@ -191,20 +321,29 @@ public enum PlaceMode{
Draw.color(Color.YELLOW, Color.SCARLET, fract);
Draw.linecrect(tile.worldx() + offset.x, tile.worldy() + offset.y, tile.block().width * Vars.tilesize, tile.block().height * Vars.tilesize);
}else if(android && player.breaktime > 0){
Draw.color(Color.YELLOW, Color.SCARLET, fract);
Draw.circle(tile.worldx(), tile.worldy(), 4 + (1f - fract) * 26);
Draw.color(Colors.get("breakStart"), Colors.get("break"), fract);
Draw.polygon(25, tile.worldx() + offset.x, tile.worldy() + offset.y, 4 + (1f - fract) * 26);
}
Draw.reset();
}
}
};
public boolean lockCamera;
public boolean pan = false;
public boolean shown = false;
public boolean showRotate;
public boolean showCancel;
public boolean delete = false;
public void draw(int tilex, int tiley, int endx, int endy){
}
public void tapped(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){
}
}