diff --git a/src/net/torvald/terrarum/modulebasegame/serialise/WriteSavegame.kt b/src/net/torvald/terrarum/modulebasegame/serialise/WriteSavegame.kt index 014c8c22a..105a339b1 100644 --- a/src/net/torvald/terrarum/modulebasegame/serialise/WriteSavegame.kt +++ b/src/net/torvald/terrarum/modulebasegame/serialise/WriteSavegame.kt @@ -119,6 +119,8 @@ object LoadSavegame { fun getFileBytes(disk: SimpleFileSystem, id: Long): ByteArray64 = disk.getFile(id)!!.bytes fun getFileReader(disk: SimpleFileSystem, id: Long): Reader = ByteArray64Reader(getFileBytes(disk, id), Common.CHARSET) + operator fun invoke(diskPair: DiskPair) = invoke(diskPair.player, diskPair.world) + /** * @param playerDisk DiskSkimmer representing the Player. * @param worldDisk0 DiskSkimmer representing the World to be loaded. @@ -126,12 +128,14 @@ object LoadSavegame { */ operator fun invoke(playerDisk: DiskSkimmer, worldDisk0: DiskSkimmer? = null) { val newIngame = TerrarumIngame(App.batch) + playerDisk.rebuild() val player = ReadActor.invoke(playerDisk, ByteArray64Reader(playerDisk.getFile(SAVEGAMEINFO)!!.bytes, Common.CHARSET)) as IngamePlayer printdbg(this, "Player localhash: ${player.localHashStr}, hasSprite: ${player.sprite != null}") val currentWorldId = player.worldCurrentlyPlaying val worldDisk = worldDisk0 ?: App.savegameWorlds[currentWorldId]!!.loadable() + worldDisk.rebuild() val world = ReadWorld(ByteArray64Reader(worldDisk.getFile(SAVEGAMEINFO)!!.bytes, Common.CHARSET), worldDisk.diskFile) world.layerTerrain = BlockLayer(world.width, world.height) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt b/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt index 5f9331f16..dc1ce93e7 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt @@ -305,7 +305,8 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory { } } ) - buttonCraft = UIItemTextButton(this, "GAME_ACTION_CRAFT", thisOffsetX + 3 + buttonWidth + listGap, craftButtonsY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) + buttonCraft = UIItemTextButton(this, + { Lang["GAME_ACTION_CRAFT"] }, thisOffsetX + 3 + buttonWidth + listGap, craftButtonsY, buttonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) spinnerCraftCount = UIItemSpinner(this, thisOffsetX + 1, craftButtonsY, 1, 1, App.getConfigInt("basegame:gameplay_max_crafting"), 1, buttonWidth, numberToTextFunction = {"×\u200A${it.toInt()}"}) spinnerCraftCount.selectionChangeListener = { itemListIngredients.numberMultiplier = it.toLong() diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIKeyboardControlPanel.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIKeyboardControlPanel.kt index 0203022d4..90b77c738 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIKeyboardControlPanel.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIKeyboardControlPanel.kt @@ -106,13 +106,12 @@ class UIKeyboardControlPanel(remoCon: UIRemoCon?) : UICanvas() { private val resetButtonWidth = 140 private val buttonReset = UIItemTextButton(this, - "MENU_LABEL_RESET", - kbx + (width - resetButtonWidth) / 2, - kby + 162 + 12, - resetButtonWidth, - readFromLang = true, - hasBorder = true, - alignment = UIItemTextButton.Companion.Alignment.CENTRE + { Lang["MENU_LABEL_RESET"] }, + kbx + (width - resetButtonWidth) / 2, + kby + 162 + 12, + resetButtonWidth, + hasBorder = true, + alignment = UIItemTextButton.Companion.Alignment.CENTRE ) private val controlPalette = UIItemControlPaletteBaloon(this, (Toolkit.drawWidth - 500) / 2, kby + 219) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadAutosave.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadAutosave.kt index 318956a09..e52d43446 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadAutosave.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadAutosave.kt @@ -46,7 +46,7 @@ class UILoadAutosave(val full: UILoadSavegame) : UICanvas() { override fun show() { super.show() - val loadables = SavegameCollectionPair(App.savegamePlayers[UILoadGovernor.playerUUID], App.savegameWorlds[UILoadGovernor.worldUUID]) + val loadables = full.loadables val autoThumb = loadables.getAutoSave()!!.getThumbnail() val manualThumb = loadables.getManualSave()!!.getThumbnail() diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadList.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadList.kt index d81dbc0b9..d6ea5f88c 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadList.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadList.kt @@ -69,33 +69,8 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() { fun advanceMode() { App.printdbg(this, "Load playerUUID: ${UILoadGovernor.playerUUID}, worldUUID: ${UILoadGovernor.worldUUID}") full.loadables = SavegameCollectionPair(App.savegamePlayers[UILoadGovernor.playerUUID], App.savegameWorlds[UILoadGovernor.worldUUID]) - - - if (full.loadables.moreRecentAutosaveAvailable()) { - // make choice for load manual or auto, if available - full.hasNewerAutosave = true - - full.queueUpManageScr() - full.bringAutosaveSelectorUp() - } - else if (!full.loadables.saveAvaliable()) { - // show save is damaged and cannot be loaded -// full.queueUpDamagedSaveScr() - full.queueUpManageScr() // management screen will take care of damaged saves - full.takeAutosaveSelectorDown() - } - else { -// val (p, w) = full.loadables.getLoadableSave()!! -// UILoadGovernor.playerDisk = p; UILoadGovernor.worldDisk = w - - if (full.loadables.newerSaveIsDamaged) { - UILoadGovernor.previousSaveWasLoaded = true - } - - full.queueUpManageScr() - full.takeAutosaveSelectorDown() - } - + full.queueUpManageScr() + full.takeAutosaveSelectorDown() full.changePanelTo(1) } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt index 10093f7db..61ad91462 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt @@ -1,15 +1,15 @@ 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.terrarum.App +import net.torvald.terrarum.gdxClearAndEnableBlend import net.torvald.terrarum.langpack.Lang -import net.torvald.terrarum.round -import net.torvald.terrarum.ui.Movement +import net.torvald.terrarum.modulebasegame.serialise.LoadSavegame import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UIItemTextButton -import kotlin.math.roundToInt /** * Created by minjaesong on 2023-07-05. @@ -36,34 +36,56 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() { private val buttonRowY = drawY + 480 - buttonHeight private val buttonRowY2 = buttonRowY - buttonHeight - buttonGap - private val mainGoButton = UIItemTextButton(this, "MENU_IO_LOAD_GAME", buttonX1third, buttonRowY, buttonWidth * 3 + buttonGap * 2, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + private val mainGoButton = UIItemTextButton(this, + { Lang["MENU_IO_LOAD_GAME"] }, buttonX1third, buttonRowY, 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() + } + else if (full.loadables.saveAvaliable()) { + if (full.loadables.newerSaveIsDamaged) { + UILoadGovernor.previousSaveWasLoaded = true + } + + full.loadManageSelectedGame = full.loadables.getLoadableSave()!! + + mode = MODE_LOAD + } + } } - private val mainNoGoButton = UIItemTextButton(this, "ERROR_SAVE_CORRUPTED", buttonX1third, buttonRowY, buttonWidth * 3 + buttonGap * 2, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + private val mainNoGoButton = UIItemTextButton(this, + { Lang["ERROR_SAVE_CORRUPTED"].replace(".","") }, buttonX1third, buttonRowY, buttonWidth * 3 + buttonGap * 2, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { it.isEnabled = false } - private val mainReturnButton = UIItemTextButton(this, "MENU_LABEL_BACK", buttonX1third, buttonRowY2, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + 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, "MENU_LABEL_RENAME", buttonXcentre, buttonRowY2, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + private val mainRenameButton = UIItemTextButton(this, + { Lang["MENU_LABEL_RENAME"] }, buttonXcentre, buttonRowY2, buttonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { it.clickOnceListener = { _,_ -> mode = MODE_RENAME } } - private val mainDeleteButton = UIItemTextButton(this, "CONTEXT_CHARACTER_DELETE", buttonX3third, buttonRowY2, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true, inactiveCol = Toolkit.Theme.COL_RED, activeCol = Toolkit.Theme.COL_REDD).also { + 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 { it.clickOnceListener = { _,_ -> mode = MODE_DELETE } } - private val confirmCancelButton = UIItemTextButton(this, "MENU_LABEL_CANCEL", buttonXleft, buttonRowY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { + private val confirmCancelButton = UIItemTextButton(this, + { Lang["MENU_LABEL_CANCEL"] }, buttonXleft, buttonRowY, buttonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { it.clickOnceListener = { _,_ -> mode = MODE_INIT } } - private val confirmDeleteButton = UIItemTextButton(this, "MENU_LABEL_DELETE", buttonXright, buttonRowY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true, inactiveCol = Toolkit.Theme.COL_RED, activeCol = Toolkit.Theme.COL_REDD).also { + private val confirmDeleteButton = UIItemTextButton(this, + { Lang["MENU_LABEL_DELETE"] }, buttonXright, buttonRowY, buttonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true, inactiveCol = Toolkit.Theme.COL_RED, activeCol = Toolkit.Theme.COL_REDD).also { it.clickOnceListener = { _,_ -> val pu = full.playerButtonSelected!!.playerUUID val wu = full.playerButtonSelected!!.worldUUID @@ -89,6 +111,7 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() { private val MODE_INIT = 0 private val MODE_DELETE = 16 // are you sure? private val MODE_RENAME = 32 // show rename dialogue + private val MODE_LOAD = 256 // is needed to make the static loading screen init { @@ -113,18 +136,39 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() { } } + private var loadFiredFrameCounter = 0 + override fun renderUI(batch: SpriteBatch, camera: Camera) { val buttonYdelta = (full.titleTopGradEnd + full.cellInterval) - full.playerButtonSelected!!.posY full.playerButtonSelected!!.render(batch, camera, 0, buttonYdelta) - if (mode == MODE_DELETE) { - Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_LABEL_SAVE_WILL_BE_DELETED"], Toolkit.drawWidth, 0, full.titleTopGradEnd + full.cellInterval - 46) - Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_LABEL_ARE_YOU_SURE"], Toolkit.drawWidth, 0, full.titleTopGradEnd + full.cellInterval + SAVE_CELL_HEIGHT + 36) + when (mode) { + MODE_INIT -> { + mainButtons.forEach { it.render(batch, camera) } + } + MODE_DELETE -> { + Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_LABEL_SAVE_WILL_BE_DELETED"], Toolkit.drawWidth, 0, full.titleTopGradEnd + full.cellInterval - 46) + Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_LABEL_ARE_YOU_SURE"], Toolkit.drawWidth, 0, full.titleTopGradEnd + full.cellInterval + SAVE_CELL_HEIGHT + 36) - delButtons.forEach { it.render(batch, camera) } - } - else if (mode == MODE_INIT) { - mainButtons.forEach { it.render(batch, camera) } + delButtons.forEach { it.render(batch, camera) } + } + 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) + } + } } } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSaveDamaged.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadSaveDamaged.kt deleted file mode 100644 index 74392e48c..000000000 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSaveDamaged.kt +++ /dev/null @@ -1,47 +0,0 @@ -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.terrarum.App -import net.torvald.terrarum.langpack.Lang -import net.torvald.terrarum.ui.Toolkit -import net.torvald.terrarum.ui.UICanvas -import net.torvald.terrarum.ui.UIItemTextButton - -/** - * Created by minjaesong on 2023-07-07. - */ -class UILoadSaveDamaged(val full: UILoadSavegame) : UICanvas() { - - override var width: Int = Toolkit.drawWidth - override var height: Int = App.scr.height - - 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 - private val corruptedBackButton = UIItemTextButton(this, "MENU_LABEL_BACK", (Toolkit.drawWidth - goButtonWidth) / 2, buttonRowY, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true).also { - it.clickOnceListener = { _,_ -> - full.changePanelTo(0) - } - } - - init { - addUIitem(corruptedBackButton) - } - - override fun updateUI(delta: Float) { - corruptedBackButton.update(delta) - } - - override fun renderUI(batch: SpriteBatch, camera: Camera) { - Toolkit.drawTextCentered(batch, App.fontGame, Lang["ERROR_SAVE_CORRUPTED"], Toolkit.drawWidth, 0, App.scr.height / 2 - 42) - - corruptedBackButton.render(batch, camera) - } - - override fun dispose() { - } - -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt index 26b27e89e..691570ecc 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt @@ -80,6 +80,8 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { 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 @@ -89,7 +91,7 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { private val altSelQdrawW = altSelDrawW / 4 private val altSelQQQdrawW = altSelDrawW * 3 / 4*/ - internal var hasNewerAutosave = false +// internal var hasNewerAutosave = false private val transitionalListing = UILoadList(this) private val transitionalAutosave = UILoadAutosave(this) @@ -132,7 +134,7 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { override fun show() { takeAutosaveSelectorDown() transitionPanel.show() - hasNewerAutosave = false +// hasNewerAutosave = false /*try { remoCon.handler.lockToggle() showSpinner = true diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UINewCharacter.kt b/src/net/torvald/terrarum/modulebasegame/ui/UINewCharacter.kt index 4d575ca18..acc2bda2a 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UINewCharacter.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UINewCharacter.kt @@ -40,8 +40,10 @@ class UINewCharacter(val remoCon: UIRemoCon) : UICanvas() { { RandomWordsName(4) }, InputLenCap(VirtualDisk.NAME_LENGTH, InputLenCap.CharLenUnit.UTF8_BYTES)) private val goButtonWidth = 180 - private val backButton = UIItemTextButton(this, "MENU_LABEL_BACK", drawX + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) - private val goButton = UIItemTextButton(this, "MENU_LABEL_CONFIRM_BUTTON", drawX + width/2 + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) + private val backButton = UIItemTextButton(this, + { Lang["MENU_LABEL_BACK"] }, drawX + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) + private val goButton = UIItemTextButton(this, + { Lang["MENU_LABEL_CONFIRM_BUTTON"] }, drawX + width/2 + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) private var returnedFromChargen = false diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt b/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt index e02e8dcab..058d0c8ef 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UINewWorld.kt @@ -85,8 +85,10 @@ class UINewWorld(val remoCon: UIRemoCon) : UICanvas() { { rng.nextLong().toString() }, InputLenCap(256, InputLenCap.CharLenUnit.CODEPOINTS)) private val goButtonWidth = 180 - private val backButton = UIItemTextButton(this, "MENU_LABEL_BACK", drawX + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) - private val goButton = UIItemTextButton(this, "MENU_LABEL_CONFIRM_BUTTON", drawX + width/2 + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) + private val backButton = UIItemTextButton(this, + { Lang["MENU_LABEL_BACK"] }, drawX + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) + private val goButton = UIItemTextButton(this, + { Lang["MENU_LABEL_CONFIRM_BUTTON"] }, drawX + width/2 + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) init { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt index 4576697d5..ee7eb51af 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt @@ -10,6 +10,7 @@ import net.torvald.terrarum.QNDTreeNode import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Yaml import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent +import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.TitleScreen import net.torvald.terrarum.serialise.WriteConfig import net.torvald.terrarum.ui.Toolkit @@ -100,11 +101,11 @@ open class UIRemoCon(val parent: TitleScreen, val treeRoot: QNDTreeNode) oldSelectedItem?.highlighted = false // selection change - if (it.labelText == "MENU_LABEL_QUIT") { + if (it.textfun() == Lang["MENU_LABEL_QUIT"]) { //System.exit(0) Gdx.app.exit() } - else if (it.labelText.startsWith("MENU_LABEL_RETURN")) { + else if (it.textfun() == Lang["MENU_LABEL_RETURN"]) { val tag = it.tags if (tag.contains("WRITETOCONFIG")) WriteConfig() diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UITitleLanguage.kt b/src/net/torvald/terrarum/modulebasegame/ui/UITitleLanguage.kt index 60442c40c..fcd866c40 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UITitleLanguage.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UITitleLanguage.kt @@ -80,12 +80,12 @@ class UITitleLanguage(remoCon: UIRemoCon?) : UICanvas() { // highlight initial textArea1.buttons.forEachIndexed { index, it -> - if (it.labelText == Lang["MENU_LANGUAGE_THIS"]) { + if (it.textfun() == Lang["MENU_LANGUAGE_THIS"]) { textArea1.select(index) } } textArea2.buttons.forEachIndexed { index, it -> - if (it.labelText == Lang["MENU_LANGUAGE_THIS"]) { + if (it.textfun() == Lang["MENU_LANGUAGE_THIS"]) { textArea2.select(index) } } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortal.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortal.kt index b3a1e3770..a96c1c6c8 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortal.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortal.kt @@ -65,7 +65,7 @@ class UIWorldPortal : UICanvas( App.scr.height, 0f, listOf(transitionalListing), - listOf(), + listOf(transitionalSearch), listOf() ) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalListing.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalListing.kt index b51fe3059..f2a83f07b 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalListing.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalListing.kt @@ -68,11 +68,10 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() { private val buttonsY = y + listHeight + gridGap private val buttonSearch = UIItemTextButton(this, - "CONTEXT_WORLD_NEW", + { Lang["CONTEXT_WORLD_NEW"] }, hx - gridGap/2 - 2*deleteButtonWidth - gridGap, buttonsY, deleteButtonWidth, - readFromLang = true, hasBorder = true, alignment = UIItemTextButton.Companion.Alignment.CENTRE ).also { @@ -81,11 +80,10 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() { } } private val buttonTeleport = UIItemTextButton(this, - "GAME_ACTION_TELEPORT", + { Lang["GAME_ACTION_TELEPORT"] }, hx - gridGap/2 - deleteButtonWidth, buttonsY, deleteButtonWidth, - readFromLang = true, hasBorder = true, alignment = UIItemTextButton.Companion.Alignment.CENTRE ).also { @@ -100,20 +98,18 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() { } } private val buttonRename = UIItemTextButton(this, - "MENU_LABEL_RENAME", + { Lang["MENU_LABEL_RENAME"] }, hx + gridGap/2, buttonsY, deleteButtonWidth, - readFromLang = true, hasBorder = true, alignment = UIItemTextButton.Companion.Alignment.CENTRE ) private val buttonDelete = UIItemTextButton(this, - "MENU_LABEL_DELETE", + { Lang["MENU_LABEL_DELETE"] }, hx + gridGap/2 + deleteButtonWidth + gridGap, buttonsY, deleteButtonWidth, - readFromLang = true, hasBorder = true, alignment = UIItemTextButton.Companion.Alignment.CENTRE ) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalSearch.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalSearch.kt index b7a7a65c4..1f311692e 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalSearch.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalSearch.kt @@ -78,8 +78,10 @@ class UIWorldPortalSearch(val full: UIWorldPortal) : UICanvas() { ) private val goButtonWidth = 180 - private val backButton = UIItemTextButton(this, "MENU_LABEL_BACK", drawX + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) - private val goButton = UIItemTextButton(this, "MENU_LABEL_CONFIRM_BUTTON", drawX + width/2 + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) + private val backButton = UIItemTextButton(this, + { Lang["MENU_LABEL_BACK"] }, drawX + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) + private val goButton = UIItemTextButton(this, + { Lang["MENU_LABEL_CONFIRM_BUTTON"] }, drawX + width/2 + (width/2 - goButtonWidth) / 2, drawY + height - 24, goButtonWidth, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) init { goButton.clickOnceListener = { _, _ -> diff --git a/src/net/torvald/terrarum/ui/UIItemTextButton.kt b/src/net/torvald/terrarum/ui/UIItemTextButton.kt index d94b809c5..50ec84e7e 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextButton.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextButton.kt @@ -16,11 +16,10 @@ import net.torvald.terrarum.langpack.Lang open class UIItemTextButton( parentUI: UICanvas, /** Stored text (independent to the Langpack) */ - val labelText: String, + val textfun: () -> String, initialX: Int, initialY: Int, override val width: Int, - val readFromLang: Boolean = false, /** Colour when mouse is over */ var activeCol: Color = Toolkit.Theme.COL_MOUSE_UP, @@ -38,6 +37,7 @@ open class UIItemTextButton( var inactiveCol: Color = Toolkit.Theme.COL_LIST_DEFAULT, var disabledCol: Color = Toolkit.Theme.COL_INVENTORY_CELL_BORDER, + var disabledTextCol: Color = Color(0x888888FF.toInt()), val hasBorder: Boolean = false, @@ -63,7 +63,7 @@ open class UIItemTextButton( /** Actually displayed text (changes with the app language) */ val label: String - get() = if (readFromLang) Lang[labelText] else labelText + get() = textfun() override val height: Int = hitboxSize @@ -128,6 +128,7 @@ open class UIItemTextButton( } // draw text + if (!isEnabled) batch.color = disabledTextCol font.draw(batch, label, fontX, fontY) } diff --git a/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt b/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt index b8628328f..37bf9fbd7 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt @@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.BlendMode import net.torvald.terrarum.Second import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.toInt import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack @@ -79,13 +80,15 @@ class UIItemTextButtonList( val lh = itemHitboxSize val vertOff = lineHeight * i + val ld0 = { s } + val ld1 = { Lang[s] } + // if (!kinematic) { UIItemTextButton( - parentUI, s, + parentUI, if (readFromLang) ld1 else ld0, initialX = posX, initialY = posY + vertOff, width = width, - readFromLang = readFromLang, activeCol = activeCol, activeBackCol = activeBackCol, activeBackBlendMode = activeBackBlendMode,