From e4f456ffa76788f8213f667cbf0d689c044df1f1 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 23 Jan 2019 12:45:40 +0900 Subject: [PATCH] gapbox toggle with F11 --- src/net/torvald/terrarum/AppLoader.java | 31 +++++++++++++++++-- src/net/torvald/terrarum/PostProcessor.kt | 18 ++++++----- src/net/torvald/terrarum/Terrarum.kt | 6 ++-- .../torvald/terrarum/console/CommandDict.kt | 1 + .../terrarum/console/CommandInterpreter.kt | 3 +- .../torvald/terrarum/console/ResizeScreen.kt | 30 ++++++++++++++++++ .../ui/UIItemInventoryDynamicList.kt | 2 +- 7 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 src/net/torvald/terrarum/console/ResizeScreen.kt diff --git a/src/net/torvald/terrarum/AppLoader.java b/src/net/torvald/terrarum/AppLoader.java index 5b7efbd9f..3906ebc06 100644 --- a/src/net/torvald/terrarum/AppLoader.java +++ b/src/net/torvald/terrarum/AppLoader.java @@ -2,6 +2,7 @@ package net.torvald.terrarum; import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; import com.badlogic.gdx.Screen; import com.badlogic.gdx.audio.AudioDevice; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; @@ -16,6 +17,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import net.torvald.dataclass.ArrayListMap; +import net.torvald.terrarum.gamecontroller.KeyToggler; import net.torvald.terrarum.imagefont.TinyAlphNum; import net.torvald.terrarum.modulebasegame.IngameRenderer; import net.torvald.terrarum.utils.JsonFetcher; @@ -151,6 +153,8 @@ public class AppLoader implements ApplicationListener { private static boolean splashDisplayed = false; private static boolean postInitFired = false; private static boolean screenshotRequested = false; + private static boolean resizeRequested = false; + private static Point2i resizeReqSize; public static LwjglApplicationConfiguration appConfig; public static GameFontBase fontGame; @@ -164,8 +168,10 @@ public class AppLoader implements ApplicationListener { public static ArrayListMap debugTimers = new ArrayListMap(); - static final int defaultW = 1110; - static final int defaultH = 740; + public static final int defaultW = 1110; + public static final int defaultH = 740; + public static final int minimumW = 1080; + public static final int minimumH = 720; public static void main(String[] args) { // load configs @@ -191,6 +197,8 @@ public class AppLoader implements ApplicationListener { if (args.length == 1 && args[0].equals("isdev=true")) { IS_DEVELOPMENT_BUILD = true; + // safe area box + KeyToggler.INSTANCE.forceSet(Input.Keys.F11, true); } new LwjglApplication(new AppLoader(appConfig), appConfig); @@ -320,6 +328,13 @@ public class AppLoader implements ApplicationListener { PostProcessor.INSTANCE.draw(camera.combined, renderFBO); + // process resize request + if (resizeRequested) { + resizeRequested = false; + resize(resizeReqSize.getX(), resizeReqSize.getY()); + } + + // process screenshot request if (screenshotRequested) { screenshotRequested = false; @@ -340,6 +355,11 @@ public class AppLoader implements ApplicationListener { @Override public void resize(int width, int height) { + printdbg(this, "Resize called"); + for (StackTraceElement stackTraceElement : Thread.currentThread().getStackTrace()) { + printdbg(this, stackTraceElement); + } + //initViewPort(width, height); screenW = width; @@ -368,7 +388,12 @@ public class AppLoader implements ApplicationListener { updateFullscreenQuad(screenW, screenH); - printdbg(this, "Resize event"); + printdbg(this, "Resize end"); + } + + public static void resizeScreen(int width, int height) { + resizeRequested = true; + resizeReqSize = new Point2i(Math.max(width, minimumW), Math.max(height, minimumH)); } @Override diff --git a/src/net/torvald/terrarum/PostProcessor.kt b/src/net/torvald/terrarum/PostProcessor.kt index d9637325d..fd1dc0867 100644 --- a/src/net/torvald/terrarum/PostProcessor.kt +++ b/src/net/torvald/terrarum/PostProcessor.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum import com.badlogic.gdx.Gdx +import com.badlogic.gdx.Input import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.OrthographicCamera @@ -10,6 +11,7 @@ import com.badlogic.gdx.graphics.glutils.FrameBuffer import com.badlogic.gdx.graphics.glutils.ShaderProgram import com.badlogic.gdx.graphics.glutils.ShapeRenderer import com.badlogic.gdx.math.Matrix4 +import net.torvald.terrarum.gamecontroller.KeyToggler import kotlin.system.measureNanoTime /** @@ -71,7 +73,7 @@ object PostProcessor { Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it - if (AppLoader.IS_DEVELOPMENT_BUILD) { + if (AppLoader.IS_DEVELOPMENT_BUILD && KeyToggler.isOn(Input.Keys.F11)) { val tvSafeAreaW = AppLoader.getTvSafeGraphicsWidth().toFloat() val tvSafeAreaH = AppLoader.getTvSafeGraphicsHeight().toFloat() val tvSafeArea2W = AppLoader.getTvSafeActionWidth().toFloat() @@ -90,10 +92,10 @@ object PostProcessor { shapeRenderer.color = defaultResCol shapeRenderer.rect( - (AppLoader.screenW - AppLoader.defaultW).div(2).toFloat(), - (AppLoader.screenH - AppLoader.defaultH).div(2).toFloat(), - AppLoader.defaultW.toFloat(), - AppLoader.defaultH.toFloat() + (AppLoader.screenW - AppLoader.minimumW).div(2).toFloat(), + (AppLoader.screenH - AppLoader.minimumH).div(2).toFloat(), + AppLoader.minimumW.toFloat(), + AppLoader.minimumH.toFloat() ) } @@ -108,8 +110,8 @@ object PostProcessor { batch.color = defaultResCol AppLoader.fontSmallNumbers.draw( batch, defaultResStr, - (AppLoader.screenW - AppLoader.defaultW).div(2).toFloat(), - (AppLoader.screenH - AppLoader.defaultH).div(2).minus(10).toFloat() + (AppLoader.screenW - AppLoader.minimumW).div(2).toFloat(), + (AppLoader.screenH - AppLoader.minimumH).div(2).minus(10).toFloat() ) } } @@ -118,7 +120,7 @@ object PostProcessor { } } - private val defaultResStr = "${AppLoader.defaultW}x${AppLoader.defaultH}" + private val defaultResStr = "${AppLoader.minimumW}x${AppLoader.minimumH}" private val safeAreaStr = "TV Safe Area" /** diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index 74f3ce57b..f9814ac2c 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -433,11 +433,9 @@ object Terrarum : Screen { AppLoader.getINSTANCE().screen.hide() } + /** For the actual resize, call AppLoader.resize() */ override fun resize(width: Int, height: Int) { - /*try { - AppLoader.getINSTANCE().screen.resize(width, height) - } - catch (e: NullPointerException) { }*/ // I sense circular recursion... + ingame?.resize(width, height) printdbg(this, "newsize: ${Gdx.graphics.width}x${Gdx.graphics.height} | internal: ${width}x$height") } diff --git a/src/net/torvald/terrarum/console/CommandDict.kt b/src/net/torvald/terrarum/console/CommandDict.kt index fc23daace..275e7dcc6 100644 --- a/src/net/torvald/terrarum/console/CommandDict.kt +++ b/src/net/torvald/terrarum/console/CommandDict.kt @@ -44,6 +44,7 @@ object CommandDict { "kill" to KillActor, "money" to MoneyDisp, "screenshot" to TakeScreenshot, + //"resize" to ResizeScreen, // Test codes "bulletintest" to SetBulletin, diff --git a/src/net/torvald/terrarum/console/CommandInterpreter.kt b/src/net/torvald/terrarum/console/CommandInterpreter.kt index 6021806df..f3f7a88cb 100644 --- a/src/net/torvald/terrarum/console/CommandInterpreter.kt +++ b/src/net/torvald/terrarum/console/CommandInterpreter.kt @@ -22,7 +22,8 @@ internal object CommandInterpreter { "help", "version", "tips", - "screenshot" + "screenshot", + "resize" ) internal fun execute(command: String) { diff --git a/src/net/torvald/terrarum/console/ResizeScreen.kt b/src/net/torvald/terrarum/console/ResizeScreen.kt new file mode 100644 index 000000000..7e5d0944c --- /dev/null +++ b/src/net/torvald/terrarum/console/ResizeScreen.kt @@ -0,0 +1,30 @@ +package net.torvald.terrarum.console + +import net.torvald.terrarum.AppLoader +import net.torvald.terrarum.Terrarum + +object ResizeScreen: ConsoleCommand { + override fun execute(args: Array) { + if (args.size == 3) { + Terrarum.resize(args[1].toInt(), args[2].toInt()) + } + else if (args.size == 2) { + when (args[1]) { + "720p" -> AppLoader.resizeScreen(1280,720) + "1080p" -> AppLoader.resizeScreen(1920,1080) + "default" -> AppLoader.resizeScreen(AppLoader.defaultW, AppLoader.defaultH) + else -> { printUsage(); return } + } + } + else { + printUsage(); return + } + + Echo("Screen resized to ${AppLoader.screenW}x${AppLoader.screenH}") + } + + override fun printUsage() { + Echo("Usage: resize [width] [height]. Minimum size is ${AppLoader.minimumW}x${AppLoader.minimumH}") + Echo("Reserved keywords: 720p, 1080p, default") + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt index 8b6f01694..c1874a53e 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt @@ -76,7 +76,7 @@ class UIItemInventoryDynamicList( companion object { const val listGap = 8 - const val horizontalCells = 12 + const val horizontalCells = 11 const val verticalCells = 8 val largeListWidth = (horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 2) * listGap) / 2