v0.8.0: refactored KeyAction into int constants so it can be expanded

This commit is contained in:
Evan Debenham
2019-12-13 23:22:44 -05:00
parent cb76fb8188
commit f269d68a27
15 changed files with 176 additions and 114 deletions
@@ -208,27 +208,27 @@ public class CellSelector extends ScrollArea {
}
private KeyAction heldAction = null;
private int heldAction = KeyAction.NONE;
private int heldTurns = 0;
private Signal.Listener<KeyEvent> keyListener = new Signal.Listener<KeyEvent>() {
@Override
public boolean onSignal(KeyEvent event) {
KeyAction action = KeyBindings.getBinding( event );
int action = KeyBindings.getBinding( event );
if (!event.pressed){
if (heldAction != null && heldAction == action) {
if (heldAction != -1 && heldAction == action) {
resetKeyHold();
return true;
} else {
switch (action){
case ZOOM_IN:
case KeyAction.ZOOM_IN:
zoom( camera.zoom+1 );
return true;
case ZOOM_OUT:
case KeyAction.ZOOM_OUT:
zoom( camera.zoom-1 );
return true;
case ZOOM_DEFAULT:
case KeyAction.ZOOM_DEFAULT:
zoom( PixelScene.defaultZoom );
return true;
}
@@ -242,33 +242,33 @@ public class CellSelector extends ScrollArea {
}
};
private boolean moveFromKey(KeyAction event){
private boolean moveFromKey(int event){
boolean moved = true;
int cell = Dungeon.hero.pos;
//TODO implement game actions, instead of using keys directly
switch (event){
case N:
case KeyAction.N:
cell += -Dungeon.level.width();
break;
case NE:
case KeyAction.NE:
cell += +1-Dungeon.level.width();
break;
case E:
case KeyAction.E:
cell += +1;
break;
case SE:
case KeyAction.SE:
cell += +1+Dungeon.level.width();
break;
case S:
case KeyAction.S:
cell += +Dungeon.level.width();
break;
case SW:
case KeyAction.SW:
cell += -1+Dungeon.level.width();
break;
case W:
case KeyAction.W:
cell += -1;
break;
case NW:
case KeyAction.NW:
cell += -1-Dungeon.level.width();
break;
default:
@@ -287,7 +287,7 @@ public class CellSelector extends ScrollArea {
}
public void processKeyHold(){
if (heldAction != null){
if (heldAction != KeyAction.NONE){
enabled = true;
heldTurns++;
moveFromKey(heldAction);
@@ -295,7 +295,7 @@ public class CellSelector extends ScrollArea {
}
public void resetKeyHold(){
heldAction = null;
heldAction = KeyAction.NONE;
heldTurns = 0;
CharSprite.setMoveInterval( CharSprite.DEFAULT_MOVE_INTERVAL );
}
@@ -43,7 +43,7 @@ public class ActionIndicator extends Tag {
}
@Override
public KeyAction keyAction() {
public int keyAction() {
return KeyAction.TAG_ACTION;
}
@@ -59,7 +59,7 @@ public class AttackIndicator extends Tag {
}
@Override
public KeyAction keyAction() {
public int keyAction() {
return KeyAction.TAG_ATTACK;
}
@@ -49,7 +49,7 @@ public class DangerIndicator extends Tag {
}
@Override
public KeyAction keyAction() {
public int keyAction() {
return KeyAction.TAG_DANGER;
}
@@ -42,7 +42,7 @@ public class LootIndicator extends Tag {
}
@Override
public KeyAction keyAction() {
public int keyAction() {
return KeyAction.TAG_LOOT;
}
@@ -95,7 +95,7 @@ public class QuickSlotButton extends Button implements WndBag.Listener {
}
@Override
public KeyAction keyAction() {
public int keyAction() {
return QuickSlotButton.this.keyAction();
}
@Override
@@ -142,7 +142,7 @@ public class QuickSlotButton extends Button implements WndBag.Listener {
}
@Override
public KeyAction keyAction() {
public int keyAction() {
switch (slotNum){
case 0:
return KeyAction.QUICKSLOT_1;
@@ -40,7 +40,7 @@ public class ResumeIndicator extends Tag {
}
@Override
public KeyAction keyAction() {
public int keyAction() {
return KeyAction.TAG_RESUME;
}
@@ -38,7 +38,6 @@ import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.PointerArea;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.particles.Emitter;
import com.watabou.noosa.ui.Button;
@@ -90,7 +89,7 @@ public class StatusPane extends Component {
}
@Override
public KeyAction keyAction() {
public int keyAction() {
return KeyAction.HERO_INFO;
}
}.setRect( 0, 1, 30, 30 ));
@@ -265,7 +264,7 @@ public class StatusPane extends Component {
}
@Override
public KeyAction keyAction() {
public int keyAction() {
return KeyAction.JOURNAL;
}
@@ -88,7 +88,7 @@ public class Toolbar extends Component {
}
@Override
public KeyAction keyAction() {
public int keyAction() {
return KeyAction.WAIT;
}
@@ -112,7 +112,7 @@ public class Toolbar extends Component {
}
@Override
public KeyAction keyAction() {
public int keyAction() {
return KeyAction.SEARCH;
}
@@ -132,7 +132,7 @@ public class Toolbar extends Component {
}
@Override
public KeyAction keyAction() {
public int keyAction() {
return KeyAction.INVENTORY;
}
@@ -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.KeyAction;
import com.watabou.input.KeyBindings;
import com.watabou.input.KeyEvent;
import com.watabou.input.PointerEvent;
@@ -158,10 +159,10 @@ public class Window extends Group implements Signal.Listener<KeyEvent> {
public boolean onSignal( KeyEvent event ) {
if (event.pressed) {
switch (KeyBindings.getBinding( event )) {
case BACK:
case KeyAction.BACK:
onBackPressed();
return true;
case MENU:
case KeyAction.MENU:
onMenuPressed();
return true;
}