TextButtonList working kinematic background

Former-commit-id: 8976d3b3d1e40731adf13430ad747351a6401b24
This commit is contained in:
Song Minjae
2017-03-15 01:06:13 +09:00
parent ff817c25e6
commit 3d91023011
20 changed files with 127 additions and 51 deletions

View File

@@ -11,5 +11,6 @@
"GAME_INVENTORY_POTIONS" : "Potions", "GAME_INVENTORY_POTIONS" : "Potions",
"GAME_INVENTORY_BLOCKS" : "Blocks", "GAME_INVENTORY_BLOCKS" : "Blocks",
"GAME_INVENTORY_WALLS" : "Walls", "GAME_INVENTORY_WALLS" : "Walls",
"CONTEXT_ITEM_EQUIPMENT_PLURAL" : "Equipments" "CONTEXT_ITEM_EQUIPMENT_PLURAL" : "Equipments",
"GAME_INVENTORY_FAVORITES" : "Favorites"
} }

View File

@@ -12,5 +12,6 @@
"GAME_INVENTORY_POTIONS" : "Juomat", "GAME_INVENTORY_POTIONS" : "Juomat",
"GAME_INVENTORY_BLOCKS" : "Lohkareet", "GAME_INVENTORY_BLOCKS" : "Lohkareet",
"GAME_INVENTORY_WALLS" : "Seinät", "GAME_INVENTORY_WALLS" : "Seinät",
"CONTEXT_ITEM_EQUIPMENT_PLURAL" : "Varusteet" "CONTEXT_ITEM_EQUIPMENT_PLURAL" : "Varusteet",
"GAME_INVENTORY_FAVORITES" : "Suosikit"
} }

View File

@@ -12,5 +12,6 @@
"GAME_INVENTORY_POTIONS" : "Potions", "GAME_INVENTORY_POTIONS" : "Potions",
"GAME_INVENTORY_BLOCKS" : "Blocs", "GAME_INVENTORY_BLOCKS" : "Blocs",
"GAME_INVENTORY_WALLS" : "Murs", "GAME_INVENTORY_WALLS" : "Murs",
"CONTEXT_ITEM_EQUIPMENT_PLURAL" : "Équipements" "CONTEXT_ITEM_EQUIPMENT_PLURAL" : "Équipements",
"GAME_INVENTORY_FAVORITES" : "Favoris"
} }

View File

@@ -12,5 +12,6 @@
"GAME_INVENTORY_POTIONS" : "물약", "GAME_INVENTORY_POTIONS" : "물약",
"GAME_INVENTORY_BLOCKS" : "블록", "GAME_INVENTORY_BLOCKS" : "블록",
"GAME_INVENTORY_WALLS" : "벽지", "GAME_INVENTORY_WALLS" : "벽지",
"CONTEXT_ITEM_EQUIPMENT_PLURAL" : "장비" "CONTEXT_ITEM_EQUIPMENT_PLURAL" : "장비",
"GAME_INVENTORY_FAVORITES" : "중요"
} }

View File

@@ -81,13 +81,16 @@ private class SimpleUI : UICanvas {
"CONTEXT_ITEM_MAGIC", "CONTEXT_ITEM_MAGIC",
"GAME_INVENTORY_BLOCKS", "GAME_INVENTORY_BLOCKS",
"GAME_INVENTORY_WALLS", "GAME_INVENTORY_WALLS",
"GAME_INVENTORY_FAVORITES",
"MENU_LABEL_ALL" "MENU_LABEL_ALL"
), ),
width = (width / 3 / 100) * 100, // chop to hundreds unit (100, 200, 300, ...) with the black magic of integer division width = (width / 3 / 100) * 100, // chop to hundreds unit (100, 200, 300, ...) with the black magic of integer division
height = height, height = height,
readFromLang = true, readFromLang = true,
highlightBackCol = Color(0x202020), highlightBackCol = Color(0x202020),
highlightBackBlendMode = BlendMode.NORMAL highlightBackBlendMode = BlendMode.NORMAL,
backgroundCol = Color(0x383838),
kinematic = true
) )
override fun update(gc: GameContainer, delta: Int) { override fun update(gc: GameContainer, delta: Int) {
@@ -100,10 +103,6 @@ private class SimpleUI : UICanvas {
g.color = Color(0x202020) g.color = Color(0x202020)
g.fillRect(0f, 0f, width.toFloat(), height.toFloat()) g.fillRect(0f, 0f, width.toFloat(), height.toFloat())
g.color = Color(0x383838)
g.fillRect(0f, 0f, buttons.width.toFloat(), height.toFloat())
buttons.render(gc, g) buttons.render(gc, g)
} }

View File

@@ -26,6 +26,8 @@ import java.util.logging.SimpleFormatter
const val GAME_NAME = "Terrarum" const val GAME_NAME = "Terrarum"
typealias Millisec = Int
/** /**
* Created by minjaesong on 15-12-30. * Created by minjaesong on 15-12-30.
*/ */

View File

@@ -202,7 +202,7 @@ open class ActorWithSprite(renderOrder: ActorOrder, val immobileBody: Boolean =
/** /**
* Post-hit invincibility, in milliseconds * Post-hit invincibility, in milliseconds
*/ */
@Transient val INVINCIBILITY_TIME: Int = 500 @Transient val INVINCIBILITY_TIME: Millisec = 500
@Transient internal val BASE_FRICTION = 0.3 @Transient internal val BASE_FRICTION = 0.3

View File

@@ -2,6 +2,7 @@ package net.torvald.terrarum.tileproperties
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.random.HQRNG import net.torvald.random.HQRNG
import net.torvald.terrarum.Millisec
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameworld.WorldTime import net.torvald.terrarum.gameworld.WorldTime
import net.torvald.terrarum.mapdrawer.LightmapRenderer import net.torvald.terrarum.mapdrawer.LightmapRenderer
@@ -13,17 +14,17 @@ import org.newdawn.slick.Color
* Created by minjaesong on 16-06-16. * Created by minjaesong on 16-06-16.
*/ */
object TilePropUtil { object TilePropUtil {
var flickerFuncX = 0 // in milliseconds; saves current status (time) of func var flickerFuncX: Millisec = 0 // in milliseconds; saves current status (time) of func
val flickerFuncDomain = 100 // time between two noise sample, in milliseconds val flickerFuncDomain: Millisec = 100 // time between two noise sample, in milliseconds
val flickerFuncRange = 0.012f // intensity [0, 1] val flickerFuncRange = 0.012f // intensity [0, 1]
var breathFuncX = 0 var breathFuncX = 0
val breathRange = 0.02f val breathRange = 0.02f
val breathCycleDuration = 2000 // in milliseconds val breathCycleDuration: Millisec = 2000 // in milliseconds
var pulsateFuncX = 0 var pulsateFuncX = 0
val pulsateRange = 0.034f val pulsateRange = 0.034f
val pulsateCycleDuration = 500 // in milliseconds val pulsateCycleDuration: Millisec = 500 // in milliseconds
val random = HQRNG() val random = HQRNG()

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui package net.torvald.terrarum.ui
import net.torvald.terrarum.Millisec
import org.newdawn.slick.GameContainer import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics import org.newdawn.slick.Graphics
import org.newdawn.slick.Input import org.newdawn.slick.Input
@@ -22,7 +23,7 @@ interface UICanvas {
* *
* Timer itself is implemented in the handler. * Timer itself is implemented in the handler.
*/ */
var openCloseTime: Int var openCloseTime: Millisec
fun update(gc: GameContainer, delta: Int) fun update(gc: GameContainer, delta: Int)

View File

@@ -19,8 +19,8 @@ class UIItemTextButton(
override val width: Int, override val width: Int,
val readFromLang: Boolean = false, val readFromLang: Boolean = false,
val activeCol: Color = Color.white, val activeCol: Color = Color.white,
val activeBackCol: Color = Color(0xd0d0d0), val activeBackCol: Color = Color(0,0,0,0),
val activeBackBlendMode: String = BlendMode.MULTIPLY, val activeBackBlendMode: String = BlendMode.NORMAL,
val highlightCol: Color = Color(0x00f8ff), val highlightCol: Color = Color(0x00f8ff),
val highlightBackCol: Color = Color(0xb0b0b0), val highlightBackCol: Color = Color(0xb0b0b0),
val highlightBackBlendMode: String = BlendMode.MULTIPLY, val highlightBackBlendMode: String = BlendMode.MULTIPLY,

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum.ui
import net.torvald.terrarum.BlendMode import net.torvald.terrarum.BlendMode
import net.torvald.terrarum.gameactors.roundInt import net.torvald.terrarum.gameactors.roundInt
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.Millisec
import org.newdawn.slick.Color import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics import org.newdawn.slick.Graphics
@@ -18,50 +19,95 @@ class UIItemTextButtonList(
val readFromLang: Boolean = false, val readFromLang: Boolean = false,
// copied directly from UIItemTextButton // copied directly from UIItemTextButton
activeCol: Color = Color.white, val activeCol: Color = Color.white,
activeBackCol: Color = Color(0xd0d0d0), val activeBackCol: Color = Color(0,0,0,0),
activeBackBlendMode: String = BlendMode.MULTIPLY, val activeBackBlendMode: String = BlendMode.NORMAL,
highlightCol: Color = Color(0x00f8ff), val highlightCol: Color = Color(0x00f8ff),
highlightBackCol: Color = Color(0xb0b0b0), val highlightBackCol: Color = Color(0xb0b0b0),
highlightBackBlendMode: String = BlendMode.MULTIPLY, val highlightBackBlendMode: String = BlendMode.MULTIPLY,
inactiveCol: Color = Color(0xc8c8c8) 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) { ) : UIItem(parentUI) {
val buttons = labelsList.mapIndexed { index, s -> val buttons = labelsList.mapIndexed { index, s ->
val height = this.height - UIItemTextButton.height val height = this.height - UIItemTextButton.height
UIItemTextButton( if (!kinematic) {
parentUI, s, UIItemTextButton(
posX = 0, parentUI, s,
posY = (height / labelsList.size.minus(1).toFloat() * index).roundInt(), posX = 0,
width = width, posY = (height / labelsList.size.minus(1).toFloat() * index).roundInt(),
readFromLang = true, width = width,
activeCol = activeCol, readFromLang = true,
activeBackCol = activeBackCol, activeCol = activeCol,
activeBackBlendMode = activeBackBlendMode, activeBackCol = activeBackCol,
highlightCol = highlightCol, activeBackBlendMode = activeBackBlendMode,
highlightBackCol = highlightBackCol, highlightCol = highlightCol,
highlightBackBlendMode = highlightBackBlendMode, highlightBackCol = highlightBackCol,
inactiveCol = inactiveCol 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 posX = 0
override var posY = 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) { override fun update(gc: GameContainer, delta: Int) {
buttons.forEachIndexed { index, btn -> if (highlighterMoving) {
// update width because Lang is mutable (you can change language at any moment) highlighterMoveTimer += delta
val textW = UIItemTextButton.font.getWidth( highlightY = UIUtils.moveQuick(
if (readFromLang) Lang[btn.labelText] else btn.labelText 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) btn.update(gc, delta)
if (btn.mousePushed) { if (btn.mousePushed && index != selected) {
selected = index 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 btn.highlighted = (index == selected) // forcibly highlight if this.highlighted != null
@@ -69,6 +115,13 @@ class UIItemTextButtonList(
} }
override fun render(gc: GameContainer, g: Graphics) { 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) } buttons.forEach { it.render(gc, g) }
} }

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.ui package net.torvald.terrarum.ui
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.terrarum.Millisec
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import org.dyn4j.geometry.Vector2 import org.dyn4j.geometry.Vector2
@@ -26,7 +27,7 @@ class UIPieMenu : UICanvas {
/** /**
* In milliseconds * In milliseconds
*/ */
override var openCloseTime: Int = 160 override var openCloseTime: Millisec = 160
private val smallenSize = 0.93f private val smallenSize = 0.93f

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui package net.torvald.terrarum.ui
import net.torvald.terrarum.Millisec
import net.torvald.terrarum.Terrarum import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import org.newdawn.slick.GameContainer import org.newdawn.slick.GameContainer
@@ -16,7 +17,7 @@ class UIQuickBar : UICanvas, MouseControlled {
/** /**
* In milliseconds * In milliseconds
*/ */
override var openCloseTime: Int = 160 override var openCloseTime: Millisec = 160
private val startPointX = ItemSlotImageBuilder.slotLarge.width / 2 private val startPointX = ItemSlotImageBuilder.slotLarge.width / 2
private val startPointY = ItemSlotImageBuilder.slotLarge.height / 2 private val startPointY = ItemSlotImageBuilder.slotLarge.height / 2

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

View File

@@ -8,6 +8,7 @@ import org.luaj.vm2.lib.TwoArgFunction
import org.luaj.vm2.lib.ZeroArgFunction import org.luaj.vm2.lib.ZeroArgFunction
import org.luaj.vm2.lib.jse.JsePlatform import org.luaj.vm2.lib.jse.JsePlatform
import net.torvald.terrarum.KVHashMap import net.torvald.terrarum.KVHashMap
import net.torvald.terrarum.Millisec
import net.torvald.terrarum.gameactors.roundInt import net.torvald.terrarum.gameactors.roundInt
import net.torvald.terrarum.virtualcomputer.luaapi.* import net.torvald.terrarum.virtualcomputer.luaapi.*
import net.torvald.terrarum.virtualcomputer.peripheral.* import net.torvald.terrarum.virtualcomputer.peripheral.*
@@ -361,7 +362,7 @@ class TerrarumComputer(peripheralSlots: Int) {
// let's regard it as a tracker... // let's regard it as a tracker...
private val beepQueue = ArrayList<Pair<Int, Double>>() private val beepQueue = ArrayList<Pair<Int, Double>>()
private var beepCursor = -1 private var beepCursor = -1
private var beepQueueLineExecTimer = 0 // millisec private var beepQueueLineExecTimer: Millisec = 0
private var beepQueueFired = false private var beepQueueFired = false
private fun driveBeepQueueManager(delta: Int) { private fun driveBeepQueueManager(delta: Int) {
@@ -432,7 +433,7 @@ class TerrarumComputer(peripheralSlots: Int) {
* *
* ,---. (true, true) ,---- (true, false) ----. (false, true) ----- (false, false) * ,---. (true, true) ,---- (true, false) ----. (false, true) ----- (false, false)
*/ */
private fun makeAudioData(duration: Int, freq: Double, private fun makeAudioData(duration: Millisec, freq: Double,
rampUp: Boolean = true, rampDown: Boolean = true): ByteBuffer { rampUp: Boolean = true, rampDown: Boolean = true): ByteBuffer {
val audioData = BufferUtils.createByteBuffer(duration.times(sampleRate).div(1000)) val audioData = BufferUtils.createByteBuffer(duration.times(sampleRate).div(1000))

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.virtualcomputer.terminal package net.torvald.terrarum.virtualcomputer.terminal
import net.torvald.terrarum.Millisec
import org.newdawn.slick.Color import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics import org.newdawn.slick.Graphics
@@ -61,7 +62,7 @@ interface Terminal : Teletype {
* @param duration: milliseconds * @param duration: milliseconds
* @param freg: Frequency (float) * @param freg: Frequency (float)
*/ */
fun emitTone(duration: Int, freq: Double) fun emitTone(duration: Millisec, freq: Double)
override fun bell(pattern: String) override fun bell(pattern: String)
/** Requires keyPressed() event to be processed. /** Requires keyPressed() event to be processed.

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.virtualcomputer.worldobject.ui package net.torvald.terrarum.virtualcomputer.worldobject.ui
import net.torvald.terrarum.Millisec
import net.torvald.terrarum.ui.* import net.torvald.terrarum.ui.*
import net.torvald.terrarum.ui.UICanvas.Companion.OPENCLOSE_GENERIC import net.torvald.terrarum.ui.UICanvas.Companion.OPENCLOSE_GENERIC
import net.torvald.terrarum.virtualcomputer.terminal.Terminal import net.torvald.terrarum.virtualcomputer.terminal.Terminal
@@ -52,7 +53,7 @@ class UITextTerminal(val terminal: Terminal) : UICanvas, KeyboardControlled, Mou
* *
* Timer itself is implemented in the handler. * Timer itself is implemented in the handler.
*/ */
override var openCloseTime: Int = OPENCLOSE_GENERIC override var openCloseTime: Millisec = OPENCLOSE_GENERIC
override fun update(gc: GameContainer, delta: Int) { override fun update(gc: GameContainer, delta: Int) {
terminal.update(gc, delta) terminal.update(gc, delta)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 124 KiB

After

Width:  |  Height:  |  Size: 155 KiB

Binary file not shown.