mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
working "equipped" view with unequip
This commit is contained in:
Binary file not shown.
@@ -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.")
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
|
||||
163
src/net/torvald/terrarum/ui/UIItemInventoryEquippedView.kt
Normal file
163
src/net/torvald/terrarum/ui/UIItemInventoryEquippedView.kt
Normal file
@@ -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<GameItem?>
|
||||
private var rebuildList = true
|
||||
|
||||
val spriteViewBackCol = Color(0xd4d4d4_ff.toInt())
|
||||
|
||||
private val itemGrid = Array<UIItemInventoryCellBase>(
|
||||
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
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user