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