working new loadscreen (not worldgen)

This commit is contained in:
minjaesong
2023-10-30 21:47:31 +09:00
parent 4c09588dc2
commit 3f3e4ad2e7
10 changed files with 20 additions and 17 deletions

View File

@@ -0,0 +1,102 @@
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.gameworld.GameWorld
import net.torvald.terrarum.realestate.LandUtil.CHUNK_W
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import kotlin.math.roundToInt
import kotlin.math.sqrt
/**
* Created by minjaesong on 2023-10-30.
*/
class FancyWorldReadLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidth: Int, private val worldheight: Int, override var preLoadJob: (LoadScreenBase) -> Unit) : LoadScreenBase() {
init {
CommonResourcePool.addToLoadingList("basegame-gui-loadscrlayer01") {
Texture(ModMgr.getGdxFile("basegame", "gui/loadscr_layer01.png"))
}
CommonResourcePool.addToLoadingList("basegame-gui-loadscrlayer02") {
Texture(ModMgr.getGdxFile("basegame", "gui/loadscr_layer02.png"))
}
CommonResourcePool.loadAll()
App.disposables.add(this)
}
override var screenToLoad: IngameInstance? = screenToBeLoaded
private val world: GameWorld // must use Getter, as the field WILL BE redefined by the TerrarumIngame.enterCreateNewWorld() !
get() = screenToLoad!!.world
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 tileSize = ((540 * ratio) / htilesCount).roundToInt() // (visible tilesize + gapSize)
val gapSize = if (tileSize >= 15) 3 else if (tileSize >= 7) 2 else 1
val visibleTileSize = tileSize - gapSize
val previewWidth = tileSize * htilesCount - gapSize
val previewHeight = tileSize * vtilesCount
val xoff = 0//(Math.random() * (1024 - 764)).toInt()
val baseTileTex = arrayOf(
CommonResourcePool.getAsTexture("basegame-gui-loadscrlayer01"),
CommonResourcePool.getAsTexture("basegame-gui-loadscrlayer02"),
)
val drawWidth = Toolkit.drawWidth
val imgYoff = (252 - previewHeight * 0.28f).toInt()
val tiles = baseTileTex.map {
TextureRegionPack(it, visibleTileSize, imgYoff + previewHeight, gapSize, 0, xoff, 0)
}
var chunksLoaded = 0 // only increments when all the chunks were loaded
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)
drawTiles(it, getStage(), getProgress(), previewX, previewY - imgYoff)
val text = messages.getHeadElem() ?: ""
App.fontGame.draw(it,
text,
(drawWidth - App.fontGame.getWidth(text)).div(2f).roundToFloat(),
previewY + previewHeight + 98 - App.fontGame.lineHeight
)
}
super.render(delta)
}
private fun getProgress(): Int {
return (chunksLoaded.toDouble() / vtilesCount).roundToInt()
}
private fun getStage(): Int {
return 2 // fixed value for Read screen
}
private fun drawTiles(batch: FlippingSpriteBatch, layerCount: Int, tileCount: Int, x: Float, y: Float) {
for (layer in 0 until layerCount) {
// for (i in 0 until if (layer == layerCount - 1) tileCount else htilesCount) {
for (i in 0 until tileCount) {
batch.draw(tiles[layer].get(i, 0), x + i * tileSize, y)
}
}
}
}