From 71df31b93dc1d0273cb19f3a2a2f8c39f1b56160 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 8 Jul 2023 23:26:47 +0900 Subject: [PATCH] working autosave chooser --- src/net/torvald/terrarum/Principii.java | 2 +- .../ui/StaticLoadScreenSubstitute.kt | 27 +++++++ .../modulebasegame/ui/UILoadAutosave.kt | 74 ++++++++++++------- .../modulebasegame/ui/UILoadManage.kt | 58 ++++++--------- .../modulebasegame/ui/UILoadSavegame.kt | 19 ++--- 5 files changed, 106 insertions(+), 74 deletions(-) create mode 100644 src/net/torvald/terrarum/modulebasegame/ui/StaticLoadScreenSubstitute.kt diff --git a/src/net/torvald/terrarum/Principii.java b/src/net/torvald/terrarum/Principii.java index 38ceca207..df14adf8a 100644 --- a/src/net/torvald/terrarum/Principii.java +++ b/src/net/torvald/terrarum/Principii.java @@ -106,7 +106,7 @@ public class Principii { // String[] cmd = (runtime+extracmd0+userDefinedExtraCmd0+" -Xms1G -Xmx"+xmx+"G -cp ./out/TerrarumBuild.jar net.torvald.terrarum.App").split(" "); List extracmds = Arrays.stream(extracmd0.split(" ")).toList(); - List userDefinedExtraCmds = Arrays.stream(userDefinedExtraCmd0.split(" ")).toList(); + List userDefinedExtraCmds = Arrays.stream(userDefinedExtraCmd0.split(" +")).filter((it) -> !it.isBlank()).toList(); ArrayList cmd0 = new ArrayList<>(); cmd0.add(runtime); cmd0.addAll(extracmds); diff --git a/src/net/torvald/terrarum/modulebasegame/ui/StaticLoadScreenSubstitute.kt b/src/net/torvald/terrarum/modulebasegame/ui/StaticLoadScreenSubstitute.kt new file mode 100644 index 000000000..11bdb07a9 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/ui/StaticLoadScreenSubstitute.kt @@ -0,0 +1,27 @@ +package net.torvald.terrarum.modulebasegame.ui + +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.terrarum.App +import net.torvald.terrarum.gdxClearAndEnableBlend +import net.torvald.terrarum.langpack.Lang + +/** + * Created by minjaesong on 2023-07-08. + */ +object StaticLoadScreenSubstitute { + + operator fun invoke(batch: SpriteBatch) { + batch.end() + + gdxClearAndEnableBlend(.094f, .094f, .094f, 0f) + + batch.begin() + + batch.color = Color.WHITE + val txt = Lang["MENU_IO_LOADING"] + App.fontGame.draw(batch, txt, (App.scr.width - App.fontGame.getWidth(txt)) / 2f, (App.scr.height - App.fontGame.lineHeight) / 2f) + + } + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadAutosave.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadAutosave.kt index e52d43446..f84d56d30 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadAutosave.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadAutosave.kt @@ -1,22 +1,18 @@ package net.torvald.terrarum.modulebasegame.ui import com.badlogic.gdx.graphics.Camera +import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Pixmap import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion -import net.torvald.terrarum.App -import net.torvald.terrarum.CommonResourcePool -import net.torvald.terrarum.DiskPair -import net.torvald.terrarum.SavegameCollectionPair +import net.torvald.terrarum.* import net.torvald.terrarum.langpack.Lang +import net.torvald.terrarum.modulebasegame.serialise.LoadSavegame import net.torvald.terrarum.savegame.ByteArray64InputStream import net.torvald.terrarum.savegame.EntryFile import net.torvald.terrarum.savegame.VDFileID -import net.torvald.terrarum.ui.Toolkit -import net.torvald.terrarum.ui.UICanvas -import net.torvald.terrarum.ui.UIItem -import net.torvald.terrarum.ui.UIItemImageButton +import net.torvald.terrarum.ui.* import java.time.Instant import java.time.format.DateTimeFormatter import java.util.* @@ -43,6 +39,26 @@ class UILoadAutosave(val full: UILoadSavegame) : UICanvas() { private lateinit var loadManualThumbButton: UIItemImageButton private lateinit var loadAutoThumbButton: UIItemImageButton + private val buttonXcentre = Toolkit.hdrawWidth - (full.buttonWidth / 2) + private val buttonRowY = full.drawY + 480 - full.buttonHeight + + private var mode = 0 + private val MODE_INIT = 0 + private val MODE_LOAD = 256 // is needed to make the static loading screen + + private lateinit var selectedGame: DiskPair + + private val mainBackButton = UIItemTextButton(this, + { Lang["MENU_LABEL_BACK"] }, buttonXcentre, buttonRowY, full.buttonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + it.clickOnceListener = { _,_ -> + full.changePanelTo(1) + } + } + + init { + addUIitem(mainBackButton) + } + override fun show() { super.show() @@ -62,10 +78,8 @@ class UILoadAutosave(val full: UILoadSavegame) : UICanvas() { ).also { it.extraDrawOp = getDrawTextualInfoFun(loadables.getManualSave()!!) it.clickOnceListener = { _,_ -> - loadables.getManualSave()!!.let { -// UILoadGovernor.playerDisk = it.player -// UILoadGovernor.worldDisk = it.world - } + selectedGame = loadables.getManualSave()!! + mode = MODE_LOAD } } loadAutoThumbButton = UIItemImageButton(this, autoThumb, @@ -80,10 +94,8 @@ class UILoadAutosave(val full: UILoadSavegame) : UICanvas() { ).also { it.extraDrawOp = getDrawTextualInfoFun(loadables.getAutoSave()!!) it.clickOnceListener = { _,_ -> - loadables.getAutoSave()!!.let { -// UILoadGovernor.playerDisk = it.player -// UILoadGovernor.worldDisk = it.world - } + selectedGame = loadables.getAutoSave()!! + mode = MODE_LOAD } } @@ -92,18 +104,30 @@ class UILoadAutosave(val full: UILoadSavegame) : UICanvas() { override fun updateUI(delta: Float) { if (::loadAutoThumbButton.isInitialized) loadAutoThumbButton.update(delta) if (::loadManualThumbButton.isInitialized) loadManualThumbButton.update(delta) + mainBackButton.update(delta) } - override fun renderUI(batch: SpriteBatch, camera: Camera) { - // "The Autosave is more recent than the manual save" - Toolkit.drawTextCentered(batch, App.fontGame, Lang["GAME_MORE_RECENT_AUTOSAVE1"], Toolkit.drawWidth, 0, altSelDrawY) - Toolkit.drawTextCentered(batch, App.fontGame, Lang["GAME_MORE_RECENT_AUTOSAVE2"], Toolkit.drawWidth, 0, altSelDrawY + 24) - // Manual Save Autosave - Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_IO_MANUAL_SAVE"], altSelHdrawW, (Toolkit.drawWidth - altSelDrawW)/2, altSelDrawY + 80) - Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_IO_AUTOSAVE"], altSelHdrawW, Toolkit.drawWidth/2, altSelDrawY + 80) + private var loadFiredFrameCounter = 0 - if (::loadAutoThumbButton.isInitialized) loadAutoThumbButton.render(batch, camera) - if (::loadManualThumbButton.isInitialized) loadManualThumbButton.render(batch, camera) + override fun renderUI(batch: SpriteBatch, camera: Camera) { + if (mode == MODE_INIT) { + // "The Autosave is more recent than the manual save" + Toolkit.drawTextCentered(batch, App.fontGame, Lang["GAME_MORE_RECENT_AUTOSAVE1"], Toolkit.drawWidth, 0, altSelDrawY) + Toolkit.drawTextCentered(batch, App.fontGame, Lang["GAME_MORE_RECENT_AUTOSAVE2"], Toolkit.drawWidth, 0, altSelDrawY + 24) + // Manual Save Autosave + Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_IO_MANUAL_SAVE"], altSelHdrawW, (Toolkit.drawWidth - altSelDrawW)/2, altSelDrawY + 80) + Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_IO_AUTOSAVE"], altSelHdrawW, Toolkit.drawWidth/2, altSelDrawY + 80) + + if (::loadAutoThumbButton.isInitialized) loadAutoThumbButton.render(batch, camera) + if (::loadManualThumbButton.isInitialized) loadManualThumbButton.render(batch, camera) + + mainBackButton.render(batch, camera) + } + else if (mode == MODE_LOAD) { + loadFiredFrameCounter += 1 + StaticLoadScreenSubstitute(batch) + if (loadFiredFrameCounter == 2) LoadSavegame(selectedGame) + } } override fun dispose() { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt index 61ad91462..e55e29f26 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt @@ -19,11 +19,11 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() { override var width: Int = Toolkit.drawWidth override var height: Int = App.scr.height - private val buttonHeight = 24 - private val buttonGap = 10 - private val buttonWidth = 180 - private val drawX = (Toolkit.drawWidth - 480) / 2 - private val drawY = (App.scr.height - 480) / 2 + private val buttonHeight = full.buttonHeight + private val buttonGap = full.buttonGap + private val buttonWidth = full.buttonWidth + private val drawX = full.drawX + private val drawY = full.drawY private val hx = Toolkit.hdrawWidth private val buttonX1third = hx - (buttonWidth * 1.5).toInt() - buttonGap @@ -37,18 +37,20 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() { private val buttonRowY2 = buttonRowY - buttonHeight - buttonGap private val mainGoButton = UIItemTextButton(this, - { Lang["MENU_IO_LOAD_GAME"] }, buttonX1third, buttonRowY, buttonWidth * 3 + buttonGap * 2, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + { Lang["MENU_IO_LOAD_GAME"] }, buttonX1third, buttonRowY2, buttonWidth * 3 + buttonGap * 2, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { it.clickOnceListener = { _,_ -> App.printdbg(this, "Load playerUUID: ${UILoadGovernor.playerUUID}, worldUUID: ${UILoadGovernor.worldUUID}") if (full.loadables.moreRecentAutosaveAvailable()) { - TODO() + full.bringAutosaveSelectorUp() + full.changePanelTo(2) } else if (full.loadables.saveAvaliable()) { if (full.loadables.newerSaveIsDamaged) { UILoadGovernor.previousSaveWasLoaded = true } + full.takeAutosaveSelectorDown() full.loadManageSelectedGame = full.loadables.getLoadableSave()!! mode = MODE_LOAD @@ -56,23 +58,23 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() { } } private val mainNoGoButton = UIItemTextButton(this, - { Lang["ERROR_SAVE_CORRUPTED"].replace(".","") }, buttonX1third, buttonRowY, buttonWidth * 3 + buttonGap * 2, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + { Lang["ERROR_SAVE_CORRUPTED"].replace(".","") }, buttonX1third, buttonRowY2, buttonWidth * 3 + buttonGap * 2, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { it.isEnabled = false } - private val mainReturnButton = UIItemTextButton(this, - { Lang["MENU_LABEL_BACK"] }, buttonX1third, buttonRowY2, buttonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { - it.clickOnceListener = { _,_ -> - full.changePanelTo(0) - } - } private val mainRenameButton = UIItemTextButton(this, - { Lang["MENU_LABEL_RENAME"] }, buttonXcentre, buttonRowY2, buttonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + { Lang["MENU_LABEL_RENAME"] }, buttonX1third, buttonRowY, buttonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { it.clickOnceListener = { _,_ -> mode = MODE_RENAME } } + private val mainBackButton = UIItemTextButton(this, + { Lang["MENU_LABEL_BACK"] }, buttonXcentre, buttonRowY, buttonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + it.clickOnceListener = { _,_ -> + full.changePanelTo(0) + } + } private val mainDeleteButton = UIItemTextButton(this, - { Lang["CONTEXT_CHARACTER_DELETE"] }, buttonX3third, buttonRowY2, buttonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true, inactiveCol = Toolkit.Theme.COL_RED, activeCol = Toolkit.Theme.COL_REDD).also { + { Lang["CONTEXT_CHARACTER_DELETE"] }, buttonX3third, buttonRowY, buttonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true, inactiveCol = Toolkit.Theme.COL_RED, activeCol = Toolkit.Theme.COL_REDD).also { it.clickOnceListener = { _,_ -> mode = MODE_DELETE } @@ -101,8 +103,8 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() { private var mode = 0 - private var mainButtons0 = listOf(mainGoButton, mainReturnButton, mainRenameButton, mainDeleteButton) - private var mainButtons1 = listOf(mainNoGoButton, mainReturnButton, mainRenameButton, mainDeleteButton) + private var mainButtons0 = listOf(mainGoButton, mainBackButton, mainRenameButton, mainDeleteButton) + private var mainButtons1 = listOf(mainNoGoButton, mainBackButton, mainRenameButton, mainDeleteButton) private var delButtons = listOf(confirmCancelButton, confirmDeleteButton) private val mainButtons: List @@ -154,20 +156,8 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() { } MODE_LOAD -> { loadFiredFrameCounter += 1 - // to hide the "flipped skybox" artefact - batch.end() - - gdxClearAndEnableBlend(.094f, .094f, .094f, 0f) - - batch.begin() - - batch.color = Color.WHITE - val txt = Lang["MENU_IO_LOADING"] - App.fontGame.draw(batch, txt, (App.scr.width - App.fontGame.getWidth(txt)) / 2f, (App.scr.height - App.fontGame.lineHeight) / 2f) - - if (loadFiredFrameCounter == 2) { - LoadSavegame(full.loadManageSelectedGame) - } + StaticLoadScreenSubstitute(batch) + if (loadFiredFrameCounter == 2) LoadSavegame(full.loadManageSelectedGame) } } } @@ -191,10 +181,10 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() { override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { when (mode) { MODE_INIT -> { - mainButtons.forEach { it.touchDown(screenX, screenY, pointer, button) } + mainButtons.forEach { it.touchUp(screenX, screenY, pointer, button) } } MODE_DELETE -> { - delButtons.forEach { it.touchDown(screenX, screenY, pointer, button) } + delButtons.forEach { it.touchUp(screenX, screenY, pointer, button) } } } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt index 691570ecc..2b7116920 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt @@ -73,25 +73,16 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { internal var playerButtonSelected: UIItemPlayerCells? = null - private val goButtonWidth = 180 - private val drawX = (Toolkit.drawWidth - 480) / 2 - private val drawY = (App.scr.height - 480) / 2 - private val buttonRowY = drawY + 480 - 24 internal lateinit var loadables: SavegameCollectionPair // will be used and modified by subUIs internal lateinit var loadManageSelectedGame: DiskPair - /*private val altSelDrawW = 640 - private val altSelHdrawW = altSelDrawW / 2 - private val altSelDrawH = 480 - private val imageButtonW = 300 - private val imageButtonH = 240 - private val altSelDrawY = ((App.scr.height - altSelDrawH)/2) - private val altSelQdrawW = altSelDrawW / 4 - private val altSelQQQdrawW = altSelDrawW * 3 / 4*/ - -// internal var hasNewerAutosave = false + internal val buttonHeight = 24 + internal val buttonGap = 10 + internal val buttonWidth = 180 + internal val drawX = (Toolkit.drawWidth - 480) / 2 + internal val drawY = (App.scr.height - 480) / 2 private val transitionalListing = UILoadList(this) private val transitionalAutosave = UILoadAutosave(this)