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 );
}
}

View File

@ -21,7 +21,6 @@
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import com.badlogic.gdx.Input;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
@ -30,6 +29,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.KeyAction;
import com.watabou.input.KeyBindings;
import com.watabou.input.KeyEvent;
import com.watabou.input.PointerEvent;
@ -55,7 +55,7 @@ public class CellSelector extends ScrollArea {
dragThreshold = PixelScene.defaultZoom * DungeonTilemap.SIZE / 2;
mouseZoom = camera.zoom;
KeyEvent.addKeyListener(movementListener);
KeyEvent.addKeyListener( keyListener );
}
private float mouseZoom;
@ -208,19 +208,33 @@ public class CellSelector extends ScrollArea {
}
private KeyEvent heldKey = null;
private int heldKeyTurns = 0;
private KeyAction heldAction = null;
private int heldTurns = 0;
private Signal.Listener<KeyEvent> movementListener = new Signal.Listener<KeyEvent>() {
private Signal.Listener<KeyEvent> keyListener = new Signal.Listener<KeyEvent>() {
@Override
public boolean onSignal(KeyEvent event) {
KeyAction action = KeyBindings.getBinding( event );
if (!event.pressed){
if (heldKey != null && heldKey.code == event.code) {
if (heldAction != null && heldAction == action) {
resetKeyHold();
return true;
} else {
switch (action){
case ZOOM_IN:
zoom( camera.zoom+1 );
return true;
case ZOOM_OUT:
zoom( camera.zoom-1 );
return true;
case ZOOM_DEFAULT:
zoom( PixelScene.defaultZoom );
return true;
}
}
} else if (moveFromKey(event)) {
heldKey = event;
} else if (moveFromKey(action)) {
heldAction = action;
return true;
}
@ -228,11 +242,11 @@ public class CellSelector extends ScrollArea {
}
};
private boolean moveFromKey(KeyEvent event){
private boolean moveFromKey(KeyAction event){
boolean moved = true;
int cell = Dungeon.hero.pos;
//TODO implement game actions, instead of using keys directly
switch (KeyBindings.getBinding( event )){
switch (event){
case N:
cell += -Dungeon.level.width();
break;
@ -265,7 +279,7 @@ public class CellSelector extends ScrollArea {
//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 - heldKeyTurns*0.025f));
Math.max(0, 0.05f - heldTurns *0.025f));
select(cell);
}
@ -273,16 +287,16 @@ public class CellSelector extends ScrollArea {
}
public void processKeyHold(){
if (heldKey != null){
if (heldAction != null){
enabled = true;
heldKeyTurns++;
moveFromKey(heldKey);
heldTurns++;
moveFromKey(heldAction);
}
}
public void resetKeyHold(){
heldKey = null;
heldKeyTurns = 0;
heldAction = null;
heldTurns = 0;
CharSprite.setMoveInterval( CharSprite.DEFAULT_MOVE_INTERVAL );
}
@ -315,7 +329,7 @@ public class CellSelector extends ScrollArea {
@Override
public void destroy() {
super.destroy();
KeyEvent.removeKeyListener(movementListener);
KeyEvent.removeKeyListener( keyListener );
}
public interface Listener {

View File

@ -23,6 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.input.KeyAction;
import com.watabou.noosa.Image;
public class ActionIndicator extends Tag {
@ -40,7 +41,12 @@ public class ActionIndicator extends Tag {
setSize( 24, 24 );
visible = false;
}
@Override
public KeyAction keyAction() {
return KeyAction.TAG_ACTION;
}
@Override
public void destroy() {
super.destroy();

View File

@ -26,6 +26,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.KeyAction;
import com.watabou.noosa.Game;
import com.watabou.utils.Random;
import com.watabou.utils.Reflection;
@ -57,6 +58,11 @@ public class AttackIndicator extends Tag {
enable( false );
}
@Override
public KeyAction keyAction() {
return KeyAction.TAG_ATTACK;
}
@Override
protected void createChildren() {
super.createChildren();

View File

@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.input.KeyAction;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Image;
@ -47,6 +48,11 @@ public class DangerIndicator extends Tag {
visible = false;
}
@Override
public KeyAction keyAction() {
return KeyAction.TAG_DANGER;
}
@Override
protected void createChildren() {
super.createChildren();

View File

@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.watabou.input.KeyAction;
public class LootIndicator extends Tag {
@ -40,6 +41,11 @@ public class LootIndicator extends Tag {
visible = false;
}
@Override
public KeyAction keyAction() {
return KeyAction.TAG_LOOT;
}
@Override
protected void createChildren() {
super.createChildren();

View File

@ -31,6 +31,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.KeyAction;
import com.watabou.noosa.Image;
import com.watabou.noosa.ui.Button;
import com.watabou.utils.PathFinder;
@ -92,6 +93,11 @@ public class QuickSlotButton extends Button implements WndBag.Listener {
item.execute( Dungeon.hero );
}
}
@Override
public KeyAction keyAction() {
return QuickSlotButton.this.keyAction();
}
@Override
protected boolean onLongClick() {
return QuickSlotButton.this.onLongClick();
@ -127,6 +133,22 @@ public class QuickSlotButton extends Button implements WndBag.Listener {
PixelScene.align(crossB);
}
@Override
public KeyAction keyAction() {
switch (slotNum){
case 0:
return KeyAction.QUICKSLOT_1;
case 1:
return KeyAction.QUICKSLOT_2;
case 2:
return KeyAction.QUICKSLOT_3;
case 3:
return KeyAction.QUICKSLOT_4;
default:
return super.keyAction();
}
}
@Override
protected void onClick() {
GameScene.selectItem( this, WndBag.Mode.QUICKSLOT, Messages.get(this, "select_item") );

View File

@ -23,6 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.input.KeyAction;
import com.watabou.noosa.Image;
public class ResumeIndicator extends Tag {
@ -37,6 +38,11 @@ public class ResumeIndicator extends Tag {
visible = false;
}
@Override
public KeyAction keyAction() {
return KeyAction.TAG_RESUME;
}
@Override
protected void createChildren() {

View File

@ -32,7 +32,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.PointerEvent;
import com.watabou.input.KeyAction;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
@ -82,14 +82,18 @@ public class StatusPane extends Component {
bg = new NinePatch( Assets.STATUS, 0, 0, 128, 36, 85, 0, 45, 0 );
add( bg );
add( new PointerArea( 0, 1, 31, 31 ) {
add( new Button(){
@Override
protected void onClick( PointerEvent event ) {
Image sprite = Dungeon.hero.sprite;
Camera.main.panTo( sprite.center(), 5f );
protected void onClick () {
Camera.main.panTo( Dungeon.hero.sprite.center(), 5f );
GameScene.show( new WndHero() );
}
} );
@Override
public KeyAction keyAction() {
return KeyAction.HERO_INFO;
}
}.setRect( 0, 1, 30, 30 ));
btnJournal = new JournalButton();
add( btnJournal );
@ -259,7 +263,12 @@ public class StatusPane extends Component {
width = bg.width + 13; //includes the depth display to the left
height = bg.height + 4;
}
@Override
public KeyAction keyAction() {
return KeyAction.JOURNAL;
}
@Override
protected void createChildren() {
super.createChildren();

View File

@ -32,6 +32,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.KeyAction;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Gizmo;
@ -78,7 +79,12 @@ public class Toolbar extends Component {
examining = false;
Dungeon.hero.rest(false);
}
@Override
public KeyAction keyAction() {
return KeyAction.WAIT;
}
protected boolean onLongClick() {
examining = false;
Dungeon.hero.rest(true);
@ -97,7 +103,12 @@ public class Toolbar extends Component {
Dungeon.hero.search(true);
}
}
@Override
public KeyAction keyAction() {
return KeyAction.SEARCH;
}
@Override
protected boolean onLongClick() {
Dungeon.hero.search(true);
@ -123,6 +134,11 @@ public class Toolbar extends Component {
GameScene.show(new WndBag(Dungeon.hero.belongings.backpack, null, WndBag.Mode.ALL, null));
}
@Override
public KeyAction keyAction() {
return KeyAction.INVENTORY;
}
@Override
protected boolean onLongClick() {
WndJournal.last_index = 3; //catalog page