From eb1a3dcd14dc83c36a700ebae1712d73e017f8a6 Mon Sep 17 00:00:00 2001 From: Minjae Song Date: Sun, 9 Dec 2018 17:11:13 +0900 Subject: [PATCH] textbuttonlist fixed incorrect vertical placement --- .../terrarum/gamecontroller/KeyToggler.kt | 3 +++ .../terrarum/modulebasegame/ui/UIRemoCon.kt | 5 ++-- .../torvald/terrarum/ui/UIItemTextButton.kt | 9 ++++--- .../terrarum/ui/UIItemTextButtonList.kt | 25 +++++++++++++------ 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/net/torvald/terrarum/gamecontroller/KeyToggler.kt b/src/net/torvald/terrarum/gamecontroller/KeyToggler.kt index 5289b6c91..e587187ef 100644 --- a/src/net/torvald/terrarum/gamecontroller/KeyToggler.kt +++ b/src/net/torvald/terrarum/gamecontroller/KeyToggler.kt @@ -20,6 +20,9 @@ object KeyToggler { return currentState[key] } + /** + * Put this into the each scene's update/render method. + */ fun update(gameMode: Boolean = true) { for (it in 0..255) { if (gameMode && it in gameKeys && diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt index 9f67c880f..0d62a2807 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt @@ -264,11 +264,12 @@ open class UIRemoCon(treeRepresentation: QNDTreeNode) : UICanvas() { uiRemoCon.width, getRemoConHeight(labels), textAreaWidth = uiRemoCon.width, readFromLang = true, - activeBackCol = Color(0), + activeBackCol = Color(0),//Color(1f,0f,.75f,1f), highlightBackCol = Color(0), backgroundCol = Color(0), inactiveCol = Color.WHITE, - defaultSelection = null + defaultSelection = null, + itemHitboxSize = 34 ) fun update(delta: Float) { diff --git a/src/net/torvald/terrarum/ui/UIItemTextButton.kt b/src/net/torvald/terrarum/ui/UIItemTextButton.kt index 7ea1a64a5..b27d6cc63 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextButton.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextButton.kt @@ -30,12 +30,13 @@ open class UIItemTextButton( val preGapX: Int = 0, val postGapX: Int = 0, - val alignment: Alignment = Alignment.CENTRE + val alignment: Alignment = Alignment.CENTRE, + val hitboxSize: Int = UIItemTextButton.height ) : UIItem(parentUI) { companion object { val font = Terrarum.fontGame - val height = font.lineHeight.toInt() * 2 + val height = font.lineHeight.toInt() val defaultInactiveCol: Color = Color(0xc8c8c8_ff.toInt()) val defaultHighlightCol: Color = Color(0x00f8ff_ff) @@ -49,7 +50,7 @@ open class UIItemTextButton( get() = if (readFromLang) Lang[labelText] else labelText - override val height: Int = UIItemTextButton.height + override val height: Int = hitboxSize var highlighted: Boolean = false @@ -85,7 +86,7 @@ open class UIItemTextButton( Alignment.LEFT -> posX.toFloat() + preGapX Alignment.RIGHT -> width - postGapX - textW.toFloat() }, - posY.toFloat() + height / 4 + posY.toFloat() + (hitboxSize - UIItemTextButton.height) / 2f ) } diff --git a/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt b/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt index 2e5458834..c7a46b90a 100644 --- a/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt +++ b/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt @@ -20,7 +20,6 @@ class UIItemTextButtonList( override var posY: Int, override var width: Int, override var height: Int, - val verticalGutter: Int = 0, val readFromLang: Boolean = false, val defaultSelection: Int? = null, // negative: INVALID, positive: valid, null: no select @@ -42,7 +41,8 @@ class UIItemTextButtonList( val backgroundBlendMode: String = BlendMode.NORMAL, val kinematic: Boolean = false, - val alignment: UIItemTextButton.Companion.Alignment = UIItemTextButton.Companion.Alignment.CENTRE + val alignment: UIItemTextButton.Companion.Alignment = UIItemTextButton.Companion.Alignment.CENTRE, + val itemHitboxSize: Int = UIItemTextButton.height ) : UIItem(parentUI) { val iconToTextGap = 20 @@ -56,13 +56,20 @@ class UIItemTextButtonList( - val buttons = labelsList.mapIndexed { index, s -> - val height = this.height - UIItemTextButton.height + val buttons = labelsList.mapIndexed { i, s -> + //val height = this.height - UIItemTextButton.height + + val h = height.toFloat() + val ss = labelsList.size.toFloat() + val half_lh = UIItemTextButton.height / 2f + val vertOff = (i * h/ss - half_lh).roundInt() + println("$i -> $vertOff for height $height") + if (!kinematic) { UIItemTextButton( parentUI, s, posX = posX, - posY = posY + verticalGutter + ((height - 2 * verticalGutter) / labelsList.size.minus(1).toFloat() * index).roundInt(), + posY = posY + vertOff, width = width, readFromLang = readFromLang, activeCol = activeCol, @@ -74,14 +81,15 @@ class UIItemTextButtonList( inactiveCol = inactiveCol, preGapX = pregap, postGapX = postgap, - alignment = alignment + alignment = alignment, + hitboxSize = itemHitboxSize ) } else { UIItemTextButton( parentUI, s, posX = posX, - posY = posY + verticalGutter + ((height - 2 * verticalGutter) / labelsList.size.minus(1).toFloat() * index).roundInt(), + posY = posY + vertOff, width = width, readFromLang = readFromLang, activeCol = activeCol, @@ -93,7 +101,8 @@ class UIItemTextButtonList( inactiveCol = inactiveCol, preGapX = pregap, postGapX = postgap, - alignment = alignment + alignment = alignment, + hitboxSize = itemHitboxSize ) } }