diff --git a/jme3-vehicle-creator/src/com/jme3/gde/vehiclecreator/VehicleCreatorCameraController.java b/jme3-vehicle-creator/src/com/jme3/gde/vehiclecreator/VehicleCreatorCameraController.java index 50fbbaab..5e8379dd 100644 --- a/jme3-vehicle-creator/src/com/jme3/gde/vehiclecreator/VehicleCreatorCameraController.java +++ b/jme3-vehicle-creator/src/com/jme3/gde/vehiclecreator/VehicleCreatorCameraController.java @@ -33,6 +33,7 @@ import com.jme3.gde.core.scene.controller.AbstractCameraController; import com.jme3.input.InputManager; +import com.jme3.input.event.KeyInputEvent; import com.jme3.renderer.Camera; import com.jme3.scene.Spatial; @@ -43,6 +44,7 @@ public class VehicleCreatorCameraController extends AbstractCameraController { private Spatial vehicle; + private VehicleEditorController editorController; public VehicleCreatorCameraController(Camera cam, InputManager inputManager) { super(cam, inputManager); @@ -67,6 +69,21 @@ public void setVehicle(Spatial vehicle) { this.vehicle = vehicle; } + /** + * @param editorController the VehicleEditorController to forward key events to + */ + public void setEditorController(VehicleEditorController editorController) { + this.editorController = editorController; + } + + @Override + public void onKeyEvent(KeyInputEvent kie) { + super.onKeyEvent(kie); + if (editorController != null) { + editorController.onKeyEvent(kie); + } + } + @Override public boolean useCameraControls() { return true; diff --git a/jme3-vehicle-creator/src/com/jme3/gde/vehiclecreator/VehicleCreatorTopComponent.java b/jme3-vehicle-creator/src/com/jme3/gde/vehiclecreator/VehicleCreatorTopComponent.java index aafb7770..cd0857cd 100644 --- a/jme3-vehicle-creator/src/com/jme3/gde/vehiclecreator/VehicleCreatorTopComponent.java +++ b/jme3-vehicle-creator/src/com/jme3/gde/vehiclecreator/VehicleCreatorTopComponent.java @@ -909,6 +909,7 @@ public void sceneOpened(final SceneRequest request) { editorController = newEditorController; cameraController = new VehicleCreatorCameraController(SceneApplication.getApplication().getCamera(), SceneApplication.getApplication().getInputManager()); cameraController.setMaster(this); + cameraController.setEditorController(editorController); cameraController.enable(); cameraController.setVehicle(request.getRootNode()); setLoadedScene(currentRequest.getDataObject().getNodeDelegate(), true); diff --git a/jme3-vehicle-creator/src/com/jme3/gde/vehiclecreator/VehicleEditorController.java b/jme3-vehicle-creator/src/com/jme3/gde/vehiclecreator/VehicleEditorController.java index 9ffd03d7..7c92314d 100644 --- a/jme3-vehicle-creator/src/com/jme3/gde/vehiclecreator/VehicleEditorController.java +++ b/jme3-vehicle-creator/src/com/jme3/gde/vehiclecreator/VehicleEditorController.java @@ -22,6 +22,7 @@ import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.KeyTrigger; +import com.jme3.input.event.KeyInputEvent; import com.jme3.light.DirectionalLight; import com.jme3.math.Matrix3f; import com.jme3.math.Vector3f; @@ -522,6 +523,39 @@ public void onAction(String binding, boolean value, float f) { } } + /** + * Handles key input events forwarded from the camera controller. + * Converts key codes to action bindings and calls onAction. + * + * @param kie the key input event + */ + public void onKeyEvent(KeyInputEvent kie) { + String binding; + switch (kie.getKeyCode()) { + case KeyInput.KEY_A: + binding = "VehicleEditor_Left"; + break; + case KeyInput.KEY_D: + binding = "VehicleEditor_Right"; + break; + case KeyInput.KEY_W: + binding = "VehicleEditor_Up"; + break; + case KeyInput.KEY_S: + binding = "VehicleEditor_Down"; + break; + case KeyInput.KEY_SPACE: + binding = "VehicleEditor_Space"; + break; + case KeyInput.KEY_RETURN: + binding = "VehicleEditor_Reset"; + break; + default: + return; + } + onAction(binding, kie.isPressed(), 0); + } + /** * @return the motorForce */