Basic ui is working! :D

This commit is contained in:
austin 2021-06-03 17:40:30 -04:00
parent bde5a77131
commit 607abd392c
18 changed files with 1052 additions and 183 deletions

View File

@ -13,12 +13,24 @@ import electrosphere.util.Utilities;
import java.util.HashMap;
import java.util.List;
import org.joml.Vector3f;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_0;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_1;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_2;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_3;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_4;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_5;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_6;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_7;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_8;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_9;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_A;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_BACKSPACE;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_D;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_DOWN;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_ENTER;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_CONTROL;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_PERIOD;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_S;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_UP;
@ -45,7 +57,22 @@ public class ControlHandler {
public static final String DATA_STRING_INPUT_CODE_MENU_BACKOUT = "menuBackout";
enum ControlsState {
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE = "menuTypeBackspace";
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_0 = "menuType0";
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_1 = "menuType1";
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_2 = "menuType2";
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_3 = "menuType3";
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_4 = "menuType4";
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_5 = "menuType5";
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_6 = "menuType6";
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_7 = "menuType7";
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_8 = "menuType8";
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_9 = "menuType9";
public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD = "menuType.";
public static enum ControlsState {
TITLE_PAGE,
TITLE_MENU,
MAIN_GAME,
@ -89,7 +116,7 @@ public class ControlHandler {
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_FALL, false);
/*
Map the controls
Map the menu navigation controls
*/
handler.addControl(DATA_STRING_INPUT_CODE_MENU_INCREMENT, GLFW_KEY_DOWN);
handler.addControl(DATA_STRING_INPUT_CODE_MENU_DECREMENT, GLFW_KEY_UP);
@ -104,6 +131,39 @@ public class ControlHandler {
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_SELECT, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_BACKOUT, false);
/*
Map the typing controls
*/
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE, GLFW_KEY_BACKSPACE);
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_0, GLFW_KEY_0);
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_1, GLFW_KEY_1);
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_2, GLFW_KEY_2);
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_3, GLFW_KEY_3);
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_4, GLFW_KEY_4);
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_5, GLFW_KEY_5);
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_6, GLFW_KEY_6);
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_7, GLFW_KEY_7);
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_8, GLFW_KEY_8);
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_9, GLFW_KEY_9);
handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD, GLFW_KEY_PERIOD);
/*
Set their states to false
*/
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_0, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_1, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_2, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_3, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_4, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_5, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_6, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_7, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_8, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_9, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD, false);
/*
set state
*/
@ -122,98 +182,7 @@ public class ControlHandler {
case MAIN_GAME:
if(Globals.playerCharacter != null){
MovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
/*
Move forward
*/
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD)) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize());
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, true);
Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
Globals.playerCharacter.getId(),
position.x,
position.y,
position.z
);
Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD) == true){
movementTree.slowdown();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, false);
}
}
/*
Move backward
*/
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD)) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(cameraEyeVector.x,0,cameraEyeVector.z).normalize());
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD) == true){
movementTree.slowdown();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, false);
}
}
/*
Move left
*/
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT)) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY((float)(90 * Math.PI / 180)).normalize());
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT) == true){
movementTree.slowdown();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, false);
}
}
/*
Move right
*/
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT)) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY((float)(-90 * Math.PI / 180)).normalize());
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT) == true){
movementTree.slowdown();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, false);
}
}
/*
Move up
*/
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP) && glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP)) == GLFW_PRESS){
EntityUtils.getEntityPosition(Globals.playerCharacter).add(new Vector3f(0,0.6f,0).mul(1f));
}
/*
Move down
*/
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FALL) && glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FALL)) == GLFW_PRESS){
EntityUtils.getEntityPosition(Globals.playerCharacter).add(new Vector3f(0,-0.6f,0).mul(1f));
}
}
pollMainGameControls();
break;
@ -222,51 +191,182 @@ public class ControlHandler {
case TITLE_MENU:
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MENU_INCREMENT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT)) == GLFW_PRESS){
controlsState.put(DATA_STRING_INPUT_CODE_MENU_INCREMENT, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT) == true){
Globals.currentMenu.incrementMenuOption();
}
controlsState.put(DATA_STRING_INPUT_CODE_MENU_INCREMENT, false);
}
}
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MENU_DECREMENT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT)) == GLFW_PRESS){
controlsState.put(DATA_STRING_INPUT_CODE_MENU_DECREMENT, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT) == true){
Globals.currentMenu.decrementMenuOption();
}
controlsState.put(DATA_STRING_INPUT_CODE_MENU_DECREMENT, false);
}
}
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MENU_SELECT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MENU_SELECT)) == GLFW_PRESS){
controlsState.put(DATA_STRING_INPUT_CODE_MENU_SELECT, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MENU_SELECT) == true){
MenuTransition.selectOption(Globals.currentMenu);
}
controlsState.put(DATA_STRING_INPUT_CODE_MENU_SELECT, false);
}
}
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MENU_BACKOUT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT)) == GLFW_PRESS){
controlsState.put(DATA_STRING_INPUT_CODE_MENU_BACKOUT, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT) == true){
MenuTransition.backout(Globals.currentMenu);
}
controlsState.put(DATA_STRING_INPUT_CODE_MENU_BACKOUT, false);
}
}
pollMenuNavigationControls();
/*
Typing..
*/
pollTypingControls();
break;
}
}
public void pollMainGameControls(){
if(Globals.playerCharacter != null){
MovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
/*
Move forward
*/
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD)) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize());
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, true);
Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
Globals.playerCharacter.getId(),
position.x,
position.y,
position.z
);
Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD) == true){
movementTree.slowdown();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, false);
}
}
/*
Move backward
*/
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD)) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(cameraEyeVector.x,0,cameraEyeVector.z).normalize());
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD) == true){
movementTree.slowdown();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, false);
}
}
/*
Move left
*/
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT)) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY((float)(90 * Math.PI / 180)).normalize());
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT) == true){
movementTree.slowdown();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, false);
}
}
/*
Move right
*/
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT)) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY((float)(-90 * Math.PI / 180)).normalize());
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT) == true){
movementTree.slowdown();
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, false);
}
}
/*
Move up
*/
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP) && glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP)) == GLFW_PRESS){
EntityUtils.getEntityPosition(Globals.playerCharacter).add(new Vector3f(0,0.6f,0).mul(1f));
}
/*
Move down
*/
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FALL) && glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FALL)) == GLFW_PRESS){
EntityUtils.getEntityPosition(Globals.playerCharacter).add(new Vector3f(0,-0.6f,0).mul(1f));
}
}
}
public void pollMenuNavigationControls(){
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MENU_INCREMENT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT)) == GLFW_PRESS){
controlsState.put(DATA_STRING_INPUT_CODE_MENU_INCREMENT, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT) == true){
Globals.currentMenu.incrementMenuOption();
}
controlsState.put(DATA_STRING_INPUT_CODE_MENU_INCREMENT, false);
}
}
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MENU_DECREMENT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT)) == GLFW_PRESS){
controlsState.put(DATA_STRING_INPUT_CODE_MENU_DECREMENT, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT) == true){
Globals.currentMenu.decrementMenuOption();
}
controlsState.put(DATA_STRING_INPUT_CODE_MENU_DECREMENT, false);
}
}
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MENU_SELECT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MENU_SELECT)) == GLFW_PRESS){
controlsState.put(DATA_STRING_INPUT_CODE_MENU_SELECT, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MENU_SELECT) == true){
MenuTransition.selectOption(Globals.currentMenu);
}
controlsState.put(DATA_STRING_INPUT_CODE_MENU_SELECT, false);
}
}
if(controlsMap.containsKey(DATA_STRING_INPUT_CODE_MENU_BACKOUT)){
if(glfwGetKey(Globals.window, controlsMap.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT)) == GLFW_PRESS){
controlsState.put(DATA_STRING_INPUT_CODE_MENU_BACKOUT, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT) == true){
MenuTransition.backout(Globals.currentMenu);
}
controlsState.put(DATA_STRING_INPUT_CODE_MENU_BACKOUT, false);
}
}
}
public void pollTypingControls(){
String[] typeKeybinds = {
DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE,
DATA_STRING_INPUT_CODE_MENU_TYPE_0,
DATA_STRING_INPUT_CODE_MENU_TYPE_1,
DATA_STRING_INPUT_CODE_MENU_TYPE_2,
DATA_STRING_INPUT_CODE_MENU_TYPE_3,
DATA_STRING_INPUT_CODE_MENU_TYPE_4,
DATA_STRING_INPUT_CODE_MENU_TYPE_5,
DATA_STRING_INPUT_CODE_MENU_TYPE_6,
DATA_STRING_INPUT_CODE_MENU_TYPE_7,
DATA_STRING_INPUT_CODE_MENU_TYPE_8,
DATA_STRING_INPUT_CODE_MENU_TYPE_9,
DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD,
};
for(String currentKey : typeKeybinds){
if(glfwGetKey(Globals.window, controlsMap.get(currentKey)) == GLFW_PRESS){
controlsState.put(currentKey, true);
} else {
if(controlsState.get(currentKey) == true){
MenuTransition.menuType(Globals.currentMenu,currentKey);
}
controlsState.put(currentKey, false);
}
}
}
public Integer getControl(String controlName){
return controlsMap.get(controlName);
}

View File

@ -1,6 +1,7 @@
package electrosphere.game.cell;
import electrosphere.game.terrain.TerrainManager;
import electrosphere.main.Globals;
import electrosphere.renderer.ShaderProgram;
import java.util.Arrays;
import org.joml.Vector3f;
@ -54,7 +55,7 @@ public class DrawCellManager {
cellX = transformRealSpaceToCellSpace(realX);
cellY = transformRealSpaceToCellSpace(realY);
program = ShaderProgram.smart_assemble_shader(false, true);
program = Globals.defaultMeshShader;
}
public int getCellX(){
@ -324,12 +325,12 @@ public class DrawCellManager {
}
public void update(){
if(containsUpdateableCell()){
updateCellModel();
if(containsInvalidCell()){
updateInvalidCell();
} else if(containsUndrawableCell()){
makeCellDrawable();
} else if(containsInvalidCell()){
updateInvalidCell();
} else if(containsUpdateableCell()){
updateCellModel();
}
}

View File

@ -1,5 +1,6 @@
package electrosphere.game.state;
import electrosphere.controls.ControlHandler;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
@ -9,11 +10,16 @@ import electrosphere.game.terrain.TerrainManager;
import electrosphere.main.Globals;
import static electrosphere.main.Globals.loadingBox;
import electrosphere.menu.MenuUtils;
import electrosphere.net.NetUtils;
import electrosphere.net.client.ClientNetworking;
import electrosphere.net.server.Server;
import electrosphere.renderer.Model;
import electrosphere.renderer.RenderUtils;
import electrosphere.renderer.assetmanager.AssetDataStrings;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.joml.Vector3f;
/**
@ -26,6 +32,9 @@ public class LoadingThread extends Thread {
public static final int LOAD_MAIN_GAME = 1;
public static final int LOAD_ARENA = 2;
boolean FLAG_INIT_SERVER = false;
boolean FLAG_INIT_CLIENT = false;
int threadType;
Semaphore lock;
@ -68,14 +77,20 @@ public class LoadingThread extends Thread {
case LOAD_MAIN_GAME:
loadingBox.setDraw(true);
//initialize the terrain manager (server only)
initTerrainManager();
//initialize the server thread (server only)
initServerThread();
if(FLAG_INIT_SERVER){
initServerThread();
}
//initialize the client thread (client)
initClientThread();
if(FLAG_INIT_CLIENT){
initClientThread();
}
//initialize the cell manager (client)
initCellManager();
@ -83,12 +98,18 @@ public class LoadingThread extends Thread {
//initialize the basic graphical entities of the world (skybox, camera)
initWorldBaseGraphicalEntities();
loadingBox.setDraw(false);
Globals.RENDER_FLAG_RENDER_SHADOW_MAP = true;
Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT = true;
Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER = true;
Globals.RENDER_FLAG_RENDER_UI = true;
Globals.RENDER_FLAG_RENDER_BLACK_BACKGROUND = false;
System.out.println("Finished loading");
SimulationState.simulationState = SimulationStateMachine.MAIN_SIMULATION;
Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.MAIN_GAME);
break;
@ -100,8 +121,39 @@ public class LoadingThread extends Thread {
case LOAD_ARENA:
loadingBox.setDraw(true);
SimulationState.simulationState = SimulationStateMachine.ARENA_SIMULATION;
//initialize the terrain manager (server only)
initTerrainManager();
//initialize the server thread (server only)
if(FLAG_INIT_SERVER){
initServerThread();
}
//initialize the client thread (client)
if(FLAG_INIT_CLIENT){
initClientThread();
}
//initialize the cell manager (client)
initCellManager();
//initialize the basic graphical entities of the world (skybox, camera)
initWorldBaseGraphicalEntities();
loadingBox.setDraw(false);
Globals.RENDER_FLAG_RENDER_SHADOW_MAP = true;
Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT = true;
Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER = true;
Globals.RENDER_FLAG_RENDER_UI = true;
Globals.RENDER_FLAG_RENDER_BLACK_BACKGROUND = false;
System.out.println("Finished loading");
SimulationState.simulationState = SimulationStateMachine.MAIN_SIMULATION;
Globals.controlHandler.setHandlerState(ControlHandler.ControlsState.MAIN_GAME);
break;
@ -178,7 +230,7 @@ public class LoadingThread extends Thread {
//start server networking
Thread serverThread = null;
if(Globals.mainConfig.runServer){
Globals.server = new Server(42536);
Globals.server = new Server(NetUtils.getPort());
serverThread = new Thread(Globals.server);
serverThread.start();
}
@ -190,7 +242,7 @@ public class LoadingThread extends Thread {
//start client networking
Thread clientThread = null;
if(Globals.mainConfig.runClient){
Globals.clientConnection = new ClientNetworking(Globals.mainConfig.serverAddress,42536);
Globals.clientConnection = new ClientNetworking(NetUtils.getAddress(),NetUtils.getPort());
clientThread = new Thread(Globals.clientConnection);
clientThread.start();
}
@ -204,11 +256,21 @@ public class LoadingThread extends Thread {
Globals.drawCellManager = new DrawCellManager(Globals.terrainManager, Globals.spawnPoint.x, Globals.spawnPoint.z);
while(Globals.drawCellManager.containsInvalidCell()){
Globals.drawCellManager.updateInvalidCell();
// Globals.drawCellManager.updateInvalidCell();
try {
TimeUnit.MILLISECONDS.sleep(10);
} catch (InterruptedException ex) {
}
// System.out.println("invalid cell");
}
while(Globals.drawCellManager.containsUndrawableCell()){
Globals.drawCellManager.makeCellDrawable();
// Globals.drawCellManager.makeCellDrawable();
try {
TimeUnit.MILLISECONDS.sleep(10);
} catch (InterruptedException ex) {
}
// System.out.println("undrawable");
}
}
@ -219,9 +281,8 @@ public class LoadingThread extends Thread {
Skybox
*/
Model skyboxModel = RenderUtils.createSkyboxModel(null);
String skyboxModelPath = Globals.assetManager.registerModel(skyboxModel);
Entity skyboxEntity = EntityUtils.spawnDrawableEntity(skyboxModelPath);
Model skyboxModel = Globals.assetManager.fetchModel(AssetDataStrings.ASSET_STRING_SKYBOX_BASIC);
Entity skyboxEntity = EntityUtils.spawnDrawableEntity(AssetDataStrings.ASSET_STRING_SKYBOX_BASIC);
EntityUtils.getEntityScale(skyboxEntity).mul(100);
@ -243,6 +304,14 @@ public class LoadingThread extends Thread {
}
public void setFLAG_INIT_SERVER(boolean FLAG_INIT_SERVER) {
this.FLAG_INIT_SERVER = FLAG_INIT_SERVER;
}
public void setFLAG_INIT_CLIENT(boolean FLAG_INIT_CLIENT) {
this.FLAG_INIT_CLIENT = FLAG_INIT_CLIENT;
}

View File

@ -22,6 +22,8 @@ import electrosphere.menu.Menu;
import electrosphere.net.client.ClientNetworking;
import electrosphere.net.server.Server;
import electrosphere.renderer.ModelUtils;
import electrosphere.renderer.RenderUtils;
import electrosphere.renderer.ShaderProgram;
import electrosphere.renderer.assetmanager.AssetDataStrings;
import electrosphere.renderer.assetmanager.AssetManager;
import electrosphere.renderer.ui.WidgetManager;
@ -125,6 +127,8 @@ public class Globals {
public static TextureMap textureMapDefault;
public static ShaderProgram defaultMeshShader;
public static Menu currentMenu;
@ -138,7 +142,7 @@ public class Globals {
//terrain manager
public static TerrainManager terrainManager;
public static Vector3f spawnPoint = new Vector3f(0,0,0);
public static Vector3f spawnPoint = new Vector3f(1000,0,1000);
//manages all models loaded into memory
public static AssetManager assetManager;
@ -214,12 +218,15 @@ public class Globals {
//create default lights
lightDirectionalDefault = new DirectionalLight(new Vector3f(0,-1f,0));
assetManager.registerModelToSpecificString(ModelUtils.createBitmapDisplay(), AssetDataStrings.ASSET_STRING_BITMAP_FONT);
RawFontMap fontMap = Utilities.loadObjectFromBakedJsonFile("/Textures/Fonts/fontMap.json", RawFontMap.class);
RawFontMap fontMap = Utilities.loadObjectFromBakedJsonFile("/Textures/Fonts/myFontMap.json", RawFontMap.class);
FontUtils.setFontDataMap(fontMap);
//black texture for backgrouns
blackTexture = new Texture("Textures/b1.png");
//loading box
loadingBox = WidgetUtils.createVerticallyAlignedTextBox(520, 100, 50, 7, 1, "LOADING", true);
//init default shaderProgram
defaultMeshShader = ShaderProgram.smart_assemble_shader(false,true);
assetManager.registerModelToSpecificString(RenderUtils.createSkyboxModel(null), AssetDataStrings.ASSET_STRING_SKYBOX_BASIC);
}
static void initEntityTypeMap(){

View File

@ -220,7 +220,7 @@ public class Main {
///
/// C L I E N T C E L L M A N A G E R
///
if(SimulationState.simulationState == SimulationStateMachine.MAIN_SIMULATION){
if(Globals.drawCellManager != null){
if(Globals.playerCharacter != null){
newPlayerCharacterPosition = EntityUtils.getEntityPosition(Globals.playerCharacter);
}

View File

@ -15,7 +15,9 @@ public class Menu {
public enum MenuType {
TITLE_MENU,
MULTIPLAYER_MENU,
IP_MENU,
OPTIONS_MAIN_MENU,
}
MenuType type;
@ -54,7 +56,7 @@ public class Menu {
if(option>=optionMax){
option = 0;
}
setMenuOptionColor(option,new Vector3f(1.0f,1.0f,0.0f));
setMenuOptionColor(option,new Vector3f(0.2f,0.8f,0.5f));
}
public void decrementMenuOption(){
@ -63,7 +65,7 @@ public class Menu {
if(option < 0){
option = optionMax - 1;
}
setMenuOptionColor(option,new Vector3f(1.0f,1.0f,0.0f));
setMenuOptionColor(option,new Vector3f(0.2f,0.8f,0.5f));
}
public int getCurrentOption(){
@ -77,4 +79,12 @@ public class Menu {
public void setMenuOptionColor(int option, Vector3f color){
((TextBox)optionList.get(option)).setColor(color);
}
public List<Widget> getOptions(){
return optionList;
}
public List<Widget> getWidgets(){
return widgetList;
}
}

View File

@ -1,8 +1,13 @@
package electrosphere.menu;
import electrosphere.controls.ControlHandler;
import electrosphere.game.state.LoadingThread;
import electrosphere.main.Globals;
import electrosphere.main.Main;
import electrosphere.net.NetUtils;
import electrosphere.net.client.ClientNetworking;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.font.TextBox;
/**
*
@ -17,26 +22,67 @@ public class MenuTransition {
case 0:
m.dispose();
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.loadingThread.setFLAG_INIT_CLIENT(true);
Globals.loadingThread.setFLAG_INIT_SERVER(true);
Globals.loadingThread.start();
break;
//multi player
case 1:
m.dispose();
Globals.currentMenu = MenuUtils.createIPMenu();
Globals.currentMenu = MenuUtils.createMultiplayerMenu();
break;
//arena
case 2:
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_ARENA);
Globals.loadingThread.setFLAG_INIT_CLIENT(true);
Globals.loadingThread.setFLAG_INIT_SERVER(true);
Globals.loadingThread.start();
break;
//options
case 2:
case 3:
m.dispose();
Globals.currentMenu = MenuUtils.createOptionsMainMenu();
break;
}
break;
case MULTIPLAYER_MENU:
switch(m.getCurrentOption()){
//HOST
case 0:
m.dispose();
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.loadingThread.setFLAG_INIT_CLIENT(true);
Globals.loadingThread.setFLAG_INIT_SERVER(true);
Globals.loadingThread.start();
break;
//JOIN
case 1:
m.dispose();
Globals.currentMenu = MenuUtils.createIPMenu();
break;
//back
case 2:
backout(m);
break;
}
break;
case IP_MENU:
switch(m.getCurrentOption()){
//connect
case 2:
NetUtils.setAddress( ( (TextBox)m.getOptions().get(0) ).getText() );
NetUtils.setPort( Integer.parseInt( ( (TextBox)m.getOptions().get(1) ).getText() ) );
m.dispose();
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.loadingThread.setFLAG_INIT_CLIENT(true);
Globals.loadingThread.setFLAG_INIT_SERVER(false);
Globals.loadingThread.start();
break;
//back
case 3:
backout(m);
break;
}
break;
}
@ -47,9 +93,78 @@ public class MenuTransition {
case TITLE_MENU:
Main.running = false;
break;
case MULTIPLAYER_MENU:
m.dispose();
Globals.currentMenu = MenuUtils.createTitleMenu();
break;
case IP_MENU:
m.dispose();
Globals.currentMenu = MenuUtils.createMultiplayerMenu();
break;
case OPTIONS_MAIN_MENU:
m.dispose();
Globals.currentMenu = MenuUtils.createTitleMenu();
break;
}
}
public static void menuType(Menu m, String code){
char toWrite = ' ';
Widget currentOption = m.getOptions().get(m.getCurrentOption());
boolean backspace = false;
switch(code){
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_BACKSPACE:
if(currentOption instanceof TextBox){
TextBox currentTextBox = (TextBox)currentOption;
String currentText = currentTextBox.getText();
if(currentText.length() > 0){
currentTextBox.setText(currentText.substring(0, currentText.length() - 1));
}
}
backspace = true;
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_0:
toWrite = '0';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_1:
toWrite = '1';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_2:
toWrite = '2';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_3:
toWrite = '3';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_4:
toWrite = '4';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_5:
toWrite = '5';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_6:
toWrite = '6';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_7:
toWrite = '7';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_8:
toWrite = '8';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_9:
toWrite = '9';
break;
case ControlHandler.DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD:
toWrite = '.';
break;
}
if(!backspace){
if(currentOption instanceof TextBox){
TextBox currentTextBox = (TextBox)currentOption;
String currentText = currentTextBox.getText();
if(currentText.length() < currentTextBox.getCols()){
currentTextBox.setText(currentText + toWrite);
}
}
}
}
}

View File

@ -2,6 +2,8 @@ package electrosphere.menu;
import electrosphere.main.Globals;
import electrosphere.menu.Menu.MenuType;
import electrosphere.net.NetUtils;
import electrosphere.net.server.Server;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.WidgetUtils;
import org.joml.Vector3f;
@ -15,24 +17,46 @@ public class MenuUtils {
public static Menu createTitleMenu(){
Menu rVal = new Menu(MenuType.TITLE_MENU);
int screenTop = Globals.WINDOW_HEIGHT / 2;
rVal.addElement(WidgetUtils.createVerticallyAlignedTextBox(170, screenTop - 50 , 50, 4, 1, "ORPG", true));
rVal.addOption(WidgetUtils.createVerticallyAlignedTextBox(500, screenTop - 125, 50, 12, 1, "SINGLEPLAYER", true));
rVal.setMenuOptionColor(0, new Vector3f(1.0f,1.0f,0.0f));
rVal.addOption(WidgetUtils.createVerticallyAlignedTextBox(460, screenTop - 200, 50, 11, 1, "MULTIPLAYER", true));
rVal.addOption(WidgetUtils.createVerticallyAlignedTextBox(290, screenTop - 275, 50, 7, 1, "OPTIONS", true));
int screenTop = Globals.WINDOW_HEIGHT - 150;
rVal.addElement(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop, "ORPG", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 125, "SINGLEPLAYER", true));
rVal.setMenuOptionColor(0, new Vector3f(0.2f,0.8f,0.5f));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 200, "MULTIPLAYER", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 275, "ARENA", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 350, "OPTIONS", true));
return rVal;
}
public static Menu createMultiplayerMenu(){
Menu rVal = new Menu(MenuType.MULTIPLAYER_MENU);
int screenTop = Globals.WINDOW_HEIGHT - 150;
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 125, "HOST", true));
rVal.setMenuOptionColor(0, new Vector3f(0.2f,0.8f,0.5f));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 200, "JOIN", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 275, "BACK", true));
return rVal;
}
public static Menu createIPMenu(){
Menu rVal = new Menu(MenuType.IP_MENU);
int screenTop = Globals.WINDOW_HEIGHT / 2;
rVal.addElement(WidgetUtils.createVerticallyAlignedTextBox(420, screenTop - 50 , 50, 10, 1, "IP ADDRESS", true));
rVal.addOption(WidgetUtils.createVerticallyAlignedTextBox(460, screenTop - 125, 50, 11, 1, "192.168.0.1", true));
rVal.setMenuOptionColor(0, new Vector3f(1.0f,1.0f,0.0f));
rVal.addElement(WidgetUtils.createVerticallyAlignedTextBox(170, screenTop - 200, 50, 4, 1, "PORT", true));
rVal.addOption(WidgetUtils.createVerticallyAlignedTextBox(170, screenTop - 275, 50, 4, 1, "1111", true));
rVal.addOption(WidgetUtils.createVerticallyAlignedTextBox(290, screenTop - 350, 50, 7, 1, "CONNECT", true));
int screenTop = Globals.WINDOW_HEIGHT - 150;
rVal.addElement(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 50, "IP ADDRESS", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedEditableTextBox(40*15, 40, screenTop - 125, 15, 1, NetUtils.getAddress(), true));
rVal.setMenuOptionColor(0, new Vector3f(0.2f,0.8f,0.5f));
rVal.addElement(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 200, "PORT", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedEditableTextBox(40*5, 40, screenTop - 275, 5, 1, NetUtils.DEFAULT_PORT + "", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 350, "CONNECT", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 425, "BACK", true));
return rVal;
}
public static Menu createOptionsMainMenu(){
Menu rVal = new Menu(MenuType.OPTIONS_MAIN_MENU);
int screenTop = Globals.WINDOW_HEIGHT - 150;
rVal.addElement(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 50, "OPTIONS", true));
rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 275, "BACK", true));
return rVal;
}
@ -47,4 +71,5 @@ public class MenuUtils {
w.setDraw(false);
}
}
}

View File

@ -10,6 +10,11 @@ import electrosphere.net.message.EntityMessage;
*/
public class NetUtils {
public static final int DEFAULT_PORT = 34251;
static int port = DEFAULT_PORT;
static String address = "127.0.0.1";
public static EntityMessage createSpawnEntityMessage(Entity e){
EntityMessage rVal = EntityMessage.constructCreateMessage(e.getId(), CreatureUtils.getCreatureType(e));
return rVal;
@ -20,4 +25,22 @@ public class NetUtils {
EntityMessage rVal = EntityMessage.constructSetPropertyMessage(e.getId(), 0, CreatureUtils.getControllerPlayerId(e));
return rVal;
}
public static int getPort() {
return port;
}
public static String getAddress() {
return address;
}
public static void setPort(int port) {
NetUtils.port = port;
}
public static void setAddress(String address) {
NetUtils.address = address;
}
}

View File

@ -33,7 +33,6 @@ import org.apache.commons.crypto.stream.CryptoOutputStream;
public class ClientNetworking implements Runnable{
static int port = 42536;
Socket socket;
// CryptoInputStream inputStream;
// CryptoOutputStream outputStream;
@ -90,11 +89,13 @@ public class ClientNetworking implements Runnable{
public void parseMessages(){
while(parser.hasIncomingMessaage()){
NetworkMessage message = parser.popIncomingMessage();
System.out.println("New message " + message.getType());
//do something
handleMessage(message);
if(initialized){
while(parser.hasIncomingMessaage()){
NetworkMessage message = parser.popIncomingMessage();
System.out.println("New message " + message.getType());
//do something
handleMessage(message);
}
}
}

View File

@ -1,6 +1,7 @@
package electrosphere.net.server;
import electrosphere.main.Main;
import electrosphere.net.NetUtils;
import electrosphere.net.message.NetworkMessage;
import java.io.IOException;
import java.net.InetSocketAddress;
@ -17,7 +18,7 @@ import java.util.logging.Logger;
*/
public class Server implements Runnable{
static int port = 42536;
int port;
ServerSocket serverSocket;

View File

@ -606,7 +606,7 @@ public class ModelUtils {
m.nodeID = AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME;
Material uiMat = new Material();
Texture uiTex = new Texture("Textures/Fonts/OpenSansBitmap.bmp");
Texture uiTex = new Texture("Textures/Fonts/myfont1-harsher.png");
uiMat.set_diffuse(uiTex);
uiMat.set_specular(uiTex);
m.set_material(uiMat);

View File

@ -7,4 +7,5 @@ package electrosphere.renderer.assetmanager;
public class AssetDataStrings {
public static final String ASSET_STRING_BITMAP_FONT = "bitmapFont";
public static final String ASSET_STRING_BITMAP_FONT_MESH_NAME = "quad";
public static final String ASSET_STRING_SKYBOX_BASIC = "skyboxBasic";
}

View File

@ -11,14 +11,38 @@ public class WidgetUtils {
public static TextBox createTextBox(int positionX, int positionY, int width, int height, int cols, int rows, String text, boolean render){
TextBox rVal = new TextBox(positionX, positionY, width, height, rows, cols, text, render);
TextBox rVal = new TextBox(-width/2, positionY, width, height, rows, cols, text, render, false);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
public static TextBox createVerticallyAlignedTextBox(int width, int positionY, int height, int cols, int rows, String text, boolean render){
TextBox rVal = new TextBox(-width/2, positionY, width/2, height, rows, cols, text, render);
public static TextBox createVerticallyAlignedTextBox(int width, int height, int windowTop, int cols, int rows, String text, boolean render){
TextBox rVal = new TextBox(-width/2, windowTop, width, height, rows, cols, text, render, false);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
public static TextBox createVerticallyAlignedMinSizeTextBox(int charWidth, int charHeight, int windowTop, int cols, int rows, String text, boolean render){
TextBox rVal = new TextBox(-cols * charWidth / 2, windowTop, cols * charWidth, rows * charHeight, rows, cols, text, render, false);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
public static TextBox createVerticallyAlignedMinSizeTextBoxFromCharCount(int charWidth, int charHeight, int windowTop, String text, boolean render){
int cols = text.length();
int rows = 1;
TextBox rVal = new TextBox(-cols * charWidth / 2, windowTop, cols * charWidth, rows * charHeight, rows, cols, text, render, false);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
public static TextBox createVerticallyAlignedEditableTextBox(int width, int height, int windowTop, int cols, int rows, String text, boolean render){
TextBox rVal = new TextBox(-(int)(width/2.5), windowTop, width, height, rows, cols, text, render, true);
Globals.widgetManager.registerWidget(rVal);
return rVal;
}
}

View File

@ -20,10 +20,11 @@ public class TextBox extends Widget{
int rows;
int cols;
String text;
boolean editable;
Vector3f color = new Vector3f(0,0,0);
public TextBox(int positionX, int positionY, int width, int height, int rows, int cols, String text, boolean render) {
public TextBox(int positionX, int positionY, int width, int height, int rows, int cols, String text, boolean render, boolean editable) {
super(positionX,positionY,width,height,render,Widget.WidgetType.TEXT_BOX);
this.positionX = positionX;
this.positionY = positionY;
@ -61,6 +62,14 @@ public class TextBox extends Widget{
public void setColor(Vector3f color) {
this.color = color;
}
public boolean isEditable() {
return editable;
}
public void setEditable(boolean editable) {
this.editable = editable;
}
@Override
@ -83,7 +92,7 @@ public class TextBox extends Widget{
Vector3f bitMapPosition = FontUtils.getPositionOfCharacter(toDraw);
Vector3f bitMapDimension = FontUtils.getDimensionOfCharacter(toDraw);
Model charModel = Globals.assetManager.fetchModel(AssetDataStrings.ASSET_STRING_BITMAP_FONT);
if(charModel != null){
if(charModel != null && toDraw != ' '){
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "mPosition", characterPosition);
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "mDimension", characterDimensions);
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "tPosition", bitMapPosition);

View File

@ -0,0 +1,483 @@
{
"imageWidth": 3864,
"imageHeight": 42,
"glyphs":
[
{
"symbol": "A",
"startX": 1,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "B",
"startX": 43,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "C",
"startX": 85,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "D",
"startX": 127,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "E",
"startX": 169,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "F",
"startX": 211,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "G",
"startX": 253,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "H",
"startX": 295,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "I",
"startX": 337,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "J",
"startX": 379,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "K",
"startX": 421,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "L",
"startX": 463,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "M",
"startX": 505,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "N",
"startX": 547,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "O",
"startX": 589,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "P",
"startX": 631,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "Q",
"startX": 673,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "R",
"startX": 715,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "S",
"startX": 757,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "T",
"startX": 799,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "U",
"startX": 841,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "V",
"startX": 883,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "W",
"startX": 925,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "X",
"startX": 967,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "Y",
"startX": 1009,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "Z",
"startX": 1051,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "a",
"startX": 1093,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "b",
"startX": 1135,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "c",
"startX": 1177,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "d",
"startX": 1219,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "e",
"startX": 1261,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "f",
"startX": 1303,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "g",
"startX": 1345,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "h",
"startX": 1387,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "i",
"startX": 1429,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "j",
"startX": 1471,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "k",
"startX": 1513,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "l",
"startX": 1555,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "m",
"startX": 1597,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "n",
"startX": 1639,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "o",
"startX": 1681,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "p",
"startX": 1723,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "q",
"startX": 1765,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "r",
"startX": 1807,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "s",
"startX": 1849,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "t",
"startX": 1891,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "u",
"startX": 1933,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "v",
"startX": 1975,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "w",
"startX": 2017,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "x",
"startX": 2059,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "y",
"startX": 2101,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "z",
"startX": 2143,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "1",
"startX": 2185,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "2",
"startX": 2227,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "3",
"startX": 2269,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "4",
"startX": 2311,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "5",
"startX": 2353,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "6",
"startX": 2395,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "7",
"startX": 2437,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "8",
"startX": 2479,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "9",
"startX": 2521,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "0",
"startX": 2563,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": ".",
"startX": 2605,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "!",
"startX": 2647,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "?",
"startX": 2689,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "\"",
"startX": 2731,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": "'",
"startX": 2773,
"startY": 1,
"width": 40,
"height": 40
},
{
"symbol": ",",
"startX": 2815,
"startY": 1,
"width": 40,
"height": 40
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB