player info cell, INVENTORY UI LEAKS MEMORY

This commit is contained in:
minjaesong
2019-02-06 05:18:00 +09:00
parent f63e6ed37c
commit 88a1beb271
11 changed files with 294 additions and 21 deletions

View File

@@ -39,7 +39,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
val itemList = ArrayList<InventoryPair>()
val quickSlot = Array<ItemID?>(UIQuickslotBar.SLOT_COUNT) { null } // 0: Slot 1, 9: Slot 10
var currency = 0 // unified currency for whole civs; Dwarf Fortress approach seems too complicated
var wallet = 0 // unified currency for whole civs; Dwarf Fortress approach seems too complicated
init {
}

View File

@@ -20,9 +20,13 @@ object ItemSlotImageFactory {
val CELLCOLOUR_BLACK_OPAQUE = Color(0x404040_FF)
val CELLCOLOUR_WHITE_OPAQUE = Color(0xC0C0C0_FF.toInt())
/** Blend mode: normal */
val CELLCOLOUR_BLACK = Color(0x404040_88)
val CELLCOLOUR_WHITE = Color(0xC0C0C0_88.toInt())
/** Blend mode: screen */
val CELLCOLOUR_BLACK_ACTIVE = Color(0x282828ff)
val slotImage = TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/quickbar/item_slots_atlas.tga"), 38, 38) // must have same w/h as slotLarge
fun produce(isBlack: Boolean, number: Int = 10, item: GameItem?): ItemSlotImage {

View File

@@ -7,11 +7,15 @@ import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import net.torvald.terrarum.*
import net.torvald.terrarum.Terrarum.PLAYER_REF_ID
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory.Companion.CAPACITY_MODE_NO_ENCUMBER
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
import net.torvald.terrarum.serialise.ReadWorldInfo
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarum.ui.UIItemTextButtonList
@@ -30,6 +34,8 @@ class UIInventoryFull(
doNotWarnConstant: Boolean = false
) : UICanvas(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant) {
// FIXME something's causing memory leak
private val debugvals = false
override var width: Int = Terrarum.WIDTH
@@ -108,7 +114,7 @@ class UIInventoryFull(
109 + (Terrarum.HEIGHT - internalHeight) / 2
)
private val gameMenuListWidth = 400
private val gameMenuListHeight = 40 * 5
private val gameMenuListHeight = UIItemPlayerInfoCell.HEIGHT
private val gameMenuCharInfoHeight = 64 + 40 // no top margin, 40 bottom margin
private val gameMenuListTotalHeight = gameMenuListHeight + gameMenuCharInfoHeight
private val gameMenuButtons = UIItemTextButtonList(
@@ -154,6 +160,8 @@ class UIInventoryFull(
}
}
private val testPlayerInfoCell: UIItemPlayerInfoCell
init {
addItem(categoryBar)
itemList.let { addItem(it) }
@@ -166,6 +174,15 @@ class UIInventoryFull(
itemList.rebuild() // have to manually rebuild, too!
}
testPlayerInfoCell = UIItemPlayerInfoCell(
this,
ReadWorldInfo.SaveMetaData("The Yucky Panopticon", 0L,0L,0L,0L,0L, (actor as Actor).referenceID!!, 84873L, 1500000000L, 2000000000L, 2, byteArrayOf(0), byteArrayOf(0), byteArrayOf(0), playerWallet = 13372),
gameMenuListWidth,
Terrarum.WIDTH + ((Terrarum.WIDTH - 400) / 2) + menuScrOffX.toInt(),
(itemList.height - gameMenuListTotalHeight) / 2 + itemList.posY,
false,
Terrarum.ingame!!.getActorByID(PLAYER_REF_ID) as IngamePlayer
)
rebuildList()
@@ -174,6 +191,7 @@ class UIInventoryFull(
addToTransitionalGroup(itemList)
addToTransitionalGroup(equipped)
addToTransitionalGroup(gameMenuButtons)
addToTransitionalGroup(testPlayerInfoCell)
// make gameMenuButtons work
gameMenuButtons.selectionChangeListener = { old, new ->
@@ -184,6 +202,7 @@ class UIInventoryFull(
Gdx.app.exit()
}
}
}
private var offsetX = ((Terrarum.WIDTH - internalWidth) / 2).toFloat()
@@ -341,15 +360,7 @@ class UIInventoryFull(
gameMenuButtons.render(batch, camera)
// character info window
// !! DUMMY !!
batch.color = itemList.backColour
batch.fillRect(
((Terrarum.WIDTH - 400) / 2) + menuScrOffX,
(itemList.height - gameMenuListTotalHeight) / 2 + itemList.posY.toFloat(),
gameMenuListWidth.toFloat(),
64f
)
testPlayerInfoCell.render(batch, camera)
}
private fun renderScreenInventory(batch: SpriteBatch, camera: Camera) {

View File

@@ -11,6 +11,7 @@ import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK_ACTIVE
import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarum.ui.UIItemImageButton
import java.util.*
@@ -99,7 +100,7 @@ class UIItemInventoryDynamicList(
item = null,
amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT,
itemImage = null,
mouseoverBackCol = Color(0x282828_ff),
mouseoverBackCol = Color(CELLCOLOUR_BLACK_ACTIVE),
mouseoverBackBlendMode = BlendMode.SCREEN,
backCol = backColour,
backBlendMode = BlendMode.NORMAL,
@@ -116,7 +117,7 @@ class UIItemInventoryDynamicList(
item = null,
amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT,
itemImage = null,
mouseoverBackCol = Color(0x282828_ff),
mouseoverBackCol = Color(CELLCOLOUR_BLACK_ACTIVE),
mouseoverBackBlendMode = BlendMode.SCREEN,
backCol = backColour,
backBlendMode = BlendMode.NORMAL,

View File

@@ -9,6 +9,7 @@ import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK_ACTIVE
import net.torvald.terrarum.ui.UIItem
/**
@@ -28,6 +29,7 @@ class UIItemInventoryEquippedView(
companion object {
val WIDTH = 2 * UIItemInventoryElemSimple.height + UIItemInventoryDynamicList.listGap
val HEIGHT = UIItemInventoryDynamicList.HEIGHT
val SPRITE_DRAW_COL = Color(0xddddddff.toInt())
}
private val listGap = 8
@@ -48,7 +50,7 @@ class UIItemInventoryEquippedView(
item = null,
amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT,
itemImage = null,
mouseoverBackCol = Color(0x282828_ff),
mouseoverBackCol = Color(CELLCOLOUR_BLACK_ACTIVE),
mouseoverBackBlendMode = BlendMode.SCREEN,
backCol = CELLCOLOUR_BLACK,
backBlendMode = BlendMode.NORMAL,
@@ -61,8 +63,6 @@ class UIItemInventoryEquippedView(
itemGrid.forEach { it.update(delta) }
}
private val spriteDrawCol = Color(0xddddddff.toInt())
// deal with the moving position
override var oldPosX = posX
override var oldPosY = posY
@@ -86,7 +86,7 @@ class UIItemInventoryEquippedView(
sprite?.let {
blendNormal(batch)
batch.color = spriteDrawCol
batch.color = SPRITE_DRAW_COL
batch.draw(
it.textureRegion.get(0, 0),
posX + (width - it.cellWidth).div(2).toFloat(),

View File

@@ -0,0 +1,136 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.blendScreen
import net.torvald.terrarum.fillRect
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
import net.torvald.terrarum.serialise.ReadWorldInfo
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem
import java.util.*
/**
* Created by minjaesong on 2019-02-05.
*
* If ingamePlayer is specified, sprite of current ingamePlayer will be drawn, instead of the SaveMetaData's thumbnail.
*/
class UIItemPlayerInfoCell(
parent: UICanvas,
val saveInfo: ReadWorldInfo.SaveMetaData,
override val width: Int,
override var posX: Int,
override var posY: Int,
var highlightable: Boolean,
var ingamePlayer: IngamePlayer? = null
) : UIItem(parent) {
// deal with the moving position
override var oldPosX = posX
override var oldPosY = posY
override val height = HEIGHT
companion object {
const val HEIGHT = 64
}
private val spriteAreaWidth = 56
private val spriteToNameAreaGap = 8
private val edgeGap = 8
private val backColInactive = ItemSlotImageFactory.CELLCOLOUR_BLACK
private val backColActive = ItemSlotImageFactory.CELLCOLOUR_BLACK_ACTIVE
private val textRow1 = (((height / 2) - Terrarum.fontGame.lineHeight) / 2).toFloat()
private val textRow2 = textRow1 + (height / 2)
private val creationTimeStr: String
private val modificationTimeStr: String
private val worldCountStr: String
private val worldCountStrWidth: Int
init {
val cal = Calendar.getInstance()
cal.timeInMillis = saveInfo.creationTime * 1000
creationTimeStr = "${cal[Calendar.YEAR]}-" +
"${cal[Calendar.MONTH].toString().padStart(2,'0')}-" +
"${cal[Calendar.DATE].toString().padStart(2,'0')}"
cal.timeInMillis = saveInfo.lastPlayTime * 1000
modificationTimeStr = "${cal[Calendar.YEAR]}-" +
"${cal[Calendar.MONTH].toString().padStart(2,'0')}-" +
"${cal[Calendar.DATE].toString().padStart(2,'0')}"
worldCountStr = Lang["CONTEXT_WORLD_COUNT"] + saveInfo.worldCount
worldCountStrWidth = Terrarum.fontGame.getWidth(worldCountStr)
}
override fun render(batch: SpriteBatch, camera: Camera) {
// background
if (highlightable && mouseUp) {
batch.color = backColActive
blendScreen(batch)
}
else {
batch.color = backColInactive
blendNormal(batch)
}
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
blendNormal(batch)
/*batch.color = SPRITE_DRAW_COL
// character sprite image
if (ingamePlayer != null) {
val spriteImage = ingamePlayer?.sprite?.textureRegion?.get(0,0)
batch.draw(spriteImage,
((spriteImage?.regionWidth ?: 2) - spriteAreaWidth).div(2).toFloat(),
((spriteImage?.regionHeight ?: 2) - height).div(2).toFloat()
)
}
else {
val spriteImage = saveInfo.thumbnail
batch.draw(spriteImage,
(spriteImage.width - spriteAreaWidth).div(2).toFloat(),
(spriteImage.height - height).div(2).toFloat()
)
}
// texts //
// name
batch.color = Color.WHITE
Terrarum.fontGame.draw(batch, saveInfo.playerName, spriteAreaWidth + spriteToNameAreaGap.toFloat(), textRow1)
// creation and modification time
Terrarum.fontGame.draw(batch, "$creationTimeStr/$modificationTimeStr", spriteAreaWidth + spriteToNameAreaGap.toFloat(), textRow2)
// world count
Terrarum.fontGame.draw(batch, worldCountStr, width - (edgeGap + worldCountStrWidth).toFloat(), textRow1)
// wallet
val walletStr = "¤ " + (ingamePlayer?.inventory?.wallet ?: saveInfo.playerWallet)
val walletStrWidth = Terrarum.fontGame.getWidth(walletStr)
Terrarum.fontGame.draw(batch, walletStr, width - (edgeGap + walletStrWidth).toFloat(), textRow2)
*/
}
override fun update(delta: Float) {
super.update(delta)
oldPosX = posX
oldPosY = posY
}
override fun dispose() {
}
}

View File

@@ -9,6 +9,7 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemList
import net.torvald.terrarum.ui.UIItemModuleInfoCell
/**
* Created by minjaesong on 2017-08-01.

View File

@@ -1,9 +1,11 @@
package net.torvald.terrarum.serialise
import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.DiskSkimmer.Companion.read
import java.io.File
import java.io.FileInputStream
import java.util.*
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.DiskSkimmer.Companion.read
object ReadWorldInfo {
@@ -55,7 +57,7 @@ object ReadWorldInfo {
}
internal data class SaveMetaData(
data class SaveMetaData(
val worldName: String,
val terrainSeed: Long,
val rngS0: Long,
@@ -69,6 +71,14 @@ object ReadWorldInfo {
val totalPlayTime: Int,
val worldinfo1Hash: ByteArray,
val worldInfo2Hash: ByteArray,
val worldInfo3Hash: ByteArray
val worldInfo3Hash: ByteArray,
// gzipped TGA in meta
val thumbnail: Texture = Texture(2, 2, Pixmap.Format.RGBA8888),
// skim through the virtualdisk entries
val worldCount: Int = 1,
// read from the entry file
val playerName: String = "Savegame",
val playerWallet: Int = 0
)
}

View File

@@ -0,0 +1,21 @@
import net.torvald.terrarum.utils.PasswordBase32
import java.nio.charset.Charset
object Base32Test {
operator fun invoke() {
val testStr = "정 참판 양반댁 규수 혼례 치른 날. 123456709".toByteArray()
val pwd = "béchamel".toByteArray()
val enc = PasswordBase32.encode(testStr, pwd)
val dec = PasswordBase32.decode(enc, testStr.size, pwd)
println("Encoded text: $enc")
println("Decoded text: ${dec.toString(Charset.defaultCharset())}")
}
}
fun main(args: Array<String>) {
Base32Test.invoke()
}

View File

@@ -0,0 +1,88 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.floor
class UIItemModuleInfoCell(
parent: UICanvas,
var moduleName: String,
override val width: Int,
override var posX: Int,
override var posY: Int
) : UIItem(parent) {
// deal with the moving position
override var oldPosX = posX
override var oldPosY = posY
override val height: Int = Terrarum.fontGame.lineHeight.toInt() * 2
private val numberAreaWidth = Terrarum.fontSmallNumbers.W * 3 + 4
override fun render(batch: SpriteBatch, camera: Camera) {
blendNormal(batch)
if (ModMgr.moduleInfo.containsKey(moduleName)) {
val modInfo = ModMgr.moduleInfo[moduleName]!!
// print load order index
batch.color = Color(0xccccccff.toInt())
var strlen = Terrarum.fontSmallNumbers.getWidth(modInfo.order.toString())
Terrarum.fontSmallNumbers.draw(batch,
modInfo.order.toString(),
posX + (numberAreaWidth - strlen).div(2f).floor(),
posY + (height - Terrarum.fontSmallNumbers.H).div(2f).floor()
)
// print module name
batch.color = Color.WHITE
Terrarum.fontGame.draw(batch,
"${modInfo.properName} (${modInfo.version})",
posX + numberAreaWidth.toFloat(),
posY.toFloat()
)
// print author name
strlen = Terrarum.fontGame.getWidth(modInfo.author)
Terrarum.fontGame.draw(batch,
modInfo.author,
posX + width - strlen.toFloat(),
posY.toFloat()
)
// print description
Terrarum.fontGame.draw(batch,
modInfo.description,
posX + numberAreaWidth.toFloat(),
posY + Terrarum.fontGame.lineHeight
)
// print releasedate
strlen = Terrarum.fontGame.getWidth(modInfo.releaseDate)
Terrarum.fontGame.draw(batch,
modInfo.releaseDate,
posX + width - strlen.toFloat(),
posY + Terrarum.fontGame.lineHeight
)
}
else {
batch.color = Color(0xff8080_ff.toInt())
val str = "InternalError: no such module: '$moduleName'"
val strlen = Terrarum.fontSmallNumbers.getWidth(str)
Terrarum.fontSmallNumbers.draw(batch,
str,
posX + (width - numberAreaWidth - strlen).div(2f).floor() + numberAreaWidth,
posY + (height - Terrarum.fontSmallNumbers.H).div(2f).floor()
)
}
}
override fun dispose() {
}
}

View File

@@ -33,5 +33,6 @@ Ord Hex Description
... SHA-256 hash of worldinfo2 (32 bytes)
... SHA-256 hash of worldinfo3 (32 bytes)
... Gzipped thumbnail image in TGA format
(it's gzipped so that it saves faster, so no Lzma)