From 6cb6ba8c1186ca222ce94ceae4c0654f7d1f7087 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Fri, 28 Jan 2022 14:04:24 +0100 Subject: [PATCH] Added start of demo code. --- .../distributedrebirth/demo4d/Demo4DMain.java | 64 +++-- .../demo4d/matrix4d/ScreenMatrix4D.java | 255 ++++++++++++++++++ .../demo4d/matrix4d/UserColorShader.java | 71 +++++ .../demo4d/screen/BasicConsoleRenderer.java | 29 ++ .../demo4d/screen/HebrewWalletRenderer.java | 58 ++++ .../demo4d/screen/ScreenCredits.java | 87 ++++++ .../demo4d/screen/ScreenDefault.java | 31 +++ .../demo4d/screen/ScreenHelp.java | 59 ++++ .../demo4d/screen/ScreenIntro.java | 57 ++++ .../demo4d/screen/ScreenIntroMission.java | 75 ++++++ .../demo4d/screen/ScreenUnicode4D.java | 53 ++++ .../demo4d/screen/ScrollScreenAdapter.java | 80 ++++++ 12 files changed, 900 insertions(+), 19 deletions(-) create mode 100644 core/src/love/distributedrebirth/demo4d/matrix4d/ScreenMatrix4D.java create mode 100644 core/src/love/distributedrebirth/demo4d/matrix4d/UserColorShader.java create mode 100644 core/src/love/distributedrebirth/demo4d/screen/BasicConsoleRenderer.java create mode 100644 core/src/love/distributedrebirth/demo4d/screen/HebrewWalletRenderer.java create mode 100644 core/src/love/distributedrebirth/demo4d/screen/ScreenCredits.java create mode 100644 core/src/love/distributedrebirth/demo4d/screen/ScreenDefault.java create mode 100644 core/src/love/distributedrebirth/demo4d/screen/ScreenHelp.java create mode 100644 core/src/love/distributedrebirth/demo4d/screen/ScreenIntro.java create mode 100644 core/src/love/distributedrebirth/demo4d/screen/ScreenIntroMission.java create mode 100644 core/src/love/distributedrebirth/demo4d/screen/ScreenUnicode4D.java create mode 100644 core/src/love/distributedrebirth/demo4d/screen/ScrollScreenAdapter.java diff --git a/core/src/love/distributedrebirth/demo4d/Demo4DMain.java b/core/src/love/distributedrebirth/demo4d/Demo4DMain.java index da1ad841..c2b182d6 100644 --- a/core/src/love/distributedrebirth/demo4d/Demo4DMain.java +++ b/core/src/love/distributedrebirth/demo4d/Demo4DMain.java @@ -15,7 +15,17 @@ import com.badlogic.gdx.utils.ScreenUtils; import imgui.ImGui; import imgui.type.ImBoolean; +import love.distributedrebirth.demo4d.matrix4d.ScreenMatrix4D; import love.distributedrebirth.demo4d.music.MusicManager; +import love.distributedrebirth.demo4d.music.MusicPlayerRenderer; +import love.distributedrebirth.demo4d.screen.BasicConsoleRenderer; +import love.distributedrebirth.demo4d.screen.HebrewWalletRenderer; +import love.distributedrebirth.demo4d.screen.ScreenCredits; +import love.distributedrebirth.demo4d.screen.ScreenDefault; +import love.distributedrebirth.demo4d.screen.ScreenHelp; +import love.distributedrebirth.demo4d.screen.ScreenIntro; +import love.distributedrebirth.demo4d.screen.ScreenIntroMission; +import love.distributedrebirth.demo4d.screen.ScreenUnicode4D; import net.spookygames.gdx.nativefilechooser.NativeFileChooser; public class Demo4DMain extends Game { @@ -29,10 +39,11 @@ public class Demo4DMain extends Game { public MusicManager music; private Map,Screen> screens; + private Map,ImGuiRenderer> widgets; private ImBoolean showImGuiDemo = new ImBoolean(false); private ImBoolean showMusicPlayer = new ImBoolean(false); private ImBoolean showHebrewWallet = new ImBoolean(false); - private MainScreenRender render; + private ImBoolean showBasicConsole = new ImBoolean(false); public Demo4DMain(List args, NativeFileChooser fileChooser) { this.args = args; @@ -51,9 +62,11 @@ public class Demo4DMain extends Game { music = new MusicManager(); music.init(); - render = new MainScreenRender(this); - ImGuiSetup.init(); + widgets = new HashMap<>(); + putWidget(new MusicPlayerRenderer(this)); + putWidget(new HebrewWalletRenderer(this)); + putWidget(new BasicConsoleRenderer(this)); screens = new HashMap<>(); putScreen(new ScreenIntro(this)); @@ -86,6 +99,10 @@ public class Demo4DMain extends Game { screens.put(screen.getClass(), screen); } + private void putWidget(ImGuiRenderer widget) { + widgets.put(widget.getClass(), widget); + } + public void selectScreen(Class screenClass) { Screen screen = screens.get(screenClass); if (screen == null) { @@ -106,10 +123,13 @@ public class Demo4DMain extends Game { ImGui.showDemoWindow(showImGuiDemo); } if (showMusicPlayer.get()) { - //render.renderMusicPlayer(showMusicPlayer); + widgets.get(MusicPlayerRenderer.class).render(showMusicPlayer); } if (showHebrewWallet.get()) { - render.renderHebrewWallet(showHebrewWallet); + widgets.get(HebrewWalletRenderer.class).render(showHebrewWallet); + } + if (showBasicConsole.get()) { + widgets.get(BasicConsoleRenderer.class).render(showBasicConsole); } if (screen != null) { screen.render(Gdx.graphics.getDeltaTime()); @@ -130,20 +150,6 @@ public class Demo4DMain extends Game { if (ImGui.menuItem("Unicode4D")) { selectScreen(ScreenUnicode4D.class); } - if (ImGui.menuItem("Hebrew Wallet")) { - showHebrewWallet.set(true); - } - ImGui.separator(); - if (ImGui.menuItem("ImGui")) { - showImGuiDemo.set(true); - } - ImGui.separator(); - if (ImGui.menuItem("Stop Music")) { - music.stop(); - } - if (ImGui.menuItem("Music Player")) { - showMusicPlayer.set(true); - } ImGui.separator(); if (ImGui.menuItem("Exit")) { dispose(); @@ -151,6 +157,26 @@ public class Demo4DMain extends Game { } ImGui.endMenu(); } + if (ImGui.beginMenu("Widgets")) { + if (ImGui.menuItem("ImGui Demo")) { + showImGuiDemo.set(true); + } + ImGui.separator(); + if (ImGui.menuItem("Hebrew Wallet")) { + showHebrewWallet.set(true); + } + if (ImGui.menuItem("Basic Console")) { + showBasicConsole.set(true); + } + ImGui.separator(); + if (ImGui.menuItem("Music Player")) { + showMusicPlayer.set(true); + } + if (ImGui.menuItem("Stop Music")) { + music.stop(); + } + ImGui.endMenu(); + } if (ImGui.beginMenu("Help")) { if (ImGui.menuItem("Credits")) { selectScreen(ScreenCredits.class); diff --git a/core/src/love/distributedrebirth/demo4d/matrix4d/ScreenMatrix4D.java b/core/src/love/distributedrebirth/demo4d/matrix4d/ScreenMatrix4D.java new file mode 100644 index 00000000..e902a7c4 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/matrix4d/ScreenMatrix4D.java @@ -0,0 +1,255 @@ +package love.distributedrebirth.demo4d.matrix4d; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.PerspectiveCamera; +import com.badlogic.gdx.graphics.VertexAttributes.Usage; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.BitmapFontCache; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.g3d.Attribute; +import com.badlogic.gdx.graphics.g3d.Environment; +import com.badlogic.gdx.graphics.g3d.Material; +import com.badlogic.gdx.graphics.g3d.Model; +import com.badlogic.gdx.graphics.g3d.ModelBatch; +import com.badlogic.gdx.graphics.g3d.ModelInstance; +import com.badlogic.gdx.graphics.g3d.Shader; +import com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute; +import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute; +import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight; +import com.badlogic.gdx.graphics.g3d.utils.CameraInputController; +import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder; +import com.badlogic.gdx.math.Matrix4; +import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.utils.Align; +import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.viewport.ScreenViewport; + +import imgui.ImGui; +import imgui.flag.ImGuiCond; +import love.distributedrebirth.demo4d.Demo4DMain; +import love.distributedrebirth.demo4d.Demo4DMainAdapter; + +public class ScreenMatrix4D extends Demo4DMainAdapter { + public Environment environment; + public PerspectiveCamera cam; + public CameraInputController camController; + public Shader shader; + public ModelBatch modelBatch; + private Model grid; + private Model model; + public Array modelInstances = new Array(); + //endregion + + //region Text rendering + public BitmapFont font; + public BitmapFontCache fontCache; + + public final ScreenViewport uiViewport = new ScreenViewport(); + public SpriteBatch spriteBatch; + + /** World-space position of the text. (Corner of the cube.) */ + public Vector3 textPosition = new Vector3(2.5f, 2.5f, 2.5f); + //endregion + + private float colorDeltaTime = 0f; + private float colorFade = 0f; + private boolean colorPositive = true; + + public ScreenMatrix4D(final Demo4DMain main) { + super(main); + this.create(); + } + + private void create() { + //region 3D Objects + environment = new Environment(); + environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f)); + environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f)); + + modelBatch = new ModelBatch(); + + cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + cam.position.set(10f, 10f, 10f); + cam.lookAt(0, 0, 0); + cam.near = 1f; + cam.far = 300f; + cam.update(); + + ModelBuilder modelBuilder = new ModelBuilder(); + + Material mat = new Material(ColorAttribute.createDiffuse(1f,1f,1f,.1f)); + grid = modelBuilder.createLineGrid(33, 33, 1f, 1f, mat, Usage.Position | Usage.Normal); + + model = modelBuilder.createBox(.3f, .3f, .3f, + new Material(ColorAttribute.createDiffuse(.1f,.1f,.1f,.1f), + new BlendingAttribute(.1f) + //new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA) + ), + Usage.Position | Usage.Normal); + + //Matrix4 model1Offset = new Matrix4(new Vector3(5f,0f,0f), new Quaternion(0f,0f,0f,0f),new Vector3(1f,1f,1f)); + + Attribute bend = new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); + for (int x = -4; x < 6; x++) { + for (int y = 1; y < 11; y++) { + for (int z = -4; z < 7; z++) { + ModelInstance instance = new ModelInstance(model, x, y, z); + instance.materials.get(0).set(bend); + modelInstances.add(instance); + } + } + } + + ModelInstance instance = new ModelInstance(grid, 0, 0, 0); + //instance.materials.get(0).set(bend); + modelInstances.add(instance); + + shader = new UserColorShader(); + shader.init(); + + camController = new CameraInputController(cam); + Gdx.input.setInputProcessor(camController); + //endregion + + //region Text rendering + font = new BitmapFont(); + fontCache = new BitmapFontCache(font, false); + spriteBatch = new SpriteBatch(); + //endregion + } + + /** + * Multiply 4x4 matrix {@code m} and 4D vector {$code (v, vW)} together. + * Store result {@code (x/w, y/w, z/w)} back in {@code v} and return {@code w}. + */ + private static float multiplyProjective(Matrix4 m, Vector3 v, float vW) { + final float[] mat = m.val; + final float x = v.x * mat[Matrix4.M00] + v.y * mat[Matrix4.M01] + v.z * mat[Matrix4.M02] + vW * mat[Matrix4.M03]; + final float y = v.x * mat[Matrix4.M10] + v.y * mat[Matrix4.M11] + v.z * mat[Matrix4.M12] + vW * mat[Matrix4.M13]; + final float z = v.x * mat[Matrix4.M20] + v.y * mat[Matrix4.M21] + v.z * mat[Matrix4.M22] + vW * mat[Matrix4.M23]; + final float w = v.x * mat[Matrix4.M30] + v.y * mat[Matrix4.M31] + v.z * mat[Matrix4.M32] + vW * mat[Matrix4.M33]; + final float iw = 1f / w; + v.set(x * iw, y * iw, z * iw); + return w; + } + + @Override + public void render(float delta) { + colorDeltaTime += delta; + if (colorDeltaTime > 0.04f) { + colorDeltaTime = 0f; + if (colorPositive) { + colorFade += delta; + } else { + colorFade -= delta; + } + if (colorFade > 1f) { + colorPositive = false; + } else if (colorFade < .5f) { + colorPositive = true; + } + } + + int i=0; + for (int x = -4; x < 6; x++) { + for (int y = 1; y < 11; y++) { + for (int z = -4; z < 7; z++) { + float red = .1f; + float green = (y+2f)/10f*colorFade; + float blue = .1f; + if (x == 3 || y == 1 || z == -1) { + red = (y+2f)/10f*colorFade; + green = 0f; + } + if (x == -1 || y == 10 || z == 5) { + green = 0f; + blue = (y+2f)/10f*colorFade; + } + + ModelInstance instance = modelInstances.get(i++); + ColorAttribute attr = ColorAttribute.createDiffuse(red, green, blue, .2f); + instance.materials.get(0).set(attr); + } + } + } + + //region 3D Objects + camController.update(); + + Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); + + modelBatch.begin(cam); + for (ModelInstance instance : modelInstances) { + modelBatch.render(instance, shader); + } + modelBatch.end(); + //endregion + + //region Text rendering + + // Multiply vector with world-space position with 3D projection-view matrix + final Vector3 clipSpacePos = new Vector3(textPosition); + final float w = multiplyProjective(cam.combined, clipSpacePos, 1f); + + // Do not render the text if it is behind the camera or too far away + if (clipSpacePos.z >= -1f && clipSpacePos.z <= 1f) { + // Calculate the position on screen (clip space is [-1,1], we need [-size/2, size/2], but this depends on your viewport) + final float textPosX = clipSpacePos.x * Gdx.graphics.getWidth() * 0.5f; + final float textPosY = clipSpacePos.y * Gdx.graphics.getHeight() * 0.5f; + + // Set the text normally. The position must be 0, otherwise the scaling won't work. + // If you don't want perspective scaling, you can set x,y to textPosX,textPosY directly and skip the next part. + fontCache.setText("Now in 3D", 0f, 0, 0f, Align.center, false); + + // Size of the text in the world + final float fontSize = 5f; + // Scaling factor + final float fontScale = fontSize / w; + // Go through prepared vertices of the font cache and do necessary transformation + final int regionCount = font.getRegions().size; + for (int page = 0; page < regionCount; page++) { + final int vertexCount = fontCache.getVertexCount(page); + final float[] vertices = fontCache.getVertices(page); + for (int v = 0; v < vertexCount; v += 5) { + // This is why the text position must be 0 - otherwise the scaling would move the text + vertices[v] = vertices[v] * fontScale + textPosX; + vertices[v + 1] = vertices[v + 1] * fontScale + textPosY; + } + } + + // Standard viewport update + uiViewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true); + spriteBatch.setProjectionMatrix(uiViewport.getCamera().projection); + // Draw the text normally + spriteBatch.begin(); + fontCache.draw(spriteBatch); + spriteBatch.end(); + } + //endregion + + + ImGui.setNextWindowPos(300, 300, ImGuiCond.FirstUseEver); + ImGui.setNextWindowSize(320, 240, ImGuiCond.FirstUseEver); + ImGui.begin("Legends"); + + ImGui.text("ComputerNode: XCV 330"); + ImGui.text("ComputerMatrix: 100 crew and 850 passengers"); + ImGui.separator(); + ImGui.textColored(255, 1, 1, 255, "Red is absolute line."); + ImGui.textColored(10, 1, 255, 255, "Blue is absolute line."); + ImGui.textColored(255, 1, 255, 255, "Pink is absolute node."); + ImGui.textColored(1, 255, 1, 255, "Green is relative node."); + ImGui.textColored(200, 200, 5, 255, "Yellow is I/O node."); + ImGui.textColored(1, 1, 1, 255, "White is dipavali route."); + ImGui.end(); + } + + @Override + public void dispose() { + shader.dispose(); + modelBatch.dispose(); + model.dispose(); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/matrix4d/UserColorShader.java b/core/src/love/distributedrebirth/demo4d/matrix4d/UserColorShader.java new file mode 100644 index 00000000..4cc0acd4 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/matrix4d/UserColorShader.java @@ -0,0 +1,71 @@ +package love.distributedrebirth.demo4d.matrix4d; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Camera; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.g3d.Renderable; +import com.badlogic.gdx.graphics.g3d.Shader; +import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute; +import com.badlogic.gdx.graphics.g3d.utils.RenderContext; +import com.badlogic.gdx.graphics.glutils.ShaderProgram; +import com.badlogic.gdx.utils.GdxRuntimeException; + +public class UserColorShader implements Shader { + ShaderProgram program; + Camera camera; + RenderContext context; + int u_projTrans; + int u_worldTrans; + int u_color; + + @Override + public void init () { + String vert = Gdx.files.internal("shader/color.vertex.glsl").readString(); + String frag = Gdx.files.internal("shader/color.fragment.glsl").readString(); + program = new ShaderProgram(vert, frag); + if (!program.isCompiled()) { + throw new GdxRuntimeException(program.getLog()); + } + u_projTrans = program.getUniformLocation("u_projTrans"); + u_worldTrans = program.getUniformLocation("u_worldTrans"); + u_color = program.getUniformLocation("u_color"); + } + + @Override + public void dispose () { + program.dispose(); + } + + @Override + public void begin (Camera camera, RenderContext context) { + this.camera = camera; + this.context = context; + program.bind(); + program.setUniformMatrix(u_projTrans, camera.combined); + context.setDepthTest(GL20.GL_LEQUAL); + context.setCullFace(GL20.GL_BACK); + } + + @Override + public void render (Renderable renderable) { + program.setUniformMatrix(u_worldTrans, renderable.worldTransform); + Color color = ((ColorAttribute)renderable.material.get(ColorAttribute.Diffuse)).color; + program.setUniformf(u_color, color.r, color.g, color.b, color.a); + renderable.meshPart.render(program); + } + + @Override + public void end () { + } + + @Override + public int compareTo (Shader other) { + return 0; + } + + @Override + public boolean canRender(Renderable renderable) { + return renderable.material.has(ColorAttribute.Diffuse); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/screen/BasicConsoleRenderer.java b/core/src/love/distributedrebirth/demo4d/screen/BasicConsoleRenderer.java new file mode 100644 index 00000000..e0b51ba4 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/screen/BasicConsoleRenderer.java @@ -0,0 +1,29 @@ +package love.distributedrebirth.demo4d.screen; + +import imgui.ImGui; +import imgui.flag.ImGuiCond; +import imgui.type.ImBoolean; +import love.distributedrebirth.demo4d.Demo4DMain; +import love.distributedrebirth.demo4d.ImGuiRendererMain; + +public class BasicConsoleRenderer extends ImGuiRendererMain { + + public BasicConsoleRenderer(Demo4DMain main) { + super(main); + } + + @Override + public void render(ImBoolean widgetOpen) { + ImGui.setNextWindowPos(300, 300, ImGuiCond.FirstUseEver); + ImGui.setNextWindowSize(320, 240, ImGuiCond.FirstUseEver); + ImGui.begin("The BASIC Shahada of DUNE", widgetOpen); + ImGui.text("10 PRINT \"THERE IS NO GOD BUT @Ω\u4ed9⁴\""); + ImGui.text("20 PRINT \"THERE IS NO RULE BUT CONSENT\""); + ImGui.text("30 PRINT \"THERE IS NO FAILURE BUT DEATH\""); + ImGui.text("40 PRINT \"TERRY A. DAVIS WAS THE PROPHET OF @Ω\u4ed9⁴\""); + ImGui.text("50 PRINT \"TERRY A. DAVIS WAS THE FIRST TRUE MENTAT\""); + ImGui.text("60 PRINT \"TERRY A. DAVIS WAS THE BEST CODER ALIVE\""); + ImGui.text("RUN"); + ImGui.end(); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/screen/HebrewWalletRenderer.java b/core/src/love/distributedrebirth/demo4d/screen/HebrewWalletRenderer.java new file mode 100644 index 00000000..2e559bd8 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/screen/HebrewWalletRenderer.java @@ -0,0 +1,58 @@ +package love.distributedrebirth.demo4d.screen; + +import imgui.ImGui; +import imgui.flag.ImGuiCond; +import imgui.flag.ImGuiTableFlags; +import imgui.type.ImBoolean; +import love.distributedrebirth.demo4d.Demo4DMain; +import love.distributedrebirth.demo4d.ImGuiRendererMain; +import love.distributedrebirth.demo4d.fraction4d.HebrewGê̄ld; + +public class HebrewWalletRenderer extends ImGuiRendererMain { + + public HebrewWalletRenderer(Demo4DMain main) { + super(main); + } + + @Override + public void render(ImBoolean widgetOpen) { + ImGui.setNextWindowPos(200, 200, ImGuiCond.FirstUseEver); + ImGui.setNextWindowSize(640, 480, ImGuiCond.FirstUseEver); + ImGui.begin("Hebrew Wallet", widgetOpen); + + ImGui.text("Current amount:"); + ImGui.sameLine(); + ImGui.text("0000"); + ImGui.separator(); + if (ImGui.button("Pay")) { + } + int flags = ImGuiTableFlags.ScrollX | ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersOuter | ImGuiTableFlags.BordersV; + ImGui.beginTable("wallet", 4, flags); + ImGui.tableSetupColumn("In/Out"); + ImGui.tableSetupColumn("AmountRaw"); + ImGui.tableSetupColumn("AmountFix"); + ImGui.tableSetupColumn("Decimal"); + ImGui.tableHeadersRow(); + + String[] walletData = { + "ה","מ","מָ","ח","חֱ","חֱ‎מָא", + "א","בד","ב","ד","ץףן", + "הזפץ","מספר","צצצצ","ץאאא","דואר" + }; + for (String data:walletData) { + HebrewGê̄ld geld = new HebrewGê̄ld(data); + ImGui.tableNextRow(); + ImGui.tableNextColumn(); + ImGui.text(data.length()==2||data.length()==3?"OUT":"IN"); + ImGui.tableNextColumn(); + ImGui.text(data); + ImGui.tableNextColumn(); + ImGui.text(geld.toHebrewString(true)); // true=reverse for ImGui + ImGui.tableNextColumn(); + ImGui.text(Double.toString(geld.getTotalDecimalValue())); + } + ImGui.endTable(); + + ImGui.end(); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/screen/ScreenCredits.java b/core/src/love/distributedrebirth/demo4d/screen/ScreenCredits.java new file mode 100644 index 00000000..adb38fd1 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/screen/ScreenCredits.java @@ -0,0 +1,87 @@ +package love.distributedrebirth.demo4d.screen; + +import com.badlogic.gdx.Screen; + +import love.distributedrebirth.demo4d.Demo4DMain; +import love.distributedrebirth.demo4d.music.MusicSongType; + +public class ScreenCredits extends ScrollScreenAdapter { + private final String creditsText = String.join("\n", + "Credits;", + "At-Ohm-Allah-to-the-power-of-Four", + "The King of kings", + "Thy Lord of Lords", + "Thee God of Gods", + "Abstract superset over all religions.", + " ", + "There is no god but AtohmAllah^4", + "There is no rule but consent", + "There is no failure but death", + " ", + "One long long day,", + "In a far far, fat-oddly-rounded galaxy,", + "Thy father is near.", + " ", + "Terry A. Davis;", + "- TempleOS", + "- HolyC", + "- Poems", + "- Abba music", + "- Baby fat", + " ", + "ID Tech;", + "- Ultimate DOOM", + "- SIGIL Beast Box", + "- DOOM Eternal", + " ", + "Sanctumwave Music;", + "- (music) TempleOS Hymn Risen", + "- (music) DIVINE INTELLECT", + "- (music) TERRY DAVIS NIGHTWALK", + " ", + "The Self Help Group;", + "- (music) The Self Help-Group Temple OS", + " ", + "PanoramaCircle;", + "- (music) TempleOS 'Waterfowl' poem on real hardware", + " ", + "Willem Abraham Cazander;", + "- http://distributedrebith.love", + " ", + "=============================================", + " ", + "The BASIC Shahada", + "10 PRINT \"THERE IS NO GOD BUT AT_OHM_ALLAH^4\"", + "20 PRINT \"THERE IS NO RULE BUT CONSENT\"", + "30 PRINT \"THERE IS THERE IS NO FAILURE BUT DEATH\"", + "40 PRINT \"TERRY A. DAVIS WAS THE PROPHET OF GOD\"", + "50 PRINT \"TERRY A. DAVIS WAS THE FIRST TRUE MENTAT\"", + "60 PRINT \"TERRY A. DAVIS WAS THE BEST CODER ALIVE\"", + "RUN", + " " + ); + + public ScreenCredits(final Demo4DMain main) { + super(main, "background/doom-credits.png"); + } + + @Override + protected String getScrollText() { + return creditsText; + } + + @Override + protected Class getNextScreen(Demo4DMain main) { + return ScreenDefault.class; + } + + @Override + public void show () { + main.music.play(MusicSongType.CREDITS); + } + + @Override + public void hide () { + main.music.play(MusicSongType.BACKGROUND); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/screen/ScreenDefault.java b/core/src/love/distributedrebirth/demo4d/screen/ScreenDefault.java new file mode 100644 index 00000000..6a2cf2e7 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/screen/ScreenDefault.java @@ -0,0 +1,31 @@ +package love.distributedrebirth.demo4d.screen; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.ScreenAdapter; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.utils.ScreenUtils; + +import love.distributedrebirth.demo4d.Demo4DMain; + +public class ScreenDefault extends ScreenAdapter { + private final Demo4DMain main; + private Texture backgroundImage; + + public ScreenDefault(final Demo4DMain main) { + this.main = main; + backgroundImage = new Texture(Gdx.files.internal("background/terrydavis-front.png")); + } + + @Override + public void render(float delta) { + ScreenUtils.clear(0f, 0f, 0f, 1f); + main.batch.begin(); + main.batch.draw(backgroundImage, 0, 0, main.viewWidth, main.viewHeight); + main.batch.end(); + } + + @Override + public void dispose() { + backgroundImage.dispose(); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/screen/ScreenHelp.java b/core/src/love/distributedrebirth/demo4d/screen/ScreenHelp.java new file mode 100644 index 00000000..3d7696d0 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/screen/ScreenHelp.java @@ -0,0 +1,59 @@ +package love.distributedrebirth.demo4d.screen; + +import com.badlogic.gdx.Screen; + +import love.distributedrebirth.demo4d.Demo4DMain; + +public class ScreenHelp extends ScrollScreenAdapter { + private final String creditsText = String.join("\n", + "Genesis 11", + " ", + "1 And the whole earth was of one language, and of one speech.", + " ", + "2 And it came to pass, as they journeyed from the east,", + " that they found a plain in the land of Shinar;", + " and they dwelt there.", + " ", + "3 And they said one to another, Go to, let us make brick,", + " and burn them thoroughly. And they had brick for stone,", + " and slime had they for mortar.", + " ", + "4 And they said, Go to, let us build us a city, and a tower,", + " whose top may reach unto heaven; and let us make us a name,", + " lest we be scattered abroad upon the face of the whole earth.", + " ", + "5 And the LORD came down to see the city and the tower,", + " which the children of men builded.", + " ", + "6 And the LORD said, Behold, the people is one,", + " and they have all one language; and this they begin to do:", + " and now nothing will be restrained from them,", + " which they have imagined to do.", + " ", + "7 Go to, let us go down, and there confound their language,", + " that they may not understand one another's speech.", + " ", + "8 So the LORD scattered them abroad from thence upon the face", + " of all the earth: and they left off to build the city.", + " ", + "9 Therefore is the name of it called Babel; because the LORD", + " did there confound the language of all the earth: and from", + " thence did the LORD scatter them abroad upon", + " the face of all the earth.", + " " + ); + + public ScreenHelp(final Demo4DMain main) { + super(main, "background/terrydavis-nose.png"); + } + + @Override + protected String getScrollText() { + return creditsText; + } + + @Override + protected Class getNextScreen(Demo4DMain main) { + return ScreenDefault.class; + } +} diff --git a/core/src/love/distributedrebirth/demo4d/screen/ScreenIntro.java b/core/src/love/distributedrebirth/demo4d/screen/ScreenIntro.java new file mode 100644 index 00000000..87baa430 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/screen/ScreenIntro.java @@ -0,0 +1,57 @@ +package love.distributedrebirth.demo4d.screen; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.ScreenAdapter; +import com.badlogic.gdx.Input.Keys; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.utils.ScreenUtils; + +import love.distributedrebirth.demo4d.Demo4DMain; +import love.distributedrebirth.demo4d.music.MusicSongType; + +public class ScreenIntro extends ScreenAdapter { + private final Demo4DMain main; + private Texture backgroundImage; + private float colorDeltaTime = 0f; + private boolean colorPositive = true; + + public ScreenIntro(final Demo4DMain main) { + this.main = main; + backgroundImage = new Texture(Gdx.files.internal("background/temple-os.png")); + } + + @Override + public void render(float delta) { + if (colorPositive) { + colorDeltaTime += Gdx.graphics.getDeltaTime()/2; + } else { + colorDeltaTime -= Gdx.graphics.getDeltaTime()/2; + } + if (colorDeltaTime > 1f) { + colorPositive = false; + } else if (colorDeltaTime < 0f) { + colorPositive = true; + } + ScreenUtils.clear(0.333f, colorDeltaTime, colorDeltaTime, 1); + + main.batch.begin(); + main.batch.draw(backgroundImage, 0, 0, main.viewWidth, main.viewHeight); + main.font.draw(main.batch, "Tap anywhere to begin!", main.viewWidth/2 - 73, 33); + main.batch.end(); + + if (Gdx.input.isTouched() || Gdx.input.isKeyPressed(Keys.ENTER) || Gdx.input.isKeyPressed(Keys.SPACE)) { + main.setScreen(new ScreenIntroMission(main)); + dispose(); + } + } + + @Override + public void show() { + main.music.play(MusicSongType.INTRO); + } + + @Override + public void dispose() { + backgroundImage.dispose(); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/screen/ScreenIntroMission.java b/core/src/love/distributedrebirth/demo4d/screen/ScreenIntroMission.java new file mode 100644 index 00000000..2747cd0b --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/screen/ScreenIntroMission.java @@ -0,0 +1,75 @@ +package love.distributedrebirth.demo4d.screen; + +import com.badlogic.gdx.Screen; + +import love.distributedrebirth.demo4d.Demo4DMain; +import love.distributedrebirth.demo4d.music.MusicSongType; + +public class ScreenIntroMission extends ScrollScreenAdapter { + private final String missionText = String.join("\n", + "To a Waterfowl", + " -- by William Cullen Bryant --", + " ", + "Whither, 'midst falling dew,", + "While glow the heavens with the last steps of day,", + "Far, through their rosy depths, dost thou pursue", + "Thy solitary way?", + " ", + "Vainly the fowler's eye", + "Might mark thy distant flight to do thee wrong,", + "As, darkly painted on the crimson sky,", + "Thy figure floats along.", + " ", + "Seek'st thou the plashy brink", + "Of weedy lake, or marge of river wide,", + "Or where the rocking billows rise and sink", + "On the chafed ocean side?", + " ", + "There is a Power whose care", + "Teaches thy way along that pathless coast,--", + "The desert and illimitable air,--", + "Lone wandering, but not lost.", + " ", + "All day thy wings have fann'd", + "At that far height, the cold thin atmosphere:", + "Yet stoop not, weary, to the welcome land,", + "Though the dark night is near.", + " ", + "And soon that toil shall end,", + "Soon shalt thou find a summer home, and rest,", + "And scream among thy fellows; reed shall bend", + "Soon o'er thy sheltered nest.", + " ", + "Thou'rt gone, the abyss of heaven", + "Hath swallowed up thy form; yet, on my heart", + "Deeply hath sunk the lesson thou hast given,", + "And shall not soon depart.", + " ", + "He, who, from zone to zone,", + "Guides through the boundless sky thy certain flight,", + "In the long way that I must tread alone,", + "Will lead my steps aright.", + " " + ); + + + + public ScreenIntroMission(final Demo4DMain main) { + super(main, "background/terrydavis-nose.png"); + } + + @Override + protected String getScrollText() { + return missionText; + } + + @Override + protected Class getNextScreen(Demo4DMain main) { + return ScreenDefault.class; + } + + @Override + public void hide () { + main.music.play(MusicSongType.BACKGROUND); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/screen/ScreenUnicode4D.java b/core/src/love/distributedrebirth/demo4d/screen/ScreenUnicode4D.java new file mode 100644 index 00000000..ffe8d049 --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/screen/ScreenUnicode4D.java @@ -0,0 +1,53 @@ +package love.distributedrebirth.demo4d.screen; + +import imgui.ImColor; +import imgui.ImDrawList; +import imgui.ImGui; +import imgui.ImVec2; +import imgui.flag.ImGuiCond; +import love.distributedrebirth.demo4d.Demo4DMain; +import love.distributedrebirth.demo4d.Demo4DMainAdapter; + +public class ScreenUnicode4D extends Demo4DMainAdapter { + + public ScreenUnicode4D(final Demo4DMain main) { + super(main); + } + + @Override + public void render(float delta) { + main.batch.begin(); + main.font.draw(main.batch, "Tap anywhere to begin!", main.viewWidth/2 - 73, 33); + main.batch.end(); + + ImGui.setNextWindowPos(400, 200, ImGuiCond.FirstUseEver); + ImGui.setNextWindowSize(320, 240, ImGuiCond.FirstUseEver); + ImGui.begin("Unicode4D test"); + ImGui.text("There is unicode and unicode4D"); + ImVec2 size = new ImVec2(144f, 48f); + ImGui.invisibleButton("canvas", size.x, size.y); + ImVec2 p0 = ImGui.getItemRectMin(); + ImVec2 p1 = ImGui.getItemRectMax(); + ImDrawList drawList = ImGui.getWindowDrawList(); + drawList.pushClipRect(p0.x, p0.y, p1.x, p1.y); + // draw unicode4D + //System.out.println("p0.x="+p0.x+" p0.y="+p0.y); + //System.out.println("p1.x="+p1.x+" p1.y="+p1.y); + +// for (int n = 0; n < (1.0f + Math.sin(ImGui.getTime() * 5.7f)) * 40.0f; n++) { +// drawList.addCircle(p0.x + size.x * 0.5f, p0.y + size.y * 0.5f, size.y * (0.01f + n * 0.03f), +// ImColor.intToColor(255, 140 - n * 4, n * 3, 255) +// ); +// } + + drawList.addQuad(p0.x, p0.y, p0.x+size.x, p0.y, p1.x, p1.y, p0.x, p0.y+size.y, + ImColor.intToColor(127, 127, 255, 255), 5f); + + drawList.addLine(p0.x+10, p0.y+40, p0.x+20, p0.y+10, ImColor.intToColor(255, 127, 63, 255)); + drawList.addLine(p0.x+30, p0.y+40, p0.x+20, p0.y+10, ImColor.intToColor(255, 127, 63, 255)); + drawList.addLine(p0.x+13, p0.y+30, p0.x+27, p0.y+30, ImColor.intToColor(255, 127, 63, 255)); + + drawList.popClipRect(); + ImGui.end(); + } +} diff --git a/core/src/love/distributedrebirth/demo4d/screen/ScrollScreenAdapter.java b/core/src/love/distributedrebirth/demo4d/screen/ScrollScreenAdapter.java new file mode 100644 index 00000000..da12e6aa --- /dev/null +++ b/core/src/love/distributedrebirth/demo4d/screen/ScrollScreenAdapter.java @@ -0,0 +1,80 @@ +package love.distributedrebirth.demo4d.screen; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Screen; +import com.badlogic.gdx.Input.Keys; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.utils.ScreenUtils; + +import love.distributedrebirth.demo4d.Demo4DMain; +import love.distributedrebirth.demo4d.Demo4DMainAdapter; + +abstract public class ScrollScreenAdapter extends Demo4DMainAdapter { + private static final int LINE_HEIGHT = 16; + private float scrollDeltaTime = 0f; + private String scrollText = ""; + private int scrollIndex = 0; + private int scrollLine = LINE_HEIGHT; + private final Texture backgroundImage; + + public ScrollScreenAdapter(final Demo4DMain main, String background) { + super(main); + backgroundImage = new Texture(Gdx.files.internal(background)); + } + + abstract protected String getScrollText(); + + abstract protected Class getNextScreen(Demo4DMain main); + + @Override + public final void render(float delta) { + ScreenUtils.clear(0f, 0f, 0f, 1f); + main.batch.begin(); + main.batch.draw(backgroundImage, 0, 0, main.viewWidth, main.viewHeight); + + scrollDeltaTime += delta; + if (scrollDeltaTime > 0.04f) { + scrollDeltaTime = 0f; + scrollLine++; + if (scrollLine > LINE_HEIGHT && scrollIndex != -1) { + scrollIndex = getScrollText().indexOf("\n", scrollIndex+1); + if (scrollIndex > 0) { + scrollText = getScrollText().substring(0, scrollIndex); + scrollLine = 0; + } + } + } + + int drawLine = 0; + String[] lines = scrollText.split("\n"); + for (int i=lines.length;i>0;i--) { + String line = lines[i-1]; + main.font.draw(main.batch, line, 100, scrollLine + (drawLine*LINE_HEIGHT)); + drawLine++; + } + main.batch.end(); + + if (scrollText.length() >= 33) { + if (scrollLine >= main.viewHeight || Gdx.input.isTouched() || Gdx.input.isKeyPressed(Keys.ENTER) || Gdx.input.isKeyPressed(Keys.SPACE)) { + main.selectScreen(getNextScreen(main)); + } + } + } + + @Override + public void hide() { + scrollText = ""; + scrollIndex = 0; + scrollLine = LINE_HEIGHT; + } + + @Override + public final void dispose() { + backgroundImage.dispose(); + disposeScreen(main); + } + + protected void disposeScreen(Demo4DMain main) { + // override if needed + } +}