v1.2.1: added support for binding mouse 4 and 5 to game actions
This commit is contained in:
@@ -91,19 +91,29 @@ public class InputHandler extends InputAdapter {
|
|||||||
public synchronized boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
public synchronized boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
||||||
ControllerHandler.setControllerPointer(false);
|
ControllerHandler.setControllerPointer(false);
|
||||||
Gdx.input.setOnscreenKeyboardVisible(false); //in-game events never need keyboard, so hide it
|
Gdx.input.setOnscreenKeyboardVisible(false); //in-game events never need keyboard, so hide it
|
||||||
PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, PointerEvent.Type.DOWN, button));
|
|
||||||
|
if (button >= 3 && KeyBindings.isKeyBound( button + 1000 )) {
|
||||||
|
KeyEvent.addKeyEvent( new KeyEvent( button + 1000, true ) );
|
||||||
|
} else if (button < 3) {
|
||||||
|
PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, PointerEvent.Type.DOWN, button));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
public synchronized boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||||
PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, PointerEvent.Type.UP, button));
|
|
||||||
|
if (button >= 3 && KeyBindings.isKeyBound( button + 1000 )) {
|
||||||
|
KeyEvent.addKeyEvent( new KeyEvent( button + 1000, true ) );
|
||||||
|
} else if (button < 3) {
|
||||||
|
PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, PointerEvent.Type.UP, button));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean touchDragged(int screenX, int screenY, int pointer) {
|
public synchronized boolean touchDragged(int screenX, int screenY, int pointer) {
|
||||||
PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, PointerEvent.Type.DOWN));
|
PointerEvent.addIfExisting(new PointerEvent(screenX, screenY, pointer, PointerEvent.Type.DOWN));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class KeyBindings {
|
|||||||
public static boolean bindingKey = false;
|
public static boolean bindingKey = false;
|
||||||
|
|
||||||
public static boolean isKeyBound(int keyCode){
|
public static boolean isKeyBound(int keyCode){
|
||||||
if (keyCode <= 0 || keyCode > 255){
|
if (keyCode < 0 || (keyCode > 255 && keyCode < 1000)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return bindingKey || bindings.containsKey( keyCode ) || hardBindings.containsKey( keyCode );
|
return bindingKey || bindings.containsKey( keyCode ) || hardBindings.containsKey( keyCode );
|
||||||
@@ -80,6 +80,13 @@ public class KeyBindings {
|
|||||||
return ControllerHandler.customButtonName(keyCode);
|
return ControllerHandler.customButtonName(keyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//custom codes for mouse buttons
|
||||||
|
if (keyCode == 1003){
|
||||||
|
return "Mouse 4";
|
||||||
|
} else if (keyCode == 1004) {
|
||||||
|
return "Mouse 5";
|
||||||
|
}
|
||||||
|
|
||||||
if (keyCode == Input.Keys.UNKNOWN){
|
if (keyCode == Input.Keys.UNKNOWN){
|
||||||
return "None";
|
return "None";
|
||||||
} else if (keyCode == Input.Keys.PLUS){
|
} else if (keyCode == Input.Keys.PLUS){
|
||||||
|
|||||||
@@ -126,6 +126,12 @@ public class PointerEvent {
|
|||||||
pointerEvents.add( event );
|
pointerEvents.add( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static synchronized void addIfExisting( PointerEvent event ){
|
||||||
|
if (activePointers.containsKey(event.id)) {
|
||||||
|
pointerEvents.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static synchronized void processPointerEvents(){
|
public static synchronized void processPointerEvents(){
|
||||||
//handle any hover events separately first as we may need to add drag events
|
//handle any hover events separately first as we may need to add drag events
|
||||||
boolean hovered = false;
|
boolean hovered = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user