Added basic controller support
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.Arrays;
|
||||
|
||||
import com.badlogic.gdx.Application.ApplicationType;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Buttons;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.audio.Music;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
@@ -29,10 +30,14 @@ import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.core.Inputs.Axis;
|
||||
import io.anuke.ucore.core.Inputs.DeviceType;
|
||||
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.util.Input;
|
||||
import io.anuke.ucore.util.InputProxy;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class Control extends Module{
|
||||
@@ -62,6 +67,10 @@ public class Control extends Module{
|
||||
|
||||
float respawntime;
|
||||
InputHandler input;
|
||||
|
||||
private InputProxy proxy;
|
||||
private float controlx, controly;
|
||||
private boolean controlling;
|
||||
|
||||
public Control(){
|
||||
if(Mindustry.args.contains("-debug", false))
|
||||
@@ -82,6 +91,18 @@ public class Control extends Module{
|
||||
}else{
|
||||
input = new DesktopInput();
|
||||
}
|
||||
|
||||
proxy = new InputProxy(Gdx.input){
|
||||
@Override
|
||||
public int getY() {
|
||||
return controlling ? (int)controly : input.getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return controlling ? (int)controlx : input.getX();
|
||||
}
|
||||
};
|
||||
|
||||
Inputs.addProcessor(input);
|
||||
|
||||
@@ -99,16 +120,45 @@ public class Control extends Module{
|
||||
Musics.load("1.ogg", "2.ogg", "3.ogg", "4.ogg");
|
||||
|
||||
KeyBinds.defaults(
|
||||
"up", Keys.W,
|
||||
"left", Keys.A,
|
||||
"down", Keys.S,
|
||||
"right", Keys.D,
|
||||
"zoom_hold", Keys.CONTROL_LEFT,
|
||||
"menu", Gdx.app.getType() == ApplicationType.Android ? Keys.BACK : Keys.ESCAPE,
|
||||
"pause", Keys.SPACE,
|
||||
"dash", Keys.SHIFT_LEFT,
|
||||
"rotate_right", Keys.R,
|
||||
"rotate_left", Keys.E
|
||||
"move_x", new Axis(Input.A, Input.D),
|
||||
"move_y", new Axis(Input.S, Input.W),
|
||||
"shoot", Input.MOUSE_LEFT,
|
||||
"zoom_hold", Input.CONTROL_LEFT,
|
||||
"zoom", new Axis(Input.SCROLL),
|
||||
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
|
||||
"pause", Input.SPACE,
|
||||
"dash", Input.SHIFT_LEFT,
|
||||
"rotate_alt", new Axis(Input.R, Input.E),
|
||||
"rotate", new Axis(Input.SCROLL),
|
||||
"weapon_1", Input.NUM_1,
|
||||
"weapon_2", Input.NUM_2,
|
||||
"weapon_3", Input.NUM_3,
|
||||
"weapon_4", Input.NUM_4,
|
||||
"weapon_5", Input.NUM_5,
|
||||
"weapon_6", Input.NUM_6
|
||||
);
|
||||
|
||||
KeyBinds.defaults(
|
||||
DeviceType.controller,
|
||||
"move_x", new Axis(Input.CONTROLLER_L_STICK_HORIZONTAL_AXIS),
|
||||
"move_y", new Axis(Input.CONTROLLER_L_STICK_VERTICAL_AXIS),
|
||||
"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,
|
||||
"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,
|
||||
"rotate_alt", new Axis(Input.UNSET),
|
||||
"rotate", new Axis(Input.CONTROLLER_DPAD_LEFT, Input.CONTROLLER_DPAD_RIGHT),
|
||||
"weapon_1", Input.NUM_1,
|
||||
"weapon_2", Input.NUM_2,
|
||||
"weapon_3", Input.NUM_3,
|
||||
"weapon_4", Input.NUM_4,
|
||||
"weapon_5", Input.NUM_5,
|
||||
"weapon_6", Input.NUM_6
|
||||
);
|
||||
|
||||
for(int i = 0; i < Vars.saveSlots; i ++){
|
||||
@@ -126,6 +176,10 @@ public class Control extends Module{
|
||||
spawns = WaveCreator.getSpawns();
|
||||
//WaveCreator.testWaves(1, 30);
|
||||
}
|
||||
|
||||
public boolean showCursor(){
|
||||
return controlling;
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
weapons.clear();
|
||||
@@ -433,32 +487,73 @@ public class Control extends Module{
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
|
||||
if(Gdx.input != proxy){
|
||||
Gdx.input = proxy;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if(Inputs.keyRelease("select")){
|
||||
Core.scene.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;
|
||||
controlling = true;
|
||||
|
||||
Core.scene.touchDragged(Gdx.input.getX(), Gdx.input.getY(), 0);
|
||||
}
|
||||
|
||||
controlx = Mathf.clamp(controlx, 0, Gdx.graphics.getWidth());
|
||||
controly = Mathf.clamp(controly, 0, Gdx.graphics.getHeight());
|
||||
|
||||
if(Gdx.input.getDeltaX() > 1 || Gdx.input.getDeltaY() > 1)
|
||||
controlling = false;
|
||||
}else{
|
||||
controlling = false;
|
||||
}
|
||||
|
||||
if(!controlling){
|
||||
controlx = Gdx.input.getX();
|
||||
controly = Gdx.input.getY();
|
||||
}
|
||||
|
||||
Gdx.input.setCursorCatched(controlling);
|
||||
|
||||
if(debug && GameState.is(State.playing)){
|
||||
//debug actions
|
||||
if(Inputs.keyUp(Keys.P)){
|
||||
if(Inputs.keyTap(Keys.P)){
|
||||
Effects.effect(Fx.shellsmoke, player);
|
||||
Effects.effect(Fx.shellexplosion, player);
|
||||
}
|
||||
|
||||
if(Inputs.keyUp(Keys.C)){
|
||||
if(Inputs.keyTap(Keys.C)){
|
||||
enemyGroup.clear();
|
||||
enemies = 0;
|
||||
}
|
||||
|
||||
if(Inputs.keyUp(Keys.F)){
|
||||
if(Inputs.keyTap(Keys.F)){
|
||||
wavetime = 0f;
|
||||
}
|
||||
|
||||
if(Inputs.keyUp(Keys.U)){
|
||||
if(Inputs.keyTap(Keys.U)){
|
||||
Vars.showUI = !Vars.showUI;
|
||||
}
|
||||
|
||||
if(Inputs.keyUp(Keys.O)){
|
||||
if(Inputs.keyTap(Keys.O)){
|
||||
Vars.noclip = !Vars.noclip;
|
||||
}
|
||||
|
||||
if(Inputs.keyUp(Keys.Y)){
|
||||
if(Inputs.keyTap(Keys.Y)){
|
||||
if(Inputs.keyDown(Keys.SHIFT_LEFT)){
|
||||
new HealerEnemy().set(player.x, player.y).add();
|
||||
}else{
|
||||
@@ -476,11 +571,11 @@ public class Control extends Module{
|
||||
if(!GameState.is(State.menu)){
|
||||
input.update();
|
||||
|
||||
if(Inputs.keyUp("pause") && !ui.isGameOver() && (GameState.is(State.paused) || GameState.is(State.playing))){
|
||||
if(Inputs.keyTap("pause") && !ui.isGameOver() && (GameState.is(State.paused) || GameState.is(State.playing))){
|
||||
GameState.set(GameState.is(State.playing) ? State.paused : State.playing);
|
||||
}
|
||||
|
||||
if(Inputs.keyUp("menu")){
|
||||
if(Inputs.keyTap("menu")){
|
||||
if(GameState.is(State.paused)){
|
||||
ui.hideMenu();
|
||||
GameState.set(State.playing);
|
||||
|
||||
@@ -22,7 +22,9 @@ import io.anuke.mindustry.ui.fragments.*;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.blocks.types.Configurable;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.core.Inputs.DeviceType;
|
||||
import io.anuke.ucore.function.Listenable;
|
||||
import io.anuke.ucore.function.VisibilityProvider;
|
||||
import io.anuke.ucore.modules.SceneModule;
|
||||
@@ -155,6 +157,13 @@ public class UI extends SceneModule{
|
||||
|
||||
scene.act();
|
||||
scene.draw();
|
||||
|
||||
if(control.showCursor()) {
|
||||
Draw.color();
|
||||
scene.getBatch().begin();
|
||||
Draw.rect("icon-close", Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY());
|
||||
scene.getBatch().end();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -163,7 +172,7 @@ public class UI extends SceneModule{
|
||||
configtable = new Table();
|
||||
scene.add(configtable);
|
||||
|
||||
editorDialog = new MapEditorDialog(editor);
|
||||
if(!Vars.gwt) editorDialog = new MapEditorDialog(editor);
|
||||
|
||||
settingserror = new Dialog("Warning", "dialog");
|
||||
settingserror.content().add("[crimson]Failed to access local storage.\nSettings will not be saved.");
|
||||
|
||||
@@ -83,17 +83,16 @@ public class Player extends DestructibleEntity{
|
||||
}
|
||||
|
||||
vector.set(0, 0);
|
||||
|
||||
float xa = Inputs.getAxis("move_x");
|
||||
float ya = Inputs.getAxis("move_y");
|
||||
if(Math.abs(xa) < 0.3) xa = 0;
|
||||
if(Math.abs(ya) < 0.3) ya = 0;
|
||||
|
||||
vector.y += ya*speed;
|
||||
vector.x += xa*speed;
|
||||
|
||||
if(Inputs.keyDown("up"))
|
||||
vector.y += speed;
|
||||
if(Inputs.keyDown("down"))
|
||||
vector.y -= speed;
|
||||
if(Inputs.keyDown("left"))
|
||||
vector.x -= speed;
|
||||
if(Inputs.keyDown("right"))
|
||||
vector.x += speed;
|
||||
|
||||
boolean shooting = !Inputs.keyDown("dash") && Inputs.buttonDown(Buttons.LEFT) && recipe == null
|
||||
boolean shooting = !Inputs.keyDown("dash") && Inputs.keyDown("shoot") && recipe == null
|
||||
&& !ui.hasMouse() && !control.getInput().onConfigurable();
|
||||
|
||||
if(shooting && Timers.get(this, "reload", weapon.reload)){
|
||||
|
||||
@@ -12,10 +12,14 @@ import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Configurable;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.core.Inputs.DeviceType;
|
||||
import io.anuke.ucore.core.KeyBinds;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.utils.Cursors;
|
||||
import io.anuke.ucore.util.InputProxy;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class DesktopInput extends InputHandler{
|
||||
@@ -23,6 +27,10 @@ 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; }
|
||||
@@ -52,7 +60,7 @@ public class DesktopInput extends InputHandler{
|
||||
@Override
|
||||
public void update(){
|
||||
if(player.isDead()) return;
|
||||
|
||||
|
||||
if(!Inputs.buttonDown(Buttons.LEFT) && !Inputs.buttonDown(Buttons.RIGHT)){
|
||||
mousex = (int)Graphics.mouseWorld().x;
|
||||
mousey = (int)Graphics.mouseWorld().y;
|
||||
@@ -61,21 +69,13 @@ public class DesktopInput extends InputHandler{
|
||||
endx = Gdx.input.getX();
|
||||
endy = Gdx.input.getY();
|
||||
|
||||
if(Inputs.scrolled() && Inputs.keyDown("zoom_hold") && !GameState.is(State.menu) && !ui.onDialog()){
|
||||
renderer.scaleCamera(Inputs.scroll());
|
||||
}
|
||||
|
||||
if(Inputs.scrolled()){
|
||||
player.rotation += Inputs.scroll();
|
||||
}
|
||||
|
||||
if(Inputs.keyUp("rotate_right")){
|
||||
player.rotation --;
|
||||
}
|
||||
|
||||
if(Inputs.keyUp("rotate_left")){
|
||||
player.rotation ++;
|
||||
if(Inputs.getAxisActive("zoom") && Inputs.keyDown("zoom_hold") && !GameState.is(State.menu) && !ui.onDialog()){
|
||||
renderer.scaleCamera((int)Inputs.getAxis("zoom"));
|
||||
}
|
||||
|
||||
player.rotation += Inputs.getAxis("rotate_alt");
|
||||
player.rotation += Inputs.getAxis("rotate");
|
||||
player.rotation = Mathf.mod(player.rotation, 4);
|
||||
|
||||
if(Inputs.buttonDown(Buttons.RIGHT)){
|
||||
player.breakMode = PlaceMode.areaDelete;
|
||||
@@ -83,11 +83,9 @@ public class DesktopInput extends InputHandler{
|
||||
player.breakMode = PlaceMode.hold;
|
||||
}
|
||||
|
||||
player.rotation = Mathf.mod(player.rotation, 4);
|
||||
|
||||
for(int i = 0; i < 9; i ++){
|
||||
if(Inputs.keyUp(Keys.valueOf(""+(i+1))) && i < control.getWeapons().size){
|
||||
player.weapon = control.getWeapons().get(i);
|
||||
for(int i = 1; i <= 6 && i < control.getWeapons().size; i ++){
|
||||
if(Inputs.keyTap("weapon_" + i) && i < control.getWeapons().size){
|
||||
player.weapon = control.getWeapons().get(i - 1);
|
||||
ui.updateWeapons();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.mapeditor;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Colors;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
@@ -219,9 +220,12 @@ public class MapView extends Element implements GestureListener{
|
||||
boolean pop = ScissorStack.pushScissors(Tmp.r1.set(x + width/2 - size/2, y + height/2 - size/2, size, size));
|
||||
|
||||
batch.draw(editor.texture(), centerx - sclwidth/2, centery - sclheight/2, sclwidth, sclheight);
|
||||
|
||||
if(grid){
|
||||
Draw.color(Color.GRAY);
|
||||
image.setBounds(centerx - sclwidth/2, centery - sclheight/2, sclwidth, sclheight);
|
||||
image.draw(batch, alpha);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
if(tool == EditorTool.line && drawing){
|
||||
|
||||
Reference in New Issue
Block a user