Add interaction usage data and functionality
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-11-14 19:49:31 -05:00
parent e1ec69c230
commit 64a3628316
32 changed files with 2718 additions and 1676 deletions

View File

@ -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": {

View File

@ -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

View File

@ -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();

View File

@ -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));
}
});
}

View File

@ -46,4 +46,9 @@ public class WindowStrings {
*/
public static final String TOOLTIP_WINDOW = "tooltipWindow";
/**
* The crafting window
*/
public static final String CRAFTING = "crafting";
}

View File

@ -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);
}
}
}
}

View File

@ -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();
}

View File

@ -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();
}
}
}

View File

@ -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;
}
}

View File

@ -643,9 +643,10 @@ public class CollisionEngine {
*/
public Entity rayCast(Vector3d start, Vector3d direction, double length, List<String> 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<String> 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);

View File

@ -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());

View File

@ -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<String> 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

View File

@ -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);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -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;
}
}

View File

@ -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<String, Control> controlMap,
List<Control> 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);
}
}

View File

@ -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<String, Control> controlMap,
List<Control> 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));
}
}

View File

@ -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<String, Control> controlMap,
List<Control> mainGameDebugControlList,
List<Control> 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);
}
}

View File

@ -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<String, Control> controlMap,
List<Control> 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())
);
}
}});
}
}

View File

@ -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<String, Control> controlMap,
List<Control> mainGameControlList,
List<Control> 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);
}
}

View File

@ -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<String, Control> controlMap,
List<Control> menuNavigationControlList,
List<Control> mainGameDebugControlList,
List<Control> 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);
}
}

View File

@ -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<String, Control> controlMap,
List<Control> 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;
}
}

View File

@ -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!");
}

View File

@ -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
*/

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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){

View File

@ -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);
}

View File

@ -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();
}
}