diff --git a/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt b/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt index b005bf743..e3ae5fe29 100644 --- a/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt +++ b/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt @@ -19,6 +19,7 @@ import net.torvald.terrarum.spriteassembler.ADProperties import net.torvald.terrarum.spriteassembler.ADPropertyObject import net.torvald.terrarum.spriteassembler.AssembleFrameBase import net.torvald.terrarum.spriteassembler.AssembleSheetPixmap +import net.torvald.terrarum.tryDispose import java.io.InputStream import java.util.* @@ -172,7 +173,7 @@ class AssembledSpriteAnimation( } override fun dispose() { - res.values.forEach { try { it?.texture?.dispose() } catch (_: GdxRuntimeException) {} } + res.values.forEach { it?.texture?.tryDispose() } } companion object { diff --git a/src/net/torvald/terrarum/IngameInstance.kt b/src/net/torvald/terrarum/IngameInstance.kt index 41dea50c5..6bc312280 100644 --- a/src/net/torvald/terrarum/IngameInstance.kt +++ b/src/net/torvald/terrarum/IngameInstance.kt @@ -205,13 +205,7 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo actorContainerInactive.forEach { it.dispose() } world.dispose() - disposables.forEach(Consumer { - try { it.dispose() } - catch (_: NullPointerException) { } - catch (_: IllegalArgumentException) { } - catch (_: GdxRuntimeException) { } - catch (_: ConcurrentModificationException) { } - }) + disposables.forEach(Consumer { it.tryDispose() }) } //////////// diff --git a/src/net/torvald/terrarum/SavegameCollection.kt b/src/net/torvald/terrarum/SavegameCollection.kt index 6947f86f4..c462c663b 100644 --- a/src/net/torvald/terrarum/SavegameCollection.kt +++ b/src/net/torvald/terrarum/SavegameCollection.kt @@ -1,11 +1,16 @@ package net.torvald.terrarum +import com.badlogic.gdx.graphics.Pixmap +import com.badlogic.gdx.graphics.Texture +import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.utils.JsonWriter import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.savegame.* +import net.torvald.terrarum.savegame.VDFileID.PLAYER_SCREENSHOT import net.torvald.terrarum.savegame.VDFileID.ROOT import net.torvald.terrarum.savegame.VDFileID.SAVEGAMEINFO +import net.torvald.terrarum.savegame.VDFileID.WORLD_SCREENSHOT import net.torvald.terrarum.serialise.Common import net.torvald.terrarum.utils.JsonFetcher import net.torvald.terrarum.utils.forEachSiblings @@ -14,7 +19,9 @@ import java.io.IOException import java.nio.file.Files import java.nio.file.StandardCopyOption import java.util.* +import java.util.zip.GZIPInputStream import kotlin.io.path.Path +import kotlin.math.roundToInt /** * Created by minjaesong on 2023-06-24. @@ -98,9 +105,35 @@ class SavegameCollection(files0: List) { skimmer.setDiskName(name, Common.CHARSET) } } + + private fun getThumbnail0(vid: EntryID, width: Int, height: Int, shrinkage: Double): TextureRegion? { + return this.loadable().requestFile(vid).let { file -> + if (file != null) { + val zippedTga = (file.contents as EntryFile).bytes + val gzin = GZIPInputStream(ByteArray64InputStream(zippedTga)) + val tgaFileContents = gzin.readAllBytes(); gzin.close() + val pixmap = Pixmap(tgaFileContents, 0, tgaFileContents.size) + TextureRegion(Texture(pixmap)).also { + App.disposables.add(it.texture) + // do cropping and resizing + it.setRegion( + ((pixmap.width - width*2) / shrinkage).roundToInt(), + ((pixmap.height - height*2) / shrinkage).roundToInt(), + (width * shrinkage).roundToInt(), + (height * shrinkage).roundToInt() + ) + } + } + else { + null + } + } + } + fun getPlayerThumbnail(width: Int, height: Int, shrinkage: Double) = getThumbnail0(PLAYER_SCREENSHOT, width, height, shrinkage) + fun getWorldThumbnail(width: Int, height: Int, shrinkage: Double) = getThumbnail0(WORLD_SCREENSHOT, width, height, shrinkage) } -class SavegameCollectionPair(player: SavegameCollection?, world: SavegameCollection?) { +class SavegameCollectionPair(private val player: SavegameCollection?, private val world: SavegameCollection?) { private var manualPlayer: DiskSkimmer? = null private var manualWorld: DiskSkimmer? = null @@ -222,4 +255,6 @@ class SavegameCollectionPair(player: SavegameCollection?, world: SavegameCollect } } -data class DiskPair(val player: DiskSkimmer, val world: DiskSkimmer) \ No newline at end of file +data class DiskPair(val player: DiskSkimmer, val world: DiskSkimmer) { + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index 067a13268..63c944749 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -10,6 +10,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.glutils.FrameBuffer import com.badlogic.gdx.graphics.glutils.ShapeRenderer import com.badlogic.gdx.utils.Disposable +import com.badlogic.gdx.utils.GdxRuntimeException import com.jme3.math.FastMath import net.torvald.gdx.graphics.Cvec import net.torvald.random.HQRNG @@ -896,3 +897,11 @@ fun checkForSavegameDamage(skimmer: DiskSkimmer): Boolean { return true } } + +/** + * No lateinit! + */ +inline fun Disposable.tryDispose() { + try { this.dispose() } + catch (_: Throwable) {} +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/TerrarumPostProcessor.kt b/src/net/torvald/terrarum/TerrarumPostProcessor.kt index afaf4e6ff..0423d83c3 100644 --- a/src/net/torvald/terrarum/TerrarumPostProcessor.kt +++ b/src/net/torvald/terrarum/TerrarumPostProcessor.kt @@ -63,7 +63,7 @@ object TerrarumPostProcessor : Disposable { } fun resize(w: Int, h: Int) { - try { outFBO.dispose() } catch (_: UninitializedPropertyAccessException) {} + if (::outFBO.isInitialized) outFBO.tryDispose() outFBO = FrameBuffer(Pixmap.Format.RGBA8888, w, h, false) } @@ -71,10 +71,10 @@ object TerrarumPostProcessor : Disposable { batch.dispose() shapeRenderer.dispose() functionRowHelper.dispose() - try { lutTex.dispose() } catch (_: UninitializedPropertyAccessException) {} shaderPostDither.dispose() shaderPostNoDither.dispose() - outFBO.dispose() + if (::lutTex.isInitialized) lutTex.tryDispose() + if (::outFBO.isInitialized) outFBO.dispose() } private var deltatBenchStr = "ΔF: Gathering data" diff --git a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt index d6770fe36..45153a239 100644 --- a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt +++ b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt @@ -862,27 +862,27 @@ object IngameRenderer : Disposable { } override fun dispose() { - try { blurWriteQuad.dispose() } catch (e: UninitializedPropertyAccessException) {} - try { blurWriteQuad2.dispose() } catch (e: UninitializedPropertyAccessException) {} - //try { blurWriteQuad4.dispose() } catch (e: UninitializedPropertyAccessException) {} + blurWriteQuad.tryDispose() + blurWriteQuad2.tryDispose() + //blurWriteQuad4.tryDispose() - try { fboRGB.dispose() } catch (e: UninitializedPropertyAccessException) {} - try { fboA.dispose() } catch (e: UninitializedPropertyAccessException) {} - try { fboRGB_lightMixed.dispose() } catch (e: UninitializedPropertyAccessException) {} - try { fboA_lightMixed.dispose() } catch (e: UninitializedPropertyAccessException) {} - try { fboMixedOut.dispose() } catch (e: UninitializedPropertyAccessException) {} - try { lightmapFbo.dispose() } catch (e: UninitializedPropertyAccessException) {} + fboRGB.tryDispose() + fboA.tryDispose() + fboRGB_lightMixed.tryDispose() + fboA_lightMixed.tryDispose() + fboMixedOut.tryDispose() + lightmapFbo.tryDispose() - try { blurtex0.dispose() } catch (e: GdxRuntimeException) {} + blurtex0.tryDispose() - try { fboBlurHalf.dispose() } catch (e: UninitializedPropertyAccessException) {} - //try { fboBlurQuarter.dispose() } catch (e: UninitializedPropertyAccessException) {} + fboBlurHalf.tryDispose() + //fboBlurQuarter.tryDispose() LightmapRenderer.dispose() BlocksDrawer.dispose() WeatherMixer.dispose() - try { batch.dispose() } catch (e: UninitializedPropertyAccessException) {} + batch.tryDispose() shaderBlur.dispose() @@ -896,10 +896,7 @@ object IngameRenderer : Disposable { shaderForActors.dispose() shaderDemultiply.dispose() - try { fboRGBexport.dispose() } - catch (e: GdxRuntimeException) {} - catch (e: UninitializedPropertyAccessException) {} - catch (e: Throwable) { e.printStackTrace(System.out) } + fboRGBexport.tryDispose() } private fun worldCamToRenderPos(): Pair { diff --git a/src/net/torvald/terrarum/modulebasegame/serialise/QuickSaveThread.kt b/src/net/torvald/terrarum/modulebasegame/serialise/QuickSaveThread.kt index 006694bc8..cdb88a8c6 100644 --- a/src/net/torvald/terrarum/modulebasegame/serialise/QuickSaveThread.kt +++ b/src/net/torvald/terrarum/modulebasegame/serialise/QuickSaveThread.kt @@ -9,8 +9,7 @@ import net.torvald.terrarum.realestate.LandUtil import net.torvald.terrarum.savegame.* import net.torvald.terrarum.savegame.VDFileID.ROOT import net.torvald.terrarum.savegame.VDFileID.SAVEGAMEINFO -import net.torvald.terrarum.savegame.VDFileID.THUMBNAIL -import net.torvald.terrarum.serialise.Common +import net.torvald.terrarum.savegame.VDFileID.WORLD_SCREENSHOT import net.torvald.terrarum.toInt import net.torvald.terrarum.utils.PlayerLastStatus import java.io.File @@ -84,7 +83,7 @@ class QuickSingleplayerWorldSavingThread( IngameRenderer.fboRGBexport.dispose() val thumbContent = EntryFile(tgaout.toByteArray64()) - val thumb = DiskEntry(THUMBNAIL, ROOT, creation_t, time_t, thumbContent) + val thumb = DiskEntry(WORLD_SCREENSHOT, ROOT, creation_t, time_t, thumbContent) addFile(disk, thumb) diff --git a/src/net/torvald/terrarum/modulebasegame/serialise/WorldSavingThread.kt b/src/net/torvald/terrarum/modulebasegame/serialise/WorldSavingThread.kt index 7091877de..922a0f038 100644 --- a/src/net/torvald/terrarum/modulebasegame/serialise/WorldSavingThread.kt +++ b/src/net/torvald/terrarum/modulebasegame/serialise/WorldSavingThread.kt @@ -108,7 +108,7 @@ class WorldSavingThread( IngameRenderer.fboRGBexport.dispose() val thumbContent = EntryFile(tgaout.toByteArray64()) - val thumb = DiskEntry(VDFileID.THUMBNAIL, VDFileID.ROOT, creation_t, time_t, thumbContent) + val thumb = DiskEntry(VDFileID.WORLD_SCREENSHOT, VDFileID.ROOT, creation_t, time_t, thumbContent) addFile(disk, thumb) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryMinimap.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryMinimap.kt index 361a9a52a..d0776d0bc 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryMinimap.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryMinimap.kt @@ -265,6 +265,6 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() { override fun dispose() { minimapFBO.dispose() - renderTextures.forEach { try { it.dispose() } catch (e: GdxRuntimeException) {} } + renderTextures.forEach { it.tryDispose() } } } \ 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 f84d56d30..9d7edfb20 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadAutosave.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadAutosave.kt @@ -138,8 +138,6 @@ class UILoadAutosave(val full: UILoadSavegame) : UICanvas() { private fun DiskPair.getThumbnail(): TextureRegion { return this.player.requestFile(VDFileID.PLAYER_SCREENSHOT).let { file -> - CommonResourcePool.getAsTextureRegion("terrarum-defaultsavegamethumb") - if (file != null) { val zippedTga = (file.contents as EntryFile).bytes val gzin = GZIPInputStream(ByteArray64InputStream(zippedTga)) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadDemoSavefiles.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadDemoSavefiles.kt index 03fc2c27b..65d3a5c4e 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadDemoSavefiles.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadDemoSavefiles.kt @@ -6,9 +6,7 @@ import com.badlogic.gdx.graphics.* import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.glutils.FrameBuffer -import com.badlogic.gdx.graphics.glutils.ShapeRenderer import com.badlogic.gdx.utils.GdxRuntimeException -import com.badlogic.gdx.utils.JsonReader import com.jme3.math.FastMath import net.torvald.unicode.EMDASH import net.torvald.unicode.getKeycapConsole @@ -458,8 +456,8 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : Advanceable() { } override fun dispose() { - try { shapeRenderer.dispose() } catch (e: IllegalArgumentException) {} - try { sliderFBO.dispose() } catch (e: IllegalArgumentException) {} + shapeRenderer.tryDispose() + sliderFBO.tryDispose() } override fun resize(width: Int, height: Int) { @@ -560,12 +558,12 @@ class UIItemPlayerCells( private var highlightCol: Color = defaultCol private var highlightTextCol: Color = defaultCol - var forceMouseDown = false + var forceUnhighlight = false override fun update(delta: Float) { super.update(delta) - highlightCol = if (mouseUp && !forceMouseDown) litCol else defaultCol - highlightTextCol = if (mouseUp && !forceMouseDown) litCol else Toolkit.Theme.COL_LIST_DEFAULT + highlightCol = if (mouseUp && !forceUnhighlight) litCol else defaultCol + highlightTextCol = if (mouseUp && !forceUnhighlight) litCol else Toolkit.Theme.COL_LIST_DEFAULT } fun render(batch: SpriteBatch, camera: Camera, offX: Int, offY: Int) { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt index a34b5dc8b..0c43745bf 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadManage.kt @@ -3,10 +3,13 @@ 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 com.badlogic.gdx.graphics.g2d.TextureRegion import net.torvald.terrarum.App -import net.torvald.terrarum.gdxClearAndEnableBlend +import net.torvald.terrarum.CommonResourcePool import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.serialise.LoadSavegame +import net.torvald.terrarum.savegame.VDFileID.PLAYER_SCREENSHOT +import net.torvald.terrarum.tryDispose import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UIItemTextButton @@ -119,12 +122,25 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() { } + private var screencap: TextureRegion? = null + private val screencapW = SAVE_CELL_WIDTH + private val screencapH = SAVE_CELL_HEIGHT * 2 + override fun doOpening(delta: Float) { - full.playerButtonSelected?.forceMouseDown = true + full.playerButtonSelected?.forceUnhighlight = true + full.playerButtonSelected?.let { button -> + screencap?.texture?.tryDispose() + screencap = App.savegamePlayers[button.playerUUID]!!.getPlayerThumbnail(screencapW, screencapH, 2.0) + } } override fun doClosing(delta: Float) { - full.playerButtonSelected?.forceMouseDown = false + full.playerButtonSelected?.forceUnhighlight = false + } + + override fun show() { + super.show() + } override fun updateUI(delta: Float) { @@ -141,12 +157,25 @@ 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 + val buttonYdelta = (full.titleTopGradEnd) - full.playerButtonSelected!!.posY full.playerButtonSelected!!.render(batch, camera, 0, buttonYdelta) when (mode) { MODE_INIT -> { mainButtons.forEach { it.render(batch, camera) } + + // draw thumbnails of the most recent game + val tex = screencap ?: CommonResourcePool.getAsTextureRegion("terrarum-defaultsavegamethumb") + val tx = (Toolkit.drawWidth - screencapW) / 2 + val ty = full.titleTopGradEnd + SAVE_CELL_HEIGHT + buttonGap + + batch.color = Toolkit.Theme.COL_INACTIVE + Toolkit.drawBoxBorder(batch, tx - 1, ty - 1, screencapW + 2, screencapH + 2) + batch.color = UIInventoryFull.CELL_COL + Toolkit.fillArea(batch, tx, ty, screencapW, screencapH) + batch.color = Color.WHITE + batch.draw(tex, tx.toFloat(), ty.toFloat(), screencapW.toFloat(), screencapH.toFloat()) + } MODE_DELETE -> { Toolkit.drawTextCentered(batch, App.fontGame, Lang["MENU_LABEL_SAVE_WILL_BE_DELETED"], Toolkit.drawWidth, 0, full.titleTopGradEnd + full.cellInterval - 46) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt b/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt index c50f192c5..bd67500d1 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UILoadSavegame.kt @@ -60,20 +60,8 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { internal val titleBottomGradStart: Int = height - App.scr.tvSafeGraphicsHeight - gradAreaHeight internal val titleBottomGradEnd: Int = titleBottomGradStart + gradAreaHeight - - private var scrollAreaHeight = height - 2 * App.scr.tvSafeGraphicsHeight - 64 - private var listScroll = 0 // only update when animation is finished - private var savesVisible = (scrollAreaHeight + cellGap) / cellInterval - private var uiScroll = 0f - private var scrollFrom = 0 - private var scrollTarget = 0 - private var scrollAnimCounter = 0f - private val scrollAnimLen = 0.1f - private var sliderFBO = FrameBuffer(Pixmap.Format.RGBA8888, uiWidth + 10, height, false) - internal var playerButtonSelected: UIItemPlayerCells? = null - internal lateinit var loadables: SavegameCollectionPair // will be used and modified by subUIs internal lateinit var loadManageSelectedGame: DiskPair @@ -88,7 +76,6 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { private val transitionalAutosave = UILoadAutosave(this) private val transitionalManage = UILoadManage(this) private val transitionalNewCharacter = UINewCharacter(remoCon) -// private val transitionalSaveDamaged = UILoadSaveDamaged(this) private val transitionPanel = UIItemHorizontalFadeSlide( this, (width - internalWidth) / 2, @@ -103,7 +90,6 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { internal fun queueUpManageScr() { transitionPanel.setCentreUIto(0) } internal fun queueUpNewCharScr() { transitionPanel.setCentreUIto(1) } -// internal fun queueUpDamagedSaveScr() { transitionPanel.setCentreUIto(2) } internal fun bringAutosaveSelectorUp() { transitionPanel.setRightUIto(1) } internal fun takeAutosaveSelectorDown() { transitionPanel.setRightUIto(0) } @@ -125,178 +111,19 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { override fun show() { takeAutosaveSelectorDown() transitionPanel.show() -// hasNewerAutosave = false - /*try { - remoCon.handler.lockToggle() - showSpinner = true - Thread { - // read savegames - var savegamesCount = 0 - App.sortedPlayers.forEach { uuid -> - val skimmer = App.savegamePlayers[uuid]!!.loadable() - val x = uiX - val y = titleTopGradEnd + cellInterval * savegamesCount - try { - playerCells.add(UIItemPlayerCells(this, x, y, skimmer)) - savegamesCount += 1 - } - catch (e: Throwable) { - System.err.println("[UILoadSavegame] Error while loading Player '${skimmer.diskFile.absolutePath}'") - e.printStackTrace() - } - } - - - remoCon.handler.unlockToggle() - showSpinner = false - }.start() - - } - catch (e: UninitializedPropertyAccessException) {}*/ } override fun hide() { transitionPanel.hide() -// playerCells.forEach { it.dispose() } -// playerCells.clear() - } - - private var touchLatched = false - -// private fun getCells() = playerCells - private var loadFired = 0 - private var oldMode = -1 - -// private val mode1Node = Yaml(UITitleRemoConYaml.injectedMenuSingleCharSel).parse() -// private val mode2Node = Yaml(UITitleRemoConYaml.injectedMenuSingleWorldSel).parse() - -// private val menus = listOf(mode1Node, mode2Node) - - /*private val deleteCharacterButton = UIItemTextButton( - this, "CONTEXT_CHARACTER_DELETE", - 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, - alignment = UIItemTextButton.Companion.Alignment.LEFT - ).also { - it.clickOnceListener = { _,_ -> - mode = MODE_SAVE_DELETE - it.highlighted = true - } - }*/ - - init { - // this UI will NOT persist; the parent of the mode1Node must be set using an absolute value (e.g. treeRoot, not remoCon.currentRemoConContents) - - //printdbg(this, "UILoadSavegame called, from:") - //printStackTrace(this) - -// mode1Node.parent = remoCon.treeRoot -// mode2Node.parent = mode1Node - -// mode1Node.data = "MENU_MODE_SINGLEPLAYER : net.torvald.terrarum.modulebasegame.ui.UILoadSavegame" -// mode2Node.data = "MENU_MODE_SINGLEPLAYER : net.torvald.terrarum.modulebasegame.ui.UILoadSavegame" - -// printdbg(this, "mode1Node parent: ${mode1Node.parent?.data}") // will be 'null' because the parent is the root node -// printdbg(this, "mode1Node data: ${mode1Node.data}") -// printdbg(this, "mode2Node data: ${mode2Node.data}") - - } - - private fun modeChangedHandler(mode: Int) { - printdbg(this, "Change mode: $oldMode -> $mode") -// remoCon.setNewRemoConContents(menus[mode]) -// remoCon.setNewRemoConContents(mode1Node) } override fun updateUI(delta: Float) { transitionPanel.update(delta) - /*if (mode == MODE_SELECT || mode == MODE_SAVE_DELETE) { - - if (oldMode != mode) { - modeChangedHandler(mode) - oldMode = mode - } - - if (scrollTarget != listScroll) { - if (scrollAnimCounter < scrollAnimLen) { - scrollAnimCounter += delta - uiScroll = Movement.fastPullOut( - scrollAnimCounter / scrollAnimLen, - listScroll * cellInterval.toFloat(), - scrollTarget * cellInterval.toFloat() - ) - } - else { - scrollAnimCounter = 0f - listScroll = scrollTarget - uiScroll = cellInterval.toFloat() * scrollTarget - } - } - - val cells = getCells() - - for (index in 0 until cells.size) { - - - val it = cells[index] - if (index in listScroll - 2 until listScroll + savesVisible + 2) { - // re-position - it.posY = (it.initialY - uiScroll).roundToInt() - it.update(delta) - } - } - }*/ - - /*if (mode == MODE_SAVE_DELETE_CONFIRM && deleteCellAnimCounter <= scrollAnimLen) { - // do transitional moving stuff - buttonSelectedForDeletion?.posY = Movement.fastPullOut(deleteCellAnimCounter / scrollAnimLen, deleteCellPosYstart, (titleTopGradEnd + cellInterval).toFloat()).roundToInt() - - deleteCellAnimCounter += delta - if (deleteCellAnimCounter > scrollAnimLen) deleteCellAnimCounter = scrollAnimLen - }*/ } - private var deleteCellAnimCounter = 0f - private var deleteCellPosYstart = 0f - override fun renderUI(batch: SpriteBatch, camera: Camera) { transitionPanel.render(batch, camera) - - /*if (mode == MODE_LOAD_DA_SHIT_ALREADY) { - loadFired += 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 (loadFired == 2) { - LoadSavegame(UILoadGovernor.playerDisk!!, UILoadGovernor.worldDisk) - } - } - - if (mode == MODE_SAVE_DELETE_CONFIRM) { - buttonSelectedForDeletion?.render(batch, camera) - confirmCancelButton.render(batch, camera) - confirmDeleteButton.render(batch, camera) - - 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 { @@ -315,48 +142,18 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() { } override fun scrolled(amountX: Float, amountY: Float): Boolean { - /*if (this.isVisible && mode == MODE_SELECT || mode == MODE_SAVE_DELETE) { - val cells = getCells() - - if (amountY <= -1f && scrollTarget > 0) { - scrollFrom = listScroll - scrollTarget -= 1 - scrollAnimCounter = 0f - } - else if (amountY >= 1f && scrollTarget < cells.size - savesVisible) { - scrollFrom = listScroll - scrollTarget += 1 - scrollAnimCounter = 0f - } - }*/ transitionPanel.scrolled(amountX, amountY) return true } - override fun endClosing(delta: Float) { - super.endClosing(delta) - listScroll = 0 - scrollTarget = 0 - uiScroll = 0f - } - override fun dispose() { - try { shapeRenderer.dispose() } catch (e: IllegalArgumentException) {} - try { sliderFBO.dispose() } catch (e: IllegalArgumentException) {} - try { transitionPanel.dispose() } catch (e: IllegalArgumentException) {} + shapeRenderer.tryDispose() + transitionPanel.tryDispose() } override fun resize(width: Int, height: Int) { + transitionPanel.uis.forEach { it.resize(width, height) } super.resize(width, height) - scrollAreaHeight = height - 2 * App.scr.tvSafeGraphicsHeight - 64 - savesVisible = (scrollAreaHeight + cellInterval) / (cellInterval + SAVE_CELL_HEIGHT) - - listScroll = 0 - scrollTarget = 0 - uiScroll = 0f - - sliderFBO.dispose() - sliderFBO = FrameBuffer(Pixmap.Format.RGBA8888, uiWidth + 10, height, false) } internal fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UITitleModules.kt b/src/net/torvald/terrarum/modulebasegame/ui/UITitleModules.kt index a2da1eb26..67e73bce2 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UITitleModules.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UITitleModules.kt @@ -244,7 +244,7 @@ class UITitleModules(val remoCon: UIRemoCon) : UICanvas() { } override fun dispose() { - try { sliderFBO.dispose() } catch (e: IllegalArgumentException) {} + sliderFBO.tryDispose() } override fun resize(width: Int, height: Int) { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalListing.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalListing.kt index 163467587..6e5803087 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalListing.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalListing.kt @@ -6,6 +6,7 @@ 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 com.badlogic.gdx.utils.Disposable import com.badlogic.gdx.utils.GdxRuntimeException import net.torvald.terrarum.* import net.torvald.terrarum.App.printdbg @@ -138,8 +139,8 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() { val lastPlayedString: String, val totalPlayedString: String, val screenshot: TextureRegion?, - ) { - fun dispose() { + ): Disposable { + override fun dispose() { screenshot?.texture?.dispose() } } @@ -419,14 +420,14 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() { uiItems.forEach { it.hide() } if (::worldCells.isInitialized) worldCells.forEach { it.hide() } - if (::worldCells.isInitialized) worldCells.forEach { try { it.dispose() } catch (_: GdxRuntimeException) {} } - worldList.forEach { try { it.dispose() } catch (_: GdxRuntimeException) {} } + if (::worldCells.isInitialized) worldCells.forEach { it.tryDispose() } + worldList.forEach { it.tryDispose() } } override fun dispose() { uiItems.forEach { it.dispose() } - if (::worldCells.isInitialized) worldCells.forEach { try { it.dispose() } catch (_: GdxRuntimeException) {} } - worldList.forEach { try { it.dispose() } catch (_: GdxRuntimeException) {} } + if (::worldCells.isInitialized) worldCells.forEach { it.tryDispose() } + worldList.forEach { it.tryDispose() } } override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { diff --git a/src/net/torvald/terrarum/savegame/VirtualDisk.kt b/src/net/torvald/terrarum/savegame/VirtualDisk.kt index 4b5ffb202..450bb07fd 100644 --- a/src/net/torvald/terrarum/savegame/VirtualDisk.kt +++ b/src/net/torvald/terrarum/savegame/VirtualDisk.kt @@ -10,8 +10,6 @@ import java.io.IOException import java.nio.charset.Charset import java.util.* import java.util.zip.CRC32 -import kotlin.experimental.and -import kotlin.experimental.or /* @@ -255,7 +253,7 @@ object VDFileID { const val ROOT = 0L const val SAVEGAMEINFO = -1L const val PLAYER_JSON = -1L - const val THUMBNAIL = -2L + const val WORLD_SCREENSHOT = -2L const val SPRITEDEF = -2L const val SPRITEDEF_GLOW = -3L const val LOADORDER = -4L @@ -267,7 +265,7 @@ object VDFileID { fun diskIDtoReadableFilename(id: EntryID, saveKind: Int?): String = when (id) { VDFileID.ROOT -> "root" VDFileID.SAVEGAMEINFO -> "savegameinfo.json" - VDFileID.THUMBNAIL, VDFileID.SPRITEDEF -> + VDFileID.WORLD_SCREENSHOT, VDFileID.SPRITEDEF -> if (saveKind == PLAYER_DATA) "spritedef" else if (saveKind == WORLD_DATA) diff --git a/src/net/torvald/terrarum/tests/UITestPad1.kt b/src/net/torvald/terrarum/tests/UITestPad1.kt index d6e5b757a..212863d32 100644 --- a/src/net/torvald/terrarum/tests/UITestPad1.kt +++ b/src/net/torvald/terrarum/tests/UITestPad1.kt @@ -105,8 +105,8 @@ class UITestPad1 : TerrarumGamescreen { } override fun dispose() { - try { colourPickerTex.dispose() } catch (e: GdxRuntimeException) {} - try { colourPickerPixmap.dispose() } catch (e: GdxRuntimeException) {} + colourPickerTex.tryDispose() + colourPickerPixmap.tryDispose() } diff --git a/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt b/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt index f95e66c56..dd19f038e 100644 --- a/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt +++ b/src/net/torvald/terrarum/ui/UIItemHorizontalFadeSlide.kt @@ -3,6 +3,7 @@ package net.torvald.terrarum.ui import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.INGAME import net.torvald.terrarum.modulebasegame.ui.NullUI +import net.torvald.terrarum.tryDispose import kotlin.math.absoluteValue import kotlin.math.roundToInt @@ -81,9 +82,9 @@ class UIItemHorizontalFadeSlide( } override fun dispose() { - uisOnLeft.forEach { try { it.dispose() } catch (e: IllegalArgumentException) {} } - uisOnCentre.forEach { try { it.dispose() } catch (e: IllegalArgumentException) {} } - uisOnRight.forEach { try { it.dispose() } catch (e: IllegalArgumentException) {} } + uisOnLeft.forEach { it.tryDispose() } + uisOnCentre.forEach { it.tryDispose() } + uisOnRight.forEach { it.tryDispose() } } override fun keyDown(keycode: Int): Boolean { diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt index afff3bf13..60a4f77cd 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawer.kt @@ -743,7 +743,7 @@ internal object BlocksDrawer { tilesFluid.dispose() tilesBuffer.dispose() _tilesBufferAsTex.dispose() - try { tilesQuad.dispose() } catch (e: UninitializedPropertyAccessException) {} + tilesQuad.tryDispose() shader.dispose() App.tileMaker.dispose()