Rewrite of all static initialization code
This commit is contained in:
@@ -2,12 +2,14 @@ package io.anuke.mindustry.input;
|
||||
|
||||
import com.badlogic.gdx.input.GestureDetector;
|
||||
import com.badlogic.gdx.input.GestureDetector.GestureListener;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.type.Recipe;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
@@ -23,6 +25,8 @@ import io.anuke.ucore.util.Mathf;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class AndroidInput extends InputHandler implements GestureListener{
|
||||
private static Rectangle r1 = new Rectangle(), r2 = new Rectangle();
|
||||
|
||||
//gesture data
|
||||
private Vector2 pinch1 = new Vector2(-1, -1), pinch2 = pinch1.cpy();
|
||||
private Vector2 vector = new Vector2();
|
||||
@@ -39,13 +43,51 @@ public class AndroidInput extends InputHandler implements GestureListener{
|
||||
Inputs.addProcessor(new GestureDetector(20, 0.5f, 2, 0.15f, this));
|
||||
}
|
||||
|
||||
/**Returns whether this tile is in the list of requests, or at least colliding with one.*/
|
||||
boolean hasRequest(Tile tile){
|
||||
return getRequest(tile) != null;
|
||||
}
|
||||
|
||||
/**Returns whether this block overlaps any placement requests.*/
|
||||
boolean checkOverlapPlacement(int x, int y, Block block){
|
||||
r2.setSize(block.size * tilesize);
|
||||
r2.setCenter(x * tilesize + block.offset(), y * tilesize + block.offset());
|
||||
|
||||
for(PlaceRequest req : placement){
|
||||
if(req.tile() == tile) return true;
|
||||
Tile other = req.tile();
|
||||
|
||||
if(other == null) continue;
|
||||
|
||||
r1.setSize(req.recipe.result.size * tilesize);
|
||||
r1.setCenter(other.worldx() + req.recipe.result.offset(), other.worldy() + req.recipe.result.offset());
|
||||
|
||||
if(r2.overlaps(r1)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**Returns the placement request that overlaps this tile, or null.*/
|
||||
PlaceRequest getRequest(Tile tile){
|
||||
r2.setSize(tilesize);
|
||||
r2.setCenter(tile.worldx(), tile.worldy());
|
||||
|
||||
for(PlaceRequest req : placement){
|
||||
Tile other = req.tile();
|
||||
|
||||
if(other == null) continue;
|
||||
|
||||
r1.setSize(req.recipe.result.size * tilesize);
|
||||
r1.setCenter(other.worldx() + req.recipe.result.offset(), other.worldy() + req.recipe.result.offset());
|
||||
|
||||
if(r2.overlaps(r1)){
|
||||
return req;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildUI(Group group) {
|
||||
|
||||
@@ -122,6 +164,24 @@ public class AndroidInput extends InputHandler implements GestureListener{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean longPress(float x, float y) {
|
||||
if(state.is(State.menu)) return false;
|
||||
|
||||
//get tile on cursor
|
||||
Tile cursor = world.tile(Mathf.scl2(Graphics.mouseWorld().x, tilesize), Mathf.scl2(Graphics.mouseWorld().y, tilesize));
|
||||
|
||||
//ignore off-screen taps
|
||||
if(cursor == null || ui.hasMouse(x, y)) return false;
|
||||
|
||||
//remove request if it's there
|
||||
if(hasRequest(cursor)){
|
||||
placement.removeValue(getRequest(cursor), true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count, int button) {
|
||||
if(state.is(State.menu)) return false;
|
||||
@@ -133,7 +193,7 @@ public class AndroidInput extends InputHandler implements GestureListener{
|
||||
if(cursor == null || ui.hasMouse(x, y)) return false;
|
||||
|
||||
//add to placement queue if it's a valid place position
|
||||
if(isPlacing() && validPlace(cursor.x, cursor.y, recipe.result)){
|
||||
if(isPlacing() && validPlace(cursor.x, cursor.y, recipe.result) && !checkOverlapPlacement(cursor.x, cursor.y, recipe.result)){
|
||||
placement.add(new PlaceRequest(cursor.worldx(), cursor.worldy(), recipe, rotation));
|
||||
}
|
||||
|
||||
@@ -215,7 +275,6 @@ public class AndroidInput extends InputHandler implements GestureListener{
|
||||
}
|
||||
|
||||
@Override public boolean touchDown(float x, float y, int pointer, int button) { return false; }
|
||||
@Override public boolean longPress(float x, float y) { return false; }
|
||||
@Override public boolean fling(float velocityX, float velocityY, int button) { return false; }
|
||||
|
||||
class PlaceRequest{
|
||||
|
||||
@@ -25,8 +25,8 @@ import io.anuke.ucore.util.Translator;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public abstract class InputHandler extends InputAdapter{
|
||||
public final static float playerSelectRange = Unit.dp.scl(60f);
|
||||
private final static Translator stackTrns = new Translator();
|
||||
float playerSelectRange = Unit.dp.scl(60f);
|
||||
Translator stackTrns = new Translator();
|
||||
|
||||
private float mx, my;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user