text labels now has background

Former-commit-id: 05f2767134b385960deb65c2e76c97432c8303ad
This commit is contained in:
Song Minjae
2017-03-14 15:08:18 +09:00
parent 1bad5550b2
commit 18ce52e407
12 changed files with 136 additions and 37 deletions

View File

@@ -28,8 +28,9 @@ class UIInventory : UICanvas {
"CONTEXT_ITEM_ARMOR",
"GAME_INVENTORY_INGREDIENTS",
"GAME_INVENTORY_POTIONS",
"CONTEXT_ITEM_MAGIC",
"GAME_INVENTORY_BLOCKS",
"GAME_INVENTORY_WALLPAPERS",
"GAME_INVENTORY_WALLS",
"MENU_LABEL_ALL"
)

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.ui
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.*
import net.torvald.terrarum.langpack.Lang
import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer
@@ -19,8 +19,12 @@ class UIItemTextButton(
override val width: Int,
val readFromLang: Boolean = false,
val activeCol: Color = Color.white,
val activeBackCol: Color = Color(0xd0d0d0),
val activeBackBlendMode: String = BlendMode.MULTIPLY,
val highlightCol: Color = Color(0x00f8ff),
val inactiveCol: Color = Color(0xc0c0c0)
val highlightBackCol: Color = Color(0xb0b0b0),
val highlightBackBlendMode: String = BlendMode.MULTIPLY,
val inactiveCol: Color = Color(0xc8c8c8)
) : UIItem(parentUI) {
companion object {
@@ -44,6 +48,21 @@ class UIItemTextButton(
override fun render(gc: GameContainer, g: Graphics) {
val textW = font.getWidth(label)
if (highlighted) {
BlendMode.resolve(highlightBackBlendMode)
g.color = highlightBackCol
g.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
}
else if (mouseOver) {
BlendMode.resolve(activeBackBlendMode)
g.color = activeBackCol
g.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
}
blendNormal()
g.font = font
mouseOver = mouseUp
g.color = if (highlighted) highlightCol
@@ -79,4 +98,4 @@ class UIItemTextButton(
override fun controllerButtonReleased(controller: Int, button: Int) {
}
}
}

View File

@@ -1,7 +1,9 @@
package net.torvald.terrarum.ui
import net.torvald.terrarum.BlendMode
import net.torvald.terrarum.gameactors.roundInt
import net.torvald.terrarum.langpack.Lang
import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
@@ -13,17 +15,33 @@ class UIItemTextButtonList(
labelsList: Array<String>,
override val width: Int,
override val height: Int,
val readFromLang: Boolean = false
val readFromLang: Boolean = false,
// copied directly from UIItemTextButton
activeCol: Color = Color.white,
activeBackCol: Color = Color(0xd0d0d0),
activeBackBlendMode: String = BlendMode.MULTIPLY,
highlightCol: Color = Color(0x00f8ff),
highlightBackCol: Color = Color(0xb0b0b0),
highlightBackBlendMode: String = BlendMode.MULTIPLY,
inactiveCol: Color = Color(0xc8c8c8)
) : UIItem(parentUI) {
val buttons = labelsList.mapIndexed { index, s ->
val height = this.height - UIItemTextButton.height
UIItemTextButton(
parentUI, s,
0,
(height / labelsList.size.minus(1).toFloat() * index).roundInt(),
width,
readFromLang = true
posX = 0,
posY = (height / labelsList.size.minus(1).toFloat() * index).roundInt(),
width = width,
readFromLang = true,
activeCol = activeCol,
activeBackCol = activeBackCol,
activeBackBlendMode = activeBackBlendMode,
highlightCol = highlightCol,
highlightBackCol = highlightBackCol,
highlightBackBlendMode = highlightBackBlendMode,
inactiveCol = inactiveCol
)
}