mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
debugging thing update
This commit is contained in:
@@ -10,6 +10,7 @@ import net.torvald.terrarum.ui.*
|
||||
import net.torvald.unicode.getKeycapPC
|
||||
import java.lang.reflect.Field
|
||||
import java.util.*
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
/**
|
||||
@@ -37,6 +38,10 @@ class UIDebugInventron : UICanvas(
|
||||
private val analyserPosY = UITemplateHalfInventory.YOFFSET
|
||||
private val analyserPosY2 = UITemplateHalfInventory.YOFFSET + UIItemInventoryElemWide.height + UIItemInventoryItemGrid.listGap
|
||||
|
||||
private val analyserWidth: Int
|
||||
private val analyserHeight: Int
|
||||
|
||||
private val analyserScroll: UIItemVertSlider
|
||||
|
||||
init {
|
||||
catBar = UIItemCatBar(
|
||||
@@ -96,6 +101,18 @@ class UIDebugInventron : UICanvas(
|
||||
keyDownFun = { _, _, _, _, _ -> },
|
||||
touchDownFun = { _, _, _, _, _ -> selectedItem = null; refreshAnalysis() },
|
||||
wheelFun = { _, _, _, _, _, _ -> }
|
||||
).also {
|
||||
it.showItemCount = false
|
||||
}
|
||||
|
||||
analyserWidth = itemListPlayer.itemList.width
|
||||
analyserHeight = itemListPlayer.itemList.height - (analyserPosY2 - analyserPosY)
|
||||
|
||||
|
||||
analyserScroll = UIItemVertSlider(this,
|
||||
analyserPosX - 18,
|
||||
analyserPosY2 + 1,
|
||||
0.0, 0.0, 1.0, analyserHeight - 2, analyserHeight - 2
|
||||
)
|
||||
|
||||
handler.allowESCtoClose = true
|
||||
@@ -103,13 +120,14 @@ class UIDebugInventron : UICanvas(
|
||||
addUIitem(catBar)
|
||||
addUIitem(itemListPlayer)
|
||||
addUIitem(selectedItemSlot)
|
||||
addUIitem(analyserScroll)
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
super.show()
|
||||
|
||||
itemListPlayer.itemList.getInventory = { INGAME.actorNowPlaying!!.inventory }
|
||||
selectedItem = null
|
||||
selectedItem = null; refreshAnalysis()
|
||||
|
||||
itemListUpdate()
|
||||
}
|
||||
@@ -147,9 +165,9 @@ class UIDebugInventron : UICanvas(
|
||||
|
||||
// analyser view
|
||||
batch.color = Color(0x7F)
|
||||
Toolkit.fillArea(batch, analyserPosX, analyserPosY2, itemListPlayer.itemList.width, itemListPlayer.itemList.height - (analyserPosY2 - analyserPosY))
|
||||
Toolkit.fillArea(batch, analyserPosX, analyserPosY2, analyserWidth, analyserHeight)
|
||||
batch.color = Toolkit.Theme.COL_INACTIVE
|
||||
Toolkit.drawBoxBorder(batch, analyserPosX, analyserPosY2, itemListPlayer.itemList.width, itemListPlayer.itemList.height - (analyserPosY2 - analyserPosY))
|
||||
Toolkit.drawBoxBorder(batch, analyserPosX, analyserPosY2, analyserWidth, analyserHeight)
|
||||
|
||||
batch.color = Color.WHITE
|
||||
drawAnalysis(batch)
|
||||
@@ -193,15 +211,15 @@ class UIDebugInventron : UICanvas(
|
||||
return fields
|
||||
}
|
||||
|
||||
private fun refreshAnalysis() {
|
||||
selectedItemSlot.item = selectedItem
|
||||
private val TEXT_LINE_HEIGHT = 24
|
||||
|
||||
private fun refreshAnalysis() {
|
||||
analysisTextBuffer = ArrayList<String>()
|
||||
|
||||
// update wall of text
|
||||
if (selectedItem != null) {
|
||||
/*analysisTextBuffer = selectedItem!!.javaClass.fields.map {
|
||||
it.isAccessible = true
|
||||
"$ccY${it.name}$ccW($ccO${it.type.simpleName}$ccW) = $ccG${it.get(selectedItem!!)}"
|
||||
}*/
|
||||
selectedItemSlot.item = selectedItem
|
||||
selectedItemSlot.itemImage = selectedItem!!.itemImage
|
||||
|
||||
val fields: ArrayList<Field> = ArrayList<Field>()
|
||||
getAllFields(fields, selectedItem!!.javaClass)
|
||||
@@ -218,11 +236,22 @@ class UIDebugInventron : UICanvas(
|
||||
catch (e: Throwable) {}
|
||||
}
|
||||
}
|
||||
else {
|
||||
selectedItemSlot.item = null
|
||||
}
|
||||
|
||||
// update scrollbar
|
||||
analyserScroll.isEnabled = (selectedItem == null)
|
||||
analyserScroll.handleHeight = if (analysisTextBuffer.isEmpty() || selectedItem == null)
|
||||
analyserHeight
|
||||
else
|
||||
(analyserHeight.toFloat() / analysisTextBuffer.size.times(TEXT_LINE_HEIGHT)).times(analyserHeight).roundToInt().coerceIn(12, analyserHeight)
|
||||
}
|
||||
|
||||
private fun drawAnalysis(batch: SpriteBatch) {
|
||||
val scroll = (analyserScroll.value * analysisTextBuffer.size.times(TEXT_LINE_HEIGHT).minus(analyserHeight - 3)).roundToInt().coerceAtLeast(0)
|
||||
analysisTextBuffer.forEachIndexed { index, s ->
|
||||
App.fontGame.draw(batch, s, analyserPosX + 6, analyserPosY2 + 3 + index * 24)
|
||||
App.fontGame.draw(batch, s, analyserPosX + 6, analyserPosY2 + 3 + index * TEXT_LINE_HEIGHT - scroll)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,17 +30,27 @@ class UIItemHorzSlider(
|
||||
val min: Double,
|
||||
val max: Double,
|
||||
override val width: Int,
|
||||
val handleWidth: Int = 12,
|
||||
initialHandleWidth: Int = 12,
|
||||
private val backgroundTexture: TextureRegion? = null,
|
||||
private val disposeTexture: Boolean = false
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
override var suppressHaptic = false
|
||||
|
||||
var handleWidth: Int = initialHandleWidth
|
||||
set(value) {
|
||||
// reset the scroll status
|
||||
handlePos = 0.0
|
||||
this.value = 0.0
|
||||
field = value
|
||||
|
||||
handleTravelDist = width - value
|
||||
}
|
||||
|
||||
override val height = 24
|
||||
private var mouseOnHandle = false
|
||||
|
||||
private val handleTravelDist = width - handleWidth
|
||||
private var handleTravelDist = width - handleWidth
|
||||
private var handlePos = (initialValue / max).times(handleTravelDist).coerceIn(0.0, handleTravelDist.toDouble())
|
||||
|
||||
var value: Double = initialValue; private set
|
||||
|
||||
@@ -23,13 +23,23 @@ class UIItemVertSlider(
|
||||
val min: Double,
|
||||
val max: Double,
|
||||
override val height: Int,
|
||||
val handleHeight: Int = 12,
|
||||
initialHandleHeight: Int = 12,
|
||||
private val backgroundTexture: TextureRegion? = null,
|
||||
private val disposeTexture: Boolean = false
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
override var suppressHaptic = false
|
||||
|
||||
var handleHeight: Int = initialHandleHeight
|
||||
set(value) {
|
||||
// reset the scroll status
|
||||
handlePos = 0.0
|
||||
this.value = 0.0
|
||||
field = value
|
||||
|
||||
handleTravelDist = height - value
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val WIDTH = 16
|
||||
}
|
||||
@@ -37,7 +47,7 @@ class UIItemVertSlider(
|
||||
override val width = WIDTH
|
||||
private var mouseOnHandle = false
|
||||
|
||||
private val handleTravelDist = height - handleHeight
|
||||
private var handleTravelDist = height - handleHeight
|
||||
private var handlePos = if (max == 0.0) 0.0 else (initialValue / max).times(handleTravelDist).coerceIn(0.0, handleTravelDist.toDouble())
|
||||
|
||||
var value: Double = initialValue; private set
|
||||
|
||||
Reference in New Issue
Block a user