v1.2.0: implemented basic controller support
This commit is contained in:
@@ -30,6 +30,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
|
||||
import com.watabou.input.ControllerHandler;
|
||||
import com.watabou.input.GameAction;
|
||||
import com.watabou.input.KeyBindings;
|
||||
import com.watabou.input.KeyEvent;
|
||||
@@ -330,8 +331,10 @@ public class CellSelector extends ScrollArea {
|
||||
if (heldDelay > 0){
|
||||
heldDelay -= Game.elapsed;
|
||||
}
|
||||
|
||||
if (heldAction1 != SPDAction.NONE && Dungeon.hero.ready){
|
||||
boolean leftStickActive = Math.abs(ControllerHandler.leftStickPosition.x) >= .5f
|
||||
|| Math.abs(ControllerHandler.leftStickPosition.y) >= 0.5f;
|
||||
leftStickActive = leftStickActive && !GameScene.InterfaceBlockingHero();
|
||||
if ((heldAction1 != SPDAction.NONE || leftStickActive) && Dungeon.hero.ready){
|
||||
processKeyHold();
|
||||
} else if (Dungeon.hero.ready) {
|
||||
lastCellMoved = -1;
|
||||
@@ -350,7 +353,7 @@ public class CellSelector extends ScrollArea {
|
||||
for (GameAction action : actions) {
|
||||
cell += directionFromAction(action);
|
||||
}
|
||||
|
||||
|
||||
if (cell != Dungeon.hero.pos && cell != lastCellMoved){
|
||||
lastCellMoved = cell;
|
||||
select(cell, PointerEvent.LEFT);
|
||||
@@ -373,9 +376,39 @@ public class CellSelector extends ScrollArea {
|
||||
if (action == SPDAction.NW) return -1-Dungeon.level.width();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
//TODO controller stick movement would probably be improved if it used the 50ms delay, like key movement
|
||||
public void processKeyHold() {
|
||||
if (directionFromAction(heldAction1) + directionFromAction(heldAction2) != 0
|
||||
//prioritize moving by controller stick over moving via keys
|
||||
PointF leftStick = ControllerHandler.leftStickPosition;
|
||||
boolean leftStickActive = Math.abs(leftStick.x) > 0.5f || Math.abs(leftStick.y) > 0.5f;
|
||||
leftStickActive = leftStickActive && !GameScene.InterfaceBlockingHero();
|
||||
if (leftStickActive) {
|
||||
enabled = Dungeon.hero.ready = true;
|
||||
Dungeon.observe();
|
||||
//determine which direction to move in.
|
||||
if (leftStick.x > 0.5f){
|
||||
if (leftStick.y < -0.5f){
|
||||
if (moveFromActions(SPDAction.NE)) Dungeon.hero.ready = false;
|
||||
} else if (leftStick.y > 0.5f){
|
||||
if (moveFromActions(SPDAction.SE)) Dungeon.hero.ready = false;
|
||||
} else if (leftStick.x > 0.8f){
|
||||
if (moveFromActions(SPDAction.E)) Dungeon.hero.ready = false;
|
||||
}
|
||||
} else if (leftStick.x < -0.5f){
|
||||
if (leftStick.y < -0.5f){
|
||||
if (moveFromActions(SPDAction.NW)) Dungeon.hero.ready = false;
|
||||
} else if (leftStick.y > 0.5f){
|
||||
if (moveFromActions(SPDAction.SW)) Dungeon.hero.ready = false;
|
||||
} else if (leftStick.x < -0.8f){
|
||||
if (moveFromActions(SPDAction.W)) Dungeon.hero.ready = false;
|
||||
}
|
||||
} else if (leftStick.y > 0.8f){
|
||||
if (moveFromActions(SPDAction.S)) Dungeon.hero.ready = false;
|
||||
} else if (leftStick.y < -0.8f){
|
||||
if (moveFromActions(SPDAction.N)) Dungeon.hero.ready = false;
|
||||
}
|
||||
} else if (directionFromAction(heldAction1) + directionFromAction(heldAction2) != 0
|
||||
&& heldDelay <= 0){
|
||||
enabled = Dungeon.hero.ready = true;
|
||||
Dungeon.observe();
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
package com.shatteredpixel.shatteredpixeldungeon.scenes;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Badges;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
|
||||
@@ -32,6 +33,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.Tooltip;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
||||
import com.watabou.gltextures.TextureCache;
|
||||
import com.watabou.glwrap.Blending;
|
||||
import com.watabou.input.ControllerHandler;
|
||||
import com.watabou.input.PointerEvent;
|
||||
import com.watabou.noosa.BitmapText;
|
||||
import com.watabou.noosa.BitmapText.Font;
|
||||
@@ -44,6 +46,7 @@ import com.watabou.noosa.Visual;
|
||||
import com.watabou.noosa.ui.Component;
|
||||
import com.watabou.noosa.ui.Cursor;
|
||||
import com.watabou.utils.GameMath;
|
||||
import com.watabou.utils.PointF;
|
||||
import com.watabou.utils.Reflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -155,7 +158,28 @@ public class PixelScene extends Scene {
|
||||
Cursor.setCustomCursor(Cursor.Type.DEFAULT, defaultZoom);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private PointF fractionalMovement = new PointF();
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
if (Math.abs(ControllerHandler.rightStickPosition.x) >= 0.1f
|
||||
|| Math.abs(ControllerHandler.rightStickPosition.y) >= 0.1f) {
|
||||
PointF curMouse = PointerEvent.currentHoverPos();
|
||||
//cursor moves 500 scaled pixels per second at full speed, 50 at minimum speed
|
||||
fractionalMovement.x += defaultZoom * 500 * Game.elapsed * ControllerHandler.rightStickPosition.x;
|
||||
fractionalMovement.y += defaultZoom * 500 * Game.elapsed * ControllerHandler.rightStickPosition.y;
|
||||
curMouse.x += (int)fractionalMovement.x;
|
||||
curMouse.y += (int)fractionalMovement.y;
|
||||
Gdx.input.setCursorPosition((int) curMouse.x, (int) curMouse.y);
|
||||
fractionalMovement.x -= (int)fractionalMovement.x;
|
||||
fractionalMovement.y -= (int)fractionalMovement.y;
|
||||
} else {
|
||||
fractionalMovement.set(0);
|
||||
}
|
||||
}
|
||||
|
||||
//FIXME this system currently only works for a subset of windows
|
||||
private static ArrayList<Class<?extends Window>> savedWindows = new ArrayList<>();
|
||||
private static Class<?extends PixelScene> savedClass = null;
|
||||
|
||||
Reference in New Issue
Block a user