mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
loadlost: preloading game screenshots
This commit is contained in:
@@ -132,12 +132,32 @@ fun DiskSkimmer.getTgaGz(vid: EntryID, width: Int, height: Int, shrinkage: Doubl
|
||||
}
|
||||
}
|
||||
}
|
||||
fun DiskSkimmer.getTgaGzPixmap(vid: EntryID, width: Int, height: Int, shrinkage: Double): Pixmap? {
|
||||
return this.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)
|
||||
return pixmap
|
||||
}
|
||||
else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
fun DiskSkimmer.getThumbnail(width: Int, height: Int, shrinkage: Double) =
|
||||
when (this.getSaveKind()) {
|
||||
1 -> this.getTgaGz(PLAYER_SCREENSHOT, width, height, shrinkage)
|
||||
2 -> this.getTgaGz(WORLD_SCREENSHOT, width, height, shrinkage)
|
||||
else -> throw IllegalArgumentException("Unknown save kind: ${this.getSaveKind()}")
|
||||
}
|
||||
fun DiskSkimmer.getThumbnailPixmap(width: Int, height: Int, shrinkage: Double) =
|
||||
when (this.getSaveKind()) {
|
||||
1 -> this.getTgaGzPixmap(PLAYER_SCREENSHOT, width, height, shrinkage)
|
||||
2 -> this.getTgaGzPixmap(WORLD_SCREENSHOT, width, height, shrinkage)
|
||||
else -> throw IllegalArgumentException("Unknown save kind: ${this.getSaveKind()}")
|
||||
}
|
||||
|
||||
class SavegameCollectionPair(private val player: SavegameCollection?, private val world: SavegameCollection?) {
|
||||
|
||||
|
||||
@@ -59,12 +59,23 @@ class UILoadAutosave(val full: UILoadSavegame) : UICanvas() {
|
||||
addUIitem(mainBackButton)
|
||||
}
|
||||
|
||||
private var textureManual: TextureRegion? = null
|
||||
private var textureAuto: TextureRegion? = null
|
||||
|
||||
override fun show() {
|
||||
super.show()
|
||||
|
||||
val loadables = full.loadables
|
||||
val autoThumb = loadables.getAutoSave()!!.getThumbnail()
|
||||
val manualThumb = loadables.getManualSave()!!.getThumbnail()
|
||||
val texPlaceholder = CommonResourcePool.getAsTextureRegion("terrarum-defaultsavegamethumb")
|
||||
|
||||
val pixmapManual = full.playerButtonSelected!!.pixmapManual
|
||||
val pixmapAuto = full.playerButtonSelected!!.pixmapAuto
|
||||
|
||||
textureManual?.texture?.tryDispose()
|
||||
textureAuto?.texture?.tryDispose()
|
||||
|
||||
val manualThumb = if (pixmapManual != null) TextureRegion(Texture(pixmapManual)) else texPlaceholder
|
||||
val autoThumb = if (pixmapAuto != null) TextureRegion(Texture(pixmapAuto)) else texPlaceholder
|
||||
|
||||
loadManualThumbButton = UIItemImageButton(this, manualThumb,
|
||||
initialX = (Toolkit.drawWidth - altSelDrawW)/2 + altSelQdrawW - imageButtonW/2,
|
||||
@@ -133,6 +144,10 @@ class UILoadAutosave(val full: UILoadSavegame) : UICanvas() {
|
||||
override fun dispose() {
|
||||
if (::loadAutoThumbButton.isInitialized) loadAutoThumbButton.dispose()
|
||||
if (::loadManualThumbButton.isInitialized) loadManualThumbButton.dispose()
|
||||
|
||||
// might throw Texture already disposed
|
||||
textureManual?.texture?.tryDispose()
|
||||
textureAuto?.texture?.tryDispose()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -512,6 +512,8 @@ class UIItemPlayerCells(
|
||||
lateinit var worldUUID: UUID; private set
|
||||
|
||||
private val savegameStatus: Int
|
||||
internal val pixmapManual: Pixmap?
|
||||
internal val pixmapAuto: Pixmap?
|
||||
|
||||
init {
|
||||
App.savegamePlayers[playerUUID]!!.loadable().getFile(SAVEGAMEINFO)?.bytes?.let {
|
||||
@@ -533,6 +535,8 @@ class UIItemPlayerCells(
|
||||
|
||||
val savegamePair = SavegameCollectionPair(App.savegamePlayers[playerUUID], App.savegameWorlds[worldUUID])
|
||||
savegameStatus = savegamePair.status
|
||||
pixmapManual = savegamePair.getManualSave()?.player?.getThumbnailPixmap(SAVE_THUMBNAIL_MAIN_WIDTH, SAVE_THUMBNAIL_MAIN_HEIGHT, 2.0)
|
||||
pixmapAuto = savegamePair.getAutoSave()?.player?.getThumbnailPixmap(SAVE_THUMBNAIL_MAIN_WIDTH, SAVE_THUMBNAIL_MAIN_HEIGHT, 2.0)
|
||||
}
|
||||
|
||||
private fun parseDuration(seconds: Long): String {
|
||||
@@ -696,6 +700,8 @@ class UIItemPlayerCells(
|
||||
|
||||
override fun dispose() {
|
||||
sprite?.texture?.dispose()
|
||||
pixmapManual?.dispose()
|
||||
pixmapAuto?.dispose()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ class UILoadList(val full: UILoadSavegame) : UICanvas() {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
Thread.sleep(18) // to alleviate the "hiccup" when the UI is being opened
|
||||
Thread.sleep(1) // to alleviate the "hiccup" when the UI is being opened
|
||||
}
|
||||
|
||||
printdbg(this, "============== ${this.hashCode()} ============== ")
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.App
|
||||
@@ -130,7 +131,9 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() {
|
||||
full.playerButtonSelected?.forceUnhighlight = true
|
||||
full.playerButtonSelected?.let { button ->
|
||||
screencap?.texture?.tryDispose()
|
||||
screencap = App.savegamePlayers[button.playerUUID]!!.getThumbnail(screencapW, screencapH, 2.0)
|
||||
(button.pixmapAuto ?: button.pixmapManual)?.let {
|
||||
screencap = TextureRegion(Texture(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,6 +169,8 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() {
|
||||
|
||||
// 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
|
||||
|
||||
@@ -192,6 +197,7 @@ class UILoadManage(val full: UILoadSavegame) : UICanvas() {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
screencap?.texture?.tryDispose()
|
||||
}
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user