v0.8.0: added all other key actions from old desktop build, no remapping yet

This commit is contained in:
Evan Debenham
2019-10-30 15:49:09 -04:00
parent 1539d57f71
commit 0696bf1f36
12 changed files with 196 additions and 33 deletions

View File

@@ -21,11 +21,32 @@
package com.watabou.input;
//FIXME this is describing actions defined in the core module, it should probably be moved there.
public enum KeyAction {
BACK,
MENU,
N, NE, E, SE, S, SW, W, NW,
HERO_INFO,
JOURNAL,
UNKNOWN
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
}

View File

@@ -32,14 +32,37 @@ public class KeyBindings {
static {
bindings = new HashMap<>();
bindings.put( Input.Keys.BACK, KeyAction.BACK );
bindings.put( Input.Keys.MENU, KeyAction.MENU );
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 );

View File

@@ -21,9 +21,13 @@
package com.watabou.noosa.ui;
import com.watabou.input.KeyAction;
import com.watabou.input.KeyBindings;
import com.watabou.input.KeyEvent;
import com.watabou.input.PointerEvent;
import com.watabou.noosa.Game;
import com.watabou.noosa.PointerArea;
import com.watabou.utils.Signal;
public class Button extends Component {
@@ -33,7 +37,6 @@ public class Button extends Component {
protected boolean pressed;
protected float pressTime;
protected boolean processed;
@Override
@@ -59,6 +62,24 @@ public class Button extends Component {
}
};
add( hotArea );
KeyEvent.addKeyListener( keyListener = new Signal.Listener<KeyEvent>() {
@Override
public boolean onSignal ( KeyEvent event ) {
if ( active && !event.pressed && KeyBindings.getBinding( event ) != null
&& KeyBindings.getBinding( event ) == keyAction()){
onClick();
return true;
}
return false;
}
});
}
private Signal.Listener<KeyEvent> keyListener;
public KeyAction keyAction(){
return null;
}
@Override
@@ -96,4 +117,11 @@ public class Button extends Component {
hotArea.width = width;
hotArea.height = height;
}
@Override
public synchronized void destroy () {
super.destroy();
KeyEvent.removeKeyListener( keyListener );
}
}