From 1ef479124e48c7e6b85782fb4c3c565506a16f1e Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 26 Jun 2023 20:18:00 +0900 Subject: [PATCH] actually working load manual/auto button --- src/net/torvald/terrarum/App.java | 4 +- .../torvald/terrarum/TerrarumScreenSize.kt | 4 +- .../modulebasegame/ui/UILoadSavegame.kt | 54 ++++++++++++++++--- .../torvald/terrarum/ui/UIItemImageButton.kt | 2 +- 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/net/torvald/terrarum/App.java b/src/net/torvald/terrarum/App.java index 1e17dbb63..5104f2c6e 100644 --- a/src/net/torvald/terrarum/App.java +++ b/src/net/torvald/terrarum/App.java @@ -777,8 +777,8 @@ public class App implements ApplicationListener { public void resize(int w0, int h0) { float magn = (float) getConfigDouble("screenmagnifying"); - int width = Math.round(w0 / magn); - int height = Math.round(h0 / magn); + int width = (int) Math.floor(w0 / magn); + int height = (int) Math.floor(h0 / magn); printdbg(this, "Resize called: "+width+","+height); diff --git a/src/net/torvald/terrarum/TerrarumScreenSize.kt b/src/net/torvald/terrarum/TerrarumScreenSize.kt index 8eeebc1e4..4cc26cfcc 100644 --- a/src/net/torvald/terrarum/TerrarumScreenSize.kt +++ b/src/net/torvald/terrarum/TerrarumScreenSize.kt @@ -56,8 +56,8 @@ class TerrarumScreenSize(scrw: Int = defaultW, scrh: Int = defaultH) { this.magn = magn - windowW = (scrw * magn).roundToInt() and 0x7FFFFFFE - windowH = (scrh * magn).roundToInt() and 0x7FFFFFFE + windowW = (scrw * magn).ceilInt() and 0x7FFFFFFE + windowH = (scrh * magn).ceilInt() and 0x7FFFFFFE printdbg(this, "Window dim: $windowW x $windowH, called by:") diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt index 68587573a..2c74d1292 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt @@ -191,7 +191,16 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { imageDrawHeight = imageButtonH, highlightable = false, useBorder = true, - ).also { it.extraDrawOp = getDrawTextualInfoFun(loadables.getManualSave()!!) } + ).also { + it.extraDrawOp = getDrawTextualInfoFun(loadables.getManualSave()!!) + it.clickOnceListener = { _,_ -> + loadables.getManualSave()!!.let { + UILoadGovernor.playerDisk = it.player + UILoadGovernor.worldDisk = it.world + } + mode = MODE_LOAD_DA_SHIT_ALREADY + } + } loadAutoThumbButton = UIItemImageButton(this, autoThumb, initialX = (Toolkit.drawWidth - altSelDrawW)/2 + altSelQQQdrawW - imageButtonW/2, initialY = altSelDrawY + 120, @@ -201,7 +210,16 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { imageDrawHeight = imageButtonH, highlightable = false, useBorder = true, - ).also { it.extraDrawOp = getDrawTextualInfoFun(loadables.getAutoSave()!!) } + ).also { + it.extraDrawOp = getDrawTextualInfoFun(loadables.getAutoSave()!!) + it.clickOnceListener = { _,_ -> + loadables.getAutoSave()!!.let { + UILoadGovernor.playerDisk = it.player + UILoadGovernor.worldDisk = it.world + } + mode = MODE_LOAD_DA_SHIT_ALREADY + } + } MODE_SAVE_MULTIPLE_CHOICES } @@ -217,12 +235,12 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { UILoadGovernor.previousSaveWasLoaded = true } -// MODE_LOAD_DA_SHIT_ALREADY + MODE_LOAD_DA_SHIT_ALREADY // test codes // - val autoThumb = loadables.getManualSave()!!.getThumbnail() + /*val autoThumb = loadables.getManualSave()!!.getThumbnail() val manualThumb = loadables.getManualSave()!!.getThumbnail() loadManualThumbButton = UIItemImageButton(this, manualThumb, @@ -234,7 +252,16 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { imageDrawHeight = imageButtonH, highlightable = false, useBorder = true, - ).also { it.extraDrawOp = getDrawTextualInfoFun(loadables.getManualSave()!!) } + ).also { + it.extraDrawOp = getDrawTextualInfoFun(loadables.getManualSave()!!) + it.clickOnceListener = { _,_ -> + loadables.getManualSave()!!.let { + UILoadGovernor.playerDisk = it.player + UILoadGovernor.worldDisk = it.world + } + mode = MODE_LOAD_DA_SHIT_ALREADY + } + } loadAutoThumbButton = UIItemImageButton(this, autoThumb, initialX = (Toolkit.drawWidth - altSelDrawW)/2 + altSelQQQdrawW - imageButtonW/2, initialY = altSelDrawY + 120, @@ -244,9 +271,18 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { imageDrawHeight = imageButtonH, highlightable = false, useBorder = true, - ).also { it.extraDrawOp = getDrawTextualInfoFun(loadables.getManualSave()!!) } + ).also { + it.extraDrawOp = getDrawTextualInfoFun(loadables.getManualSave()!!) + it.clickOnceListener = { _,_ -> + loadables.getManualSave()!!.let { + UILoadGovernor.playerDisk = it.player + UILoadGovernor.worldDisk = it.world + } + mode = MODE_LOAD_DA_SHIT_ALREADY + } + } - MODE_SAVE_MULTIPLE_CHOICES + MODE_SAVE_MULTIPLE_CHOICES*/ } } } @@ -492,11 +528,15 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { if (mode == MODE_SELECT) getCells().forEach { it.touchDown(screenX, screenY, pointer, button) } + if (::loadAutoThumbButton.isInitialized && mode == MODE_SAVE_MULTIPLE_CHOICES) { loadAutoThumbButton.touchDown(screenX, screenY, pointer, button) } + if (::loadManualThumbButton.isInitialized && mode == MODE_SAVE_MULTIPLE_CHOICES) { loadManualThumbButton.touchDown(screenX, screenY, pointer, button) } return true } override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { if (mode == MODE_SELECT) getCells().forEach { it.touchUp(screenX, screenY, pointer, button) } + if (::loadAutoThumbButton.isInitialized && mode == MODE_SAVE_MULTIPLE_CHOICES) { loadAutoThumbButton.touchUp(screenX, screenY, pointer, button) } + if (::loadManualThumbButton.isInitialized && mode == MODE_SAVE_MULTIPLE_CHOICES) { loadManualThumbButton.touchUp(screenX, screenY, pointer, button) } return true } diff --git a/src/net/torvald/terrarum/ui/UIItemImageButton.kt b/src/net/torvald/terrarum/ui/UIItemImageButton.kt index 180c15251..6b3c8d47d 100644 --- a/src/net/torvald/terrarum/ui/UIItemImageButton.kt +++ b/src/net/torvald/terrarum/ui/UIItemImageButton.kt @@ -76,7 +76,7 @@ open class UIItemImageButton( // draw image batch.color = if (highlighted) highlightCol else if (mouseUp) activeCol - else Toolkit.Theme.COL_INACTIVE + else if (useBorder) Toolkit.Theme.COL_INACTIVE else inactiveCol if (useBorder) { Toolkit.drawBoxBorder(batch, posX - 1f, posY - 1f, width + 2f, height + 2f) batch.color = Color.WHITE