mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
catbar and grid: updates and renders as intended
This commit is contained in:
Binary file not shown.
@@ -747,11 +747,11 @@ fun Float.round(): Float {
|
||||
fun SpriteBatch.fillRect(x: Float, y: Float, w: Float, h: Float) {
|
||||
this.draw(Terrarum.textureWhiteSquare, x, y, w, h)
|
||||
}
|
||||
inline fun SpriteBatch.drawStraightLine(x: Float, y: Float, length: Float, thickness: Float, isVertical: Boolean) {
|
||||
inline fun SpriteBatch.drawStraightLine(x: Float, y: Float, otherEnd: Float, thickness: Float, isVertical: Boolean) {
|
||||
if (!isVertical)
|
||||
this.fillRect(x, y, length - x, thickness)
|
||||
this.fillRect(x, y, otherEnd - x, thickness)
|
||||
else
|
||||
this.fillRect(x, y, thickness, length - y)
|
||||
this.fillRect(x, y, thickness, otherEnd - y)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,17 +18,19 @@ class UIItemInventoryCatBar(
|
||||
parentUI: UICanvas,
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
override val width: Int,
|
||||
val catIcons: TextureRegionPack = TextureRegionPack("./assets/graphics/gui/inventory/category.tga", 20, 20),
|
||||
val catArrangement: IntArray = intArrayOf(9,6,7,1,0,2,3,4,5,8)
|
||||
override val width: Int
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
private val catIcons = (parentUI as UIInventoryFull).catIcons
|
||||
private val catArrangement = (parentUI as UIInventoryFull).catArrangement
|
||||
|
||||
|
||||
private val inventoryUI = parentUI
|
||||
override val height = catIcons.tileH + 5
|
||||
|
||||
|
||||
private val buttons: Array<UIItemImageButton>
|
||||
private val buttonGapSize = (width.toFloat() - (catArrangement.size * catIcons.tileW)) / (catArrangement.size + 1f)
|
||||
private val buttonGapSize = (width.toFloat() - (catArrangement.size * catIcons.tileW)) / (catArrangement.size)
|
||||
var selectedIndex = 0 // default to ALL
|
||||
private set
|
||||
val selectedIcon: Int
|
||||
@@ -39,7 +41,7 @@ class UIItemInventoryCatBar(
|
||||
init {
|
||||
// place sub UIs: Image Buttons
|
||||
buttons = Array(catArrangement.size, { index ->
|
||||
val iconPosX = (buttonGapSize + catIcons.tileW).roundInt()
|
||||
val iconPosX = ((buttonGapSize / 2) + index * (catIcons.tileW + buttonGapSize)).roundInt()
|
||||
val iconPosY = 0
|
||||
|
||||
UIItemImageButton(
|
||||
@@ -58,10 +60,12 @@ class UIItemInventoryCatBar(
|
||||
private val underlineIndTex: Texture
|
||||
private val underlineColour = Color(0xeaeaea_40.toInt())
|
||||
private val underlineHighlightColour = buttons[0].highlightCol
|
||||
private var highlighterXStart = 0.0 // left-end position
|
||||
private var highlighterXEnd = 0.0 // left-end position
|
||||
private var highlighterXPos = 0.0 // left-end position
|
||||
private val highlighterYPos = catIcons.tileH + 5f
|
||||
|
||||
private var highlighterXPos = buttons[selectedIndex].posX.toDouble()
|
||||
private var highlighterXStart = highlighterXPos
|
||||
private var highlighterXEnd = highlighterXPos
|
||||
|
||||
private val highlighterYPos = catIcons.tileH + 4f
|
||||
private var highlighterMoving = false
|
||||
private val highlighterMoveDuration: Second = 0.1f
|
||||
private var highlighterMoveTimer: Second = 0f
|
||||
@@ -80,7 +84,10 @@ class UIItemInventoryCatBar(
|
||||
}
|
||||
underlineIndTex = Texture(pixmap)
|
||||
underlineIndTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||
pixmap.dispose() // FIXME is this how it's supposed to work? (still a noob)
|
||||
pixmap.dispose()
|
||||
|
||||
|
||||
buttons[selectedIndex].highlighted = true
|
||||
}
|
||||
|
||||
|
||||
@@ -89,19 +96,17 @@ class UIItemInventoryCatBar(
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
|
||||
|
||||
|
||||
if (highlighterMoving) {
|
||||
highlighterMoveTimer += delta
|
||||
|
||||
if (selectedIndex != null) {
|
||||
highlighterXPos = UIUtils.moveQuick(
|
||||
highlighterXStart,
|
||||
highlighterXEnd,
|
||||
highlighterMoveTimer.toDouble(),
|
||||
highlighterMoveDuration.toDouble()
|
||||
)
|
||||
}
|
||||
highlighterXPos = UIUtils.moveQuick(
|
||||
highlighterXStart,
|
||||
highlighterXEnd,
|
||||
highlighterMoveTimer.toDouble(),
|
||||
highlighterMoveDuration.toDouble()
|
||||
)
|
||||
|
||||
if (highlighterMoveTimer > highlighterMoveDuration) {
|
||||
highlighterMoveTimer = 0f
|
||||
@@ -119,10 +124,10 @@ class UIItemInventoryCatBar(
|
||||
if (btn.mousePushed && index != selectedIndex) {
|
||||
val oldIndex = selectedIndex
|
||||
|
||||
highlighterXStart = buttons[selectedIndex].posY.toDouble()
|
||||
highlighterXStart = buttons[selectedIndex].posX.toDouble() // using old selectedIndex
|
||||
selectedIndex = index
|
||||
highlighterMoving = true
|
||||
highlighterXEnd = buttons[selectedIndex].posY.toDouble()
|
||||
highlighterXEnd = buttons[selectedIndex].posX.toDouble() // using new selectedIndex
|
||||
|
||||
selectionChangeListener?.invoke(oldIndex, index)
|
||||
}
|
||||
@@ -140,11 +145,11 @@ class UIItemInventoryCatBar(
|
||||
|
||||
// underline
|
||||
batch.color = underlineColour
|
||||
batch.drawStraightLine(posX.toFloat(), posY + height - 1f, width.toFloat(), 1f, false)
|
||||
batch.drawStraightLine(posX.toFloat(), posY + height - 1f, posX + width.toFloat(), 1f, false)
|
||||
|
||||
// indicator
|
||||
batch.color = underlineHighlightColour
|
||||
batch.draw(underlineIndTex, (posX + highlighterXPos).toFloat().round(), posY + highlighterYPos)
|
||||
batch.draw(underlineIndTex, (highlighterXPos - buttonGapSize / 2).toFloat().round(), posY + highlighterYPos)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.torvald.terrarum.gameactors.Pocketed
|
||||
import net.torvald.terrarum.gameactors.Second
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import java.util.ArrayList
|
||||
|
||||
/**
|
||||
@@ -32,6 +33,11 @@ class UIInventoryFull(
|
||||
|
||||
|
||||
|
||||
internal val catIcons: TextureRegionPack = TextureRegionPack("./assets/graphics/gui/inventory/category.tga", 20, 20)
|
||||
internal val catArrangement: IntArray = intArrayOf(9,6,7,1,0,2,3,4,5,8)
|
||||
|
||||
|
||||
|
||||
private val SP = "${0x3000.toChar()}${0x3000.toChar()}"
|
||||
val listControlHelp: String
|
||||
get() = if (Terrarum.environment == RunningEnvironment.PC)
|
||||
@@ -50,7 +56,7 @@ class UIInventoryFull(
|
||||
private var isEncumbered = false
|
||||
|
||||
|
||||
val catBarWidth = 328
|
||||
val catBarWidth = 330
|
||||
val catBar = UIItemInventoryCatBar(
|
||||
this,
|
||||
(Terrarum.WIDTH - catBarWidth) / 2,
|
||||
@@ -87,7 +93,8 @@ class UIInventoryFull(
|
||||
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
|
||||
catBar.update(delta)
|
||||
itemList?.update(delta)
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
|
||||
@@ -35,6 +35,7 @@ class UIItemInventoryDynamicList(
|
||||
override val width = 496
|
||||
override val height = 384
|
||||
|
||||
private val catArrangement = parentUI.catArrangement
|
||||
|
||||
|
||||
|
||||
@@ -58,7 +59,7 @@ class UIItemInventoryDynamicList(
|
||||
private val selectedIcon: Int
|
||||
get() = inventoryUI.catSelectedIcon
|
||||
|
||||
private val compactViewCat = setOf(6, 7, 9) // blocks, walls, all (spritesheet order)
|
||||
private val compactViewCat = setOf(4, 6, 7, 9) // potions, blocks, walls, all (spritesheet order)
|
||||
|
||||
var itemPage = 0
|
||||
var itemPageCount = 1 // TODO total size of current category / items.size
|
||||
@@ -106,7 +107,7 @@ class UIItemInventoryDynamicList(
|
||||
)
|
||||
|
||||
private val items: Array<UIItemInventoryCellBase>
|
||||
get() = if (selection in compactViewCat) itemGrid else itemList
|
||||
get() = if (catArrangement[selection] in compactViewCat) itemGrid else itemList
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user