mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-17 05:54:05 +09:00
bigger click hitbox for titlescreen uiremocon
This commit is contained in:
@@ -6,8 +6,10 @@ import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.Pixmap
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
import net.torvald.terrarum.*
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
@@ -15,19 +17,29 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
/**
|
||||
* Created by minjaesong on 2016-08-04.
|
||||
*/
|
||||
object Toolkit {
|
||||
object Toolkit : Disposable {
|
||||
|
||||
val DEFAULT_BOX_BORDER_COL = Color(1f, 1f, 1f, 0.2f)
|
||||
|
||||
private val shaderBlur = App.loadShaderFromFile("assets/blur.vert", "assets/blur2.frag")
|
||||
val baloonTile = TextureRegionPack("assets/graphics/gui/message_black_tileable.tga", 36, 36)
|
||||
|
||||
|
||||
init {
|
||||
App.disposableSingletonsPool.add(this)
|
||||
|
||||
CommonResourcePool.addToLoadingList("toolkit_box_border") {
|
||||
TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/box_border_flat_tileable.tga"), 1, 1)
|
||||
}
|
||||
CommonResourcePool.loadAll()
|
||||
}
|
||||
|
||||
|
||||
override fun dispose() {
|
||||
baloonTile.dispose()
|
||||
}
|
||||
|
||||
|
||||
fun drawCentered(batch: SpriteBatch, image: Texture, screenPosY: Int, ui: UICanvas? = null) {
|
||||
val imageW = image.width
|
||||
val targetW = if (ui == null) App.scr.width else ui.width
|
||||
@@ -98,4 +110,21 @@ object Toolkit {
|
||||
batch.shader = null
|
||||
}
|
||||
|
||||
fun drawBaloon(batch: SpriteBatch, x: Float, y: Float, w: Float, h: Float) {
|
||||
// centre area
|
||||
batch.draw(baloonTile.get(1, 1), x, y, w, h)
|
||||
|
||||
// edges
|
||||
batch.draw(baloonTile.get(1, 0), x, y - baloonTile.tileH, w, baloonTile.tileH.toFloat())
|
||||
batch.draw(baloonTile.get(1, 2), x, y + h, w, baloonTile.tileH.toFloat())
|
||||
batch.draw(baloonTile.get(0, 1), x - baloonTile.tileW, y, baloonTile.tileW.toFloat(), h)
|
||||
batch.draw(baloonTile.get(2, 1), x + w, y, baloonTile.tileW.toFloat(), h)
|
||||
|
||||
// corners
|
||||
batch.draw(baloonTile.get(0, 0), x - baloonTile.tileW, y - baloonTile.tileH)
|
||||
batch.draw(baloonTile.get(2, 0), x + w, y - baloonTile.tileH)
|
||||
batch.draw(baloonTile.get(2, 2), x + w, y + h)
|
||||
batch.draw(baloonTile.get(0, 2), x - baloonTile.tileW, y + h)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -93,7 +93,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
||||
get() = mouseUp && Gdx.input.isButtonPressed(mouseButton)
|
||||
|
||||
|
||||
private var mouseLatched = Gdx.input.isButtonPressed(mouseButton)
|
||||
protected var mouseLatched = Gdx.input.isButtonPressed(mouseButton)
|
||||
|
||||
/** UI to call (show up) while mouse is up */
|
||||
open val mouseOverCall: UICanvas? = null
|
||||
|
||||
@@ -40,8 +40,8 @@ open class UIItemTextButton(
|
||||
val backgroundBlendMode: String = BlendMode.NORMAL,
|
||||
|
||||
|
||||
val preGapX: Int = 0,
|
||||
val postGapX: Int = 0,
|
||||
val paddingLeft: Int = 0,
|
||||
val paddingRight: Int = 0,
|
||||
|
||||
val alignment: Alignment = Alignment.CENTRE,
|
||||
val hitboxSize: Int = UIItemTextButton.height,
|
||||
@@ -109,9 +109,9 @@ open class UIItemTextButton(
|
||||
label,
|
||||
// "$label/H:${highlighted.toInt()}, M:${mouseUp.toInt()}",
|
||||
when (alignment) {
|
||||
Alignment.CENTRE -> posX.toFloat() + width.minus(textW).div(2) + (preGapX - postGapX).div(2)
|
||||
Alignment.LEFT -> posX.toFloat() + preGapX
|
||||
Alignment.RIGHT -> width - postGapX - textW.toFloat()
|
||||
Alignment.CENTRE -> posX.toFloat() + width.minus(textW).div(2) + (paddingLeft - paddingRight).div(2)
|
||||
Alignment.LEFT -> posX.toFloat() + paddingLeft
|
||||
Alignment.RIGHT -> width - paddingRight - textW.toFloat()
|
||||
},
|
||||
posY.toFloat() + (hitboxSize - UIItemTextButton.height) / 2f
|
||||
)
|
||||
|
||||
@@ -52,6 +52,9 @@ class UIItemTextButtonList(
|
||||
|
||||
val kinematic: Boolean = false,
|
||||
|
||||
val leftPadding: Int = 0,
|
||||
val rightPadding: Int = 0,
|
||||
|
||||
val alignment: UIItemTextButton.Companion.Alignment = UIItemTextButton.Companion.Alignment.CENTRE,
|
||||
val itemHitboxSize: Int = lineHeight,
|
||||
tagsCollection: Array<Array<String>> = Array(labelsList.size) { arrayOf("") }
|
||||
@@ -70,8 +73,8 @@ class UIItemTextButtonList(
|
||||
|
||||
// zero if iconSpriteSheet is null
|
||||
val iconsWithGap: Int = iconToTextGap + iconCellWidth
|
||||
val pregap = (width - textAreaWidth - iconsWithGap) / 2 + iconsWithGap
|
||||
val postgap = (width - textAreaWidth - iconsWithGap) / 2
|
||||
val pregap = (width - textAreaWidth - iconsWithGap) / 2 + iconsWithGap + leftPadding
|
||||
val postgap = (width - textAreaWidth - iconsWithGap) / 2 + rightPadding
|
||||
|
||||
|
||||
|
||||
@@ -99,8 +102,8 @@ class UIItemTextButtonList(
|
||||
inactiveCol = inactiveCol,
|
||||
backgroundCol = backgroundCol,
|
||||
backgroundBlendMode = backgroundBlendMode,
|
||||
preGapX = pregap,
|
||||
postGapX = postgap,
|
||||
paddingLeft = pregap,
|
||||
paddingRight = postgap,
|
||||
alignment = alignment,
|
||||
hitboxSize = itemHitboxSize,
|
||||
tags = tagsCollection[i]
|
||||
@@ -121,8 +124,8 @@ class UIItemTextButtonList(
|
||||
highlightBackBlendMode = activeBackBlendMode, // we are using custom highlighter
|
||||
backgroundCol = Color(0),
|
||||
inactiveCol = inactiveCol,
|
||||
preGapX = pregap,
|
||||
postGapX = postgap,
|
||||
paddingLeft = pregap,
|
||||
paddingRight = postgap,
|
||||
alignment = alignment,
|
||||
hitboxSize = itemHitboxSize,
|
||||
tags = tagsCollection[i]
|
||||
|
||||
Reference in New Issue
Block a user