From bb017fa9b7c110b6f138f3664f8e351432a64048 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 28 Jun 2023 16:10:15 +0900 Subject: [PATCH] gui for load savegame --- assets/locales/en/terrarum.json | 3 +- assets/locales/koKR/terrarum.json | 5 +- .../torvald/terrarum/SavegameCollection.kt | 2 +- src/net/torvald/terrarum/Terrarum.kt | 1 + .../modulebasegame/ui/UILoadSavegame.kt | 59 ++++++++++--------- src/net/torvald/terrarum/ui/Toolkit.kt | 7 +++ 6 files changed, 46 insertions(+), 31 deletions(-) diff --git a/assets/locales/en/terrarum.json b/assets/locales/en/terrarum.json index cb03ebed8..f48a4a6ba 100644 --- a/assets/locales/en/terrarum.json +++ b/assets/locales/en/terrarum.json @@ -44,5 +44,6 @@ "GAME_MORE_RECENT_AUTOSAVE1": "The Autosave is more recent than the manual save.", "GAME_MORE_RECENT_AUTOSAVE2": "Please select the saved game you wish to play:", "MENU_IO_MANUAL_SAVE": "Manual Save", - "MENU_IO_AUTOSAVE": "Autosave" + "MENU_IO_AUTOSAVE": "Autosave", + "MENU_LABEL_SAVE_WILL_BE_DELETED": "The selected save file will be deleted." } \ No newline at end of file diff --git a/assets/locales/koKR/terrarum.json b/assets/locales/koKR/terrarum.json index 3b7bc438f..66d203cca 100644 --- a/assets/locales/koKR/terrarum.json +++ b/assets/locales/koKR/terrarum.json @@ -40,7 +40,8 @@ "GAME_PREV_SAVE_WAS_LOADED1": "가장 최근에 저장된 게임이 손상되었습니다.", "GAME_PREV_SAVE_WAS_LOADED2": "이전에 저장된 게임을 불러왔습니다.", "GAME_MORE_RECENT_AUTOSAVE1": "자동 저장된 게임이 수동으로 저장한 게임보다 더 최신입니다.", - "GAME_MORE_RECENT_AUTOSAVE2": "불러올 게임을 선택해주십시오.", + "GAME_MORE_RECENT_AUTOSAVE2": "불러올 게임을 선택해 주십시오.", "MENU_IO_MANUAL_SAVE": "수동 저장", - "MENU_IO_AUTOSAVE": "자동 저장" + "MENU_IO_AUTOSAVE": "자동 저장", + "MENU_LABEL_SAVE_WILL_BE_DELETED": "선택된 세이브가 삭제됩니다." } diff --git a/src/net/torvald/terrarum/SavegameCollection.kt b/src/net/torvald/terrarum/SavegameCollection.kt index a02d66236..24a405802 100644 --- a/src/net/torvald/terrarum/SavegameCollection.kt +++ b/src/net/torvald/terrarum/SavegameCollection.kt @@ -14,7 +14,7 @@ import kotlin.io.path.Path class SavegameCollection(files0: List) { /** Sorted in reverse by the last modified time of the files, index zero being the most recent */ - val files = files0.sortedByDescending { it.getLastModifiedTime() } + val files = files0.sortedByDescending { it.getLastModifiedTime().shl(1) or it.diskFile.extension.matches(Regex("^[abc]\$")).toLong() } /** Sorted in reverse by the last modified time of the files, index zero being the most recent */ val autoSaves = files.filter { it.diskFile.extension.matches(Regex("[a-z]")) } /** Sorted in reverse by the last modified time of the files, index zero being the most recent */ diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index 44cf84940..2bcc0226e 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -630,6 +630,7 @@ fun Float.sqrt() = FastMath.sqrt(this) fun Int.abs() = this.absoluteValue fun Double.bipolarClamp(limit: Double) = this.coerceIn(-limit, limit) fun Boolean.toInt(shift: Int = 0) = if (this) 1.shl(shift) else 0 +fun Boolean.toLong(shift: Int = 0) = if (this) 1L.shl(shift) else 0L fun Int.bitCount() = java.lang.Integer.bitCount(this) fun Long.bitCount() = java.lang.Long.bitCount(this) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt index e6237f656..2a6818626 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt @@ -116,7 +116,8 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { private val goButtonWidth = 180 private val drawX = (Toolkit.drawWidth - 480) / 2 private val drawY = (App.scr.height - 480) / 2 - private val confirmBackButton = UIItemTextButton(this, "MENU_LABEL_BACK", drawX + (240 - goButtonWidth) / 2, drawY + 480 - 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) + private val corruptedBackButton = UIItemTextButton(this, "MENU_LABEL_BACK", (Toolkit.drawWidth - goButtonWidth) / 2, drawY + 480 - 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) + private val confirmCancelButton = UIItemTextButton(this, "MENU_LABEL_CANCEL", drawX + (240 - goButtonWidth) / 2, drawY + 480 - 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) private val confirmDeleteButton = UIItemTextButton(this, "MENU_LABEL_DELETE", drawX + 240 + (240 - goButtonWidth) / 2, drawY + 480- 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true, inactiveCol = Toolkit.Theme.COL_RED, activeCol = Toolkit.Theme.COL_REDD) private lateinit var loadables: SavegameCollectionPair @@ -171,9 +172,8 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { } init { - confirmBackButton.clickOnceListener = { _,_ -> - remoCon.openUI(UILoadSavegame(remoCon)) - } + corruptedBackButton.clickOnceListener = { _,_ -> remoCon.openUI(UILoadSavegame(remoCon)) } + confirmCancelButton.clickOnceListener = { _, _ -> remoCon.openUI(UILoadSavegame(remoCon)) } confirmDeleteButton.clickOnceListener = { _,_ -> val pu = buttonSelectedForDeletion!!.playerUUID val wu = buttonSelectedForDeletion!!.worldUUID @@ -182,11 +182,7 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { App.savegamePlayers.remove(pu) App.savegamePlayersName.remove(pu) } - App.savegameWorlds[wu]?.moveToRecycle(App.recycledWorldsDir)?.let { - App.sortedSavegameWorlds.remove(wu) - App.savegameWorlds.remove(wu) - App.savegameWorldsName.remove(wu) - } + // don't delete the world please remoCon.openUI(UILoadSavegame(remoCon)) } } @@ -374,13 +370,14 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { private val deleteCharacterButton = UIItemTextButton( this, "CONTEXT_CHARACTER_DELETE", - UIRemoCon.menubarOffX - UIRemoCon.UIRemoConElement.paddingLeft + 11, + UIRemoCon.menubarOffX - UIRemoCon.UIRemoConElement.paddingLeft + 72, UIRemoCon.menubarOffY - UIRemoCon.UIRemoConElement.lineHeight * 3 + 16, remoCon.width + UIRemoCon.UIRemoConElement.paddingLeft, true, inactiveCol = Toolkit.Theme.COL_RED, activeCol = Toolkit.Theme.COL_REDD, - hitboxSize = UIRemoCon.UIRemoConElement.lineHeight - 2 + hitboxSize = UIRemoCon.UIRemoConElement.lineHeight - 2, + alignment = UIItemTextButton.Companion.Alignment.LEFT ).also { it.clickOnceListener = { _,_ -> mode = MODE_SAVE_DELETE @@ -553,34 +550,40 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { } else if (mode == MODE_SAVE_MULTIPLE_CHOICES) { // "The Autosave is more recent than the manual save" - val tw1 = App.fontGame.getWidth(Lang["GAME_MORE_RECENT_AUTOSAVE1"]) - val tw2 = App.fontGame.getWidth(Lang["GAME_MORE_RECENT_AUTOSAVE2"]) - App.fontGame.draw(batch, Lang["GAME_MORE_RECENT_AUTOSAVE1"], ((Toolkit.drawWidth - tw1)/2).toFloat(), altSelDrawY + 0f) - App.fontGame.draw(batch, Lang["GAME_MORE_RECENT_AUTOSAVE2"], ((Toolkit.drawWidth - tw2)/2).toFloat(), altSelDrawY + 24f) - - val twm = App.fontGame.getWidth(Lang["MENU_IO_MANUAL_SAVE"]) - val twa = App.fontGame.getWidth(Lang["MENU_IO_AUTOSAVE"]) - - App.fontGame.draw(batch, Lang["MENU_IO_MANUAL_SAVE"], ((Toolkit.drawWidth - altSelDrawW)/2).toFloat() + altSelQdrawW - twm/2, altSelDrawY + 80f) - App.fontGame.draw(batch, Lang["MENU_IO_AUTOSAVE"], ((Toolkit.drawWidth - altSelDrawW)/2).toFloat() + altSelQQQdrawW - twa/2, altSelDrawY + 80f) + 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) // draw thumbnail-buttons loadAutoThumbButton.render(batch, camera) loadManualThumbButton.render(batch, camera) } + else if (mode == MODE_SAVE_DAMAGED) { + Toolkit.drawTextCentered(batch, App.fontGame, Lang["ERROR_SAVE_CORRUPTED"], Toolkit.drawWidth, 0, App.scr.height / 2 - 42) + + corruptedBackButton.render(batch, camera) + } if (mode == MODE_SELECT || mode == MODE_SAVE_DELETE || mode == MODE_SAVE_DELETE_CONFIRM) { deleteCharacterButton.render(batch, camera) } if (mode == MODE_SAVE_DELETE_CONFIRM) { - // do transitional moving stuff - buttonSelectedForDeletion?.render(batch, camera) - confirmBackButton.render(batch, camera) + confirmCancelButton.render(batch, camera) confirmDeleteButton.render(batch, camera) } + + if (mode == MODE_SAVE_DELETE_CONFIRM) { + batch.color = Color.WHITE + Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_LABEL_SAVE_WILL_BE_DELETED"], Toolkit.drawWidth, 0, titleTopGradEnd + cellInterval - 46) + Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_LABEL_ARE_YOU_SURE"], Toolkit.drawWidth, 0, titleTopGradEnd + cellInterval + SAVE_CELL_HEIGHT + 36) + } + + } override fun keyDown(keycode: Int): Boolean { @@ -607,9 +610,10 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { if (::loadManualThumbButton.isInitialized && mode == MODE_SAVE_MULTIPLE_CHOICES) { loadManualThumbButton.touchDown(screenX, screenY, pointer, button) } if (mode == MODE_SELECT || mode == MODE_SAVE_DELETE) deleteCharacterButton.touchDown(screenX, screenY, pointer, button) if (mode == MODE_SAVE_DELETE_CONFIRM) { - confirmBackButton.touchDown(screenX, screenY, pointer, button) + confirmCancelButton.touchDown(screenX, screenY, pointer, button) confirmDeleteButton.touchDown(screenX, screenY, pointer, button) } + if (mode == MODE_SAVE_DAMAGED) corruptedBackButton.touchDown(screenX, screenY, pointer, button) return true } @@ -618,11 +622,12 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { if (mode == MODE_SELECT || mode == MODE_SAVE_DELETE) 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) } - if (mode == MODE_SELECT || mode == MODE_SAVE_DELETE) deleteCharacterButton.touchDown(screenX, screenY, pointer, button) + if (mode == MODE_SELECT || mode == MODE_SAVE_DELETE) deleteCharacterButton.touchUp(screenX, screenY, pointer, button) if (mode == MODE_SAVE_DELETE_CONFIRM) { - confirmBackButton.touchUp(screenX, screenY, pointer, button) + confirmCancelButton.touchUp(screenX, screenY, pointer, button) confirmDeleteButton.touchUp(screenX, screenY, pointer, button) } + if (mode == MODE_SAVE_DAMAGED) corruptedBackButton.touchUp(screenX, screenY, pointer, button) return true } diff --git a/src/net/torvald/terrarum/ui/Toolkit.kt b/src/net/torvald/terrarum/ui/Toolkit.kt index e12cb3c5a..d3e229511 100644 --- a/src/net/torvald/terrarum/ui/Toolkit.kt +++ b/src/net/torvald/terrarum/ui/Toolkit.kt @@ -2,6 +2,7 @@ package net.torvald.terrarum.ui import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.* +import com.badlogic.gdx.graphics.g2d.BitmapFont import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.glutils.FloatFrameBuffer @@ -9,6 +10,7 @@ import com.badlogic.gdx.utils.Disposable import com.jme3.math.FastMath import net.torvald.random.HQRNG import net.torvald.terrarum.* +import net.torvald.terrarumsansbitmap.gdx.TerrarumSansBitmap import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import kotlin.math.roundToInt @@ -120,6 +122,11 @@ object Toolkit : Disposable { batch.draw(image, targetW.minus(imageW).ushr(1).toFloat() + offsetX, screenPosY.toFloat() + offsetY) } + fun drawTextCentered(batch: SpriteBatch, font: TerrarumSansBitmap, text: String, tbw: Int, tbx: Int, tby: Int) { + val tw = font.getWidth(text) + font.draw(batch, text, tbx + (tbw - tw) / 2, tby) + } + fun fillArea(batch: SpriteBatch, x: Int, y: Int, w: Int, h: Int) { batch.draw(textureWhiteSquare, x.toFloat(), y.toFloat(), w.toFloat(), h.toFloat()) }