a debug item

This commit is contained in:
minjaesong
2025-02-01 14:53:14 +09:00
parent ff2a022394
commit b3b86b0965
9 changed files with 302 additions and 13 deletions

View File

@@ -22,7 +22,7 @@ object TooltipManager {
*/
abstract class TooltipListener {
open val tooltipHash = System.nanoTime()
@Transient open val tooltipHash = System.nanoTime()
/**
* Acquire a control over the "tooltip bus". If the message is null, `releaseTooltip()` will be invoked instead.

View File

@@ -0,0 +1,38 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase
import net.torvald.terrarum.modulebasegame.ui.UIDebugInventron
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
* Created by minjaesong on 2025-02-01.
*/
class FixtureDebugInventron : FixtureBase {
constructor() : super(
BlockBox(BlockBox.ALLOW_MOVE_DOWN, 2, 2),
nameFun = { Lang["ITEM_DEBUG_INVENTRON"] },
mainUI = UIDebugInventron()
)
init {
val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/mysterious_atm.tga")
val itemImage2 = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/mysterious_atm_emsv.tga")
density = 2800.0
setHitboxDimension(TILE_SIZE * 2, TILE_SIZE * 2, 0, 0)
makeNewSprite(TextureRegionPack(itemImage.texture, TILE_SIZE * 2, TILE_SIZE * 2)).let {
it.setRowsAndFrames(1,1)
}
makeNewSpriteEmissive(TextureRegionPack(itemImage2.texture, TILE_SIZE * 2, TILE_SIZE * 2)).let {
it.setRowsAndFrames(1,1)
}
actorValue[AVKey.BASEMASS] = 2000.0
}
}

View File

@@ -86,6 +86,9 @@ class FixtureTypewriter : FixtureBase {
it.useItemHandler = "net.torvald.terrarum.modulebasegame.gameactors.TestLeafletPrimaryUseHandler"
it.name = "Testification"
it.author = INGAME.actorNowPlaying?.actorValue?.getAsString(AVKey.NAME) ?: ""
// documents can be photocopied
it.isUnique = false
it.stackable = true
}
inventory.add(newItem)

View File

@@ -18,4 +18,20 @@ class ItemMysteriousATM(originalID: ItemID) : FixtureItemBase(originalID, "net.t
override var originalName = "ITEM_MYSTERIOUS_ATM"
}
/**
* Created by minjaesong on 2025-02-01.
*/
class ItemDebugInventron(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureDebugInventron") {
override var baseMass = 2000.0
override val canBeDynamic = false
override val materialId = ""
init {
itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/mysterious_atm.tga")
}
override var originalName = "ITEM_DEBUG_INVENTRON"
}

View File

@@ -0,0 +1,230 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.ui.*
import net.torvald.unicode.getKeycapPC
import java.lang.reflect.Field
import java.util.*
/**
* Created by minjaesong on 2025-02-01.
*/
class UIDebugInventron : UICanvas(
toggleKeyLiteral = "control_key_inventory",
toggleButtonLiteral = "control_gamepad_start",
) {
override var width = Toolkit.drawWidth
override var height = App.scr.height
private val catBar: UIItemCatBar
private val itemListPlayer: UITemplateHalfInventory
private val selectedItemSlot: UIItemInventoryElemWide
private val halfSlotOffset = (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap * 2) / 2
private var selectedItem: GameItem? = null
private val analyserPosX = UITemplateHalfInventory.XOFFSET_LEFT
private val analyserPosY = UITemplateHalfInventory.YOFFSET
private val analyserPosY2 = UITemplateHalfInventory.YOFFSET + UIItemInventoryElemWide.height + UIItemInventoryItemGrid.listGap
init {
catBar = UIItemCatBar(
this,
(width - UIInventoryFull.catBarWidth) / 2,
42 - UIInventoryFull.YPOS_CORRECTION + (App.scr.height - UIInventoryFull.internalHeight) / 2,
UIInventoryFull.internalWidth,
UIInventoryFull.catBarWidth,
false,
catIcons = CommonResourcePool.getAsTextureRegionPack("inventory_category"),
catArrangement = intArrayOf(9,6,7,1,0,2,1_011,3,4,5,8), // icon order
catIconsMeaning = listOf(
// sortedBy: catArrangement
arrayOf(UIItemCatBar.CAT_ALL),
arrayOf(GameItem.Category.BLOCK),
arrayOf(GameItem.Category.WALL),
arrayOf(GameItem.Category.TOOL, GameItem.Category.WIRE),
arrayOf(GameItem.Category.WEAPON),
arrayOf(GameItem.Category.ARMOUR),
arrayOf(GameItem.Category.FIXTURE),
arrayOf(GameItem.Category.GENERIC),
arrayOf(GameItem.Category.POTION),
arrayOf(GameItem.Category.MAGIC),
arrayOf(GameItem.Category.MISC),
),
catIconsLabels = listOf(
{ Lang["MENU_LABEL_ALL"] },
{ Lang["GAME_INVENTORY_BLOCKS"] },
{ Lang["GAME_INVENTORY_WALLS"] },
{ Lang["CONTEXT_ITEM_TOOL_PLURAL"] },
{ Lang["GAME_INVENTORY_WEAPONS"] },
{ Lang["CONTEXT_ITEM_ARMOR"] },
{ Lang["CONTEXT_ITEM_FIXTURES"] },
{ Lang["GAME_INVENTORY_INGREDIENTS"] },
{ Lang["GAME_INVENTORY_POTIONS"] },
{ Lang["CONTEXT_ITEM_MAGIC"] },
{ Lang["GAME_GENRE_MISC"] },
),
)
catBar.selectionChangeListener = { old, new -> itemListUpdate() }
itemListPlayer = UITemplateHalfInventory(this, false).also {
it.itemListKeyDownFun = { _, _, _, _, _ -> Unit }
it.itemListTouchDownFun = { gameItem, amount, button, _, _ ->
selectedItem = gameItem
refreshAnalysis()
}
}
itemListPlayer.itemList.navRemoCon.listButtonListener = { _,_ -> setCompact(false) }
itemListPlayer.itemList.navRemoCon.gridButtonListener = { _,_ -> setCompact(true) }
selectedItemSlot = UIItemInventoryElemWide(this,
analyserPosX, analyserPosY, itemListPlayer.itemList.width,
keyDownFun = { _, _, _, _, _ -> },
touchDownFun = { _, _, _, _, _ -> selectedItem = null; refreshAnalysis() },
wheelFun = { _, _, _, _, _, _ -> }
)
handler.allowESCtoClose = true
addUIitem(catBar)
addUIitem(itemListPlayer)
addUIitem(selectedItemSlot)
}
override fun show() {
super.show()
itemListPlayer.itemList.getInventory = { INGAME.actorNowPlaying!!.inventory }
selectedItem = null
itemListUpdate()
}
private fun itemListUpdate() {
itemListPlayer.rebuild(catBar.catIconsMeaning[catBar.selectedIndex])
}
private fun setCompact(yes: Boolean) {
itemListPlayer.itemList.isCompactMode = yes
itemListPlayer.itemList.navRemoCon.gridModeButtons[0].highlighted = !yes
itemListPlayer.itemList.navRemoCon.gridModeButtons[1].highlighted = yes
itemListPlayer.itemList.itemPage = 0
itemListPlayer.rebuild(catBar.catIconsMeaning[catBar.selectedIndex])
itemListUpdate()
}
override fun updateImpl(delta: Float) {
uiItems.forEach { it.update(delta) }
}
private val SP = "\u3000"
private val controlHelpLeft: String
get() = if (App.environment == RunningEnvironment.PC)
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}"
else
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}"
override fun renderImpl(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
// background fill
UIInventoryFull.drawBackground(batch, 1f)
// analyser view
batch.color = Color(0x7F)
Toolkit.fillArea(batch, analyserPosX, analyserPosY2, itemListPlayer.itemList.width, itemListPlayer.itemList.height - (analyserPosY2 - analyserPosY))
batch.color = Toolkit.Theme.COL_INACTIVE
Toolkit.drawBoxBorder(batch, analyserPosX, analyserPosY2, itemListPlayer.itemList.width, itemListPlayer.itemList.height - (analyserPosY2 - analyserPosY))
batch.color = Color.WHITE
drawAnalysis(batch)
// UI items
batch.color = Color.WHITE
uiItems.forEach { it.render(frameDelta, batch, camera) }
blendNormalStraightAlpha(batch)
// control hint
val controlHintXPos = analyserPosX + 2f
batch.color = Color.WHITE
App.fontGame.draw(batch, controlHelpLeft, controlHintXPos, UIInventoryFull.yEnd - 20)
}
override fun doOpening(delta: Float) {
super.doOpening(delta)
INGAME.pause()
}
override fun doClosing(delta: Float) {
super.doClosing(delta)
INGAME.resume()
}
override fun dispose() {
}
private var analysisTextBuffer = ArrayList<String>()
fun getAllFields(fields: MutableList<Field>, type: Class<*>): List<Field> {
fields.addAll(Arrays.asList(*type.declaredFields))
if (type.superclass != null) {
getAllFields(fields, type.superclass)
}
return fields
}
private fun refreshAnalysis() {
selectedItemSlot.item = selectedItem
analysisTextBuffer = ArrayList<String>()
if (selectedItem != null) {
/*analysisTextBuffer = selectedItem!!.javaClass.fields.map {
it.isAccessible = true
"$ccY${it.name}$ccW($ccO${it.type.simpleName}$ccW) = $ccG${it.get(selectedItem!!)}"
}*/
val fields: ArrayList<Field> = ArrayList<Field>()
getAllFields(fields, selectedItem!!.javaClass)
println("FIELDS:")
println(fields)
fields.forEach {
try {
it.isAccessible = true
println("${it.name}(${it.type.simpleName}) = ${it.get(selectedItem)}")
analysisTextBuffer.add("$ccY${it.name}$ccW($ccO${it.type.simpleName}$ccW) = $ccG${it.get(selectedItem!!)}")
}
catch (e: Throwable) {}
}
}
}
private fun drawAnalysis(batch: SpriteBatch) {
analysisTextBuffer.forEachIndexed { index, s ->
App.fontGame.draw(batch, s, analyserPosX + 6, analyserPosY2 + 3 + index * 24)
}
}
}

View File

@@ -31,15 +31,16 @@ class UITemplateHalfInventory(
companion object {
const val INVENTORY_NAME_TEXT_GAP = 28
const val halfSlotOffset = (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap) / 2
val XOFFSET_LEFT = UIInventoryFull.INVENTORY_CELLS_OFFSET_X() + UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap - halfSlotOffset
val XOFFSET_RIGHT = XOFFSET_LEFT + (UIItemInventoryItemGrid.listGap + UIItemInventoryElemWide.height) * 7
val YOFFSET = UIInventoryFull.INVENTORY_CELLS_OFFSET_Y()
}
val itemList: UIItemInventoryItemGrid
private val halfSlotOffset = (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap) / 2
private val thisOffsetX = UIInventoryFull.INVENTORY_CELLS_OFFSET_X() + UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap - halfSlotOffset
private val thisOffsetX2 = thisOffsetX + (UIItemInventoryItemGrid.listGap + UIItemInventoryElemWide.height) * 7
private val thisOffsetY = UIInventoryFull.INVENTORY_CELLS_OFFSET_Y()
internal var itemListKeyDownFun = { gameItem: GameItem?, amount: Long, keycode: Int, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase ->
/* crickets */
}
@@ -54,8 +55,8 @@ class UITemplateHalfInventory(
itemList = UIItemInventoryItemGrid(
parent,
getInventoryFun,
if (drawOnLeft) thisOffsetX else thisOffsetX2,
thisOffsetY,
if (drawOnLeft) XOFFSET_LEFT else XOFFSET_RIGHT,
YOFFSET,
6, UIInventoryFull.CELLS_VRT,
drawScrollOnRightside = !drawOnLeft,
drawWallet = false,
@@ -92,7 +93,7 @@ class UITemplateHalfInventory(
itemList.render(frameDelta, batch, camera)
batch.color = Color.WHITE
Toolkit.drawTextCentered(batch, App.fontGame, inventoryNameFun(), width, posX, thisOffsetY - INVENTORY_NAME_TEXT_GAP)
Toolkit.drawTextCentered(batch, App.fontGame, inventoryNameFun(), width, posX, YOFFSET - INVENTORY_NAME_TEXT_GAP)
}
var posX: Int

View File

@@ -44,7 +44,7 @@ class UIItemInventoryElemSimple(
override var suppressHaptic = false
companion object {
val height = UIItemInventoryElemWide.height
const val height = UIItemInventoryElemWide.height
}
override val width = Companion.height

View File

@@ -43,10 +43,10 @@ class UIItemInventoryElemWide(
override var suppressHaptic = false
companion object {
val height = 48
val UNIQUE_ITEM_HAS_NO_AMOUNT = -1L
const val height = 48
const val UNIQUE_ITEM_HAS_NO_AMOUNT = -1L
val durabilityBarThickness = 3
const val durabilityBarThickness = 3
}
override val height = Companion.height