v0.8.0: refactored KeyAction into int constants so it can be expanded
This commit is contained in:
parent
cb76fb8188
commit
f269d68a27
|
@ -21,32 +21,125 @@
|
|||
|
||||
package com.watabou.input;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
|
||||
//FIXME this is describing actions defined in the core module, it should probably be moved there.
|
||||
public enum KeyAction {
|
||||
BACK,
|
||||
MENU,
|
||||
|
||||
HERO_INFO,
|
||||
JOURNAL,
|
||||
|
||||
WAIT,
|
||||
SEARCH,
|
||||
|
||||
INVENTORY,
|
||||
QUICKSLOT_1,
|
||||
QUICKSLOT_2,
|
||||
QUICKSLOT_3,
|
||||
QUICKSLOT_4,
|
||||
|
||||
TAG_ATTACK,
|
||||
TAG_DANGER,
|
||||
TAG_ACTION,
|
||||
TAG_LOOT,
|
||||
TAG_RESUME,
|
||||
|
||||
ZOOM_IN,
|
||||
ZOOM_OUT,
|
||||
ZOOM_DEFAULT,
|
||||
|
||||
N, NE, E, SE, S, SW, W, NW
|
||||
public class KeyAction {
|
||||
|
||||
public static final int NONE = 0;
|
||||
|
||||
public static final int BACK = 1;
|
||||
public static final int MENU = 2;
|
||||
|
||||
public static final int HERO_INFO = 3;
|
||||
public static final int JOURNAL = 4;
|
||||
|
||||
public static final int WAIT = 5;
|
||||
public static final int SEARCH = 6;
|
||||
|
||||
public static final int INVENTORY = 7;
|
||||
public static final int QUICKSLOT_1 = 8;
|
||||
public static final int QUICKSLOT_2 = 9;
|
||||
public static final int QUICKSLOT_3 = 10;
|
||||
public static final int QUICKSLOT_4 = 11;
|
||||
|
||||
public static final int TAG_ATTACK = 12;
|
||||
public static final int TAG_DANGER = 13;
|
||||
public static final int TAG_ACTION = 14;
|
||||
public static final int TAG_LOOT = 15;
|
||||
public static final int TAG_RESUME = 16;
|
||||
|
||||
public static final int ZOOM_IN = 17;
|
||||
public static final int ZOOM_OUT = 18;
|
||||
public static final int ZOOM_DEFAULT= 19;
|
||||
|
||||
public static final int N = 20;
|
||||
public static final int NE = 21;
|
||||
public static final int E = 22;
|
||||
public static final int SE = 23;
|
||||
public static final int S = 24;
|
||||
public static final int SW = 25;
|
||||
public static final int W = 26;
|
||||
public static final int NW = 27;
|
||||
|
||||
public static void initialize() {
|
||||
|
||||
KeyBindings.addName(NONE, "none");
|
||||
|
||||
KeyBindings.addName(BACK, "back");
|
||||
KeyBindings.addName(MENU, "menu");
|
||||
|
||||
KeyBindings.addName(HERO_INFO, "hero_info");
|
||||
KeyBindings.addName(JOURNAL, "journal");
|
||||
|
||||
KeyBindings.addName(WAIT, "wait");
|
||||
KeyBindings.addName(SEARCH, "search");
|
||||
|
||||
KeyBindings.addName(INVENTORY, "inventory");
|
||||
KeyBindings.addName(QUICKSLOT_1, "quickslot_1");
|
||||
KeyBindings.addName(QUICKSLOT_2, "quickslot_2");
|
||||
KeyBindings.addName(QUICKSLOT_3, "quickslot_3");
|
||||
KeyBindings.addName(QUICKSLOT_4, "quickslot_4");
|
||||
|
||||
KeyBindings.addName(TAG_ATTACK, "tag_attack");
|
||||
KeyBindings.addName(TAG_DANGER, "tag_danger");
|
||||
KeyBindings.addName(TAG_ACTION, "tag_action");
|
||||
KeyBindings.addName(TAG_LOOT, "tag_loot");
|
||||
KeyBindings.addName(TAG_RESUME, "tag_resume");
|
||||
|
||||
KeyBindings.addName(ZOOM_IN, "zoom_in");
|
||||
KeyBindings.addName(ZOOM_OUT, "zoom_out");
|
||||
KeyBindings.addName(ZOOM_DEFAULT, "zoom_default");
|
||||
|
||||
KeyBindings.addName(N, "none");
|
||||
KeyBindings.addName(NE, "none");
|
||||
KeyBindings.addName(E, "none");
|
||||
KeyBindings.addName(SE, "none");
|
||||
KeyBindings.addName(S, "none");
|
||||
KeyBindings.addName(SW, "none");
|
||||
KeyBindings.addName(W, "none");
|
||||
KeyBindings.addName(NW, "none");
|
||||
|
||||
//default key bindings
|
||||
KeyBindings.addBinding( Input.Keys.BACK, KeyAction.BACK );
|
||||
KeyBindings.addBinding( Input.Keys.MENU, KeyAction.MENU );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.H, KeyAction.HERO_INFO );
|
||||
KeyBindings.addBinding( Input.Keys.J, KeyAction.JOURNAL );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_5, KeyAction.WAIT );
|
||||
KeyBindings.addBinding( Input.Keys.SPACE, KeyAction.WAIT );
|
||||
KeyBindings.addBinding( Input.Keys.S, KeyAction.SEARCH );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.I, KeyAction.INVENTORY );
|
||||
KeyBindings.addBinding( Input.Keys.Q, KeyAction.QUICKSLOT_1 );
|
||||
KeyBindings.addBinding( Input.Keys.W, KeyAction.QUICKSLOT_2 );
|
||||
KeyBindings.addBinding( Input.Keys.E, KeyAction.QUICKSLOT_3 );
|
||||
KeyBindings.addBinding( Input.Keys.R, KeyAction.QUICKSLOT_4 );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.A, KeyAction.TAG_ATTACK );
|
||||
KeyBindings.addBinding( Input.Keys.TAB, KeyAction.TAG_DANGER );
|
||||
KeyBindings.addBinding( Input.Keys.D, KeyAction.TAG_ACTION );
|
||||
KeyBindings.addBinding( Input.Keys.ENTER, KeyAction.TAG_LOOT );
|
||||
KeyBindings.addBinding( Input.Keys.T, KeyAction.TAG_RESUME );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.PLUS, KeyAction.ZOOM_IN );
|
||||
KeyBindings.addBinding( Input.Keys.EQUALS, KeyAction.ZOOM_IN );
|
||||
KeyBindings.addBinding( Input.Keys.MINUS, KeyAction.ZOOM_OUT );
|
||||
KeyBindings.addBinding( Input.Keys.SLASH, KeyAction.ZOOM_DEFAULT );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.UP, KeyAction.N );
|
||||
KeyBindings.addBinding( Input.Keys.RIGHT, KeyAction.E );
|
||||
KeyBindings.addBinding( Input.Keys.DOWN, KeyAction.S );
|
||||
KeyBindings.addBinding( Input.Keys.LEFT, KeyAction.W );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_8, KeyAction.N );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_9, KeyAction.NE );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_6, KeyAction.E );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_3, KeyAction.SE );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_2, KeyAction.S );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_1, KeyAction.SW );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_4, KeyAction.W );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_7, KeyAction.NW );
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,64 +21,31 @@
|
|||
|
||||
package com.watabou.input;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class KeyBindings {
|
||||
|
||||
private static HashMap<Integer, KeyAction> bindings;
|
||||
|
||||
static {
|
||||
bindings = new HashMap<>();
|
||||
|
||||
bindings.put( Input.Keys.BACK, KeyAction.BACK );
|
||||
bindings.put( Input.Keys.MENU, KeyAction.MENU );
|
||||
|
||||
bindings.put( Input.Keys.H, KeyAction.HERO_INFO );
|
||||
bindings.put( Input.Keys.J, KeyAction.JOURNAL );
|
||||
|
||||
bindings.put( Input.Keys.NUMPAD_5, KeyAction.WAIT );
|
||||
bindings.put( Input.Keys.SPACE, KeyAction.WAIT );
|
||||
bindings.put( Input.Keys.S, KeyAction.SEARCH );
|
||||
|
||||
bindings.put( Input.Keys.I, KeyAction.INVENTORY );
|
||||
bindings.put( Input.Keys.Q, KeyAction.QUICKSLOT_1 );
|
||||
bindings.put( Input.Keys.W, KeyAction.QUICKSLOT_2 );
|
||||
bindings.put( Input.Keys.E, KeyAction.QUICKSLOT_3 );
|
||||
bindings.put( Input.Keys.R, KeyAction.QUICKSLOT_4 );
|
||||
|
||||
bindings.put( Input.Keys.A, KeyAction.TAG_ATTACK );
|
||||
bindings.put( Input.Keys.TAB, KeyAction.TAG_DANGER );
|
||||
bindings.put( Input.Keys.D, KeyAction.TAG_ACTION );
|
||||
bindings.put( Input.Keys.ENTER, KeyAction.TAG_LOOT );
|
||||
bindings.put( Input.Keys.T, KeyAction.TAG_RESUME );
|
||||
|
||||
bindings.put( Input.Keys.PLUS, KeyAction.ZOOM_IN );
|
||||
bindings.put( Input.Keys.EQUALS, KeyAction.ZOOM_IN );
|
||||
bindings.put( Input.Keys.MINUS, KeyAction.ZOOM_OUT );
|
||||
bindings.put( Input.Keys.SLASH, KeyAction.ZOOM_DEFAULT );
|
||||
|
||||
bindings.put( Input.Keys.UP, KeyAction.N );
|
||||
bindings.put( Input.Keys.RIGHT, KeyAction.E );
|
||||
bindings.put( Input.Keys.DOWN, KeyAction.S );
|
||||
bindings.put( Input.Keys.LEFT, KeyAction.W );
|
||||
bindings.put( Input.Keys.NUMPAD_8, KeyAction.N );
|
||||
bindings.put( Input.Keys.NUMPAD_9, KeyAction.NE );
|
||||
bindings.put( Input.Keys.NUMPAD_6, KeyAction.E );
|
||||
bindings.put( Input.Keys.NUMPAD_3, KeyAction.SE );
|
||||
bindings.put( Input.Keys.NUMPAD_2, KeyAction.S );
|
||||
bindings.put( Input.Keys.NUMPAD_1, KeyAction.SW );
|
||||
bindings.put( Input.Keys.NUMPAD_4, KeyAction.W );
|
||||
bindings.put( Input.Keys.NUMPAD_7, KeyAction.NW );
|
||||
|
||||
private static HashMap<Integer, Integer> bindings = new HashMap<>();
|
||||
private static HashMap<Integer, String> names = new HashMap<>();
|
||||
|
||||
public static void addBinding( int keyCode, int keyAction){
|
||||
bindings.put(keyCode, keyAction);
|
||||
}
|
||||
|
||||
public static boolean isBound( int keyCode ){
|
||||
return bindings.keySet().contains( keyCode );
|
||||
}
|
||||
|
||||
public static KeyAction getBinding( KeyEvent event ){
|
||||
public static int getBinding( KeyEvent event ){
|
||||
return bindings.get( event.code );
|
||||
}
|
||||
|
||||
|
||||
public static void addName( int keyAction, String name ){
|
||||
names.put(keyAction, name);
|
||||
}
|
||||
|
||||
public static String getName( int keyAction ){
|
||||
return names.get( keyAction );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import com.watabou.gltextures.TextureCache;
|
|||
import com.watabou.glwrap.Blending;
|
||||
import com.watabou.glwrap.Vertexbuffer;
|
||||
import com.watabou.input.InputHandler;
|
||||
import com.watabou.input.KeyEvent;
|
||||
import com.watabou.input.KeyAction;
|
||||
import com.watabou.noosa.audio.Music;
|
||||
import com.watabou.noosa.audio.Sample;
|
||||
import com.watabou.utils.Callback;
|
||||
|
@ -100,6 +100,7 @@ public class Game implements ApplicationListener {
|
|||
Blending.useDefault();
|
||||
|
||||
inputHandler = new InputHandler( Gdx.input );
|
||||
KeyAction.initialize();
|
||||
|
||||
//refreshes texture and vertex data stored on the gpu
|
||||
TextureCache.reload();
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
package com.watabou.noosa;
|
||||
|
||||
import com.watabou.input.KeyAction;
|
||||
import com.watabou.input.KeyBindings;
|
||||
import com.watabou.input.KeyEvent;
|
||||
import com.watabou.utils.Signal;
|
||||
|
@ -35,10 +36,10 @@ public class Scene extends Group {
|
|||
public boolean onSignal( KeyEvent event ) {
|
||||
if (Game.instance != null && event.pressed) {
|
||||
switch (KeyBindings.getBinding( event )) {
|
||||
case BACK:
|
||||
case KeyAction.BACK:
|
||||
onBackPressed();
|
||||
break;
|
||||
case MENU:
|
||||
case KeyAction.MENU:
|
||||
onMenuPressed();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class Button extends Component {
|
|||
KeyEvent.addKeyListener( keyListener = new Signal.Listener<KeyEvent>() {
|
||||
@Override
|
||||
public boolean onSignal ( KeyEvent event ) {
|
||||
if ( active && !event.pressed && KeyBindings.getBinding( event ) != null
|
||||
if ( active && !event.pressed
|
||||
&& KeyBindings.getBinding( event ) == keyAction()){
|
||||
onClick();
|
||||
return true;
|
||||
|
@ -78,8 +78,8 @@ public class Button extends Component {
|
|||
|
||||
private Signal.Listener<KeyEvent> keyListener;
|
||||
|
||||
public KeyAction keyAction(){
|
||||
return null;
|
||||
public int keyAction(){
|
||||
return KeyAction.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user