diff --git a/assets/Data/entity/objects/furniture.json b/assets/Data/entity/objects/furniture.json index c39e5e8c..8114af4f 100644 --- a/assets/Data/entity/objects/furniture.json +++ b/assets/Data/entity/objects/furniture.json @@ -61,17 +61,21 @@ "id" : "Workbench", "collidable": { "type" : "CUBE", - "dimension1" : 0.03, - "dimension2" : 0.03, - "dimension3" : 0.2, + "dimension1" : 1.0, + "dimension2" : 1.0, + "dimension3" : 2.0, "rotX": 0, "rotY": 0, "rotZ": 0, "rotW": 1, "offsetX" : 0.0, - "offsetY" : 0.05, + "offsetY" : 0.5, "offsetZ" : 0.0 }, + "interaction" : { + "onInteract" : "menu", + "windowTarget" : "crafting" + }, "spawnItem" : { "graphicsTemplate" : { "model": { diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 56233806..9980197f 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1036,6 +1036,12 @@ Define interaction distance explicitly Fix client side store-in-inventory transform failing to destroy world-side item Fix gravity trees failing to handle missing collidables Fix token NPE +Physics editing debug tab +ControlHandler refactor to break out callbacks into dedicated files +Add concept of interaction definition in common entity type +Fix bug with entity ray casting selecting player entity +Fix crafting menu yoga appliation logic +Workbench can open crafting menu diff --git a/src/main/java/electrosphere/client/sim/ClientSimulation.java b/src/main/java/electrosphere/client/sim/ClientSimulation.java index 88d1ee49..1eb8f290 100644 --- a/src/main/java/electrosphere/client/sim/ClientSimulation.java +++ b/src/main/java/electrosphere/client/sim/ClientSimulation.java @@ -113,7 +113,7 @@ public class ClientSimulation { // //wrap up functions - runClientFunctions(); + this.runClientFunctions(); Globals.profiler.endCpuSample(); } @@ -122,11 +122,11 @@ public class ClientSimulation { Globals.profiler.beginCpuSample("client functions"); ClientTerrainManager.generateTerrainChunkGeometry(); ClientFluidManager.generateFluidChunkGeometry(); - updateSkyboxPos(); + this.updateSkyboxPos(); Globals.clientSceneWrapper.destroyEntitiesOutsideSimRange(); InstanceUpdater.updateInstancedActorPriority(); Globals.cameraHandler.updateGlobalCamera(); - updateFirstPersonAttachments(); + this.updateFirstPersonAttachments(); //bones have potenitally moved, so need to update where attached entities actually are before drawing AttachUtils.clientUpdateAttachedEntityPositions(); // updateCellManager(); diff --git a/src/main/java/electrosphere/client/ui/components/CraftingPanel.java b/src/main/java/electrosphere/client/ui/components/CraftingPanel.java index f738458a..dc4388c8 100644 --- a/src/main/java/electrosphere/client/ui/components/CraftingPanel.java +++ b/src/main/java/electrosphere/client/ui/components/CraftingPanel.java @@ -74,7 +74,7 @@ public class CraftingPanel { //select the first recipe selectedRecipe = Globals.gameConfigCurrent.getRecipeMap().getTypes().iterator().next(); - setDetails(rVal, recipeDetailsSection, selectedRecipe); + CraftingPanel.setDetails(rVal, recipeDetailsSection, selectedRecipe); @@ -82,7 +82,7 @@ public class CraftingPanel { VirtualScrollable recipeScrollable = new VirtualScrollable(SCROLLABLE_WIDTH, SCROLLABLE_HEIGHT); Globals.gameConfigCurrent.getRecipeMap().getTypes().forEach((RecipeData recipe) -> { Button recipeButton = Button.createButton(recipe.getDisplayName(), () -> { - setDetails(rVal, recipeDetailsSection, selectedRecipe); + CraftingPanel.setDetails(rVal, recipeDetailsSection, recipe); }); recipeScrollable.addChild(recipeButton); }); @@ -145,7 +145,11 @@ public class CraftingPanel { }); //apply yoga - Globals.signalSystem.post(SignalType.YOGA_APPLY, Globals.elementService.getWindow(WindowStrings.WINDOW_CHARACTER)); + if(Globals.elementService.getWindow(WindowStrings.CRAFTING) != null){ + Globals.signalSystem.post(SignalType.YOGA_APPLY, Globals.elementService.getWindow(WindowStrings.CRAFTING)); + } else if(Globals.elementService.getWindow(WindowStrings.WINDOW_MENU_MAIN) != null){ + Globals.signalSystem.post(SignalType.YOGA_APPLY, Globals.elementService.getWindow(WindowStrings.WINDOW_MENU_MAIN)); + } }); } diff --git a/src/main/java/electrosphere/client/ui/menu/WindowStrings.java b/src/main/java/electrosphere/client/ui/menu/WindowStrings.java index b77f843c..39c61dfb 100644 --- a/src/main/java/electrosphere/client/ui/menu/WindowStrings.java +++ b/src/main/java/electrosphere/client/ui/menu/WindowStrings.java @@ -46,4 +46,9 @@ public class WindowStrings { */ public static final String TOOLTIP_WINDOW = "tooltipWindow"; + /** + * The crafting window + */ + public static final String CRAFTING = "crafting"; + } diff --git a/src/main/java/electrosphere/client/ui/menu/WindowUtils.java b/src/main/java/electrosphere/client/ui/menu/WindowUtils.java index 59aff70c..4caafdc1 100644 --- a/src/main/java/electrosphere/client/ui/menu/WindowUtils.java +++ b/src/main/java/electrosphere/client/ui/menu/WindowUtils.java @@ -1,9 +1,13 @@ package electrosphere.client.ui.menu; +import electrosphere.audio.VirtualAudioSourceManager.VirtualAudioSourceType; import electrosphere.client.ui.components.PlayerInventoryWindow; +import electrosphere.client.ui.menu.ingame.CraftingWindow; import electrosphere.client.ui.menu.ingame.MenuGeneratorsInventory; import electrosphere.client.ui.menu.mainmenu.MenuGeneratorsTitleMenu; +import electrosphere.controls.ControlHandler.ControlsState; import electrosphere.engine.Globals; +import electrosphere.engine.assetmanager.AssetDataStrings; import electrosphere.engine.signal.Signal.SignalType; import electrosphere.renderer.ui.elements.Label; import electrosphere.renderer.ui.elements.Window; @@ -231,6 +235,10 @@ public class WindowUtils { Globals.elementService.registerWindow(WindowStrings.TOOLTIP_WINDOW, tooltipWindow); } + /** + * Focuses a window + * @param window The window to focus + */ public static void focusWindow(String window){ Element windowEl = Globals.elementService.getWindow(window); if(windowEl != null){ @@ -247,5 +255,29 @@ public class WindowUtils { public static boolean isInventoryWindow(String windowId){ return windowId.contains("INVENTORY") || windowId.equals(WindowStrings.WINDOW_MENU_INVENTORY) || windowId.equals(WindowStrings.WINDOW_CHARACTER); } + + /** + * Opens an interaction menu + * @param windowName The name of the window + */ + public static void openInteractionMenu(String windowName){ + switch(windowName){ + case WindowStrings.CRAFTING: { + Window craftingWindow = CraftingWindow.createCraftingWindow(); + Globals.elementService.registerWindow(WindowStrings.CRAFTING, craftingWindow); + WindowUtils.recursiveSetVisible(Globals.elementService.getWindow(WindowStrings.CRAFTING), true); + Globals.elementService.focusFirstElement(); + Globals.controlHandler.hintUpdateControlState(ControlsState.IN_GAME_MAIN_MENU); + //play sound effect + if(Globals.virtualAudioSourceManager != null){ + Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.UI_TONE_CONFIRM_PRIMARY, VirtualAudioSourceType.UI, false); + } + Globals.renderingEngine.getPostProcessingPipeline().setApplyBlur(true); + } break; + default: { + throw new Error("Tried to open unsupported window name! " + windowName); + } + } + } } diff --git a/src/main/java/electrosphere/client/ui/menu/debug/entity/ImGuiEntityMacros.java b/src/main/java/electrosphere/client/ui/menu/debug/entity/ImGuiEntityMacros.java index f89b3e43..25e8e8da 100644 --- a/src/main/java/electrosphere/client/ui/menu/debug/entity/ImGuiEntityMacros.java +++ b/src/main/java/electrosphere/client/ui/menu/debug/entity/ImGuiEntityMacros.java @@ -190,7 +190,7 @@ public class ImGuiEntityMacros { ImGuiEntityMacros.drawFirstPersonView(); ImGuiEntityMacros.drawLinkedEntities(); ImGuiEntityMacros.drawServerViewDir(); - ImGuiEntityMacros.drawPhysicsDetails(); + ImGuiEntityPhysicsTab.drawPhysicsView(showPhysicsTab, detailViewEntity); ImGuiEntityDebugActions.drawDebugActions(showDebugActionsTab, detailViewEntity); ImGuiEntityMacros.drawDataView(); } diff --git a/src/main/java/electrosphere/client/ui/menu/debug/entity/ImGuiEntityPhysicsTab.java b/src/main/java/electrosphere/client/ui/menu/debug/entity/ImGuiEntityPhysicsTab.java new file mode 100644 index 00000000..37c49c1e --- /dev/null +++ b/src/main/java/electrosphere/client/ui/menu/debug/entity/ImGuiEntityPhysicsTab.java @@ -0,0 +1,181 @@ +package electrosphere.client.ui.menu.debug.entity; + +import org.ode4j.ode.DBody; +import org.ode4j.ode.DBox; +import org.ode4j.ode.DCylinder; +import org.ode4j.ode.DGeom; +import org.ode4j.ode.DMass; + +import electrosphere.collision.PhysicsEntityUtils; +import electrosphere.engine.Globals; +import electrosphere.entity.Entity; +import electrosphere.entity.EntityDataStrings; +import electrosphere.entity.EntityUtils; +import electrosphere.entity.types.creature.CreatureUtils; +import electrosphere.game.data.collidable.CollidableTemplate; +import electrosphere.server.datacell.utils.EntityLookupUtils; +import imgui.ImGui; + +/** + * Tab for both exploring and editing physics on this entity + */ +public class ImGuiEntityPhysicsTab { + + /** + * The minimum offset + */ + static final float MIN_OFFSET = -10; + + /** + * The maximum offset + */ + static final float MAX_OFFSET = 10; + + /** + * Minimum mass value + */ + static final float MIN_MASS = 0; + + /** + * Maximum mass value + */ + static final float MAX_MASS = 1.0f; + + /** + * Storage for the modified scale of the collidable + */ + static float[] scale = new float[3]; + + /** + * Storage for the modified offset of the collidable + */ + static float[] offset = new float[3]; + + /** + * Radius slider + */ + static float[] radius = new float[1]; + + /** + * Length slider + */ + static float[] length = new float[1]; + + /** + * Mass slider + */ + static float[] mass = new float[1]; + + /** + * Physics view + */ + protected static void drawPhysicsView(boolean show, Entity detailViewEntity){ + if(show && ImGui.collapsingHeader("Physics Details")){ + ImGui.indent(); + if(PhysicsEntityUtils.getDBody(detailViewEntity) != null){ + DBody physicsBody = PhysicsEntityUtils.getDBody(detailViewEntity); + if(physicsBody != null){ + ImGui.text("Position: " + EntityUtils.getPosition(detailViewEntity)); + ImGui.text("Rotation: " + EntityUtils.getRotation(detailViewEntity)); + ImGui.text("Velocity: " + physicsBody.getLinearVel()); + ImGui.text("Force: " + physicsBody.getForce()); + ImGui.text("Angular Velocity: " + physicsBody.getAngularVel()); + ImGui.text("Torque: " + physicsBody.getTorque()); + ImGui.text("Move Vector: " + CreatureUtils.getFacingVector(detailViewEntity)); + ImGui.text("Velocity: " + CreatureUtils.getVelocity(detailViewEntity)); + } + //synchronized data + if( + Globals.clientSceneWrapper.getScene().getEntityFromId(detailViewEntity.getId()) != null && + Globals.clientSceneWrapper.mapClientToServerId(detailViewEntity.getId()) != -1 + ){ + //detailViewEntity is a client entity + //get server entity + int serverIdForClientEntity = Globals.clientSceneWrapper.mapClientToServerId(detailViewEntity.getId()); + Entity serverEntity = EntityLookupUtils.getEntityById(serverIdForClientEntity); + DBody serverPhysicsBody = PhysicsEntityUtils.getDBody(serverEntity); + if(serverPhysicsBody != null){ + ImGui.newLine(); + ImGui.text("Linked server entity:"); + ImGui.text("Position (Server): " + EntityUtils.getPosition(serverEntity)); + ImGui.text("Rotation (Server): " + EntityUtils.getRotation(serverEntity)); + ImGui.text("Velocity (Server): " + serverPhysicsBody.getLinearVel()); + ImGui.text("Force (Server): " + serverPhysicsBody.getForce()); + ImGui.text("Angular Velocity: " + serverPhysicsBody.getAngularVel()); + ImGui.text("Torque: " + serverPhysicsBody.getTorque()); + ImGui.text("Move Vector (Server): "+ CreatureUtils.getFacingVector(serverEntity)); + ImGui.text("Velocity (Server): " + CreatureUtils.getVelocity(serverEntity)); + } + } else if(Globals.clientSceneWrapper.containsServerId(detailViewEntity.getId())){ + //detailViewEntity is a server entity + //get client entity + int clientId = Globals.clientSceneWrapper.mapServerToClientId(detailViewEntity.getId()); + Entity clientEntity = Globals.clientSceneWrapper.getScene().getEntityFromId(clientId); + DBody clientPhysicsBody = PhysicsEntityUtils.getDBody(clientEntity); + if(clientPhysicsBody != null){ + ImGui.newLine(); + ImGui.text("Linked client entity:"); + ImGui.text("Position (Client): " + EntityUtils.getPosition(clientEntity)); + ImGui.text("Rotation (Client): " + EntityUtils.getRotation(clientEntity)); + ImGui.text("Velocity (Client): " + clientPhysicsBody.getLinearVel()); + ImGui.text("Force (Client): " + clientPhysicsBody.getForce()); + ImGui.text("Angular Velocity: " + clientPhysicsBody.getAngularVel()); + ImGui.text("Torque: " + clientPhysicsBody.getTorque()); + ImGui.text("Move Vector (Client): " + CreatureUtils.getFacingVector(clientEntity)); + ImGui.text("Velocity (Client): " + CreatureUtils.getVelocity(clientEntity)); + } + } + //Collidable editing + if(physicsBody != null && physicsBody.getFirstGeom() != null && ImGui.collapsingHeader("Modify")){ + DGeom geom = physicsBody.getFirstGeom(); + CollidableTemplate template = (CollidableTemplate)detailViewEntity.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE); + if(geom instanceof DBox){ + DBox box = (DBox)geom; + if(ImGui.sliderFloat3("Offset", offset, MIN_OFFSET, MAX_OFFSET)){ + box.setOffsetPosition(offset[0], offset[1], offset[2]); + template.setOffsetX(offset[0]); + template.setOffsetY(offset[1]); + template.setOffsetZ(offset[2]); + } + if(ImGui.sliderFloat3("Scale",scale,MIN_OFFSET,MAX_OFFSET)){ + box.setLengths(scale[0], scale[1], scale[2]); + template.setDimension1(scale[0]); + template.setDimension2(scale[1]); + template.setDimension3(scale[2]); + } + if(physicsBody.getMass() instanceof DMass && ImGui.sliderFloat("Mass",mass,MIN_MASS,MAX_MASS)){ + DMass massObj = (DMass)physicsBody.getMass(); + float adjusted = (float)Math.log(mass[0] + 1); + massObj.setMass(adjusted); + } + } else if(geom instanceof DCylinder){ + DCylinder cylinder = (DCylinder)geom; + if(ImGui.sliderFloat3("Offset", offset, MIN_OFFSET, MAX_OFFSET)){ + cylinder.setOffsetPosition(offset[0], offset[1], offset[2]); + template.setOffsetX(offset[0]); + template.setOffsetY(offset[1]); + template.setOffsetZ(offset[2]); + } + if(ImGui.sliderFloat("Radius",radius,MIN_OFFSET,MAX_OFFSET)){ + cylinder.setParams(radius[0], cylinder.getLength()); + template.setDimension1(radius[0]); + } + if(ImGui.sliderFloat("Length",length,MIN_OFFSET,MAX_OFFSET)){ + cylinder.setParams(cylinder.getRadius(), length[0]); + template.setDimension2(length[0]); + } + if(physicsBody.getMass() instanceof DMass && ImGui.sliderFloat("Mass",mass,MIN_MASS,MAX_MASS)){ + DMass massObj = (DMass)physicsBody.getMass(); + float adjusted = (float)Math.log(mass[0] + 1); + massObj.setMass(adjusted); + } + } else { + throw new Error("Unsupported geom type! " + geom); + } + } + } + ImGui.unindent(); + } + } + +} diff --git a/src/main/java/electrosphere/client/ui/menu/ingame/CraftingWindow.java b/src/main/java/electrosphere/client/ui/menu/ingame/CraftingWindow.java new file mode 100644 index 00000000..157a48b8 --- /dev/null +++ b/src/main/java/electrosphere/client/ui/menu/ingame/CraftingWindow.java @@ -0,0 +1,77 @@ +package electrosphere.client.ui.menu.ingame; + +import electrosphere.audio.VirtualAudioSourceManager.VirtualAudioSourceType; +import electrosphere.client.ui.components.CraftingPanel; +import electrosphere.client.ui.menu.WindowStrings; +import electrosphere.client.ui.menu.WindowUtils; +import electrosphere.controls.ControlHandler.ControlsState; +import electrosphere.engine.Globals; +import electrosphere.engine.assetmanager.AssetDataStrings; +import electrosphere.engine.signal.Signal.SignalType; +import electrosphere.renderer.ui.elements.Window; +import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaAlignment; +import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaJustification; +import electrosphere.renderer.ui.elementtypes.NavigableElement.NavigationEventCallback; +import electrosphere.renderer.ui.events.NavigationEvent; + +/** + * Creates a crafting window + */ +public class CraftingWindow { + + /** + * Minimum width of the component + */ + public static final int MIN_WIDTH = 500; + + /** + * Minimum height of the component + */ + public static final int MIN_HEIGHT = 500; + + /** + * Creates a character customizer panel + * @return The panel component + */ + public static Window createCraftingWindow(){ + int width = MIN_WIDTH; + int height = MIN_HEIGHT; + + + Window rVal = Window.createExpandableCenterAligned(Globals.renderingEngine.getOpenGLState(), width, height); + rVal.setParentAlignItem(YogaAlignment.Center); + rVal.setParentJustifyContent(YogaJustification.Center); + + rVal.setOnNavigationCallback(new NavigationEventCallback() {public boolean execute(NavigationEvent event){ + WindowUtils.recursiveSetVisible(Globals.elementService.getWindow(WindowStrings.CRAFTING), false); + Globals.elementService.unregisterWindow(WindowStrings.CRAFTING); + if(Globals.cameraHandler.getTrackPlayerEntity()){ + Globals.controlHandler.hintUpdateControlState(ControlsState.MAIN_GAME); + } else { + Globals.controlHandler.hintUpdateControlState(ControlsState.IN_GAME_FREE_CAMERA); + } + if(Globals.virtualAudioSourceManager != null){ + Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.UI_SFX_INVENTORY_CLOSE, VirtualAudioSourceType.UI, false); + } + Globals.renderingEngine.getPostProcessingPipeline().setApplyBlur(false); + return false; + }}); + + + // + //contents + // + rVal.addChild(CraftingPanel.createCraftingPanelComponent()); + + // + //Final setup + // + + Globals.signalSystem.post(SignalType.YOGA_APPLY, rVal); + + + + return rVal; + } + +} diff --git a/src/main/java/electrosphere/collision/CollisionEngine.java b/src/main/java/electrosphere/collision/CollisionEngine.java index e1e05b0c..b58ace98 100644 --- a/src/main/java/electrosphere/collision/CollisionEngine.java +++ b/src/main/java/electrosphere/collision/CollisionEngine.java @@ -643,9 +643,10 @@ public class CollisionEngine { */ public Entity rayCast(Vector3d start, Vector3d direction, double length, List typeMask){ spaceLock.acquireUninterruptibly(); + Vector3d unitDir = new Vector3d(direction).normalize(); //create the ray DRay ray = OdeHelper.createRay(space, length); - ray.set(start.x, start.y, start.z, direction.x, direction.y, direction.z); + ray.set(start.x, start.y, start.z, unitDir.x, unitDir.y, unitDir.z); //collide RayCastCallbackData data = new RayCastCallbackData(bodyPointerMap, typeMask); rayCastCallback.setLength(length); @@ -690,9 +691,10 @@ public class CollisionEngine { */ public Vector3d rayCastPositionMasked(Vector3d start, Vector3d direction, double length, List typeMask){ spaceLock.acquireUninterruptibly(); + Vector3d unitDir = new Vector3d(direction).normalize(); //create the ray DRay ray = OdeHelper.createRay(space, length); - ray.set(start.x, start.y, start.z, direction.x, direction.y, direction.z); + ray.set(start.x, start.y, start.z, unitDir.x, unitDir.y, unitDir.z); //collide RayCastCallbackData data = new RayCastCallbackData(bodyPointerMap, typeMask); rayCastCallback.setLength(length); diff --git a/src/main/java/electrosphere/collision/RayCastCallback.java b/src/main/java/electrosphere/collision/RayCastCallback.java index 946df507..463227af 100644 --- a/src/main/java/electrosphere/collision/RayCastCallback.java +++ b/src/main/java/electrosphere/collision/RayCastCallback.java @@ -86,14 +86,17 @@ void RayCallback(void *Data, dGeomID Geometry1, dGeomID Geometry2) { Collidable collidable2 = rayCastData.bodyEntityMap.get(b2); if( ( - rayCastData.collidableTypeMask != null && + rayCastData.collidableTypeMask == null || ( - (o1 instanceof DRay && rayCastData.collidableTypeMask.contains(collidable2.getType())) || - (o2 instanceof DRay && rayCastData.collidableTypeMask.contains(collidable1.getType())) + rayCastData.collidableTypeMask != null && + ( + (o1 instanceof DRay && rayCastData.collidableTypeMask.contains(collidable2.getType())) || + (o2 instanceof DRay && rayCastData.collidableTypeMask.contains(collidable1.getType())) + ) ) - ) || - rayCastData.collidableTypeMask == null && - collidable2 != null && collidable2.getParent() != Globals.playerEntity //don't self cast -- should work on both server and client + ) && + collidable1 != null && collidable1.getParent() != Globals.playerEntity && //don't self cast -- should work on both server and client + collidable2 != null && collidable2.getParent() != Globals.playerEntity //don't self cast -- should work on both server and client ){ //calculate collisions int numc = OdeHelper.collide(o1,o2,MAX_CONTACTS,contacts.getGeomBuffer()); diff --git a/src/main/java/electrosphere/collision/collidable/Collidable.java b/src/main/java/electrosphere/collision/collidable/Collidable.java index ed7cb45f..05f131c5 100644 --- a/src/main/java/electrosphere/collision/collidable/Collidable.java +++ b/src/main/java/electrosphere/collision/collidable/Collidable.java @@ -2,6 +2,8 @@ package electrosphere.collision.collidable; import electrosphere.entity.Entity; import electrosphere.entity.state.collidable.Impulse; + +import java.util.Arrays; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -55,6 +57,20 @@ public class Collidable { public static final String TYPE_WORLD_BOUND = "worldBound"; public static final long TYPE_WORLD_BOUND_BIT = 0x100; + /** + * A ray casting mask to exclude terrain + */ + public static final List MASK_NO_TERRAIN = Arrays.asList(new String[]{ + TYPE_STATIC, + TYPE_CREATURE, + TYPE_STRUCTURE, + TYPE_ITEM, + TYPE_FORCE, + TYPE_OBJECT, + TYPE_FOLIAGE_STATIC, + TYPE_WORLD_BOUND, + }); + /** * Constructor diff --git a/src/main/java/electrosphere/controls/Control.java b/src/main/java/electrosphere/controls/Control.java index 43582005..cd029184 100644 --- a/src/main/java/electrosphere/controls/Control.java +++ b/src/main/java/electrosphere/controls/Control.java @@ -8,53 +8,106 @@ import electrosphere.renderer.ui.events.ScrollEvent; */ public class Control { + /** + * The different types of controls + */ public static enum ControlType { + /** + * A key control + */ KEY, + /** + * A mouse button control + */ MOUSE_BUTTON, + /** + * A mouse movement control + */ MOUSE_MOVEMENT, + /** + * A mouse scroll control + */ MOUSE_SCROLL, } + /** + * The type of this control + */ ControlType type; + + /** + * The activated state of the control + */ boolean state; + + /** + * The key value of the control if it is a key control + */ int keyValue; + + /** + * The name of the control + */ String name; + + /** + * The description of the control + */ String description; + + /** + * True if this control is rebindable, false otherwise + */ boolean rebindable; + + /** + * The method to fire on pressing the button/key + */ ControlMethod onPress; + + /** + * The method to fire on releasing the button/key + */ ControlMethod onRelease; + + /** + * The method to fire on repeating the button/key + */ ControlMethod onRepeat; + + /** + * The method to fire on clicking with the mouse + */ ControlMethod onClick; + + /** + * The method to fire on moving the mouse + */ MouseCallback onMove; + + /** + * The method to fire on scrollign with the mouse + */ ScrollCallback onScroll; + /** + * The frame the control was pressed on + */ float pressFrame = 0; + + /** + * The repeat timeout of the control + */ float repeatTimeout = 0; - public boolean isIsKey() { - return type == ControlType.KEY; - } - - public boolean isIsMouse() { - return type == ControlType.MOUSE_BUTTON; - } - - public boolean isState() { - return state; - } - - public ControlType getType(){ - return type; - } - - public int getKeyValue() { - return keyValue; - } - - public void setState(boolean state) { - this.state = state; - } - + /** + * Constructor + * @param type + * @param keyValue + * @param rebindable + * @param name + * @param description + */ public Control(ControlType type, int keyValue, boolean rebindable, String name, String description) { this.type = type; this.keyValue = keyValue; @@ -64,105 +117,252 @@ public class Control { this.description = description; } + /** + * Gets if this is a key control + * @return true if it is a key control, false otherwise + */ + public boolean isIsKey() { + return type == ControlType.KEY; + } + + /** + * Gets if this is a mouse control + * @return true if it is a mouse control, false otheriwse + */ + public boolean isIsMouse() { + return type == ControlType.MOUSE_BUTTON; + } + + /** + * Gets the state of the control + * @return true if it is active, false otherwise + */ + public boolean isState() { + return state; + } + + /** + * Gets the type of control + * @return The type + */ + public ControlType getType(){ + return type; + } + + /** + * Gets the key value of the control + * @return The key value + */ + public int getKeyValue() { + return keyValue; + } + + /** + * Sets the state of the control + * @param state The state + */ + public void setState(boolean state) { + this.state = state; + } + + /** + * Sets the on press callback of the control + * @param method The callback + */ public void setOnPress(ControlMethod method){ onPress = method; } + /** + * Sets the on release callback of the control + * @param method The callback + */ public void setOnRelease(ControlMethod method){ onRelease = method; } + /** + * Sets the on repeat callback of the control + * @param method The callback + */ public void setOnRepeat(ControlMethod method){ onRepeat = method; } + /** + * Sets the on mouse move callback of the control + * @param method The callback + */ public void setOnMove(MouseCallback method){ onMove = method; } + /** + * Sets the on mouse click of the control + * @param method The callback + */ public void setOnClick(ControlMethod method){ onClick = method; } + /** + * Sets the on mouse scroll callback of the control + * @param method The callback + */ public void setOnScroll(ScrollCallback callback){ onScroll = callback; } - public void onPress(){ + /** + * Sets the on press callback of the control + * @param method The callback + */ + public void onPress(MouseState mouseState){ if(onPress != null){ - onPress.execute(); + onPress.execute(mouseState); } } - public void onRelease(){ + /** + * Sets the on release callback of the control + * @param method The callback + */ + public void onRelease(MouseState mouseState){ if(onRelease != null){ - onRelease.execute(); + onRelease.execute(mouseState); } } - public void onRepeat(){ + /** + * Sets the on repeat callback of the control + * @param method The callback + */ + public void onRepeat(MouseState mouseState){ if(onRepeat != null){ - onRepeat.execute(); + onRepeat.execute(mouseState); } } - public void onMove(MouseEvent event){ + /** + * Sets the on mouse move callback of the control + * @param method The callback + */ + public void onMove(MouseState mouseState, MouseEvent event){ if(onMove != null){ - onMove.execute(event); + onMove.execute(mouseState, event); } } - public void onClick(){ + /** + * Sets the on mouse click callback of the control + * @param method The callback + */ + public void onClick(MouseState mouseState){ if(onClick != null){ - onClick.execute(); + onClick.execute(mouseState); } } - public void onScroll(ScrollEvent event){ + /** + * Sets the on mouse scroll callback of the control + * @param method The callback + */ + public void onScroll(MouseState mouseState, ScrollEvent event){ if(onScroll != null){ - onScroll.execute(event); + onScroll.execute(mouseState, event); } } + /** + * Gets the frame the control was pressed + * @return The frame + */ public float getPressFrame(){ return this.pressFrame; } + /** + * Sets the frame the control was pressed + * @param frame The frame + */ public void setPressFrame(float frame){ pressFrame = frame; } + /** + * Gets the repeat timeout of the control + * @return The repeat timeout + */ public float getRepeatTimeout(){ return this.repeatTimeout; } + /** + * Sets the repeat timeout of the control + * @param timeout The repeat timeout + */ public void setRepeatTimeout(float timeout){ repeatTimeout = timeout; } + /** + * Gets whether this control is rebindable + * @return true if it is rebindable, false otherwise + */ public boolean isRebindable(){ return rebindable; } + /** + * Gets the name of the control + * @return The name + */ public String getName(){ return name; } + /** + * Gets the description of the control + * @return The description + */ public String getDescription(){ return description; } + /** + * A callback to fire on a control event + */ public interface ControlMethod { - public void execute(); + /** + * Excecutes the callback + * @param mouseState The state of the mouse + */ + public void execute(MouseState mouseState); } + /** + * A callback to fire on a mouse event + */ public interface MouseCallback { - public void execute(MouseEvent event); + /** + * Executes the callback + * @param mouseState The state of the mouse + * @param event The mouse event + */ + public void execute(MouseState mouseState, MouseEvent event); } + /** + * A callback to fire on a mouse scroll event + */ public interface ScrollCallback { - public void execute(ScrollEvent event); + /** + * Executes the callback + * @param mouseState The state of the mouse + * @param event The mouse event + */ + public void execute(MouseState mouseState, ScrollEvent event); } } diff --git a/src/main/java/electrosphere/controls/ControlHandler.java b/src/main/java/electrosphere/controls/ControlHandler.java index c0435987..4418d4b9 100644 --- a/src/main/java/electrosphere/controls/ControlHandler.java +++ b/src/main/java/electrosphere/controls/ControlHandler.java @@ -3,66 +3,10 @@ package electrosphere.controls; import static org.lwjgl.glfw.GLFW.GLFW_CURSOR; import static org.lwjgl.glfw.GLFW.GLFW_CURSOR_DISABLED; import static org.lwjgl.glfw.GLFW.GLFW_CURSOR_NORMAL; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_0; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_1; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_2; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_3; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_4; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_5; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_6; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_7; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_8; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_9; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_A; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_B; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_BACKSPACE; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_C; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_CAPS_LOCK; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_D; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_DOWN; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_E; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_ENTER; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_F; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_F2; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_F24; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_F4; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_G; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_H; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_I; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_J; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_K; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_L; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_ALT; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_CONTROL; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_SHIFT; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_M; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_N; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_O; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_P; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_PERIOD; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_Q; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_R; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_RIGHT; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_S; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_SLASH; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_T; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_U; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_UP; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_V; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_W; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_X; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_Y; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_Z; import static org.lwjgl.glfw.GLFW.GLFW_MOUSE_BUTTON_1; import static org.lwjgl.glfw.GLFW.GLFW_MOUSE_BUTTON_2; -import static org.lwjgl.glfw.GLFW.GLFW_MOUSE_BUTTON_LEFT; -import static org.lwjgl.glfw.GLFW.GLFW_MOUSE_BUTTON_RIGHT; import static org.lwjgl.glfw.GLFW.glfwGetCursorPos; import static org.lwjgl.glfw.GLFW.glfwSetInputMode; -import org.lwjgl.glfw.GLFW; import java.util.Arrays; import java.util.HashMap; @@ -70,47 +14,20 @@ import java.util.LinkedList; import java.util.List; import org.joml.Vector2f; -import org.joml.Vector3d; -import org.joml.Vector3f; -import electrosphere.audio.VirtualAudioSourceManager.VirtualAudioSourceType; import electrosphere.client.entity.camera.CameraEntityUtils; -import electrosphere.client.entity.crosshair.Crosshair; -import electrosphere.client.item.ItemActions; -import electrosphere.client.terrain.editing.TerrainEditing; -import electrosphere.client.ui.components.PlayerInventoryWindow; import electrosphere.client.ui.menu.WindowStrings; import electrosphere.client.ui.menu.WindowUtils; -import electrosphere.client.ui.menu.debug.ImGuiWindowMacros; -import electrosphere.client.ui.menu.ingame.MenuGeneratorsInGame; -import electrosphere.collision.CollisionEngine; -import electrosphere.controls.Control.ControlMethod; -import electrosphere.controls.Control.ControlType; +import electrosphere.controls.categories.ControlCategoryAlwaysOnDebug; +import electrosphere.controls.categories.ControlCategoryFreecam; +import electrosphere.controls.categories.ControlCategoryInGameDebug; +import electrosphere.controls.categories.ControlCategoryInventory; +import electrosphere.controls.categories.ControlCategoryMainGame; +import electrosphere.controls.categories.ControlCategoryMenuNav; +import electrosphere.controls.categories.ControlCategoryTyping; import electrosphere.engine.Globals; -import electrosphere.engine.Main; -import electrosphere.engine.assetmanager.AssetDataStrings; -import electrosphere.entity.Entity; -import electrosphere.entity.btree.BehaviorTree; import electrosphere.entity.state.equip.ClientEquipState; -import electrosphere.entity.state.equip.ClientToolbarState; -import electrosphere.entity.state.inventory.InventoryUtils; -import electrosphere.entity.state.inventory.UnrelationalInventoryState; -import electrosphere.entity.state.movement.editor.ClientEditorMovementTree; -import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree; -import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree.MovementRelativeFacing; -import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree.MovementTreeState; -import electrosphere.entity.state.movement.jump.ClientJumpTree; -import electrosphere.entity.state.movement.sprint.ClientSprintTree; -import electrosphere.entity.state.movement.walk.ClientWalkTree; -import electrosphere.entity.types.creature.CreatureUtils; -import electrosphere.logger.LoggerInterface; -import electrosphere.net.parser.net.message.CharacterMessage; import electrosphere.renderer.ui.elements.Window; -import electrosphere.renderer.ui.events.ClickEvent; -import electrosphere.renderer.ui.events.KeyboardEvent; -import electrosphere.renderer.ui.events.MenuEvent; -import electrosphere.renderer.ui.events.MenuEvent.MenuEventType; -import electrosphere.util.FileUtils; import electrosphere.renderer.ui.events.MouseEvent; import electrosphere.renderer.ui.events.ScrollEvent; @@ -119,108 +36,6 @@ import electrosphere.renderer.ui.events.ScrollEvent; */ public class ControlHandler { - //main game - 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_WALK = "walk"; - public static final String INPUT_CODE_SINK = "sink"; - 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 ITEM_SECONDARY = "actionItemSecondary"; - public static final String INPUT_CODE_PLACE_TERRAIN = "placeTerrain"; - public static final String INPUT_CODE_REMOVE_TERRAIN = "removeTerrain"; - public static final String TOOLBAR_SCROLL = "toolbarScroll"; - - - //menu navigation - 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 MENU_MOUSE_MOVE = "menuMouseMove"; - public static final String MENU_SCROLL = "menuScroll"; - public static final String MENU_DRAG_MANIPULATE = "menuDragManipulate"; - public static final String MENU_DRAG_START = "menuDragStart"; - public static final String MENU_CAPTURE_SCREEN = "menuCaptureScreen"; - - - - //typing - 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"; - - //inventory - 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"; - - //debug - public static final String DEBUG_FRAMESTEP = "framestep"; - public static final String DEBUG_OPEN_DEBUG_MENU = "openDebugMenu"; - public static final String DEBUG_SWAP_EDITOR_MODE = "swapEditorMode"; - - //freecam - public static final String FREECAM_UP = "freecamUp"; - public static final String FREECAM_DOWN = "freecamDown"; - public static final String FREECAM_FORWARD = "freecamForward"; - public static final String FREECAM_BACKWARD = "freecamBackward"; - public static final String FREECAM_LEFT = "freecamLeft"; - public static final String FREECAM_RIGHT = "freecamRight"; - public static final String FREECAM_MOUSE = "freecamMouse"; - /** * The different buckets of inputs that the control handler be configured to scan for each frame */ @@ -237,6 +52,11 @@ public class ControlHandler { //The bucket of inputs that the control handler is currently scanning for ControlsState state = ControlsState.TITLE_MENU; + /** + * The state of the mouse + */ + MouseState mouseState = new MouseState(); + /** * The list of control states that have the mouse visible and enabled @@ -249,16 +69,24 @@ public class ControlHandler { }; - //controls whether the mouse is visible or not + /** + * Controls whether the mouse is visible or not + */ boolean mouseIsVisible = true; - //if set to true, opengl will try to capture the screen next frame + /** + * If set to true, opengl will try to capture the screen next frame + */ boolean shouldRecaptureScreen = false; - //controls whether the camera is first or third person + /** + * Controls whether the camera is first or third person + */ boolean cameraIsThirdPerson = true; - //The list of window strings that would block main game controls + /** + * The list of window strings that would block main game controls + */ static String[] controlBlockingWindows = new String[]{ WindowStrings.LEVEL_EDTIOR_SIDE_PANEL, WindowStrings.VOXEL_TYPE_SELECTION, @@ -271,19 +99,9 @@ public class ControlHandler { }; - /* - 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; //tracks whether the mouse is doing a drag input or not - - - //The map of data string -> control object + /** + * The map of control name (string) -> control (object) + */ HashMap controls; List mainGameControlList = new LinkedList(); @@ -307,134 +125,20 @@ public class ControlHandler { */ 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,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, new Control(ControlType.KEY,GLFW_KEY_W,false,"Move Foward","Moves the player forward")); - handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, new Control(ControlType.KEY,GLFW_KEY_S,false,"Move Backward","Moves the player backward")); - handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, new Control(ControlType.KEY,GLFW_KEY_F24,false,"Move Left","Moves the player left")); - handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, new Control(ControlType.KEY,GLFW_KEY_F24,false,"Move Right","Moves the player right")); - handler.addControl(DATA_STRING_INPUT_CODE_STRAFE_LEFT, new Control(ControlType.KEY,GLFW_KEY_A,false,"Strafe Left","Strafes the player left")); - handler.addControl(DATA_STRING_INPUT_CODE_STRAFE_RIGHT, new Control(ControlType.KEY,GLFW_KEY_D,false,"Strafe Right","Strafes the player right")); - handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP, new Control(ControlType.KEY,GLFW_KEY_SPACE,false,"Jump","Jumps")); - handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FALL, new Control(ControlType.KEY,GLFW_KEY_LEFT_CONTROL,false,"Fall","Lowers the camera")); - handler.addControl(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_LEFT,false,"Attack","Attacks")); - handler.addControl(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU, new Control(ControlType.KEY,GLFW_KEY_ESCAPE,false,"Main Menu","Opens the main menu while in game")); - handler.addControl(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR, new Control(ControlType.KEY,GLFW_KEY_CAPS_LOCK,false,"Lock On","Locks the camera onto the target")); - handler.addControl(INPUT_CODE_SPRINT, new Control(ControlType.KEY,GLFW_KEY_LEFT_SHIFT,false,"Sprint (hold)","Causes the player to sprint")); - handler.addControl(INPUT_CODE_WALK, new Control(ControlType.KEY,GLFW_KEY_LEFT_ALT,false,"Walk (hold)","Causes the player to walk")); - handler.addControl(INPUT_CODE_SINK, new Control(ControlType.KEY,GLFW_KEY_LEFT_CONTROL,true,"Sink","Sinks the entity")); - handler.addControl(INPUT_CODE_INTERACT, new Control(ControlType.KEY,GLFW_KEY_E,false,"Interact","Interacts with whatever is targeted currently")); - handler.addControl(INPUT_CODE_DROP, new Control(ControlType.KEY,GLFW_KEY_Y,false,"Drop","Drops the currently equipped item")); - handler.addControl(INPUT_CODE_INVENTORY_OPEN, new Control(ControlType.KEY,GLFW.GLFW_KEY_TAB,false,"Inventory","Opens the player's inventory")); - handler.addControl(ITEM_SECONDARY, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_RIGHT,false,"Secondary","Uses the secondary equipped item")); - handler.addControl(TOOLBAR_SCROLL, new Control(ControlType.MOUSE_SCROLL,0,false,"","")); - - /* - Map the menu navigation controls - */ - handler.addControl(DATA_STRING_INPUT_CODE_MENU_NAVIGATE_FORWARD, new Control(ControlType.KEY,GLFW_KEY_DOWN,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_NAVIGATE_BACKWARDS, new Control(ControlType.KEY,GLFW_KEY_UP,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_INCREMENT, new Control(ControlType.KEY,GLFW_KEY_RIGHT,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_DECREMENT, new Control(ControlType.KEY,GLFW_KEY_LEFT,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_SELECT, new Control(ControlType.KEY,GLFW_KEY_ENTER,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_BACKOUT, new Control(ControlType.KEY,GLFW_KEY_ESCAPE,false,"","")); - handler.addControl(MENU_MOUSE_MOVE, new Control(ControlType.MOUSE_MOVEMENT,0,false,"","")); - handler.addControl(INPUT_CODE_MENU_MOUSE_PRIMARY, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_LEFT,false,"","")); - handler.addControl(MENU_SCROLL, new Control(ControlType.MOUSE_SCROLL,0,false,"","")); - handler.addControl(MENU_DRAG_START, new Control(ControlType.MOUSE_MOVEMENT,0,false,"","")); - handler.addControl(MENU_CAPTURE_SCREEN, new Control(ControlType.KEY,GLFW_KEY_F4,true,"Screenshot","Takes a screenshot of the engine")); - handler.addControl(MENU_DRAG_MANIPULATE, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_1,false,"","")); - - /* - Map the typing controls - */ - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE, new Control(ControlType.KEY,GLFW_KEY_BACKSPACE,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_0, new Control(ControlType.KEY,GLFW_KEY_0,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_1, new Control(ControlType.KEY,GLFW_KEY_1,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_2, new Control(ControlType.KEY,GLFW_KEY_2,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_3, new Control(ControlType.KEY,GLFW_KEY_3,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_4, new Control(ControlType.KEY,GLFW_KEY_4,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_5, new Control(ControlType.KEY,GLFW_KEY_5,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_6, new Control(ControlType.KEY,GLFW_KEY_6,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_7, new Control(ControlType.KEY,GLFW_KEY_7,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_8, new Control(ControlType.KEY,GLFW_KEY_8,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_9, new Control(ControlType.KEY,GLFW_KEY_9,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD, new Control(ControlType.KEY,GLFW_KEY_PERIOD,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_A, new Control(ControlType.KEY,GLFW_KEY_A,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_B, new Control(ControlType.KEY,GLFW_KEY_B,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_C, new Control(ControlType.KEY,GLFW_KEY_C,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_D, new Control(ControlType.KEY,GLFW_KEY_D,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_E, new Control(ControlType.KEY,GLFW_KEY_E,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_F, new Control(ControlType.KEY,GLFW_KEY_F,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_G, new Control(ControlType.KEY,GLFW_KEY_G,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_H, new Control(ControlType.KEY,GLFW_KEY_H,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_I, new Control(ControlType.KEY,GLFW_KEY_I,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_J, new Control(ControlType.KEY,GLFW_KEY_J,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_K, new Control(ControlType.KEY,GLFW_KEY_K,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_L, new Control(ControlType.KEY,GLFW_KEY_L,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_M, new Control(ControlType.KEY,GLFW_KEY_M,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_N, new Control(ControlType.KEY,GLFW_KEY_N,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_O, new Control(ControlType.KEY,GLFW_KEY_O,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_P, new Control(ControlType.KEY,GLFW_KEY_P,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_Q, new Control(ControlType.KEY,GLFW_KEY_Q,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_R, new Control(ControlType.KEY,GLFW_KEY_R,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_S, new Control(ControlType.KEY,GLFW_KEY_S,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_T, new Control(ControlType.KEY,GLFW_KEY_T,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_U, new Control(ControlType.KEY,GLFW_KEY_U,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_V, new Control(ControlType.KEY,GLFW_KEY_V,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_W, new Control(ControlType.KEY,GLFW_KEY_W,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_X, new Control(ControlType.KEY,GLFW_KEY_X,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_Y, new Control(ControlType.KEY,GLFW_KEY_Y,false,"","")); - handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_Z, new Control(ControlType.KEY,GLFW_KEY_Z,false,"","")); - handler.addControl(INPUT_CODE_MENU_TYPE_FORWARD_SLASH, new Control(ControlType.KEY,GLFW_KEY_SLASH,false,"","")); - /* - Inventory controls - */ - handler.addControl(INPUT_CODE_INVENTORY_CLOSE, new Control(ControlType.KEY,GLFW_KEY_I,false,"","")); - handler.addControl(INPUT_CODE_INVENTORY_ITEM_MANIPULATE, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_1,false,"","")); - handler.addControl(INPUT_CODE_INVENTORY_ITEM_DRAG, new Control(ControlType.MOUSE_MOVEMENT,0,false,"","")); - - /** - Terrain controls - */ - handler.addControl(INPUT_CODE_PLACE_TERRAIN, new Control(ControlType.KEY,GLFW_KEY_T,false,"Place Terrain","Places terrain")); - handler.addControl(INPUT_CODE_REMOVE_TERRAIN, new Control(ControlType.KEY,GLFW_KEY_Y,false,"Remove Terrain","Removes terrain")); - - /* - framestep controls - */ - handler.addControl(DEBUG_FRAMESTEP, new Control(ControlType.KEY, GLFW_KEY_P,false,"Framesetp","Steps the engine forward one frame")); - - /* - * Free camera - */ - handler.addControl(FREECAM_UP, new Control(ControlType.KEY,GLFW_KEY_SPACE,false,"Up","Moves the camera up")); - handler.addControl(FREECAM_DOWN, new Control(ControlType.KEY,GLFW_KEY_LEFT_CONTROL,false,"Down","Moves the camera down")); - handler.addControl(FREECAM_FORWARD, new Control(ControlType.KEY,GLFW_KEY_W,false,"Forward","Moves the camera forward")); - handler.addControl(FREECAM_BACKWARD, new Control(ControlType.KEY,GLFW_KEY_S,false,"Backward","Moves the camera backward")); - handler.addControl(FREECAM_LEFT, new Control(ControlType.KEY,GLFW_KEY_A,false,"Left","Moves the camera left")); - handler.addControl(FREECAM_RIGHT, new Control(ControlType.KEY,GLFW_KEY_D,false,"Right","Moves the camera right")); - handler.addControl(FREECAM_MOUSE, new Control(ControlType.MOUSE_MOVEMENT,0,false,"","")); + ControlCategoryAlwaysOnDebug.mapControls(handler); + ControlCategoryMainGame.mapControls(handler); + ControlCategoryMenuNav.mapControls(handler); + ControlCategoryTyping.mapControls(handler); + ControlCategoryInventory.mapControls(handler); + ControlCategoryInGameDebug.mapControls(handler); + ControlCategoryFreecam.mapControls(handler); /* 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,false,"","")); - handler.addControl(DEBUG_OPEN_DEBUG_MENU, new Control(ControlType.KEY, GLFW_KEY_F2,false,"Debug Menu","Opens the debug menu")); - handler.addControl(DEBUG_SWAP_EDITOR_MODE, new Control(ControlType.KEY, GLFW_KEY_F4,false,"Swap Editor Mode","Swaps to/from the editor entity")); /* return @@ -452,11 +156,11 @@ public class ControlHandler { switch(state){ - case MAIN_GAME: - runHandlers(mainGameControlList); - runHandlers(mainGameDebugControlList); - runHandlers(alwaysOnDebugControlList); - break; + case MAIN_GAME: { + this.runHandlers(mainGameControlList); + this.runHandlers(mainGameDebugControlList); + this.runHandlers(alwaysOnDebugControlList); + } break; @@ -464,37 +168,37 @@ public class ControlHandler { break; - case TITLE_MENU: - runHandlers(menuNavigationControlList); - /* - Typing.. - */ - runHandlers(typingControlList); - runHandlers(alwaysOnDebugControlList); - break; + case TITLE_MENU: { + this.runHandlers(menuNavigationControlList); + /* + Typing.. + */ + this.runHandlers(typingControlList); + this.runHandlers(alwaysOnDebugControlList); + } break; - case IN_GAME_MAIN_MENU: - runHandlers(menuNavigationControlList); - runHandlers(typingControlList); - runHandlers(alwaysOnDebugControlList); - // pollMenuNavigationControls(); - break; + case IN_GAME_MAIN_MENU: { + this.runHandlers(menuNavigationControlList); + this.runHandlers(typingControlList); + this.runHandlers(alwaysOnDebugControlList); + // pollMenuNavigationControls(); + } break; - case IN_GAME_FREE_CAMERA: - runHandlers(freeCameraControlList); - runHandlers(mainGameDebugControlList); - runHandlers(alwaysOnDebugControlList); - break; + case IN_GAME_FREE_CAMERA: { + this.runHandlers(freeCameraControlList); + this.runHandlers(mainGameDebugControlList); + this.runHandlers(alwaysOnDebugControlList); + } break; - case INVENTORY: - runHandlers(inventoryControlList); - runHandlers(menuNavigationControlList); - runHandlers(alwaysOnDebugControlList); - break; + case INVENTORY: { + this.runHandlers(inventoryControlList); + this.runHandlers(menuNavigationControlList); + this.runHandlers(alwaysOnDebugControlList); + } break; - case NO_INPUT: - runHandlers(alwaysOnDebugControlList); - break; + case NO_INPUT: { + this.runHandlers(alwaysOnDebugControlList); + } break; } Globals.scrollCallback.clear(); @@ -504,1048 +208,13 @@ public class ControlHandler { * Attaches callbacks to each of the control objects */ public void setCallbacks(){ - setMainGameControls(); - setInGameDebugControls(); - setMenuNavigationControls(); - setTypingControls(); - setInventoryControls(); - setAlwaysOnDebugControls(); - setFreecamControls(); - } - - - /** - * Sets callbacks for the main game controls - */ - 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){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).isState()){ - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - groundTree.start(MovementRelativeFacing.FORWARD_LEFT); - } else if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).isState()){ - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - groundTree.start(MovementRelativeFacing.FORWARD_RIGHT); - } else { - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - groundTree.start(MovementRelativeFacing.FORWARD); - } - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); - } - } - }}); - controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).setOnRepeat(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).isState()){ - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - groundTree.start(MovementRelativeFacing.FORWARD_LEFT); - } else if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).isState()){ - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - groundTree.start(MovementRelativeFacing.FORWARD_RIGHT); - } else { - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - groundTree.start(MovementRelativeFacing.FORWARD); - } - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); - } - } - }}); - controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).setOnRelease(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - groundTree.slowdown(); - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - clientEditorMovementTree.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){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); - if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).isState()){ - CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(3.0/4.0*Math.PI).normalize()); - groundTree.start(MovementRelativeFacing.BACKWARD_LEFT); - } else if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).isState()){ - CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(5.0/4.0*Math.PI).normalize()); - groundTree.start(MovementRelativeFacing.BACKWARD_RIGHT); - } else { - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - groundTree.start(MovementRelativeFacing.BACKWARD); - } - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.BACKWARD); - } - } - }}); - controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).setOnRepeat(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); - if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).isState()){ - CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(3.0/4.0*Math.PI).normalize()); - groundTree.start(MovementRelativeFacing.BACKWARD_LEFT); - } else if(controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).isState()){ - CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(5.0/4.0*Math.PI).normalize()); - groundTree.start(MovementRelativeFacing.BACKWARD_RIGHT); - } else { - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - groundTree.start(MovementRelativeFacing.BACKWARD); - } - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.BACKWARD); - } - } - }}); - controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).setOnRelease(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - groundTree.slowdown(); - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - clientEditorMovementTree.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){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - 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()); - groundTree.start(MovementRelativeFacing.FORWARD); - } - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI/2.0).normalize()); - clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); - } - } - }}); - controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).setOnRepeat(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - 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()); - groundTree.start(MovementRelativeFacing.FORWARD); - } - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI/2.0).normalize()); - clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); - } - } - }}); - controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).setOnRelease(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - groundTree.slowdown(); - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - clientEditorMovementTree.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){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - 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()); - groundTree.start(MovementRelativeFacing.FORWARD); - } - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(-Math.PI/2.0).normalize()); - clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); - } - } - }}); - controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).setOnRepeat(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - 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()); - groundTree.start(MovementRelativeFacing.FORWARD); - } - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(-Math.PI/2.0).normalize()); - clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); - } - } - }}); - controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).setOnRelease(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - groundTree.slowdown(); - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - clientEditorMovementTree.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){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - if( - (groundTree.getState()==MovementTreeState.IDLE || groundTree.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())) - ){ - groundTree.start(MovementRelativeFacing.LEFT); - } - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.LEFT); - } - } - }}); - controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).setOnRepeat(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - if( - (groundTree.getState()==MovementTreeState.IDLE || groundTree.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())) - ){ - groundTree.start(MovementRelativeFacing.LEFT); - } - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.LEFT); - } - } - }}); - controls.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).setOnRelease(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - groundTree.slowdown(); - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - clientEditorMovementTree.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){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - if( - (groundTree.getState()==MovementTreeState.IDLE || groundTree.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())) - ){ - groundTree.start(MovementRelativeFacing.RIGHT); - } - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.RIGHT); - } - } - }}); - controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).setOnRepeat(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - if( - (groundTree.getState()==MovementTreeState.IDLE || groundTree.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())) - ){ - groundTree.start(MovementRelativeFacing.RIGHT); - } - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); - clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.RIGHT); - } - } - }}); - controls.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).setOnRelease(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); - if(movementTree instanceof ClientGroundMovementTree){ - ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - groundTree.slowdown(); - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - clientEditorMovementTree.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){ - ClientJumpTree jumpTree = ClientJumpTree.getClientJumpTree(Globals.playerEntity); - if(jumpTree != null){ - jumpTree.start(); - } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.UP); - } - } - }}); - controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP).setOnRelease(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - clientEditorMovementTree.slowdown(); - } - } - }}); - /** - * Sink - */ - mainGameControlList.add(controls.get(INPUT_CODE_SINK)); - controls.get(INPUT_CODE_SINK).setOnPress(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.DOWN); - } - } - }}); - controls.get(INPUT_CODE_SINK).setOnRelease(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); - clientEditorMovementTree.slowdown(); - } - } - }}); - /* - Sprint - */ - mainGameControlList.add(controls.get(INPUT_CODE_SPRINT)); - controls.get(INPUT_CODE_SPRINT).setOnPress(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - ClientSprintTree sprintTree = ClientSprintTree.getClientSprintTree(Globals.playerEntity); - if(sprintTree != null){ - sprintTree.start(); - } - } - }}); - controls.get(INPUT_CODE_SPRINT).setOnRelease(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - ClientSprintTree sprintTree = ClientSprintTree.getClientSprintTree(Globals.playerEntity); - if(sprintTree != null){ - sprintTree.interrupt(); - } - } - }}); - - /** - * Walk - */ - mainGameControlList.add(controls.get(INPUT_CODE_WALK)); - controls.get(INPUT_CODE_WALK).setOnPress(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null && ClientWalkTree.getClientWalkTree(Globals.playerEntity) != null){ - ClientWalkTree clientWalkTree = ClientWalkTree.getClientWalkTree(Globals.playerEntity); - clientWalkTree.start(); - } - }}); - controls.get(INPUT_CODE_WALK).setOnRelease(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null && ClientWalkTree.getClientWalkTree(Globals.playerEntity) != null){ - ClientWalkTree clientWalkTree = ClientWalkTree.getClientWalkTree(Globals.playerEntity); - clientWalkTree.interrupt(); - } - }}); - - - /* - 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(){ - ItemActions.attemptPrimaryItemAction(); - }}); - controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).setOnRepeat(new ControlMethod(){public void execute(){ - ItemActions.repeatPrimaryItemAction(); - }}); - controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).setOnRelease(new ControlMethod(){public void execute(){ - ItemActions.releasePrimaryItemAction(); - }}); - controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).setRepeatTimeout(0.5f * Main.targetFrameRate); - - /** - * Secondary item actions - */ - mainGameControlList.add(controls.get(ITEM_SECONDARY)); - controls.get(ITEM_SECONDARY).setOnPress(new ControlMethod() {public void execute() { - ItemActions.attemptSecondaryItemAction(); - }}); - controls.get(ITEM_SECONDARY).setOnRelease(new ControlMethod() {public void execute() { - ItemActions.releaseSecondaryItemAction(); - }}); - - /** - * Toolbar scrolling - */ - mainGameControlList.add(controls.get(TOOLBAR_SCROLL)); - controls.get(TOOLBAR_SCROLL).setOnScroll(new Control.ScrollCallback() {public void execute(ScrollEvent scrollEvent){ - if(Globals.playerEntity != null && ClientToolbarState.getClientToolbarState(Globals.playerEntity) != null){ - ClientToolbarState clientToolbarState = ClientToolbarState.getClientToolbarState(Globals.playerEntity); - if(scrollEvent.getScrollAmount() > 0){ - clientToolbarState.attemptChangeSelection(clientToolbarState.getSelectedSlot() - 1); - } else { - clientToolbarState.attemptChangeSelection(clientToolbarState.getSelectedSlot() + 1); - } - } - }}); - - /* - Interact - */ - mainGameControlList.add(controls.get(INPUT_CODE_INTERACT)); - controls.get(INPUT_CODE_INTERACT).setOnPress(new ControlMethod(){public void execute(){ - if(Globals.playerEntity != null){ - if(ClientEquipState.hasEquipState(Globals.playerEntity) && Crosshair.hasTarget()){ - if(InventoryUtils.hasNaturalInventory(Globals.playerEntity)){ - InventoryUtils.clientAttemptStoreItem(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(ClientEquipState.hasEquipState(Globals.playerEntity)){ - UnrelationalInventoryState inventory = InventoryUtils.getNaturalInventory(Globals.playerEntity); - if(inventory.getItems().size() > 0){ - Entity itemToDrop = inventory.getItems().get(0); - InventoryUtils.clientAttemptEjectItem(Globals.playerEntity,itemToDrop); - } - } - } - }}); - - - /* - 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.hintUpdateControlState(ControlsState.IN_GAME_MAIN_MENU); - - // Window mainMenuWindow = new Window(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); - Window mainMenuInGame = MenuGeneratorsInGame.createInGameMainMenu(); - // mainMenuWindow.addChild(mainMenuInGame); - Globals.elementService.registerWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, mainMenuInGame); - WindowUtils.recursiveSetVisible(Globals.elementService.getWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN), true); - Globals.elementService.focusFirstElement(); - Globals.controlHandler.hintUpdateControlState(ControlsState.IN_GAME_MAIN_MENU); - //play sound effect - if(Globals.virtualAudioSourceManager != null){ - Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.UI_TONE_CONFIRM_PRIMARY, VirtualAudioSourceType.UI, false); - } - Globals.renderingEngine.getPostProcessingPipeline().setApplyBlur(true); - }}); - 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(Globals.elementService.getWindow(WindowStrings.WINDOW_CHARACTER) == null){ - //create window - Window mainMenuWindow = PlayerInventoryWindow.createPlayerInventoryWindow(Globals.playerEntity); - //register - Globals.elementService.registerWindow(WindowStrings.WINDOW_CHARACTER, mainMenuWindow); - //make visible - WindowUtils.recursiveSetVisible(WindowStrings.WINDOW_CHARACTER, true); - //controls - Globals.controlHandler.hintUpdateControlState(ControlsState.INVENTORY); - //play sound effect - if(Globals.virtualAudioSourceManager != null){ - Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.UI_SFX_INVENTORY_OPEN, VirtualAudioSourceType.UI, false); - } - Globals.renderingEngine.getPostProcessingPipeline().setApplyBlur(true); - // - Globals.openInventoriesCount++; - } else if(InventoryUtils.hasNaturalInventory(Globals.playerEntity) && Globals.elementService.getWindow(WindowStrings.WINDOW_CHARACTER) != null){ - Globals.elementService.closeWindow(WindowStrings.WINDOW_CHARACTER); - Globals.renderingEngine.getPostProcessingPipeline().setApplyBlur(false); - if(Globals.virtualAudioSourceManager != null){ - Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.UI_SFX_INVENTORY_CLOSE, VirtualAudioSourceType.UI, false); - } - } - }}); - controls.get(INPUT_CODE_INVENTORY_OPEN).setRepeatTimeout(0.5f * Main.targetFrameRate); - - /** - * Places terrain - */ - mainGameControlList.add(controls.get(INPUT_CODE_PLACE_TERRAIN)); - controls.get(INPUT_CODE_PLACE_TERRAIN).setOnPress(new ControlMethod(){public void execute(){ - CollisionEngine collisionEngine = Globals.clientSceneWrapper.getCollisionEngine(); - Entity camera = Globals.playerCamera; - if( - collisionEngine != null && - camera != null - ){ - Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(camera)); - Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(camera)); - Vector3d cursorPos = collisionEngine.rayCastPosition(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1.0), CollisionEngine.DEFAULT_INTERACT_DISTANCE); - if(Globals.clientSelectedVoxelType != null){ - TerrainEditing.editTerrain(cursorPos, 1.1f, Globals.clientSelectedVoxelType.getId(), 0.1f); - } - } - }}); - controls.get(INPUT_CODE_PLACE_TERRAIN).setOnRepeat(new ControlMethod(){public void execute(){ - CollisionEngine collisionEngine = Globals.clientSceneWrapper.getCollisionEngine(); - Entity camera = Globals.playerCamera; - if( - collisionEngine != null && - camera != null - ){ - Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(camera)); - Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(camera)); - Vector3d cursorPos = collisionEngine.rayCastPosition(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1.0), CollisionEngine.DEFAULT_INTERACT_DISTANCE); - if(Globals.clientSelectedVoxelType != null){ - TerrainEditing.editTerrain(cursorPos, 1.1f, Globals.clientSelectedVoxelType.getId(), 0.1f); - } - } - }}); - controls.get(INPUT_CODE_PLACE_TERRAIN).setRepeatTimeout(0.2f * Main.targetFrameRate); - - mainGameControlList.add(controls.get(INPUT_CODE_REMOVE_TERRAIN)); - controls.get(INPUT_CODE_REMOVE_TERRAIN).setOnPress(new ControlMethod(){public void execute(){ - CollisionEngine collisionEngine = Globals.clientSceneWrapper.getCollisionEngine(); - Entity camera = Globals.playerCamera; - if( - collisionEngine != null && - camera != null - ){ - Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(camera)); - Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(camera)); - Vector3d cursorPos = collisionEngine.rayCastPosition(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1.0), CollisionEngine.DEFAULT_INTERACT_DISTANCE); - TerrainEditing.editTerrain(cursorPos, 1.1f, 1, -0.01f); - } - }}); - controls.get(INPUT_CODE_REMOVE_TERRAIN).setOnRepeat(new ControlMethod(){public void execute(){ - CollisionEngine collisionEngine = Globals.clientSceneWrapper.getCollisionEngine(); - Entity camera = Globals.playerCamera; - if( - collisionEngine != null && - camera != null - ){ - Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(camera)); - Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(camera)); - Vector3d cursorPos = collisionEngine.rayCastPosition(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1.0), CollisionEngine.DEFAULT_INTERACT_DISTANCE); - TerrainEditing.editTerrain(cursorPos, 1.1f, 1, -0.01f); - } - }}); - controls.get(INPUT_CODE_REMOVE_TERRAIN).setRepeatTimeout(0.2f * Main.targetFrameRate); - - } - - - /** - * Sets the in game debug control callbacks - */ - 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); - }}); - controls.get(DEBUG_FRAMESTEP).setOnRepeat(new ControlMethod(){public void execute(){ - Main.setFramestep(1); - }}); - controls.get(DEBUG_FRAMESTEP).setRepeatTimeout(0.5f * Main.targetFrameRate); - // RenderingEngine.incrementOutputFramebuffer(); - - - // - //Swap to/from editor entity - // - alwaysOnDebugControlList.add(controls.get(DEBUG_SWAP_EDITOR_MODE)); - controls.get(DEBUG_SWAP_EDITOR_MODE).setOnPress(new ControlMethod(){public void execute(){ - LoggerInterface.loggerEngine.INFO("Swap to/from editor entity"); - Globals.clientConnection.queueOutgoingMessage(CharacterMessage.constructEditorSwapMessage()); - }}); - controls.get(DEBUG_SWAP_EDITOR_MODE).setRepeatTimeout(0.5f * Main.targetFrameRate); - } - - void setAlwaysOnDebugControls(){ - alwaysOnDebugControlList.add(controls.get(DEBUG_OPEN_DEBUG_MENU)); - controls.get(DEBUG_OPEN_DEBUG_MENU).setOnPress(new ControlMethod(){public void execute(){ - LoggerInterface.loggerEngine.INFO("open debug menu"); - ImGuiWindowMacros.toggleMainDebugMenu(); - //play sound effect - if(Globals.virtualAudioSourceManager != null){ - Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.UI_TONE_CONFIRM_PRIMARY, VirtualAudioSourceType.UI, false); - } - }}); - controls.get(DEBUG_OPEN_DEBUG_MENU).setRepeatTimeout(0.5f * Main.targetFrameRate); - } - - 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.elementService.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.elementService.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.elementService.fireEvent( - new MenuEvent(MenuEventType.INCREMENT), - Globals.elementService.getFocusedElement().getAbsoluteX(), - Globals.elementService.getFocusedElement().getAbsoluteY() - ); - }}); - controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).setOnRepeat(new ControlMethod(){public void execute(){ - Globals.elementService.fireEvent( - new MenuEvent(MenuEventType.INCREMENT), - Globals.elementService.getFocusedElement().getAbsoluteX(), - Globals.elementService.getFocusedElement().getAbsoluteY() - ); - }}); - controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).setRepeatTimeout(0.5f * Main.targetFrameRate); - - //moving the mouse - inventoryControlList.add(controls.get(MENU_MOUSE_MOVE)); - menuNavigationControlList.add(controls.get(MENU_MOUSE_MOVE)); - controls.get(MENU_MOUSE_MOVE).setOnMove(new Control.MouseCallback(){public void execute(MouseEvent mouseEvent){ - Globals.elementService.updateHover(mouseEvent.getCurrentX(), mouseEvent.getCurrentY()); - }}); - - //scrolling the mouse - menuNavigationControlList.add(controls.get(MENU_SCROLL)); - controls.get(MENU_SCROLL).setOnScroll(new Control.ScrollCallback() {public void execute(ScrollEvent scrollEvent){ - Globals.elementService.fireEvent(scrollEvent, GLFW_KEY_X, GLFW_KEY_Z); - }}); - - //dragging the cursor - menuNavigationControlList.add(controls.get(MENU_DRAG_MANIPULATE)); - controls.get(MENU_DRAG_MANIPULATE).setOnPress(new ControlMethod(){public void execute(){ - }}); - controls.get(MENU_DRAG_MANIPULATE).setOnRelease(new ControlMethod(){public void execute(){ - if(dragging){ - dragging = false; - //fire dragrelease event to elementmanager - Globals.elementService.dragRelease((int)xpos,(int)ypos,(int)mouse_lastX,(int)mouse_lastY,(int)(xpos - mouse_lastX),(int)(mouse_lastY - ypos)); - } - }}); - /* - item dragging - */ - menuNavigationControlList.add(controls.get(MENU_DRAG_START)); - controls.get(MENU_DRAG_START).setOnMove(new Control.MouseCallback(){public void execute(MouseEvent event){ - if(!dragging && event.getButton1()){ - dragging = true; - //fire dragstart event to elementmanager - Globals.elementService.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.elementService.drag((int)xpos,(int)ypos,(int)mouse_lastX,(int)mouse_lastY,(int)(xpos - mouse_lastX),(int)(mouse_lastY - ypos)); - } - }}); - - /** - Screenshots - */ - menuNavigationControlList.add(controls.get(MENU_CAPTURE_SCREEN)); - controls.get(MENU_CAPTURE_SCREEN).setOnPress(new Control.ControlMethod() {public void execute(){ - FileUtils.writeBufferedImage( - Globals.renderingEngine.defaultFramebuffer.getPixels(Globals.renderingEngine.getOpenGLState()), - "Screenshots/" + System.currentTimeMillis() + ".png" - ); - }}); - - - - - //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.elementService.fireEvent( - new MenuEvent(MenuEventType.DECREMENT), - Globals.elementService.getFocusedElement().getAbsoluteX(), - Globals.elementService.getFocusedElement().getAbsoluteY() - ); - }}); - controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).setOnRepeat(new ControlMethod(){public void execute(){ - Globals.elementService.fireEvent( - new MenuEvent(MenuEventType.DECREMENT), - Globals.elementService.getFocusedElement().getAbsoluteX(), - Globals.elementService.getFocusedElement().getAbsoluteY() - ); - }}); - 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.elementService.click(new ClickEvent( - Globals.elementService.getFocusedElement().getAbsoluteX() + 1, - Globals.elementService.getFocusedElement().getAbsoluteY() + 1, - 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.elementService.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.elementService.navigateBackwards(); - // Globals.elementManager.unregisterWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN); - }}); - controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).setRepeatTimeout(0.5f * Main.targetFrameRate); - - } - - /** - * Sets the freecam control callbacks - */ - void setFreecamControls(){ - freeCameraControlList.add(controls.get(FREECAM_UP)); - controls.get(FREECAM_UP).setOnRepeat(new ControlMethod(){public void execute(){ - Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); - playerCameraCenterPos.add(0,0.1f,0); - CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); - }}); - - - freeCameraControlList.add(controls.get(FREECAM_DOWN)); - controls.get(FREECAM_DOWN).setOnRepeat(new ControlMethod(){public void execute(){ - Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); - playerCameraCenterPos.add(0,-0.1f,0); - CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); - }}); - - - freeCameraControlList.add(controls.get(FREECAM_FORWARD)); - ControlMethod freeCamForwardCallback = new ControlMethod(){public void execute(){ - Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); - Vector3f playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); - playerCameraCenterPos.add(new Vector3f(playerCameraEyePos).normalize().mul(-0.1f)); - CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); - }}; - controls.get(FREECAM_FORWARD).setOnClick(freeCamForwardCallback); - controls.get(FREECAM_FORWARD).setOnRepeat(freeCamForwardCallback); - - freeCameraControlList.add(controls.get(FREECAM_BACKWARD)); - ControlMethod freeCamBackwardCallback = new ControlMethod(){public void execute(){ - Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); - Vector3f playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); - playerCameraCenterPos.add(new Vector3f(playerCameraEyePos).normalize().mul(0.1f)); - CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); - }}; - controls.get(FREECAM_BACKWARD).setOnClick(freeCamBackwardCallback); - controls.get(FREECAM_BACKWARD).setOnRepeat(freeCamBackwardCallback); - - freeCameraControlList.add(controls.get(FREECAM_LEFT)); - ControlMethod freeCamLeftCallback = new ControlMethod(){public void execute(){ - Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); - Vector3f playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); - Vector3f modifiedVec = new Vector3f(playerCameraEyePos.x,0,playerCameraEyePos.z).rotateY((float)(-90 * Math.PI / 180)).normalize(); - playerCameraCenterPos.add(new Vector3f(modifiedVec).mul(0.1f)); - CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); - }}; - controls.get(FREECAM_LEFT).setOnClick(freeCamLeftCallback); - controls.get(FREECAM_LEFT).setOnRepeat(freeCamLeftCallback); - - freeCameraControlList.add(controls.get(FREECAM_RIGHT)); - ControlMethod freeCamRightCallback = new ControlMethod(){public void execute(){ - Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); - Vector3f playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); - Vector3f modifiedVec = new Vector3f(playerCameraEyePos.x,0,playerCameraEyePos.z).rotateY((float)(90 * Math.PI / 180)).normalize(); - playerCameraCenterPos.add(new Vector3f(modifiedVec).mul(0.1f)); - CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); - }}; - controls.get(FREECAM_RIGHT).setOnClick(freeCamRightCallback); - controls.get(FREECAM_RIGHT).setOnRepeat(freeCamRightCallback); - - //terrain controls -- these should have already been defined in the main game controls section - freeCameraControlList.add(controls.get(INPUT_CODE_PLACE_TERRAIN)); - freeCameraControlList.add(controls.get(INPUT_CODE_REMOVE_TERRAIN)); - - freeCameraControlList.add(controls.get(FREECAM_MOUSE)); - controls.get(FREECAM_MOUSE).setOnMove(new Control.MouseCallback(){public void execute(MouseEvent event){ - Globals.cameraHandler.handleMouseEvent(event); - }}); - - freeCameraControlList.add(controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU)); - - } - - /** - * Sets the typing control callbacks - */ - 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.elementService.fireEventNoPosition( - new KeyboardEvent(convertKeycodeToName(controls.get(currentKey).keyValue)), - Globals.elementService.getFocusedElement() - ); - // 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); - // } - } - } - - /** - * Sets the inventory control callbacks - */ - void setInventoryControls(){ - /* - 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.elementService.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.elementService.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.elementService.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.elementService.drag((int)xpos,(int)ypos,(int)mouse_lastX,(int)mouse_lastY,(int)(xpos - mouse_lastX),(int)(mouse_lastY - ypos)); - } - }}); + ControlCategoryMainGame.setCallbacks(controls, mainGameControlList, inventoryControlList); + ControlCategoryInGameDebug.setCallbacks(controls, mainGameDebugControlList, alwaysOnDebugControlList); + ControlCategoryMenuNav.setCallbacks(controls, menuNavigationControlList, mainGameDebugControlList, inventoryControlList); + ControlCategoryTyping.setCallbacks(controls, typingControlList); + ControlCategoryInventory.setCallbacks(controls, inventoryControlList); + ControlCategoryAlwaysOnDebug.setCallbacks(controls, alwaysOnDebugControlList); + ControlCategoryFreecam.setCallbacks(controls, freeCameraControlList); } /** @@ -1561,17 +230,27 @@ public class ControlHandler { * Checks a list of controls to see if the corresponding key/mouse event is firing this frame * @param controls The list of controls to check */ - public void runHandlers(List controls){ - - //construct mouse event - + private void runHandlers(List controls){ //Fills the buffer - getMousePositionInBuffer(); - 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,getButton1Raw(),getButton2Raw()); + this.getMousePositionInBuffer(); + this.mouseState.setLastX((float)this.mouseState.getCurrentX()); + this.mouseState.setLastY((float)this.mouseState.getCurrentY()); + this.mouseState.setCurrentX(this.mouseState.getMouseBufferX()[0]); + this.mouseState.setCurrentY(this.mouseState.getMouseBufferY()[0]); + this.mouseState.setDeltaX(this.mouseState.getCurrentX() - this.mouseState.getLastX()); + this.mouseState.setDeltaY(this.mouseState.getLastY() - this.mouseState.getCurrentY()); + float xoffset = (float) (this.mouseState.getCurrentX() - this.mouseState.getLastX()); + float yoffset = (float) (this.mouseState.getLastY() - this.mouseState.getCurrentY()); + MouseEvent currentMouseEvent = new MouseEvent( + (int)this.mouseState.getCurrentX(), + (int)this.mouseState.getCurrentY(), + (int)this.mouseState.getLastX(), + (int)this.mouseState.getLastY(), + (int)xoffset, + (int)yoffset, + this.getButton1Raw(), + this.getButton2Raw() + ); boolean mouseMoveEvent = xoffset != 0 || yoffset != 0; @@ -1581,22 +260,22 @@ public class ControlHandler { if(Globals.controlCallback.getKey(control.getKeyValue())){ if(!control.isState()){ //on press - control.onPress(); + control.onPress(this.mouseState); control.setPressFrame((float)Globals.timekeeper.getNumberOfRenderFramesElapsed()); } else { //on repeat if((float)Globals.timekeeper.getNumberOfRenderFramesElapsed() - control.getPressFrame() > control.getRepeatTimeout()){ - control.onRepeat(); + control.onRepeat(this.mouseState); } } control.setState(true); } else { if(control.isState()){ //on release - control.onRelease(); + control.onRelease(this.mouseState); //on click if((float)Globals.timekeeper.getNumberOfRenderFramesElapsed() - control.getPressFrame() < control.getRepeatTimeout()){ - control.onClick(); + control.onClick(this.mouseState); } } else { } @@ -1607,19 +286,19 @@ public class ControlHandler { if(Globals.mouseCallback.getButton(control.getKeyValue())){ if(!control.isState()){ //on press - control.onPress(); + control.onPress(this.mouseState); control.setPressFrame((float)Globals.timekeeper.getNumberOfRenderFramesElapsed()); } else { //on repeat - control.onRepeat(); + control.onRepeat(this.mouseState); } control.setState(true); } else { if(control.isState()){ //on release - control.onRelease(); + control.onRelease(this.mouseState); if((float)Globals.timekeeper.getNumberOfRenderFramesElapsed() - control.getPressFrame() < control.getRepeatTimeout()){ - control.onClick(); + control.onClick(this.mouseState); } } else { } @@ -1628,14 +307,14 @@ public class ControlHandler { } break; case MOUSE_MOVEMENT: { if(mouseMoveEvent){ - control.onMove(currentMouseEvent); + control.onMove(this.mouseState,currentMouseEvent); } } break; case MOUSE_SCROLL: { double yScroll = Globals.scrollCallback.getOffsetY(); if(yScroll != 0){ - ScrollEvent event = new ScrollEvent(xpos,ypos,yScroll); - control.onScroll(event); + ScrollEvent event = new ScrollEvent(this.mouseState.getCurrentX(),this.mouseState.getCurrentY(),yScroll); + control.onScroll(this.mouseState,event); } } break; } @@ -1716,9 +395,7 @@ public class ControlHandler { void getMousePositionInBuffer(){ //only if not headless, gather position if(!Globals.HEADLESS){ - glfwGetCursorPos(Globals.window, mouse_X_Buffer, mouse_Y_Buffer); - xpos = mouse_X_Buffer[0]; - ypos = mouse_Y_Buffer[0]; + glfwGetCursorPos(Globals.window, this.mouseState.getMouseBufferX(), this.mouseState.getMouseBufferY()); } } @@ -1746,19 +423,41 @@ public class ControlHandler { } } + /** + * Gets a control + * @param controlName The name of the control + * @return The control if it exists, null otherwise + */ public Control getControl(String controlName){ return controls.get(controlName); } + /** + * Checks if the handler contains a control + * @param controlName The name of the control + * @return true if the control exists, false otherwise + */ public boolean containsControl(String controlName){ return controls.containsKey(controlName); } + /** + * Removes a control from the handler + * @param controlName The name of the control + */ public void removeControl(String controlName){ controls.remove(controlName); } + /** + * Adds a control to the handler + * @param controlName The name of the control + * @param c The control itself + */ public void addControl(String controlName, Control c){ + if(controls.containsKey(controlName)){ + throw new Error("Control handler already contains control " + controlName + " " + c + " " + controls.get(controlName)); + } controls.put(controlName, c); } @@ -1815,141 +514,6 @@ public class ControlHandler { return rVal; } - /** - * Converts a keycode to a string containing a code related to the keycode (ie "A" for 65, "Escape" for 256, etc) - * @param code The keycode - * @return The corresponding string code - */ - 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; - } - /** * Sets whether the engine should try to recapture window focus next frame or not * @param shouldRecapture true if should try to recapture next frame, false otherwise diff --git a/src/main/java/electrosphere/controls/MouseState.java b/src/main/java/electrosphere/controls/MouseState.java new file mode 100644 index 00000000..0f83f35a --- /dev/null +++ b/src/main/java/electrosphere/controls/MouseState.java @@ -0,0 +1,185 @@ +package electrosphere.controls; + +/** + * Tracks the state of the mouse + */ +public class MouseState { + + /** + * The x coordinate of the position last frame + */ + float lastX = 400; + + /** + * The y coordinate of the position last frame + */ + float lastY = 300; + + /** + * The x coordinate of the position this frame + */ + double currentX = 400; + + /** + * The y coordinate of the position this frame + */ + double currentY = 300; + + /** + * The delta in the x axis between last frame and this frame + */ + double deltaX = 0; + + /** + * The delta in the y axis between last frame and this frame + */ + double deltaY = 0; + + /** + * The buffer for storing x coordinates + */ + + double mouseBufferX[] = new double[1]; + + /** + * The buffer for storing y coordinates + */ + double mouseBufferY[] = new double[1]; + + /** + * Tracks whether the mouse is doing a drag input or not + */ + boolean dragging = false; + + /** + * Gets the x coordinate of the position last frame + * @return The x coordinate of the position last frame + */ + public float getLastX() { + return lastX; + } + + /** + * Sets the x coordinate of the position last frame + * @param lastX The x coordinate of the position last frame + */ + public void setLastX(float lastX) { + this.lastX = lastX; + } + + /** + * Gets the y coordinate of the position last frame + * @return The y coordinate of the position last frame + */ + public float getLastY() { + return lastY; + } + + /** + * Sets the y coordinate of the position last frame + * @param lastY The y coordinate of the position last frame + */ + public void setLastY(float lastY) { + this.lastY = lastY; + } + + /** + * Gets the x coordinate of the position this frame + * @return The x coordinate of the position this frame + */ + public double getCurrentX() { + return currentX; + } + + /** + * Sets the x coordinate of the position this frame + * @param currentX The x coordinate of the position this frame + */ + public void setCurrentX(double currentX) { + this.currentX = currentX; + } + + /** + * Gets the y coordinate of the position this frame + * @return The y coordinate of the position this frame + */ + public double getCurrentY() { + return currentY; + } + + /** + * Sets the y coordinate of the position this frame + * @param currentY The y coordinate of the position this frame + */ + public void setCurrentY(double currentY) { + this.currentY = currentY; + } + + /** + * Gets the buffer for storing x coordinates + * @return The buffer for storing x coordinates + */ + public double[] getMouseBufferX() { + return mouseBufferX; + } + + /** + * Gets the buffer for storing y coordinates + * @return The buffer for storing y coordinates + */ + public double[] getMouseBufferY() { + return mouseBufferY; + } + + /** + * Checks whether the mouse is doing a drag input or not + * @return true if the mouse is dragging, false otherwise + */ + public boolean isDragging() { + return dragging; + } + + /** + * Sets whether the mouse is doing a drag input or not + * @param dragging true if the mouse is dragging, false otherwise + */ + public void setDragging(boolean dragging) { + this.dragging = dragging; + } + + /** + * Gets the delta in the x axis between last frame and this frame + * @return The delta in the x axis between last frame and this frame + */ + public double getDeltaX() { + return deltaX; + } + + /** + * Sets the delta in the x axis between last frame and this frame + * @return The delta in the x axis between last frame and this frame + */ + public void setDeltaX(double deltaX) { + this.deltaX = deltaX; + } + + /** + * Gets the delta in the y axis between last frame and this frame + * @return The delta in the y axis between last frame and this frame + */ + public double getDeltaY() { + return deltaY; + } + + /** + * Sets the delta in the y axis between last frame and this frame + * @return The delta in the y axis between last frame and this frame + */ + public void setDeltaY(double deltaY) { + this.deltaY = deltaY; + } + + + + +} diff --git a/src/main/java/electrosphere/controls/categories/ControlCategoryAlwaysOnDebug.java b/src/main/java/electrosphere/controls/categories/ControlCategoryAlwaysOnDebug.java new file mode 100644 index 00000000..b78eead4 --- /dev/null +++ b/src/main/java/electrosphere/controls/categories/ControlCategoryAlwaysOnDebug.java @@ -0,0 +1,52 @@ +package electrosphere.controls.categories; + +import java.util.HashMap; +import java.util.List; + +import org.lwjgl.glfw.GLFW; + +import electrosphere.audio.VirtualAudioSourceManager.VirtualAudioSourceType; +import electrosphere.client.ui.menu.debug.ImGuiWindowMacros; +import electrosphere.controls.Control; +import electrosphere.controls.Control.ControlMethod; +import electrosphere.controls.Control.ControlType; +import electrosphere.controls.ControlHandler; +import electrosphere.controls.MouseState; +import electrosphere.engine.Globals; +import electrosphere.engine.Main; +import electrosphere.engine.assetmanager.AssetDataStrings; +import electrosphere.logger.LoggerInterface; + +public class ControlCategoryAlwaysOnDebug { + + public static final String DEBUG_OPEN_DEBUG_MENU = "openDebugMenu"; + + /** + * Maps the controls + * @param handler + */ + public static void mapControls(ControlHandler handler){ + handler.addControl(DEBUG_OPEN_DEBUG_MENU, new Control(ControlType.KEY, GLFW.GLFW_KEY_F2,false,"Debug Menu","Opens the debug menu")); + } + + /** + * Populates the in-game debug controls list + * @param controlMap + */ + public static void setCallbacks( + HashMap controlMap, + List alwaysOnDebugControlList + ){ + alwaysOnDebugControlList.add(controlMap.get(DEBUG_OPEN_DEBUG_MENU)); + controlMap.get(DEBUG_OPEN_DEBUG_MENU).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + LoggerInterface.loggerEngine.INFO("open debug menu"); + ImGuiWindowMacros.toggleMainDebugMenu(); + //play sound effect + if(Globals.virtualAudioSourceManager != null){ + Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.UI_TONE_CONFIRM_PRIMARY, VirtualAudioSourceType.UI, false); + } + }}); + controlMap.get(DEBUG_OPEN_DEBUG_MENU).setRepeatTimeout(0.5f * Main.targetFrameRate); + } + +} diff --git a/src/main/java/electrosphere/controls/categories/ControlCategoryFreecam.java b/src/main/java/electrosphere/controls/categories/ControlCategoryFreecam.java new file mode 100644 index 00000000..afeb63a1 --- /dev/null +++ b/src/main/java/electrosphere/controls/categories/ControlCategoryFreecam.java @@ -0,0 +1,120 @@ +package electrosphere.controls.categories; + +import java.util.HashMap; +import java.util.List; + +import org.joml.Vector3f; +import org.lwjgl.glfw.GLFW; + +import electrosphere.client.entity.camera.CameraEntityUtils; +import electrosphere.controls.Control; +import electrosphere.controls.Control.ControlMethod; +import electrosphere.controls.Control.ControlType; +import electrosphere.controls.ControlHandler; +import electrosphere.controls.MouseState; +import electrosphere.engine.Globals; +import electrosphere.renderer.ui.events.MouseEvent; + +public class ControlCategoryFreecam { + + public static final String FREECAM_UP = "freecamUp"; + public static final String FREECAM_DOWN = "freecamDown"; + public static final String FREECAM_FORWARD = "freecamForward"; + public static final String FREECAM_BACKWARD = "freecamBackward"; + public static final String FREECAM_LEFT = "freecamLeft"; + public static final String FREECAM_RIGHT = "freecamRight"; + public static final String FREECAM_MOUSE = "freecamMouse"; + + /** + * Maps the controls + * @param handler + */ + public static void mapControls(ControlHandler handler){ + handler.addControl(FREECAM_UP, new Control(ControlType.KEY,GLFW.GLFW_KEY_SPACE,false,"Up","Moves the camera up")); + handler.addControl(FREECAM_DOWN, new Control(ControlType.KEY,GLFW.GLFW_KEY_LEFT_CONTROL,false,"Down","Moves the camera down")); + handler.addControl(FREECAM_FORWARD, new Control(ControlType.KEY,GLFW.GLFW_KEY_W,false,"Forward","Moves the camera forward")); + handler.addControl(FREECAM_BACKWARD, new Control(ControlType.KEY,GLFW.GLFW_KEY_S,false,"Backward","Moves the camera backward")); + handler.addControl(FREECAM_LEFT, new Control(ControlType.KEY,GLFW.GLFW_KEY_A,false,"Left","Moves the camera left")); + handler.addControl(FREECAM_RIGHT, new Control(ControlType.KEY,GLFW.GLFW_KEY_D,false,"Right","Moves the camera right")); + handler.addControl(FREECAM_MOUSE, new Control(ControlType.MOUSE_MOVEMENT,0,false,"","")); + } + + /** + * Populates the in-game debug controls list + * @param controlMap + */ + public static void setCallbacks( + HashMap controlMap, + List freeCameraControlList + ){ + freeCameraControlList.add(controlMap.get(FREECAM_UP)); + controlMap.get(FREECAM_UP).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ + Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + playerCameraCenterPos.add(0,0.1f,0); + CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); + }}); + + + freeCameraControlList.add(controlMap.get(FREECAM_DOWN)); + controlMap.get(FREECAM_DOWN).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ + Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + playerCameraCenterPos.add(0,-0.1f,0); + CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); + }}); + + + freeCameraControlList.add(controlMap.get(FREECAM_FORWARD)); + ControlMethod freeCamForwardCallback = new ControlMethod(){public void execute(MouseState mouseState){ + Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + Vector3f playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); + playerCameraCenterPos.add(new Vector3f(playerCameraEyePos).normalize().mul(-0.1f)); + CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); + }}; + controlMap.get(FREECAM_FORWARD).setOnClick(freeCamForwardCallback); + controlMap.get(FREECAM_FORWARD).setOnRepeat(freeCamForwardCallback); + + freeCameraControlList.add(controlMap.get(FREECAM_BACKWARD)); + ControlMethod freeCamBackwardCallback = new ControlMethod(){public void execute(MouseState mouseState){ + Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + Vector3f playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); + playerCameraCenterPos.add(new Vector3f(playerCameraEyePos).normalize().mul(0.1f)); + CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); + }}; + controlMap.get(FREECAM_BACKWARD).setOnClick(freeCamBackwardCallback); + controlMap.get(FREECAM_BACKWARD).setOnRepeat(freeCamBackwardCallback); + + freeCameraControlList.add(controlMap.get(FREECAM_LEFT)); + ControlMethod freeCamLeftCallback = new ControlMethod(){public void execute(MouseState mouseState){ + Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + Vector3f playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); + Vector3f modifiedVec = new Vector3f(playerCameraEyePos.x,0,playerCameraEyePos.z).rotateY((float)(-90 * Math.PI / 180)).normalize(); + playerCameraCenterPos.add(new Vector3f(modifiedVec).mul(0.1f)); + CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); + }}; + controlMap.get(FREECAM_LEFT).setOnClick(freeCamLeftCallback); + controlMap.get(FREECAM_LEFT).setOnRepeat(freeCamLeftCallback); + + freeCameraControlList.add(controlMap.get(FREECAM_RIGHT)); + ControlMethod freeCamRightCallback = new ControlMethod(){public void execute(MouseState mouseState){ + Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + Vector3f playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); + Vector3f modifiedVec = new Vector3f(playerCameraEyePos.x,0,playerCameraEyePos.z).rotateY((float)(90 * Math.PI / 180)).normalize(); + playerCameraCenterPos.add(new Vector3f(modifiedVec).mul(0.1f)); + CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); + }}; + controlMap.get(FREECAM_RIGHT).setOnClick(freeCamRightCallback); + controlMap.get(FREECAM_RIGHT).setOnRepeat(freeCamRightCallback); + + //terrain controls -- these should have already been defined in the main game controls section + freeCameraControlList.add(controlMap.get(ControlCategoryMainGame.INPUT_CODE_PLACE_TERRAIN)); + freeCameraControlList.add(controlMap.get(ControlCategoryMainGame.INPUT_CODE_REMOVE_TERRAIN)); + + freeCameraControlList.add(controlMap.get(FREECAM_MOUSE)); + controlMap.get(FREECAM_MOUSE).setOnMove(new Control.MouseCallback(){public void execute(MouseState mouseState, MouseEvent event){ + Globals.cameraHandler.handleMouseEvent(event); + }}); + + freeCameraControlList.add(controlMap.get(ControlCategoryMainGame.DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU)); + } + +} diff --git a/src/main/java/electrosphere/controls/categories/ControlCategoryInGameDebug.java b/src/main/java/electrosphere/controls/categories/ControlCategoryInGameDebug.java new file mode 100644 index 00000000..21e17304 --- /dev/null +++ b/src/main/java/electrosphere/controls/categories/ControlCategoryInGameDebug.java @@ -0,0 +1,66 @@ +package electrosphere.controls.categories; + +import java.util.HashMap; +import java.util.List; + +import org.lwjgl.glfw.GLFW; + +import electrosphere.controls.Control; +import electrosphere.controls.Control.ControlMethod; +import electrosphere.controls.Control.ControlType; +import electrosphere.controls.ControlHandler; +import electrosphere.controls.MouseState; +import electrosphere.engine.Globals; +import electrosphere.engine.Main; +import electrosphere.logger.LoggerInterface; +import electrosphere.net.parser.net.message.CharacterMessage; + +/** + * Control callbacks for in-game debug controls + */ +public class ControlCategoryInGameDebug { + + public static final String DEBUG_FRAMESTEP = "framestep"; + public static final String DEBUG_SWAP_EDITOR_MODE = "swapEditorMode"; + + /** + * Maps the controls + * @param handler + */ + public static void mapControls(ControlHandler handler){ + handler.addControl(DEBUG_FRAMESTEP, new Control(ControlType.KEY, GLFW.GLFW_KEY_P,false,"Framesetp","Steps the engine forward one frame")); + handler.addControl(DEBUG_SWAP_EDITOR_MODE, new Control(ControlType.KEY, GLFW.GLFW_KEY_F4,false,"Swap Editor Mode","Swaps to/from the editor entity")); + } + + /** + * Populates the in-game debug controls list + * @param controlMap + */ + public static void setCallbacks( + HashMap controlMap, + List mainGameDebugControlList, + List alwaysOnDebugControlList + ){ + mainGameDebugControlList.add(controlMap.get(DEBUG_FRAMESTEP)); + controlMap.get(DEBUG_FRAMESTEP).setOnRelease(new ControlMethod(){public void execute(MouseState mouseState){ + Main.setFramestep(1); + }}); + controlMap.get(DEBUG_FRAMESTEP).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ + Main.setFramestep(1); + }}); + controlMap.get(DEBUG_FRAMESTEP).setRepeatTimeout(0.5f * Main.targetFrameRate); + // RenderingEngine.incrementOutputFramebuffer(); + + + // + //Swap to/from editor entity + // + alwaysOnDebugControlList.add(controlMap.get(DEBUG_SWAP_EDITOR_MODE)); + controlMap.get(DEBUG_SWAP_EDITOR_MODE).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + LoggerInterface.loggerEngine.INFO("Swap to/from editor entity"); + Globals.clientConnection.queueOutgoingMessage(CharacterMessage.constructEditorSwapMessage()); + }}); + controlMap.get(DEBUG_SWAP_EDITOR_MODE).setRepeatTimeout(0.5f * Main.targetFrameRate); + } + +} diff --git a/src/main/java/electrosphere/controls/categories/ControlCategoryInventory.java b/src/main/java/electrosphere/controls/categories/ControlCategoryInventory.java new file mode 100644 index 00000000..90d74448 --- /dev/null +++ b/src/main/java/electrosphere/controls/categories/ControlCategoryInventory.java @@ -0,0 +1,99 @@ +package electrosphere.controls.categories; + +import java.util.HashMap; +import java.util.List; + +import org.lwjgl.glfw.GLFW; + +import electrosphere.controls.Control; +import electrosphere.controls.Control.ControlMethod; +import electrosphere.controls.Control.ControlType; +import electrosphere.controls.ControlHandler; +import electrosphere.controls.MouseState; +import electrosphere.engine.Globals; +import electrosphere.renderer.ui.events.ClickEvent; +import electrosphere.renderer.ui.events.MouseEvent; + +/** + * Inventory control callbacks + */ +public class ControlCategoryInventory { + + //inventory + 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"; + + /** + * Maps the controls + * @param handler + */ + public static void mapControls(ControlHandler handler){ + handler.addControl(INPUT_CODE_INVENTORY_CLOSE, new Control(ControlType.KEY,GLFW.GLFW_KEY_I,false,"","")); + handler.addControl(INPUT_CODE_INVENTORY_ITEM_MANIPULATE, new Control(ControlType.MOUSE_BUTTON,GLFW.GLFW_MOUSE_BUTTON_1,false,"","")); + handler.addControl(INPUT_CODE_INVENTORY_ITEM_DRAG, new Control(ControlType.MOUSE_MOVEMENT,0,false,"","")); + } + + /** + * Populates the in-game debug controls list + * @param controlMap + */ + public static void setCallbacks( + HashMap controlMap, + List inventoryControlList + ){ + /* + Item manipulation + */ + inventoryControlList.add(controlMap.get(INPUT_CODE_INVENTORY_ITEM_MANIPULATE)); + controlMap.get(INPUT_CODE_INVENTORY_ITEM_MANIPULATE).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + }}); + controlMap.get(INPUT_CODE_INVENTORY_ITEM_MANIPULATE).setOnRelease(new ControlMethod(){public void execute(MouseState mouseState){ + if(mouseState.isDragging()){ + mouseState.setDragging(false); + //fire dragrelease event to elementmanager + Globals.elementService.dragRelease( + (int)mouseState.getCurrentX(), + (int)mouseState.getCurrentY(), + (int)mouseState.getLastX(), + (int)mouseState.getLastY(), + (int)(mouseState.getDeltaX()), + (int)(mouseState.getDeltaY()) + ); + } else { + //fire onclick event to elementmanager + Globals.elementService.click(new ClickEvent((int)mouseState.getCurrentX(),(int)mouseState.getCurrentY(),true,Globals.mouseCallback.getButton(GLFW.GLFW_MOUSE_BUTTON_2))); + } + }}); + /* + item dragging + */ + inventoryControlList.add(controlMap.get(INPUT_CODE_INVENTORY_ITEM_DRAG)); + controlMap.get(INPUT_CODE_INVENTORY_ITEM_DRAG).setOnMove(new Control.MouseCallback(){public void execute(MouseState mouseState, MouseEvent event){ + if(!mouseState.isDragging() && event.getButton1()){ + mouseState.setDragging(true); + //fire dragstart event to elementmanager + Globals.elementService.dragStart( + (int)mouseState.getCurrentX(), + (int)mouseState.getCurrentY(), + (int)mouseState.getLastX(), + (int)mouseState.getLastY(), + (int)(mouseState.getDeltaX()), + (int)(mouseState.getDeltaY()) + ); + } + if(mouseState.isDragging()){ + //fire drag event to elementmanager + Globals.elementService.drag( + (int)mouseState.getCurrentX(), + (int)mouseState.getCurrentY(), + (int)mouseState.getLastX(), + (int)mouseState.getLastY(), + (int)(mouseState.getDeltaX()), + (int)(mouseState.getDeltaY()) + ); + } + }}); + } + +} diff --git a/src/main/java/electrosphere/controls/categories/ControlCategoryMainGame.java b/src/main/java/electrosphere/controls/categories/ControlCategoryMainGame.java new file mode 100644 index 00000000..ac612fad --- /dev/null +++ b/src/main/java/electrosphere/controls/categories/ControlCategoryMainGame.java @@ -0,0 +1,792 @@ +package electrosphere.controls.categories; + +import java.util.HashMap; +import java.util.List; + +import org.joml.Vector3d; +import org.joml.Vector3f; +import org.lwjgl.glfw.GLFW; + +import electrosphere.audio.VirtualAudioSourceManager.VirtualAudioSourceType; +import electrosphere.client.entity.camera.CameraEntityUtils; +import electrosphere.client.entity.crosshair.Crosshair; +import electrosphere.client.item.ItemActions; +import electrosphere.client.terrain.editing.TerrainEditing; +import electrosphere.client.ui.components.PlayerInventoryWindow; +import electrosphere.client.ui.menu.WindowStrings; +import electrosphere.client.ui.menu.WindowUtils; +import electrosphere.client.ui.menu.ingame.MenuGeneratorsInGame; +import electrosphere.collision.CollisionEngine; +import electrosphere.collision.collidable.Collidable; +import electrosphere.controls.Control; +import electrosphere.controls.Control.ControlMethod; +import electrosphere.controls.Control.ControlType; +import electrosphere.controls.ControlHandler; +import electrosphere.controls.ControlHandler.ControlsState; +import electrosphere.controls.MouseState; +import electrosphere.engine.Globals; +import electrosphere.engine.Main; +import electrosphere.engine.assetmanager.AssetDataStrings; +import electrosphere.entity.Entity; +import electrosphere.entity.btree.BehaviorTree; +import electrosphere.entity.state.equip.ClientEquipState; +import electrosphere.entity.state.equip.ClientToolbarState; +import electrosphere.entity.state.inventory.InventoryUtils; +import electrosphere.entity.state.inventory.UnrelationalInventoryState; +import electrosphere.entity.state.movement.editor.ClientEditorMovementTree; +import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree; +import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree.MovementRelativeFacing; +import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree.MovementTreeState; +import electrosphere.entity.state.movement.jump.ClientJumpTree; +import electrosphere.entity.state.movement.sprint.ClientSprintTree; +import electrosphere.entity.state.movement.walk.ClientWalkTree; +import electrosphere.entity.types.common.CommonEntityFlags; +import electrosphere.entity.types.common.CommonEntityUtils; +import electrosphere.entity.types.creature.CreatureUtils; +import electrosphere.game.data.common.interact.InteractionData; +import electrosphere.renderer.ui.elements.Window; +import electrosphere.renderer.ui.events.MouseEvent; +import electrosphere.renderer.ui.events.ScrollEvent; + +/** + * Main game controls + */ +public class ControlCategoryMainGame { + + 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_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_WALK = "walk"; + public static final String INPUT_CODE_SINK = "sink"; + 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 ITEM_SECONDARY = "actionItemSecondary"; + public static final String INPUT_CODE_PLACE_TERRAIN = "placeTerrain"; + public static final String INPUT_CODE_REMOVE_TERRAIN = "removeTerrain"; + public static final String TOOLBAR_SCROLL = "toolbarScroll"; + + /** + * Maps the controls + * @param handler + */ + public static void mapControls(ControlHandler handler){ + handler.addControl(INPUT_CODE_CAMERA_ROTATION, new Control(ControlType.MOUSE_MOVEMENT,0,false,"","")); + handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, new Control(ControlType.KEY,GLFW.GLFW_KEY_W,false,"Move Foward","Moves the player forward")); + handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, new Control(ControlType.KEY,GLFW.GLFW_KEY_S,false,"Move Backward","Moves the player backward")); + handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, new Control(ControlType.KEY,GLFW.GLFW_KEY_F24,false,"Move Left","Moves the player left")); + handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, new Control(ControlType.KEY,GLFW.GLFW_KEY_F24,false,"Move Right","Moves the player right")); + handler.addControl(DATA_STRING_INPUT_CODE_STRAFE_LEFT, new Control(ControlType.KEY,GLFW.GLFW_KEY_A,false,"Strafe Left","Strafes the player left")); + handler.addControl(DATA_STRING_INPUT_CODE_STRAFE_RIGHT, new Control(ControlType.KEY,GLFW.GLFW_KEY_D,false,"Strafe Right","Strafes the player right")); + handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP, new Control(ControlType.KEY,GLFW.GLFW_KEY_SPACE,false,"Jump","Jumps")); + handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FALL, new Control(ControlType.KEY,GLFW.GLFW_KEY_LEFT_CONTROL,false,"Fall","Lowers the camera")); + handler.addControl(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY, new Control(ControlType.MOUSE_BUTTON,GLFW.GLFW_MOUSE_BUTTON_LEFT,false,"Attack","Attacks")); + handler.addControl(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU, new Control(ControlType.KEY,GLFW.GLFW_KEY_ESCAPE,false,"Main Menu","Opens the main menu while in game")); + handler.addControl(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR, new Control(ControlType.KEY,GLFW.GLFW_KEY_CAPS_LOCK,false,"Lock On","Locks the camera onto the target")); + handler.addControl(INPUT_CODE_SPRINT, new Control(ControlType.KEY,GLFW.GLFW_KEY_LEFT_SHIFT,false,"Sprint (hold)","Causes the player to sprint")); + handler.addControl(INPUT_CODE_WALK, new Control(ControlType.KEY,GLFW.GLFW_KEY_LEFT_ALT,false,"Walk (hold)","Causes the player to walk")); + handler.addControl(INPUT_CODE_SINK, new Control(ControlType.KEY,GLFW.GLFW_KEY_LEFT_CONTROL,true,"Sink","Sinks the entity")); + handler.addControl(INPUT_CODE_INTERACT, new Control(ControlType.KEY,GLFW.GLFW_KEY_E,false,"Interact","Interacts with whatever is targeted currently")); + handler.addControl(INPUT_CODE_DROP, new Control(ControlType.KEY,GLFW.GLFW_KEY_Y,false,"Drop","Drops the currently equipped item")); + handler.addControl(INPUT_CODE_INVENTORY_OPEN, new Control(ControlType.KEY,GLFW.GLFW_KEY_TAB,false,"Inventory","Opens the player's inventory")); + handler.addControl(ITEM_SECONDARY, new Control(ControlType.MOUSE_BUTTON,GLFW.GLFW_MOUSE_BUTTON_RIGHT,false,"Secondary","Uses the secondary equipped item")); + handler.addControl(TOOLBAR_SCROLL, new Control(ControlType.MOUSE_SCROLL,0,false,"","")); + handler.addControl(INPUT_CODE_PLACE_TERRAIN, new Control(ControlType.KEY,GLFW.GLFW_KEY_T,false,"Place Terrain","Places terrain")); + handler.addControl(INPUT_CODE_REMOVE_TERRAIN, new Control(ControlType.KEY,GLFW.GLFW_KEY_Y,false,"Remove Terrain","Removes terrain")); + } + + /** + * Populates the control callbacks + * @param controlMap The control map + * @param mainGameControlList The main game control list + * @param inventoryControlList The inventory control list + */ + public static void setCallbacks( + HashMap controlMap, + List mainGameControlList, + List inventoryControlList + ){ + /* + Camera rotation + */ + mainGameControlList.add(controlMap.get(INPUT_CODE_CAMERA_ROTATION)); + controlMap.get(INPUT_CODE_CAMERA_ROTATION).setOnMove(new Control.MouseCallback(){public void execute(MouseState mouseState, MouseEvent event){ + Globals.cameraHandler.handleMouseEvent(event); + }}); + /* + Move forward + */ + mainGameControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD)); + controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + if(controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).isState()){ + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + groundTree.start(MovementRelativeFacing.FORWARD_LEFT); + } else if(controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).isState()){ + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + groundTree.start(MovementRelativeFacing.FORWARD_RIGHT); + } else { + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + groundTree.start(MovementRelativeFacing.FORWARD); + } + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); + } + } + }}); + controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + if(controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).isState()){ + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + groundTree.start(MovementRelativeFacing.FORWARD_LEFT); + } else if(controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).isState()){ + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + groundTree.start(MovementRelativeFacing.FORWARD_RIGHT); + } else { + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + groundTree.start(MovementRelativeFacing.FORWARD); + } + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); + } + } + }}); + controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).setOnRelease(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + groundTree.slowdown(); + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + clientEditorMovementTree.slowdown(); + } + } + }}); + /* + Move backward + */ + mainGameControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD)); + controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + if(controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).isState()){ + CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(3.0/4.0*Math.PI).normalize()); + groundTree.start(MovementRelativeFacing.BACKWARD_LEFT); + } else if(controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).isState()){ + CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(5.0/4.0*Math.PI).normalize()); + groundTree.start(MovementRelativeFacing.BACKWARD_RIGHT); + } else { + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + groundTree.start(MovementRelativeFacing.BACKWARD); + } + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.BACKWARD); + } + } + }}); + controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + if(controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).isState()){ + CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(3.0/4.0*Math.PI).normalize()); + groundTree.start(MovementRelativeFacing.BACKWARD_LEFT); + } else if(controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).isState()){ + CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(5.0/4.0*Math.PI).normalize()); + groundTree.start(MovementRelativeFacing.BACKWARD_RIGHT); + } else { + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + groundTree.start(MovementRelativeFacing.BACKWARD); + } + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.BACKWARD); + } + } + }}); + controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).setOnRelease(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + groundTree.slowdown(); + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + clientEditorMovementTree.slowdown(); + } + } + }}); + /* + move left + */ + mainGameControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT)); + controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + if( + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) && + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.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()); + groundTree.start(MovementRelativeFacing.FORWARD); + } + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI/2.0).normalize()); + clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); + } + } + }}); + controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + if( + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) && + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.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()); + groundTree.start(MovementRelativeFacing.FORWARD); + } + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI/2.0).normalize()); + clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); + } + } + }}); + controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).setOnRelease(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + groundTree.slowdown(); + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + clientEditorMovementTree.slowdown(); + } + } + }}); + /* + move right + */ + mainGameControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT)); + controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + if( + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) && + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.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()); + groundTree.start(MovementRelativeFacing.FORWARD); + } + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(-Math.PI/2.0).normalize()); + clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); + } + } + }}); + controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + if( + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) && + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.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()); + groundTree.start(MovementRelativeFacing.FORWARD); + } + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(-Math.PI/2.0).normalize()); + clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); + } + } + }}); + controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).setOnRelease(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + groundTree.slowdown(); + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + clientEditorMovementTree.slowdown(); + } + } + }}); + + /* + Move up + */ + + /* + Move down + */ + + /* + strafe left + */ + mainGameControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT)); + controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + if( + (groundTree.getState()==MovementTreeState.IDLE || groundTree.getState()==MovementTreeState.SLOWDOWN) && + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) && + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue())) + ){ + groundTree.start(MovementRelativeFacing.LEFT); + } + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.LEFT); + } + } + }}); + controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + if( + (groundTree.getState()==MovementTreeState.IDLE || groundTree.getState()==MovementTreeState.SLOWDOWN) && + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) && + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue())) + ){ + groundTree.start(MovementRelativeFacing.LEFT); + } + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.LEFT); + } + } + }}); + controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).setOnRelease(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + groundTree.slowdown(); + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + clientEditorMovementTree.slowdown(); + } + } + }}); + /* + strafe right + */ + mainGameControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT)); + controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + if( + (groundTree.getState()==MovementTreeState.IDLE || groundTree.getState()==MovementTreeState.SLOWDOWN) && + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) && + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue())) + ){ + groundTree.start(MovementRelativeFacing.RIGHT); + } + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.RIGHT); + } + } + }}); + controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + if( + (groundTree.getState()==MovementTreeState.IDLE || groundTree.getState()==MovementTreeState.SLOWDOWN) && + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) && + (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue())) + ){ + groundTree.start(MovementRelativeFacing.RIGHT); + } + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + CreatureUtils.setFacingVector(Globals.playerEntity, CameraEntityUtils.getFacingVec(Globals.playerCamera)); + clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.RIGHT); + } + } + }}); + controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_RIGHT).setOnRelease(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); + if(movementTree instanceof ClientGroundMovementTree){ + ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; + groundTree.slowdown(); + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + clientEditorMovementTree.slowdown(); + } + } + }}); + /* + Jump + DATA_STRING_INPUT_CODE_MOVEMENT_JUMP + */ + mainGameControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP)); + controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + ClientJumpTree jumpTree = ClientJumpTree.getClientJumpTree(Globals.playerEntity); + if(jumpTree != null){ + jumpTree.start(); + } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.UP); + } + } + }}); + controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP).setOnRelease(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + clientEditorMovementTree.slowdown(); + } + } + }}); + /** + * Sink + */ + mainGameControlList.add(controlMap.get(INPUT_CODE_SINK)); + controlMap.get(INPUT_CODE_SINK).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.DOWN); + } + } + }}); + controlMap.get(INPUT_CODE_SINK).setOnRelease(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ + ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); + clientEditorMovementTree.slowdown(); + } + } + }}); + /* + Sprint + */ + mainGameControlList.add(controlMap.get(INPUT_CODE_SPRINT)); + controlMap.get(INPUT_CODE_SPRINT).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + ClientSprintTree sprintTree = ClientSprintTree.getClientSprintTree(Globals.playerEntity); + if(sprintTree != null){ + sprintTree.start(); + } + } + }}); + controlMap.get(INPUT_CODE_SPRINT).setOnRelease(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + ClientSprintTree sprintTree = ClientSprintTree.getClientSprintTree(Globals.playerEntity); + if(sprintTree != null){ + sprintTree.interrupt(); + } + } + }}); + + /** + * Walk + */ + mainGameControlList.add(controlMap.get(INPUT_CODE_WALK)); + controlMap.get(INPUT_CODE_WALK).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null && ClientWalkTree.getClientWalkTree(Globals.playerEntity) != null){ + ClientWalkTree clientWalkTree = ClientWalkTree.getClientWalkTree(Globals.playerEntity); + clientWalkTree.start(); + } + }}); + controlMap.get(INPUT_CODE_WALK).setOnRelease(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null && ClientWalkTree.getClientWalkTree(Globals.playerEntity) != null){ + ClientWalkTree clientWalkTree = ClientWalkTree.getClientWalkTree(Globals.playerEntity); + clientWalkTree.interrupt(); + } + }}); + + + /* + Attack + */ + mainGameControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY)); + controlMap.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + ItemActions.attemptPrimaryItemAction(); + }}); + controlMap.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ + ItemActions.repeatPrimaryItemAction(); + }}); + controlMap.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).setOnRelease(new ControlMethod(){public void execute(MouseState mouseState){ + ItemActions.releasePrimaryItemAction(); + }}); + controlMap.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).setRepeatTimeout(0.5f * Main.targetFrameRate); + + /** + * Secondary item actions + */ + mainGameControlList.add(controlMap.get(ITEM_SECONDARY)); + controlMap.get(ITEM_SECONDARY).setOnPress(new ControlMethod() {public void execute(MouseState mouseState) { + ItemActions.attemptSecondaryItemAction(); + }}); + controlMap.get(ITEM_SECONDARY).setOnRelease(new ControlMethod() {public void execute(MouseState mouseState) { + ItemActions.releaseSecondaryItemAction(); + }}); + + /** + * Toolbar scrolling + */ + mainGameControlList.add(controlMap.get(TOOLBAR_SCROLL)); + controlMap.get(TOOLBAR_SCROLL).setOnScroll(new Control.ScrollCallback() {public void execute(MouseState mouseState, ScrollEvent scrollEvent){ + if(Globals.playerEntity != null && ClientToolbarState.getClientToolbarState(Globals.playerEntity) != null){ + ClientToolbarState clientToolbarState = ClientToolbarState.getClientToolbarState(Globals.playerEntity); + if(scrollEvent.getScrollAmount() > 0){ + clientToolbarState.attemptChangeSelection(clientToolbarState.getSelectedSlot() - 1); + } else { + clientToolbarState.attemptChangeSelection(clientToolbarState.getSelectedSlot() + 1); + } + } + }}); + + /* + Interact + */ + mainGameControlList.add(controlMap.get(INPUT_CODE_INTERACT)); + controlMap.get(INPUT_CODE_INTERACT).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null && Globals.playerCamera != null){ + Entity camera = Globals.playerCamera; + CollisionEngine collisionEngine = Globals.clientSceneWrapper.getCollisionEngine(); + Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(camera)).mul(-1.0); + Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(camera)); + Entity target = collisionEngine.rayCast(centerPos, eyePos, CollisionEngine.DEFAULT_INTERACT_DISTANCE, Collidable.MASK_NO_TERRAIN); + if(target != null && CommonEntityFlags.isInteractable(target)){ + InteractionData interactionData = CommonEntityUtils.getCommonData(target).getInteraction(); + switch(interactionData.getOnInteract()){ + case InteractionData.ON_INTERACT_TARGET: { + WindowUtils.openInteractionMenu(interactionData.getWindowTarget()); + } break; + default: { + throw new Error("Unhandled interaction signal " + interactionData.getOnInteract()); + } + } + } else if(ClientEquipState.hasEquipState(Globals.playerEntity) && Crosshair.hasTarget()){ + if(InventoryUtils.hasNaturalInventory(Globals.playerEntity)){ + InventoryUtils.clientAttemptStoreItem(Globals.playerEntity, Crosshair.getTarget()); + } + } + } + }}); + + /* + Drop + */ + mainGameControlList.add(controlMap.get(INPUT_CODE_DROP)); + controlMap.get(INPUT_CODE_DROP).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.playerEntity != null){ + if(ClientEquipState.hasEquipState(Globals.playerEntity)){ + UnrelationalInventoryState inventory = InventoryUtils.getNaturalInventory(Globals.playerEntity); + if(inventory.getItems().size() > 0){ + Entity itemToDrop = inventory.getItems().get(0); + InventoryUtils.clientAttemptEjectItem(Globals.playerEntity,itemToDrop); + } + } + } + }}); + + + /* + Lock on crosshair + */ + mainGameControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR)); + controlMap.get(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + if(Crosshair.hasTarget()){ + Crosshair.setCrosshairActive(true); + } + }}); + controlMap.get(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR).setOnRelease(new ControlMethod(){public void execute(MouseState mouseState){ + if(Crosshair.getCrosshairActive()){ + Crosshair.setCrosshairActive(false); + } + }}); + + + /* + Main menu dialog toggle + */ + mainGameControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU)); + controlMap.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).setOnClick(new ControlMethod(){public void execute(MouseState mouseState){ + // Globals.elementManager.registerWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, MenuGenerators.createInGameMainMenu()); + // Globals.controlHandler.hintUpdateControlState(ControlsState.IN_GAME_MAIN_MENU); + + // Window mainMenuWindow = new Window(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); + Window mainMenuInGame = MenuGeneratorsInGame.createInGameMainMenu(); + // mainMenuWindow.addChild(mainMenuInGame); + Globals.elementService.registerWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, mainMenuInGame); + WindowUtils.recursiveSetVisible(Globals.elementService.getWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN), true); + Globals.elementService.focusFirstElement(); + Globals.controlHandler.hintUpdateControlState(ControlsState.IN_GAME_MAIN_MENU); + //play sound effect + if(Globals.virtualAudioSourceManager != null){ + Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.UI_TONE_CONFIRM_PRIMARY, VirtualAudioSourceType.UI, false); + } + Globals.renderingEngine.getPostProcessingPipeline().setApplyBlur(true); + }}); + controlMap.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).setRepeatTimeout(0.5f * Main.targetFrameRate); + + /* + Open inventory + */ + mainGameControlList.add(controlMap.get(INPUT_CODE_INVENTORY_OPEN)); + inventoryControlList.add(controlMap.get(INPUT_CODE_INVENTORY_OPEN)); + controlMap.get(INPUT_CODE_INVENTORY_OPEN).setOnClick(new ControlMethod(){public void execute(MouseState mouseState){ + if(Globals.elementService.getWindow(WindowStrings.WINDOW_CHARACTER) == null){ + //create window + Window mainMenuWindow = PlayerInventoryWindow.createPlayerInventoryWindow(Globals.playerEntity); + //register + Globals.elementService.registerWindow(WindowStrings.WINDOW_CHARACTER, mainMenuWindow); + //make visible + WindowUtils.recursiveSetVisible(WindowStrings.WINDOW_CHARACTER, true); + //controls + Globals.controlHandler.hintUpdateControlState(ControlsState.INVENTORY); + //play sound effect + if(Globals.virtualAudioSourceManager != null){ + Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.UI_SFX_INVENTORY_OPEN, VirtualAudioSourceType.UI, false); + } + Globals.renderingEngine.getPostProcessingPipeline().setApplyBlur(true); + // + Globals.openInventoriesCount++; + } else if(InventoryUtils.hasNaturalInventory(Globals.playerEntity) && Globals.elementService.getWindow(WindowStrings.WINDOW_CHARACTER) != null){ + Globals.elementService.closeWindow(WindowStrings.WINDOW_CHARACTER); + Globals.renderingEngine.getPostProcessingPipeline().setApplyBlur(false); + if(Globals.virtualAudioSourceManager != null){ + Globals.virtualAudioSourceManager.createVirtualAudioSource(AssetDataStrings.UI_SFX_INVENTORY_CLOSE, VirtualAudioSourceType.UI, false); + } + } + }}); + controlMap.get(INPUT_CODE_INVENTORY_OPEN).setRepeatTimeout(0.5f * Main.targetFrameRate); + + /** + * Places terrain + */ + mainGameControlList.add(controlMap.get(INPUT_CODE_PLACE_TERRAIN)); + controlMap.get(INPUT_CODE_PLACE_TERRAIN).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + CollisionEngine collisionEngine = Globals.clientSceneWrapper.getCollisionEngine(); + Entity camera = Globals.playerCamera; + if( + collisionEngine != null && + camera != null + ){ + Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(camera)); + Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(camera)); + Vector3d cursorPos = collisionEngine.rayCastPosition(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1.0), CollisionEngine.DEFAULT_INTERACT_DISTANCE); + if(Globals.clientSelectedVoxelType != null){ + TerrainEditing.editTerrain(cursorPos, 1.1f, Globals.clientSelectedVoxelType.getId(), 0.1f); + } + } + }}); + controlMap.get(INPUT_CODE_PLACE_TERRAIN).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ + CollisionEngine collisionEngine = Globals.clientSceneWrapper.getCollisionEngine(); + Entity camera = Globals.playerCamera; + if( + collisionEngine != null && + camera != null + ){ + Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(camera)); + Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(camera)); + Vector3d cursorPos = collisionEngine.rayCastPosition(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1.0), CollisionEngine.DEFAULT_INTERACT_DISTANCE); + if(Globals.clientSelectedVoxelType != null){ + TerrainEditing.editTerrain(cursorPos, 1.1f, Globals.clientSelectedVoxelType.getId(), 0.1f); + } + } + }}); + controlMap.get(INPUT_CODE_PLACE_TERRAIN).setRepeatTimeout(0.2f * Main.targetFrameRate); + + mainGameControlList.add(controlMap.get(INPUT_CODE_REMOVE_TERRAIN)); + controlMap.get(INPUT_CODE_REMOVE_TERRAIN).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + CollisionEngine collisionEngine = Globals.clientSceneWrapper.getCollisionEngine(); + Entity camera = Globals.playerCamera; + if( + collisionEngine != null && + camera != null + ){ + Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(camera)); + Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(camera)); + Vector3d cursorPos = collisionEngine.rayCastPosition(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1.0), CollisionEngine.DEFAULT_INTERACT_DISTANCE); + TerrainEditing.editTerrain(cursorPos, 1.1f, 1, -0.01f); + } + }}); + controlMap.get(INPUT_CODE_REMOVE_TERRAIN).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ + CollisionEngine collisionEngine = Globals.clientSceneWrapper.getCollisionEngine(); + Entity camera = Globals.playerCamera; + if( + collisionEngine != null && + camera != null + ){ + Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(camera)); + Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(camera)); + Vector3d cursorPos = collisionEngine.rayCastPosition(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1.0), CollisionEngine.DEFAULT_INTERACT_DISTANCE); + TerrainEditing.editTerrain(cursorPos, 1.1f, 1, -0.01f); + } + }}); + controlMap.get(INPUT_CODE_REMOVE_TERRAIN).setRepeatTimeout(0.2f * Main.targetFrameRate); + } + +} diff --git a/src/main/java/electrosphere/controls/categories/ControlCategoryMenuNav.java b/src/main/java/electrosphere/controls/categories/ControlCategoryMenuNav.java new file mode 100644 index 00000000..17c64032 --- /dev/null +++ b/src/main/java/electrosphere/controls/categories/ControlCategoryMenuNav.java @@ -0,0 +1,224 @@ +package electrosphere.controls.categories; + +import java.util.HashMap; +import java.util.List; + +import org.lwjgl.glfw.GLFW; + +import electrosphere.controls.Control; +import electrosphere.controls.Control.ControlMethod; +import electrosphere.controls.Control.ControlType; +import electrosphere.controls.ControlHandler; +import electrosphere.controls.MouseState; +import electrosphere.engine.Globals; +import electrosphere.engine.Main; +import electrosphere.renderer.ui.events.ClickEvent; +import electrosphere.renderer.ui.events.MenuEvent; +import electrosphere.renderer.ui.events.MenuEvent.MenuEventType; +import electrosphere.renderer.ui.events.MouseEvent; +import electrosphere.renderer.ui.events.ScrollEvent; +import electrosphere.util.FileUtils; + +public class ControlCategoryMenuNav { + + 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 MENU_MOUSE_MOVE = "menuMouseMove"; + public static final String MENU_SCROLL = "menuScroll"; + public static final String MENU_DRAG_MANIPULATE = "menuDragManipulate"; + public static final String MENU_DRAG_START = "menuDragStart"; + public static final String MENU_CAPTURE_SCREEN = "menuCaptureScreen"; + + /** + * Maps the controls + * @param handler + */ + public static void mapControls(ControlHandler handler){ + handler.addControl(DATA_STRING_INPUT_CODE_MENU_NAVIGATE_FORWARD, new Control(ControlType.KEY,GLFW.GLFW_KEY_DOWN,false,"","")); + handler.addControl(DATA_STRING_INPUT_CODE_MENU_NAVIGATE_BACKWARDS, new Control(ControlType.KEY,GLFW.GLFW_KEY_UP,false,"","")); + handler.addControl(DATA_STRING_INPUT_CODE_MENU_INCREMENT, new Control(ControlType.KEY,GLFW.GLFW_KEY_RIGHT,false,"","")); + handler.addControl(DATA_STRING_INPUT_CODE_MENU_DECREMENT, new Control(ControlType.KEY,GLFW.GLFW_KEY_LEFT,false,"","")); + handler.addControl(DATA_STRING_INPUT_CODE_MENU_SELECT, new Control(ControlType.KEY,GLFW.GLFW_KEY_ENTER,false,"","")); + handler.addControl(DATA_STRING_INPUT_CODE_MENU_BACKOUT, new Control(ControlType.KEY,GLFW.GLFW_KEY_ESCAPE,false,"","")); + handler.addControl(MENU_MOUSE_MOVE, new Control(ControlType.MOUSE_MOVEMENT,0,false,"","")); + handler.addControl(INPUT_CODE_MENU_MOUSE_PRIMARY, new Control(ControlType.MOUSE_BUTTON,GLFW.GLFW_MOUSE_BUTTON_LEFT,false,"","")); + handler.addControl(MENU_SCROLL, new Control(ControlType.MOUSE_SCROLL,0,false,"","")); + handler.addControl(MENU_DRAG_START, new Control(ControlType.MOUSE_MOVEMENT,0,false,"","")); + handler.addControl(MENU_CAPTURE_SCREEN, new Control(ControlType.KEY,GLFW.GLFW_KEY_F4,true,"Screenshot","Takes a screenshot of the engine")); + handler.addControl(MENU_DRAG_MANIPULATE, new Control(ControlType.MOUSE_BUTTON,GLFW.GLFW_MOUSE_BUTTON_1,false,"","")); + } + + /** + * Populates the menu navigation controls list + * @param controlMap + */ + public static void setCallbacks( + HashMap controlMap, + List menuNavigationControlList, + List mainGameDebugControlList, + List inventoryControlList + ){ + menuNavigationControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_MENU_NAVIGATE_FORWARD)); + controlMap.get(DATA_STRING_INPUT_CODE_MENU_NAVIGATE_FORWARD).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + // Globals.currentMenu.incrementMenuOption(); + Globals.elementService.focusNextElement(); + }}); + + menuNavigationControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_MENU_NAVIGATE_BACKWARDS)); + controlMap.get(DATA_STRING_INPUT_CODE_MENU_NAVIGATE_BACKWARDS).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + // Globals.currentMenu.decrementMenuOption(); + Globals.elementService.focusPreviousElement(); + }}); + + + + //Incrementing a menu element + menuNavigationControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT)); + controlMap.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + Globals.elementService.fireEvent( + new MenuEvent(MenuEventType.INCREMENT), + Globals.elementService.getFocusedElement().getAbsoluteX(), + Globals.elementService.getFocusedElement().getAbsoluteY() + ); + }}); + controlMap.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ + Globals.elementService.fireEvent( + new MenuEvent(MenuEventType.INCREMENT), + Globals.elementService.getFocusedElement().getAbsoluteX(), + Globals.elementService.getFocusedElement().getAbsoluteY() + ); + }}); + controlMap.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).setRepeatTimeout(0.5f * Main.targetFrameRate); + + //moving the mouse + inventoryControlList.add(controlMap.get(MENU_MOUSE_MOVE)); + menuNavigationControlList.add(controlMap.get(MENU_MOUSE_MOVE)); + controlMap.get(MENU_MOUSE_MOVE).setOnMove(new Control.MouseCallback(){public void execute(MouseState mouseState, MouseEvent mouseEvent){ + Globals.elementService.updateHover(mouseEvent.getCurrentX(), mouseEvent.getCurrentY()); + }}); + + //scrolling the mouse + menuNavigationControlList.add(controlMap.get(MENU_SCROLL)); + controlMap.get(MENU_SCROLL).setOnScroll(new Control.ScrollCallback() {public void execute(MouseState mouseState, ScrollEvent scrollEvent){ + Globals.elementService.fireEvent(scrollEvent, GLFW.GLFW_KEY_X, GLFW.GLFW_KEY_Z); + }}); + + //dragging the cursor + menuNavigationControlList.add(controlMap.get(MENU_DRAG_MANIPULATE)); + controlMap.get(MENU_DRAG_MANIPULATE).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + }}); + controlMap.get(MENU_DRAG_MANIPULATE).setOnRelease(new ControlMethod(){public void execute(MouseState mouseState){ + if(mouseState.isDragging()){ + mouseState.setDragging(false); + //fire dragrelease event to elementmanager + Globals.elementService.dragRelease( + (int)mouseState.getCurrentX(), + (int)mouseState.getCurrentY(), + (int)mouseState.getLastX(), + (int)mouseState.getLastY(), + (int)(mouseState.getDeltaX()), + (int)(mouseState.getDeltaY()) + ); + } + }}); + /* + item dragging + */ + menuNavigationControlList.add(controlMap.get(MENU_DRAG_START)); + controlMap.get(MENU_DRAG_START).setOnMove(new Control.MouseCallback(){public void execute(MouseState mouseState, MouseEvent event){ + if(!mouseState.isDragging() && event.getButton1()){ + mouseState.setDragging(true); + //fire dragstart event to elementmanager + Globals.elementService.dragStart( + (int)mouseState.getCurrentX(), + (int)mouseState.getCurrentY(), + (int)mouseState.getLastX(), + (int)mouseState.getLastY(), + (int)(mouseState.getDeltaX()), + (int)(mouseState.getDeltaY()) + ); + } + if(mouseState.isDragging()){ + //fire drag event to elementmanager + Globals.elementService.drag( + (int)mouseState.getCurrentX(), + (int)mouseState.getCurrentY(), + (int)mouseState.getLastX(), + (int)mouseState.getLastY(), + (int)(mouseState.getDeltaX()), + (int)(mouseState.getDeltaY()) + ); + } + }}); + + /** + Screenshots + */ + menuNavigationControlList.add(controlMap.get(MENU_CAPTURE_SCREEN)); + controlMap.get(MENU_CAPTURE_SCREEN).setOnPress(new Control.ControlMethod() {public void execute(MouseState mouseState){ + FileUtils.writeBufferedImage( + Globals.renderingEngine.defaultFramebuffer.getPixels(Globals.renderingEngine.getOpenGLState()), + "Screenshots/" + System.currentTimeMillis() + ".png" + ); + }}); + + + + + //Decrementing a menu element + menuNavigationControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT)); + controlMap.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + Globals.elementService.fireEvent( + new MenuEvent(MenuEventType.DECREMENT), + Globals.elementService.getFocusedElement().getAbsoluteX(), + Globals.elementService.getFocusedElement().getAbsoluteY() + ); + }}); + controlMap.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ + Globals.elementService.fireEvent( + new MenuEvent(MenuEventType.DECREMENT), + Globals.elementService.getFocusedElement().getAbsoluteX(), + Globals.elementService.getFocusedElement().getAbsoluteY() + ); + }}); + controlMap.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).setRepeatTimeout(0.5f * Main.targetFrameRate); + + + + + menuNavigationControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_MENU_SELECT)); + controlMap.get(DATA_STRING_INPUT_CODE_MENU_SELECT).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + Globals.elementService.click(new ClickEvent( + Globals.elementService.getFocusedElement().getAbsoluteX() + 1, + Globals.elementService.getFocusedElement().getAbsoluteY() + 1, + true, + Globals.mouseCallback.getButton(GLFW.GLFW_MOUSE_BUTTON_2) + )); + }}); + + menuNavigationControlList.add(controlMap.get(INPUT_CODE_MENU_MOUSE_PRIMARY)); + mainGameDebugControlList.add(controlMap.get(INPUT_CODE_MENU_MOUSE_PRIMARY)); + controlMap.get(INPUT_CODE_MENU_MOUSE_PRIMARY).setOnClick(new ControlMethod(){public void execute(MouseState mouseState){ + Globals.elementService.click(new ClickEvent( + (int)mouseState.getCurrentX(), + (int)mouseState.getCurrentY(), + true, + Globals.mouseCallback.getButton(GLFW.GLFW_MOUSE_BUTTON_2) + )); + }}); + controlMap.get(INPUT_CODE_MENU_MOUSE_PRIMARY).setRepeatTimeout(0.5f * Main.targetFrameRate); + + menuNavigationControlList.add(controlMap.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT)); + controlMap.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).setOnClick(new ControlMethod(){public void execute(MouseState mouseState){ + Globals.elementService.navigateBackwards(); + }}); + controlMap.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).setRepeatTimeout(0.5f * Main.targetFrameRate); + } + + +} diff --git a/src/main/java/electrosphere/controls/categories/ControlCategoryTyping.java b/src/main/java/electrosphere/controls/categories/ControlCategoryTyping.java new file mode 100644 index 00000000..6938253c --- /dev/null +++ b/src/main/java/electrosphere/controls/categories/ControlCategoryTyping.java @@ -0,0 +1,300 @@ +package electrosphere.controls.categories; + +import java.util.HashMap; +import java.util.List; + +import org.lwjgl.glfw.GLFW; + +import electrosphere.controls.Control; +import electrosphere.controls.ControlHandler; +import electrosphere.controls.Control.ControlMethod; +import electrosphere.controls.Control.ControlType; +import electrosphere.controls.MouseState; +import electrosphere.engine.Globals; +import electrosphere.logger.LoggerInterface; +import electrosphere.renderer.ui.events.KeyboardEvent; + +public class ControlCategoryTyping { + + public static final String MENU_TYPE_BACKSPACE = "menuTypeBackspace"; + public static final String MENU_TYPE_0 = "menuType0"; + public static final String MENU_TYPE_1 = "menuType1"; + public static final String MENU_TYPE_2 = "menuType2"; + public static final String MENU_TYPE_3 = "menuType3"; + public static final String MENU_TYPE_4 = "menuType4"; + public static final String MENU_TYPE_5 = "menuType5"; + public static final String MENU_TYPE_6 = "menuType6"; + public static final String MENU_TYPE_7 = "menuType7"; + public static final String MENU_TYPE_8 = "menuType8"; + public static final String MENU_TYPE_9 = "menuType9"; + public static final String MENU_TYPE_PERIOD = "menuType."; + public static final String MENU_TYPE_A = "menuTypeA"; + public static final String MENU_TYPE_B = "menuTypeB"; + public static final String MENU_TYPE_C = "menuTypeC"; + public static final String MENU_TYPE_D = "menuTypeD"; + public static final String MENU_TYPE_E = "menuTypeE"; + public static final String MENU_TYPE_F = "menuTypeF"; + public static final String MENU_TYPE_G = "menuTypeG"; + public static final String MENU_TYPE_H = "menuTypeH"; + public static final String MENU_TYPE_I = "menuTypeI"; + public static final String MENU_TYPE_J = "menuTypeJ"; + public static final String MENU_TYPE_K = "menuTypeK"; + public static final String MENU_TYPE_L = "menuTypeL"; + public static final String MENU_TYPE_M = "menuTypeM"; + public static final String MENU_TYPE_N = "menuTypeN"; + public static final String MENU_TYPE_O = "menuTypeO"; + public static final String MENU_TYPE_P = "menuTypeP"; + public static final String MENU_TYPE_Q = "menuTypeQ"; + public static final String MENU_TYPE_R = "menuTypeR"; + public static final String MENU_TYPE_S = "menuTypeS"; + public static final String MENU_TYPE_T = "menuTypeT"; + public static final String MENU_TYPE_U = "menuTypeU"; + public static final String MENU_TYPE_V = "menuTypeV"; + public static final String MENU_TYPE_W = "menuTypeW"; + public static final String MENU_TYPE_X = "menuTypeX"; + public static final String MENU_TYPE_Y = "menuTypeY"; + public static final String MENU_TYPE_Z = "menuTypeZ"; + public static final String MENU_TYPE_FORWARD_SLASH = "menuTypeForwardSlash"; + + + public static void mapControls(ControlHandler handler){ + /* + Map the typing controls + */ + handler.addControl(MENU_TYPE_BACKSPACE, new Control(ControlType.KEY,GLFW.GLFW_KEY_BACKSPACE,false,"","")); + handler.addControl(MENU_TYPE_0, new Control(ControlType.KEY,GLFW.GLFW_KEY_0,false,"","")); + handler.addControl(MENU_TYPE_1, new Control(ControlType.KEY,GLFW.GLFW_KEY_1,false,"","")); + handler.addControl(MENU_TYPE_2, new Control(ControlType.KEY,GLFW.GLFW_KEY_2,false,"","")); + handler.addControl(MENU_TYPE_3, new Control(ControlType.KEY,GLFW.GLFW_KEY_3,false,"","")); + handler.addControl(MENU_TYPE_4, new Control(ControlType.KEY,GLFW.GLFW_KEY_4,false,"","")); + handler.addControl(MENU_TYPE_5, new Control(ControlType.KEY,GLFW.GLFW_KEY_5,false,"","")); + handler.addControl(MENU_TYPE_6, new Control(ControlType.KEY,GLFW.GLFW_KEY_6,false,"","")); + handler.addControl(MENU_TYPE_7, new Control(ControlType.KEY,GLFW.GLFW_KEY_7,false,"","")); + handler.addControl(MENU_TYPE_8, new Control(ControlType.KEY,GLFW.GLFW_KEY_8,false,"","")); + handler.addControl(MENU_TYPE_9, new Control(ControlType.KEY,GLFW.GLFW_KEY_9,false,"","")); + handler.addControl(MENU_TYPE_PERIOD, new Control(ControlType.KEY,GLFW.GLFW_KEY_PERIOD,false,"","")); + handler.addControl(MENU_TYPE_A, new Control(ControlType.KEY,GLFW.GLFW_KEY_A,false,"","")); + handler.addControl(MENU_TYPE_B, new Control(ControlType.KEY,GLFW.GLFW_KEY_B,false,"","")); + handler.addControl(MENU_TYPE_C, new Control(ControlType.KEY,GLFW.GLFW_KEY_C,false,"","")); + handler.addControl(MENU_TYPE_D, new Control(ControlType.KEY,GLFW.GLFW_KEY_D,false,"","")); + handler.addControl(MENU_TYPE_E, new Control(ControlType.KEY,GLFW.GLFW_KEY_E,false,"","")); + handler.addControl(MENU_TYPE_F, new Control(ControlType.KEY,GLFW.GLFW_KEY_F,false,"","")); + handler.addControl(MENU_TYPE_G, new Control(ControlType.KEY,GLFW.GLFW_KEY_G,false,"","")); + handler.addControl(MENU_TYPE_H, new Control(ControlType.KEY,GLFW.GLFW_KEY_H,false,"","")); + handler.addControl(MENU_TYPE_I, new Control(ControlType.KEY,GLFW.GLFW_KEY_I,false,"","")); + handler.addControl(MENU_TYPE_J, new Control(ControlType.KEY,GLFW.GLFW_KEY_J,false,"","")); + handler.addControl(MENU_TYPE_K, new Control(ControlType.KEY,GLFW.GLFW_KEY_K,false,"","")); + handler.addControl(MENU_TYPE_L, new Control(ControlType.KEY,GLFW.GLFW_KEY_L,false,"","")); + handler.addControl(MENU_TYPE_M, new Control(ControlType.KEY,GLFW.GLFW_KEY_M,false,"","")); + handler.addControl(MENU_TYPE_N, new Control(ControlType.KEY,GLFW.GLFW_KEY_N,false,"","")); + handler.addControl(MENU_TYPE_O, new Control(ControlType.KEY,GLFW.GLFW_KEY_O,false,"","")); + handler.addControl(MENU_TYPE_P, new Control(ControlType.KEY,GLFW.GLFW_KEY_P,false,"","")); + handler.addControl(MENU_TYPE_Q, new Control(ControlType.KEY,GLFW.GLFW_KEY_Q,false,"","")); + handler.addControl(MENU_TYPE_R, new Control(ControlType.KEY,GLFW.GLFW_KEY_R,false,"","")); + handler.addControl(MENU_TYPE_S, new Control(ControlType.KEY,GLFW.GLFW_KEY_S,false,"","")); + handler.addControl(MENU_TYPE_T, new Control(ControlType.KEY,GLFW.GLFW_KEY_T,false,"","")); + handler.addControl(MENU_TYPE_U, new Control(ControlType.KEY,GLFW.GLFW_KEY_U,false,"","")); + handler.addControl(MENU_TYPE_V, new Control(ControlType.KEY,GLFW.GLFW_KEY_V,false,"","")); + handler.addControl(MENU_TYPE_W, new Control(ControlType.KEY,GLFW.GLFW_KEY_W,false,"","")); + handler.addControl(MENU_TYPE_X, new Control(ControlType.KEY,GLFW.GLFW_KEY_X,false,"","")); + handler.addControl(MENU_TYPE_Y, new Control(ControlType.KEY,GLFW.GLFW_KEY_Y,false,"","")); + handler.addControl(MENU_TYPE_Z, new Control(ControlType.KEY,GLFW.GLFW_KEY_Z,false,"","")); + handler.addControl(MENU_TYPE_FORWARD_SLASH, new Control(ControlType.KEY,GLFW.GLFW_KEY_SLASH,false,"","")); + } + + /** + * Populates the typing controls list + * @param controlMap + */ + public static void setCallbacks( + HashMap controlMap, + List typingControlList + ){ + String[] typeKeybinds = { + MENU_TYPE_BACKSPACE, + MENU_TYPE_0, + MENU_TYPE_1, + MENU_TYPE_2, + MENU_TYPE_3, + MENU_TYPE_4, + MENU_TYPE_5, + MENU_TYPE_6, + MENU_TYPE_7, + MENU_TYPE_8, + MENU_TYPE_9, + MENU_TYPE_PERIOD, + MENU_TYPE_A, + MENU_TYPE_B, + MENU_TYPE_C, + MENU_TYPE_D, + MENU_TYPE_E, + MENU_TYPE_F, + MENU_TYPE_G, + MENU_TYPE_H, + MENU_TYPE_I, + MENU_TYPE_J, + MENU_TYPE_K, + MENU_TYPE_L, + MENU_TYPE_M, + MENU_TYPE_N, + MENU_TYPE_O, + MENU_TYPE_P, + MENU_TYPE_Q, + MENU_TYPE_R, + MENU_TYPE_S, + MENU_TYPE_T, + MENU_TYPE_U, + MENU_TYPE_V, + MENU_TYPE_W, + MENU_TYPE_X, + MENU_TYPE_Y, + MENU_TYPE_Z, + MENU_TYPE_FORWARD_SLASH, + }; + for(String currentKey : typeKeybinds){ + typingControlList.add(controlMap.get(currentKey)); + controlMap.get(currentKey).setOnPress(new ControlMethod(){public void execute(MouseState mouseState){ + Globals.elementService.fireEventNoPosition( + new KeyboardEvent(convertKeycodeToName(controlMap.get(currentKey).getKeyValue())), + Globals.elementService.getFocusedElement() + ); + }}); + } + } + + /** + * Converts a keycode to a string containing a code related to the keycode (ie "A" for 65, "Escape" for 256, etc) + * @param code The keycode + * @return The corresponding string code + */ + 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; + } + +} diff --git a/src/main/java/electrosphere/entity/EntityCreationUtils.java b/src/main/java/electrosphere/entity/EntityCreationUtils.java index fcb92dd0..ac2f5144 100644 --- a/src/main/java/electrosphere/entity/EntityCreationUtils.java +++ b/src/main/java/electrosphere/entity/EntityCreationUtils.java @@ -55,8 +55,6 @@ public class EntityCreationUtils { ServerBehaviorTreeUtils.registerEntity(rVal); if(Globals.entityDataCellMapper.getEntityDataCell(rVal) == null){ - Globals.entityDataCellMapper.registerEntity(rVal, cell); - ServerDataCell mapping = Globals.entityDataCellMapper.getEntityDataCell(rVal); throw new Error("Failed to map entity to cell!"); } diff --git a/src/main/java/electrosphere/entity/EntityDataStrings.java b/src/main/java/electrosphere/entity/EntityDataStrings.java index 2f44873a..74644788 100644 --- a/src/main/java/electrosphere/entity/EntityDataStrings.java +++ b/src/main/java/electrosphere/entity/EntityDataStrings.java @@ -214,6 +214,11 @@ public class EntityDataStrings { public static final String ATTACK_MOVE_TYPE_BOW_TWO_HAND = "RANGED_WEAPON_BOW_TWO_HAND"; public static final String ATTACK_MOVE_UNARMED = "ATTACK_MOVE_UNARMED"; + /** + * Common flags + */ + public static final String INTERACTABLE = "interactable"; + /** * Ambient audio */ diff --git a/src/main/java/electrosphere/entity/types/common/CommonEntityFlags.java b/src/main/java/electrosphere/entity/types/common/CommonEntityFlags.java new file mode 100644 index 00000000..4146b23c --- /dev/null +++ b/src/main/java/electrosphere/entity/types/common/CommonEntityFlags.java @@ -0,0 +1,47 @@ +package electrosphere.entity.types.common; + +import electrosphere.entity.Entity; +import electrosphere.entity.EntityDataStrings; + +/** + * Handling for common entity flags + */ +public class CommonEntityFlags { + + /** + * Checks if the entity should be serialized + * @param entity The entity + * @return true if should be serialized, false otherwise + */ + public static boolean shouldBeSerialized(Entity entity){ + return entity.containsKey(EntityDataStrings.SHOULD_SERIALIZE); + } + + /** + * Checks if the entity should be synchronized between server and client + * @param entity The entity + * @return true if should be synchronized, false otherwise + */ + public static boolean shouldBeSynchronized(Entity entity){ + return entity.containsKey(EntityDataStrings.SHOULD_SYNCHRONIZE); + } + + /** + * Gets whether the entity is interactable or not + * @param entity The entity + * @return true if it is interactable, false otherwise + */ + public static boolean isInteractable(Entity entity){ + return entity.containsKey(EntityDataStrings.INTERACTABLE) && (boolean)entity.getData(EntityDataStrings.INTERACTABLE); + } + + /** + * Sets whether this entity is interactable or not + * @param entity The entity + * @param isInteractable true if it is interactable, false otherwise + */ + public static void setIsInteractable(Entity entity, boolean isInteractable){ + entity.putData(EntityDataStrings.INTERACTABLE, isInteractable); + } + +} diff --git a/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java b/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java index c14fbccd..33c00a1e 100644 --- a/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java +++ b/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java @@ -267,6 +267,15 @@ public class CommonEntityUtils { } } + // + // + // Interaction Logic + // + // + if(rawType.getInteraction() != null){ + CommonEntityFlags.setIsInteractable(entity, true); + } + // // // Light generation @@ -562,6 +571,15 @@ public class CommonEntityUtils { } } } + + // + // + // Interaction Logic + // + // + if(rawType.getInteraction() != null){ + CommonEntityFlags.setIsInteractable(entity, true); + } // // @@ -874,22 +892,4 @@ public class CommonEntityUtils { entity.putData(EntityDataStrings.ENTITY_SUBTYPE, subtype); } - /** - * Checks if the entity should be serialized - * @param entity The entity - * @return true if should be serialized, false otherwise - */ - public static boolean shouldBeSerialized(Entity entity){ - return entity.containsKey(EntityDataStrings.SHOULD_SERIALIZE); - } - - /** - * Checks if the entity should be synchronized between server and client - * @param entity The entity - * @return true if should be synchronized, false otherwise - */ - public static boolean shouldBeSynchronized(Entity entity){ - return entity.containsKey(EntityDataStrings.SHOULD_SYNCHRONIZE); - } - } diff --git a/src/main/java/electrosphere/game/data/collidable/CollidableTemplate.java b/src/main/java/electrosphere/game/data/collidable/CollidableTemplate.java index 325e39bb..ff30071c 100644 --- a/src/main/java/electrosphere/game/data/collidable/CollidableTemplate.java +++ b/src/main/java/electrosphere/game/data/collidable/CollidableTemplate.java @@ -122,6 +122,32 @@ public class CollidableTemplate { public boolean isAngularlyStatic(){ return this.angularlyStatic; } + + public void setDimension1(float dimension1) { + this.dimension1 = dimension1; + } + + public void setDimension2(float dimension2) { + this.dimension2 = dimension2; + } + + public void setDimension3(float dimension3) { + this.dimension3 = dimension3; + } + + public void setOffsetX(float offsetX) { + this.offsetX = offsetX; + } + + public void setOffsetY(float offsetY) { + this.offsetY = offsetY; + } + + public void setOffsetZ(float offsetZ) { + this.offsetZ = offsetZ; + } + + diff --git a/src/main/java/electrosphere/game/data/common/CommonEntityType.java b/src/main/java/electrosphere/game/data/common/CommonEntityType.java index a13f448e..27ee5d34 100644 --- a/src/main/java/electrosphere/game/data/common/CommonEntityType.java +++ b/src/main/java/electrosphere/game/data/common/CommonEntityType.java @@ -5,6 +5,7 @@ import java.util.List; import electrosphere.game.data.collidable.CollidableTemplate; import electrosphere.game.data.collidable.HitboxData; import electrosphere.game.data.common.camera.CameraData; +import electrosphere.game.data.common.interact.InteractionData; import electrosphere.game.data.common.item.SpawnItemDescription; import electrosphere.game.data.common.life.HealthSystem; import electrosphere.game.data.common.light.PointLightDescription; @@ -144,6 +145,11 @@ public class CommonEntityType { */ SpawnItemDescription spawnItem; + /** + * The behavior when this entity is interacted with + */ + InteractionData interaction; + /** * Gets the id for this creature type * @return The id @@ -367,6 +373,24 @@ public class CommonEntityType { public SpawnItemDescription getSpawnItem(){ return this.spawnItem; } + + /** + * Gets the behavior when this entity is interacted with + * @return The behavior when this entity is interacted with + */ + public InteractionData getInteraction() { + return interaction; + } + + /** + * Sets the behavior when this entity is interacted with + * @return The behavior when this entity is interacted with + */ + public void setInteraction(InteractionData interaction) { + this.interaction = interaction; + } + + } diff --git a/src/main/java/electrosphere/game/data/common/interact/InteractionData.java b/src/main/java/electrosphere/game/data/common/interact/InteractionData.java new file mode 100644 index 00000000..7a87d03e --- /dev/null +++ b/src/main/java/electrosphere/game/data/common/interact/InteractionData.java @@ -0,0 +1,41 @@ +package electrosphere.game.data.common.interact; + +/** + * Controls handling when interacting with this entity + */ +public class InteractionData { + + /** + * Pulls up a menu on interaction + */ + public static final String ON_INTERACT_TARGET = "menu"; + + /** + * The function to run on interaction + */ + String onInteract; + + /** + * The window to open on interaction + */ + String windowTarget; + + /** + * Gets the function to run on interaction + * @return The function to run on interaction + */ + public String getOnInteract() { + return onInteract; + } + + /** + * Gets the window to open on interaction + * @return The window to open on interaction + */ + public String getWindowTarget(){ + return windowTarget; + } + + + +} diff --git a/src/main/java/electrosphere/game/data/item/Item.java b/src/main/java/electrosphere/game/data/item/Item.java index f3afd337..0c2ff995 100644 --- a/src/main/java/electrosphere/game/data/item/Item.java +++ b/src/main/java/electrosphere/game/data/item/Item.java @@ -78,7 +78,7 @@ public class Item extends CommonEntityType { Item rVal = new Item(); - rVal.setId("SPAWN_" + objectData.getId()); + rVal.setId(objectData.getId()); if(description.getItemIcon() != null){ diff --git a/src/main/java/electrosphere/game/data/item/ItemDataMap.java b/src/main/java/electrosphere/game/data/item/ItemDataMap.java index cbb1e37a..d827680c 100644 --- a/src/main/java/electrosphere/game/data/item/ItemDataMap.java +++ b/src/main/java/electrosphere/game/data/item/ItemDataMap.java @@ -29,6 +29,9 @@ public class ItemDataMap { * @param type The item data */ public void putType(String id, Item type){ + if(idItemMap.containsKey(id)){ + throw new Error("Registering item id that already exists! " + id + " " + type + " " + idItemMap.get(id)); + } idItemMap.put(id,type); } diff --git a/src/test/java/electrosphere/test/testutils/InputAPI.java b/src/test/java/electrosphere/test/testutils/InputAPI.java deleted file mode 100644 index 9e7c6a01..00000000 --- a/src/test/java/electrosphere/test/testutils/InputAPI.java +++ /dev/null @@ -1,34 +0,0 @@ -package electrosphere.test.testutils; - -import electrosphere.engine.Globals; - -/** - * Used to programmatically send input signals as if a user had - */ -public class InputAPI { - - /** - * Simulates clicking a control - * @param controlName The name of the control - */ - public static void simulateClick(String controlName){ - Globals.controlHandler.getControl(controlName).onClick(); - } - - /** - * Simulates pressing a control - * @param controlName The name of the control - */ - public static void simulatePress(String controlName){ - Globals.controlHandler.getControl(controlName).onPress(); - } - - /** - * Simulates releasing a control - * @param controlName The name of the control - */ - public static void simulateRelease(String controlName){ - Globals.controlHandler.getControl(controlName).onRelease(); - } - -}