mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 19:14:05 +09:00
smooth progress bar
This commit is contained in:
@@ -3,6 +3,7 @@ package net.torvald.terrarum.modulebasegame
|
|||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
|
import net.torvald.terrarum.realestate.LandUtil.CHUNK_H
|
||||||
import net.torvald.terrarum.realestate.LandUtil.CHUNK_W
|
import net.torvald.terrarum.realestate.LandUtil.CHUNK_W
|
||||||
import net.torvald.terrarum.ui.Toolkit
|
import net.torvald.terrarum.ui.Toolkit
|
||||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
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 ratio = worldwidth * sqrt(2.0 / (worldwidth.sqr() + worldheight.sqr())) // world size is always wider than tall
|
||||||
val htilesCount = worldwidth / CHUNK_W
|
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 unitSize = ((540 * ratio) / htilesCount).roundToInt() // (visible tilesize + gapSize)
|
||||||
val gapSize = 0//if (tileSize >= 10) 2 else 1
|
val previewWidth = unitSize * htilesCount
|
||||||
val visibleTileSize = tileSize - gapSize
|
val previewHeight = unitSize * vtilesCount
|
||||||
val previewWidth = tileSize * htilesCount - gapSize
|
|
||||||
val previewHeight = tileSize * vtilesCount
|
|
||||||
|
|
||||||
val xoff = (Math.random() * (1024-764)/2).toInt()
|
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 imgYoff = (252 - previewHeight * 0.28f).toInt()
|
||||||
|
|
||||||
val tiles = baseTileTex.map {
|
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) {
|
override fun render(delta: Float) {
|
||||||
gdxClearAndEnableBlend(.063f, .070f, .086f, 1f)
|
gdxClearAndEnableBlend(.063f, .070f, .086f, 1f)
|
||||||
|
|
||||||
App.batch.inUse { val it = it as FlippingSpriteBatch
|
App.batch.inUse { val it = it as FlippingSpriteBatch
|
||||||
it.color = Color.WHITE
|
|
||||||
val previewX = (drawWidth - previewWidth).div(2f).roundToFloat()
|
val previewX = (drawWidth - previewWidth).div(2f).roundToFloat()
|
||||||
val previewY = (App.scr.height - previewHeight.times(1.5f)).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)
|
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() ?: ""
|
val text = messages.getHeadElem() ?: ""
|
||||||
App.fontGame.draw(it,
|
App.fontGame.draw(it,
|
||||||
text,
|
text,
|
||||||
@@ -78,18 +79,23 @@ open class FancyWorldReadLoadScreen(screenToBeLoaded: IngameInstance, private va
|
|||||||
super.render(delta)
|
super.render(delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun getProgress(): Int {
|
private val totalChunkCount = (worldwidth / CHUNK_W) * (worldheight / CHUNK_H)
|
||||||
return ((progress.get() / 3.0) / vtilesCount).roundToInt()
|
protected open fun getProgress(): Double {
|
||||||
|
return progress.get().toDouble() / totalChunkCount * previewWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun getStage(): Int {
|
protected open fun getStage(): Int {
|
||||||
return 2 // fixed value for Read screen
|
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 (layer in 0 until layerCount) {
|
||||||
for (i in 0 until tileCount) {
|
for (i in 0 until tileCount.ceilToInt()) {
|
||||||
batch.draw(tiles[layer].get(i, 0), x + i * tileSize, y)
|
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, {}) {
|
class FancyWorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidth: Int, private val worldheight: Int) : FancyWorldReadLoadScreen(screenToBeLoaded, worldwidth, worldheight, {}) {
|
||||||
|
|
||||||
override fun getProgress(): Int {
|
override fun getProgress(): Double {
|
||||||
return (progress.get() / CHUNK_W).toInt()
|
return progress.get().toDouble() / worldwidth * previewWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getStage(): Int {
|
override fun getStage(): Int {
|
||||||
return stageValue
|
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 (layer in 0 until layerCount) {
|
||||||
for (i in 0 until if (layer == layerCount - 1) tileCount else htilesCount) {
|
val isOldLayer = (layer != layerCount - 1)
|
||||||
batch.draw(tiles[layer].get(i, 0), x + i * tileSize, y)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,8 +199,8 @@ object LoadSavegame {
|
|||||||
val chunkXY = LandUtil.chunkNumToChunkXY(world, chunk.toInt())
|
val chunkXY = LandUtil.chunkNumToChunkXY(world, chunk.toInt())
|
||||||
|
|
||||||
ReadWorld.decodeChunkToLayer(chunkFile.getContent(), worldLayer[layer]!!, chunkXY.x, chunkXY.y)
|
ReadWorld.decodeChunkToLayer(chunkFile.getContent(), worldLayer[layer]!!, chunkXY.x, chunkXY.y)
|
||||||
loadscreen.progress.getAndAdd(1)
|
|
||||||
}
|
}
|
||||||
|
loadscreen.progress.getAndAdd(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
loadscreen.addMessage("Updating Block Mappings...")
|
loadscreen.addMessage("Updating Block Mappings...")
|
||||||
|
|||||||
Reference in New Issue
Block a user