Massive input refactoring
This commit is contained in:
@@ -1,150 +1,237 @@
|
||||
package io.anuke.mindustry.input;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.input.GestureDetector;
|
||||
import com.badlogic.gdx.input.GestureDetector.GestureListener;
|
||||
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.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.type.Recipe;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.scene.builders.imagebutton;
|
||||
import io.anuke.ucore.scene.builders.table;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class AndroidInput extends InputHandler{
|
||||
public float lmousex, lmousey;
|
||||
public float mousex, mousey;
|
||||
public boolean brokeBlock = false;
|
||||
public boolean placing = false;
|
||||
|
||||
private boolean enableHold = false;
|
||||
private float warmup;
|
||||
private float warmupDelay = 20;
|
||||
public class AndroidInput extends InputHandler implements GestureListener{
|
||||
//gesture data
|
||||
private Vector2 pinch1 = new Vector2(-1, -1), pinch2 = pinch1.cpy();
|
||||
private Vector2 vector = new Vector2();
|
||||
private float initzoom = -1;
|
||||
private boolean zoomed = false;
|
||||
|
||||
/**List of currently selected tiles to place.*/
|
||||
private Array<PlaceRequest> placement = new Array<>();
|
||||
/**Whether or not the player is currently shifting all placed tiles.*/
|
||||
private boolean selecting;
|
||||
|
||||
public AndroidInput(Player player){
|
||||
super(player);
|
||||
Inputs.addProcessor(new GestureDetector(20, 0.5f, 2, 0.15f, new GestureHandler(this)));
|
||||
Inputs.addProcessor(new GestureDetector(20, 0.5f, 2, 0.15f, this));
|
||||
}
|
||||
|
||||
@Override public float getCursorEndX(){ return Gdx.input.getX(0); }
|
||||
@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 && !brokeBlock) || (placeMode.pan && recipe != null); }
|
||||
|
||||
@Override
|
||||
public boolean touchUp(int screenX, int screenY, int pointer, int button){
|
||||
if(brokeBlock){
|
||||
brokeBlock = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(placing && pointer == 0 && !placeMode.pan && !breaking()){
|
||||
placeMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}else if(pointer == 0 && !breakMode.pan && breaking() && drawPlace()){
|
||||
breakMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}
|
||||
boolean hasRequest(Tile tile){
|
||||
for(PlaceRequest req : placement){
|
||||
if(req.tile() == tile) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
placing = false;
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void buildUI(Group group) {
|
||||
|
||||
//Create confirm/cancel table
|
||||
new table(){{
|
||||
abottom().aleft();
|
||||
defaults().size(60f);
|
||||
|
||||
//Add a cancel button, which clears the selection.
|
||||
new imagebutton("icon-cancel", 14*2f, () -> {
|
||||
placement.clear();
|
||||
selecting = false;
|
||||
});
|
||||
|
||||
//Add an accept button, which places everything.
|
||||
new imagebutton("icon-check", 14*2f, () -> {
|
||||
for(PlaceRequest request : placement){
|
||||
Tile tile = request.tile();
|
||||
|
||||
if(tile != null){
|
||||
rotation = request.rotation;
|
||||
recipe = request.recipe;
|
||||
tryPlaceBlock(tile.x, tile.y);
|
||||
}
|
||||
}
|
||||
|
||||
placement.clear();
|
||||
selecting = false;
|
||||
});
|
||||
}}.visible(this::isPlacing).end();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
Draw.color(Palette.accent);
|
||||
|
||||
//Draw all placement requests as squares
|
||||
for(PlaceRequest request : placement){
|
||||
Tile tile = request.tile();
|
||||
if(tile == null) continue;
|
||||
Lines.square(tile.worldx() + request.recipe.result.offset(), tile.worldy() + request.recipe.result.offset(),
|
||||
request.recipe.result.size * tilesize/2f);
|
||||
}
|
||||
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
||||
if(ui.hasMouse()){
|
||||
brokeBlock = true;
|
||||
return false;
|
||||
}
|
||||
if(state.is(State.menu)) return false;
|
||||
|
||||
lmousex = screenX;
|
||||
lmousey = screenY;
|
||||
|
||||
if((!placeMode.pan || breaking()) && pointer == 0){
|
||||
mousex = screenX;
|
||||
mousey = screenY;
|
||||
}
|
||||
//get tile on cursor
|
||||
Tile cursor = world.tile(Mathf.scl2(Graphics.mouseWorld().x, tilesize), Mathf.scl2(Graphics.mouseWorld().y, tilesize));
|
||||
|
||||
placing = pointer == 0;
|
||||
|
||||
warmup = 0;
|
||||
//ignore off-screen taps
|
||||
if(cursor == null || ui.hasMouse(screenX, screenY)) return false;
|
||||
|
||||
if(!state.is(State.menu)){
|
||||
Tile cursor = world.tile(Mathf.scl2(Graphics.mouseWorld().x, tilesize), Mathf.scl2(Graphics.mouseWorld().y, tilesize));
|
||||
if(cursor != null && !ui.hasMouse(screenX, screenY)){
|
||||
Tile linked = cursor.isLinked() ? cursor.getLinked() : cursor;
|
||||
if(linked != null && linked.block().isConfigurable(linked)){
|
||||
frag.config.showConfig(linked);
|
||||
}else if(!frag.config.hasConfigMouse()){
|
||||
frag.config.hideConfig();
|
||||
}
|
||||
//only begin selecting if the tapped block is a request
|
||||
selecting = hasRequest(cursor);
|
||||
|
||||
Tile linked = cursor.target();
|
||||
|
||||
//show-hide configuration fragment for blocks
|
||||
if(linked.block().isConfigurable(linked)){
|
||||
frag.config.showConfig(linked);
|
||||
}else if(!frag.config.hasConfigMouse()){
|
||||
frag.config.hideConfig();
|
||||
}
|
||||
|
||||
//call tapped() event
|
||||
//TODO net event for block tapped
|
||||
linked.block().tapped(linked, player);
|
||||
|
||||
if(linked != null) {
|
||||
linked.block().tapped(linked, player);
|
||||
if(Net.active()) NetEvents.handleBlockTap(linked);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetCursor(){
|
||||
mousex = Gdx.graphics.getWidth()/2;
|
||||
mousey = Gdx.graphics.getHeight()/2;
|
||||
}
|
||||
|
||||
public Tile selected(){
|
||||
Vector2 vec = Graphics.world(mousex, mousey);
|
||||
return world.tile(Mathf.scl2(vec.x, tilesize), Mathf.scl2(vec.y, tilesize));
|
||||
}
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count, int button) {
|
||||
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;
|
||||
|
||||
//add to placement queue if it's a valid place position
|
||||
if(isPlacing() && validPlace(cursor.x, cursor.y, recipe.result)){
|
||||
placement.add(new PlaceRequest(cursor.worldx(), cursor.worldy(), recipe, rotation));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
enableHold = breakMode == PlaceMode.holdDelete;
|
||||
|
||||
float xa = Inputs.getAxis("move_x");
|
||||
float ya = Inputs.getAxis("move_y");
|
||||
if(Math.abs(xa) < controllerMin) xa = 0;
|
||||
if(Math.abs(ya) < controllerMin) ya = 0;
|
||||
|
||||
player.x += xa * 4f;
|
||||
player.y += ya * 4f;
|
||||
|
||||
rotation += Inputs.getAxis("rotate_alt");
|
||||
rotation += Inputs.getAxis("rotate");
|
||||
rotation = Mathf.mod(rotation, 4);
|
||||
|
||||
if(enableHold && Gdx.input.isTouched(0) && Mathf.near2d(lmousex, lmousey, Gdx.input.getX(0), Gdx.input.getY(0), Unit.dp.scl(50))
|
||||
&& !ui.hasMouse()){
|
||||
warmup += Timers.delta();
|
||||
|
||||
float lx = mousex, ly = mousey;
|
||||
|
||||
mousex = Gdx.input.getX(0);
|
||||
mousey = Gdx.input.getY(0);
|
||||
|
||||
Tile sel = selected();
|
||||
|
||||
if(sel == null)
|
||||
return;
|
||||
|
||||
mousex = lx;
|
||||
mousey = ly;
|
||||
}else{
|
||||
warmup = 0;
|
||||
breaktime = 0;
|
||||
|
||||
mousex = Mathf.clamp(mousex, 0, Gdx.graphics.getWidth());
|
||||
mousey = Mathf.clamp(mousey, 0, Gdx.graphics.getHeight());
|
||||
}
|
||||
if(!isPlacing()){
|
||||
selecting = false;
|
||||
placement.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean breaking(){
|
||||
return recipe == null;
|
||||
}
|
||||
@Override
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY){
|
||||
float dx = deltaX * Core.camera.zoom / Core.cameraScale, dy = deltaY * Core.camera.zoom / Core.cameraScale;
|
||||
|
||||
if(selecting){
|
||||
for(PlaceRequest req : placement){
|
||||
req.x += dx;
|
||||
req.y -= dy;
|
||||
}
|
||||
}else{
|
||||
player.x -= dx;
|
||||
player.y += dy;
|
||||
player.targetAngle = Mathf.atan2(dx, -dy) + 180f;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean panStop(float x, float y, int pointer, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pinch (Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
|
||||
if(pinch1.x < 0){
|
||||
pinch1.set(initialPointer1);
|
||||
pinch2.set(initialPointer2);
|
||||
}
|
||||
|
||||
Vector2 vec = (vector.set(pointer1).add(pointer2).scl(0.5f)).sub(pinch1.add(pinch2).scl(0.5f));
|
||||
|
||||
player.x -= vec.x*Core.camera.zoom/Core.cameraScale;
|
||||
player.y += vec.y*Core.camera.zoom/Core.cameraScale;
|
||||
|
||||
pinch1.set(pointer1);
|
||||
pinch2.set(pointer2);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean zoom(float initialDistance, float distance){
|
||||
if(initzoom < 0){
|
||||
initzoom = initialDistance;
|
||||
}
|
||||
|
||||
if(Math.abs(distance - initzoom) > Unit.dp.scl(100f) && !zoomed){
|
||||
int amount = (distance > initzoom ? 1 : -1);
|
||||
renderer.scaleCamera(Math.round(Unit.dp.scl(amount)));
|
||||
initzoom = distance;
|
||||
zoomed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pinchStop () {
|
||||
initzoom = -1;
|
||||
pinch2.set(pinch1.set(-1, -1));
|
||||
zoomed = false;
|
||||
}
|
||||
|
||||
@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{
|
||||
float x, y;
|
||||
Recipe recipe;
|
||||
int rotation;
|
||||
|
||||
PlaceRequest(float x, float y, Recipe recipe, int rotation) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.recipe = recipe;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
Tile tile(){
|
||||
return world.tileWorld(x - recipe.result.offset(), y - recipe.result.offset());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,26 +32,12 @@ public class DesktopInput extends InputHandler{
|
||||
this.index = player.playerIndex;
|
||||
this.section = "player_" + (player.playerIndex + 1);
|
||||
}
|
||||
|
||||
@Override public float getCursorEndX(){ return endx; }
|
||||
@Override public float getCursorEndY(){ return endy; }
|
||||
@Override public float getCursorX(){ return prmousex; }
|
||||
@Override public float getCursorY(){ return prmousey; }
|
||||
@Override public boolean drawPlace(){ return !beganBreak; }
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
|
||||
if(player.isDead()) return;
|
||||
|
||||
if(Inputs.keyRelease(section, "select") && recipe != null){
|
||||
placeMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}
|
||||
|
||||
if(Inputs.keyRelease(section, "break") && !beganBreak){
|
||||
breakMode.released(this, getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}
|
||||
|
||||
if(!Inputs.keyDown(section, "select")){
|
||||
shooting = false;
|
||||
}
|
||||
@@ -97,12 +83,6 @@ public class DesktopInput extends InputHandler{
|
||||
rotation += Inputs.getAxis(section,"rotate");
|
||||
|
||||
rotation = Mathf.mod(rotation, 4);
|
||||
|
||||
if(Inputs.keyDown(section,"break")){
|
||||
breakMode = PlaceMode.areaDelete;
|
||||
}else{
|
||||
breakMode = PlaceMode.hold;
|
||||
}
|
||||
|
||||
int keyIndex = 1;
|
||||
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
package io.anuke.mindustry.input;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.input.GestureDetector.GestureAdapter;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class GestureHandler extends GestureAdapter{
|
||||
AndroidInput input;
|
||||
Vector2 pinch1 = new Vector2(-1, -1), pinch2 = pinch1.cpy();
|
||||
Vector2 vector = new Vector2();
|
||||
float initzoom = -1;
|
||||
boolean zoomed = false;
|
||||
|
||||
GestureHandler(AndroidInput input){
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean longPress(float x, float y){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap (float x, float y, int count, int button) {
|
||||
if(ui.hasMouse() || input.brokeBlock) return false;
|
||||
|
||||
if(!input.placeMode.pan || input.recipe == null){
|
||||
input.mousex = x;
|
||||
input.mousey = y;
|
||||
|
||||
if(input.recipe == null)
|
||||
input.breakMode.tapped(input, input.getBlockX(), input.getBlockY());
|
||||
else
|
||||
input.placeMode.tapped(input, input.getBlockX(), input.getBlockY());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY){
|
||||
if(input.isCursorVisible() && !Inputs.keyDown("select")) return false;
|
||||
|
||||
if(!input.isCursorVisible() && !(input.recipe != null
|
||||
&& input.placeMode.lockCamera) &&
|
||||
!(input.recipe == null && input.breakMode.lockCamera)){
|
||||
float dx = deltaX*Core.camera.zoom/Core.cameraScale, dy = deltaY*Core.camera.zoom/Core.cameraScale;
|
||||
input.player.x -= dx;
|
||||
input.player.y += dy;
|
||||
input.player.targetAngle = Mathf.atan2(dx, -dy) + 180f;
|
||||
}else if(input.placeMode.lockCamera && (input.placeMode.pan && input.recipe != null)){
|
||||
input.mousex += deltaX;
|
||||
input.mousey += deltaY;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pinch (Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
|
||||
if(input.recipe == null && !input.breakMode.lockCamera)
|
||||
return false;
|
||||
|
||||
if(pinch1.x < 0){
|
||||
pinch1.set(initialPointer1);
|
||||
pinch2.set(initialPointer2);
|
||||
}
|
||||
|
||||
Vector2 vec = (vector.set(pointer1).add(pointer2).scl(0.5f)).sub(pinch1.add(pinch2).scl(0.5f));
|
||||
|
||||
input.player.x -= vec.x*Core.camera.zoom/Core.cameraScale;
|
||||
input.player.y += vec.y*Core.camera.zoom/Core.cameraScale;
|
||||
|
||||
pinch1.set(pointer1);
|
||||
pinch2.set(pointer2);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean zoom(float initialDistance, float distance){
|
||||
if(initzoom < 0){
|
||||
initzoom = initialDistance;
|
||||
}
|
||||
|
||||
if(Math.abs(distance - initzoom) > Unit.dp.scl(100f) && !zoomed){
|
||||
int amount = (distance > initzoom ? 1 : -1);
|
||||
renderer.scaleCamera(Math.round(Unit.dp.scl(amount)));
|
||||
initzoom = distance;
|
||||
zoomed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pinchStop () {
|
||||
initzoom = -1;
|
||||
pinch2.set(pinch1.set(-1, -1));
|
||||
zoomed = false;
|
||||
}
|
||||
|
||||
int touches(){
|
||||
int sum = 0;
|
||||
for(int i = 0; i < 10; i ++){
|
||||
if(Gdx.input.isTouched(i)) sum++;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
@@ -27,37 +28,61 @@ public abstract class InputHandler extends InputAdapter{
|
||||
public final static float playerSelectRange = Unit.dp.scl(60f);
|
||||
private final static Translator stackTrns = new Translator();
|
||||
|
||||
public float breaktime = 0;
|
||||
private float mx, my;
|
||||
|
||||
public final Player player;
|
||||
public final OverlayFragment frag = new OverlayFragment(this);
|
||||
|
||||
public Recipe recipe;
|
||||
public int rotation;
|
||||
public Player player;
|
||||
public PlaceMode placeMode = mobile ? PlaceMode.cursor : PlaceMode.hold;
|
||||
public PlaceMode breakMode = mobile ? PlaceMode.none : PlaceMode.holdDelete;
|
||||
public PlaceMode lastPlaceMode = placeMode;
|
||||
public PlaceMode lastBreakMode = breakMode;
|
||||
public boolean droppingItem, transferring;
|
||||
public boolean shooting;
|
||||
public OverlayFragment frag = new OverlayFragment(this);
|
||||
|
||||
public InputHandler(Player player){
|
||||
this.player = player;
|
||||
Timers.run(1f, () -> frag.build(Core.scene.getRoot()));
|
||||
}
|
||||
|
||||
public abstract void update();
|
||||
public abstract float getCursorX();
|
||||
public abstract float getCursorY();
|
||||
public abstract float getCursorEndX();
|
||||
public abstract float getCursorEndY();
|
||||
public float getMouseX(){ return Gdx.input.getX(); };
|
||||
public float getMouseY(){ return Gdx.input.getY(); };
|
||||
public int getBlockX(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).x, tilesize, round2()); }
|
||||
public int getBlockY(){ return Mathf.sclb(Graphics.world(getCursorX(), getCursorY()).y, tilesize, round2()); }
|
||||
public int getBlockEndX(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).x, tilesize, round2()); }
|
||||
public int getBlockEndY(){ return Mathf.sclb(Graphics.world(getCursorEndX(), getCursorEndY()).y, tilesize, round2()); }
|
||||
public void resetCursor(){}
|
||||
public boolean isCursorVisible(){ return false; }
|
||||
public void updateController(){}
|
||||
//methods to override
|
||||
|
||||
public void update(){
|
||||
|
||||
}
|
||||
|
||||
public float getMouseX(){
|
||||
return mx;
|
||||
}
|
||||
|
||||
public float getMouseY(){
|
||||
return my;
|
||||
}
|
||||
|
||||
public void resetCursor(){
|
||||
|
||||
}
|
||||
|
||||
public boolean isCursorVisible(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public void updateController(){
|
||||
mx = Gdx.input.getX();
|
||||
my = Gdx.input.getY();
|
||||
}
|
||||
|
||||
public void buildUI(Group group){
|
||||
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
|
||||
}
|
||||
|
||||
//utility methods
|
||||
|
||||
public boolean isPlacing(){
|
||||
return recipe != null;
|
||||
}
|
||||
|
||||
public float mouseAngle(float x, float y){
|
||||
return Graphics.world(getMouseX(), getMouseY()).sub(x, y).angle();
|
||||
@@ -75,12 +100,9 @@ public abstract class InputHandler extends InputAdapter{
|
||||
public boolean isShooting(){
|
||||
return shooting;
|
||||
}
|
||||
|
||||
public boolean drawPlace(){ return true; }
|
||||
|
||||
public boolean onConfigurable(){
|
||||
Tile tile = world.tile(getBlockX(), getBlockY());
|
||||
return tile != null && (tile.block().isConfigurable(tile) || (tile.isLinked() && tile.getLinked().block().isConfigurable(tile)));
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDroppingItem(){
|
||||
@@ -129,26 +151,8 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
});
|
||||
}
|
||||
}else{
|
||||
//TODO create drop on the ground
|
||||
/*
|
||||
Vector2 vec = Graphics.screen(player.x, player.y);
|
||||
|
||||
if(vec.dst(Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY()) > playerSelectRange) {
|
||||
int sent = Mathf.clamp(stack.amount / 4, 1, 8);
|
||||
float backTrns = 3f;
|
||||
for (int i = 0; i < sent; i++) {
|
||||
Timers.run(i, () -> {
|
||||
float x = player.x + Angles.trnsx(rotation + 180f, backTrns),
|
||||
y = player.y + Angles.trnsy(rotation + 180f, backTrns);
|
||||
|
||||
ItemTransfer.create(stack.item,
|
||||
x, y, x + Mathf.range(20f), y + Mathf.range(20f), () -> {});
|
||||
});
|
||||
}
|
||||
player.inventory.clear();
|
||||
}*/
|
||||
}
|
||||
//TODO create drop on the ground otherwise
|
||||
}
|
||||
|
||||
public boolean cursorNear(){
|
||||
@@ -156,8 +160,7 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
|
||||
public boolean tryPlaceBlock(int x, int y){
|
||||
if(recipe != null &&
|
||||
validPlace(x, y, recipe.result) && !ui.hasMouse() && cursorNear()){
|
||||
if(recipe != null && validPlace(x, y, recipe.result) && cursorNear()){
|
||||
|
||||
placeBlock(x, y, recipe, rotation);
|
||||
|
||||
@@ -174,10 +177,6 @@ public abstract class InputHandler extends InputAdapter{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean round2(){
|
||||
return !(recipe != null && recipe.result.isMultiblock() && recipe.result.size % 2 == 0);
|
||||
}
|
||||
|
||||
public boolean validPlace(int x, int y, Block type){
|
||||
for(Tile tile : state.teams.get(player.team).cores){
|
||||
if(tile.distanceTo(x * tilesize, y * tilesize) < coreBuildRange){
|
||||
|
||||
@@ -3,10 +3,8 @@ package io.anuke.mindustry.input;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.graphics.Shaders;
|
||||
import io.anuke.mindustry.ui.fragments.ToolFragment;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Build;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@@ -34,14 +32,14 @@ public enum PlaceMode{
|
||||
float y = tiley * tilesize;
|
||||
|
||||
boolean valid = input.validPlace(tilex, tiley, input.recipe.result) && (mobile || input.cursorNear());
|
||||
|
||||
Vector2 offset = input.recipe.result.getPlaceOffset();
|
||||
|
||||
float offset = input.recipe.result.offset();
|
||||
|
||||
float si = MathUtils.sin(Timers.time() / 6f) + 1.5f;
|
||||
|
||||
Draw.color(valid ? Palette.place : Palette.remove);
|
||||
Lines.stroke(2f);
|
||||
Lines.crect(x + offset.x, y + offset.y, tilesize * input.recipe.result.size + si,
|
||||
Lines.crect(x + offset, y + offset, tilesize * input.recipe.result.size + si,
|
||||
tilesize * input.recipe.result.size + si);
|
||||
|
||||
input.recipe.result.drawPlace(tilex, tiley, input.rotation, valid);
|
||||
@@ -77,29 +75,6 @@ public enum PlaceMode{
|
||||
both = true;
|
||||
}
|
||||
},
|
||||
holdDelete{
|
||||
{
|
||||
delete = true;
|
||||
shown = true;
|
||||
both = true;
|
||||
}
|
||||
|
||||
public void draw(InputHandler input, int tilex, int tiley, int endx, int endy){
|
||||
Tile tile = world.tile(tilex, tiley);
|
||||
|
||||
if(tile != null && input.validBreak(tilex, tiley)){
|
||||
if(tile.isLinked())
|
||||
tile = tile.getLinked();
|
||||
float fin = input.breaktime / tile.getBreakTime();
|
||||
|
||||
if(mobile && input.breaktime > 0){
|
||||
Draw.color(Palette.place, Palette.remove, fin);
|
||||
Lines.poly(tile.drawx(), tile.drawy(), 25, 4 + (1f - fin) * 26);
|
||||
}
|
||||
Draw.reset();
|
||||
}
|
||||
}
|
||||
},
|
||||
touchDelete{
|
||||
{
|
||||
shown = true;
|
||||
@@ -174,18 +149,6 @@ public enum PlaceMode{
|
||||
|
||||
input.player.clearBuilding();
|
||||
|
||||
if(mobile){
|
||||
ToolFragment t = input.frag.tool;
|
||||
if(!t.confirming || t.px != tilex || t.py != tiley || t.px2 != endx || t.py2 != endy) {
|
||||
t.confirming = true;
|
||||
t.px = tilex;
|
||||
t.py = tiley;
|
||||
t.px2 = endx;
|
||||
t.py2 = endy;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for(int cx = tilex; cx <= endx; cx ++){
|
||||
for(int cy = tiley; cy <= endy; cy ++){
|
||||
input.tryDeleteBlock(cx, cy);
|
||||
@@ -241,7 +204,7 @@ public enum PlaceMode{
|
||||
|
||||
float t = tilesize;
|
||||
Block block = input.recipe.result;
|
||||
Vector2 offset = block.getPlaceOffset();
|
||||
float offset = block.offset();
|
||||
|
||||
process(input, tilex, tiley, endx, endy);
|
||||
float x = rtilex * t, y = rtiley * t,
|
||||
@@ -257,10 +220,10 @@ public enum PlaceMode{
|
||||
y2 += block.size * t/2;
|
||||
}
|
||||
|
||||
x += offset.x;
|
||||
y += offset.y;
|
||||
x2 += offset.x;
|
||||
y2 += offset.y;
|
||||
x += offset;
|
||||
y += offset;
|
||||
x2 += offset;
|
||||
y2 += offset;
|
||||
|
||||
if(tilex == endx && tiley == endy){
|
||||
cursor.draw(input, tilex, tiley, endx, endy);
|
||||
@@ -285,7 +248,7 @@ public enum PlaceMode{
|
||||
Draw.color(Palette.accent);
|
||||
}
|
||||
|
||||
drawPreview(block, wx * t + offset.x, wy * t + offset.y);
|
||||
drawPreview(block, wx * t + offset, wy * t + offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user