bigger click hitbox for titlescreen uiremocon

This commit is contained in:
minjaesong
2021-09-19 20:39:23 +09:00
parent bccac0fbd3
commit 10bee994a7
9 changed files with 113 additions and 69 deletions

View File

@@ -1,43 +0,0 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.utils.Disposable
import net.torvald.terrarum.App
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
* Created by minjaesong on 2019-05-24.
*/
object FloatDrawer : Disposable {
val tile = TextureRegionPack("assets/graphics/gui/message_black_tileable.tga", 36, 36)
init {
App.disposableSingletonsPool.add(this)
}
/**
* Draws the Float at given position in given size. The size is that of the centre area, excluding the edges. Size of the edges are 8x8 pixels.
*/
operator fun invoke(batch: SpriteBatch, x: Float, y: Float, w: Float, h: Float) {
// centre area
batch.draw(tile.get(1, 1), x, y, w, h)
// edges
batch.draw(tile.get(1, 0), x, y - tile.tileH, w, tile.tileH.toFloat())
batch.draw(tile.get(1, 2), x, y + h, w, tile.tileH.toFloat())
batch.draw(tile.get(0, 1), x - tile.tileW, y, tile.tileW.toFloat(), h)
batch.draw(tile.get(2, 1), x + w, y, tile.tileW.toFloat(), h)
// corners
batch.draw(tile.get(0, 0), x - tile.tileW, y - tile.tileH)
batch.draw(tile.get(2, 0), x + w, y - tile.tileH)
batch.draw(tile.get(2, 2), x + w, y + h)
batch.draw(tile.get(0, 2), x - tile.tileW, y + h)
}
override fun dispose() {
tile.dispose()
}
}

View File

@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.App
import net.torvald.terrarum.Second
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
/**
@@ -67,7 +68,7 @@ class Notification : UICanvas() {
batch.color = drawColor
FloatDrawer(batch, 0f, -textHeight, displayedTextWidth.toFloat(), textHeight)
Toolkit.drawBaloon(batch, 0f, -textHeight, displayedTextWidth.toFloat(), textHeight)
batch.color = fontCol
message.forEachIndexed { index, s ->

View File

@@ -116,8 +116,7 @@ class UIKeyboardControlPanel : UICanvas() {
-4 to UIItemKeycap(this, 401,129, null, oneu, ""),
Input.Keys.CONTROL_RIGHT to UIItemKeycap(this, 433,129, Input.Keys.CONTROL_RIGHT, onehalfu, "21,3"),
// ...
)
) // end of keycaps
private val symbolLeft = labels.get(0,2)
private val symbolUp = labels.get(1,2)
@@ -129,6 +128,7 @@ class UIKeyboardControlPanel : UICanvas() {
private val symbolGrapplingHook = labels.get(5,1)
private val symbolGamemenu = labels.get(6,2)
private val controlPalette = UIItemControlPaletteBaloon(this, (App.scr.width - 480) / 2, kby + 199)
init {
keycaps.values.forEach { addUIitem(it) }
@@ -147,8 +147,26 @@ class UIKeyboardControlPanel : UICanvas() {
keycaps[App.getConfigInt("control_key_gamemenu")]?.symbolControl = symbolGamemenu
}
internal var keycapClicked = -13372
set(value) {
if (field != value) keycaps[field]?.selected = false
field = value
}
internal var controlSelected = -1
override fun updateUI(delta: Float) {
uiItems.forEach { it.update(delta) }
uiItems.forEach {
it.update(delta)
if (it is UIItemKeycap && it.mousePushed) {
it.selected = true
// println("key ${it.key}; selected = ${it.selected}")
keycapClicked = it.key ?: -13372
}
}
if (keycapClicked >= 0 && controlSelected < 0) {
controlPalette.update(delta)
}
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
@@ -159,6 +177,12 @@ class UIKeyboardControlPanel : UICanvas() {
uiItems.forEach { it.render(batch, camera) }
batch.color = Color.WHITE
if (keycapClicked >= 0 && controlSelected < 0) {
controlPalette.render(batch, camera)
}
val title = Lang["MENU_CONTROLS_KEYBOARD"]
App.fontGame.draw(batch, title, drawX.toFloat() + (width - App.fontGame.getWidth(title)) / 2, drawY.toFloat())
@@ -207,11 +231,13 @@ class UIItemKeycap(
private val s1 = if (symbolDefault.isNotBlank()) symbolDefault.split(',').map { it.toInt() } else null
var symbolControl: TextureRegion? = null
var selected = false
private val borderKeyForbidden = Color(0x000000C0)
private val borderKeyNormal = Color(0xFFFFFFAA.toInt())
private val borderMouseUp = UIItemTextButton.defaultActiveCol
private val borderKeyPressed = UIItemTextButton.defaultHighlightCol
private val borderKeyPressedAndSelected = Color(0x33FF33FF.toInt())
private val keycapFill = Color(0x404040_C0)
@@ -227,7 +253,9 @@ class UIItemKeycap(
batch.color = if (key == null)
borderKeyForbidden
else if (Gdx.input.isKeyPressed(key))
else if (Gdx.input.isKeyPressed(key) && selected)
borderKeyPressedAndSelected
else if (Gdx.input.isKeyPressed(key) || selected)
borderKeyPressed
else if (mouseUp)
borderMouseUp
@@ -260,3 +288,26 @@ class UIItemKeycap(
}
}
class UIItemControlPaletteBaloon(val parent: UIKeyboardControlPanel, initialX: Int, initialY: Int) : UIItem(parent, initialX, initialY) {
override val width = 480
override val height = 240
override fun dispose() {}
override fun render(batch: SpriteBatch, camera: Camera) {
super.render(batch, camera)
Toolkit.drawBaloon(batch, posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
}
override fun update(delta: Float) {
super.update(delta) // unlatches mouse
// close
if (!mouseLatched && mousePushed) {
mouseLatched = true
parent.keycapClicked = -13372
}
}
}

View File

@@ -258,14 +258,15 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
class UIRemoConElement(uiRemoCon: UIRemoCon, val labels: Array<String>, val tags: Array<Array<String>>) {
private val lineHeight = 36
private val paddingLeft = 48
private val menubar = UIItemTextButtonList(
uiRemoCon,
lineHeight,
labels,
menubarOffX,
menubarOffX - paddingLeft,
menubarOffY - lineHeight * labels.size + 16,
uiRemoCon.width, getRemoConHeight(labels),
uiRemoCon.width + paddingLeft, getRemoConHeight(labels),
textAreaWidth = uiRemoCon.width,
readFromLang = true,
activeBackCol = Color(0),//Color(1f,0f,.75f,1f),
@@ -275,6 +276,7 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
defaultSelection = null,
itemHitboxSize = lineHeight - 2,
alignment = UIItemTextButton.Companion.Alignment.LEFT,
leftPadding = paddingLeft,
tagsCollection = tags
)
@@ -302,7 +304,7 @@ open class UIRemoCon(val parent: TitleScreen, treeRepresentation: QNDTreeNode<St
}
companion object {
val remoConWidth = 300
val remoConWidth = 160
fun getRemoConHeight(menu: ArrayList<String>) = DEFAULT_LINE_HEIGHT * menu.size.plus(1)
fun getRemoConHeight(menu: Array<String>) = DEFAULT_LINE_HEIGHT * menu.size.plus(1)
val menubarOffX: Int; get() = (0.11 * App.scr.width).toInt()

View File

@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.App
import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
/**
@@ -34,10 +35,10 @@ class UITooltip : UICanvas() {
val textMarginX = 4
override var width: Int
get() = msgWidth + (textMarginX + FloatDrawer.tile.tileW) * 2
get() = msgWidth + (textMarginX + Toolkit.baloonTile.tileW) * 2
set(value) { throw Error("You are not supposed to set the width of the tooltip manually.") }
override var height: Int
get() = FloatDrawer.tile.tileH * 2 + font.lineHeight.toInt()
get() = Toolkit.baloonTile.tileH * 2 + font.lineHeight.toInt()
set(value) { throw Error("You are not supposed to set the height of the tooltip manually.") }
override fun renderUI(batch: SpriteBatch, camera: Camera) {
@@ -54,7 +55,7 @@ class UITooltip : UICanvas() {
batch.color = tooltipBackCol
FloatDrawer(batch,
Toolkit.drawBaloon(batch,
tooltipX - textMarginX,
tooltipY,
tooltipW,