From a2006b0354b87b703117532cf399508ab578c8d3 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 1 Feb 2025 19:31:07 +0900 Subject: [PATCH] debugging thing update --- .../modulebasegame/ui/UIDebugInventron.kt | 49 +++++++++++++++---- .../torvald/terrarum/ui/UIItemHorzSlider.kt | 14 +++++- .../torvald/terrarum/ui/UIItemVertSlider.kt | 14 +++++- 3 files changed, 63 insertions(+), 14 deletions(-) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIDebugInventron.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIDebugInventron.kt index ebb743a67..2142643c1 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIDebugInventron.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIDebugInventron.kt @@ -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() + + // 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 = ArrayList() 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) } } diff --git a/src/net/torvald/terrarum/ui/UIItemHorzSlider.kt b/src/net/torvald/terrarum/ui/UIItemHorzSlider.kt index f7e0f76e5..6d1e60bf0 100644 --- a/src/net/torvald/terrarum/ui/UIItemHorzSlider.kt +++ b/src/net/torvald/terrarum/ui/UIItemHorzSlider.kt @@ -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 diff --git a/src/net/torvald/terrarum/ui/UIItemVertSlider.kt b/src/net/torvald/terrarum/ui/UIItemVertSlider.kt index c2d556738..de94d7815 100644 --- a/src/net/torvald/terrarum/ui/UIItemVertSlider.kt +++ b/src/net/torvald/terrarum/ui/UIItemVertSlider.kt @@ -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