Added better controller support
This commit is contained in:
@@ -10,7 +10,7 @@ import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
public class Vars{
|
||||
public static final boolean testAndroid = false;
|
||||
public static final boolean testAndroid = true;
|
||||
//shorthand for whether or not this is running on android
|
||||
public static final boolean android = (Gdx.app.getType() == ApplicationType.Android) || testAndroid;
|
||||
//shorthand for whether or not this is running on GWT
|
||||
@@ -54,6 +54,10 @@ public class Vars{
|
||||
//whether to hide ui, only on debug
|
||||
public static boolean showUI = true;
|
||||
|
||||
public static float controllerMin = 0.25f;
|
||||
|
||||
public static float baseControllerSpeed = 11f;
|
||||
|
||||
public static final int saveSlots = 10;
|
||||
//amount of drops that are left when breaking a block
|
||||
public static final float breakDropAmount = 0.5f;
|
||||
|
||||
@@ -36,6 +36,7 @@ import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.graphics.Atlas;
|
||||
import io.anuke.ucore.modules.Module;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
import io.anuke.ucore.util.Input;
|
||||
import io.anuke.ucore.util.InputProxy;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
@@ -102,6 +103,16 @@ public class Control extends Module{
|
||||
public int getX() {
|
||||
return controlling ? (int)controlx : input.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY(int pointer) {
|
||||
return pointer == 0 ? getY() : super.getY(pointer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX(int pointer) {
|
||||
return pointer == 0 ? getX() : super.getX(pointer);
|
||||
}
|
||||
};
|
||||
|
||||
Inputs.addProcessor(input);
|
||||
@@ -122,6 +133,8 @@ public class Control extends Module{
|
||||
KeyBinds.defaults(
|
||||
"move_x", new Axis(Input.A, Input.D),
|
||||
"move_y", new Axis(Input.S, Input.W),
|
||||
"select", Input.MOUSE_LEFT,
|
||||
"break", Input.MOUSE_RIGHT,
|
||||
"shoot", Input.MOUSE_LEFT,
|
||||
"zoom_hold", Input.CONTROL_LEFT,
|
||||
"zoom", new Axis(Input.SCROLL),
|
||||
@@ -145,14 +158,15 @@ public class Control extends Module{
|
||||
"cursor_x", new Axis(Input.CONTROLLER_R_STICK_HORIZONTAL_AXIS),
|
||||
"cursor_y", new Axis(Input.CONTROLLER_R_STICK_VERTICAL_AXIS),
|
||||
"select", Input.CONTROLLER_R_BUMPER,
|
||||
"shoot", Input.CONTROLLER_Y,
|
||||
"break", Input.CONTROLLER_L_BUMPER,
|
||||
"shoot", Input.CONTROLLER_R_TRIGGER,
|
||||
"zoom_hold", Input.ANY_KEY,
|
||||
"zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP),
|
||||
"menu", Input.CONTROLLER_X,
|
||||
"pause", Input.CONTROLLER_L_BUMPER,
|
||||
"dash", Input.CONTROLLER_B,
|
||||
"pause", Input.CONTROLLER_L_TRIGGER,
|
||||
"dash", Input.CONTROLLER_Y,
|
||||
"rotate_alt", new Axis(Input.UNSET),
|
||||
"rotate", new Axis(Input.CONTROLLER_DPAD_LEFT, Input.CONTROLLER_DPAD_RIGHT),
|
||||
"rotate", new Axis(Input.CONTROLLER_A, Input.CONTROLLER_B),
|
||||
"weapon_1", Input.NUM_1,
|
||||
"weapon_2", Input.NUM_2,
|
||||
"weapon_3", Input.NUM_3,
|
||||
@@ -494,23 +508,23 @@ public class Control extends Module{
|
||||
|
||||
if(KeyBinds.getSection("default").device.type == DeviceType.controller){
|
||||
if(Inputs.keyTap("select")){
|
||||
UCore.log("Select.");
|
||||
Core.scene.touchDown(Gdx.input.getX(), Gdx.input.getY(), 0, Buttons.LEFT);
|
||||
Inputs.getProcessor().touchDown(Gdx.input.getX(), Gdx.input.getY(), 0, Buttons.LEFT);
|
||||
}
|
||||
|
||||
if(Inputs.keyRelease("select")){
|
||||
Core.scene.touchUp(Gdx.input.getX(), Gdx.input.getY(), 0, Buttons.LEFT);
|
||||
Inputs.getProcessor().touchUp(Gdx.input.getX(), Gdx.input.getY(), 0, Buttons.LEFT);
|
||||
}
|
||||
|
||||
float xa = Inputs.getAxis("cursor_x");
|
||||
float ya = Inputs.getAxis("cursor_y");
|
||||
|
||||
if(Math.abs(xa) > 0.3 || Math.abs(ya) > 0.3) {
|
||||
controlx += xa*10;
|
||||
controly -= ya*10;
|
||||
if(Math.abs(xa) > Vars.controllerMin || Math.abs(ya) > Vars.controllerMin) {
|
||||
float scl = Settings.getInt("sensitivity")/100f * Unit.dp.scl(1f);
|
||||
controlx += xa*Vars.baseControllerSpeed*scl;
|
||||
controly -= ya*Vars.baseControllerSpeed*scl;
|
||||
controlling = true;
|
||||
|
||||
Core.scene.touchDragged(Gdx.input.getX(), Gdx.input.getY(), 0);
|
||||
Inputs.getProcessor().touchDragged(Gdx.input.getX(), Gdx.input.getY(), 0);
|
||||
}
|
||||
|
||||
controlx = Mathf.clamp(controlx, 0, Gdx.graphics.getWidth());
|
||||
@@ -544,7 +558,11 @@ public class Control extends Module{
|
||||
if(Inputs.keyTap(Keys.F)){
|
||||
wavetime = 0f;
|
||||
}
|
||||
|
||||
|
||||
if(Inputs.keyDown(Keys.I)){
|
||||
wavetime -= delta() * 10f;
|
||||
}
|
||||
|
||||
if(Inputs.keyTap(Keys.U)){
|
||||
Vars.showUI = !Vars.showUI;
|
||||
}
|
||||
@@ -608,11 +626,7 @@ public class Control extends Module{
|
||||
|
||||
if(enemies <= 0){
|
||||
wavetime -= delta();
|
||||
|
||||
if(Vars.debug && Inputs.keyDown(Keys.I)){
|
||||
wavetime -= delta() * 10f;
|
||||
}
|
||||
|
||||
|
||||
if(lastUpdated < wave + 1 && wavetime < Vars.aheadPathfinding){ //start updatingbeforehand
|
||||
world.pathfinder().updatePath();
|
||||
lastUpdated = wave + 1;
|
||||
|
||||
@@ -24,6 +24,7 @@ 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.ucore.UCore;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.entities.DestructibleEntity;
|
||||
import io.anuke.ucore.entities.EffectEntity;
|
||||
@@ -369,7 +370,7 @@ public class Renderer extends RendererModule{
|
||||
&& control.input.drawPlace()) || (player.placeMode.delete && Inputs.keyDown("area_delete_mode"))){
|
||||
|
||||
player.placeMode.draw(control.input.getBlockX(), control.input.getBlockY(), control.input.getBlockEndX(), control.input.getBlockEndY());
|
||||
|
||||
|
||||
Draw.thickness(1f);
|
||||
Draw.color(Color.SCARLET);
|
||||
for(SpawnPoint spawn : control.getSpawnPoints()){
|
||||
|
||||
@@ -12,6 +12,8 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import com.badlogic.gdx.utils.IntSet;
|
||||
import com.badlogic.gdx.utils.IntSet.IntSetIterator;
|
||||
import io.anuke.mindustry.Mindustry;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
@@ -160,8 +162,9 @@ public class UI extends SceneModule{
|
||||
|
||||
if(control.showCursor()) {
|
||||
Draw.color();
|
||||
float scl = Unit.dp.scl(3f);
|
||||
scene.getBatch().begin();
|
||||
Draw.rect("icon-close", Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY());
|
||||
Draw.rect("controller-cursor", Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY(), 16*scl, 16*scl);
|
||||
scene.getBatch().end();
|
||||
}
|
||||
}
|
||||
@@ -214,6 +217,7 @@ public class UI extends SceneModule{
|
||||
prefs.game.checkPref("smoothcam", "Smooth Camera", true);
|
||||
prefs.game.checkPref("indicators", "Enemy Indicators", true);
|
||||
prefs.game.checkPref("effects", "Display Effects", true);
|
||||
prefs.game.sliderPref("sensitivity", "Controller Sensitivity", 100, 10, 300, i -> i + "%");
|
||||
|
||||
prefs.graphics.checkPref("fps", "Show FPS", false);
|
||||
prefs.graphics.checkPref("vsync", "VSync", true, b -> Gdx.graphics.setVSync(b));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.graphics.Colors;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.scene.ui.Dialog;
|
||||
|
||||
public class FloatingDialog extends Dialog{
|
||||
@@ -19,13 +20,17 @@ public class FloatingDialog extends Dialog{
|
||||
|
||||
@Override
|
||||
public void addCloseButton(){
|
||||
buttons().addImageTextButton("Back", "icon-arrow-left", 30f, ()->{
|
||||
hide();
|
||||
}).size(230f, 64f);
|
||||
buttons().addImageTextButton("Back", "icon-arrow-left", 30f, this::hide).size(230f, 64f);
|
||||
|
||||
keyDown(key->{
|
||||
if(key == Keys.ESCAPE || key == Keys.BACK)
|
||||
hide();
|
||||
});
|
||||
|
||||
update(() -> {
|
||||
if(Inputs.keyTap("menu")){
|
||||
hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
import io.anuke.ucore.function.Listenable;
|
||||
import io.anuke.ucore.scene.builders.table;
|
||||
import io.anuke.ucore.scene.ui.*;
|
||||
import io.anuke.ucore.scene.ui.layout.Stack;
|
||||
@@ -35,9 +37,14 @@ public class MindustrySettingsDialog extends SettingsDialog{
|
||||
|
||||
menu = new Table();
|
||||
|
||||
game = new SettingsTable();
|
||||
graphics = new SettingsTable();
|
||||
sound = new SettingsTable();
|
||||
Consumer<SettingsTable> s = table -> {
|
||||
table.row();
|
||||
table.addImageTextButton("Back", "icon-arrow-left", 10*3, this::back).size(240f, 60f).colspan(2).padTop(15f);
|
||||
};
|
||||
|
||||
game = new SettingsTable(s);
|
||||
graphics = new SettingsTable(s);
|
||||
sound = new SettingsTable(s);
|
||||
|
||||
prefs = new Table();
|
||||
prefs.top();
|
||||
@@ -50,10 +57,10 @@ public class MindustrySettingsDialog extends SettingsDialog{
|
||||
menu.row();
|
||||
menu.addButton("Sound", () -> visible(2));
|
||||
|
||||
if(!Vars.android) {
|
||||
menu.row();
|
||||
menu.addButton("Controls", () -> Vars.ui.showControls());
|
||||
}
|
||||
//if(!Vars.android) {
|
||||
menu.row();
|
||||
menu.addButton("Controls", () -> Vars.ui.showControls());
|
||||
//}
|
||||
|
||||
prefs.clearChildren();
|
||||
prefs.add(menu);
|
||||
@@ -67,16 +74,6 @@ public class MindustrySettingsDialog extends SettingsDialog{
|
||||
add(buttons()).fillX();
|
||||
|
||||
hidden(this::back);
|
||||
|
||||
shown(() -> {
|
||||
if(built) return;
|
||||
built = true;
|
||||
|
||||
Mathf.each(table -> {
|
||||
table.row();
|
||||
table.addImageTextButton("Back", "icon-arrow-left", 10*3, this::back).size(240f, 60f).colspan(2).padTop(15f);
|
||||
}, game, graphics, sound);
|
||||
});
|
||||
}
|
||||
|
||||
private void back(){
|
||||
|
||||
Reference in New Issue
Block a user