v1.3.0: implemented new radial menus and made a bunch of keybind changes
This commit is contained in:
@@ -27,6 +27,8 @@ import com.badlogic.gdx.controllers.Controller;
|
||||
import com.badlogic.gdx.controllers.ControllerListener;
|
||||
import com.badlogic.gdx.controllers.ControllerMapping;
|
||||
import com.badlogic.gdx.controllers.Controllers;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.noosa.ui.Cursor;
|
||||
import com.watabou.utils.DeviceCompat;
|
||||
import com.watabou.utils.PointF;
|
||||
|
||||
@@ -138,14 +140,32 @@ public class ControllerHandler implements ControllerListener {
|
||||
|
||||
//we use a separate variable as Gdx.input.isCursorCatched only works on desktop
|
||||
private static boolean controllerPointerActive = false;
|
||||
private static PointF controllerPointerPos;
|
||||
|
||||
public static void setControllerPointer( boolean active ){
|
||||
Gdx.input.setCursorCatched(active);
|
||||
if (controllerPointerActive == active) return;
|
||||
controllerPointerActive = active;
|
||||
if (active){
|
||||
Gdx.input.setCursorCatched(true);
|
||||
controllerPointerPos = new PointF(Game.width/2, Game.height/2);
|
||||
} else if (!Cursor.isCursorCaptured()) {
|
||||
Gdx.input.setCursorCatched(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean controllerPointerActive(){
|
||||
return controllerPointerActive;
|
||||
return controllerPointerActive && !Cursor.isCursorCaptured();
|
||||
}
|
||||
|
||||
public static PointF getControllerPointerPos(){
|
||||
return controllerPointerPos.clone();
|
||||
}
|
||||
|
||||
public static void updateControllerPointer(PointF pos, boolean sendEvent){
|
||||
controllerPointerPos.set(pos);
|
||||
if (sendEvent) {
|
||||
PointerEvent.addPointerEvent(new PointerEvent((int) controllerPointerPos.x, (int) controllerPointerPos.y, 10_000, PointerEvent.Type.HOVER, PointerEvent.NONE));
|
||||
}
|
||||
}
|
||||
|
||||
//converts controller button codes to keyEvent codes
|
||||
@@ -199,6 +219,16 @@ public class ControllerHandler implements ControllerListener {
|
||||
} else if (keyCode == Input.Keys.BUTTON_Y){
|
||||
return "Triangle Button";
|
||||
}
|
||||
} else if (lastUsedType == ControllerType.XBOX){
|
||||
if (keyCode == Input.Keys.BUTTON_L1){
|
||||
return "Left Bumper";
|
||||
} else if (keyCode == Input.Keys.BUTTON_L2){
|
||||
return "Left Trigger";
|
||||
} else if (keyCode == Input.Keys.BUTTON_R1){
|
||||
return "Right Bumper";
|
||||
} else if (keyCode == Input.Keys.BUTTON_R2){
|
||||
return "Right Trigger";
|
||||
}
|
||||
}
|
||||
|
||||
if (keyCode == Input.Keys.DPAD_UP + 1000){
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.badlogic.gdx.InputAdapter;
|
||||
import com.badlogic.gdx.InputMultiplexer;
|
||||
import com.badlogic.gdx.InputProcessor;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.noosa.ui.Cursor;
|
||||
|
||||
public class InputHandler extends InputAdapter {
|
||||
|
||||
|
||||
@@ -82,19 +82,17 @@ public class KeyBindings {
|
||||
return GameAction.NONE;
|
||||
}
|
||||
|
||||
public static ArrayList<Integer> getBoundKeysForAction(GameAction action){
|
||||
ArrayList<Integer> result = new ArrayList<>();
|
||||
for( int i : bindings.keySet() ){
|
||||
if (bindings.get(i) == action){
|
||||
result.add(i);
|
||||
}
|
||||
public static int getFirstKeyForAction(GameAction action, boolean preferController){
|
||||
ArrayList<Integer> keys = getKeyboardKeysForAction(action);
|
||||
ArrayList<Integer> buttons = getControllerKeysForAction(action);
|
||||
if (preferController){
|
||||
if (!buttons.isEmpty()) return buttons.get(0);
|
||||
else if (!keys.isEmpty()) return keys.get(0);
|
||||
} else {
|
||||
if (!keys.isEmpty()) return keys.get(0);
|
||||
else if (!buttons.isEmpty()) return buttons.get(0);
|
||||
}
|
||||
for( int i : controllerBindings.keySet() ){
|
||||
if (controllerBindings.get(i) == action){
|
||||
result.add(i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static ArrayList<Integer> getKeyboardKeysForAction(GameAction action){
|
||||
|
||||
@@ -23,10 +23,13 @@ package com.watabou.input;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.noosa.ui.Cursor;
|
||||
import com.watabou.utils.GameMath;
|
||||
import com.watabou.utils.PointF;
|
||||
import com.watabou.utils.Signal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Currency;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PointerEvent {
|
||||
@@ -57,6 +60,10 @@ public class PointerEvent {
|
||||
}
|
||||
|
||||
public PointerEvent( int x, int y, int id, Type type, int button){
|
||||
if (Cursor.isCursorCaptured()){
|
||||
x = Game.width/2;
|
||||
y = Game.width/2;
|
||||
}
|
||||
start = current = new PointF(x, y);
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
|
||||
@@ -24,7 +24,10 @@ package com.watabou.noosa.ui;
|
||||
import com.badlogic.gdx.Files;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.watabou.input.ControllerHandler;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.utils.FileUtils;
|
||||
import com.watabou.utils.PointF;
|
||||
|
||||
public class Cursor {
|
||||
|
||||
@@ -86,4 +89,30 @@ public class Cursor {
|
||||
|
||||
}
|
||||
|
||||
private static boolean cursorCaptured = false;
|
||||
|
||||
public static void captureCursor(boolean captured){
|
||||
cursorCaptured = captured;
|
||||
|
||||
if (captured) {
|
||||
Gdx.input.setCursorCatched(true);
|
||||
} else {
|
||||
if (ControllerHandler.controllerPointerActive()) {
|
||||
ControllerHandler.setControllerPointer(true);
|
||||
ControllerHandler.updateControllerPointer(new PointF(Game.width/2, Game.height/2), false);
|
||||
} else {
|
||||
Gdx.input.setCursorCatched(false);
|
||||
Gdx.input.setCursorPosition(Game.width/2, Game.height/2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static PointF getCursorDelta(){
|
||||
return new PointF(Gdx.input.getDeltaX(), Gdx.input.getDeltaY());
|
||||
}
|
||||
|
||||
public static boolean isCursorCaptured(){
|
||||
return cursorCaptured;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -138,7 +138,11 @@ public class PointF {
|
||||
float dy = a.y - b.y;
|
||||
return (float)Math.sqrt( dx * dx + dy * dy );
|
||||
}
|
||||
|
||||
|
||||
public static float angle( float x, float y ) {
|
||||
return (float)Math.atan2( y, x );
|
||||
}
|
||||
|
||||
public static float angle( PointF start, PointF end ) {
|
||||
return (float)Math.atan2( end.y - start.y, end.x - start.x );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user