mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
inventory gamemenu visual only
This commit is contained in:
@@ -44,6 +44,25 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
||||
abstract val width: Int
|
||||
abstract val height: Int
|
||||
|
||||
/** This variable is NOT updated on its own.
|
||||
* ```
|
||||
* val posXDelta = posX - oldPosX
|
||||
* itemGrid.forEach { it.posX += posXDelta }
|
||||
* ...
|
||||
* oldPosX = posX
|
||||
* ```
|
||||
*/
|
||||
protected abstract var oldPosX: Int
|
||||
/** This variable is NOT updated on its own.
|
||||
* ```
|
||||
* val posYDelta = posY - oldPosY
|
||||
* itemGrid.forEach { it.posY += posYDelta }
|
||||
* ...
|
||||
* oldPosY = posY
|
||||
* ```
|
||||
*/
|
||||
protected abstract var oldPosY: Int
|
||||
|
||||
/** Position of mouse relative to this item */
|
||||
protected val relativeMouseX: Int
|
||||
get() = (Terrarum.mouseScreenX - (parentUI.posX) - this.posX)
|
||||
|
||||
@@ -35,6 +35,10 @@ open class UIItemImageButton(
|
||||
var highlightable: Boolean
|
||||
) : UIItem(parent) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
override var oldPosY = posY
|
||||
|
||||
var highlighted = false
|
||||
|
||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||
|
||||
@@ -20,6 +20,10 @@ class UIItemImageGallery(
|
||||
val column: Int = 1
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
override var oldPosY = posY
|
||||
|
||||
override fun update(delta: Float) {
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,10 @@ class UIItemIntSlider(
|
||||
)
|
||||
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
override var oldPosY = posY
|
||||
|
||||
var value = initValue
|
||||
|
||||
|
||||
|
||||
@@ -36,6 +36,10 @@ class UIItemList<Item: UIItem>(
|
||||
val border: Int = 0
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
override var oldPosY = posY
|
||||
|
||||
init {
|
||||
itemList.forEachIndexed { index, item ->
|
||||
item.posX = this.posX + border
|
||||
@@ -47,7 +51,7 @@ class UIItemList<Item: UIItem>(
|
||||
var selectedIndex: Int? = defaultSelection
|
||||
val selectedButton: UIItem?
|
||||
get() = if (selectedIndex != null) itemList[selectedIndex!!] else null
|
||||
private var highlightY: Double? = if (selectedIndex != null) itemList[selectedIndex!!].posY.toDouble() else null
|
||||
private var highlightY: Float? = if (selectedIndex != null) itemList[selectedIndex!!].posY.toFloat() else null
|
||||
private val highlighterMoveDuration: Second = 0.1f
|
||||
private var highlighterMoveTimer: Second = 0f
|
||||
private var highlighterMoving = false
|
||||
@@ -66,8 +70,8 @@ class UIItemList<Item: UIItem>(
|
||||
highlightY = UIUtils.moveQuick(
|
||||
highlighterYStart!!,
|
||||
highlighterYEnd!!,
|
||||
highlighterMoveTimer.toDouble(),
|
||||
highlighterMoveDuration.toDouble()
|
||||
highlighterMoveTimer,
|
||||
highlighterMoveDuration
|
||||
)
|
||||
}
|
||||
|
||||
@@ -87,14 +91,14 @@ class UIItemList<Item: UIItem>(
|
||||
val oldIndex = selectedIndex
|
||||
|
||||
if (kinematic) {
|
||||
highlighterYStart = itemList[selectedIndex!!].posY.toDouble()
|
||||
highlighterYStart = itemList[selectedIndex!!].posY.toFloat()
|
||||
selectedIndex = index
|
||||
highlighterMoving = true
|
||||
highlighterYEnd = itemList[selectedIndex!!].posY.toDouble()
|
||||
highlighterYEnd = itemList[selectedIndex!!].posY.toFloat()
|
||||
}
|
||||
else {
|
||||
selectedIndex = index
|
||||
highlightY = itemList[selectedIndex!!].posY.toDouble()
|
||||
highlightY = itemList[selectedIndex!!].posY.toFloat()
|
||||
}
|
||||
|
||||
selectionChangeListener?.invoke(oldIndex, index)
|
||||
|
||||
@@ -17,6 +17,10 @@ class UIItemTextArea(
|
||||
val align: Alignment = Alignment.LEFT
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
override var oldPosY = posY
|
||||
|
||||
private var entireText: List<String> = listOf("") // placeholder
|
||||
|
||||
var scrollPos = 0
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.BlendMode
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
|
||||
/**
|
||||
* Text button. Height of hitbox is extended (double lineHeight, or 40 px) for better clicking
|
||||
@@ -34,6 +37,10 @@ open class UIItemTextButton(
|
||||
val hitboxSize: Int = UIItemTextButton.height
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
override var oldPosY = posY
|
||||
|
||||
companion object {
|
||||
val font = Terrarum.fontGame
|
||||
val height = font.lineHeight.toInt()
|
||||
|
||||
@@ -4,8 +4,8 @@ import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.BlendMode
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.fillRect
|
||||
import net.torvald.terrarum.gameactors.ai.toInt
|
||||
import net.torvald.terrarum.roundInt
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
@@ -45,6 +45,10 @@ class UIItemTextButtonList(
|
||||
val itemHitboxSize: Int = UIItemTextButton.height
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
// deal with the moving position
|
||||
override var oldPosX = posX
|
||||
override var oldPosY = posY
|
||||
|
||||
val iconToTextGap = 20
|
||||
val iconCellWidth = (iconSpriteSheet?.tileW ?: -iconToTextGap) / (iconSpriteSheet?.horizontalCount ?: 1)
|
||||
val iconCellHeight = (iconSpriteSheet?.tileH ?: 0) / (iconSpriteSheet?.verticalCount ?: 1)
|
||||
@@ -130,7 +134,7 @@ class UIItemTextButtonList(
|
||||
var selectedIndex: Int? = defaultSelection
|
||||
val selectedButton: UIItemTextButton?
|
||||
get() = if (selectedIndex != null) buttons[selectedIndex!!] else null
|
||||
private var highlightY: Double? = if (selectedIndex != null) buttons[selectedIndex!!].posY.toDouble() else null
|
||||
private var highlightY: Float? = if (selectedIndex != null) buttons[selectedIndex!!].posY.toFloat() else null
|
||||
private val highlighterMoveDuration: Second = 0.1f
|
||||
private var highlighterMoveTimer: Second = 0f
|
||||
private var highlighterMoving = false
|
||||
@@ -141,6 +145,10 @@ class UIItemTextButtonList(
|
||||
var selectionChangeListener: ((Int?, Int) -> Unit)? = null
|
||||
|
||||
override fun update(delta: Float) {
|
||||
val posXDelta = posX - oldPosX
|
||||
buttons.forEach { it.posX += posXDelta }
|
||||
|
||||
|
||||
if (highlighterMoving) {
|
||||
highlighterMoveTimer += delta
|
||||
|
||||
@@ -148,8 +156,8 @@ class UIItemTextButtonList(
|
||||
highlightY = UIUtils.moveQuick(
|
||||
highlighterYStart!!,
|
||||
highlighterYEnd!!,
|
||||
highlighterMoveTimer.toDouble(),
|
||||
highlighterMoveDuration.toDouble()
|
||||
highlighterMoveTimer.toFloat(),
|
||||
highlighterMoveDuration.toFloat()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -170,13 +178,13 @@ class UIItemTextButtonList(
|
||||
|
||||
if (kinematic) {
|
||||
selectedIndex = index
|
||||
highlighterYStart = buttons[selectedIndex!!].posY.toDouble()
|
||||
highlighterYStart = buttons[selectedIndex!!].posY.toFloat()
|
||||
highlighterMoving = true
|
||||
highlighterYEnd = buttons[selectedIndex!!].posY.toDouble()
|
||||
highlighterYEnd = buttons[selectedIndex!!].posY.toFloat()
|
||||
}
|
||||
else {
|
||||
selectedIndex = index
|
||||
highlightY = buttons[selectedIndex!!].posY.toDouble()
|
||||
highlightY = buttons[selectedIndex!!].posY.toFloat()
|
||||
}
|
||||
|
||||
selectionChangeListener?.invoke(oldIndex, index)
|
||||
@@ -184,6 +192,8 @@ class UIItemTextButtonList(
|
||||
btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
|
||||
|
||||
}
|
||||
|
||||
oldPosX = posX
|
||||
}
|
||||
|
||||
override fun render(batch: SpriteBatch, camera: Camera) {
|
||||
|
||||
@@ -6,6 +6,6 @@ import net.torvald.terrarum.sqr
|
||||
* Created by minjaesong on 2017-03-14.
|
||||
*/
|
||||
object UIUtils {
|
||||
fun moveQuick(start: Double, end: Double, timer: Double, duration: Double) =
|
||||
fun moveQuick(start: Float, end: Float, timer: Float, duration: Float) =
|
||||
(start - end) * ((timer / duration) - 1).sqr() + end
|
||||
}
|
||||
Reference in New Issue
Block a user