textbuttonlist fixed incorrect vertical placement

This commit is contained in:
Minjae Song
2018-12-09 17:11:13 +09:00
parent 32ecdc4b4d
commit eb1a3dcd14
4 changed files with 28 additions and 14 deletions

View File

@@ -20,6 +20,9 @@ object KeyToggler {
return currentState[key] return currentState[key]
} }
/**
* Put this into the each scene's update/render method.
*/
fun update(gameMode: Boolean = true) { fun update(gameMode: Boolean = true) {
for (it in 0..255) { for (it in 0..255) {
if (gameMode && it in gameKeys && if (gameMode && it in gameKeys &&

View File

@@ -264,11 +264,12 @@ open class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
uiRemoCon.width, getRemoConHeight(labels), uiRemoCon.width, getRemoConHeight(labels),
textAreaWidth = uiRemoCon.width, textAreaWidth = uiRemoCon.width,
readFromLang = true, readFromLang = true,
activeBackCol = Color(0), activeBackCol = Color(0),//Color(1f,0f,.75f,1f),
highlightBackCol = Color(0), highlightBackCol = Color(0),
backgroundCol = Color(0), backgroundCol = Color(0),
inactiveCol = Color.WHITE, inactiveCol = Color.WHITE,
defaultSelection = null defaultSelection = null,
itemHitboxSize = 34
) )
fun update(delta: Float) { fun update(delta: Float) {

View File

@@ -30,12 +30,13 @@ open class UIItemTextButton(
val preGapX: Int = 0, val preGapX: Int = 0,
val postGapX: Int = 0, val postGapX: Int = 0,
val alignment: Alignment = Alignment.CENTRE val alignment: Alignment = Alignment.CENTRE,
val hitboxSize: Int = UIItemTextButton.height
) : UIItem(parentUI) { ) : UIItem(parentUI) {
companion object { companion object {
val font = Terrarum.fontGame val font = Terrarum.fontGame
val height = font.lineHeight.toInt() * 2 val height = font.lineHeight.toInt()
val defaultInactiveCol: Color = Color(0xc8c8c8_ff.toInt()) val defaultInactiveCol: Color = Color(0xc8c8c8_ff.toInt())
val defaultHighlightCol: Color = Color(0x00f8ff_ff) val defaultHighlightCol: Color = Color(0x00f8ff_ff)
@@ -49,7 +50,7 @@ open class UIItemTextButton(
get() = if (readFromLang) Lang[labelText] else labelText get() = if (readFromLang) Lang[labelText] else labelText
override val height: Int = UIItemTextButton.height override val height: Int = hitboxSize
var highlighted: Boolean = false var highlighted: Boolean = false
@@ -85,7 +86,7 @@ open class UIItemTextButton(
Alignment.LEFT -> posX.toFloat() + preGapX Alignment.LEFT -> posX.toFloat() + preGapX
Alignment.RIGHT -> width - postGapX - textW.toFloat() Alignment.RIGHT -> width - postGapX - textW.toFloat()
}, },
posY.toFloat() + height / 4 posY.toFloat() + (hitboxSize - UIItemTextButton.height) / 2f
) )
} }

View File

@@ -20,7 +20,6 @@ class UIItemTextButtonList(
override var posY: Int, override var posY: Int,
override var width: Int, override var width: Int,
override var height: Int, override var height: Int,
val verticalGutter: Int = 0,
val readFromLang: Boolean = false, val readFromLang: Boolean = false,
val defaultSelection: Int? = null, // negative: INVALID, positive: valid, null: no select val defaultSelection: Int? = null, // negative: INVALID, positive: valid, null: no select
@@ -42,7 +41,8 @@ class UIItemTextButtonList(
val backgroundBlendMode: String = BlendMode.NORMAL, val backgroundBlendMode: String = BlendMode.NORMAL,
val kinematic: Boolean = false, 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) { ) : UIItem(parentUI) {
val iconToTextGap = 20 val iconToTextGap = 20
@@ -56,13 +56,20 @@ class UIItemTextButtonList(
val buttons = labelsList.mapIndexed { index, s -> val buttons = labelsList.mapIndexed { i, s ->
val height = this.height - UIItemTextButton.height //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) { if (!kinematic) {
UIItemTextButton( UIItemTextButton(
parentUI, s, parentUI, s,
posX = posX, posX = posX,
posY = posY + verticalGutter + ((height - 2 * verticalGutter) / labelsList.size.minus(1).toFloat() * index).roundInt(), posY = posY + vertOff,
width = width, width = width,
readFromLang = readFromLang, readFromLang = readFromLang,
activeCol = activeCol, activeCol = activeCol,
@@ -74,14 +81,15 @@ class UIItemTextButtonList(
inactiveCol = inactiveCol, inactiveCol = inactiveCol,
preGapX = pregap, preGapX = pregap,
postGapX = postgap, postGapX = postgap,
alignment = alignment alignment = alignment,
hitboxSize = itemHitboxSize
) )
} }
else { else {
UIItemTextButton( UIItemTextButton(
parentUI, s, parentUI, s,
posX = posX, posX = posX,
posY = posY + verticalGutter + ((height - 2 * verticalGutter) / labelsList.size.minus(1).toFloat() * index).roundInt(), posY = posY + vertOff,
width = width, width = width,
readFromLang = readFromLang, readFromLang = readFromLang,
activeCol = activeCol, activeCol = activeCol,
@@ -93,7 +101,8 @@ class UIItemTextButtonList(
inactiveCol = inactiveCol, inactiveCol = inactiveCol,
preGapX = pregap, preGapX = pregap,
postGapX = postgap, postGapX = postgap,
alignment = alignment alignment = alignment,
hitboxSize = itemHitboxSize
) )
} }
} }