mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
moved white box tex to AppLoader; textButton now has alignment option
This commit is contained in:
@@ -78,9 +78,9 @@ abstract class UICanvas(
|
||||
}
|
||||
|
||||
|
||||
/** Override this for the actual update. You must update uiItems by yourself. */
|
||||
/** Override this for the actual update. Note that you must update uiItems by yourself. */
|
||||
abstract fun updateUI(delta: Float)
|
||||
/** Override this for the actual render. You must render uiItems by yourself. */
|
||||
/** Override this for the actual render. Note that you must render uiItems by yourself. */
|
||||
abstract fun renderUI(batch: SpriteBatch, camera: Camera)
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.floor
|
||||
import net.torvald.terrarum.ui.UIItemTextButton.Companion.Alignment
|
||||
|
||||
class UIItemTextArea(
|
||||
parentUI: UICanvas,
|
||||
@@ -13,16 +14,9 @@ class UIItemTextArea(
|
||||
override val height: Int,
|
||||
val lineGap: Int = 0,
|
||||
val lineCount: Int = ((height + lineGap) / Terrarum.fontGame.lineHeight).toInt(),
|
||||
val align: UIItemTextArea.Align = Align.LEFT
|
||||
val align: Alignment = Alignment.LEFT
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
|
||||
enum class Align {
|
||||
LEFT, CENTRE, RIGHT
|
||||
}
|
||||
|
||||
|
||||
|
||||
private var entireText: List<String> = listOf("") // placeholder
|
||||
|
||||
var scrollPos = 0
|
||||
@@ -45,9 +39,9 @@ class UIItemTextArea(
|
||||
val textWidth = Terrarum.fontGame.getWidth(entireText[i])
|
||||
|
||||
when (align) {
|
||||
Align.LEFT -> Terrarum.fontGame.draw(batch, entireText[i], posX.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
|
||||
Align.CENTRE -> Terrarum.fontGame.draw(batch, entireText[i], posX + ((width - textWidth) / 2f).floor(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
|
||||
Align.RIGHT -> Terrarum.fontGame.draw(batch, entireText[i], posX + width - textWidth.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
|
||||
Alignment.LEFT -> Terrarum.fontGame.draw(batch, entireText[i], posX.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
|
||||
Alignment.CENTRE -> Terrarum.fontGame.draw(batch, entireText[i], posX + ((width - textWidth) / 2f).floor(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
|
||||
Alignment.RIGHT -> Terrarum.fontGame.draw(batch, entireText[i], posX + width - textWidth.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,9 @@ open class UIItemTextButton(
|
||||
val highlightBackBlendMode: String = BlendMode.MULTIPLY,
|
||||
val inactiveCol: Color = defaultInactiveCol,
|
||||
val preGapX: Int = 0,
|
||||
val postGapX: Int = 0
|
||||
val postGapX: Int = 0,
|
||||
|
||||
val alignment: Alignment = Alignment.CENTRE
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
companion object {
|
||||
@@ -36,6 +38,10 @@ open class UIItemTextButton(
|
||||
val height = font.lineHeight.toInt() * 2
|
||||
val defaultInactiveCol: Color = Color(0xc8c8c8_ff.toInt())
|
||||
val defaultHighlightCol: Color = Color(0x00f8ff_ff)
|
||||
|
||||
enum class Alignment {
|
||||
CENTRE, LEFT, RIGHT
|
||||
}
|
||||
}
|
||||
|
||||
/** Actually displayed text (changes with the app language) */
|
||||
@@ -74,7 +80,11 @@ open class UIItemTextButton(
|
||||
|
||||
font.draw(batch,
|
||||
label,
|
||||
posX.toFloat() + width.minus(textW).div(2) + (preGapX - postGapX).div(2),
|
||||
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()
|
||||
},
|
||||
posY.toFloat() + height / 4
|
||||
)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,9 @@ class UIItemTextButtonList(
|
||||
val inactiveCol: Color = Color(0xc0c0c0_ff.toInt()),
|
||||
val backgroundCol: Color = Color(0x242424_80),
|
||||
val backgroundBlendMode: String = BlendMode.NORMAL,
|
||||
val kinematic: Boolean = false
|
||||
val kinematic: Boolean = false,
|
||||
|
||||
val alignment: UIItemTextButton.Companion.Alignment = UIItemTextButton.Companion.Alignment.CENTRE
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
val iconToTextGap = 20
|
||||
@@ -71,7 +73,8 @@ class UIItemTextButtonList(
|
||||
highlightBackBlendMode = highlightBackBlendMode,
|
||||
inactiveCol = inactiveCol,
|
||||
preGapX = pregap,
|
||||
postGapX = postgap
|
||||
postGapX = postgap,
|
||||
alignment = alignment
|
||||
)
|
||||
}
|
||||
else {
|
||||
@@ -89,7 +92,8 @@ class UIItemTextButtonList(
|
||||
highlightBackBlendMode = activeBackBlendMode, // we are using custom highlighter
|
||||
inactiveCol = inactiveCol,
|
||||
preGapX = pregap,
|
||||
postGapX = postgap
|
||||
postGapX = postgap,
|
||||
alignment = alignment
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user