mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-14 15:46:06 +09:00
129 lines
4.2 KiB
Kotlin
129 lines
4.2 KiB
Kotlin
package net.torvald.terrarum.modulebasegame.ui
|
|
|
|
import com.badlogic.gdx.graphics.Camera
|
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
|
import com.badlogic.gdx.utils.JsonValue
|
|
import net.torvald.terrarum.*
|
|
import net.torvald.terrarum.langpack.Lang
|
|
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
|
|
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: JsonValue,
|
|
override val width: Int,
|
|
initialX: Int,
|
|
initialY: Int,
|
|
var highlightable: Boolean,
|
|
var ingamePlayer: IngamePlayer? = null
|
|
) : UIItem(parent, initialX, initialY) {
|
|
|
|
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) - App.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.getLong("creation_t") * 1000
|
|
creationTimeStr = "${cal[Calendar.YEAR]}-" +
|
|
"${cal[Calendar.MONTH].toString().padStart(2,'0')}-" +
|
|
"${cal[Calendar.DATE].toString().padStart(2,'0')}"
|
|
|
|
cal.timeInMillis = saveInfo.getLong("lastplay_t") * 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.get("worlds").asIntArray().size
|
|
worldCountStrWidth = App.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
|
|
AppLoader.fontGame.draw(batch, saveInfo.playerName, spriteAreaWidth + spriteToNameAreaGap.toFloat(), textRow1)
|
|
// creation and modification time
|
|
AppLoader.fontGame.draw(batch, "$creationTimeStr/$modificationTimeStr", spriteAreaWidth + spriteToNameAreaGap.toFloat(), textRow2)
|
|
// world count
|
|
AppLoader.fontGame.draw(batch, worldCountStr, width - (edgeGap + worldCountStrWidth).toFloat(), textRow1)
|
|
// wallet
|
|
val walletStr = "¤ " + (ingamePlayer?.inventory?.wallet ?: saveInfo.playerWallet)
|
|
val walletStrWidth = AppLoader.fontGame.getWidth(walletStr)
|
|
AppLoader.fontGame.draw(batch, walletStr, width - (edgeGap + walletStrWidth).toFloat(), textRow2)
|
|
*/
|
|
}
|
|
|
|
override fun update(delta: Float) {
|
|
super.update(delta)
|
|
|
|
|
|
|
|
oldPosX = posX
|
|
oldPosY = posY
|
|
}
|
|
|
|
override fun dispose() {
|
|
|
|
}
|
|
} |