"Continue" button on the titlescreen is working

This commit is contained in:
minjaesong
2021-09-13 14:20:55 +09:00
parent af954b8c39
commit d731812e4e
9 changed files with 113 additions and 34 deletions

View File

@@ -30,6 +30,7 @@ import net.torvald.terrarum.langpack.Lang;
import net.torvald.terrarum.modulebasegame.IngameRenderer;
import net.torvald.terrarum.modulebasegame.TerrarumIngame;
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory;
import net.torvald.terrarum.tvda.VirtualDisk;
import net.torvald.terrarum.utils.JsonFetcher;
import net.torvald.terrarum.utils.JsonWriter;
import net.torvald.terrarum.worlddrawer.CreateTileAtlas;
@@ -41,8 +42,7 @@ import java.io.File;
import java.io.IOException;
import java.util.*;
import static net.torvald.terrarum.TerrarumKt.gdxClearAndSetBlend;
import static net.torvald.terrarum.TerrarumKt.printStackTrace;
import static net.torvald.terrarum.TerrarumKt.*;
/**
* The framework's Application Loader
@@ -191,6 +191,16 @@ public class App implements ApplicationListener {
public static float gamepadDeadzone = 0.2f;
/**
* Sorted by the lastplaytime, in reverse order (index 0 is the most recent game played)
*/
public static ArrayList<VirtualDisk> savegames = new ArrayList<>();
public static void updateListOfSavegames() {
AppUpdateListOfSavegames();
}
/**
* For the events depends on rendering frame (e.g. flicker on post-hit invincibility)
*/
@@ -285,6 +295,7 @@ public class App implements ApplicationListener {
getDefaultDirectory();
createDirs();
readConfigJson();
updateListOfSavegames();
setGamepadButtonLabels();
@@ -461,7 +472,7 @@ public class App implements ApplicationListener {
fontGame = new GameFontBase(FONT_DIR, false, true,
false, Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, false, 64, false
false, Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, false, 90, false
);
Lang.invoke();

View File

@@ -23,6 +23,9 @@ import net.torvald.terrarum.gameactors.ActorID
import net.torvald.terrarum.gameactors.faction.FactionCodex
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.MaterialCodex
import net.torvald.terrarum.serialise.Common
import net.torvald.terrarum.tvda.VDUtil
import net.torvald.terrarum.tvda.VirtualDisk
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.worlddrawer.WorldCamera
import net.torvald.terrarumsansbitmap.gdx.GameFontBase
@@ -673,4 +676,18 @@ class Codex : KVHashMap() {
return value as Cvec
}
}
fun AppUpdateListOfSavegames() {
File(App.defaultSaveDir).listFiles().filter { !it.isDirectory && !it.name.contains('.') }.map { file ->
try {
VDUtil.readDiskArchive(file, charset = Common.CHARSET)
}
catch (e: Throwable) {
e.printStackTrace()
null
}
}.filter { it != null }.sortedByDescending { (it as VirtualDisk).entries[0]!!.modificationDate }.forEach {
App.savegames.add(it!!)
}
}

View File

@@ -43,7 +43,6 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
var camera = OrthographicCamera(App.scr.wf, App.scr.hf)
// invert Y
fun initViewPort(width: Int, height: Int) {
// Set Y to point downwards
@@ -221,6 +220,9 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
loadThingsWhileIntroIsVisible()
// load list of savegames
App.updateListOfSavegames()
printdbg(this, "show() exit")
}

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
import net.torvald.terrarum.*
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.ui.Toolkit
import kotlin.math.roundToInt
/**
@@ -67,9 +68,11 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidt
App.batch.inUse {
it.color = Color.WHITE
val previewX = (App.scr.width - previewWidth).div(2f).round()
val previewY = (App.scr.height - previewHeight.times(1.5f)).div(2f).round()
Toolkit.drawBoxBorder(it, previewX.toInt()-1, previewY.toInt()-1, previewWidth+2, previewHeight+2)
it.draw(previewTexture,
(App.scr.width - previewWidth).div(2f).round(),
previewX,
previewY
)
val text = messages.getHeadElem() ?: ""

View File

@@ -10,14 +10,12 @@ import net.torvald.getKeycapConsole
import net.torvald.getKeycapPC
import net.torvald.terrarum.*
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.serialise.Common
import net.torvald.terrarum.serialise.LoadSavegame
import net.torvald.terrarum.serialise.ReadMeta
import net.torvald.terrarum.tvda.ByteArray64InputStream
import net.torvald.terrarum.tvda.VDUtil
import net.torvald.terrarum.tvda.VirtualDisk
import net.torvald.terrarum.ui.*
import java.io.File
import java.time.Instant
import java.time.format.DateTimeFormatter
import java.util.*
@@ -67,15 +65,7 @@ class UILoadDemoSavefiles : UICanvas() {
// read savegames
init {
File(App.defaultSaveDir).listFiles().filter { !it.isDirectory && !it.name.contains('.') }.map { file ->
try {
VDUtil.readDiskArchive(file, charset = Common.CHARSET)
}
catch (e: Throwable) {
e.printStackTrace()
null
}
}.filter { it != null }.sortedByDescending { (it as VirtualDisk).entries[0]!!.modificationDate }.forEachIndexed { index, disk ->
App.savegames.forEachIndexed { index, disk ->
val x = uiX
val y = titleTopGradEnd + cellInterval * index
addUIitem(UIItemDemoSaveCells(this, x, y, disk as VirtualDisk))
@@ -180,7 +170,9 @@ class UILoadDemoSavefiles : UICanvas() {
// draw texts
val loadGameTitleStr = Lang["MENU_IO_LOAD_GAME"]
// "Game Load"
App.fontGame.draw(batch, loadGameTitleStr, (width - App.fontGame.getWidth(loadGameTitleStr)).div(2).toFloat(), titleTextPosY.toFloat())
// Control help
App.fontGame.draw(batch, controlHelp, uiX.toFloat(), controlHelperY.toFloat())
}
@@ -264,6 +256,12 @@ class UILoadDemoSavefiles : UICanvas() {
}
class UIItemDemoSaveCells(
parent: UILoadDemoSavefiles,
initialX: Int,
@@ -344,12 +342,15 @@ class UIItemDemoSaveCells(
// draw texts
batch.color = highlightCol
// draw timestamp
// timestamp
blendNormal(batch)
val tlen = App.fontSmallNumbers.getWidth(lastPlayedTimestamp)
App.fontSmallNumbers.draw(batch, lastPlayedTimestamp, x + (width - tlen) - 3f, y + height - 16f)
// draw savegame name
// App.fontGame.draw(batch, disk.getDiskNameString(Common.CHARSET), posX + 3f, posY + 1f)
// file size
App.fontSmallNumbers.draw(batch, "${disk.usedBytes.ushr(10)} KiB", x + 3f, y + height - 16f)
// savegame name
// App.fontGame.draw(batch, disk.getDiskNameString(Common.CHARSET), x + 3f, y + 1f)
super.render(batch, camera)
batch.color = Color.WHITE

View File

@@ -0,0 +1,42 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.App
import net.torvald.terrarum.Second
import net.torvald.terrarum.serialise.LoadSavegame
import net.torvald.terrarum.ui.UICanvas
/**
* Created by minjaesong on 2021-09-13.
*/
class UIProxyLoadLatestSave : UICanvas() {
override var width: Int = 0
override var height: Int = 0
override var openCloseTime: Second = 0f
override fun updateUI(delta: Float) {
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
}
override fun doOpening(delta: Float) {
}
override fun doClosing(delta: Float) {
}
override fun endOpening(delta: Float) {
if (App.savegames.size > 0) {
LoadSavegame(App.savegames[0])
}
}
override fun endClosing(delta: Float) {
}
override fun dispose() {
}
}

View File

@@ -38,13 +38,13 @@ class UIProxyNewRandomGame : UICanvas() {
val ingame = TerrarumIngame(App.batch)
val worldParam = TerrarumIngame.NewWorldParameters(2880, 1350, HQRNG().nextLong())
// val worldParam = TerrarumIngame.NewWorldParameters(2880, 1350, HQRNG().nextLong())
// val worldParam = TerrarumIngame.NewWorldParameters(2880, 1350, 0x51621D)
//val worldParam = TerrarumIngame.NewWorldParameters(6000, 1800, 0x51621DL) // small
// val worldParam = TerrarumIngame.NewWorldParameters(9000, 2250, 0x51621DL) // normal
//val worldParam = TerrarumIngame.NewWorldParDoubleameters(13500, 3000, 0x51621DL) // large
//val worldParam = TerrarumIngame.NewWorldParameters(22500, 4500, 0x51621DL) // huge
val worldParam = TerrarumIngame.NewWorldParameters(6030, 1800, HQRNG().nextLong()) // small
// val worldParam = TerrarumIngame.NewWorldParameters(9000, 2250, HQRNG().nextLong()) // normal
// val worldParam = TerrarumIngame.NewWorldParameters(13500, 2970, HQRNG().nextLong()) // large
// val worldParam = TerrarumIngame.NewWorldParameters(22500, 4500, HQRNG().nextLong()) // huge
ingame.gameLoadInfoPayload = worldParam
ingame.gameLoadMode = TerrarumIngame.GameLoadMode.CREATE_NEW

View File

@@ -3,7 +3,11 @@ package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
import net.torvald.terrarum.App
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Second
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemList
import net.torvald.terrarum.ui.UIItemModuleInfoCell
@@ -18,7 +22,7 @@ class UITitleModules : UICanvas() {
private val moduleAreaHMargin = 48
private val moduleAreaBorder = 8
override var width = App.scr.width - UIRemoCon.remoConWidth - moduleAreaHMargin
override var width = 600//App.scr.width - UIRemoCon.remoConWidth - moduleAreaHMargin
override var height = App.scr.height - moduleAreaHMargin * 2
@@ -35,10 +39,10 @@ class UITitleModules : UICanvas() {
}
}
private val mouduleArea = UIItemList<UIItemModuleInfoCell>(
private val moduleArea = UIItemList<UIItemModuleInfoCell>(
this,
moduleInfoCells,
UIRemoCon.remoConWidth, moduleAreaHMargin,
(App.scr.width - this.width) / 2, moduleAreaHMargin,
width,
height,
inactiveCol = Color.WHITE,
@@ -47,17 +51,18 @@ class UITitleModules : UICanvas() {
init {
uiItems.add(mouduleArea)
uiItems.add(moduleArea)
}
override fun updateUI(delta: Float) {
mouduleArea.update(delta)
moduleArea.update(delta)
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
batch.color = Color.WHITE
blendNormal(batch)
mouduleArea.render(batch, camera)
Toolkit.drawBoxBorder(batch, moduleArea.posX, moduleArea.posY, width, height)
moduleArea.render(batch, camera)
}
override fun doOpening(delta: Float) {

View File

@@ -13,7 +13,7 @@ object UITitleRemoConYaml {
* The class must be the UICanvas
*/
val menus = """
- MENU_LABEL_CONTINUE
- MENU_LABEL_CONTINUE : net.torvald.terrarum.modulebasegame.ui.UIProxyLoadLatestSave
- MENU_LABEL_NEW_GAME : net.torvald.terrarum.modulebasegame.ui.UIProxyNewRandomGame
- MENU_IO_LOAD : net.torvald.terrarum.modulebasegame.ui.UILoadDemoSavefiles
- MENU_LABEL_RETURN
@@ -27,8 +27,6 @@ object UITitleRemoConYaml {
- MENU_LABEL_LANGUAGE : net.torvald.terrarum.modulebasegame.ui.UITitleLanguage
- MENU_MODULES : net.torvald.terrarum.ModOptionsHost
- MENU_LABEL_RETURN
- MENU_MODULES : net.torvald.terrarum.modulebasegame.ui.UITitleModules
- MENU_LABEL_RETURN
- MENU_LABEL_CREDITS : net.torvald.terrarum.modulebasegame.ui.UITitleCredits
- MENU_LABEL_CREDITS : net.torvald.terrarum.modulebasegame.ui.UITitleCredits
- MENU_CREDIT_GPL_DNT : net.torvald.terrarum.modulebasegame.ui.UITitleGPL3