mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-17 00:56:07 +09:00
UI testing env and working text buttons
Former-commit-id: b8fd27c7f71f9bc8da259ae132badcbc9ce117ac
This commit is contained in:
82
src/net/torvald/terrarum/ui/UIItemTextButton.kt
Normal file
82
src/net/torvald/terrarum/ui/UIItemTextButton.kt
Normal file
@@ -0,0 +1,82 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
|
||||
/**
|
||||
* Text button. Height of hitbox is extended (double lineHeight, or 40 px) for better clicking
|
||||
*
|
||||
* Created by SKYHi14 on 2017-03-13.
|
||||
*/
|
||||
class UIItemTextButton(
|
||||
parentUI: UICanvas,
|
||||
val labelText: String,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
override val width: Int,
|
||||
val readFromLang: Boolean = false,
|
||||
val activeCol: Color = Color.white,
|
||||
val highlightCol: Color = Color(0x00f8ff),
|
||||
val inactiveCol: Color = Color(0xc0c0c0)
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
companion object {
|
||||
val font = Terrarum.fontGame!!
|
||||
val height = font.lineHeight * 2
|
||||
}
|
||||
|
||||
private val label: String
|
||||
get() = if (readFromLang) Lang[labelText] else labelText
|
||||
|
||||
|
||||
override val height: Int = UIItemTextButton.height
|
||||
|
||||
var highlighted: Boolean = false
|
||||
var mouseOver = false
|
||||
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
val textW = font.getWidth(label)
|
||||
|
||||
g.font = font
|
||||
mouseOver = mouseUp
|
||||
g.color = if (highlighted) highlightCol
|
||||
else if (mouseOver) activeCol
|
||||
else inactiveCol
|
||||
|
||||
g.drawString(label, posX.toFloat() + (width.minus(textW).div(2)), posY.toFloat() + height / 4)
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
}
|
||||
|
||||
override fun keyReleased(key: Int, c: Char) {
|
||||
}
|
||||
|
||||
override fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) {
|
||||
}
|
||||
|
||||
override fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) {
|
||||
}
|
||||
|
||||
override fun mousePressed(button: Int, x: Int, y: Int) {
|
||||
}
|
||||
|
||||
override fun mouseReleased(button: Int, x: Int, y: Int) {
|
||||
}
|
||||
|
||||
override fun mouseWheelMoved(change: Int) {
|
||||
}
|
||||
|
||||
override fun controllerButtonPressed(controller: Int, button: Int) {
|
||||
}
|
||||
|
||||
override fun controllerButtonReleased(controller: Int, button: Int) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user