diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemFileRef.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemFileRef.kt index 7271fbbb1..d538cd6fa 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemFileRef.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemFileRef.kt @@ -60,7 +60,7 @@ open class ItemFileRef(originalID: ItemID) : GameItem(originalID) { override var baseMass = 1.0 override var baseToolSize: Double? = null override var inventoryCategory = Category.GENERIC - override val isDynamic = true + override val isDynamic = false override val materialId = "" override var equipPosition = EquipPosition.HAND_GRIP } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt index 4cc048160..2e90410b6 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt @@ -61,8 +61,10 @@ abstract class UIItemInventoryCellBase( } override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { - touchDownFun(item, amount, button, extraInfo, this) - super.touchDown(screenX, screenY, pointer, button) + if (mouseUp) { + touchDownFun(item, amount, button, extraInfo, this) + super.touchDown(screenX, screenY, pointer, button) + } return true } } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt index ce4e6f141..d2e48305d 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt @@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.* +import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.ui.UIItemCatBar.Companion.CAT_ALL import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameitems.GameItem diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIJukeboxInventory.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIJukeboxInventory.kt index 1d61f6af2..82be33b7c 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIJukeboxInventory.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIJukeboxInventory.kt @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.* +import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair @@ -30,8 +31,8 @@ class UIJukeboxInventory(val parent: UIJukebox) : UICanvas() { private val playerInventory: ActorInventory get() = INGAME.actorNowPlaying!!.inventory - private val fixtureDiscCell: List = (0 until SLOT_SIZE).map { index -> - UIItemJukeboxSonglist(this, + private val fixtureDiscCell: Array = (0 until SLOT_SIZE).map { index -> + UIItemInventoryElemWide(this, thisOffsetX, thisOffsetY + (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap) * index, 6 * UIItemInventoryElemSimple.height + 5 * UIItemInventoryItemGrid.listGap, keyDownFun = { _, _, _, _, _ -> Unit }, @@ -39,25 +40,29 @@ class UIJukeboxInventory(val parent: UIJukebox) : UICanvas() { if (mouseButton == App.getConfigInt("config_mouseprimary")) { if (gameItem != null) { parent.discInventory[index] = null - playerInventory.add(gameItem, 1) + playerInventory.add(gameItem) // shift discs for (i in index + 1 until SLOT_SIZE) { parent.discInventory[i - 1] = parent.discInventory[i] } parent.discInventory[SLOT_SIZE - 1] = null + + rebuild() } } }, ) - } + }.toTypedArray() private val playerInventoryUI = UITemplateHalfInventory(this, false).also { it.itemListTouchDownFun = { gameItem, _, _, _, _ -> - if (currentFreeSlot < SLOT_SIZE) { - fixtureDiscCell[currentFreeSlot].title = (gameItem as ItemFileRef).name - fixtureDiscCell[currentFreeSlot].artist = (gameItem as ItemFileRef).author + if (currentFreeSlot < SLOT_SIZE && gameItem != null) { + fixtureDiscCell[currentFreeSlot].item = gameItem + playerInventory.remove(gameItem) currentFreeSlot += 1 + + rebuild() } } } @@ -77,7 +82,7 @@ class UIJukeboxInventory(val parent: UIJukebox) : UICanvas() { override fun show() { super.show() - playerInventoryUI.rebuild(playerInventoryFilterFun) + rebuild() } override fun updateUI(delta: Float) { @@ -91,7 +96,9 @@ class UIJukeboxInventory(val parent: UIJukebox) : UICanvas() { override fun dispose() { } - + private fun rebuild() { + playerInventoryUI.rebuild(playerInventoryFilterFun) + } } @@ -113,10 +120,19 @@ class UIJukeboxSonglistPanel(val parent: UIJukebox) : UICanvas() { cellBackgroundCol = Color(0x704c20c8.toInt()) ) + private val rows = SLOT_SIZE / 2 + private val vgap = 48 + private val internalHeight = (UIItemJukeboxSonglist.height + vgap) * (rows - 1) + + private val ys = (0 until rows).map { + App.scr.halfh - (internalHeight / 2) + (UIItemJukeboxSonglist.height + vgap) * it + } + + private val jukeboxPlayButtons = (0 until SLOT_SIZE).map { index -> UIItemJukeboxSonglist(this, if (index % 2 == 0) thisOffsetX else thisOffsetX2, - thisOffsetY + (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap) * index.shr(1), + ys[index.shr(1)], 6 * UIItemInventoryElemSimple.height + 5 * UIItemInventoryItemGrid.listGap, colourTheme = songButtonColourTheme, keyDownFun = { _, _, _, _, _ -> Unit }, @@ -126,18 +142,23 @@ class UIJukeboxSonglistPanel(val parent: UIJukebox) : UICanvas() { } } ) - } + }.toTypedArray() fun rebuild() { jukeboxPlayButtons.forEachIndexed { index, button -> parent.discInventory[index].let { val item = ItemCodex[it] as? ItemFileRef - button.title = item?.name ?: "" - button.artist = item?.author ?: "" + button.title = "${index+1} ${item?.name}"// ?: "" + button.artist = "${index+1} ${item?.author}"// ?: "" } } } + override fun show() { + super.show() + rebuild() + } + init { jukeboxPlayButtons.forEach { addUIitem(it) diff --git a/src/net/torvald/terrarum/ui/UIItemInventoryElemSimple.kt b/src/net/torvald/terrarum/ui/UIItemInventoryElemSimple.kt index d7671f21a..6f9690fe7 100644 --- a/src/net/torvald/terrarum/ui/UIItemInventoryElemSimple.kt +++ b/src/net/torvald/terrarum/ui/UIItemInventoryElemSimple.kt @@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion import net.torvald.terrarum.App +import net.torvald.terrarum.CommonResourcePool import net.torvald.terrarum.blendNormalStraightAlpha import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.modulebasegame.ui.InventoryCellColourTheme @@ -42,10 +43,13 @@ class UIItemInventoryElemSimple( override val width = Companion.height override val height = Companion.height + private val itemImageOrDefault: TextureRegion + get() = itemImage ?: CommonResourcePool.getAsTextureRegion("itemplaceholder_16") + private val imgOffsetY: Float - get() = (this.height - itemImage!!.regionHeight).div(2).toFloat() // to snap to the pixel grid + get() = (this.height - itemImageOrDefault.regionHeight).div(2).toFloat() // to snap to the pixel grid private val imgOffsetX: Float - get() = (this.height - itemImage!!.regionWidth).div(2).toFloat() // to snap to the pixel grid + get() = (this.height - itemImageOrDefault.regionWidth).div(2).toFloat() // to snap to the pixel grid override fun update(delta: Float) { @@ -76,11 +80,11 @@ class UIItemInventoryElemSimple( // quickslot and equipped slot indicator is not needed as it's intended for blocks and walls // and you can clearly see the quickslot UI anyway - if (item != null && itemImage != null) { + if (item != null) { // item image batch.color = Color.WHITE - batch.draw(itemImage, posX + imgOffsetX, posY + imgOffsetY) + batch.draw(itemImageOrDefault, posX + imgOffsetX, posY + imgOffsetY) diff --git a/src/net/torvald/terrarum/ui/UIItemInventoryElemWide.kt b/src/net/torvald/terrarum/ui/UIItemInventoryElemWide.kt index eeeaa20de..ecaea8459 100644 --- a/src/net/torvald/terrarum/ui/UIItemInventoryElemWide.kt +++ b/src/net/torvald/terrarum/ui/UIItemInventoryElemWide.kt @@ -5,6 +5,8 @@ import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion import net.torvald.terrarum.App +import net.torvald.terrarum.App.printdbg +import net.torvald.terrarum.CommonResourcePool import net.torvald.terrarum.blendNormalStraightAlpha import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.modulebasegame.ui.InventoryCellColourTheme @@ -46,10 +48,13 @@ class UIItemInventoryElemWide( override val height = Companion.height + private val itemImageOrDefault: TextureRegion + get() = itemImage ?: CommonResourcePool.getAsTextureRegion("itemplaceholder_16") + private val imgOffsetY: Float - get() = (this.height - itemImage!!.regionHeight).div(2).toFloat() // to snap to the pixel grid + get() = (this.height - itemImageOrDefault.regionHeight).div(2).toFloat() // to snap to the pixel grid private val imgOffsetX: Float - get() = (this.height - itemImage!!.regionWidth).div(2).toFloat() // NOTE we're using this.height to get horizontal value; this is absofreakinlutely intentional (otherwise images would draw center of this wide cell which is not something we want) + get() = (this.height - itemImageOrDefault.regionWidth).div(2).toFloat() // NOTE we're using this.height to get horizontal value; this is absofreakinlutely intentional (otherwise images would draw center of this wide cell which is not something we want) private val textOffsetX = 50f private val textOffsetY = 8f @@ -88,14 +93,14 @@ class UIItemInventoryElemWide( Toolkit.drawBoxBorder(batch, posX, posY, width, height) - if (item != null && itemImage != null) { + if (item != null) { val amountString = amount.toItemCountText() blendNormalStraightAlpha(batch) // item image batch.color = Color.WHITE - batch.draw(itemImage, posX + imgOffsetX, posY + imgOffsetY) + batch.draw(itemImageOrDefault, posX + imgOffsetX, posY + imgOffsetY) // if mouse is over, text lights up // highlight item name and count (blocks/walls) if the item is equipped