In game ui
This commit is contained in:
parent
1cfeb5c173
commit
ad04661533
BIN
assets/Audio/Footstep1.ogg
Normal file
BIN
assets/Audio/Footstep1.ogg
Normal file
Binary file not shown.
@ -116,6 +116,11 @@
|
||||
"isKey": false,
|
||||
"isMouse": true,
|
||||
"keyValue": 0
|
||||
},
|
||||
"inGameMainMenu" : {
|
||||
"isKey": true,
|
||||
"isMouse": false,
|
||||
"keyValue": 256
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -89,8 +89,8 @@
|
||||
"movementSystems" : [
|
||||
{
|
||||
"type" : "GROUND",
|
||||
"acceleration" : 1.0,
|
||||
"maxVelocity" : 4.0
|
||||
"acceleration" : 16.0,
|
||||
"maxVelocity" : 3.0
|
||||
}
|
||||
],
|
||||
"collidable" : {
|
||||
|
||||
@ -15,7 +15,9 @@ void main(){
|
||||
|
||||
vec2 finalPos = vec2(
|
||||
((aPos.x + 1)/2 * mDimension.x + mPosition.x) * 2 - 1,
|
||||
((1-(aPos.y + 1)/2) * mDimension.y + mPosition.y) * 2 - 1
|
||||
((((aPos.y + 1)/2) * mDimension.y + mPosition.y) * 2 - 1)
|
||||
// (aPos.y * mDimension.y + mPosition.y)
|
||||
// -((((aPos.y + 1)/2) * mDimension.y + mPosition.y) * 2 - 1)
|
||||
// aPos.y * mDimension.y + (mPosition.y) + (1 - mDimension.y)
|
||||
);
|
||||
gl_Position = vec4(finalPos.x, finalPos.y, 0.0, 1.0);
|
||||
@ -23,7 +25,7 @@ void main(){
|
||||
|
||||
vec2 finalTex = vec2(
|
||||
aTexCoords.x * tDimension.x + tPosition.x,
|
||||
aTexCoords.y * tDimension.y + tPosition.y
|
||||
(1-aTexCoords.y) * tDimension.y + tPosition.y
|
||||
);
|
||||
TexCoords = finalTex;
|
||||
}
|
||||
@ -6,5 +6,9 @@ in vec2 TexCoords;
|
||||
uniform sampler2D screenTexture;
|
||||
|
||||
void main(){
|
||||
FragColor = texture(screenTexture, TexCoords);
|
||||
vec4 textureColor = texture(screenTexture, TexCoords);
|
||||
if(textureColor.a < 0.1){
|
||||
discard;
|
||||
}
|
||||
FragColor = textureColor;
|
||||
}
|
||||
@ -12,7 +12,7 @@ uniform vec3 tDimension;
|
||||
void main(){
|
||||
vec2 finalPos = vec2(
|
||||
((aPos.x + 1)/2 * mDimension.x + mPosition.x) * 2 - 1,
|
||||
((1-(aPos.y + 1)/2) * mDimension.y + mPosition.y) * 2 - 1
|
||||
-((((aPos.y + 1)/2) * mDimension.y + mPosition.y) * 2 - 1)
|
||||
// aPos.y * mDimension.y + (mPosition.y) + (1 - mDimension.y)
|
||||
);
|
||||
gl_Position = vec4(finalPos.x, finalPos.y, 0.0, 1.0);
|
||||
|
||||
@ -66,5 +66,10 @@ public class AudioEngine {
|
||||
return engineGain;
|
||||
}
|
||||
|
||||
public void shutdown(){
|
||||
ALC10.alcDestroyContext(context);
|
||||
ALC10.alcCloseDevice(device);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -12,7 +12,9 @@ import electrosphere.entity.types.collision.CollisionObjUtils;
|
||||
import electrosphere.entity.types.item.ItemUtils;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.menu.MenuTransition;
|
||||
import electrosphere.menu.MenuUtils;
|
||||
import electrosphere.net.parser.net.message.EntityMessage;
|
||||
import electrosphere.renderer.ui.Widget;
|
||||
import electrosphere.util.Utilities;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -39,6 +41,7 @@ public class ControlHandler {
|
||||
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_FALL = "fall";
|
||||
public static final String DATA_STRING_INPUT_CODE_ATTACK_PRIMARY = "attackPrimary";
|
||||
public static final String DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM = "debugSpawnItem";
|
||||
public static final String DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU = "inGameMainMenu";
|
||||
|
||||
public static final String DATA_STRING_INPUT_CODE_MENU_INCREMENT = "menuIncrement";
|
||||
public static final String DATA_STRING_INPUT_CODE_MENU_DECREMENT = "menuDecrement";
|
||||
@ -91,6 +94,7 @@ public class ControlHandler {
|
||||
TITLE_PAGE,
|
||||
TITLE_MENU,
|
||||
MAIN_GAME,
|
||||
IN_GAME_MAIN_MENU,
|
||||
NO_INPUT,
|
||||
}
|
||||
|
||||
@ -120,6 +124,7 @@ public class ControlHandler {
|
||||
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP, new Control(true,false,GLFW_KEY_SPACE));
|
||||
handler.addControl(DATA_STRING_INPUT_CODE_MOVEMENT_FALL, new Control(true,false,GLFW_KEY_LEFT_CONTROL));
|
||||
handler.addControl(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY, new Control(false,true,GLFW_MOUSE_BUTTON_LEFT));
|
||||
handler.addControl(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU, new Control(true,false,GLFW_KEY_ESCAPE));
|
||||
|
||||
/*
|
||||
Map the menu navigation controls
|
||||
@ -216,6 +221,10 @@ public class ControlHandler {
|
||||
pollTypingControls();
|
||||
break;
|
||||
|
||||
case IN_GAME_MAIN_MENU:
|
||||
pollMenuNavigationControls();
|
||||
break;
|
||||
|
||||
case NO_INPUT:
|
||||
break;
|
||||
|
||||
@ -367,6 +376,27 @@ public class ControlHandler {
|
||||
controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).setState(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Main menu dialog toggle
|
||||
*/
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).getKeyValue()) == GLFW_PRESS){
|
||||
controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).setState(true);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).isState() == true){
|
||||
//make menu dialog visible
|
||||
//change control scheme to in game main menu scheme
|
||||
System.out.println("Press main menu");
|
||||
Globals.currentMenu = MenuUtils.createInGameMainMenu();
|
||||
MenuUtils.makeMenuDrawable(Globals.currentMenu);
|
||||
Globals.controlHandler.setHandlerState(ControlsState.IN_GAME_MAIN_MENU);
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).setState(false);
|
||||
}
|
||||
}
|
||||
//DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU
|
||||
}
|
||||
}
|
||||
|
||||
@ -502,6 +532,124 @@ public class ControlHandler {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static String convertKeycodeToName(int code){
|
||||
String rVal = "";
|
||||
switch(code){
|
||||
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 256:
|
||||
rVal = "Escape";
|
||||
break;
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -46,6 +46,8 @@ import electrosphere.game.client.targeting.crosshair.Crosshair;
|
||||
import electrosphere.game.server.pathfinding.NavMeshPathfinder;
|
||||
import electrosphere.game.server.pathfinding.navmesh.NavCube;
|
||||
import electrosphere.game.server.pathfinding.navmesh.NavMesh;
|
||||
import electrosphere.renderer.ui.Widget;
|
||||
import electrosphere.renderer.ui.WidgetUtils;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -181,6 +183,9 @@ public class LoadingThread extends Thread {
|
||||
//hide cursor
|
||||
Globals.controlHandler.hideMouse();
|
||||
|
||||
//create in game ui
|
||||
showInGameUI();
|
||||
|
||||
|
||||
loadingBox.setVisible(false);
|
||||
|
||||
@ -266,6 +271,9 @@ public class LoadingThread extends Thread {
|
||||
//hide cursor
|
||||
Globals.controlHandler.hideMouse();
|
||||
|
||||
//create in game ui
|
||||
showInGameUI();
|
||||
|
||||
loadingBox.setVisible(false);
|
||||
|
||||
RenderUtils.recaptureScreen();
|
||||
@ -513,6 +521,13 @@ public class LoadingThread extends Thread {
|
||||
Globals.microSimulation = new MicroSimulation();
|
||||
}
|
||||
|
||||
static void showInGameUI(){
|
||||
for(Widget widget : Globals.inGameUI){
|
||||
// System.out.println("Set widget visible");
|
||||
widget.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
static void setSimulationsToReady(){
|
||||
Globals.microSimulation.setReady(true);
|
||||
if(Globals.macroSimulation != null){
|
||||
@ -600,7 +615,7 @@ public class LoadingThread extends Thread {
|
||||
// //attach ai to evil goblin
|
||||
// MindlessAttacker.attachToCreature(goblin);
|
||||
|
||||
StructureUtils.spawnBasicStructure("building1", new Vector3f(5,2.4f,5), new Quaternionf());
|
||||
// StructureUtils.spawnBasicStructure("building1", new Vector3f(5,2.4f,5), new Quaternionf());
|
||||
|
||||
Entity bow = ItemUtils.spawnBasicItem("Bow");
|
||||
EntityUtils.getPosition(bow).set(1, 1, 2);
|
||||
|
||||
@ -141,7 +141,8 @@ public class PhysicsUtils {
|
||||
true // "useQuantizedAabbCompression" -- apparently means better memory usage ( http://jbullet.advel.cz/javadoc/com/bulletphysics/collision/shapes/BvhTriangleMeshShape.html )
|
||||
);
|
||||
|
||||
terrainShape.setMargin(0.08f);
|
||||
//uncomment if we start falling through things again
|
||||
// terrainShape.setMargin(0.08f);
|
||||
|
||||
// terrainShape.localGetSupportingVertex(new javax.vecmath.Vector3f(1,0,0), aabbMin);
|
||||
// terrainShape.recalcLocalAabb();
|
||||
|
||||
@ -47,6 +47,7 @@ import electrosphere.renderer.ShaderProgram;
|
||||
import electrosphere.engine.assetmanager.AssetDataStrings;
|
||||
import electrosphere.engine.assetmanager.AssetManager;
|
||||
import electrosphere.game.server.pathfinding.NavMeshManager;
|
||||
import electrosphere.renderer.ui.Widget;
|
||||
import electrosphere.renderer.ui.WidgetManager;
|
||||
import electrosphere.renderer.ui.WidgetUtils;
|
||||
import electrosphere.renderer.ui.font.FontUtils;
|
||||
@ -64,6 +65,7 @@ import org.joml.Vector3f;
|
||||
import electrosphere.util.ModelLoader;
|
||||
import electrosphere.util.Utilities;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.lwjgl.glfw.GLFWErrorCallback;
|
||||
@ -90,6 +92,12 @@ public class Globals {
|
||||
public static AudioEngine audioEngine;
|
||||
|
||||
|
||||
//
|
||||
//Core Engine signals
|
||||
//
|
||||
public static boolean ENGINE_SHUTDOWN_FLAG = false;
|
||||
|
||||
|
||||
//
|
||||
//Client connection to server
|
||||
//
|
||||
@ -206,6 +214,8 @@ public class Globals {
|
||||
|
||||
public static Menu currentMenu;
|
||||
|
||||
public static List<Widget> inGameUI = new LinkedList();
|
||||
|
||||
public static String particleBillboardModel;
|
||||
|
||||
|
||||
@ -300,8 +310,8 @@ 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_WHITE_BACKGROUND = false;
|
||||
public static boolean RENDER_FLAG_RENDER_BLACK_BACKGROUND = false;
|
||||
public static boolean RENDER_FLAG_RENDER_WHITE_BACKGROUND = true;
|
||||
public static boolean RENDER_FLAG_RENDER_UI = true;
|
||||
|
||||
|
||||
@ -394,7 +404,10 @@ public class Globals {
|
||||
testingTexture = "Textures/Testing1.png";
|
||||
Globals.assetManager.addTexturePathtoQueue(testingTexture);
|
||||
|
||||
assetManager.addModelPathToQueue("Models/deer1.fbx");
|
||||
//in game ui stuff
|
||||
inGameUI.add(WidgetUtils.createInGameMainMenuButton());
|
||||
|
||||
|
||||
|
||||
//as these assets are required for the renderer to work, we go ahead and
|
||||
//load them into memory now. The loading time penalty is worth it I think.
|
||||
|
||||
@ -234,9 +234,9 @@ 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 && Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT) {
|
||||
break;
|
||||
}
|
||||
// if (glfwGetKey(Globals.window, GLFW_KEY_ESCAPE) == GLFW_PRESS && Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT) {
|
||||
// break;
|
||||
// }
|
||||
|
||||
//cell tracking values
|
||||
Vector3d oldPlayerCharacterPosition = new Vector3d();
|
||||
@ -332,7 +332,7 @@ public class Main {
|
||||
Globals.renderingEngine.drawScreen();
|
||||
|
||||
|
||||
if(glfwWindowShouldClose(Globals.window)){
|
||||
if(glfwWindowShouldClose(Globals.window) || Globals.ENGINE_SHUTDOWN_FLAG){
|
||||
running = false;
|
||||
}
|
||||
|
||||
@ -346,6 +346,8 @@ public class Main {
|
||||
Globals.server.close();
|
||||
Globals.serverThread.interrupt();
|
||||
}
|
||||
//shut down audio engine
|
||||
Globals.audioEngine.shutdown();
|
||||
}
|
||||
|
||||
static void sleep(int i) {
|
||||
|
||||
@ -25,6 +25,7 @@ public class Menu {
|
||||
MULTIPLAYER_MENU,
|
||||
IP_MENU,
|
||||
OPTIONS_MAIN_MENU,
|
||||
IN_GAME_MAIN_MENU,
|
||||
TEST,
|
||||
}
|
||||
|
||||
@ -87,7 +88,9 @@ public class Menu {
|
||||
}
|
||||
|
||||
public void setMenuOptionColor(int option, Vector3f color){
|
||||
((TextBox)optionList.get(option)).setColor(color);
|
||||
if(optionList.get(option) instanceof TextBox){
|
||||
((TextBox)optionList.get(option)).setColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Widget> getOptions(){
|
||||
|
||||
@ -3,6 +3,7 @@ package electrosphere.menu;
|
||||
import electrosphere.audio.AudioSource;
|
||||
import electrosphere.audio.AudioUtils;
|
||||
import electrosphere.controls.ControlHandler;
|
||||
import electrosphere.controls.ControlHandler.ControlsState;
|
||||
import electrosphere.engine.LoadingThread;
|
||||
import electrosphere.game.server.saves.SaveUtils;
|
||||
import electrosphere.main.Globals;
|
||||
@ -11,6 +12,7 @@ import electrosphere.net.NetUtils;
|
||||
import electrosphere.net.client.ClientNetworking;
|
||||
import electrosphere.renderer.ui.Widget;
|
||||
import electrosphere.renderer.ui.font.TextBox;
|
||||
import electrosphere.renderer.ui.label.Label;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
/**
|
||||
@ -139,6 +141,21 @@ public class MenuTransition {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case IN_GAME_MAIN_MENU:
|
||||
switch(((Label)m.getCurrentOption()).getText()){
|
||||
//connect
|
||||
case "QUIT":
|
||||
//TODO: actually shut down program
|
||||
Globals.ENGINE_SHUTDOWN_FLAG = true;
|
||||
break;
|
||||
//back
|
||||
case "BACK":
|
||||
MenuUtils.makeMenuUndrawable(Globals.currentMenu);
|
||||
Globals.currentMenu.dispose();
|
||||
Globals.controlHandler.setHandlerState(ControlsState.MAIN_GAME);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,6 +201,11 @@ public class MenuTransition {
|
||||
m.dispose();
|
||||
Globals.currentMenu = MenuUtils.createTitleMenu();
|
||||
break;
|
||||
case IN_GAME_MAIN_MENU:
|
||||
MenuUtils.makeMenuUndrawable(Globals.currentMenu);
|
||||
Globals.currentMenu.dispose();
|
||||
Globals.controlHandler.setHandlerState(ControlsState.MAIN_GAME);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,9 @@ import electrosphere.net.NetUtils;
|
||||
import electrosphere.net.server.Server;
|
||||
import electrosphere.renderer.ui.Widget;
|
||||
import electrosphere.renderer.ui.WidgetUtils;
|
||||
import electrosphere.renderer.ui.Window;
|
||||
import electrosphere.renderer.ui.label.Label;
|
||||
import electrosphere.renderer.ui.widgets.ImagePanel;
|
||||
import java.util.List;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
@ -116,6 +119,42 @@ public class MenuUtils {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static Menu createInGameMainMenu(){
|
||||
Menu rVal = new Menu(MenuType.IN_GAME_MAIN_MENU);
|
||||
int screenTop = Globals.WINDOW_HEIGHT - 150;
|
||||
int width = 500;
|
||||
int height = 500;
|
||||
int screenLeft = (Globals.WINDOW_WIDTH - width)/2;
|
||||
Window menuWindow = new Window(100, 100, 500, 500);
|
||||
|
||||
//black texture background
|
||||
ImagePanel imagePanel = new ImagePanel(0,0,width,height);
|
||||
imagePanel.setWidth(width);
|
||||
imagePanel.setHeight(height);
|
||||
imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.blackTexture));
|
||||
menuWindow.addWidget(imagePanel);
|
||||
|
||||
//label 1 (back)
|
||||
Label backLabel = new Label(100,50,1.0f);
|
||||
backLabel.setText("BACK");
|
||||
menuWindow.addWidget(backLabel);
|
||||
rVal.addOption(backLabel);
|
||||
|
||||
|
||||
//label 2 (quit)
|
||||
Label quitLabel = new Label(100,150,1.0f);
|
||||
quitLabel.setText("QUIT");
|
||||
menuWindow.addWidget(quitLabel);
|
||||
rVal.addOption(quitLabel);
|
||||
|
||||
|
||||
rVal.addElement(menuWindow);
|
||||
Globals.widgetManager.registerWidget(menuWindow);
|
||||
// rVal.addElement(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 50, "BACK", true));
|
||||
// rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 275, "QUIT", true));
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static Menu createTestMainMenu(){
|
||||
Menu rVal = new Menu(MenuType.TEST);
|
||||
rVal.addElement(WidgetUtils.createWindowTEST());
|
||||
|
||||
@ -12,6 +12,7 @@ import static org.lwjgl.opengl.GL11.GL_NEAREST;
|
||||
import static org.lwjgl.opengl.GL11.GL_NONE;
|
||||
import static org.lwjgl.opengl.GL11.GL_REPEAT;
|
||||
import static org.lwjgl.opengl.GL11.GL_RGB;
|
||||
import static org.lwjgl.opengl.GL11.GL_RGBA;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_BORDER_COLOR;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MAG_FILTER;
|
||||
@ -85,7 +86,7 @@ public class FramebufferUtils {
|
||||
//texture
|
||||
int texture = glGenTextures();
|
||||
glBindTexture(GL_TEXTURE_2D,texture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
//these make sure the texture actually clamps to the borders of the quad
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
package electrosphere.renderer.ui;
|
||||
|
||||
import electrosphere.controls.ControlHandler;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.renderer.ui.font.FontUtils;
|
||||
import electrosphere.renderer.ui.font.TextBox;
|
||||
import electrosphere.renderer.ui.font.bitmapchar.BitmapCharacter;
|
||||
import electrosphere.renderer.ui.label.Label;
|
||||
import electrosphere.renderer.ui.layout.LayoutSchemeListScrollable;
|
||||
import electrosphere.renderer.ui.widgets.ImagePanel;
|
||||
import electrosphere.renderer.ui.widgets.TextInput;
|
||||
@ -95,8 +98,12 @@ public class WidgetUtils {
|
||||
// rVal.addWidget(textInput);
|
||||
|
||||
|
||||
BitmapCharacter characterDisp = new BitmapCharacter(0,0,500,500,'A');
|
||||
rVal.addWidget(characterDisp);
|
||||
// BitmapCharacter characterDisp = new BitmapCharacter(0,0,500,500,'A');
|
||||
// rVal.addWidget(characterDisp);
|
||||
|
||||
Label label = new Label(100,100,1);
|
||||
label.setText("TESTING");
|
||||
rVal.addWidget(label);
|
||||
|
||||
// TextInput textInput2 = new TextInput();
|
||||
// textInput2.setText("TESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\nTESTESTE$STESTET\n");
|
||||
@ -114,5 +121,37 @@ public class WidgetUtils {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static Widget createInGameMainMenuButton(){
|
||||
int width = (int)(Globals.WINDOW_WIDTH * 0.05);
|
||||
int height = (int)(Globals.WINDOW_HEIGHT * 0.05);
|
||||
int x = Globals.WINDOW_WIDTH - width;
|
||||
int y = Globals.WINDOW_HEIGHT - height;
|
||||
// Window rVal = new Window(x, 10, 100, 20);
|
||||
Window rVal = new Window(x,y,width,height);
|
||||
// Window rVal = new Window(100,100,100,100);
|
||||
// System.out.println(x + " " + y + " " + width + " " + height);
|
||||
// LayoutSchemeListScrollable rVal = new LayoutSchemeListScrollable(x, y, width, height, true);
|
||||
//// rVal.addWidget(createVerticallyAlignedMinSizeTextBoxFromCharCount(25, 25, 0, "TESTESTESTEST", true));
|
||||
// rVal.addWidget(WidgetUtils.createTextBox(0, 0, width, height, 1, 4, "MENU", true));
|
||||
// Widget rVal = WidgetUtils.createTextBox(x, y, width, height, 4, 1, "MENU", true);
|
||||
|
||||
//the actual "menu" label
|
||||
Label menuLabel = new Label(0,0,0.3f);
|
||||
menuLabel.setText("Menu");
|
||||
menuLabel.setVisible(true);
|
||||
rVal.addWidget(menuLabel);
|
||||
|
||||
//label telling player what key they have their menu bound to
|
||||
Label keyCodeLabel = new Label(0,10,0.3f);
|
||||
keyCodeLabel.setText(ControlHandler.convertKeycodeToName(Globals.controlHandler.getControl(ControlHandler.DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).getKeyValue()));
|
||||
keyCodeLabel.setVisible(true);
|
||||
rVal.addWidget(keyCodeLabel);
|
||||
|
||||
rVal.setVisible(false);
|
||||
// Globals.inGameUI.add(rVal);
|
||||
Globals.widgetManager.registerWidget(rVal);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -27,8 +27,8 @@ public class Window extends Widget {
|
||||
|
||||
public Window(int positionX, int positionY, int width, int height){
|
||||
//TODO: figure out why this has to be 1920x1080
|
||||
// widgetBuffer = FramebufferUtils.generateTextureFramebuffer(width, height);
|
||||
widgetBuffer = FramebufferUtils.generateScreensizeTextureFramebuffer();
|
||||
widgetBuffer = FramebufferUtils.generateTextureFramebuffer(width, height);
|
||||
// widgetBuffer = FramebufferUtils.generateScreensizeTextureFramebuffer();
|
||||
customMat.setTexturePointer(widgetBuffer.getTexturePointer());
|
||||
// customMat.setTexturePointer(Globals.assetManager.fetchTexture("Textures/Testing1.png").getTexturePointer());
|
||||
float ndcX = (float)positionX/Globals.WINDOW_WIDTH;
|
||||
@ -47,7 +47,7 @@ public class Window extends Widget {
|
||||
widgetBuffer.bind();
|
||||
// Globals.renderingEngine.setViewportSize(width, height);
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
for(Widget child : widgetList){
|
||||
|
||||
@ -11,6 +11,7 @@ import electrosphere.renderer.ui.font.RawFontMap.Glyph;
|
||||
import java.util.HashMap;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -23,6 +24,9 @@ public class FontUtils {
|
||||
static HashMap<Character,Vector3f> positionMap = new HashMap();
|
||||
static HashMap<Character,Vector3f> dimensionMap = new HashMap();
|
||||
|
||||
static int width = 10;
|
||||
static int height = 10;
|
||||
|
||||
public static Vector3f getPositionOfCharacter(char character){
|
||||
Vector3f position;
|
||||
if((position = positionMap.get(character))!=null){
|
||||
@ -47,8 +51,24 @@ public class FontUtils {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
public static Vector3f getDimensionOfCharacterDiscrete(char character){
|
||||
Vector3f dimension;
|
||||
if((dimension = dimensionMap.get(character))!=null){
|
||||
dimension = new Vector3f(dimension);
|
||||
} else {
|
||||
dimension = new Vector3f(12,14,0f);
|
||||
}
|
||||
return dimension;
|
||||
}
|
||||
|
||||
public static int getFontHeight(){
|
||||
return height;
|
||||
}
|
||||
|
||||
public static void setFontDataMap(RawFontMap map){
|
||||
rawFontMap = map;
|
||||
width = map.imageWidth;
|
||||
height = map.imageHeight;
|
||||
//fill position map
|
||||
positionMap.clear();
|
||||
for(Glyph glyph : rawFontMap.glyphs){
|
||||
|
||||
@ -51,11 +51,9 @@ public class BitmapCharacter extends Widget {
|
||||
Globals.renderingEngine.bindFramebuffer(parentFramebufferPointer);
|
||||
Globals.renderingEngine.setViewportSize(parentWidth, parentHeight);
|
||||
float ndcX = (float)positionX/parentWidth;
|
||||
float ndcY = (float)positionY/parentHeight + (float)Globals.WINDOW_TITLE_BAR_HEIGHT/parentHeight;
|
||||
float ndcY = (float)positionY/parentHeight;// + (float)Globals.WINDOW_TITLE_BAR_HEIGHT/parentHeight;
|
||||
float ndcWidth = (float)width/parentWidth;
|
||||
float ndcHeight = (float)height/parentHeight;
|
||||
// System.out.println(ndcX + " " + ndcY + " " + ndcWidth + " " + ndcHeight);
|
||||
//monowidth for the moment
|
||||
// float charWidth = ndcWidth/cols;
|
||||
// float charHeight = ndcHeight/rows;
|
||||
char toDraw = text.charAt(0);
|
||||
|
||||
66
src/main/java/electrosphere/renderer/ui/label/Label.java
Normal file
66
src/main/java/electrosphere/renderer/ui/label/Label.java
Normal file
@ -0,0 +1,66 @@
|
||||
package electrosphere.renderer.ui.label;
|
||||
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.renderer.Model;
|
||||
import electrosphere.renderer.ui.Widget;
|
||||
import electrosphere.renderer.ui.font.FontUtils;
|
||||
import electrosphere.renderer.ui.font.bitmapchar.BitmapCharacter;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class Label extends Widget{
|
||||
|
||||
String text = "";
|
||||
int textPixelWidth = 0;
|
||||
|
||||
float fontSize = 1.0f;
|
||||
|
||||
List<Widget> childrenElements = new LinkedList();
|
||||
|
||||
public Label(int x, int y, float fontSize){
|
||||
this.positionX = x;
|
||||
this.positionY = y;
|
||||
this.width = 0;
|
||||
this.height = (int)(FontUtils.getFontHeight() * fontSize);
|
||||
this.fontSize = fontSize;
|
||||
}
|
||||
|
||||
void generateLetters(){
|
||||
childrenElements.clear();
|
||||
int rollingOffset = 0;
|
||||
for(int i = 0; i < text.length(); i++){
|
||||
char toDraw = text.charAt(i);
|
||||
Vector3f bitMapDimension = FontUtils.getDimensionOfCharacterDiscrete(toDraw);
|
||||
Widget newLetter = new BitmapCharacter((int)(rollingOffset * fontSize) + positionX, positionY, (int)(bitMapDimension.x * fontSize), this.height, toDraw);
|
||||
rollingOffset += (int)bitMapDimension.x;
|
||||
childrenElements.add(newLetter);
|
||||
}
|
||||
}
|
||||
|
||||
public void setText(String text){
|
||||
this.text = text;
|
||||
textPixelWidth = 0;
|
||||
for(int i = 0; i < text.length(); i++){
|
||||
Vector3f bitMapDimension = FontUtils.getDimensionOfCharacterDiscrete(text.charAt(i));
|
||||
textPixelWidth = textPixelWidth + (int)bitMapDimension.x;
|
||||
}
|
||||
generateLetters();
|
||||
}
|
||||
|
||||
public String getText(){
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int parentFramebufferPointer, int parentWidth, int parentHeight) {
|
||||
for(Widget child : childrenElements){
|
||||
child.draw(parentFramebufferPointer, parentWidth, parentHeight);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -24,14 +24,17 @@ public class ImagePanel extends Widget {
|
||||
Material customMat = new Material();
|
||||
Texture texture = null;
|
||||
|
||||
Vector3f boxPosition = new Vector3f(0,0,0);
|
||||
Vector3f boxDimensions = new Vector3f(1,1,0);
|
||||
|
||||
Vector3f texPosition = new Vector3f(0,0,0);
|
||||
Vector3f texScale = new Vector3f(1,1,0);
|
||||
|
||||
public ImagePanel(){
|
||||
public ImagePanel(int x, int y, int width, int height){
|
||||
texture = Globals.assetManager.fetchTexture("Textures/default_diffuse.png");
|
||||
customMat.setTexturePointer(texture.getTexturePointer());
|
||||
this.positionX = x;
|
||||
this.positionY = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void setTexture(Texture texture){
|
||||
@ -41,34 +44,6 @@ public class ImagePanel extends Widget {
|
||||
public Texture getTexture(){
|
||||
return texture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPositionY(int positionY) {
|
||||
float ndcY = (float)positionY/Globals.WINDOW_HEIGHT;
|
||||
boxPosition.y = ndcY;
|
||||
super.setPositionY(positionY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPositionX(int positionX) {
|
||||
float ndcX = (float)positionX/Globals.WINDOW_WIDTH;
|
||||
boxPosition.x = ndcX;
|
||||
super.setPositionX(positionX);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeight(int height) {
|
||||
float ndcHeight = (float)height/Globals.WINDOW_HEIGHT;
|
||||
boxDimensions.y = ndcHeight;
|
||||
super.setHeight(height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidth(int width) {
|
||||
float ndcWidth = (float)width/Globals.WINDOW_WIDTH;
|
||||
boxDimensions.x = ndcWidth;
|
||||
super.setWidth(width);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -78,6 +53,14 @@ public class ImagePanel extends Widget {
|
||||
//have to call before actually rendering
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, parentFramebufferPointer);
|
||||
|
||||
float ndcX = (float)positionX/parentWidth;
|
||||
float ndcY = (float)positionY/parentHeight;
|
||||
float ndcWidth = (float)width/parentWidth;
|
||||
float ndcHeight = (float)height/parentHeight;
|
||||
|
||||
Vector3f boxPosition = new Vector3f(ndcX,ndcY,0);
|
||||
Vector3f boxDimensions = new Vector3f(ndcWidth,ndcHeight,0);
|
||||
|
||||
Model planeModel = Globals.assetManager.fetchModel(Globals.planeModelID);
|
||||
planeModel.pushUniformToMesh("plane", "mPosition", boxPosition);
|
||||
planeModel.pushUniformToMesh("plane", "mDimension", boxDimensions);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user