mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
player info cell, INVENTORY UI LEAKS MEMORY
This commit is contained in:
@@ -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 {
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user