From 4c09588dc20a70f8004681ef85684b5105d8e2c0 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 30 Oct 2023 20:53:49 +0900 Subject: [PATCH] new loadscreen mockup --- assets/mods/basegame/gui/loadscr_layer01.png | 4 +- .../modulebasegame/FancyWorldGenLoadScreen.kt | 99 +++++++++++++++++++ .../modulebasegame/serialise/WriteSavegame.kt | 5 +- 3 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 src/net/torvald/terrarum/modulebasegame/FancyWorldGenLoadScreen.kt diff --git a/assets/mods/basegame/gui/loadscr_layer01.png b/assets/mods/basegame/gui/loadscr_layer01.png index 9ebe531b2..6d79586d3 100644 --- a/assets/mods/basegame/gui/loadscr_layer01.png +++ b/assets/mods/basegame/gui/loadscr_layer01.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9819aeeb574e8183a3eba3a5b329163dd411b6f7fca84ab415bd2c194d1809e4 -size 56042 +oid sha256:5e3f98aa8885882af52bc8cd3550c7e289f35426d4d67bd54b5a8543ba68348d +size 58759 diff --git a/src/net/torvald/terrarum/modulebasegame/FancyWorldGenLoadScreen.kt b/src/net/torvald/terrarum/modulebasegame/FancyWorldGenLoadScreen.kt new file mode 100644 index 000000000..d746a9aae --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/FancyWorldGenLoadScreen.kt @@ -0,0 +1,99 @@ +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 FancyWorldGenLoadScreen(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) + } + + override fun render(delta: Float) { + gdxClearAndEnableBlend(.094f, .094f, .094f, 0f) + + 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 42 + } + + private fun getStage(): Int { + return 2 + } + + 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) { + batch.draw(tiles[layer].get(i, 0), x + i * tileSize, y) + } + } + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/serialise/WriteSavegame.kt b/src/net/torvald/terrarum/modulebasegame/serialise/WriteSavegame.kt index d67cbba0a..a4158e25f 100644 --- a/src/net/torvald/terrarum/modulebasegame/serialise/WriteSavegame.kt +++ b/src/net/torvald/terrarum/modulebasegame/serialise/WriteSavegame.kt @@ -10,6 +10,7 @@ import net.torvald.terrarum.gameworld.BlockLayerI16I8 import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.ChunkLoadingLoadScreen +import net.torvald.terrarum.modulebasegame.FancyWorldGenLoadScreen import net.torvald.terrarum.modulebasegame.IngameRenderer import net.torvald.terrarum.modulebasegame.TerrarumIngame import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer @@ -162,7 +163,7 @@ object LoadSavegame { val loadJob = { it: LoadScreenBase -> - val loadscreen = it as ChunkLoadingLoadScreen + val loadscreen = it as FancyWorldGenLoadScreen loadscreen.addMessage(Lang["MENU_IO_LOADING"]) @@ -210,7 +211,7 @@ object LoadSavegame { printdbg(this, "World loaded: ${newIngame.worldDisk.getDiskName(Common.CHARSET)}") } - val loadScreen = ChunkLoadingLoadScreen(newIngame, world.width, world.height, loadJob) + val loadScreen = FancyWorldGenLoadScreen(newIngame, world.width, world.height, loadJob) Terrarum.setCurrentIngameInstance(newIngame) App.setLoadScreen(loadScreen) }