fixed a bug where UI of the storagechest won't properly initialise after a load

This commit is contained in:
minjaesong
2021-10-14 11:21:10 +09:00
parent f9cff90496
commit 4b67121e70
7 changed files with 48 additions and 35 deletions

View File

@@ -30,8 +30,8 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
lateinit var blockBox: BlockBox // something like TapestryObject will want to redefine this
fun blockBoxIndexToPoint2i(it: BlockBoxIndex): Point2i = this.blockBox.width.let { w -> Point2i(it % w, it / w) }
var blockBoxProps: BlockBoxProps = BlockBoxProps(0)
var nameFun: () -> String = { "" }
var mainUI: UICanvas? = null
@Transient var nameFun: () -> String = { "" }
@Transient var mainUI: UICanvas? = null
var inventory: FixtureInventory? = null
protected constructor() : super(RenderOrder.BEHIND, PhysProperties.IMMOBILE, null)

View File

@@ -45,6 +45,19 @@ internal class FixtureStorageChest : FixtureBase {
sprite!!.setRowsAndFrames(1, 1)
actorValue[AVKey.BASEMASS] = MASS
println("FixtureStorageChest constructor call")
printStackTrace(this)
}
override fun reload() {
super.reload()
// doing this is required as when things are deserialised, constructor is called, THEN the fields are
// filled in, thus the initialised mainUI has a stale reference;
// we fix it by simply giving a new reference to the mainUI
(mainUI as UIStorageChest).chestInventory = this.inventory!!
(mainUI as UIStorageChest).chestNameFun = this.nameFun
}
companion object {
@@ -202,12 +215,13 @@ internal class UIStorageChest : UICanvas(
// encumbrance meter
val encumbranceText = Lang["GAME_INVENTORY_ENCUMBRANCE"]
val chestName = chestNameFun()
val chestNameXpos = itemListChest.posX + 6f
val encumbBarXPos = itemListPlayer.posX + itemListPlayer.width - weightBarWidth
val encumbBarTextXPos = encumbBarXPos - 6 - App.fontGame.getWidth(encumbranceText)
val encumbBarYPos = UIInventoryCells.encumbBarYPos
val encumbBarYPos = (App.scr.height + internalHeight).div(2) - 20 + 3f
val encumbCol = UIItemInventoryCellCommonRes.getHealthMeterColour(1f - encumbrancePerc, 0f, 1f)
val encumbBack = encumbCol mul UIItemInventoryCellCommonRes.meterBackDarkening
val chestName = chestNameFun()
// encumbrance bar background
batch.color = encumbBack
@@ -228,10 +242,14 @@ internal class UIStorageChest : UICanvas(
// chest name text
batch.color = Color.WHITE
App.fontGame.draw(batch, chestName, itemListChest.posX + 6f, encumbBarYPos - 3f)
App.fontGame.draw(batch, chestName, chestNameXpos, encumbBarYPos - 3f)
// encumb text
batch.color = Color.WHITE
App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f)
App.fontGame.draw(batch, encumbranceText, encumbBarTextXPos, encumbBarYPos - 3f +
if (App.fontGame.getWidth(chestName) + 2 + chestNameXpos >= encumbBarTextXPos)
App.fontGame.lineHeight
else 0f
)
}
override fun doOpening(delta: Float) {
@@ -253,6 +271,6 @@ internal class UIStorageChest : UICanvas(
override fun dispose() {
shapeRenderer.dispose()
try { shapeRenderer.dispose() } catch (e: IllegalArgumentException) {}
}
}

View File

@@ -12,6 +12,7 @@ import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTOR
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVEN_DEBUG_MODE
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.controlHelpHeight
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.internalHeight
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.internalWidth
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericKeyDownFun
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericTouchDownFun
@@ -28,7 +29,7 @@ internal class UIInventoryCells(
companion object {
val weightBarWidth = UIItemInventoryElemSimple.height * 2f + UIItemInventoryItemGrid.listGap
var encumbBarYPos = 0f
// var encumbBarYPos = (App.scr.height + internalHeight).div(2) - 20 + 3f
}
internal var encumbrancePerc = 0f
@@ -106,7 +107,7 @@ internal class UIInventoryCells(
if (App.fontGame.getWidth(full.listControlHelp) + 2 + controlHintXPos >= encumbBarTextXPos)
App.fontGame.lineHeight
else 0f
Companion.encumbBarYPos = encumbBarYPos // q&d hack to share some numbers
// Companion.encumbBarYPos = encumbBarYPos // q&d hack to share some numbers
App.fontGame.draw(batch,
encumbranceText,