loading works but not quite

This commit is contained in:
minjaesong
2021-10-12 16:48:54 +09:00
parent ce1289efe3
commit 1a7c01825d
3 changed files with 135 additions and 88 deletions

View File

@@ -310,13 +310,20 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
// overwrite player's props with world's for multiplayer // overwrite player's props with world's for multiplayer
// see comments on IngamePlayer.unauthorisedPlayerProps to know why this is necessary. // see comments on IngamePlayer.unauthorisedPlayerProps to know why this is necessary.
codices.player.backupPlayerProps(isMultiplayer) // backup first! codices.player.backupPlayerProps(isMultiplayer) // backup first!
world.playersLastStatus[codices.player.uuid]?.let { // if nothing was saved, nothing would happen and we still keep the backup, which WriteActor looks for it world.playersLastStatus[codices.player.uuid].let { // regardless of the null-ness, we still keep the backup, which WriteActor looks for it
// if the world has some saved values, use them
if (it != null) {
codices.player.setPosition(it.physics.position) codices.player.setPosition(it.physics.position)
if (isMultiplayer) { if (isMultiplayer) {
codices.player.actorValue = it.actorValue!! codices.player.actorValue = it.actorValue!!
codices.player.inventory = it.inventory!! codices.player.inventory = it.inventory!!
} }
} }
// if not, move player to the spawn point
else {
codices.player.setPosition(world.spawnX * TILE_SIZED, world.spawnY * TILE_SIZED)
}
}
// by doing this, whatever the "possession" the player had will be broken by the game load // by doing this, whatever the "possession" the player had will be broken by the game load

View File

@@ -19,6 +19,7 @@ import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELL_COL import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELL_COL
import net.torvald.terrarum.serialise.Common import net.torvald.terrarum.serialise.Common
import net.torvald.terrarum.serialise.LoadSavegame
import net.torvald.terrarum.serialise.ReadPlayer import net.torvald.terrarum.serialise.ReadPlayer
import net.torvald.terrarum.tvda.ByteArray64InputStream import net.torvald.terrarum.tvda.ByteArray64InputStream
import net.torvald.terrarum.tvda.ByteArray64Reader import net.torvald.terrarum.tvda.ByteArray64Reader
@@ -113,11 +114,20 @@ class UILoadDemoSavefiles : UICanvas() {
private val worldCells = ArrayList<UIItemWorldCells>() private val worldCells = ArrayList<UIItemWorldCells>()
private val playerCells = ArrayList<UIItemPlayerCells>() private val playerCells = ArrayList<UIItemPlayerCells>()
var mode = 0 // 0: show players, 1: show worlds var mode = 0; private set// 0: show players, 1: show worlds
fun advanceMode() {
mode += 1
uiScroll = 0f
scrollFrom = 0
scrollTarget = 0
scrollAnimCounter = 0f
loadFired = 0
println("savelist mode: $mode")
}
override fun show() { override fun show() {
printdbg(this, "savefiles show()")
try { try {
val remoCon = (App.getCurrentScreen() as TitleScreen).uiRemoCon val remoCon = (App.getCurrentScreen() as TitleScreen).uiRemoCon
@@ -171,9 +181,11 @@ class UILoadDemoSavefiles : UICanvas() {
} }
private fun getCells() = if (mode == 0) playerCells else worldCells private fun getCells() = if (mode == 0) playerCells else worldCells
private var loadFired = 0
override fun updateUI(delta: Float) { override fun updateUI(delta: Float) {
if (mode < 2) {
if (scrollTarget != listScroll) { if (scrollTarget != listScroll) {
if (scrollAnimCounter < scrollAnimLen) { if (scrollAnimCounter < scrollAnimLen) {
scrollAnimCounter += delta scrollAnimCounter += delta
@@ -193,6 +205,8 @@ class UILoadDemoSavefiles : UICanvas() {
val cells = getCells() val cells = getCells()
for (index in 0 until cells.size) { for (index in 0 until cells.size) {
val it = cells[index] val it = cells[index]
if (index in listScroll - 2 until listScroll + savesVisible + 2) { if (index in listScroll - 2 until listScroll + savesVisible + 2) {
// re-position // re-position
@@ -201,11 +215,20 @@ class UILoadDemoSavefiles : UICanvas() {
} }
} }
} }
}
override fun renderUI(batch: SpriteBatch, camera: Camera) { override fun renderUI(batch: SpriteBatch, camera: Camera) {
if (mode == 2) {
loadFired += 1
// to hide the "flipped skybox" artefact
gdxClearAndSetBlend(.094f, .094f, .094f, 0f)
if (loadFired == 2) {
LoadSavegame(playerDisk!!, worldDisk)
}
}
else {
batch.end() batch.end()
val cells = getCells() val cells = getCells()
@@ -274,6 +297,7 @@ class UILoadDemoSavefiles : UICanvas() {
batch.begin() batch.begin()
} }
}
override fun keyDown(keycode: Int): Boolean { override fun keyDown(keycode: Int): Boolean {
@@ -294,6 +318,16 @@ class UILoadDemoSavefiles : UICanvas() {
return true return true
} }
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
getCells().forEach { it.touchDown(screenX, screenY, pointer, button) }
return true
}
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
getCells().forEach { it.touchUp(screenX, screenY, pointer, button) }
return true
}
override fun scrolled(amountX: Float, amountY: Float): Boolean { override fun scrolled(amountX: Float, amountY: Float): Boolean {
if (this.isVisible) { if (this.isVisible) {
val cells = getCells() val cells = getCells()
@@ -370,6 +404,7 @@ class UIItemPlayerCells(
override var clickOnceListener: ((Int, Int, Int) -> Unit)? = { _: Int, _: Int, _: Int -> override var clickOnceListener: ((Int, Int, Int) -> Unit)? = { _: Int, _: Int, _: Int ->
parent.playerDisk = skimmer parent.playerDisk = skimmer
parent.advanceMode()
} }
private var playerName: String = "$EMDASH" private var playerName: String = "$EMDASH"
@@ -559,7 +594,7 @@ class UIItemWorldCells(
override var clickOnceListener: ((Int, Int, Int) -> Unit)? = { _: Int, _: Int, _: Int -> override var clickOnceListener: ((Int, Int, Int) -> Unit)? = { _: Int, _: Int, _: Int ->
parent.worldDisk = skimmer parent.worldDisk = skimmer
TODO() parent.advanceMode()
} }
internal var hasTexture = false internal var hasTexture = false

View File

@@ -44,6 +44,8 @@ import net.torvald.terrarum.Terrarum
* As mentioned in [UICanvas], UIItems must be added to the Canvas to make listeners work without implementing * As mentioned in [UICanvas], UIItems must be added to the Canvas to make listeners work without implementing
* everything by yourself. * everything by yourself.
* *
* PROTIP: if [clickOnceListener] does not seem to work, make sure your parent UI is handling touchDown() and touchUp() events!
*
* @param initialX initial position of the item. Useful for making transition that requires the item to be moved * @param initialX initial position of the item. Useful for making transition that requires the item to be moved
* @param initialY initial position of the item. Useful for making transition that requires the item to be moved * @param initialY initial position of the item. Useful for making transition that requires the item to be moved
* *
@@ -113,7 +115,10 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
open var touchUpListener: ((Int, Int, Int, Int) -> Unit)? = null open var touchUpListener: ((Int, Int, Int, Int) -> Unit)? = null
/** Parameters: amountX, amountY */ /** Parameters: amountX, amountY */
open var scrolledListener: ((Float, Float) -> Unit)? = null open var scrolledListener: ((Float, Float) -> Unit)? = null
/** Parameters: relative mouseX, relative mouseY, button */ /** Parameters: relative mouseX, relative mouseY, button
*
* PROTIP: if clickOnceListener does not seem to work, make sure your parent UI is handling touchDown() and touchUp() events!
*/
open var clickOnceListener: ((Int, Int, Int) -> Unit)? = null open var clickOnceListener: ((Int, Int, Int) -> Unit)? = null
open var clickOnceListenerFired = false open var clickOnceListenerFired = false