load list: thumbnail on management scr

This commit is contained in:
minjaesong
2023-07-11 15:18:44 +09:00
parent c033260ec5
commit 64e05a4f17
19 changed files with 128 additions and 271 deletions

View File

@@ -19,6 +19,7 @@ import net.torvald.terrarum.spriteassembler.ADProperties
import net.torvald.terrarum.spriteassembler.ADPropertyObject import net.torvald.terrarum.spriteassembler.ADPropertyObject
import net.torvald.terrarum.spriteassembler.AssembleFrameBase import net.torvald.terrarum.spriteassembler.AssembleFrameBase
import net.torvald.terrarum.spriteassembler.AssembleSheetPixmap import net.torvald.terrarum.spriteassembler.AssembleSheetPixmap
import net.torvald.terrarum.tryDispose
import java.io.InputStream import java.io.InputStream
import java.util.* import java.util.*
@@ -172,7 +173,7 @@ class AssembledSpriteAnimation(
} }
override fun dispose() { override fun dispose() {
res.values.forEach { try { it?.texture?.dispose() } catch (_: GdxRuntimeException) {} } res.values.forEach { it?.texture?.tryDispose() }
} }
companion object { companion object {

View File

@@ -205,13 +205,7 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
actorContainerInactive.forEach { it.dispose() } actorContainerInactive.forEach { it.dispose() }
world.dispose() world.dispose()
disposables.forEach(Consumer { disposables.forEach(Consumer { it.tryDispose() })
try { it.dispose() }
catch (_: NullPointerException) { }
catch (_: IllegalArgumentException) { }
catch (_: GdxRuntimeException) { }
catch (_: ConcurrentModificationException) { }
})
} }
//////////// ////////////

View File

@@ -1,11 +1,16 @@
package net.torvald.terrarum 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 com.badlogic.gdx.utils.JsonWriter
import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.savegame.* 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.ROOT
import net.torvald.terrarum.savegame.VDFileID.SAVEGAMEINFO 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.serialise.Common
import net.torvald.terrarum.utils.JsonFetcher import net.torvald.terrarum.utils.JsonFetcher
import net.torvald.terrarum.utils.forEachSiblings import net.torvald.terrarum.utils.forEachSiblings
@@ -14,7 +19,9 @@ import java.io.IOException
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.StandardCopyOption import java.nio.file.StandardCopyOption
import java.util.* import java.util.*
import java.util.zip.GZIPInputStream
import kotlin.io.path.Path import kotlin.io.path.Path
import kotlin.math.roundToInt
/** /**
* Created by minjaesong on 2023-06-24. * Created by minjaesong on 2023-06-24.
@@ -98,9 +105,35 @@ class SavegameCollection(files0: List<DiskSkimmer>) {
skimmer.setDiskName(name, Common.CHARSET) 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 manualPlayer: DiskSkimmer? = null
private var manualWorld: 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) data class DiskPair(val player: DiskSkimmer, val world: DiskSkimmer) {
}

View File

@@ -10,6 +10,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.FrameBuffer import com.badlogic.gdx.graphics.glutils.FrameBuffer
import com.badlogic.gdx.graphics.glutils.ShapeRenderer import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.utils.Disposable import com.badlogic.gdx.utils.Disposable
import com.badlogic.gdx.utils.GdxRuntimeException
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.gdx.graphics.Cvec import net.torvald.gdx.graphics.Cvec
import net.torvald.random.HQRNG import net.torvald.random.HQRNG
@@ -896,3 +897,11 @@ fun checkForSavegameDamage(skimmer: DiskSkimmer): Boolean {
return true return true
} }
} }
/**
* No lateinit!
*/
inline fun Disposable.tryDispose() {
try { this.dispose() }
catch (_: Throwable) {}
}

View File

@@ -63,7 +63,7 @@ object TerrarumPostProcessor : Disposable {
} }
fun resize(w: Int, h: Int) { fun resize(w: Int, h: Int) {
try { outFBO.dispose() } catch (_: UninitializedPropertyAccessException) {} if (::outFBO.isInitialized) outFBO.tryDispose()
outFBO = FrameBuffer(Pixmap.Format.RGBA8888, w, h, false) outFBO = FrameBuffer(Pixmap.Format.RGBA8888, w, h, false)
} }
@@ -71,10 +71,10 @@ object TerrarumPostProcessor : Disposable {
batch.dispose() batch.dispose()
shapeRenderer.dispose() shapeRenderer.dispose()
functionRowHelper.dispose() functionRowHelper.dispose()
try { lutTex.dispose() } catch (_: UninitializedPropertyAccessException) {}
shaderPostDither.dispose() shaderPostDither.dispose()
shaderPostNoDither.dispose() shaderPostNoDither.dispose()
outFBO.dispose() if (::lutTex.isInitialized) lutTex.tryDispose()
if (::outFBO.isInitialized) outFBO.dispose()
} }
private var deltatBenchStr = "ΔF: Gathering data" private var deltatBenchStr = "ΔF: Gathering data"

View File

@@ -862,27 +862,27 @@ object IngameRenderer : Disposable {
} }
override fun dispose() { override fun dispose() {
try { blurWriteQuad.dispose() } catch (e: UninitializedPropertyAccessException) {} blurWriteQuad.tryDispose()
try { blurWriteQuad2.dispose() } catch (e: UninitializedPropertyAccessException) {} blurWriteQuad2.tryDispose()
//try { blurWriteQuad4.dispose() } catch (e: UninitializedPropertyAccessException) {} //blurWriteQuad4.tryDispose()
try { fboRGB.dispose() } catch (e: UninitializedPropertyAccessException) {} fboRGB.tryDispose()
try { fboA.dispose() } catch (e: UninitializedPropertyAccessException) {} fboA.tryDispose()
try { fboRGB_lightMixed.dispose() } catch (e: UninitializedPropertyAccessException) {} fboRGB_lightMixed.tryDispose()
try { fboA_lightMixed.dispose() } catch (e: UninitializedPropertyAccessException) {} fboA_lightMixed.tryDispose()
try { fboMixedOut.dispose() } catch (e: UninitializedPropertyAccessException) {} fboMixedOut.tryDispose()
try { lightmapFbo.dispose() } catch (e: UninitializedPropertyAccessException) {} lightmapFbo.tryDispose()
try { blurtex0.dispose() } catch (e: GdxRuntimeException) {} blurtex0.tryDispose()
try { fboBlurHalf.dispose() } catch (e: UninitializedPropertyAccessException) {} fboBlurHalf.tryDispose()
//try { fboBlurQuarter.dispose() } catch (e: UninitializedPropertyAccessException) {} //fboBlurQuarter.tryDispose()
LightmapRenderer.dispose() LightmapRenderer.dispose()
BlocksDrawer.dispose() BlocksDrawer.dispose()
WeatherMixer.dispose() WeatherMixer.dispose()
try { batch.dispose() } catch (e: UninitializedPropertyAccessException) {} batch.tryDispose()
shaderBlur.dispose() shaderBlur.dispose()
@@ -896,10 +896,7 @@ object IngameRenderer : Disposable {
shaderForActors.dispose() shaderForActors.dispose()
shaderDemultiply.dispose() shaderDemultiply.dispose()
try { fboRGBexport.dispose() } fboRGBexport.tryDispose()
catch (e: GdxRuntimeException) {}
catch (e: UninitializedPropertyAccessException) {}
catch (e: Throwable) { e.printStackTrace(System.out) }
} }
private fun worldCamToRenderPos(): Pair<Float, Float> { private fun worldCamToRenderPos(): Pair<Float, Float> {

View File

@@ -9,8 +9,7 @@ import net.torvald.terrarum.realestate.LandUtil
import net.torvald.terrarum.savegame.* import net.torvald.terrarum.savegame.*
import net.torvald.terrarum.savegame.VDFileID.ROOT import net.torvald.terrarum.savegame.VDFileID.ROOT
import net.torvald.terrarum.savegame.VDFileID.SAVEGAMEINFO import net.torvald.terrarum.savegame.VDFileID.SAVEGAMEINFO
import net.torvald.terrarum.savegame.VDFileID.THUMBNAIL import net.torvald.terrarum.savegame.VDFileID.WORLD_SCREENSHOT
import net.torvald.terrarum.serialise.Common
import net.torvald.terrarum.toInt import net.torvald.terrarum.toInt
import net.torvald.terrarum.utils.PlayerLastStatus import net.torvald.terrarum.utils.PlayerLastStatus
import java.io.File import java.io.File
@@ -84,7 +83,7 @@ class QuickSingleplayerWorldSavingThread(
IngameRenderer.fboRGBexport.dispose() IngameRenderer.fboRGBexport.dispose()
val thumbContent = EntryFile(tgaout.toByteArray64()) 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) addFile(disk, thumb)

View File

@@ -108,7 +108,7 @@ class WorldSavingThread(
IngameRenderer.fboRGBexport.dispose() IngameRenderer.fboRGBexport.dispose()
val thumbContent = EntryFile(tgaout.toByteArray64()) 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) addFile(disk, thumb)

View File

@@ -265,6 +265,6 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
override fun dispose() { override fun dispose() {
minimapFBO.dispose() minimapFBO.dispose()
renderTextures.forEach { try { it.dispose() } catch (e: GdxRuntimeException) {} } renderTextures.forEach { it.tryDispose() }
} }
} }

View File

@@ -138,8 +138,6 @@ class UILoadAutosave(val full: UILoadSavegame) : UICanvas() {
private fun DiskPair.getThumbnail(): TextureRegion { private fun DiskPair.getThumbnail(): TextureRegion {
return this.player.requestFile(VDFileID.PLAYER_SCREENSHOT).let { file -> return this.player.requestFile(VDFileID.PLAYER_SCREENSHOT).let { file ->
CommonResourcePool.getAsTextureRegion("terrarum-defaultsavegamethumb")
if (file != null) { if (file != null) {
val zippedTga = (file.contents as EntryFile).bytes val zippedTga = (file.contents as EntryFile).bytes
val gzin = GZIPInputStream(ByteArray64InputStream(zippedTga)) val gzin = GZIPInputStream(ByteArray64InputStream(zippedTga))

View File

@@ -6,9 +6,7 @@ import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.graphics.glutils.FrameBuffer 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.GdxRuntimeException
import com.badlogic.gdx.utils.JsonReader
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.unicode.EMDASH import net.torvald.unicode.EMDASH
import net.torvald.unicode.getKeycapConsole import net.torvald.unicode.getKeycapConsole
@@ -458,8 +456,8 @@ class UILoadDemoSavefiles(val remoCon: UIRemoCon) : Advanceable() {
} }
override fun dispose() { override fun dispose() {
try { shapeRenderer.dispose() } catch (e: IllegalArgumentException) {} shapeRenderer.tryDispose()
try { sliderFBO.dispose() } catch (e: IllegalArgumentException) {} sliderFBO.tryDispose()
} }
override fun resize(width: Int, height: Int) { override fun resize(width: Int, height: Int) {
@@ -560,12 +558,12 @@ class UIItemPlayerCells(
private var highlightCol: Color = defaultCol private var highlightCol: Color = defaultCol
private var highlightTextCol: Color = defaultCol private var highlightTextCol: Color = defaultCol
var forceMouseDown = false var forceUnhighlight = false
override fun update(delta: Float) { override fun update(delta: Float) {
super.update(delta) super.update(delta)
highlightCol = if (mouseUp && !forceMouseDown) litCol else defaultCol highlightCol = if (mouseUp && !forceUnhighlight) litCol else defaultCol
highlightTextCol = if (mouseUp && !forceMouseDown) litCol else Toolkit.Theme.COL_LIST_DEFAULT highlightTextCol = if (mouseUp && !forceUnhighlight) litCol else Toolkit.Theme.COL_LIST_DEFAULT
} }
fun render(batch: SpriteBatch, camera: Camera, offX: Int, offY: Int) { fun render(batch: SpriteBatch, camera: Camera, offX: Int, offY: Int) {

View File

@@ -3,10 +3,13 @@ package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.App 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.langpack.Lang
import net.torvald.terrarum.modulebasegame.serialise.LoadSavegame 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.Toolkit
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextButton 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) { 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) { override fun doClosing(delta: Float) {
full.playerButtonSelected?.forceMouseDown = false full.playerButtonSelected?.forceUnhighlight = false
}
override fun show() {
super.show()
} }
override fun updateUI(delta: Float) { override fun updateUI(delta: Float) {
@@ -141,12 +157,25 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() {
private var loadFiredFrameCounter = 0 private var loadFiredFrameCounter = 0
override fun renderUI(batch: SpriteBatch, camera: Camera) { 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) full.playerButtonSelected!!.render(batch, camera, 0, buttonYdelta)
when (mode) { when (mode) {
MODE_INIT -> { MODE_INIT -> {
mainButtons.forEach { it.render(batch, camera) } 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 -> { 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_SAVE_WILL_BE_DELETED"], Toolkit.drawWidth, 0, full.titleTopGradEnd + full.cellInterval - 46)

View File

@@ -60,20 +60,8 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
internal val titleBottomGradStart: Int = height - App.scr.tvSafeGraphicsHeight - gradAreaHeight internal val titleBottomGradStart: Int = height - App.scr.tvSafeGraphicsHeight - gradAreaHeight
internal val titleBottomGradEnd: Int = titleBottomGradStart + 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 var playerButtonSelected: UIItemPlayerCells? = null
internal lateinit var loadables: SavegameCollectionPair // will be used and modified by subUIs internal lateinit var loadables: SavegameCollectionPair // will be used and modified by subUIs
internal lateinit var loadManageSelectedGame: DiskPair internal lateinit var loadManageSelectedGame: DiskPair
@@ -88,7 +76,6 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
private val transitionalAutosave = UILoadAutosave(this) private val transitionalAutosave = UILoadAutosave(this)
private val transitionalManage = UILoadManage(this) private val transitionalManage = UILoadManage(this)
private val transitionalNewCharacter = UINewCharacter(remoCon) private val transitionalNewCharacter = UINewCharacter(remoCon)
// private val transitionalSaveDamaged = UILoadSaveDamaged(this)
private val transitionPanel = UIItemHorizontalFadeSlide( private val transitionPanel = UIItemHorizontalFadeSlide(
this, this,
(width - internalWidth) / 2, (width - internalWidth) / 2,
@@ -103,7 +90,6 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
internal fun queueUpManageScr() { transitionPanel.setCentreUIto(0) } internal fun queueUpManageScr() { transitionPanel.setCentreUIto(0) }
internal fun queueUpNewCharScr() { transitionPanel.setCentreUIto(1) } internal fun queueUpNewCharScr() { transitionPanel.setCentreUIto(1) }
// internal fun queueUpDamagedSaveScr() { transitionPanel.setCentreUIto(2) }
internal fun bringAutosaveSelectorUp() { transitionPanel.setRightUIto(1) } internal fun bringAutosaveSelectorUp() { transitionPanel.setRightUIto(1) }
internal fun takeAutosaveSelectorDown() { transitionPanel.setRightUIto(0) } internal fun takeAutosaveSelectorDown() { transitionPanel.setRightUIto(0) }
@@ -125,178 +111,19 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
override fun show() { override fun show() {
takeAutosaveSelectorDown() takeAutosaveSelectorDown()
transitionPanel.show() 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() { override fun hide() {
transitionPanel.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) { override fun updateUI(delta: Float) {
transitionPanel.update(delta) 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) { override fun renderUI(batch: SpriteBatch, camera: Camera) {
transitionPanel.render(batch, 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 { override fun keyDown(keycode: Int): Boolean {
@@ -315,48 +142,18 @@ class UILoadSavegame(val remoCon: UIRemoCon) : Advanceable() {
} }
override fun scrolled(amountX: Float, amountY: Float): Boolean { 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) transitionPanel.scrolled(amountX, amountY)
return true return true
} }
override fun endClosing(delta: Float) {
super.endClosing(delta)
listScroll = 0
scrollTarget = 0
uiScroll = 0f
}
override fun dispose() { override fun dispose() {
try { shapeRenderer.dispose() } catch (e: IllegalArgumentException) {} shapeRenderer.tryDispose()
try { sliderFBO.dispose() } catch (e: IllegalArgumentException) {} transitionPanel.tryDispose()
try { transitionPanel.dispose() } catch (e: IllegalArgumentException) {}
} }
override fun resize(width: Int, height: Int) { override fun resize(width: Int, height: Int) {
transitionPanel.uis.forEach { it.resize(width, height) }
super.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) { internal fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {

View File

@@ -244,7 +244,7 @@ class UITitleModules(val remoCon: UIRemoCon) : UICanvas() {
} }
override fun dispose() { override fun dispose() {
try { sliderFBO.dispose() } catch (e: IllegalArgumentException) {} sliderFBO.tryDispose()
} }
override fun resize(width: Int, height: Int) { override fun resize(width: Int, height: Int) {

View File

@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.utils.Disposable
import com.badlogic.gdx.utils.GdxRuntimeException import com.badlogic.gdx.utils.GdxRuntimeException
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.App.printdbg
@@ -138,8 +139,8 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
val lastPlayedString: String, val lastPlayedString: String,
val totalPlayedString: String, val totalPlayedString: String,
val screenshot: TextureRegion?, val screenshot: TextureRegion?,
) { ): Disposable {
fun dispose() { override fun dispose() {
screenshot?.texture?.dispose() screenshot?.texture?.dispose()
} }
} }
@@ -419,14 +420,14 @@ class UIWorldPortalListing(val full: UIWorldPortal) : UICanvas() {
uiItems.forEach { it.hide() } uiItems.forEach { it.hide() }
if (::worldCells.isInitialized) worldCells.forEach { it.hide() } if (::worldCells.isInitialized) worldCells.forEach { it.hide() }
if (::worldCells.isInitialized) worldCells.forEach { try { it.dispose() } catch (_: GdxRuntimeException) {} } if (::worldCells.isInitialized) worldCells.forEach { it.tryDispose() }
worldList.forEach { try { it.dispose() } catch (_: GdxRuntimeException) {} } worldList.forEach { it.tryDispose() }
} }
override fun dispose() { override fun dispose() {
uiItems.forEach { it.dispose() } uiItems.forEach { it.dispose() }
if (::worldCells.isInitialized) worldCells.forEach { try { it.dispose() } catch (_: GdxRuntimeException) {} } if (::worldCells.isInitialized) worldCells.forEach { it.tryDispose() }
worldList.forEach { try { it.dispose() } catch (_: GdxRuntimeException) {} } worldList.forEach { it.tryDispose() }
} }
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {

View File

@@ -10,8 +10,6 @@ import java.io.IOException
import java.nio.charset.Charset import java.nio.charset.Charset
import java.util.* import java.util.*
import java.util.zip.CRC32 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 ROOT = 0L
const val SAVEGAMEINFO = -1L const val SAVEGAMEINFO = -1L
const val PLAYER_JSON = -1L const val PLAYER_JSON = -1L
const val THUMBNAIL = -2L const val WORLD_SCREENSHOT = -2L
const val SPRITEDEF = -2L const val SPRITEDEF = -2L
const val SPRITEDEF_GLOW = -3L const val SPRITEDEF_GLOW = -3L
const val LOADORDER = -4L const val LOADORDER = -4L
@@ -267,7 +265,7 @@ object VDFileID {
fun diskIDtoReadableFilename(id: EntryID, saveKind: Int?): String = when (id) { fun diskIDtoReadableFilename(id: EntryID, saveKind: Int?): String = when (id) {
VDFileID.ROOT -> "root" VDFileID.ROOT -> "root"
VDFileID.SAVEGAMEINFO -> "savegameinfo.json" VDFileID.SAVEGAMEINFO -> "savegameinfo.json"
VDFileID.THUMBNAIL, VDFileID.SPRITEDEF -> VDFileID.WORLD_SCREENSHOT, VDFileID.SPRITEDEF ->
if (saveKind == PLAYER_DATA) if (saveKind == PLAYER_DATA)
"spritedef" "spritedef"
else if (saveKind == WORLD_DATA) else if (saveKind == WORLD_DATA)

View File

@@ -105,8 +105,8 @@ class UITestPad1 : TerrarumGamescreen {
} }
override fun dispose() { override fun dispose() {
try { colourPickerTex.dispose() } catch (e: GdxRuntimeException) {} colourPickerTex.tryDispose()
try { colourPickerPixmap.dispose() } catch (e: GdxRuntimeException) {} colourPickerPixmap.tryDispose()
} }

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum.ui
import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.INGAME import net.torvald.terrarum.INGAME
import net.torvald.terrarum.modulebasegame.ui.NullUI import net.torvald.terrarum.modulebasegame.ui.NullUI
import net.torvald.terrarum.tryDispose
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
import kotlin.math.roundToInt import kotlin.math.roundToInt
@@ -81,9 +82,9 @@ class UIItemHorizontalFadeSlide(
} }
override fun dispose() { override fun dispose() {
uisOnLeft.forEach { try { it.dispose() } catch (e: IllegalArgumentException) {} } uisOnLeft.forEach { it.tryDispose() }
uisOnCentre.forEach { try { it.dispose() } catch (e: IllegalArgumentException) {} } uisOnCentre.forEach { it.tryDispose() }
uisOnRight.forEach { try { it.dispose() } catch (e: IllegalArgumentException) {} } uisOnRight.forEach { it.tryDispose() }
} }
override fun keyDown(keycode: Int): Boolean { override fun keyDown(keycode: Int): Boolean {

View File

@@ -743,7 +743,7 @@ internal object BlocksDrawer {
tilesFluid.dispose() tilesFluid.dispose()
tilesBuffer.dispose() tilesBuffer.dispose()
_tilesBufferAsTex.dispose() _tilesBufferAsTex.dispose()
try { tilesQuad.dispose() } catch (e: UninitializedPropertyAccessException) {} tilesQuad.tryDispose()
shader.dispose() shader.dispose()
App.tileMaker.dispose() App.tileMaker.dispose()