From 341d5e696c77f4bccf652d029e56aea2622c866e Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sat, 28 Oct 2017 15:07:58 +0900 Subject: [PATCH] working "equipped" view with unequip --- .../terrarum-sans-bitmap/ascii_variable.tga | 2 +- .../terrarum/gameactors/ActorInventory.kt | 2 +- .../torvald/terrarum/imagefont/TinyAlphNum.kt | 4 + .../torvald/terrarum/ui/UIInventoryFull.kt | 47 ++++- .../ui/UIItemInventoryEquippedView.kt | 163 ++++++++++++++++++ work_files/UI/inventory_nouveau_2.psd | 4 +- work_files/graphics/fonts/ascii_variable.psd | 4 +- 7 files changed, 212 insertions(+), 14 deletions(-) create mode 100644 src/net/torvald/terrarum/ui/UIItemInventoryEquippedView.kt diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/ascii_variable.tga b/assets/graphics/fonts/terrarum-sans-bitmap/ascii_variable.tga index cb0fc1aa9..0d7f00f14 100644 --- a/assets/graphics/fonts/terrarum-sans-bitmap/ascii_variable.tga +++ b/assets/graphics/fonts/terrarum-sans-bitmap/ascii_variable.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ea628ce55158bd3e650b36f0be6ed6d935881930302e036007608f9c85ec977e +oid sha256:50588210227daf6e621f931b6d81f9f8ac8a297f7e79d1cab2f0c479fa42c033 size 327724 diff --git a/src/net/torvald/terrarum/gameactors/ActorInventory.kt b/src/net/torvald/terrarum/gameactors/ActorInventory.kt index 04700bceb..3101fbdc1 100644 --- a/src/net/torvald/terrarum/gameactors/ActorInventory.kt +++ b/src/net/torvald/terrarum/gameactors/ActorInventory.kt @@ -57,7 +57,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode if (count == 0) throw IllegalArgumentException("Item count is zero.") if (count < 0) - throw IllegalArgumentException("Item count is negative number. If you intended removing items, use remove()" + + throw IllegalArgumentException("Item count is negative number. If you intended removing items, use remove()\n" + "These commands are NOT INTERCHANGEABLE; they handle things differently according to the context.") if (item.originalID == Player.PLAYER_REF_ID || item.originalID == 0x51621D) // do not delete this magic throw IllegalArgumentException("Attempted to put human player into the inventory.") diff --git a/src/net/torvald/terrarum/imagefont/TinyAlphNum.kt b/src/net/torvald/terrarum/imagefont/TinyAlphNum.kt index bd461d5bd..8e9008dcc 100644 --- a/src/net/torvald/terrarum/imagefont/TinyAlphNum.kt +++ b/src/net/torvald/terrarum/imagefont/TinyAlphNum.kt @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.graphics.g2d.BitmapFont import com.badlogic.gdx.graphics.g2d.GlyphLayout +import net.torvald.terrarum.round import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack /** @@ -32,6 +33,9 @@ object TinyAlphNum : BitmapFont() { val originalColour = batch.color colourHolder = batch.color + val x = x.round() + val y = y.round() + var charsPrinted = 0 text.forEachIndexed { index, c -> if (isColourCodeHigh(c)) { diff --git a/src/net/torvald/terrarum/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/ui/UIInventoryFull.kt index 434b54374..77d9d4986 100644 --- a/src/net/torvald/terrarum/ui/UIInventoryFull.kt +++ b/src/net/torvald/terrarum/ui/UIInventoryFull.kt @@ -2,11 +2,11 @@ package net.torvald.terrarum.ui import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.Camera +import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.g2d.SpriteBatch -import net.torvald.terrarum.RunningEnvironment -import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.UIItemInventoryCatBar +import net.torvald.terrarum.* +import net.torvald.terrarum.gameactors.ActorWithPhysics import net.torvald.terrarum.gameactors.InventoryPair import net.torvald.terrarum.gameactors.Pocketed import net.torvald.terrarum.gameactors.Second @@ -43,7 +43,7 @@ class UIInventoryFull( private val SP = "${0x3000.toChar()}${0x3000.toChar()}" val listControlHelp: String get() = if (Terrarum.environment == RunningEnvironment.PC) - "${0xe037.toChar()} ${Lang["GAME_ACTION_CLOSE"]}$SP" + + "${0xe031.toChar()} ${Lang["GAME_ACTION_CLOSE"]}$SP" + "${0xe006.toChar()} ${Lang["GAME_INVENTORY_USE"]}$SP" + "${0xe011.toChar()}..${0xe010.toChar()} ${Lang["GAME_INVENTORY_REGISTER"]}$SP" + "${0xe034.toChar()} ${Lang["GAME_INVENTORY_DROP"]}" @@ -52,7 +52,7 @@ class UIInventoryFull( "${Terrarum.joypadLabelNinY} ${Lang["GAME_INVENTORY_USE"]}$SP" + "${0xe011.toChar()}${0xe010.toChar()} ${Lang["GAME_INVENTORY_REGISTER"]}$SP" + "${Terrarum.joypadLabelNinA} ${Lang["GAME_INVENTORY_DROP"]}" - val controlHelpHeight = Terrarum.fontGame.lineHeight.toInt() + val controlHelpHeight = Terrarum.fontGame.lineHeight private var encumbrancePerc = 0f private var isEncumbered = false @@ -85,11 +85,24 @@ class UIInventoryFull( else null + private val equipped: UIItemInventoryEquippedView? = + if (actor != null) { + UIItemInventoryEquippedView( + this, + actor!!.inventory, + actor as ActorWithPhysics, + internalWidth - UIItemInventoryEquippedView.width + (Terrarum.WIDTH - internalWidth) / 2, + 109 + (Terrarum.HEIGHT - internalHeight) / 2 + ) + } + else null + + + init { addItem(catBar) - itemList?.let { - addItem(it) - } + itemList?.let { addItem(it) } + equipped?.let { addItem(it) } catBar.selectionChangeListener = { old, new -> rebuildList() } @@ -97,8 +110,13 @@ class UIInventoryFull( rebuildList() + } + private var offsetX = ((Terrarum.WIDTH - internalWidth) / 2).toFloat() + private var offsetY = ((Terrarum.HEIGHT - internalHeight) / 2).toFloat() + + override fun updateUI(delta: Float) { if (handler.openFired) { @@ -108,22 +126,32 @@ class UIInventoryFull( catBar.update(delta) itemList?.update(delta) + equipped?.update(delta) } override fun renderUI(batch: SpriteBatch, camera: Camera) { catBar.render(batch, camera) itemList?.render(batch, camera) + equipped?.render(batch, camera) + + + // control hints + blendNormal(batch) + batch.color = Color.WHITE + Terrarum.fontGame.draw(batch, listControlHelp, offsetX, offsetY + internalHeight + controlHelpHeight) } fun rebuildList() { itemList?.rebuild() + equipped?.rebuild() } override fun dispose() { catBar.dispose() itemList?.dispose() + equipped?.dispose() } @@ -144,6 +172,9 @@ class UIInventoryFull( override fun resize(width: Int, height: Int) { super.resize(width, height) + + offsetX = ((Terrarum.WIDTH - internalWidth) / 2).toFloat() + offsetY = ((Terrarum.HEIGHT - internalHeight) / 2).toFloat() } diff --git a/src/net/torvald/terrarum/ui/UIItemInventoryEquippedView.kt b/src/net/torvald/terrarum/ui/UIItemInventoryEquippedView.kt new file mode 100644 index 000000000..a778c9867 --- /dev/null +++ b/src/net/torvald/terrarum/ui/UIItemInventoryEquippedView.kt @@ -0,0 +1,163 @@ +package net.torvald.terrarum.ui + +import com.badlogic.gdx.graphics.Camera +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.terrarum.* +import net.torvald.terrarum.gameactors.ActorInventory +import net.torvald.terrarum.gameactors.ActorWithPhysics +import net.torvald.terrarum.gameactors.InventoryPair +import net.torvald.terrarum.itemproperties.GameItem +import net.torvald.terrarum.itemproperties.ItemCodex +import java.util.ArrayList + +/** + * Created by minjaesong on 2017-10-28. + */ +class UIItemInventoryEquippedView( + parentUI: UIInventoryFull, + val inventory: ActorInventory, + val theActor: ActorWithPhysics, + override var posX: Int, + override var posY: Int +) : UIItem(parentUI) { + + override val width = 104 + override val height = 384 + + companion object { + val width = 104 + val height = 384 + } + + private val listGap = 8 + + var itemPage = 0 + var itemPageCount = 1 // TODO total size of current category / itemGrid.size + + lateinit var inventorySortList: Array + private var rebuildList = true + + val spriteViewBackCol = Color(0xd4d4d4_ff.toInt()) + + private val itemGrid = Array( + 2 * 5, { + UIItemInventoryElemSimple( + parentUI = parentUI, + posX = this.posX + (UIItemInventoryElemSimple.height + listGap) * ((it + 4) % 2), + posY = this.posY + (UIItemInventoryElemSimple.height + listGap) * ((it + 4) / 2), + item = null, + amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT, + itemImage = null, + mouseoverBackCol = Color(0x282828_ff), + mouseoverBackBlendMode = BlendMode.SCREEN, + backCol = Color(0xd4d4d4_ff.toInt()), + backBlendMode = BlendMode.MULTIPLY, + drawBackOnNull = true + ) + } + ) + + + override fun update(delta: Float) { + itemGrid.forEach { it.update(delta) } + } + + override fun render(batch: SpriteBatch, camera: Camera) { + // sprite background + batch.color = spriteViewBackCol + batch.fillRect( + posX.toFloat(), posY.toFloat(), + width.toFloat(), width.toFloat() + ) + + // sprite + val sprite = theActor.sprite + sprite?.let { + blendNormal(batch) + + it.render( + batch, + posX + (width - it.cellWidth).div(2).toFloat(), + posY + (width - it.cellHeight).div(2).toFloat() + ) } + + + itemGrid.forEach { it.render(batch, camera) } + } + + + internal fun rebuild() { + inventorySortList = inventory.itemEquipped.clone() + + + + rebuildList = false + + // TODO sort if needed + + + // fill the grid from fastest index, make no gap in-between of slots + var listPushCnt = 0 + for (k in 0 until itemGrid.size) { + val it = inventorySortList[k] + + if (it != null) { + val itemRecord = inventory.getByDynamicID(it.dynamicID)!! + + itemGrid[listPushCnt].item = it + itemGrid[listPushCnt].amount = itemRecord.amount + itemGrid[listPushCnt].itemImage = ItemCodex.getItemImage(it) + itemGrid[listPushCnt].quickslot = null // don't need to be displayed + itemGrid[listPushCnt].equippedSlot = null // don't need to be displayed + + listPushCnt++ + } + } + + // empty out un-filled grids from previous garbage + for (m in listPushCnt until itemGrid.size) { + itemGrid[m].item = null + itemGrid[m].amount = 0 + itemGrid[m].itemImage = null + itemGrid[m].quickslot = null + itemGrid[m].equippedSlot = null + } + } + + + override fun dispose() { + itemGrid.forEach { it.dispose() } + } + + override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { + super.touchDown(screenX, screenY, pointer, button) + + itemGrid.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) } + return true + } + + override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { + itemGrid.forEach { if (it.mouseUp) it.touchUp(screenX, screenY, pointer, button) } + + return true + } + + override fun keyDown(keycode: Int): Boolean { + super.keyDown(keycode) + + itemGrid.forEach { if (it.mouseUp) it.keyDown(keycode) } + rebuild() + + return true + } + + override fun keyUp(keycode: Int): Boolean { + super.keyUp(keycode) + + itemGrid.forEach { if (it.mouseUp) it.keyUp(keycode) } + rebuild() + + return true + } +} \ No newline at end of file diff --git a/work_files/UI/inventory_nouveau_2.psd b/work_files/UI/inventory_nouveau_2.psd index 9a8581318..f43a06640 100644 --- a/work_files/UI/inventory_nouveau_2.psd +++ b/work_files/UI/inventory_nouveau_2.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d976f2e4c8b98076af04a44ab5b1fdc8a98f78af04ad4f5b78d02709c3942e0a -size 3037848 +oid sha256:599e04f02c2f046a6c84c26c6778d90616c1c0473ce1a2b2c9af9142bc161ae6 +size 3049902 diff --git a/work_files/graphics/fonts/ascii_variable.psd b/work_files/graphics/fonts/ascii_variable.psd index 94ab16a82..3c66dfe6b 100644 --- a/work_files/graphics/fonts/ascii_variable.psd +++ b/work_files/graphics/fonts/ascii_variable.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:41de48ba2d59d01d1216315a82ae40f3d683a8d08ab00aa23bd6b790dd67a41f -size 327047 +oid sha256:76c1c6ef2f1135e8039beca7008efff75987b1636e28fa810be82623edf3ac0b +size 327049