diff --git a/src/net/torvald/terrarum/App.java b/src/net/torvald/terrarum/App.java index 7a72885e3..91c64feda 100644 --- a/src/net/torvald/terrarum/App.java +++ b/src/net/torvald/terrarum/App.java @@ -351,8 +351,8 @@ public class App implements ApplicationListener { ShaderProgram.pedantic = false; scr = new TerrarumScreenSize(getConfigInt("screenwidth"), getConfigInt("screenheight")); - int width = scr.getWidth(); - int height = scr.getHeight(); + int width = (int) Math.round(scr.getWidth() * scr.getMagn()); + int height = (int) Math.round(scr.getHeight() * scr.getMagn()); Lwjgl3ApplicationConfiguration appConfig = new Lwjgl3ApplicationConfiguration(); //appConfig.useGL30 = false; // https://stackoverflow.com/questions/46753218/libgdx-should-i-use-gl30 @@ -719,7 +719,13 @@ public class App implements ApplicationListener { } @Override - public void resize(int width, int height) { + public void resize(int w, int h) { + + double magn = getConfigDouble("screenmagnifying"); + int width = (int) Math.round(w / magn); + int height = (int) Math.round(h / magn); + + printdbg(this, "Resize called: "+width+","+height); printStackTrace(this); @@ -1223,6 +1229,20 @@ public class App implements ApplicationListener { return ((int) cfg); } + + /** + * Return config from config set. If the config does not exist, default value will be returned. + * @param key + * * + * @return Config from config set or default config if it does not exist. + * * + * @throws NullPointerException if the specified config simply does not exist. + */ + public static double getConfigDouble(String key) { + Object cfg = getConfigMaster(key); + return (cfg instanceof Integer) ? (((Integer) cfg) * 1.0) : ((double) (cfg)); + } + /** * Return config from config set. If the config does not exist, default value will be returned. * @param key diff --git a/src/net/torvald/terrarum/DefaultConfig.kt b/src/net/torvald/terrarum/DefaultConfig.kt index 2dd6ca4da..09a062a6d 100644 --- a/src/net/torvald/terrarum/DefaultConfig.kt +++ b/src/net/torvald/terrarum/DefaultConfig.kt @@ -105,7 +105,9 @@ object DefaultConfig { //"fx_3dlut" to false, "basekeyboardlayout" to "en_intl_qwerty", - "inputmethod" to "none" + "inputmethod" to "none", + + "screenmagnifying" to 1.0 // settings regarding debugger diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index e9995e2c4..a6c519e76 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -220,16 +220,16 @@ object Terrarum : Disposable { /** Position of the cursor in the world, rounded */ val mouseX: Double - get() = (WorldCamera.zoomedX + Gdx.input.x / (ingame?.screenZoom ?: 1f).toDouble()).fmod(WorldCamera.worldWidth.toDouble()) + get() = (WorldCamera.zoomedX + Gdx.input.x / (ingame?.screenZoom ?: 1f).times(scr.magn)).fmod(WorldCamera.worldWidth.toDouble()) /** Position of the cursor in the world */ val mouseY: Double - get() = (WorldCamera.zoomedY + Gdx.input.y / (ingame?.screenZoom ?: 1f).toDouble()) + get() = (WorldCamera.zoomedY + Gdx.input.y / (ingame?.screenZoom ?: 1f).times(scr.magn)) /** Position of the cursor in the world, rounded */ val oldMouseX: Double - get() = (WorldCamera.zoomedX + (Gdx.input.x - Gdx.input.deltaX) / (ingame?.screenZoom ?: 1f).toDouble()).fmod(WorldCamera.worldWidth.toDouble()) + get() = (WorldCamera.zoomedX + (Gdx.input.x - Gdx.input.deltaX) / (ingame?.screenZoom ?: 1f).times(scr.magn)).fmod(WorldCamera.worldWidth.toDouble()) /** Position of the cursor in the world */ val oldMouseY: Double - get() = WorldCamera.zoomedY + (Gdx.input.y - Gdx.input.deltaY) / (ingame?.screenZoom ?: 1f).toDouble() + get() = WorldCamera.zoomedY + (Gdx.input.y - Gdx.input.deltaY) / (ingame?.screenZoom ?: 1f).times(scr.magn) /** Position of the cursor in the world, rounded */ @JvmStatic val mouseTileX: Int get() = (mouseX / TILE_SIZE).floorInt() @@ -243,13 +243,13 @@ object Terrarum : Disposable { @JvmStatic val oldMouseTileY: Int get() = (oldMouseY / TILE_SIZE).floorInt() inline val mouseScreenX: Int - get() = Gdx.input.x + get() = Gdx.input.x.div(scr.magn).roundToInt() inline val mouseScreenY: Int - get() = Gdx.input.y + get() = Gdx.input.y.div(scr.magn).roundToInt() inline val mouseDeltaX: Int - get() = Gdx.input.deltaX + get() = Gdx.input.deltaX.div(scr.magn).roundToInt() inline val mouseDeltaY: Int - get() = Gdx.input.deltaY + get() = Gdx.input.deltaY.div(scr.magn).roundToInt() /** Delta converted as it it was a FPS */ inline val updateRate: Double get() = 1.0 / Gdx.graphics.deltaTime diff --git a/src/net/torvald/terrarum/TerrarumScreenSize.kt b/src/net/torvald/terrarum/TerrarumScreenSize.kt index d7bef600d..9eac1c2de 100644 --- a/src/net/torvald/terrarum/TerrarumScreenSize.kt +++ b/src/net/torvald/terrarum/TerrarumScreenSize.kt @@ -25,6 +25,7 @@ class TerrarumScreenSize(scrw: Int = defaultW, scrh: Int = defaultH) { var aspectRatio: Float = 0f; private set var chatWidth: Int = 0; private set + var magn: Double = 0.0; private set // this value is stored here so that the initial instance would stay, forcing the players to require restart to apply the screen magnifying val tvSafeGraphicsWidth: Int; get() = Math.round(width * TV_SAFE_GRAPHICS) val tvSafeGraphicsHeight: Int; get() = Math.round(height * TV_SAFE_GRAPHICS) @@ -46,6 +47,8 @@ class TerrarumScreenSize(scrw: Int = defaultW, scrh: Int = defaultH) { halfhf = hf / 2f aspectRatio = wf / hf chatWidth = (width - (width * 0.84375).roundToInt()) and 0x7FFFFFFE + + magn = App.getConfigDouble("screenmagnifying") } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt index e0ac70cd1..ee0a138b7 100644 --- a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt +++ b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt @@ -511,7 +511,7 @@ object IngameRenderer : Disposable { } - // NOTE TO SELF: this works. + // NOTE TO SELF: thã„´is works. } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt index 0230fbcd0..c6cd940f0 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIGraphicsControlPanel.kt @@ -3,11 +3,11 @@ package net.torvald.terrarum.modulebasegame.ui import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch -import net.torvald.unicode.TIMES import net.torvald.terrarum.App import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELL_COL import net.torvald.terrarum.ui.* +import net.torvald.unicode.TIMES /** * Created by minjaesong on 2021-10-06. @@ -31,7 +31,8 @@ class UIGraphicsControlPanel(remoCon: UIRemoCon?) : UICanvas() { arrayOf("fx_backgroundblur", { Lang["MENU_OPTIONS_BLUR"] }, "toggle"), arrayOf("fx_streamerslayout", { Lang["MENU_OPTION_STREAMERS_LAYOUT"] }, "toggle"), arrayOf("usevsync", { Lang["MENU_OPTIONS_VSYNC"]+"*" }, "toggle"), - arrayOf("maxparticles", { Lang["MENU_OPTIONS_PARTICLES"] }, "spinner,256,1024,256") + arrayOf("screenmagnifying", { Lang["MENU_OPTIONS_RESOLUTION"]+"*" }, "spinnerd,1.0,2.0,0.25"), + arrayOf("maxparticles", { Lang["MENU_OPTIONS_PARTICLES"] }, "spinner,256,1024,256"), ) private fun makeButton(args: String, x: Int, y: Int, optionName: String): UIItem { @@ -40,7 +41,11 @@ class UIGraphicsControlPanel(remoCon: UIRemoCon?) : UICanvas() { } else if (args.startsWith("spinner,")) { val arg = args.split(',') - UIItemSpinner(this, x - spinnerWidth, y, App.getConfigInt(optionName), arg[1].toInt(), arg[2].toInt(), arg[3].toInt(), spinnerWidth) + UIItemSpinner(this, x - spinnerWidth, y, App.getConfigInt(optionName), arg[1].toInt(), arg[2].toInt(), arg[3].toInt(), spinnerWidth, numberToTextFunction = { "${it.toLong()}" }) + } + else if (args.startsWith("spinnerd,")) { + val arg = args.split(',') + UIItemSpinner(this, x - spinnerWidth, y, App.getConfigDouble(optionName), arg[1].toDouble(), arg[2].toDouble(), arg[3].toDouble(), spinnerWidth, numberToTextFunction = { "${it}x" }) } else throw IllegalArgumentException(args) } diff --git a/src/net/torvald/terrarum/ui/UIItemSpinner.kt b/src/net/torvald/terrarum/ui/UIItemSpinner.kt index 20716f06d..6487f22ea 100644 --- a/src/net/torvald/terrarum/ui/UIItemSpinner.kt +++ b/src/net/torvald/terrarum/ui/UIItemSpinner.kt @@ -15,12 +15,13 @@ import net.torvald.terrarum.* class UIItemSpinner( parentUI: UICanvas, initialX: Int, initialY: Int, - initialValue: Int, - val min: Int, - val max: Int, - val step: Int, + initialValue: Number, + val min: Number, + val max: Number, + val step: Number, override val width: Int, - private val drawBorder: Boolean = true + private val drawBorder: Boolean = true, + private val numberToTextFunction: (Number) -> String = { "$it" } ) : UIItem(parentUI, initialX, initialY) { init { @@ -33,12 +34,12 @@ class UIItemSpinner( private val fbo = FrameBuffer(Pixmap.Format.RGBA8888, width - 2*buttonW - 6, height - 4, false) - var value = initialValue.coerceIn(min, max) + var value = initialValue.toDouble().coerceIn(min.toDouble(), max.toDouble()) as Number var fboUpdateLatch = true private var mouseOnButton = 0 // 0: nothing, 1: left, 2: right - var selectionChangeListener: (Int) -> Unit = {} + var selectionChangeListener: (Number) -> Unit = {} override fun update(delta: Float) { super.update(delta) @@ -55,7 +56,7 @@ class UIItemSpinner( if (!mouseLatched && Terrarum.mouseDown && mouseOnButton in 1..2) { mouseLatched = true - value = (value + step * ((mouseOnButton * 2) - 3)).coerceIn(min, max) + value = (value.toDouble() + step.toDouble() * ((mouseOnButton * 2) - 3)).coerceIn(min.toDouble(), max.toDouble()) fboUpdateLatch = true selectionChangeListener(value) } @@ -72,7 +73,7 @@ class UIItemSpinner( gdxClearAndSetBlend(0f, 0f, 0f, 0f) it.color = Color.WHITE - val t = "$value" + val t = numberToTextFunction(value) val tw = App.fontGame.getWidth(t) App.fontGameFBO.draw(it, t, (fbo.width - tw) / 2, 0) } } @@ -133,9 +134,9 @@ class UIItemSpinner( override fun scrolled(amountX: Float, amountY: Float): Boolean { if (mouseUp) { if (amountX <= -1 || amountY <= -1) - value = (value - step).coerceIn(min, max) + value = (value.toDouble() - step.toDouble()).coerceIn(min.toDouble(), max.toDouble()) else if (amountX >= 1 || amountY >= 1) - value = (value + step).coerceIn(min, max) + value = (value.toDouble() + step.toDouble()).coerceIn(min.toDouble(), max.toDouble()) selectionChangeListener(value) fboUpdateLatch = true