Controls refactor
This commit is contained in:
parent
dc0b6efa43
commit
ac8a3a665a
@ -47,6 +47,24 @@ public class Control {
|
||||
public void setOnRepeat(ControlMethod method){
|
||||
onRepeat = method;
|
||||
}
|
||||
|
||||
public void onPress(){
|
||||
if(onPress != null){
|
||||
onPress.execute();
|
||||
}
|
||||
}
|
||||
|
||||
public void onRelease(){
|
||||
if(onRelease != null){
|
||||
onRelease.execute();
|
||||
}
|
||||
}
|
||||
|
||||
public void onRepeat(){
|
||||
if(onRepeat != null){
|
||||
onRepeat.execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface ControlMethod {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package electrosphere.controls;
|
||||
|
||||
import electrosphere.controls.Control.ControlMethod;
|
||||
import electrosphere.entity.CameraEntityUtils;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
@ -18,6 +19,9 @@ import electrosphere.main.Globals;
|
||||
import electrosphere.menu.MenuTransition;
|
||||
import electrosphere.menu.MenuUtils;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3f;
|
||||
@ -108,6 +112,11 @@ public class ControlHandler {
|
||||
boolean mouseIsVisible = true;
|
||||
|
||||
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>();
|
||||
|
||||
ControlHandler(){
|
||||
controls = new HashMap<String, Control>();
|
||||
@ -207,6 +216,8 @@ public class ControlHandler {
|
||||
*/
|
||||
return handler;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -215,428 +226,456 @@ public class ControlHandler {
|
||||
|
||||
|
||||
case MAIN_GAME:
|
||||
pollMainGameControls();
|
||||
pollInGameDebugControls();
|
||||
break;
|
||||
runHandlers(mainGameControlList);
|
||||
runHandlers(mainGameDebugControlList);
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case TITLE_PAGE:
|
||||
break;
|
||||
break;
|
||||
|
||||
|
||||
case TITLE_MENU:
|
||||
pollMenuNavigationControls();
|
||||
/*
|
||||
Typing..
|
||||
*/
|
||||
pollTypingControls();
|
||||
break;
|
||||
runHandlers(menuNavigationControlList);
|
||||
/*
|
||||
Typing..
|
||||
*/
|
||||
runHandlers(typingControlList);
|
||||
break;
|
||||
|
||||
case IN_GAME_MAIN_MENU:
|
||||
pollMenuNavigationControls();
|
||||
break;
|
||||
runHandlers(menuNavigationControlList);
|
||||
// pollMenuNavigationControls();
|
||||
break;
|
||||
|
||||
case NO_INPUT:
|
||||
break;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setCallbacks(){
|
||||
setMainGameControls();
|
||||
setInGameDebugControls();
|
||||
setMenuNavigationControls();
|
||||
setTypingControls();
|
||||
}
|
||||
|
||||
public void pollMainGameControls(){
|
||||
if(Globals.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
SprintTree sprintTree = CreatureUtils.getSprintTree(Globals.playerCharacter);
|
||||
AttackTree attackTree = CreatureUtils.getAttackTree(Globals.playerCharacter);
|
||||
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||
/*
|
||||
Move forward
|
||||
*/
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())){
|
||||
Vector3d newFacingVector = new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize();
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, newFacingVector);
|
||||
// System.out.println("Movement vector: " + newFacingVector);
|
||||
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN || movementTree.getFacing() != MovementRelativeFacing.FORWARD){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).getKeyValue())){
|
||||
movementTree.start(MovementRelativeFacing.FORWARD_LEFT);
|
||||
} else if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).getKeyValue())){
|
||||
movementTree.start(MovementRelativeFacing.FORWARD_RIGHT);
|
||||
// System.out.println("f-r");
|
||||
} else {
|
||||
// System.out.println(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isIsKey() + "&&" + Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).getKeyValue()));
|
||||
movementTree.start(MovementRelativeFacing.FORWARD);
|
||||
}
|
||||
void setMainGameControls(){
|
||||
/*
|
||||
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.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||
Vector3d newFacingVector = new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize();
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, newFacingVector);
|
||||
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN || movementTree.getFacing() != MovementRelativeFacing.FORWARD){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).getKeyValue())){
|
||||
movementTree.start(MovementRelativeFacing.FORWARD_LEFT);
|
||||
} else if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).getKeyValue())){
|
||||
movementTree.start(MovementRelativeFacing.FORWARD_RIGHT);
|
||||
} else {
|
||||
movementTree.start(MovementRelativeFacing.FORWARD);
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).setState(true);
|
||||
//send to server
|
||||
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||
// Globals.playerCharacter.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// position.x,
|
||||
// position.y,
|
||||
// position.z
|
||||
// );
|
||||
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isState() == true){
|
||||
movementTree.slowdown();
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).setState(false);
|
||||
}
|
||||
}
|
||||
/*
|
||||
Move backward
|
||||
*/
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue())){
|
||||
}});
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).setOnRepeat(new ControlMethod(){public void execute(){
|
||||
if(Globals.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||
Vector3d newFacingVector = new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize();
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, newFacingVector);
|
||||
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN || movementTree.getFacing() != MovementRelativeFacing.FORWARD){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).getKeyValue())){
|
||||
movementTree.start(MovementRelativeFacing.FORWARD_LEFT);
|
||||
} else if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).getKeyValue())){
|
||||
movementTree.start(MovementRelativeFacing.FORWARD_RIGHT);
|
||||
} else {
|
||||
movementTree.start(MovementRelativeFacing.FORWARD);
|
||||
}
|
||||
}
|
||||
}
|
||||
}});
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).setOnRelease(new ControlMethod(){public void execute(){
|
||||
if(Globals.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
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.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize());
|
||||
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN || movementTree.getFacing() != MovementRelativeFacing.BACKWARD){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).getKeyValue())){
|
||||
movementTree.start(MovementRelativeFacing.BACKWARD_LEFT);
|
||||
} else if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).getKeyValue())){
|
||||
movementTree.start(MovementRelativeFacing.BACKWARD_RIGHT);
|
||||
} else {
|
||||
movementTree.start(MovementRelativeFacing.BACKWARD);
|
||||
}
|
||||
}
|
||||
}
|
||||
}});
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).setOnRepeat(new ControlMethod(){public void execute(){
|
||||
if(Globals.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize());
|
||||
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN || movementTree.getFacing() != MovementRelativeFacing.BACKWARD){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).getKeyValue())){
|
||||
movementTree.start(MovementRelativeFacing.BACKWARD_LEFT);
|
||||
} else if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).getKeyValue())){
|
||||
movementTree.start(MovementRelativeFacing.BACKWARD_RIGHT);
|
||||
} else {
|
||||
movementTree.start(MovementRelativeFacing.BACKWARD);
|
||||
}
|
||||
}
|
||||
}
|
||||
}});
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).setOnRelease(new ControlMethod(){public void execute(){
|
||||
if(Globals.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
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.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI/2.0).normalize());
|
||||
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.FORWARD);
|
||||
}
|
||||
}
|
||||
}});
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).setOnRepeat(new ControlMethod(){public void execute(){
|
||||
if(Globals.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI/2.0).normalize());
|
||||
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.FORWARD);
|
||||
}
|
||||
}
|
||||
}});
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).setOnRelease(new ControlMethod(){public void execute(){
|
||||
if(Globals.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
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.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(-Math.PI/2.0).normalize());
|
||||
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.FORWARD);
|
||||
}
|
||||
}
|
||||
}});
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).setOnRepeat(new ControlMethod(){public void execute(){
|
||||
if(Globals.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(-Math.PI/2.0).normalize());
|
||||
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.FORWARD);
|
||||
}
|
||||
}
|
||||
}});
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).setOnRelease(new ControlMethod(){public void execute(){
|
||||
if(Globals.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
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.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, 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.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, 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.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
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.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, 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.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, 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.playerCharacter != null){
|
||||
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||
movementTree.slowdown();
|
||||
}
|
||||
}});
|
||||
/*
|
||||
Sprint
|
||||
*/
|
||||
mainGameControlList.add(controls.get(INPUT_CODE_SPRINT));
|
||||
controls.get(INPUT_CODE_SPRINT).setOnPress(new ControlMethod(){public void execute(){
|
||||
if(Globals.playerCharacter != null){
|
||||
SprintTree sprintTree = CreatureUtils.getSprintTree(Globals.playerCharacter);
|
||||
if(sprintTree != null){
|
||||
sprintTree.start();
|
||||
}
|
||||
}
|
||||
}});
|
||||
controls.get(INPUT_CODE_SPRINT).setOnRelease(new ControlMethod(){public void execute(){
|
||||
if(Globals.playerCharacter != null){
|
||||
SprintTree sprintTree = CreatureUtils.getSprintTree(Globals.playerCharacter);
|
||||
if(sprintTree != null){
|
||||
sprintTree.stop();
|
||||
}
|
||||
}
|
||||
}});
|
||||
|
||||
/*
|
||||
Interact
|
||||
*/
|
||||
mainGameControlList.add(controls.get(INPUT_CODE_INTERACT));
|
||||
controls.get(INPUT_CODE_INTERACT).setOnPress(new ControlMethod(){public void execute(){
|
||||
if(Globals.playerCharacter != null){
|
||||
if(Globals.playerCharacter.getDataKeys().contains(EntityDataStrings.EQUIP_STATE) && Crosshair.hasTarget()){
|
||||
EquipState equipState = (EquipState)Globals.playerCharacter.getData(EntityDataStrings.EQUIP_STATE);
|
||||
equipState.attemptEquip(Crosshair.getTarget());
|
||||
}
|
||||
}
|
||||
}});
|
||||
|
||||
/*
|
||||
Drop
|
||||
*/
|
||||
mainGameControlList.add(controls.get(INPUT_CODE_DROP));
|
||||
controls.get(INPUT_CODE_DROP).setOnPress(new ControlMethod(){public void execute(){
|
||||
if(Globals.playerCharacter != null){
|
||||
if(Globals.playerCharacter.getDataKeys().contains(EntityDataStrings.EQUIP_STATE)){
|
||||
EquipState equipState = (EquipState)Globals.playerCharacter.getData(EntityDataStrings.EQUIP_STATE);
|
||||
equipState.drop();
|
||||
}
|
||||
}
|
||||
}});
|
||||
|
||||
/*
|
||||
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.playerCharacter != null){
|
||||
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||
AttackTree attackTree = CreatureUtils.getAttackTree(Globals.playerCharacter);
|
||||
if(attackTree != null){
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize());
|
||||
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN || movementTree.getFacing() != MovementRelativeFacing.BACKWARD){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).getKeyValue())){
|
||||
movementTree.start(MovementRelativeFacing.BACKWARD_LEFT);
|
||||
} else if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).getKeyValue())){
|
||||
movementTree.start(MovementRelativeFacing.BACKWARD_RIGHT);
|
||||
} else {
|
||||
movementTree.start(MovementRelativeFacing.BACKWARD);
|
||||
}
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).setState(true);
|
||||
//send to server
|
||||
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||
// Globals.playerCharacter.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// position.x,
|
||||
// position.y,
|
||||
// position.z
|
||||
// );
|
||||
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isState() == true){
|
||||
movementTree.slowdown();
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).setState(false);
|
||||
attackTree.start(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND);
|
||||
}
|
||||
}
|
||||
/*
|
||||
Strafe left
|
||||
*/
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).getKeyValue())){
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI/2.0).normalize());
|
||||
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.FORWARD);
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).setState(true);
|
||||
//send to server
|
||||
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||
// Globals.playerCharacter.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// position.x,
|
||||
// position.y,
|
||||
// position.z
|
||||
// );
|
||||
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isState() == true){
|
||||
movementTree.slowdown();
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).setState(false);
|
||||
}
|
||||
}});
|
||||
|
||||
|
||||
/*
|
||||
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);
|
||||
}
|
||||
/*
|
||||
Strafe right
|
||||
*/
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).getKeyValue())){
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(-Math.PI/2.0).normalize());
|
||||
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.FORWARD);
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).setState(true);
|
||||
//send to server
|
||||
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||
// Globals.playerCharacter.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// position.x,
|
||||
// position.y,
|
||||
// position.z
|
||||
// );
|
||||
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isState() == true){
|
||||
movementTree.slowdown();
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).setState(false);
|
||||
}
|
||||
}});
|
||||
controls.get(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR).setOnRelease(new ControlMethod(){public void execute(){
|
||||
if(Crosshair.getCrosshairActive()){
|
||||
Crosshair.setCrosshairActive(false);
|
||||
}
|
||||
/*
|
||||
Move up
|
||||
*/
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP) && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP).getKeyValue())){
|
||||
// EntityUtils.getPosition(Globals.playerCharacter).add(new Vector3f(0,0.6f,0).mul(1f));
|
||||
}
|
||||
/*
|
||||
Move down
|
||||
*/
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FALL) && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FALL).getKeyValue())){
|
||||
// EntityUtils.getPosition(Globals.playerCharacter).add(new Vector3f(0,-0.6f,0).mul(1f));
|
||||
}
|
||||
/*
|
||||
Move left
|
||||
*/
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_STRAFE_LEFT)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).getKeyValue())){
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, 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).setState(true);
|
||||
//send to server
|
||||
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||
// Globals.playerCharacter.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// position.x,
|
||||
// position.y,
|
||||
// position.z
|
||||
// );
|
||||
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).isState() == true){
|
||||
movementTree.slowdown();
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).setState(false);
|
||||
}
|
||||
}
|
||||
/*
|
||||
Move right
|
||||
*/
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_STRAFE_RIGHT)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).getKeyValue())){
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, 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).setState(true);
|
||||
//send to server
|
||||
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||
// Globals.playerCharacter.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// position.x,
|
||||
// position.y,
|
||||
// position.z
|
||||
// );
|
||||
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).isState() == true){
|
||||
movementTree.slowdown();
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).setState(false);
|
||||
}
|
||||
}
|
||||
/*
|
||||
Sprint
|
||||
*/
|
||||
if(controls.containsKey(INPUT_CODE_SPRINT)){
|
||||
if(controls.get(INPUT_CODE_SPRINT).isIsKey() && Globals.controlCallback.getKey(controls.get(INPUT_CODE_SPRINT).getKeyValue())){
|
||||
if(controls.get(INPUT_CODE_SPRINT).isState() == false){
|
||||
if(sprintTree != null){
|
||||
sprintTree.start();
|
||||
}
|
||||
}
|
||||
controls.get(INPUT_CODE_SPRINT).setState(true);
|
||||
} else {
|
||||
if(controls.get(INPUT_CODE_SPRINT).isState() == true){
|
||||
if(sprintTree != null){
|
||||
sprintTree.stop();
|
||||
}
|
||||
}
|
||||
controls.get(INPUT_CODE_SPRINT).setState(false);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Interact
|
||||
*/
|
||||
if(controls.containsKey(INPUT_CODE_INTERACT)){
|
||||
if(controls.get(INPUT_CODE_INTERACT).isIsKey() && Globals.controlCallback.getKey(controls.get(INPUT_CODE_INTERACT).getKeyValue())){
|
||||
if(controls.get(INPUT_CODE_INTERACT).isState() == false){
|
||||
if(Globals.playerCharacter.getDataKeys().contains(EntityDataStrings.EQUIP_STATE) && Crosshair.hasTarget()){
|
||||
EquipState equipState = (EquipState)Globals.playerCharacter.getData(EntityDataStrings.EQUIP_STATE);
|
||||
equipState.attemptEquip(Crosshair.getTarget());
|
||||
}
|
||||
}
|
||||
controls.get(INPUT_CODE_INTERACT).setState(true);
|
||||
} else {
|
||||
if(controls.get(INPUT_CODE_INTERACT).isState() == true){
|
||||
}
|
||||
controls.get(INPUT_CODE_INTERACT).setState(false);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Drop
|
||||
*/
|
||||
if(controls.containsKey(INPUT_CODE_DROP)){
|
||||
if(controls.get(INPUT_CODE_DROP).isIsKey() && Globals.controlCallback.getKey(controls.get(INPUT_CODE_DROP).getKeyValue())){
|
||||
if(controls.get(INPUT_CODE_DROP).isState() == false){
|
||||
if(Globals.playerCharacter.getDataKeys().contains(EntityDataStrings.EQUIP_STATE)){
|
||||
EquipState equipState = (EquipState)Globals.playerCharacter.getData(EntityDataStrings.EQUIP_STATE);
|
||||
equipState.drop();
|
||||
}
|
||||
}
|
||||
controls.get(INPUT_CODE_DROP).setState(true);
|
||||
} else {
|
||||
if(controls.get(INPUT_CODE_DROP).isState() == true){
|
||||
}
|
||||
controls.get(INPUT_CODE_DROP).setState(false);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Attack
|
||||
*/
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).isIsMouse() && glfwGetMouseButton(Globals.window, controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).getKeyValue()) == GLFW_PRESS){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).isState() == false){
|
||||
if(attackTree != null){
|
||||
CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize());
|
||||
attackTree.start(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND);
|
||||
}
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).setState(true);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).isState() == true){
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).setState(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Lock on crosshair
|
||||
*/
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR).isIsMouse() && glfwGetMouseButton(Globals.window, controls.get(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR).getKeyValue()) == GLFW_PRESS){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR).isState() == false){
|
||||
if(Crosshair.hasTarget()){
|
||||
Crosshair.setCrosshairActive(true);
|
||||
}
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR).setState(true);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR).isState() == true){
|
||||
if(Crosshair.getCrosshairActive()){
|
||||
Crosshair.setCrosshairActive(false);
|
||||
}
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR).setState(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Main menu dialog toggle
|
||||
*/
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).getKeyValue())){
|
||||
controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).setState(true);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).isState() == true){
|
||||
//make menu dialog visible
|
||||
//change control scheme to in game main menu scheme
|
||||
// System.out.println("Press main menu");
|
||||
Globals.currentMenu = MenuUtils.createInGameMainMenu();
|
||||
MenuUtils.makeMenuDrawable(Globals.currentMenu);
|
||||
Globals.controlHandler.setHandlerState(ControlsState.IN_GAME_MAIN_MENU);
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).setState(false);
|
||||
}
|
||||
}
|
||||
//DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU
|
||||
}
|
||||
}});
|
||||
|
||||
|
||||
/*
|
||||
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).setOnPress(new ControlMethod(){public void execute(){
|
||||
Globals.currentMenu = MenuUtils.createInGameMainMenu();
|
||||
MenuUtils.makeMenuDrawable(Globals.currentMenu);
|
||||
Globals.controlHandler.setHandlerState(ControlsState.IN_GAME_MAIN_MENU);
|
||||
}});
|
||||
|
||||
}
|
||||
|
||||
public void pollInGameDebugControls(){
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).getKeyValue())){
|
||||
controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).setState(true);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).isState() == true){
|
||||
Entity bow = ItemUtils.spawnBasicItem("shorts1");
|
||||
EntityUtils.getPosition(bow).set(1, 5, 2);
|
||||
CollisionObjUtils.positionCharacter(bow, new Vector3f(1, 5, 2));
|
||||
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(){
|
||||
Entity bow = ItemUtils.spawnBasicItem("shorts1");
|
||||
EntityUtils.getPosition(bow).set(1, 5, 2);
|
||||
CollisionObjUtils.positionCharacter(bow, new Vector3f(1, 5, 2));
|
||||
}});
|
||||
}
|
||||
|
||||
void setMenuNavigationControls(){
|
||||
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.currentMenu.incrementMenuOption();
|
||||
}});
|
||||
|
||||
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.currentMenu.decrementMenuOption();
|
||||
}});
|
||||
|
||||
menuNavigationControlList.add(controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT));
|
||||
controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT).setOnPress(new ControlMethod(){public void execute(){
|
||||
MenuTransition.selectOption(Globals.currentMenu);
|
||||
}});
|
||||
|
||||
menuNavigationControlList.add(controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT));
|
||||
controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).setOnPress(new ControlMethod(){public void execute(){
|
||||
MenuTransition.backout(Globals.currentMenu);
|
||||
}});
|
||||
}
|
||||
|
||||
public void runHandlers(List<Control> controls){
|
||||
for(Control control : controls){
|
||||
if(control.isIsKey()){
|
||||
if(Globals.controlCallback.getKey(control.getKeyValue())){
|
||||
if(!control.isState()){
|
||||
//on press
|
||||
control.onPress();
|
||||
} else {
|
||||
//on repeat
|
||||
control.onRepeat();
|
||||
}
|
||||
control.setState(true);
|
||||
} else {
|
||||
if(control.isState()){
|
||||
//on release
|
||||
control.onRelease();
|
||||
} else {
|
||||
}
|
||||
control.setState(false);
|
||||
}
|
||||
} else if(control.isIsMouse()){
|
||||
if(Globals.controlCallback.getKey(control.getKeyValue())){
|
||||
if(!control.isState()){
|
||||
//on press
|
||||
control.onPress();
|
||||
} else {
|
||||
//on repeat
|
||||
control.onRepeat();
|
||||
}
|
||||
control.setState(true);
|
||||
} else {
|
||||
if(control.isState()){
|
||||
//on release
|
||||
control.onRelease();
|
||||
} else {
|
||||
}
|
||||
control.setState(false);
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).setState(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void pollMenuNavigationControls(){
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_MENU_INCREMENT)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).getKeyValue())){
|
||||
controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).setState(true);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isState() == true){
|
||||
Globals.currentMenu.incrementMenuOption();
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).setState(false);
|
||||
}
|
||||
}
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_MENU_DECREMENT)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).getKeyValue())){
|
||||
controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).setState(true);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).isState() == true){
|
||||
Globals.currentMenu.decrementMenuOption();
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).setState(false);
|
||||
}
|
||||
}
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_MENU_SELECT)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT).getKeyValue())){
|
||||
controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT).setState(true);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT).isState() == true){
|
||||
MenuTransition.selectOption(Globals.currentMenu);
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT).setState(false);
|
||||
}
|
||||
}
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_MENU_BACKOUT)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).getKeyValue())){
|
||||
controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).setState(true);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).isState() == true){
|
||||
MenuTransition.backout(Globals.currentMenu);
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).setState(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void pollTypingControls(){
|
||||
void setTypingControls(){
|
||||
|
||||
String[] typeKeybinds = {
|
||||
DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE,
|
||||
@ -651,16 +690,46 @@ public class ControlHandler {
|
||||
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,
|
||||
};
|
||||
for(String currentKey : typeKeybinds){
|
||||
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);
|
||||
}
|
||||
typingControlList.add(controls.get(currentKey));
|
||||
controls.get(currentKey).setOnPress(new ControlMethod(){public void execute(){
|
||||
MenuTransition.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);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -417,6 +417,7 @@ public class Main {
|
||||
public static void initControlHandler(){
|
||||
LoggerInterface.loggerStartup.INFO("Initialize control handler");
|
||||
Globals.controlHandler = ControlHandler.generateExampleControlsMap();
|
||||
Globals.controlHandler.setCallbacks();
|
||||
// Globals.controlHandler = FileLoadingUtils.loadModelObjectFromBakedJsonFile("/Config/keybinds.json",ControlHandler.class);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user