From d1f3a491f1d56f14cb21017e489ec6bfc5b3723d Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 24 Oct 2017 00:21:13 +0900 Subject: [PATCH] catbar and grid: updates and renders as intended --- assets/graphics/gui/inventory/category.tga | 2 +- src/net/torvald/terrarum/Terrarum.kt | 6 +-- .../torvald/terrarum/UIItemInventoryCatBar.kt | 51 ++++++++++--------- .../torvald/terrarum/ui/UIInventoryFull.kt | 11 +++- .../terrarum/ui/UIItemInventoryDynamicList.kt | 5 +- 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/assets/graphics/gui/inventory/category.tga b/assets/graphics/gui/inventory/category.tga index defa15991..86dc2ff22 100644 --- a/assets/graphics/gui/inventory/category.tga +++ b/assets/graphics/gui/inventory/category.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:38ecfb0754a6263d4fdc4669a36409e91c415f6a63d2e486fca8401c200deda5 +oid sha256:84d51489fad142e1f47cc8d70452d8325b333ed8e52e520bf5b345b494e96950 size 25644 diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index f005f4214..fb9a85a95 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -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) } diff --git a/src/net/torvald/terrarum/UIItemInventoryCatBar.kt b/src/net/torvald/terrarum/UIItemInventoryCatBar.kt index d06bcb819..647b03f8b 100644 --- a/src/net/torvald/terrarum/UIItemInventoryCatBar.kt +++ b/src/net/torvald/terrarum/UIItemInventoryCatBar.kt @@ -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 - 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) } diff --git a/src/net/torvald/terrarum/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/ui/UIInventoryFull.kt index 6d19cdcbd..5f5caf870 100644 --- a/src/net/torvald/terrarum/ui/UIInventoryFull.kt +++ b/src/net/torvald/terrarum/ui/UIInventoryFull.kt @@ -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) { diff --git a/src/net/torvald/terrarum/ui/UIItemInventoryDynamicList.kt b/src/net/torvald/terrarum/ui/UIItemInventoryDynamicList.kt index ebd1af1e9..5da035cea 100644 --- a/src/net/torvald/terrarum/ui/UIItemInventoryDynamicList.kt +++ b/src/net/torvald/terrarum/ui/UIItemInventoryDynamicList.kt @@ -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 - get() = if (selection in compactViewCat) itemGrid else itemList + get() = if (catArrangement[selection] in compactViewCat) itemGrid else itemList