diff --git a/src/net/torvald/terrarum/AppLoader.java b/src/net/torvald/terrarum/AppLoader.java index 8e4ff7000..a93198c9d 100644 --- a/src/net/torvald/terrarum/AppLoader.java +++ b/src/net/torvald/terrarum/AppLoader.java @@ -41,7 +41,19 @@ public class AppLoader implements ApplicationListener { private static AppLoader INSTANCE = null; - private AppLoader() { } + private static Screen injectScreen = null; + + public AppLoader(LwjglApplicationConfiguration appConfig, Screen injectScreen) { + AppLoader.injectScreen = injectScreen; + AppLoader.appConfig = appConfig; + } + + public AppLoader(LwjglApplicationConfiguration appConfig) { + AppLoader.appConfig = appConfig; + } + + public AppLoader() { + } public static AppLoader getINSTANCE() { if (INSTANCE == null) { @@ -98,7 +110,7 @@ public class AppLoader implements ApplicationListener { public static void main(String[] args) { ShaderProgram.pedantic = false; - appConfig = new LwjglApplicationConfiguration(); + LwjglApplicationConfiguration appConfig = new LwjglApplicationConfiguration(); appConfig.vSyncEnabled = false; appConfig.resizable = false;//true; //appConfig.width = 1072; // IMAX ratio @@ -110,7 +122,7 @@ public class AppLoader implements ApplicationListener { appConfig.title = GAME_NAME; appConfig.forceExit = false; - new LwjglApplication(new AppLoader(), appConfig); + new LwjglApplication(new AppLoader(appConfig), appConfig); } @@ -128,6 +140,8 @@ public class AppLoader implements ApplicationListener { public Screen screen; + public static Texture textureWhiteSquare; + private void initViewPort(int width, int height) { // Set Y to point downwards camera.setToOrtho(true, width, height); @@ -153,6 +167,10 @@ public class AppLoader implements ApplicationListener { initViewPort(appConfig.width, appConfig.height); + textureWhiteSquare = new Texture(Gdx.files.internal("assets/graphics/ortho_line_tex_2px.tga")); + textureWhiteSquare.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest); + + shaderBayerSkyboxFill = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer_skyboxfill.frag")); shaderHicolour = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/hicolour.frag")); shaderColLUT = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/passthru.frag")); @@ -182,6 +200,12 @@ public class AppLoader implements ApplicationListener { TextureRegionPack.Companion.setGlobalFlipY(true); fontGame = new GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap", false, true, Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, false, 128, false); + + + // if there is a predefined screen, open that screen after my init process + if (injectScreen != null) { + setScreen(injectScreen); + } } @Override @@ -200,6 +224,7 @@ public class AppLoader implements ApplicationListener { FrameBufferManager.begin(renderFBO); setCameraPosition(0, 0); + // if there's no predefined screen, default to the actual game's screen, and set the screen as the one if (screen == null) { shaderBayerSkyboxFill.begin(); shaderBayerSkyboxFill.setUniformMatrix("u_projTrans", camera.combined); diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index 8e5eb1ab1..c8ba0fb08 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -222,10 +222,6 @@ object Terrarum : Screen { lateinit var shaderRGBOnly: ShaderProgram lateinit var shaderAtoGrey: ShaderProgram - - lateinit var textureWhiteSquare: Texture - - lateinit var testTexture: Texture @@ -357,10 +353,6 @@ object Terrarum : Screen { fontSmallNumbers = TinyAlphNum - textureWhiteSquare = Texture(Gdx.files.internal("assets/graphics/ortho_line_tex_2px.tga")) - textureWhiteSquare.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest) - - ShaderProgram.pedantic = false shaderBlur = ShaderProgram(Gdx.files.internal("assets/blur.vert"), Gdx.files.internal("assets/blur.frag")) @@ -788,7 +780,7 @@ fun Float.round(): Float { // ShapeRenderer alternative for rects fun SpriteBatch.fillRect(x: Float, y: Float, w: Float, h: Float) { - this.draw(Terrarum.textureWhiteSquare, x, y, w, h) + this.draw(AppLoader.textureWhiteSquare, x, y, w, h) } inline fun SpriteBatch.drawStraightLine(x: Float, y: Float, otherEnd: Float, thickness: Float, isVertical: Boolean) { if (!isVertical) @@ -840,11 +832,11 @@ object BlendMode { const val NORMAL = "normal" //const val MAX = "GL_MAX" // not supported by GLES -- use shader - fun resolve(mode: String) { + fun resolve(mode: String, batch: SpriteBatch? = null) { when (mode) { - SCREEN -> blendScreen() - MULTIPLY -> blendMul() - NORMAL -> blendNormal() + SCREEN -> blendScreen(batch) + MULTIPLY -> blendMul(batch) + NORMAL -> blendNormal(batch) //MAX -> blendLightenOnly() // not supported by GLES -- use shader else -> throw Error("Unknown blend mode: $mode") } diff --git a/src/net/torvald/terrarum/ui/UICanvas.kt b/src/net/torvald/terrarum/ui/UICanvas.kt index ca9fa8922..669ac392e 100644 --- a/src/net/torvald/terrarum/ui/UICanvas.kt +++ b/src/net/torvald/terrarum/ui/UICanvas.kt @@ -78,9 +78,9 @@ abstract class UICanvas( } - /** Override this for the actual update. You must update uiItems by yourself. */ + /** Override this for the actual update. Note that you must update uiItems by yourself. */ abstract fun updateUI(delta: Float) - /** Override this for the actual render. You must render uiItems by yourself. */ + /** Override this for the actual render. Note that you must render uiItems by yourself. */ abstract fun renderUI(batch: SpriteBatch, camera: Camera) /** diff --git a/src/net/torvald/terrarum/ui/UIItemTextArea.kt b/src/net/torvald/terrarum/ui/UIItemTextArea.kt index bcfd243f1..a74727efa 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextArea.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextArea.kt @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.Terrarum import net.torvald.terrarum.floor +import net.torvald.terrarum.ui.UIItemTextButton.Companion.Alignment class UIItemTextArea( parentUI: UICanvas, @@ -13,16 +14,9 @@ class UIItemTextArea( override val height: Int, val lineGap: Int = 0, val lineCount: Int = ((height + lineGap) / Terrarum.fontGame.lineHeight).toInt(), - val align: UIItemTextArea.Align = Align.LEFT + val align: Alignment = Alignment.LEFT ) : UIItem(parentUI) { - - enum class Align { - LEFT, CENTRE, RIGHT - } - - - private var entireText: List = listOf("") // placeholder var scrollPos = 0 @@ -45,9 +39,9 @@ class UIItemTextArea( val textWidth = Terrarum.fontGame.getWidth(entireText[i]) when (align) { - Align.LEFT -> Terrarum.fontGame.draw(batch, entireText[i], posX.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap)) - Align.CENTRE -> Terrarum.fontGame.draw(batch, entireText[i], posX + ((width - textWidth) / 2f).floor(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap)) - Align.RIGHT -> Terrarum.fontGame.draw(batch, entireText[i], posX + width - textWidth.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap)) + Alignment.LEFT -> Terrarum.fontGame.draw(batch, entireText[i], posX.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap)) + Alignment.CENTRE -> Terrarum.fontGame.draw(batch, entireText[i], posX + ((width - textWidth) / 2f).floor(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap)) + Alignment.RIGHT -> Terrarum.fontGame.draw(batch, entireText[i], posX + width - textWidth.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap)) } } } diff --git a/src/net/torvald/terrarum/ui/UIItemTextButton.kt b/src/net/torvald/terrarum/ui/UIItemTextButton.kt index f7668ffe3..71c521ecd 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextButton.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextButton.kt @@ -28,7 +28,9 @@ open class UIItemTextButton( val highlightBackBlendMode: String = BlendMode.MULTIPLY, val inactiveCol: Color = defaultInactiveCol, val preGapX: Int = 0, - val postGapX: Int = 0 + val postGapX: Int = 0, + + val alignment: Alignment = Alignment.CENTRE ) : UIItem(parentUI) { companion object { @@ -36,6 +38,10 @@ open class UIItemTextButton( val height = font.lineHeight.toInt() * 2 val defaultInactiveCol: Color = Color(0xc8c8c8_ff.toInt()) val defaultHighlightCol: Color = Color(0x00f8ff_ff) + + enum class Alignment { + CENTRE, LEFT, RIGHT + } } /** Actually displayed text (changes with the app language) */ @@ -74,7 +80,11 @@ open class UIItemTextButton( font.draw(batch, label, - posX.toFloat() + width.minus(textW).div(2) + (preGapX - postGapX).div(2), + when (alignment) { + Alignment.CENTRE -> posX.toFloat() + width.minus(textW).div(2) + (preGapX - postGapX).div(2) + Alignment.LEFT -> posX.toFloat() + preGapX + Alignment.RIGHT -> width - postGapX - textW.toFloat() + }, posY.toFloat() + height / 4 ) } diff --git a/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt b/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt index 7f51602eb..1f6b3928d 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt @@ -40,7 +40,9 @@ class UIItemTextButtonList( val inactiveCol: Color = Color(0xc0c0c0_ff.toInt()), val backgroundCol: Color = Color(0x242424_80), val backgroundBlendMode: String = BlendMode.NORMAL, - val kinematic: Boolean = false + val kinematic: Boolean = false, + + val alignment: UIItemTextButton.Companion.Alignment = UIItemTextButton.Companion.Alignment.CENTRE ) : UIItem(parentUI) { val iconToTextGap = 20 @@ -71,7 +73,8 @@ class UIItemTextButtonList( highlightBackBlendMode = highlightBackBlendMode, inactiveCol = inactiveCol, preGapX = pregap, - postGapX = postgap + postGapX = postgap, + alignment = alignment ) } else { @@ -89,7 +92,8 @@ class UIItemTextButtonList( highlightBackBlendMode = activeBackBlendMode, // we are using custom highlighter inactiveCol = inactiveCol, preGapX = pregap, - postGapX = postgap + postGapX = postgap, + alignment = alignment ) } }