diff --git a/src/net/torvald/terrarum/modulebasegame/FancyWorldReadLoadScreen.kt b/src/net/torvald/terrarum/modulebasegame/FancyWorldReadLoadScreen.kt index b65bcb6a7..b2d4fe4db 100644 --- a/src/net/torvald/terrarum/modulebasegame/FancyWorldReadLoadScreen.kt +++ b/src/net/torvald/terrarum/modulebasegame/FancyWorldReadLoadScreen.kt @@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Texture import net.torvald.terrarum.* +import net.torvald.terrarum.realestate.LandUtil.CHUNK_H import net.torvald.terrarum.realestate.LandUtil.CHUNK_W import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack @@ -32,13 +33,11 @@ open class FancyWorldReadLoadScreen(screenToBeLoaded: IngameInstance, private va val ratio = worldwidth * sqrt(2.0 / (worldwidth.sqr() + worldheight.sqr())) // world size is always wider than tall val htilesCount = worldwidth / CHUNK_W - val vtilesCount = worldheight / CHUNK_W + val vtilesCount = worldheight / CHUNK_H - val tileSize = ((540 * ratio) / htilesCount).roundToInt() // (visible tilesize + gapSize) - val gapSize = 0//if (tileSize >= 10) 2 else 1 - val visibleTileSize = tileSize - gapSize - val previewWidth = tileSize * htilesCount - gapSize - val previewHeight = tileSize * vtilesCount + val unitSize = ((540 * ratio) / htilesCount).roundToInt() // (visible tilesize + gapSize) + val previewWidth = unitSize * htilesCount + val previewHeight = unitSize * vtilesCount val xoff = (Math.random() * (1024-764)/2).toInt() @@ -52,20 +51,22 @@ open class FancyWorldReadLoadScreen(screenToBeLoaded: IngameInstance, private va val imgYoff = (252 - previewHeight * 0.28f).toInt() val tiles = baseTileTex.map { - TextureRegionPack(it, visibleTileSize, imgYoff + previewHeight, gapSize, 0, xoff, 0) + TextureRegionPack(it, 1, imgYoff + previewHeight, 0, 0, xoff, 0) } override fun render(delta: Float) { gdxClearAndEnableBlend(.063f, .070f, .086f, 1f) App.batch.inUse { val it = it as FlippingSpriteBatch - it.color = Color.WHITE val previewX = (drawWidth - previewWidth).div(2f).roundToFloat() val previewY = (App.scr.height - previewHeight.times(1.5f)).div(2f).roundToFloat() - Toolkit.drawBoxBorder(it, previewX.toInt()-1, previewY.toInt()-1, previewWidth+2, previewHeight+2) + // it sets the colour by itself drawTiles(it, getStage(), getProgress(), previewX, previewY - imgYoff) + + it.color = Color.WHITE + Toolkit.drawBoxBorder(it, previewX.toInt()-1, previewY.toInt()-1, previewWidth+2, previewHeight+2) val text = messages.getHeadElem() ?: "" App.fontGame.draw(it, text, @@ -78,18 +79,23 @@ open class FancyWorldReadLoadScreen(screenToBeLoaded: IngameInstance, private va super.render(delta) } - protected open fun getProgress(): Int { - return ((progress.get() / 3.0) / vtilesCount).roundToInt() + private val totalChunkCount = (worldwidth / CHUNK_W) * (worldheight / CHUNK_H) + protected open fun getProgress(): Double { + return progress.get().toDouble() / totalChunkCount * previewWidth } protected open fun getStage(): Int { return 2 // fixed value for Read screen } - protected open fun drawTiles(batch: FlippingSpriteBatch, layerCount: Int, tileCount: Int, x: Float, y: Float) { + protected val batchColour = Color(-1) // create new Color instance just for the progress bar + + protected open fun drawTiles(batch: FlippingSpriteBatch, layerCount: Int, tileCount: Double, x: Float, y: Float) { + batch.color = batchColour for (layer in 0 until layerCount) { - for (i in 0 until tileCount) { - batch.draw(tiles[layer].get(i, 0), x + i * tileSize, y) + for (i in 0 until tileCount.ceilToInt()) { + batch.color.a = (tileCount - i).toFloat() + batch.draw(tiles[layer].get(i, 0), x + i, y) } } } @@ -97,18 +103,21 @@ open class FancyWorldReadLoadScreen(screenToBeLoaded: IngameInstance, private va class FancyWorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidth: Int, private val worldheight: Int) : FancyWorldReadLoadScreen(screenToBeLoaded, worldwidth, worldheight, {}) { - override fun getProgress(): Int { - return (progress.get() / CHUNK_W).toInt() + override fun getProgress(): Double { + return progress.get().toDouble() / worldwidth * previewWidth } override fun getStage(): Int { return stageValue } - override fun drawTiles(batch: FlippingSpriteBatch, layerCount: Int, tileCount: Int, x: Float, y: Float) { + override fun drawTiles(batch: FlippingSpriteBatch, layerCount: Int, tileCount: Double, x: Float, y: Float) { + batch.color = batchColour for (layer in 0 until layerCount) { - for (i in 0 until if (layer == layerCount - 1) tileCount else htilesCount) { - batch.draw(tiles[layer].get(i, 0), x + i * tileSize, y) + val isOldLayer = (layer != layerCount - 1) + for (i in 0 until if (!isOldLayer) tileCount.ceilToInt() else previewWidth) { + batch.color.a = if (!isOldLayer) (tileCount - i).toFloat() else 1f + batch.draw(tiles[layer].get(i, 0), x + i, y) } } } diff --git a/src/net/torvald/terrarum/modulebasegame/serialise/WriteSavegame.kt b/src/net/torvald/terrarum/modulebasegame/serialise/WriteSavegame.kt index d9807b63a..86b3546a1 100644 --- a/src/net/torvald/terrarum/modulebasegame/serialise/WriteSavegame.kt +++ b/src/net/torvald/terrarum/modulebasegame/serialise/WriteSavegame.kt @@ -199,8 +199,8 @@ object LoadSavegame { val chunkXY = LandUtil.chunkNumToChunkXY(world, chunk.toInt()) ReadWorld.decodeChunkToLayer(chunkFile.getContent(), worldLayer[layer]!!, chunkXY.x, chunkXY.y) - loadscreen.progress.getAndAdd(1) } + loadscreen.progress.getAndAdd(1) } loadscreen.addMessage("Updating Block Mappings...")