1288 lines
64 KiB
Java
1288 lines
64 KiB
Java
package electrosphere.controls;
|
|
|
|
import electrosphere.audio.AudioUtils;
|
|
import electrosphere.controls.Control.ControlMethod;
|
|
import electrosphere.controls.Control.ControlType;
|
|
import electrosphere.entity.Entity;
|
|
import electrosphere.entity.EntityDataStrings;
|
|
import electrosphere.entity.types.creature.CreatureUtils;
|
|
import electrosphere.entity.state.AttackTree;
|
|
import electrosphere.entity.state.equip.EquipState;
|
|
import electrosphere.entity.state.inventory.InventoryUtils;
|
|
import electrosphere.entity.state.inventory.UnrelationalInventoryState;
|
|
import electrosphere.entity.state.ironsight.IronSightTree;
|
|
import electrosphere.entity.state.movement.GroundMovementTree;
|
|
import electrosphere.entity.state.movement.JumpTree;
|
|
import electrosphere.entity.state.movement.GroundMovementTree.MovementRelativeFacing;
|
|
import electrosphere.entity.state.movement.GroundMovementTree.MovementTreeState;
|
|
import electrosphere.entity.state.movement.SprintTree;
|
|
import electrosphere.entity.types.camera.CameraEntityUtils;
|
|
import electrosphere.game.client.targeting.crosshair.Crosshair;
|
|
import electrosphere.logger.LoggerInterface;
|
|
import electrosphere.main.Globals;
|
|
import electrosphere.main.Main;
|
|
import electrosphere.menu.WindowStrings;
|
|
import electrosphere.menu.WindowUtils;
|
|
import electrosphere.menu.MenuGenerators;
|
|
import electrosphere.menu.MenuGeneratorsInventory;
|
|
import electrosphere.renderer.ui.Window;
|
|
import electrosphere.renderer.ui.events.ClickEvent;
|
|
import electrosphere.renderer.ui.events.KeyboardEvent;
|
|
import electrosphere.renderer.ui.events.MenuEvent;
|
|
import electrosphere.renderer.ui.events.MouseEvent;
|
|
import electrosphere.renderer.ui.events.MenuEvent.MenuEventType;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
import org.joml.Vector2f;
|
|
import org.joml.Vector3d;
|
|
import org.joml.Vector3f;
|
|
import org.lwjgl.glfw.GLFW;
|
|
|
|
import static org.lwjgl.glfw.GLFW.*;
|
|
import static org.lwjgl.glfw.GLFW.glfwGetCursorPos;
|
|
import static org.lwjgl.glfw.GLFW.glfwSetInputMode;
|
|
|
|
/**
|
|
*
|
|
* @author amaterasu
|
|
*/
|
|
public class ControlHandler {
|
|
|
|
public static final String INPUT_CODE_CAMERA_ROTATION = "cameraRotation";
|
|
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD = "moveForward";
|
|
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD = "moveBackward";
|
|
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_LEFT = "moveLeft";
|
|
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT = "moveRight";
|
|
public static final String DATA_STRING_INPUT_CODE_STRAFE_LEFT = "strafeLeft";
|
|
public static final String DATA_STRING_INPUT_CODE_STRAFE_RIGHT = "strafeRight";
|
|
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_JUMP = "jump";
|
|
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_FALL = "fall";
|
|
public static final String DATA_STRING_INPUT_CODE_ATTACK_PRIMARY = "attackPrimary";
|
|
public static final String DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM = "debugSpawnItem";
|
|
public static final String DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU = "inGameMainMenu";
|
|
public static final String DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR = "crosshairLock";
|
|
public static final String INPUT_CODE_SPRINT = "sprint";
|
|
public static final String INPUT_CODE_INTERACT = "interact";
|
|
public static final String INPUT_CODE_DROP = "drop";
|
|
public static final String INPUT_CODE_INVENTORY_OPEN = "inventoryOpen";
|
|
public static final String INPUT_CODE_CHARACTER_OPEN = "characterOpen";
|
|
public static final String INPUT_CODE_IRON_SIGHT = "ironSight";
|
|
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_NAVIGATE_FORWARD = "menuNavigateForward";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_NAVIGATE_BACKWARDS = "menuNavigateBackwards";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_INCREMENT = "menuIncrement";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_DECREMENT = "menuDecrement";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_SELECT = "menuSelect";
|
|
public static final String INPUT_CODE_MENU_MOUSE_PRIMARY = "menuMousePrimary";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_BACKOUT = "menuBackout";
|
|
|
|
|
|
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE = "menuTypeBackspace";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_0 = "menuType0";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_1 = "menuType1";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_2 = "menuType2";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_3 = "menuType3";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_4 = "menuType4";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_5 = "menuType5";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_6 = "menuType6";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_7 = "menuType7";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_8 = "menuType8";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_9 = "menuType9";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD = "menuType.";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_A = "menuTypeA";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_B = "menuTypeB";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_C = "menuTypeC";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_D = "menuTypeD";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_E = "menuTypeE";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_F = "menuTypeF";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_G = "menuTypeG";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_H = "menuTypeH";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_I = "menuTypeI";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_J = "menuTypeJ";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_K = "menuTypeK";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_L = "menuTypeL";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_M = "menuTypeM";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_N = "menuTypeN";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_O = "menuTypeO";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_P = "menuTypeP";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_Q = "menuTypeQ";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_R = "menuTypeR";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_S = "menuTypeS";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_T = "menuTypeT";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_U = "menuTypeU";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_V = "menuTypeV";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_W = "menuTypeW";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_X = "menuTypeX";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_Y = "menuTypeY";
|
|
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_Z = "menuTypeZ";
|
|
public static final String INPUT_CODE_MENU_TYPE_FORWARD_SLASH = "menuTypeForwardSlash";
|
|
|
|
public static final String INPUT_CODE_INVENTORY_CLOSE = "inventoryClose";
|
|
public static final String INPUT_CODE_INVENTORY_ITEM_MANIPULATE = "inventoryItemManipulate";
|
|
public static final String INPUT_CODE_INVENTORY_ITEM_DRAG = "inventoryDrag";
|
|
|
|
public static final String DEBUG_FRAMESTEP = "framestep";
|
|
|
|
|
|
public static enum ControlsState {
|
|
TITLE_PAGE,
|
|
TITLE_MENU,
|
|
MAIN_GAME,
|
|
IN_GAME_MAIN_MENU,
|
|
INVENTORY,
|
|
NO_INPUT,
|
|
}
|
|
|
|
ControlsState state = ControlsState.TITLE_MENU;
|
|
|
|
boolean mouseIsVisible = true;
|
|
|
|
boolean shouldRecaptureScreen = false;
|
|
|
|
|
|
/*
|
|
Mouse event parsing related stuff
|
|
*/
|
|
float mouse_lastX = 400;
|
|
float mouse_lastY = 300;
|
|
double xpos = 400;
|
|
double ypos = 300;
|
|
double mouse_X_Buffer[] = new double[1];
|
|
double mouse_Y_Buffer[] = new double[1];
|
|
boolean dragging = false;
|
|
|
|
|
|
|
|
HashMap<String, Control> controls;
|
|
|
|
List<Control> mainGameControlList = new LinkedList<Control>();
|
|
List<Control> mainGameDebugControlList = new LinkedList<Control>();
|
|
List<Control> menuNavigationControlList = new LinkedList<Control>();
|
|
List<Control> typingControlList = new LinkedList<Control>();
|
|
List<Control> inventoryControlList = new LinkedList<Control>();
|
|
|
|
ControlHandler(){
|
|
controls = new HashMap<String, Control>();
|
|
}
|
|
|
|
public static ControlHandler generateExampleControlsMap(){
|
|
ControlHandler handler = new ControlHandler();
|
|
/*
|
|
Main Game controls
|
|
*/
|
|
|
|
/*
|
|
Map the controls
|
|
*/
|
|
handler.addControl(INPUT_CODE_CAMERA_ROTATION, new Control(ControlType.MOUSE_MOVEMENT,0));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, new Control(ControlType.KEY,GLFW_KEY_W));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, new Control(ControlType.KEY,GLFW_KEY_S));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, new Control(ControlType.KEY,GLFW_KEY_A));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, new Control(ControlType.KEY,GLFW_KEY_D));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_STRAFE_LEFT, new Control(ControlType.KEY,GLFW_KEY_F24));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_STRAFE_RIGHT, new Control(ControlType.KEY,GLFW_KEY_F24));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP, new Control(ControlType.KEY,GLFW_KEY_SPACE));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FALL, new Control(ControlType.KEY,GLFW_KEY_LEFT_CONTROL));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_LEFT));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU, new Control(ControlType.KEY,GLFW_KEY_ESCAPE));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR, new Control(ControlType.KEY,GLFW_KEY_CAPS_LOCK));
|
|
handler.addControl(INPUT_CODE_SPRINT, new Control(ControlType.KEY,GLFW_KEY_LEFT_SHIFT));
|
|
handler.addControl(INPUT_CODE_INTERACT, new Control(ControlType.KEY,GLFW_KEY_E));
|
|
handler.addControl(INPUT_CODE_DROP, new Control(ControlType.KEY,GLFW_KEY_Y));
|
|
handler.addControl(INPUT_CODE_INVENTORY_OPEN, new Control(ControlType.KEY,GLFW_KEY_I));
|
|
handler.addControl(INPUT_CODE_CHARACTER_OPEN, new Control(ControlType.KEY,GLFW_KEY_C));
|
|
handler.addControl(INPUT_CODE_IRON_SIGHT, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_RIGHT));
|
|
|
|
/*
|
|
Map the menu navigation controls
|
|
*/
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_NAVIGATE_FORWARD, new Control(ControlType.KEY,GLFW_KEY_DOWN));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_NAVIGATE_BACKWARDS, new Control(ControlType.KEY,GLFW_KEY_UP));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_INCREMENT, new Control(ControlType.KEY,GLFW_KEY_RIGHT));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_DECREMENT, new Control(ControlType.KEY,GLFW_KEY_LEFT));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_SELECT, new Control(ControlType.KEY,GLFW_KEY_ENTER));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_BACKOUT, new Control(ControlType.KEY,GLFW_KEY_ESCAPE));
|
|
handler.addControl(INPUT_CODE_MENU_MOUSE_PRIMARY, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_LEFT));
|
|
|
|
/*
|
|
Map the typing controls
|
|
*/
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE, new Control(ControlType.KEY,GLFW_KEY_BACKSPACE));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_0, new Control(ControlType.KEY,GLFW_KEY_0));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_1, new Control(ControlType.KEY,GLFW_KEY_1));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_2, new Control(ControlType.KEY,GLFW_KEY_2));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_3, new Control(ControlType.KEY,GLFW_KEY_3));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_4, new Control(ControlType.KEY,GLFW_KEY_4));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_5, new Control(ControlType.KEY,GLFW_KEY_5));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_6, new Control(ControlType.KEY,GLFW_KEY_6));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_7, new Control(ControlType.KEY,GLFW_KEY_7));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_8, new Control(ControlType.KEY,GLFW_KEY_8));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_9, new Control(ControlType.KEY,GLFW_KEY_9));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD, new Control(ControlType.KEY,GLFW_KEY_PERIOD));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_A, new Control(ControlType.KEY,GLFW_KEY_A));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_B, new Control(ControlType.KEY,GLFW_KEY_B));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_C, new Control(ControlType.KEY,GLFW_KEY_C));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_D, new Control(ControlType.KEY,GLFW_KEY_D));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_E, new Control(ControlType.KEY,GLFW_KEY_E));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_F, new Control(ControlType.KEY,GLFW_KEY_F));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_G, new Control(ControlType.KEY,GLFW_KEY_G));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_H, new Control(ControlType.KEY,GLFW_KEY_H));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_I, new Control(ControlType.KEY,GLFW_KEY_I));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_J, new Control(ControlType.KEY,GLFW_KEY_J));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_K, new Control(ControlType.KEY,GLFW_KEY_K));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_L, new Control(ControlType.KEY,GLFW_KEY_L));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_M, new Control(ControlType.KEY,GLFW_KEY_M));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_N, new Control(ControlType.KEY,GLFW_KEY_N));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_O, new Control(ControlType.KEY,GLFW_KEY_O));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_P, new Control(ControlType.KEY,GLFW_KEY_P));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_Q, new Control(ControlType.KEY,GLFW_KEY_Q));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_R, new Control(ControlType.KEY,GLFW_KEY_R));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_S, new Control(ControlType.KEY,GLFW_KEY_S));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_T, new Control(ControlType.KEY,GLFW_KEY_T));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_U, new Control(ControlType.KEY,GLFW_KEY_U));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_V, new Control(ControlType.KEY,GLFW_KEY_V));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_W, new Control(ControlType.KEY,GLFW_KEY_W));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_X, new Control(ControlType.KEY,GLFW_KEY_X));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_Y, new Control(ControlType.KEY,GLFW_KEY_Y));
|
|
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_Z, new Control(ControlType.KEY,GLFW_KEY_Z));
|
|
handler.addControl(INPUT_CODE_MENU_TYPE_FORWARD_SLASH, new Control(ControlType.KEY,GLFW_KEY_SLASH));
|
|
|
|
/*
|
|
Inventory controls
|
|
*/
|
|
handler.addControl(INPUT_CODE_INVENTORY_CLOSE, new Control(ControlType.KEY,GLFW_KEY_I));
|
|
handler.addControl(INPUT_CODE_INVENTORY_ITEM_MANIPULATE, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_1));
|
|
handler.addControl(INPUT_CODE_INVENTORY_ITEM_DRAG, new Control(ControlType.MOUSE_MOVEMENT,0));
|
|
|
|
/*
|
|
framestep controls
|
|
*/
|
|
handler.addControl(DEBUG_FRAMESTEP, new Control(ControlType.KEY, GLFW_KEY_P));
|
|
|
|
/*
|
|
set state
|
|
*/
|
|
handler.setHandlerState(ControlsState.TITLE_MENU);
|
|
|
|
/*
|
|
Save to file
|
|
*/
|
|
// Utilities.saveObjectToBakedJsonFile("/Config/keybinds.json", handler);
|
|
|
|
/*
|
|
Debug controls
|
|
*/
|
|
handler.addControl(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM, new Control(ControlType.KEY,GLFW_KEY_Q));
|
|
|
|
/*
|
|
return
|
|
*/
|
|
return handler;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void pollControls(){
|
|
switch(state){
|
|
|
|
|
|
case MAIN_GAME:
|
|
runHandlers(mainGameControlList);
|
|
runHandlers(mainGameDebugControlList);
|
|
break;
|
|
|
|
|
|
|
|
case TITLE_PAGE:
|
|
break;
|
|
|
|
|
|
case TITLE_MENU:
|
|
runHandlers(menuNavigationControlList);
|
|
/*
|
|
Typing..
|
|
*/
|
|
runHandlers(typingControlList);
|
|
break;
|
|
|
|
case IN_GAME_MAIN_MENU:
|
|
runHandlers(menuNavigationControlList);
|
|
runHandlers(typingControlList);
|
|
// pollMenuNavigationControls();
|
|
break;
|
|
|
|
case INVENTORY:
|
|
runHandlers(inventoryControlList);
|
|
runHandlers(menuNavigationControlList);
|
|
break;
|
|
|
|
case NO_INPUT:
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public void setCallbacks(){
|
|
setMainGameControls();
|
|
setInGameDebugControls();
|
|
setMenuNavigationControls();
|
|
setTypingControls();
|
|
setInventoryControls();
|
|
}
|
|
|
|
void setMainGameControls(){
|
|
/*
|
|
Camera rotation
|
|
*/
|
|
mainGameControlList.add(controls.get(INPUT_CODE_CAMERA_ROTATION));
|
|
controls.get(INPUT_CODE_CAMERA_ROTATION).setOnMove(new Control.MouseCallback(){public void execute(MouseEvent event){
|
|
Globals.cameraHandler.handleMouseEvent(event);
|
|
}});
|
|
/*
|
|
Move forward
|
|
*/
|
|
mainGameControlList.add(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD));
|
|
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).setOnPress(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
|
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isState()){
|
|
Vector3d newFacingVector = new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI/4.0).normalize();
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, newFacingVector);
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
} else if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isState()){
|
|
Vector3d newFacingVector = new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(-Math.PI/4.0).normalize();
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, newFacingVector);
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
} else {
|
|
Vector3d newFacingVector = new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize();
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, newFacingVector);
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
}
|
|
}
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).setOnRepeat(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
|
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isState()){
|
|
Vector3d newFacingVector = new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI/4.0).normalize();
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, newFacingVector);
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
} else if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isState()){
|
|
Vector3d newFacingVector = new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(-Math.PI/4.0).normalize();
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, newFacingVector);
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
} else {
|
|
Vector3d newFacingVector = new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize();
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, newFacingVector);
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
}
|
|
}
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).setOnRelease(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
movementTree.slowdown();
|
|
}
|
|
}});
|
|
/*
|
|
Move backward
|
|
*/
|
|
mainGameControlList.add(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD));
|
|
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).setOnPress(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
|
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isState()){
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(3.0/4.0*Math.PI).normalize());
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
} else if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isState()){
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(5.0/4.0*Math.PI).normalize());
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
} else {
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI).normalize());
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
}
|
|
}
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).setOnRepeat(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
|
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isState()){
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(3.0/4.0*Math.PI).normalize());
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
} else if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isState()){
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(5.0/4.0*Math.PI).normalize());
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
} else {
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI).normalize());
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
}
|
|
}
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).setOnRelease(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
movementTree.slowdown();
|
|
}
|
|
}});
|
|
/*
|
|
move left
|
|
*/
|
|
mainGameControlList.add(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT));
|
|
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).setOnPress(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
|
if(
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) &&
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()))
|
|
){
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI/2.0).normalize());
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
}
|
|
}
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).setOnRepeat(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
|
if(
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) &&
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()))
|
|
){
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI/2.0).normalize());
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
}
|
|
}
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).setOnRelease(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
movementTree.slowdown();
|
|
}
|
|
}});
|
|
/*
|
|
move right
|
|
*/
|
|
mainGameControlList.add(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT));
|
|
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).setOnPress(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
|
if(
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) &&
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()))
|
|
){
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(-Math.PI/2.0).normalize());
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
}
|
|
}
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).setOnRepeat(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
|
if(
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) &&
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()))
|
|
){
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(-Math.PI/2.0).normalize());
|
|
movementTree.start(MovementRelativeFacing.FORWARD);
|
|
}
|
|
}
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).setOnRelease(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
movementTree.slowdown();
|
|
}
|
|
}});
|
|
|
|
/*
|
|
Move up
|
|
*/
|
|
|
|
/*
|
|
Move down
|
|
*/
|
|
|
|
/*
|
|
strafe left
|
|
*/
|
|
mainGameControlList.add(controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT));
|
|
controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).setOnPress(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z));
|
|
if(
|
|
(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN) &&
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) &&
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()))
|
|
){
|
|
movementTree.start(MovementRelativeFacing.LEFT);
|
|
}
|
|
}
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).setOnRepeat(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z));
|
|
if(
|
|
(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN) &&
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) &&
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()))
|
|
){
|
|
movementTree.start(MovementRelativeFacing.LEFT);
|
|
}
|
|
}
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).setOnRelease(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
movementTree.slowdown();
|
|
}
|
|
}});
|
|
/*
|
|
strafe right
|
|
*/
|
|
mainGameControlList.add(controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT));
|
|
controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).setOnPress(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z));
|
|
if(
|
|
(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN) &&
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) &&
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()))
|
|
){
|
|
movementTree.start(MovementRelativeFacing.RIGHT);
|
|
}
|
|
}
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).setOnRepeat(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
|
CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z));
|
|
if(
|
|
(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN) &&
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) &&
|
|
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()))
|
|
){
|
|
movementTree.start(MovementRelativeFacing.RIGHT);
|
|
}
|
|
}
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).setOnRelease(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerEntity);
|
|
movementTree.slowdown();
|
|
}
|
|
}});
|
|
/*
|
|
Jump
|
|
DATA_STRING_INPUT_CODE_MOVEMENT_JUMP
|
|
*/
|
|
mainGameControlList.add(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP));
|
|
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP).setOnPress(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
JumpTree jumpTree = JumpTree.getJumpTree(Globals.playerEntity);
|
|
if(jumpTree != null){
|
|
jumpTree.start();
|
|
}
|
|
}
|
|
}});
|
|
/*
|
|
Sprint
|
|
*/
|
|
mainGameControlList.add(controls.get(INPUT_CODE_SPRINT));
|
|
controls.get(INPUT_CODE_SPRINT).setOnPress(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
SprintTree sprintTree = CreatureUtils.getSprintTree(Globals.playerEntity);
|
|
if(sprintTree != null){
|
|
sprintTree.start();
|
|
}
|
|
}
|
|
}});
|
|
controls.get(INPUT_CODE_SPRINT).setOnRelease(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
SprintTree sprintTree = CreatureUtils.getSprintTree(Globals.playerEntity);
|
|
if(sprintTree != null){
|
|
sprintTree.stop();
|
|
}
|
|
}
|
|
}});
|
|
|
|
mainGameControlList.add(controls.get(INPUT_CODE_IRON_SIGHT));
|
|
controls.get(INPUT_CODE_IRON_SIGHT).setOnPress(new ControlMethod() {public void execute() {
|
|
if(Globals.playerEntity != null){
|
|
IronSightTree ironSightTree = IronSightTree.getIronSightTree(Globals.playerEntity);
|
|
if(ironSightTree != null){
|
|
ironSightTree.start();
|
|
}
|
|
}
|
|
}});
|
|
controls.get(INPUT_CODE_IRON_SIGHT).setOnRelease(new ControlMethod() {public void execute() {
|
|
if(Globals.playerEntity != null){
|
|
IronSightTree ironSightTree = IronSightTree.getIronSightTree(Globals.playerEntity);
|
|
if(ironSightTree != null){
|
|
ironSightTree.release();
|
|
}
|
|
}
|
|
}});
|
|
|
|
/*
|
|
Interact
|
|
*/
|
|
mainGameControlList.add(controls.get(INPUT_CODE_INTERACT));
|
|
controls.get(INPUT_CODE_INTERACT).setOnPress(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
if(EquipState.hasEquipState(Globals.playerEntity) && Crosshair.hasTarget()){
|
|
if(InventoryUtils.hasNaturalInventory(Globals.playerEntity)){
|
|
InventoryUtils.attemptStoreItem(Globals.playerEntity, Crosshair.getTarget());
|
|
}
|
|
}
|
|
}
|
|
}});
|
|
|
|
/*
|
|
Drop
|
|
*/
|
|
mainGameControlList.add(controls.get(INPUT_CODE_DROP));
|
|
controls.get(INPUT_CODE_DROP).setOnPress(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
if(EquipState.hasEquipState(Globals.playerEntity)){
|
|
UnrelationalInventoryState inventory = InventoryUtils.getNaturalInventory(Globals.playerEntity);
|
|
if(inventory.getItems().size() > 0){
|
|
Entity itemToDrop = inventory.getItems().get(0);
|
|
InventoryUtils.attemptEjectItem(Globals.playerEntity,itemToDrop);
|
|
}
|
|
}
|
|
}
|
|
}});
|
|
|
|
/*
|
|
Attack
|
|
*/
|
|
mainGameControlList.add(controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY));
|
|
controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).setOnPress(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
// Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
|
AttackTree attackTree = CreatureUtils.getAttackTree(Globals.playerEntity);
|
|
if(attackTree != null){
|
|
// CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize());
|
|
attackTree.start();
|
|
}
|
|
}
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).setOnRelease(new ControlMethod(){public void execute(){
|
|
if(Globals.playerEntity != null){
|
|
// Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
|
AttackTree attackTree = CreatureUtils.getAttackTree(Globals.playerEntity);
|
|
if(attackTree != null){
|
|
// CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize());
|
|
attackTree.release();
|
|
}
|
|
}
|
|
}});
|
|
|
|
|
|
/*
|
|
Lock on crosshair
|
|
*/
|
|
mainGameControlList.add(controls.get(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR));
|
|
controls.get(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR).setOnPress(new ControlMethod(){public void execute(){
|
|
if(Crosshair.hasTarget()){
|
|
Crosshair.setCrosshairActive(true);
|
|
}
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR).setOnRelease(new ControlMethod(){public void execute(){
|
|
if(Crosshair.getCrosshairActive()){
|
|
Crosshair.setCrosshairActive(false);
|
|
}
|
|
}});
|
|
|
|
|
|
/*
|
|
Main menu dialog toggle
|
|
*/
|
|
mainGameControlList.add(controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU));
|
|
controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).setOnClick(new ControlMethod(){public void execute(){
|
|
// Globals.elementManager.registerWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, MenuGenerators.createInGameMainMenu());
|
|
// Globals.controlHandler.setHandlerState(ControlsState.IN_GAME_MAIN_MENU);
|
|
|
|
// Window mainMenuWindow = new Window(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
|
|
Window mainMenuInGame = MenuGenerators.createInGameMainMenu();
|
|
// mainMenuWindow.addChild(mainMenuInGame);
|
|
Globals.elementManager.registerWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, mainMenuInGame);
|
|
WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN), true);
|
|
Globals.elementManager.focusFirstElement();
|
|
Globals.controlHandler.setHandlerState(ControlsState.IN_GAME_MAIN_MENU);
|
|
Globals.controlHandler.showMouse();
|
|
//play sound effect
|
|
AudioUtils.playAudio("/Audio/openMenu.ogg");
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).setRepeatTimeout(0.5f * Main.targetFrameRate);
|
|
|
|
/*
|
|
Open inventory
|
|
*/
|
|
mainGameControlList.add(controls.get(INPUT_CODE_INVENTORY_OPEN));
|
|
inventoryControlList.add(controls.get(INPUT_CODE_INVENTORY_OPEN));
|
|
controls.get(INPUT_CODE_INVENTORY_OPEN).setOnClick(new ControlMethod(){public void execute(){
|
|
if(InventoryUtils.hasNaturalInventory(Globals.playerEntity) && Globals.elementManager.getWindow(WindowUtils.getInventoryWindowID(InventoryUtils.getNaturalInventory(Globals.playerEntity).getId())) == null){
|
|
//create window
|
|
UnrelationalInventoryState inventory = InventoryUtils.getNaturalInventory(Globals.playerEntity);
|
|
Window mainMenuWindow = MenuGeneratorsInventory.createNaturalInventoryMenu(inventory);
|
|
//register
|
|
Globals.elementManager.registerWindow(WindowUtils.getInventoryWindowID(inventory.getId()), mainMenuWindow);
|
|
//make visible
|
|
WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowUtils.getInventoryWindowID(inventory.getId())), true);
|
|
//controls
|
|
Globals.controlHandler.setHandlerState(ControlsState.INVENTORY);
|
|
Globals.controlHandler.showMouse();
|
|
//play sound effect
|
|
AudioUtils.playAudio("/Audio/openMenu.ogg");
|
|
//
|
|
Globals.openInventoriesCount++;
|
|
}
|
|
}});
|
|
controls.get(INPUT_CODE_INVENTORY_OPEN).setRepeatTimeout(0.5f * Main.targetFrameRate);
|
|
|
|
/*
|
|
Open character
|
|
*/
|
|
mainGameControlList.add(controls.get(INPUT_CODE_CHARACTER_OPEN));
|
|
inventoryControlList.add(controls.get(INPUT_CODE_CHARACTER_OPEN));
|
|
controls.get(INPUT_CODE_CHARACTER_OPEN).setOnClick(new ControlMethod(){public void execute(){
|
|
if(InventoryUtils.hasEquipInventory(Globals.playerEntity) && Globals.elementManager.getWindow(WindowStrings.WINDOW_CHARACTER) == null){
|
|
//create window
|
|
Window mainMenuWindow = MenuGeneratorsInventory.createCharacterInventoryMenu(InventoryUtils.getEquipInventory(Globals.playerEntity));
|
|
//register
|
|
Globals.elementManager.registerWindow(WindowStrings.WINDOW_CHARACTER, mainMenuWindow);
|
|
//make visible
|
|
WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_CHARACTER), true);
|
|
//controls
|
|
Globals.controlHandler.setHandlerState(ControlsState.INVENTORY);
|
|
Globals.controlHandler.showMouse();
|
|
//play sound effect
|
|
AudioUtils.playAudio("/Audio/openMenu.ogg");
|
|
//
|
|
Globals.openInventoriesCount++;
|
|
}
|
|
}});
|
|
controls.get(INPUT_CODE_CHARACTER_OPEN).setRepeatTimeout(0.5f * Main.targetFrameRate);
|
|
|
|
}
|
|
|
|
void setInGameDebugControls(){
|
|
mainGameDebugControlList.add(controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM));
|
|
controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).setOnPress(new ControlMethod(){public void execute(){
|
|
// RenderingEngine.incrementOutputFramebuffer();
|
|
// Entity bow = ItemUtils.spawnBasicItem("shorts1");
|
|
// EntityUtils.getPosition(bow).set(1, 5, 2);
|
|
// CollisionObjUtils.positionCharacter(bow, new Vector3f(1, 5, 2));
|
|
}});
|
|
|
|
mainGameDebugControlList.add(controls.get(DEBUG_FRAMESTEP));
|
|
controls.get(DEBUG_FRAMESTEP).setOnRelease(new ControlMethod(){public void execute(){
|
|
Main.setFramestep(1);
|
|
}});
|
|
// RenderingEngine.incrementOutputFramebuffer();
|
|
}
|
|
|
|
void setMenuNavigationControls(){
|
|
menuNavigationControlList.add(controls.get(DATA_STRING_INPUT_CODE_MENU_NAVIGATE_FORWARD));
|
|
controls.get(DATA_STRING_INPUT_CODE_MENU_NAVIGATE_FORWARD).setOnPress(new ControlMethod(){public void execute(){
|
|
// Globals.currentMenu.incrementMenuOption();
|
|
Globals.elementManager.focusNextElement();
|
|
}});
|
|
|
|
menuNavigationControlList.add(controls.get(DATA_STRING_INPUT_CODE_MENU_NAVIGATE_BACKWARDS));
|
|
controls.get(DATA_STRING_INPUT_CODE_MENU_NAVIGATE_BACKWARDS).setOnPress(new ControlMethod(){public void execute(){
|
|
// Globals.currentMenu.decrementMenuOption();
|
|
Globals.elementManager.focusPreviousElement();
|
|
}});
|
|
|
|
|
|
|
|
//Incrementing a menu element
|
|
menuNavigationControlList.add(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT));
|
|
controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).setOnPress(new ControlMethod(){public void execute(){
|
|
Globals.elementManager.fireEvent(
|
|
new MenuEvent(MenuEventType.INCREMENT),
|
|
Globals.elementManager.getFocusedElement().getPositionX(),
|
|
Globals.elementManager.getFocusedElement().getPositionY()
|
|
);
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).setOnRepeat(new ControlMethod(){public void execute(){
|
|
Globals.elementManager.fireEvent(
|
|
new MenuEvent(MenuEventType.INCREMENT),
|
|
Globals.elementManager.getFocusedElement().getPositionX(),
|
|
Globals.elementManager.getFocusedElement().getPositionY()
|
|
);
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).setRepeatTimeout(0.5f * Main.targetFrameRate);
|
|
|
|
|
|
|
|
|
|
//Decrementing a menu element
|
|
menuNavigationControlList.add(controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT));
|
|
controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).setOnPress(new ControlMethod(){public void execute(){
|
|
Globals.elementManager.fireEvent(
|
|
new MenuEvent(MenuEventType.DECREMENT),
|
|
Globals.elementManager.getFocusedElement().getPositionX(),
|
|
Globals.elementManager.getFocusedElement().getPositionY()
|
|
);
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).setOnRepeat(new ControlMethod(){public void execute(){
|
|
Globals.elementManager.fireEvent(
|
|
new MenuEvent(MenuEventType.DECREMENT),
|
|
Globals.elementManager.getFocusedElement().getPositionX(),
|
|
Globals.elementManager.getFocusedElement().getPositionY()
|
|
);
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).setRepeatTimeout(0.5f * Main.targetFrameRate);
|
|
|
|
|
|
|
|
|
|
menuNavigationControlList.add(controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT));
|
|
controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT).setOnPress(new ControlMethod(){public void execute(){
|
|
Globals.elementManager.click(new ClickEvent(
|
|
Globals.elementManager.getFocusedElement().getPositionX(),
|
|
Globals.elementManager.getFocusedElement().getPositionY(),
|
|
true,
|
|
Globals.mouseCallback.getButton(GLFW_MOUSE_BUTTON_2)
|
|
));
|
|
// MenuCallbacks.selectOption(Globals.currentMenu);
|
|
}});
|
|
|
|
menuNavigationControlList.add(controls.get(INPUT_CODE_MENU_MOUSE_PRIMARY));
|
|
mainGameDebugControlList.add(controls.get(INPUT_CODE_MENU_MOUSE_PRIMARY));
|
|
controls.get(INPUT_CODE_MENU_MOUSE_PRIMARY).setOnClick(new ControlMethod(){public void execute(){
|
|
Globals.elementManager.click(new ClickEvent(
|
|
(int)xpos,
|
|
(int)ypos,
|
|
true,
|
|
Globals.mouseCallback.getButton(GLFW_MOUSE_BUTTON_2)
|
|
));
|
|
}});
|
|
controls.get(INPUT_CODE_MENU_MOUSE_PRIMARY).setRepeatTimeout(0.5f * Main.targetFrameRate);
|
|
|
|
menuNavigationControlList.add(controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT));
|
|
// controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).setOnPress(new ControlMethod(){public void execute(){
|
|
// // MenuCallbacks.backout(Globals.currentMenu);
|
|
// Globals.elementManager.unregisterWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN);
|
|
// }});
|
|
controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).setOnClick(new ControlMethod(){public void execute(){
|
|
// MenuCallbacks.backout(Globals.currentMenu);
|
|
Globals.elementManager.navigateBackwards();
|
|
// Globals.elementManager.unregisterWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN);
|
|
}});
|
|
controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).setRepeatTimeout(0.5f * Main.targetFrameRate);
|
|
|
|
}
|
|
|
|
void setTypingControls(){
|
|
|
|
String[] typeKeybinds = {
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_0,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_1,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_2,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_3,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_4,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_5,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_6,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_7,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_8,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_9,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_A,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_B,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_C,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_D,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_E,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_F,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_G,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_H,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_I,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_J,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_K,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_L,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_M,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_N,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_O,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_P,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_Q,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_R,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_S,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_T,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_U,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_V,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_W,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_X,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_Y,
|
|
DATA_STRING_INPUT_CODE_MENU_TYPE_Z,
|
|
INPUT_CODE_MENU_TYPE_FORWARD_SLASH,
|
|
};
|
|
for(String currentKey : typeKeybinds){
|
|
typingControlList.add(controls.get(currentKey));
|
|
controls.get(currentKey).setOnPress(new ControlMethod(){public void execute(){
|
|
Globals.elementManager.fireEvent(
|
|
new KeyboardEvent(convertKeycodeToName(controls.get(currentKey).keyValue)),
|
|
Globals.elementManager.getFocusedElement().getPositionX(),
|
|
Globals.elementManager.getFocusedElement().getPositionY()
|
|
);
|
|
// MenuCallbacks.menuHandleKeypress(Globals.currentMenu,currentKey);
|
|
}});
|
|
// if(controls.get(currentKey).isIsKey() && Globals.controlCallback.getKey(controls.get(currentKey).getKeyValue())){
|
|
// controls.get(currentKey).setState(true);
|
|
// } else {
|
|
// if(controls.get(currentKey).isState() == true){
|
|
// MenuTransition.menuHandleKeypress(Globals.currentMenu,currentKey);
|
|
// }
|
|
// controls.get(currentKey).setState(false);
|
|
// }
|
|
}
|
|
}
|
|
|
|
void setInventoryControls(){
|
|
/*
|
|
Close inventory
|
|
*/
|
|
// inventoryControlList.add(controls.get(INPUT_CODE_INVENTORY_CLOSE));
|
|
// controls.get(INPUT_CODE_INVENTORY_CLOSE).setOnPress(new ControlMethod(){public void execute(){
|
|
// // MenuCallbacks.backout(Globals.currentMenu);
|
|
// UnrelationalInventoryState inventory = InventoryUtils.getNaturalInventory(Globals.playerCharacter);
|
|
// Element inventoryWindow = Globals.elementManager.getWindow(WindowUtils.getInventoryWindowID(inventory.getId()));
|
|
// WindowUtils.recursiveSetVisible(inventoryWindow, false);
|
|
// hideMouse();
|
|
// Globals.elementManager.unregisterWindow(WindowUtils.getInventoryWindowID(inventory.getId()));
|
|
// Globals.controlHandler.setHandlerState(ControlsState.MAIN_GAME);
|
|
// }});
|
|
/*
|
|
Item manipulation
|
|
*/
|
|
inventoryControlList.add(controls.get(INPUT_CODE_INVENTORY_ITEM_MANIPULATE));
|
|
controls.get(INPUT_CODE_INVENTORY_ITEM_MANIPULATE).setOnPress(new ControlMethod(){public void execute(){
|
|
}});
|
|
controls.get(INPUT_CODE_INVENTORY_ITEM_MANIPULATE).setOnRelease(new ControlMethod(){public void execute(){
|
|
if(dragging){
|
|
dragging = false;
|
|
//fire dragrelease event to elementmanager
|
|
Globals.elementManager.dragRelease((int)xpos,(int)ypos,(int)mouse_lastX,(int)mouse_lastY,(int)(xpos - mouse_lastX),(int)(mouse_lastY - ypos));
|
|
} else {
|
|
//fire onclick event to elementmanager
|
|
Globals.elementManager.click(new ClickEvent((int)xpos,(int)ypos,true,Globals.mouseCallback.getButton(GLFW_MOUSE_BUTTON_2)));
|
|
}
|
|
}});
|
|
/*
|
|
item dragging
|
|
*/
|
|
inventoryControlList.add(controls.get(INPUT_CODE_INVENTORY_ITEM_DRAG));
|
|
controls.get(INPUT_CODE_INVENTORY_ITEM_DRAG).setOnMove(new Control.MouseCallback(){public void execute(MouseEvent event){
|
|
if(!dragging && event.getButton1()){
|
|
dragging = true;
|
|
//fire dragstart event to elementmanager
|
|
Globals.elementManager.dragStart((int)xpos,(int)ypos,(int)mouse_lastX,(int)mouse_lastY,(int)(xpos - mouse_lastX),(int)(mouse_lastY - ypos));
|
|
}
|
|
if(dragging){
|
|
//fire drag event to elementmanager
|
|
Globals.elementManager.drag((int)xpos,(int)ypos,(int)mouse_lastX,(int)mouse_lastY,(int)(xpos - mouse_lastX),(int)(mouse_lastY - ypos));
|
|
}
|
|
}});
|
|
}
|
|
|
|
|
|
public void runHandlers(List<Control> controls){
|
|
|
|
//construct mouse event
|
|
glfwGetCursorPos(Globals.window, mouse_X_Buffer, mouse_Y_Buffer);
|
|
xpos = mouse_X_Buffer[0];
|
|
ypos = mouse_Y_Buffer[0];
|
|
float xoffset = (float) (xpos - mouse_lastX);
|
|
float yoffset = (float) (mouse_lastY - ypos);
|
|
mouse_lastX = (float) xpos;
|
|
mouse_lastY = (float) ypos;
|
|
MouseEvent currentMouseEvent = new MouseEvent((int)xpos,(int)ypos,(int)mouse_lastX,(int)mouse_lastY,(int)xoffset,(int)yoffset,Globals.mouseCallback.getButton(GLFW_MOUSE_BUTTON_1),Globals.mouseCallback.getButton(GLFW_MOUSE_BUTTON_2));
|
|
boolean mouseMoveEvent = xoffset != 0 || yoffset != 0;
|
|
|
|
|
|
for(Control control : controls){
|
|
switch(control.getType()){
|
|
case KEY:
|
|
if(Globals.controlCallback.getKey(control.getKeyValue())){
|
|
if(!control.isState()){
|
|
//on press
|
|
control.onPress();
|
|
control.setPressFrame(Main.getCurrentFrame());
|
|
} else {
|
|
//on repeat
|
|
if(Main.getCurrentFrame() - control.getPressFrame() > control.getRepeatTimeout()){
|
|
control.onRepeat();
|
|
}
|
|
}
|
|
control.setState(true);
|
|
} else {
|
|
if(control.isState()){
|
|
//on release
|
|
control.onRelease();
|
|
//on click
|
|
if(Main.getCurrentFrame() - control.getPressFrame() < control.getRepeatTimeout()){
|
|
control.onClick();
|
|
}
|
|
} else {
|
|
}
|
|
control.setState(false);
|
|
}
|
|
break;
|
|
case MOUSE_BUTTON:
|
|
if(Globals.mouseCallback.getButton(control.getKeyValue())){
|
|
if(!control.isState()){
|
|
//on press
|
|
control.onPress();
|
|
control.setPressFrame(Main.getCurrentFrame());
|
|
} else {
|
|
//on repeat
|
|
control.onRepeat();
|
|
}
|
|
control.setState(true);
|
|
} else {
|
|
if(control.isState()){
|
|
//on release
|
|
control.onRelease();
|
|
if(Main.getCurrentFrame() - control.getPressFrame() < control.getRepeatTimeout()){
|
|
control.onClick();
|
|
}
|
|
} else {
|
|
}
|
|
control.setState(false);
|
|
}
|
|
break;
|
|
case MOUSE_MOVEMENT:
|
|
if(mouseMoveEvent){
|
|
control.onMove(currentMouseEvent);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public Control getControl(String controlName){
|
|
return controls.get(controlName);
|
|
}
|
|
|
|
public boolean containsControl(String controlName){
|
|
return controls.containsKey(controlName);
|
|
}
|
|
|
|
public void removeControl(String controlName){
|
|
controls.remove(controlName);
|
|
}
|
|
|
|
public void addControl(String controlName, Control c){
|
|
controls.put(controlName, c);
|
|
}
|
|
|
|
public void setHandlerState(ControlsState state){
|
|
this.state = state;
|
|
}
|
|
|
|
public ControlsState getState(){
|
|
return state;
|
|
}
|
|
|
|
public void hideMouse(){
|
|
glfwSetInputMode(Globals.window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
|
glfwSetInputMode(Globals.window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
|
mouseIsVisible = false;
|
|
}
|
|
|
|
public void showMouse(){
|
|
glfwSetInputMode(Globals.window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
|
mouseIsVisible = true;
|
|
}
|
|
|
|
public boolean isMouseVisible(){
|
|
return mouseIsVisible;
|
|
}
|
|
|
|
public Vector2f getMousePosition(){
|
|
double posX[] = new double[1];
|
|
double posY[] = new double[1];
|
|
glfwGetCursorPos(Globals.window, posX, posY);
|
|
Vector2f rVal = new Vector2f((float)posX[0],(float)posY[0]);
|
|
return rVal;
|
|
}
|
|
|
|
public static String convertKeycodeToName(int code){
|
|
String rVal = "";
|
|
switch(code){
|
|
case 46:
|
|
rVal = ".";
|
|
break;
|
|
case 47:
|
|
rVal = "/";
|
|
break;
|
|
case 48:
|
|
rVal = "0";
|
|
break;
|
|
case 49:
|
|
rVal = "1";
|
|
break;
|
|
case 50:
|
|
rVal = "2";
|
|
break;
|
|
case 51:
|
|
rVal = "3";
|
|
break;
|
|
case 52:
|
|
rVal = "4";
|
|
break;
|
|
case 53:
|
|
rVal = "5";
|
|
break;
|
|
case 54:
|
|
rVal = "6";
|
|
break;
|
|
case 55:
|
|
rVal = "7";
|
|
break;
|
|
case 56:
|
|
rVal = "8";
|
|
break;
|
|
case 57:
|
|
rVal = "9";
|
|
break;
|
|
case 65:
|
|
rVal = "A";
|
|
break;
|
|
case 66:
|
|
rVal = "B";
|
|
break;
|
|
case 67:
|
|
rVal = "C";
|
|
break;
|
|
case 68:
|
|
rVal = "D";
|
|
break;
|
|
case 69:
|
|
rVal = "E";
|
|
break;
|
|
case 70:
|
|
rVal = "F";
|
|
break;
|
|
case 71:
|
|
rVal = "G";
|
|
break;
|
|
case 72:
|
|
rVal = "H";
|
|
break;
|
|
case 73:
|
|
rVal = "I";
|
|
break;
|
|
case 74:
|
|
rVal = "J";
|
|
break;
|
|
case 75:
|
|
rVal = "K";
|
|
break;
|
|
case 76:
|
|
rVal = "L";
|
|
break;
|
|
case 77:
|
|
rVal = "M";
|
|
break;
|
|
case 78:
|
|
rVal = "N";
|
|
break;
|
|
case 79:
|
|
rVal = "O";
|
|
break;
|
|
case 80:
|
|
rVal = "P";
|
|
break;
|
|
case 81:
|
|
rVal = "Q";
|
|
break;
|
|
case 82:
|
|
rVal = "R";
|
|
break;
|
|
case 83:
|
|
rVal = "S";
|
|
break;
|
|
case 84:
|
|
rVal = "T";
|
|
break;
|
|
case 85:
|
|
rVal = "U";
|
|
break;
|
|
case 86:
|
|
rVal = "V";
|
|
break;
|
|
case 87:
|
|
rVal = "W";
|
|
break;
|
|
case 88:
|
|
rVal = "X";
|
|
break;
|
|
case 89:
|
|
rVal = "Y";
|
|
break;
|
|
case 90:
|
|
rVal = "Z";
|
|
break;
|
|
case 259:
|
|
rVal = "bs"; //backspace
|
|
break;
|
|
case 256:
|
|
rVal = "Escape";
|
|
break;
|
|
default:
|
|
LoggerInterface.loggerEngine.WARNING("Unable to convert keycode " + code + " in control handler.");
|
|
break;
|
|
}
|
|
return rVal;
|
|
}
|
|
|
|
public void setShouldRecapture(boolean shouldRecapture){
|
|
this.shouldRecaptureScreen = shouldRecapture;
|
|
}
|
|
|
|
public void recaptureIfNecessary(){
|
|
if(shouldRecaptureScreen){
|
|
//Makes the window that was just created the current OS-level window context
|
|
glfwMakeContextCurrent(Globals.window);
|
|
//Maximize it
|
|
glfwMaximizeWindow(Globals.window);
|
|
//grab focus
|
|
GLFW.glfwFocusWindow(Globals.window);
|
|
//apply mouse controls state
|
|
if(Globals.controlHandler.isMouseVisible()){
|
|
Globals.controlHandler.showMouse();
|
|
} else {
|
|
Globals.controlHandler.hideMouse();
|
|
}
|
|
shouldRecaptureScreen = false;
|
|
}
|
|
}
|
|
|
|
|
|
}
|