v0.8.0: refactored GameAction classes to more closely resemble enums
This commit is contained in:
parent
6dc0235aa6
commit
93320fb676
|
@ -21,13 +21,47 @@
|
|||
|
||||
package com.watabou.input;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
//This is similar to an enum, but we don't use that because subclasses should be able to add actions
|
||||
public class GameAction {
|
||||
|
||||
public static final int NONE = 0;
|
||||
private static final ArrayList<GameAction> ALL_ACTIONS = new ArrayList<>();
|
||||
|
||||
public static final int BACK = 1;
|
||||
public static final int MENU = 2;
|
||||
private int code;
|
||||
private String name;
|
||||
|
||||
public static final int TOTAL_ACTIONS = 3;
|
||||
protected GameAction( String name ){
|
||||
code = ALL_ACTIONS.size();
|
||||
this.name = name;
|
||||
|
||||
ALL_ACTIONS.add(this);
|
||||
}
|
||||
|
||||
public int code(){
|
||||
return code;
|
||||
}
|
||||
|
||||
public String name(){
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof GameAction && ((GameAction) o).code == code;
|
||||
}
|
||||
|
||||
public static final GameAction NONE = new GameAction( "none" );
|
||||
|
||||
public static final GameAction BACK = new GameAction( "back" );
|
||||
public static final GameAction MENU = new GameAction( "menu" );
|
||||
|
||||
public static ArrayList<GameAction> allActions(){
|
||||
return new ArrayList<>(ALL_ACTIONS);
|
||||
}
|
||||
|
||||
public static int totalActions(){
|
||||
return ALL_ACTIONS.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ public class InputHandler extends InputAdapter {
|
|||
|
||||
@Override
|
||||
public synchronized boolean keyDown( int keyCode ) {
|
||||
if (KeyBindings.isBound( keyCode )) {
|
||||
if (KeyBindings.isKeyBound( keyCode )) {
|
||||
KeyEvent.addKeyEvent( new KeyEvent( keyCode, true ) );
|
||||
return true;
|
||||
} else {
|
||||
|
@ -96,7 +96,7 @@ public class InputHandler extends InputAdapter {
|
|||
|
||||
@Override
|
||||
public synchronized boolean keyUp( int keyCode ) {
|
||||
if (KeyBindings.isBound( keyCode )) {
|
||||
if (KeyBindings.isKeyBound( keyCode )) {
|
||||
KeyEvent.addKeyEvent( new KeyEvent( keyCode, false ) );
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
@ -24,31 +24,28 @@ package com.watabou.input;
|
|||
import com.badlogic.gdx.Input;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
//TODO maybe just move to game action?
|
||||
public class KeyBindings {
|
||||
|
||||
private static LinkedHashMap<Integer, Integer> bindings = new LinkedHashMap<>();
|
||||
private static HashMap<Integer, String> names = new HashMap<>();
|
||||
private static LinkedHashMap<Integer, GameAction> bindings = new LinkedHashMap<>();
|
||||
|
||||
public static void addBinding( int keyCode, int keyAction){
|
||||
bindings.put(keyCode, keyAction);
|
||||
public static void addKeyBinding(int keyCode, GameAction action){
|
||||
bindings.put(keyCode, action);
|
||||
}
|
||||
|
||||
public static boolean isBound( int keyCode ){
|
||||
return bindings.keySet().contains( keyCode );
|
||||
public static boolean isKeyBound(int keyCode ){
|
||||
return bindings.containsKey( keyCode );
|
||||
}
|
||||
|
||||
public static int getBinding( KeyEvent event ){
|
||||
public static GameAction getActionForKey(KeyEvent event ){
|
||||
return bindings.get( event.code );
|
||||
}
|
||||
|
||||
public static ArrayList<Integer> getBindings( int gameAction ){
|
||||
public static ArrayList<Integer> getKeysForAction(GameAction action ){
|
||||
ArrayList<Integer> result = new ArrayList<>();
|
||||
for( int i : bindings.keySet()){
|
||||
if (bindings.get(i) == gameAction){
|
||||
if (bindings.get(i) == action){
|
||||
result.add(i);
|
||||
}
|
||||
}
|
||||
|
@ -65,12 +62,4 @@ public class KeyBindings {
|
|||
}
|
||||
}
|
||||
|
||||
public static void addName( int keyAction, String name ){
|
||||
names.put(keyAction, name);
|
||||
}
|
||||
|
||||
public static String getName( int keyAction ){
|
||||
return names.get( keyAction );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,13 +35,12 @@ public class Scene extends Group {
|
|||
@Override
|
||||
public boolean onSignal( KeyEvent event ) {
|
||||
if (Game.instance != null && event.pressed) {
|
||||
switch (KeyBindings.getBinding( event )) {
|
||||
case GameAction.BACK:
|
||||
onBackPressed();
|
||||
break;
|
||||
case GameAction.MENU:
|
||||
onMenuPressed();
|
||||
break;
|
||||
if (KeyBindings.getActionForKey( event ) == GameAction.BACK){
|
||||
onBackPressed();
|
||||
|
||||
} else if (KeyBindings.getActionForKey( event ) == GameAction.MENU){
|
||||
onMenuPressed();
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -67,7 +67,7 @@ public class Button extends Component {
|
|||
@Override
|
||||
public boolean onSignal ( KeyEvent event ) {
|
||||
if ( active && !event.pressed
|
||||
&& KeyBindings.getBinding( event ) == keyAction()){
|
||||
&& KeyBindings.getActionForKey( event ) == keyAction()){
|
||||
onClick();
|
||||
return true;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public class Button extends Component {
|
|||
|
||||
private Signal.Listener<KeyEvent> keyListener;
|
||||
|
||||
public int keyAction(){
|
||||
public GameAction keyAction(){
|
||||
return GameAction.NONE;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,122 +27,89 @@ import com.watabou.input.KeyBindings;
|
|||
|
||||
public class SPDAction extends GameAction {
|
||||
|
||||
//--Existing actions from GameAction
|
||||
public static final int NONE = GameAction.NONE;
|
||||
protected SPDAction( String name ){
|
||||
super( name );
|
||||
}
|
||||
|
||||
public static final int BACK = GameAction.BACK;
|
||||
public static final int MENU = GameAction.MENU;
|
||||
//--New references to existing actions from GameAction
|
||||
public static final GameAction NONE = GameAction.NONE;
|
||||
|
||||
public static final GameAction BACK = GameAction.BACK;
|
||||
public static final GameAction MENU = GameAction.MENU;
|
||||
//--
|
||||
|
||||
public static final int HERO_INFO = 3;
|
||||
public static final int JOURNAL = 4;
|
||||
public static final GameAction HERO_INFO = new SPDAction("hero_info");
|
||||
public static final GameAction JOURNAL = new SPDAction("journal");
|
||||
|
||||
public static final int WAIT = 5;
|
||||
public static final int SEARCH = 6;
|
||||
public static final GameAction WAIT = new SPDAction("wait");
|
||||
public static final GameAction SEARCH = new SPDAction("search");
|
||||
|
||||
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 GameAction INVENTORY = new SPDAction("inventory");
|
||||
public static final GameAction QUICKSLOT_1 = new SPDAction("quickslot_1");
|
||||
public static final GameAction QUICKSLOT_2 = new SPDAction("quickslot_2");
|
||||
public static final GameAction QUICKSLOT_3 = new SPDAction("quickslot_3");
|
||||
public static final GameAction QUICKSLOT_4 = new SPDAction("quickslot_4");
|
||||
|
||||
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 GameAction TAG_ATTACK = new SPDAction("tag_attack");
|
||||
public static final GameAction TAG_DANGER = new SPDAction("tag_danger");
|
||||
public static final GameAction TAG_ACTION = new SPDAction("tag_action");
|
||||
public static final GameAction TAG_LOOT = new SPDAction("tag_loot");
|
||||
public static final GameAction TAG_RESUME = new SPDAction("tag_resume");
|
||||
|
||||
public static final int ZOOM_IN = 17;
|
||||
public static final int ZOOM_OUT = 18;
|
||||
public static final GameAction ZOOM_IN = new SPDAction("zoom_in");
|
||||
public static final GameAction ZOOM_OUT = new SPDAction("zoom_out");
|
||||
|
||||
public static final int N = 19;
|
||||
public static final int E = 20;
|
||||
public static final int S = 21;
|
||||
public static final int W = 22;
|
||||
public static final int NE = 23;
|
||||
public static final int SE = 24;
|
||||
public static final int SW = 25;
|
||||
public static final int NW = 26;
|
||||
|
||||
public static final int TOTAL_ACTIONS = 27;
|
||||
public static final GameAction N = new SPDAction("n");
|
||||
public static final GameAction E = new SPDAction("e");
|
||||
public static final GameAction S = new SPDAction("s");
|
||||
public static final GameAction W = new SPDAction("w");
|
||||
public static final GameAction NE = new SPDAction("ne");
|
||||
public static final GameAction SE = new SPDAction("se");
|
||||
public static final GameAction SW = new SPDAction("sw");
|
||||
public static final GameAction NW = new SPDAction("nw");
|
||||
|
||||
public static void initDefaults() {
|
||||
|
||||
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(N, "n");
|
||||
KeyBindings.addName(E, "e");
|
||||
KeyBindings.addName(S, "s");
|
||||
KeyBindings.addName(W, "w");
|
||||
KeyBindings.addName(NE, "ne");
|
||||
KeyBindings.addName(SE, "se");
|
||||
KeyBindings.addName(SW, "sw");
|
||||
KeyBindings.addName(NW, "nw");
|
||||
|
||||
//default key bindings
|
||||
KeyBindings.addBinding( Input.Keys.BACK, GameAction.BACK );
|
||||
KeyBindings.addBinding( Input.Keys.MENU, GameAction.MENU );
|
||||
KeyBindings.addKeyBinding( Input.Keys.BACK, SPDAction.BACK );
|
||||
KeyBindings.addKeyBinding( Input.Keys.MENU, SPDAction.MENU );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.H, SPDAction.HERO_INFO );
|
||||
KeyBindings.addBinding( Input.Keys.J, SPDAction.JOURNAL );
|
||||
KeyBindings.addKeyBinding( Input.Keys.H, SPDAction.HERO_INFO );
|
||||
KeyBindings.addKeyBinding( Input.Keys.J, SPDAction.JOURNAL );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.SPACE, SPDAction.WAIT );
|
||||
KeyBindings.addBinding( Input.Keys.S, SPDAction.SEARCH );
|
||||
KeyBindings.addKeyBinding( Input.Keys.SPACE, SPDAction.WAIT );
|
||||
KeyBindings.addKeyBinding( Input.Keys.S, SPDAction.SEARCH );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.I, SPDAction.INVENTORY );
|
||||
KeyBindings.addBinding( Input.Keys.Q, SPDAction.QUICKSLOT_1 );
|
||||
KeyBindings.addBinding( Input.Keys.W, SPDAction.QUICKSLOT_2 );
|
||||
KeyBindings.addBinding( Input.Keys.E, SPDAction.QUICKSLOT_3 );
|
||||
KeyBindings.addBinding( Input.Keys.R, SPDAction.QUICKSLOT_4 );
|
||||
KeyBindings.addKeyBinding( Input.Keys.I, SPDAction.INVENTORY );
|
||||
KeyBindings.addKeyBinding( Input.Keys.Q, SPDAction.QUICKSLOT_1 );
|
||||
KeyBindings.addKeyBinding( Input.Keys.W, SPDAction.QUICKSLOT_2 );
|
||||
KeyBindings.addKeyBinding( Input.Keys.E, SPDAction.QUICKSLOT_3 );
|
||||
KeyBindings.addKeyBinding( Input.Keys.R, SPDAction.QUICKSLOT_4 );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.A, SPDAction.TAG_ATTACK );
|
||||
KeyBindings.addBinding( Input.Keys.TAB, SPDAction.TAG_DANGER );
|
||||
KeyBindings.addBinding( Input.Keys.D, SPDAction.TAG_ACTION );
|
||||
KeyBindings.addBinding( Input.Keys.ENTER, SPDAction.TAG_LOOT );
|
||||
KeyBindings.addBinding( Input.Keys.T, SPDAction.TAG_RESUME );
|
||||
KeyBindings.addKeyBinding( Input.Keys.A, SPDAction.TAG_ATTACK );
|
||||
KeyBindings.addKeyBinding( Input.Keys.TAB, SPDAction.TAG_DANGER );
|
||||
KeyBindings.addKeyBinding( Input.Keys.D, SPDAction.TAG_ACTION );
|
||||
KeyBindings.addKeyBinding( Input.Keys.ENTER, SPDAction.TAG_LOOT );
|
||||
KeyBindings.addKeyBinding( Input.Keys.T, SPDAction.TAG_RESUME );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.PLUS, SPDAction.ZOOM_IN );
|
||||
KeyBindings.addBinding( Input.Keys.EQUALS, SPDAction.ZOOM_IN );
|
||||
KeyBindings.addBinding( Input.Keys.MINUS, SPDAction.ZOOM_OUT );
|
||||
KeyBindings.addKeyBinding( Input.Keys.PLUS, SPDAction.ZOOM_IN );
|
||||
KeyBindings.addKeyBinding( Input.Keys.EQUALS, SPDAction.ZOOM_IN );
|
||||
KeyBindings.addKeyBinding( Input.Keys.MINUS, SPDAction.ZOOM_OUT );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.UP, SPDAction.N );
|
||||
KeyBindings.addBinding( Input.Keys.RIGHT, SPDAction.E );
|
||||
KeyBindings.addBinding( Input.Keys.DOWN, SPDAction.S );
|
||||
KeyBindings.addBinding( Input.Keys.LEFT, SPDAction.W );
|
||||
KeyBindings.addKeyBinding( Input.Keys.UP, SPDAction.N );
|
||||
KeyBindings.addKeyBinding( Input.Keys.RIGHT, SPDAction.E );
|
||||
KeyBindings.addKeyBinding( Input.Keys.DOWN, SPDAction.S );
|
||||
KeyBindings.addKeyBinding( Input.Keys.LEFT, SPDAction.W );
|
||||
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_5, SPDAction.WAIT );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_8, SPDAction.N );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_9, SPDAction.NE );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_6, SPDAction.E );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_3, SPDAction.SE );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_2, SPDAction.S );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_1, SPDAction.SW );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_4, SPDAction.W );
|
||||
KeyBindings.addBinding( Input.Keys.NUMPAD_7, SPDAction.NW );
|
||||
KeyBindings.addKeyBinding( Input.Keys.NUMPAD_5, SPDAction.WAIT );
|
||||
KeyBindings.addKeyBinding( Input.Keys.NUMPAD_8, SPDAction.N );
|
||||
KeyBindings.addKeyBinding( Input.Keys.NUMPAD_9, SPDAction.NE );
|
||||
KeyBindings.addKeyBinding( Input.Keys.NUMPAD_6, SPDAction.E );
|
||||
KeyBindings.addKeyBinding( Input.Keys.NUMPAD_3, SPDAction.SE );
|
||||
KeyBindings.addKeyBinding( Input.Keys.NUMPAD_2, SPDAction.S );
|
||||
KeyBindings.addKeyBinding( Input.Keys.NUMPAD_1, SPDAction.SW );
|
||||
KeyBindings.addKeyBinding( Input.Keys.NUMPAD_4, SPDAction.W );
|
||||
KeyBindings.addKeyBinding( Input.Keys.NUMPAD_7, SPDAction.NW );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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.GameAction;
|
||||
import com.watabou.input.KeyBindings;
|
||||
import com.watabou.input.KeyEvent;
|
||||
import com.watabou.input.PointerEvent;
|
||||
|
@ -208,29 +209,29 @@ public class CellSelector extends ScrollArea {
|
|||
|
||||
}
|
||||
|
||||
private int heldAction = SPDAction.NONE;
|
||||
private GameAction heldAction = SPDAction.NONE;
|
||||
private int heldTurns = 0;
|
||||
|
||||
private Signal.Listener<KeyEvent> keyListener = new Signal.Listener<KeyEvent>() {
|
||||
@Override
|
||||
public boolean onSignal(KeyEvent event) {
|
||||
int action = KeyBindings.getBinding( event );
|
||||
GameAction action = KeyBindings.getActionForKey( event );
|
||||
if (!event.pressed){
|
||||
|
||||
if (heldAction != -1 && heldAction == action) {
|
||||
if (heldAction != SPDAction.NONE && heldAction == action) {
|
||||
resetKeyHold();
|
||||
return true;
|
||||
} else {
|
||||
switch (action){
|
||||
case SPDAction.ZOOM_IN:
|
||||
zoom( camera.zoom+1 );
|
||||
return true;
|
||||
case SPDAction.ZOOM_OUT:
|
||||
zoom( camera.zoom-1 );
|
||||
return true;
|
||||
if (action == SPDAction.ZOOM_IN){
|
||||
zoom( camera.zoom+1 );
|
||||
return true;
|
||||
|
||||
} else if (action == SPDAction.ZOOM_OUT){
|
||||
zoom( camera.zoom-1 );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (moveFromKey(action)) {
|
||||
} else if (moveFromAction(action)) {
|
||||
heldAction = action;
|
||||
return true;
|
||||
}
|
||||
|
@ -239,54 +240,37 @@ public class CellSelector extends ScrollArea {
|
|||
}
|
||||
};
|
||||
|
||||
private boolean moveFromKey(int event){
|
||||
boolean moved = true;
|
||||
private boolean moveFromAction(GameAction action){
|
||||
int cell = Dungeon.hero.pos;
|
||||
switch (event){
|
||||
case SPDAction.N:
|
||||
cell += -Dungeon.level.width();
|
||||
break;
|
||||
case SPDAction.NE:
|
||||
cell += +1-Dungeon.level.width();
|
||||
break;
|
||||
case SPDAction.E:
|
||||
cell += +1;
|
||||
break;
|
||||
case SPDAction.SE:
|
||||
cell += +1+Dungeon.level.width();
|
||||
break;
|
||||
case SPDAction.S:
|
||||
cell += +Dungeon.level.width();
|
||||
break;
|
||||
case SPDAction.SW:
|
||||
cell += -1+Dungeon.level.width();
|
||||
break;
|
||||
case SPDAction.W:
|
||||
cell += -1;
|
||||
break;
|
||||
case SPDAction.NW:
|
||||
cell += -1-Dungeon.level.width();
|
||||
break;
|
||||
default:
|
||||
moved = false;
|
||||
}
|
||||
|
||||
if (action == SPDAction.N) cell += -Dungeon.level.width();
|
||||
if (action == SPDAction.NE) cell += +1-Dungeon.level.width();
|
||||
if (action == SPDAction.E) cell += +1;
|
||||
if (action == SPDAction.SE) cell += +1+Dungeon.level.width();
|
||||
if (action == SPDAction.S) cell += +Dungeon.level.width();
|
||||
if (action == SPDAction.SW) cell += -1+Dungeon.level.width();
|
||||
if (action == SPDAction.W) cell += -1;
|
||||
if (action == SPDAction.NW) cell += -1-Dungeon.level.width();
|
||||
|
||||
if (moved){
|
||||
if (cell != Dungeon.hero.pos){
|
||||
//each step when keyboard moving takes 0.15s, 0.125s, 0.1s, 0.1s, ...
|
||||
// this is to make it easier to move 1 or 2 steps without overshooting
|
||||
CharSprite.setMoveInterval( CharSprite.DEFAULT_MOVE_INTERVAL +
|
||||
Math.max(0, 0.05f - heldTurns *0.025f));
|
||||
select(cell);
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return moved;
|
||||
|
||||
}
|
||||
|
||||
public void processKeyHold(){
|
||||
if (heldAction != SPDAction.NONE){
|
||||
enabled = true;
|
||||
heldTurns++;
|
||||
moveFromKey(heldAction);
|
||||
moveFromAction(heldAction);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.watabou.input.GameAction;
|
||||
import com.watabou.noosa.Image;
|
||||
|
||||
public class ActionIndicator extends Tag {
|
||||
|
@ -43,7 +44,7 @@ public class ActionIndicator extends Tag {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int keyAction() {
|
||||
public GameAction keyAction() {
|
||||
return SPDAction.TAG_ACTION;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
||||
import com.watabou.input.GameAction;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.utils.Random;
|
||||
import com.watabou.utils.Reflection;
|
||||
|
@ -59,7 +60,7 @@ public class AttackIndicator extends Tag {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int keyAction() {
|
||||
public GameAction keyAction() {
|
||||
return SPDAction.TAG_ATTACK;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.watabou.input.GameAction;
|
||||
import com.watabou.noosa.BitmapText;
|
||||
import com.watabou.noosa.Camera;
|
||||
import com.watabou.noosa.Image;
|
||||
|
@ -49,7 +50,7 @@ public class DangerIndicator extends Tag {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int keyAction() {
|
||||
public GameAction keyAction() {
|
||||
return SPDAction.TAG_DANGER;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||
import com.watabou.input.GameAction;
|
||||
|
||||
public class LootIndicator extends Tag {
|
||||
|
||||
|
@ -42,7 +43,7 @@ public class LootIndicator extends Tag {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int keyAction() {
|
||||
public GameAction keyAction() {
|
||||
return SPDAction.TAG_LOOT;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.utils.BArray;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
||||
import com.watabou.input.GameAction;
|
||||
import com.watabou.noosa.Image;
|
||||
import com.watabou.noosa.ui.Button;
|
||||
import com.watabou.utils.PathFinder;
|
||||
|
@ -95,7 +96,7 @@ public class QuickSlotButton extends Button implements WndBag.Listener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int keyAction() {
|
||||
public GameAction keyAction() {
|
||||
return QuickSlotButton.this.keyAction();
|
||||
}
|
||||
@Override
|
||||
|
@ -142,7 +143,7 @@ public class QuickSlotButton extends Button implements WndBag.Listener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int keyAction() {
|
||||
public GameAction keyAction() {
|
||||
switch (slotNum){
|
||||
case 0:
|
||||
return SPDAction.QUICKSLOT_1;
|
||||
|
|
|
@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.watabou.input.GameAction;
|
||||
import com.watabou.noosa.Image;
|
||||
|
||||
public class ResumeIndicator extends Tag {
|
||||
|
@ -40,7 +41,7 @@ public class ResumeIndicator extends Tag {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int keyAction() {
|
||||
public GameAction keyAction() {
|
||||
return SPDAction.TAG_RESUME;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal;
|
||||
import com.watabou.input.GameAction;
|
||||
import com.watabou.noosa.BitmapText;
|
||||
import com.watabou.noosa.Camera;
|
||||
import com.watabou.noosa.Game;
|
||||
|
@ -89,7 +90,7 @@ public class StatusPane extends Component {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int keyAction() {
|
||||
public GameAction keyAction() {
|
||||
return SPDAction.HERO_INFO;
|
||||
}
|
||||
}.setRect( 0, 1, 30, 30 ));
|
||||
|
@ -264,7 +265,7 @@ public class StatusPane extends Component {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int keyAction() {
|
||||
public GameAction keyAction() {
|
||||
return SPDAction.JOURNAL;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
|
|||
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTerrainTilemap;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal;
|
||||
import com.watabou.input.GameAction;
|
||||
import com.watabou.noosa.Camera;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.noosa.Gizmo;
|
||||
|
@ -88,7 +89,7 @@ public class Toolbar extends Component {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int keyAction() {
|
||||
public GameAction keyAction() {
|
||||
return SPDAction.WAIT;
|
||||
}
|
||||
|
||||
|
@ -112,7 +113,7 @@ public class Toolbar extends Component {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int keyAction() {
|
||||
public GameAction keyAction() {
|
||||
return SPDAction.SEARCH;
|
||||
}
|
||||
|
||||
|
@ -132,7 +133,7 @@ public class Toolbar extends Component {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int keyAction() {
|
||||
public GameAction keyAction() {
|
||||
return SPDAction.INVENTORY;
|
||||
}
|
||||
|
||||
|
|
|
@ -158,13 +158,12 @@ public class Window extends Group implements Signal.Listener<KeyEvent> {
|
|||
@Override
|
||||
public boolean onSignal( KeyEvent event ) {
|
||||
if (event.pressed) {
|
||||
switch (KeyBindings.getBinding( event )) {
|
||||
case SPDAction.BACK:
|
||||
onBackPressed();
|
||||
return true;
|
||||
case SPDAction.MENU:
|
||||
onMenuPressed();
|
||||
return true;
|
||||
if (KeyBindings.getActionForKey( event ) == SPDAction.BACK){
|
||||
onBackPressed();
|
||||
|
||||
} else if (KeyBindings.getActionForKey( event ) == SPDAction.MENU){
|
||||
onMenuPressed();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,13 +21,13 @@
|
|||
|
||||
package com.shatteredpixel.shatteredpixeldungeon.windows;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
||||
import com.watabou.input.GameAction;
|
||||
import com.watabou.input.KeyBindings;
|
||||
import com.watabou.noosa.ColorBlock;
|
||||
import com.watabou.noosa.ui.Component;
|
||||
|
@ -86,8 +86,10 @@ public class WndKeyBindings extends Window {
|
|||
add(scrollingList);
|
||||
|
||||
int y = 0;
|
||||
//start at 3. No bindings for NONE, BACK, and MENU.
|
||||
for (int action = 3; action < SPDAction.TOTAL_ACTIONS; action++){
|
||||
for (GameAction action : GameAction.allActions()){
|
||||
//start at 3. No bindings for NONE, BACK, and MENU.
|
||||
if (action.code() < 3) continue;
|
||||
|
||||
BindingListItem item = new BindingListItem(action);
|
||||
item.setRect(0, y, WIDTH, 12);
|
||||
bindingsList.add(item);
|
||||
|
@ -138,7 +140,7 @@ public class WndKeyBindings extends Window {
|
|||
private static final int DEFAULT = 0xFFFFFF;
|
||||
private static final int UNBOUND = 0x888888;
|
||||
|
||||
private int gameAction;
|
||||
private GameAction gameAction;
|
||||
private int key1;
|
||||
private int key2;
|
||||
|
||||
|
@ -150,14 +152,14 @@ public class WndKeyBindings extends Window {
|
|||
private ColorBlock sep2;
|
||||
private ColorBlock sep3;
|
||||
|
||||
public BindingListItem( int action ){
|
||||
public BindingListItem( GameAction action ){
|
||||
gameAction = action;
|
||||
|
||||
actionName = PixelScene.renderTextBlock(Messages.get(WndKeyBindings.class, KeyBindings.getName(action)), 6 );
|
||||
actionName = PixelScene.renderTextBlock(Messages.get(WndKeyBindings.class, action.name()), 6 );
|
||||
actionName.setHightlighting(false);
|
||||
add(actionName);
|
||||
|
||||
ArrayList<Integer> keys = KeyBindings.getBindings(action);
|
||||
ArrayList<Integer> keys = KeyBindings.getKeysForAction(action);
|
||||
|
||||
if (keys.size() >= 1){
|
||||
key1Name = PixelScene.renderTextBlock( KeyBindings.getKeyName(keys.get(0)), 6 );
|
||||
|
@ -165,7 +167,7 @@ public class WndKeyBindings extends Window {
|
|||
} else {
|
||||
key1Name = PixelScene.renderTextBlock( Messages.get(WndKeyBindings.class, "unbound"), 6 );
|
||||
key1Name.hardlight(UNBOUND);
|
||||
key1 = SPDAction.NONE;
|
||||
key1 = 0;
|
||||
}
|
||||
add(key1Name);
|
||||
|
||||
|
@ -175,7 +177,7 @@ public class WndKeyBindings extends Window {
|
|||
} else {
|
||||
key2Name = PixelScene.renderTextBlock( Messages.get(WndKeyBindings.class, "unbound"), 6 );
|
||||
key2Name.hardlight(UNBOUND);
|
||||
key2 = SPDAction.NONE;
|
||||
key2 = 0;
|
||||
}
|
||||
add(key2Name);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user