mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 11:04:05 +09:00
TextButtonList working kinematic background
Former-commit-id: 8976d3b3d1e40731adf13430ad747351a6401b24
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.Millisec
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Input
|
||||
@@ -22,7 +23,7 @@ interface UICanvas {
|
||||
*
|
||||
* Timer itself is implemented in the handler.
|
||||
*/
|
||||
var openCloseTime: Int
|
||||
var openCloseTime: Millisec
|
||||
|
||||
fun update(gc: GameContainer, delta: Int)
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ 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 activeBackCol: Color = Color(0,0,0,0),
|
||||
val activeBackBlendMode: String = BlendMode.NORMAL,
|
||||
val highlightCol: Color = Color(0x00f8ff),
|
||||
val highlightBackCol: Color = Color(0xb0b0b0),
|
||||
val highlightBackBlendMode: String = BlendMode.MULTIPLY,
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.torvald.terrarum.ui
|
||||
import net.torvald.terrarum.BlendMode
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.Millisec
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
@@ -18,50 +19,95 @@ class UIItemTextButtonList(
|
||||
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)
|
||||
val activeCol: Color = Color.white,
|
||||
val activeBackCol: Color = Color(0,0,0,0),
|
||||
val activeBackBlendMode: String = BlendMode.NORMAL,
|
||||
val highlightCol: Color = Color(0x00f8ff),
|
||||
val highlightBackCol: Color = Color(0xb0b0b0),
|
||||
val highlightBackBlendMode: String = BlendMode.MULTIPLY,
|
||||
val inactiveCol: Color = Color(0xc8c8c8),
|
||||
val backgroundCol: Color = Color(0,0,0,0),
|
||||
val backgroundBlendMode: String = BlendMode.NORMAL,
|
||||
val kinematic: Boolean = false // more "kinetic" movement of selector
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
val buttons = labelsList.mapIndexed { index, s ->
|
||||
val height = this.height - UIItemTextButton.height
|
||||
UIItemTextButton(
|
||||
parentUI, s,
|
||||
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
|
||||
)
|
||||
if (!kinematic) {
|
||||
UIItemTextButton(
|
||||
parentUI, s,
|
||||
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
|
||||
)
|
||||
}
|
||||
else {
|
||||
UIItemTextButton(
|
||||
parentUI, s,
|
||||
posX = 0,
|
||||
posY = (height / labelsList.size.minus(1).toFloat() * index).roundInt(),
|
||||
width = width,
|
||||
readFromLang = true,
|
||||
activeBackCol = Color(0,0,0,0),
|
||||
activeBackBlendMode = BlendMode.NORMAL,
|
||||
highlightBackCol = Color(0,0,0,0)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override var posX = 0
|
||||
override var posY = 0
|
||||
|
||||
var selected: Int? = labelsList.size - 1 // default to "All"
|
||||
var selected = labelsList.size - 1 // default to "All"
|
||||
private var highlightY = buttons[selected].posY.toDouble()
|
||||
private val highlighterMoveDuration: Millisec = 100
|
||||
private var highlighterMoveTimer: Millisec = 0
|
||||
private var highlighterMoving = false
|
||||
private var highlighterYStart = highlightY
|
||||
private var highlighterYEnd = highlightY
|
||||
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
buttons.forEachIndexed { index, btn ->
|
||||
// update width because Lang is mutable (you can change language at any moment)
|
||||
val textW = UIItemTextButton.font.getWidth(
|
||||
if (readFromLang) Lang[btn.labelText] else btn.labelText
|
||||
if (highlighterMoving) {
|
||||
highlighterMoveTimer += delta
|
||||
highlightY = UIUtils.moveQuick(
|
||||
highlighterYStart,
|
||||
highlighterYEnd,
|
||||
highlighterMoveTimer.toDouble(),
|
||||
highlighterMoveDuration.toDouble()
|
||||
)
|
||||
|
||||
if (highlighterMoveTimer > highlighterMoveDuration) {
|
||||
highlighterMoveTimer = 0
|
||||
highlighterYStart = highlighterYEnd
|
||||
highlightY = highlighterYEnd
|
||||
highlighterMoving = false
|
||||
}
|
||||
}
|
||||
|
||||
buttons.forEachIndexed { index, btn ->
|
||||
btn.update(gc, delta)
|
||||
|
||||
|
||||
if (btn.mousePushed) {
|
||||
selected = index
|
||||
if (btn.mousePushed && index != selected) {
|
||||
if (kinematic) {
|
||||
highlighterYStart = buttons[selected].posY.toDouble()
|
||||
selected = index
|
||||
highlighterMoving = true
|
||||
highlighterYEnd = buttons[selected].posY.toDouble()
|
||||
}
|
||||
else {
|
||||
selected = index
|
||||
highlightY = buttons[selected].posY.toDouble()
|
||||
}
|
||||
}
|
||||
btn.highlighted = (index == selected) // forcibly highlight if this.highlighted != null
|
||||
|
||||
@@ -69,6 +115,13 @@ class UIItemTextButtonList(
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
g.color = backgroundCol
|
||||
BlendMode.resolve(backgroundBlendMode)
|
||||
g.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
|
||||
g.color = highlightBackCol
|
||||
g.fillRect(posX.toFloat(), highlightY.toFloat(), width.toFloat(), UIItemTextButton.height.toFloat())
|
||||
|
||||
buttons.forEach { it.render(gc, g) }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.Millisec
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import org.dyn4j.geometry.Vector2
|
||||
@@ -26,7 +27,7 @@ class UIPieMenu : UICanvas {
|
||||
/**
|
||||
* In milliseconds
|
||||
*/
|
||||
override var openCloseTime: Int = 160
|
||||
override var openCloseTime: Millisec = 160
|
||||
|
||||
private val smallenSize = 0.93f
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.Millisec
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import org.newdawn.slick.GameContainer
|
||||
@@ -16,7 +17,7 @@ class UIQuickBar : UICanvas, MouseControlled {
|
||||
/**
|
||||
* In milliseconds
|
||||
*/
|
||||
override var openCloseTime: Int = 160
|
||||
override var openCloseTime: Millisec = 160
|
||||
|
||||
private val startPointX = ItemSlotImageBuilder.slotLarge.width / 2
|
||||
private val startPointY = ItemSlotImageBuilder.slotLarge.height / 2
|
||||
|
||||
11
src/net/torvald/terrarum/ui/UIUtils.kt
Normal file
11
src/net/torvald/terrarum/ui/UIUtils.kt
Normal file
@@ -0,0 +1,11 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.terrarum.gameactors.sqr
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-03-14.
|
||||
*/
|
||||
object UIUtils {
|
||||
fun moveQuick(start: Double, end: Double, timer: Double, duration: Double) =
|
||||
(start - end) * ((timer / duration) - 1).sqr() + end
|
||||
}
|
||||
Reference in New Issue
Block a user