diff --git a/assets/Textures/Fonts/myFont2Map.json b/assets/Textures/Fonts/myFont2Map.json new file mode 100644 index 00000000..d41782e3 --- /dev/null +++ b/assets/Textures/Fonts/myFont2Map.json @@ -0,0 +1,483 @@ +{ + "imageWidth": 3864, + "imageHeight": 60, + "glyphs": +[ + { + "symbol": "A", + "startX": 1, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "B", + "startX": 43, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "C", + "startX": 85, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "D", + "startX": 127, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "E", + "startX": 169, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "F", + "startX": 211, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "G", + "startX": 253, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "H", + "startX": 295, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "I", + "startX": 337, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "J", + "startX": 379, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "K", + "startX": 421, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "L", + "startX": 463, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "M", + "startX": 505, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "N", + "startX": 547, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "O", + "startX": 589, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "P", + "startX": 631, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "Q", + "startX": 673, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "R", + "startX": 715, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "S", + "startX": 757, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "T", + "startX": 799, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "U", + "startX": 841, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "V", + "startX": 883, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "W", + "startX": 925, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "X", + "startX": 967, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "Y", + "startX": 1009, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "Z", + "startX": 1051, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "a", + "startX": 1093, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "b", + "startX": 1135, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "c", + "startX": 1177, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "d", + "startX": 1219, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "e", + "startX": 1261, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "f", + "startX": 1303, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "g", + "startX": 1345, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "h", + "startX": 1387, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "i", + "startX": 1429, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "j", + "startX": 1471, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "k", + "startX": 1513, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "l", + "startX": 1555, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "m", + "startX": 1597, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "n", + "startX": 1639, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "o", + "startX": 1681, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "p", + "startX": 1723, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "q", + "startX": 1765, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "r", + "startX": 1807, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "s", + "startX": 1849, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "t", + "startX": 1891, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "u", + "startX": 1933, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "v", + "startX": 1975, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "w", + "startX": 2017, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "x", + "startX": 2059, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "y", + "startX": 2101, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "z", + "startX": 2143, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "1", + "startX": 2185, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "2", + "startX": 2227, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "3", + "startX": 2269, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "4", + "startX": 2311, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "5", + "startX": 2353, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "6", + "startX": 2395, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "7", + "startX": 2437, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "8", + "startX": 2479, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "9", + "startX": 2521, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "0", + "startX": 2563, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": ".", + "startX": 2605, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "!", + "startX": 2647, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "?", + "startX": 2689, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "\"", + "startX": 2731, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": "'", + "startX": 2773, + "startY": 1, + "width": 40, + "height": 58 + }, + { + "symbol": ",", + "startX": 2815, + "startY": 1, + "width": 40, + "height": 58 + } +] +} \ No newline at end of file diff --git a/assets/Textures/Fonts/myfont2.png b/assets/Textures/Fonts/myfont2.png new file mode 100644 index 00000000..4af3caf8 Binary files /dev/null and b/assets/Textures/Fonts/myfont2.png differ diff --git a/src/main/java/electrosphere/controls/ControlHandler.java b/src/main/java/electrosphere/controls/ControlHandler.java index c3f2e9e5..9d7895b9 100644 --- a/src/main/java/electrosphere/controls/ControlHandler.java +++ b/src/main/java/electrosphere/controls/ControlHandler.java @@ -300,6 +300,7 @@ public class ControlHandler { case IN_GAME_MAIN_MENU: runHandlers(menuNavigationControlList); + runHandlers(typingControlList); // pollMenuNavigationControls(); break; diff --git a/src/main/java/electrosphere/main/Globals.java b/src/main/java/electrosphere/main/Globals.java index ecf6f258..d598e54d 100644 --- a/src/main/java/electrosphere/main/Globals.java +++ b/src/main/java/electrosphere/main/Globals.java @@ -370,7 +370,7 @@ public class Globals { //create default lights assetManager.registerModelToSpecificString(RenderUtils.createBitmapDisplay(), AssetDataStrings.ASSET_STRING_BITMAP_FONT); assetManager.registerModelToSpecificString(RenderUtils.createBitmapCharacter(), AssetDataStrings.BITMAP_CHARACTER_MODEL); - RawFontMap fontMap = FileUtils.loadObjectFromAssetPath("Textures/Fonts/myFontMap.json", RawFontMap.class); + RawFontMap fontMap = FileUtils.loadObjectFromAssetPath("Textures/Fonts/myFont2Map.json", RawFontMap.class); FontUtils.setFontDataMap(fontMap); //particle billboard model particleBillboardModel = assetManager.registerModel(RenderUtils.createParticleModel()); diff --git a/src/main/java/electrosphere/menu/MenuGenerators.java b/src/main/java/electrosphere/menu/MenuGenerators.java index f03b4d13..7230ca96 100644 --- a/src/main/java/electrosphere/menu/MenuGenerators.java +++ b/src/main/java/electrosphere/menu/MenuGenerators.java @@ -13,6 +13,7 @@ import electrosphere.game.server.saves.SaveUtils; import electrosphere.main.Globals; import electrosphere.main.Main; import electrosphere.net.NetUtils; +import electrosphere.renderer.Model; import electrosphere.renderer.RenderingEngine; import electrosphere.renderer.ui.ClickableElement; import electrosphere.renderer.ui.DrawableElement; @@ -537,21 +538,42 @@ public class MenuGenerators { return false; }}); + + //text entry (port) + TextInput modelDebugInput = new TextInput(100,150, 40*5, 40); + scrollable.addChild(modelDebugInput); + modelDebugInput.setText("Model path goes here"); + modelDebugInput.setOnFocus(new FocusEventCallback() {public boolean execute(FocusEvent event) { + return false; + }}); + modelDebugInput.setOnLoseFocus(new FocusEventCallback() {public boolean execute(FocusEvent event) { + return false; + }}); //label 2 (quit) Button quitButton = new Button(); - Label quitLabel = new Label(100,150,fontSize); - quitLabel.setText("debug or smthn"); + Label quitLabel = new Label(100,250,fontSize); + quitLabel.setText("Print Model Debug Info"); quitButton.addChild(quitLabel); scrollable.addChild(quitButton); quitButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){ // Main.running = false; + Model targetModel = null; + if((targetModel = Globals.assetManager.fetchModel(modelDebugInput.getText())) != null){ + targetModel.describeHighLevel(); + } else { + Globals.assetManager.addModelPathToQueue(modelDebugInput.getText()); + Globals.assetManager.loadAssetsInQueue(); + if((targetModel = Globals.assetManager.fetchModel(modelDebugInput.getText())) != null){ + targetModel.describeHighLevel(); + } + } return false; }}); - for(int i = 0; i < 10; i++){ + for(int i = 0; i < 9; i++){ Button someButton = new Button(); - Label someLabel = new Label(100,250 + i * 100,fontSize); + Label someLabel = new Label(100,350 + i * 100,fontSize); someLabel.setText("aaaaaa" + i); someButton.addChild(someLabel); scrollable.addChild(someButton); diff --git a/src/main/java/electrosphere/renderer/RenderUtils.java b/src/main/java/electrosphere/renderer/RenderUtils.java index b53d8dec..6d67b9bb 100644 --- a/src/main/java/electrosphere/renderer/RenderUtils.java +++ b/src/main/java/electrosphere/renderer/RenderUtils.java @@ -797,9 +797,9 @@ public class RenderUtils { m.nodeID = AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME; Material uiMat = new Material(); - Globals.assetManager.addTexturePathtoQueue("/Textures/Fonts/myfont1-harsher.png"); - uiMat.set_diffuse("/Textures/Fonts/myfont1-harsher.png"); - uiMat.set_specular("/Textures/Fonts/myfont1-harsher.png"); + Globals.assetManager.addTexturePathtoQueue("/Textures/Fonts/myfont2.png"); + uiMat.set_diffuse("/Textures/Fonts/myfont2.png"); + uiMat.set_specular("/Textures/Fonts/myfont2.png"); m.setMaterial(uiMat); rVal.materials = new ArrayList(); rVal.materials.add(uiMat); diff --git a/src/main/java/electrosphere/renderer/ui/elements/TextInput.java b/src/main/java/electrosphere/renderer/ui/elements/TextInput.java index 4a379cf2..38d981d1 100644 --- a/src/main/java/electrosphere/renderer/ui/elements/TextInput.java +++ b/src/main/java/electrosphere/renderer/ui/elements/TextInput.java @@ -8,7 +8,9 @@ import electrosphere.renderer.framebuffer.Framebuffer; import electrosphere.renderer.framebuffer.FramebufferUtils; import electrosphere.renderer.texture.Texture; import electrosphere.renderer.ui.DrawableElement; +import electrosphere.renderer.ui.FocusableElement; import electrosphere.renderer.ui.events.Event; +import electrosphere.renderer.ui.events.FocusEvent; import electrosphere.renderer.ui.font.FontUtils; import org.joml.Vector3f; import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER; @@ -18,7 +20,7 @@ import static org.lwjgl.opengl.GL30.glBindFramebuffer; * * @author amaterasu */ -public class TextInput implements DrawableElement { +public class TextInput implements DrawableElement, FocusableElement { Framebuffer widgetBuffer; Material customMat = new Material(); @@ -35,6 +37,10 @@ public class TextInput implements DrawableElement { int linePaddingHorizonal = 2; int linePaddingVertical = 5; + + boolean focused = false; + FocusEventCallback onFocusCallback = null; + FocusEventCallback onLoseFocusCallback = null; Vector3f color = new Vector3f(0,0,0); @@ -82,7 +88,6 @@ public class TextInput implements DrawableElement { public void setWidth(int width) { float ndcWidth = (float)width/(float)parentWidth; boxDimensions.x = ndcWidth; - System.out.println(ndcWidth); Framebuffer newBuffer = FramebufferUtils.generateTextureFramebuffer(width, height); Framebuffer oldBuffer = widgetBuffer; widgetBuffer = newBuffer; @@ -217,7 +222,34 @@ public class TextInput implements DrawableElement { } public boolean handleEvent(Event event){ - return true; + boolean propagate = true; + if(event instanceof FocusEvent){ + this.focused = ((FocusEvent)event).isFocused(); + if(this.focused && onFocusCallback != null){ + propagate = onFocusCallback.execute((FocusEvent)event); + } else if(!this.focused && onLoseFocusCallback != null){ + propagate = onLoseFocusCallback.execute((FocusEvent)event); + } + } + return propagate; + } + + @Override + public boolean isFocused() { + // TODO Auto-generated method stub + return focused; + } + + @Override + public void setOnFocus(FocusEventCallback callback) { + // TODO Auto-generated method stub + onFocusCallback = callback; + } + + @Override + public void setOnLoseFocus(FocusEventCallback callback) { + // TODO Auto-generated method stub + onLoseFocusCallback = callback; } }