v0.8.0: added basic key action and key mapping support

This commit is contained in:
Evan Debenham
2019-10-28 21:06:02 -04:00
parent 4f430015c3
commit df3a0a010b
8 changed files with 136 additions and 35 deletions
@@ -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.KeyBindings;
import com.watabou.input.KeyEvent;
import com.watabou.input.PointerEvent;
import com.watabou.input.ScrollEvent;
@@ -231,31 +232,31 @@ public class CellSelector extends ScrollArea {
boolean moved = true;
int cell = Dungeon.hero.pos;
//TODO implement game actions, instead of using keys directly
switch (event.code){
case Input.Keys.NUMPAD_7:
cell += -1-Dungeon.level.width();
break;
case Input.Keys.UP: case Input.Keys.NUMPAD_8:
switch (KeyBindings.getBinding( event )){
case N:
cell += -Dungeon.level.width();
break;
case Input.Keys.NUMPAD_9:
case NE:
cell += +1-Dungeon.level.width();
break;
case Input.Keys.RIGHT: case Input.Keys.NUMPAD_6:
case E:
cell += +1;
break;
case Input.Keys.NUMPAD_3:
case SE:
cell += +1+Dungeon.level.width();
break;
case Input.Keys.DOWN: case Input.Keys.NUMPAD_2:
case S:
cell += +Dungeon.level.width();
break;
case Input.Keys.NUMPAD_1:
case SW:
cell += -1+Dungeon.level.width();
break;
case Input.Keys.LEFT: case Input.Keys.NUMPAD_4:
case W:
cell += -1;
break;
case NW:
cell += -1-Dungeon.level.width();
break;
default:
moved = false;
}
@@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.effects.ShadowBox;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.input.KeyBindings;
import com.watabou.input.KeyEvent;
import com.watabou.input.PointerEvent;
import com.watabou.noosa.Camera;
@@ -156,11 +157,11 @@ public class Window extends Group implements Signal.Listener<KeyEvent> {
@Override
public boolean onSignal( KeyEvent event ) {
if (event.pressed) {
switch (event.code) {
case KeyEvent.BACK:
switch (KeyBindings.getBinding( event )) {
case BACK:
onBackPressed();
return true;
case KeyEvent.MENU:
case MENU:
onMenuPressed();
return true;
}