UI testing env and working text buttons

Former-commit-id: b8fd27c7f71f9bc8da259ae132badcbc9ce117ac
This commit is contained in:
Song Minjae
2017-03-13 21:40:50 +09:00
parent 0113ca5d09
commit bc4fd8866a
73 changed files with 688 additions and 264 deletions

View 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) {
}
}