Added better controller support
This commit is contained in:
@@ -14,6 +14,7 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Configurable;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.scene.utils.Cursors;
|
||||
@@ -67,12 +68,8 @@ public class AndroidInput extends InputHandler{
|
||||
mousex = screenX;
|
||||
mousey = screenY;
|
||||
}
|
||||
|
||||
if(pointer != 0){
|
||||
placing = false;
|
||||
}else{
|
||||
placing = true;
|
||||
}
|
||||
|
||||
placing = pointer == 0;
|
||||
|
||||
warmup = 0;
|
||||
|
||||
@@ -121,6 +118,19 @@ public class AndroidInput extends InputHandler{
|
||||
public void update(){
|
||||
enableHold = player.breakMode == PlaceMode.holdDelete;
|
||||
|
||||
float scl = Settings.getInt("sensitivity")/100f * Unit.dp.scl(1f);
|
||||
float xa = Inputs.getAxis("move_x");
|
||||
float ya = Inputs.getAxis("move_y");
|
||||
if(Math.abs(xa) < Vars.controllerMin) xa = 0;
|
||||
if(Math.abs(ya) < Vars.controllerMin) ya = 0;
|
||||
|
||||
player.x += xa * 4f;
|
||||
player.y += ya * 4f;
|
||||
|
||||
player.rotation += Inputs.getAxis("rotate_alt");
|
||||
player.rotation += Inputs.getAxis("rotate");
|
||||
player.rotation = Mathf.mod(player.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();
|
||||
|
||||
@@ -27,10 +27,6 @@ public class DesktopInput extends InputHandler{
|
||||
int endx, endy;
|
||||
private boolean enableHold = false;
|
||||
private boolean beganBreak;
|
||||
|
||||
public DesktopInput(){
|
||||
|
||||
}
|
||||
|
||||
@Override public float getCursorEndX(){ return endx; }
|
||||
@Override public float getCursorEndY(){ return endy; }
|
||||
@@ -38,30 +34,25 @@ public class DesktopInput extends InputHandler{
|
||||
@Override public float getCursorY(){ return (int)(Gdx.graphics.getHeight() - 1 - Graphics.screen(mousex, mousey).y); }
|
||||
@Override public boolean drawPlace(){ return !beganBreak; }
|
||||
|
||||
@Override
|
||||
public boolean touchDown (int screenX, int screenY, int pointer, int button){
|
||||
if((button == Buttons.LEFT && player.recipe != null) || (button == Buttons.RIGHT)){
|
||||
Vector2 vec = Graphics.world(screenX, screenY);
|
||||
mousex = (int)vec.x;
|
||||
mousey = (int)vec.y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean touchUp(int screenX, int screenY, int pointer, int button){
|
||||
if(button == Buttons.LEFT){
|
||||
player.placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}else if(button == Buttons.RIGHT && !beganBreak){
|
||||
player.breakMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
if(player.isDead()) return;
|
||||
|
||||
if(!Inputs.buttonDown(Buttons.LEFT) && !Inputs.buttonDown(Buttons.RIGHT)){
|
||||
if(Inputs.keyRelease("select")){
|
||||
player.placeMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}
|
||||
|
||||
if(Inputs.keyRelease("break") && !beganBreak){
|
||||
player.breakMode.released(getBlockX(), getBlockY(), getBlockEndX(), getBlockEndY());
|
||||
}
|
||||
|
||||
if((Inputs.keyTap("select") && player.recipe != null) || Inputs.keyTap("break")){
|
||||
Vector2 vec = Graphics.world(Gdx.input.getX(), Gdx.input.getY());
|
||||
mousex = (int)vec.x;
|
||||
mousey = (int)vec.y;
|
||||
}
|
||||
|
||||
if(!Inputs.keyDown("select") && !Inputs.keyDown("break")){
|
||||
mousex = (int)Graphics.mouseWorld().x;
|
||||
mousey = (int)Graphics.mouseWorld().y;
|
||||
}
|
||||
@@ -77,7 +68,7 @@ public class DesktopInput extends InputHandler{
|
||||
player.rotation += Inputs.getAxis("rotate");
|
||||
player.rotation = Mathf.mod(player.rotation, 4);
|
||||
|
||||
if(Inputs.buttonDown(Buttons.RIGHT)){
|
||||
if(Inputs.keyDown("break")){
|
||||
player.breakMode = PlaceMode.areaDelete;
|
||||
}else{
|
||||
player.breakMode = PlaceMode.hold;
|
||||
@@ -92,7 +83,7 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
Tile cursor = world.tile(tilex(), tiley());
|
||||
|
||||
if(Inputs.buttonUp(Buttons.LEFT) && cursor != null && !ui.hasMouse()){
|
||||
if(Inputs.keyTap("select") && cursor != null && !ui.hasMouse()){
|
||||
Tile linked = cursor.isLinked() ? cursor.getLinked() : cursor;
|
||||
if(linked != null && linked.block() instanceof Configurable){
|
||||
ui.showConfig(linked);
|
||||
@@ -101,25 +92,24 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
}
|
||||
|
||||
if(Inputs.buttonUp(Buttons.RIGHT)){
|
||||
if(Inputs.keyTap("break")){
|
||||
ui.hideConfig();
|
||||
}
|
||||
|
||||
if(Inputs.buttonRelease(Buttons.RIGHT)){
|
||||
if(Inputs.keyRelease("break")){
|
||||
beganBreak = false;
|
||||
}
|
||||
|
||||
if(player.recipe != null && Inputs.buttonUp(Buttons.RIGHT)){
|
||||
if(player.recipe != null && Inputs.keyTap("break")){
|
||||
beganBreak = true;
|
||||
player.recipe = null;
|
||||
Cursors.restoreCursor();
|
||||
}
|
||||
|
||||
//block breaking
|
||||
if(enableHold && Inputs.buttonDown(Buttons.RIGHT) && cursor != null && validBreak(tilex(), tiley())){
|
||||
Tile tile = cursor;
|
||||
if(enableHold && Inputs.keyDown("break") && cursor != null && validBreak(tilex(), tiley())){
|
||||
player.breaktime += Timers.delta();
|
||||
if(player.breaktime >= tile.getBreakTime()){
|
||||
if(player.breaktime >= cursor.getBreakTime()){
|
||||
breakBlock(cursor.x, cursor.y, true);
|
||||
player.breaktime = 0f;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
public class GestureHandler extends GestureAdapter{
|
||||
@@ -44,7 +45,9 @@ public class GestureHandler extends GestureAdapter{
|
||||
|
||||
@Override
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY){
|
||||
if(!(player.recipe != null && Vars.control.hasItems(player.recipe.requirements) && player.placeMode.lockCamera) &&
|
||||
if(Vars.control.showCursor() && !Inputs.keyDown("select")) return false;
|
||||
|
||||
if(!Vars.control.showCursor() && !(player.recipe != null && Vars.control.hasItems(player.recipe.requirements) && player.placeMode.lockCamera) &&
|
||||
!(player.recipe == null && player.breakMode.lockCamera)){
|
||||
player.x -= deltaX*Core.camera.zoom/Core.cameraScale;
|
||||
player.y += deltaY*Core.camera.zoom/Core.cameraScale;
|
||||
|
||||
@@ -233,7 +233,7 @@ public enum PlaceMode{
|
||||
}
|
||||
|
||||
public void draw(int tilex, int tiley, int endx, int endy){
|
||||
if(Vars.android && !Gdx.input.isTouched(0)){
|
||||
if(Vars.android && !Gdx.input.isTouched(0) && !Vars.control.showCursor()){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user