Basic menus

This commit is contained in:
austin 2021-06-02 00:32:47 -04:00
parent f4a7a8d513
commit bde5a77131
12 changed files with 511 additions and 91 deletions

View File

@ -6,6 +6,7 @@ import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.MovementTree;
import electrosphere.entity.state.MovementTree.MovementTreeState;
import electrosphere.main.Globals;
import electrosphere.menu.MenuTransition;
import electrosphere.net.client.ClientNetworkMessage;
import electrosphere.net.message.EntityMessage;
import electrosphere.util.Utilities;
@ -14,9 +15,13 @@ import java.util.List;
import org.joml.Vector3f;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_A;
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_S;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_UP;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_W;
import static org.lwjgl.glfw.GLFW.GLFW_PRESS;
import static org.lwjgl.glfw.GLFW.glfwGetKey;
@ -34,6 +39,11 @@ public class ControlHandler {
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_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 DATA_STRING_INPUT_CODE_MENU_BACKOUT = "menuBackout";
enum ControlsState {
TITLE_PAGE,
@ -41,6 +51,8 @@ public class ControlHandler {
MAIN_GAME,
}
ControlsState state;
HashMap<String, Integer> controlsMap;
HashMap<String, Boolean> controlsState;
@ -52,6 +64,10 @@ public class ControlHandler {
public static void generateExampleControlsMap(){
ControlHandler handler = new ControlHandler();
/*
Main Game controls
*/
/*
Map the controls
*/
@ -71,103 +87,183 @@ public class ControlHandler {
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MOVEMENT_FALL, false);
/*
Map the controls
*/
handler.addControl(DATA_STRING_INPUT_CODE_MENU_INCREMENT, GLFW_KEY_DOWN);
handler.addControl(DATA_STRING_INPUT_CODE_MENU_DECREMENT, GLFW_KEY_UP);
handler.addControl(DATA_STRING_INPUT_CODE_MENU_SELECT, GLFW_KEY_ENTER);
handler.addControl(DATA_STRING_INPUT_CODE_MENU_BACKOUT, GLFW_KEY_ESCAPE);
/*
Set their states to false(not pressed)
*/
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_INCREMENT, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_DECREMENT, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_SELECT, false);
handler.addControlState(DATA_STRING_INPUT_CODE_MENU_BACKOUT, false);
/*
set state
*/
handler.setHandlerState(ControlsState.TITLE_MENU);
/*
Save to file
*/
Utilities.saveObjectToBakedJsonFile("/Config/keybinds.json", handler);
}
public void pollControls(){
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();
switch(state){
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);
}
}
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();
/*
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));
}
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();
break;
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);
}
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD) == true){
movementTree.slowdown();
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);
}
}
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();
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);
}
}
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, true);
} else {
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT) == true){
movementTree.slowdown();
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);
}
}
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));
}
break;
}
}
@ -191,4 +287,12 @@ public class ControlHandler {
controlsState.put(controlName,state);
}
public void setHandlerState(ControlsState state){
this.state = state;
}
public ControlsState getState(){
return state;
}
}

View File

@ -7,6 +7,8 @@ import electrosphere.game.cell.DrawCellManager;
import electrosphere.game.state.SimulationState.SimulationStateMachine;
import electrosphere.game.terrain.TerrainManager;
import electrosphere.main.Globals;
import static electrosphere.main.Globals.loadingBox;
import electrosphere.menu.MenuUtils;
import electrosphere.net.client.ClientNetworking;
import electrosphere.net.server.Server;
import electrosphere.renderer.Model;
@ -47,6 +49,12 @@ public class LoadingThread extends Thread {
case LOAD_TITLE_MENU:
Globals.currentMenu = MenuUtils.createTitleMenu();
loadingBox.setDraw(false);
MenuUtils.makeMenuDrawable(Globals.currentMenu);
SimulationState.simulationState = SimulationStateMachine.TITLE_MENU;
break;

View File

@ -18,14 +18,17 @@ import electrosphere.entity.types.creature.CreatureTypeList;
import electrosphere.game.cell.DrawCellManager;
import electrosphere.game.state.LoadingThread;
import electrosphere.game.terrain.TerrainManager;
import electrosphere.menu.Menu;
import electrosphere.net.client.ClientNetworking;
import electrosphere.net.server.Server;
import electrosphere.renderer.ModelUtils;
import electrosphere.renderer.assetmanager.AssetDataStrings;
import electrosphere.renderer.assetmanager.AssetManager;
import electrosphere.renderer.ui.WidgetManager;
import electrosphere.renderer.ui.WidgetUtils;
import electrosphere.renderer.ui.font.FontUtils;
import electrosphere.renderer.ui.font.RawFontMap;
import electrosphere.renderer.ui.font.TextBox;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
@ -114,13 +117,15 @@ public class Globals {
public static Texture textureSpecularDefault;
public static Material materialDefault;
public static Texture blackTexture;
public static DirectionalLight lightDirectionalDefault;
public static ArrayList<PointLight> lightPointListDefault;
public static SpotLight lightSpotDefault;
public static TextureMap textureMapDefault;
public static Menu currentMenu;
@ -155,6 +160,9 @@ public class Globals {
//manager for all widgets currently being drawn to screen
public static WidgetManager widgetManager;
//ui text box for loading text
public static TextBox loadingBox;
//the player camera entity
public static Entity playerCamera;
@ -168,6 +176,7 @@ public class Globals {
public static boolean RENDER_FLAG_RENDER_SHADOW_MAP = false;
public static boolean RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT = false;
public static boolean RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER = false;
public static boolean RENDER_FLAG_RENDER_BLACK_BACKGROUND = true;
public static boolean RENDER_FLAG_RENDER_UI = true;
@ -207,6 +216,10 @@ public class Globals {
assetManager.registerModelToSpecificString(ModelUtils.createBitmapDisplay(), AssetDataStrings.ASSET_STRING_BITMAP_FONT);
RawFontMap fontMap = Utilities.loadObjectFromBakedJsonFile("/Textures/Fonts/fontMap.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);
}
static void initEntityTypeMap(){

View File

@ -108,7 +108,7 @@ public class Main {
public static int playerId = -1;
static boolean running = true;
public static boolean running = true;
public static Entity letterEntity;
@ -143,8 +143,6 @@ public class Main {
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_TITLE_MENU);
Globals.loadingThread.start();
TextBox loadingText = WidgetUtils.createVerticallyAlignedTextBox(520, 100, 50, 7, 1, "LOADING", true);
//recapture the screen for rendering
RenderUtils.recaptureScreen();
@ -189,7 +187,7 @@ public class Main {
/// I N P U T C O N T R O L S
///
cameraSpeed = 2.5f * deltaTime;
if (glfwGetKey(Globals.window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
if (glfwGetKey(Globals.window, GLFW_KEY_ESCAPE) == GLFW_PRESS && SimulationState.simulationState == SimulationStateMachine.MAIN_SIMULATION) {
break;
}

View File

@ -0,0 +1,80 @@
package electrosphere.menu;
import electrosphere.main.Globals;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.font.TextBox;
import java.util.ArrayList;
import java.util.List;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
public class Menu {
public enum MenuType {
TITLE_MENU,
IP_MENU,
}
MenuType type;
int option = 0;
int optionMax = 0;
List<Widget> widgetList = new ArrayList();
List<Widget> optionList = new ArrayList();
public Menu(MenuType type){
this.type = type;
}
public void addOption(Widget option){
widgetList.add(option);
optionList.add(option);
optionMax++;
}
public void addElement(Widget element){
widgetList.add(element);
}
public void dispose(){
for(Widget w : widgetList){
Globals.widgetManager.unregisterWidget(w);
}
widgetList.clear();
optionList.clear();
}
public void incrementMenuOption(){
setMenuOptionColor(option,new Vector3f(1.0f,1.0f,1.0f));
option++;
if(option>=optionMax){
option = 0;
}
setMenuOptionColor(option,new Vector3f(1.0f,1.0f,0.0f));
}
public void decrementMenuOption(){
setMenuOptionColor(option,new Vector3f(1.0f,1.0f,1.0f));
option--;
if(option < 0){
option = optionMax - 1;
}
setMenuOptionColor(option,new Vector3f(1.0f,1.0f,0.0f));
}
public int getCurrentOption(){
return option;
}
public MenuType getType(){
return type;
}
public void setMenuOptionColor(int option, Vector3f color){
((TextBox)optionList.get(option)).setColor(color);
}
}

View File

@ -0,0 +1,55 @@
package electrosphere.menu;
import electrosphere.game.state.LoadingThread;
import electrosphere.main.Globals;
import electrosphere.main.Main;
/**
*
* @author amaterasu
*/
public class MenuTransition {
public static void selectOption(Menu m){
switch(m.getType()){
case TITLE_MENU:
switch(m.getCurrentOption()){
//single player
case 0:
m.dispose();
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.loadingThread.start();
break;
//multi player
case 1:
m.dispose();
Globals.currentMenu = MenuUtils.createIPMenu();
break;
//options
case 2:
break;
}
break;
case IP_MENU:
switch(m.getCurrentOption()){
//connect
case 2:
Globals.loadingThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.loadingThread.start();
break;
}
break;
}
}
public static void backout(Menu m){
switch(m.getType()){
case TITLE_MENU:
Main.running = false;
break;
case IP_MENU:
Globals.currentMenu = MenuUtils.createTitleMenu();
break;
}
}
}

View File

@ -0,0 +1,50 @@
package electrosphere.menu;
import electrosphere.main.Globals;
import electrosphere.menu.Menu.MenuType;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.WidgetUtils;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
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));
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));
return rVal;
}
public static void makeMenuDrawable(Menu m){
for(Widget w : m.widgetList){
w.setDraw(true);
}
}
public static void makeMenuUndrawable(Menu m){
for(Widget w : m.widgetList){
w.setDraw(false);
}
}
}

View File

@ -542,6 +542,13 @@ public class RenderUtils {
renderScreenFramebuffer();
}
/*
Render black background
*/
if(Globals.RENDER_FLAG_RENDER_BLACK_BACKGROUND){
renderBlackBackground();
}
/*
Render any ui elements
*/
@ -552,6 +559,8 @@ public class RenderUtils {
//check and call events and swap the buffers
glfwSwapBuffers(Globals.window);
glfwPollEvents();
@ -725,8 +734,14 @@ public class RenderUtils {
// }
}
static void renderLoading(){
static void renderBlackBackground(){
//render full screen quad
glUseProgram(screenTextureShaders.shaderProgram);
glBindVertexArray(screenTextureVAO);
Globals.blackTexture.bind();
// glBindTexture(GL_TEXTURE_2D, screenFramebuffer.getTexture());
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
}
}

View File

@ -27,5 +27,10 @@ public class WidgetManager {
return widgetList;
}
public void unregisterWidget(Widget w){
if(widgetList.contains(w)){
widgetList.remove(w);
}
}
}

View File

@ -20,6 +20,8 @@ public class TextBox extends Widget{
int rows;
int cols;
String text;
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) {
super(positionX,positionY,width,height,render,Widget.WidgetType.TEXT_BOX);
@ -56,6 +58,10 @@ public class TextBox extends Widget{
this.text = text;
}
public void setColor(Vector3f color) {
this.color = color;
}
@Override
public void draw(){
@ -82,6 +88,7 @@ public class TextBox extends Widget{
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "mDimension", characterDimensions);
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "tPosition", bitMapPosition);
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "tDimension", bitMapDimension);
charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "color", color);
charModel.drawUI();
}
}

View File

@ -204,6 +204,91 @@
"startY": 16,
"width": 6,
"height": 11
},
{
"symbol": " ",
"startX": 0,
"startY": 240,
"width": 16,
"height": 16
},
{
"symbol": "0",
"startX": 0,
"startY": 175,
"width": 10,
"height": 14
},
{
"symbol": "1",
"startX": 32,
"startY": 175,
"width": 10,
"height": 14
},
{
"symbol": "2",
"startX": 64,
"startY": 175,
"width": 10,
"height": 14
},
{
"symbol": "3",
"startX": 96,
"startY": 175,
"width": 10,
"height": 14
},
{
"symbol": "4",
"startX": 128,
"startY": 175,
"width": 10,
"height": 14
},
{
"symbol": "5",
"startX": 160,
"startY": 175,
"width": 10,
"height": 14
},
{
"symbol": "6",
"startX": 192,
"startY": 175,
"width": 10,
"height": 14
},
{
"symbol": "7",
"startX": 224,
"startY": 175,
"width": 10,
"height": 14
},
{
"symbol": "8",
"startX": 0,
"startY": 143,
"width": 11,
"height": 14
},
{
"symbol": "9",
"startX": 31,
"startY": 143,
"width": 11,
"height": 14
},
{
"symbol": ".",
"startX": 190,
"startY": 205,
"width": 11,
"height": 14
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 B