mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-17 14:04:05 +09:00
inventory ui update
This commit is contained in:
@@ -29,6 +29,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
||||
* Sorted by referenceID.
|
||||
*/
|
||||
private val itemList = ArrayList<InventoryPair>()
|
||||
|
||||
init {
|
||||
}
|
||||
|
||||
@@ -135,8 +136,8 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
||||
|
||||
|
||||
|
||||
fun hasItem(item: InventoryItem) = hasItem(item.id)
|
||||
fun hasItem(id: Int) =
|
||||
fun contains(item: InventoryItem) = contains(item.id)
|
||||
fun contains(id: Int) =
|
||||
if (itemList.size == 0)
|
||||
false
|
||||
else
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.gameactors.faction.FactionFactory
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.tileproperties.Tile
|
||||
import net.torvald.terrarum.to10bit
|
||||
import net.torvald.terrarum.toInt
|
||||
import org.newdawn.slick.Color
|
||||
@@ -75,8 +76,15 @@ object PlayerBuilderSigrid {
|
||||
|
||||
|
||||
// Test fill up inventory
|
||||
p.inventory.add(16, 512)
|
||||
p.equipItem(ItemCodex[16])
|
||||
val tiles = arrayOf(
|
||||
Tile.AIR, Tile.DIRT, Tile.GLASS_CRUDE,
|
||||
Tile.GRASS, Tile.GRAVEL, Tile.ICE_MAGICAL, Tile.LANTERN,
|
||||
Tile.PLANK_BIRCH, Tile.PLANK_BLOODROSE, Tile.PLANK_EBONY, Tile.PLANK_NORMAL,
|
||||
Tile.SANDSTONE, Tile.SANDSTONE_BLACK, Tile.SANDSTONE_GREEN,
|
||||
Tile.SANDSTONE_RED, Tile.STONE, Tile.STONE_BRICKS,
|
||||
Tile.STONE_QUARRIED, Tile.STONE_TILE_WHITE, Tile.TORCH
|
||||
)
|
||||
tiles.forEach { p.inventory.add(it, 999) }
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameitem.InventoryItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@@ -18,7 +19,7 @@ interface Pocketed {
|
||||
if (item.equipPosition == InventoryItem.EquipPosition.NULL)
|
||||
throw Error("Unequipping the item that cannot be equipped")
|
||||
|
||||
if (!inventory.hasItem(item))
|
||||
if (!inventory.contains(item))
|
||||
throw Error("Unequipping the item that does not exist in inventory")
|
||||
|
||||
inventory.itemEquipped[item.equipPosition] = null
|
||||
@@ -29,7 +30,7 @@ interface Pocketed {
|
||||
* Equips an item. If the item is not in the inventory, adds the item first.
|
||||
*/
|
||||
fun equipItem(item: InventoryItem) {
|
||||
if (!inventory.hasItem(item))
|
||||
if (!inventory.contains(item))
|
||||
inventory.add(item)
|
||||
|
||||
if (item.equipPosition >= 0) {
|
||||
@@ -38,10 +39,17 @@ interface Pocketed {
|
||||
}
|
||||
}
|
||||
|
||||
fun isEquipped(item: InventoryItem): Boolean {
|
||||
fun equipped(item: InventoryItem): Boolean {
|
||||
return inventory.itemEquipped[item.equipPosition] == item
|
||||
}
|
||||
|
||||
fun addItem(itemID: Int, count: Int = 1) = inventory.add(ItemCodex[itemID], count)
|
||||
fun addItem(item: InventoryItem, count: Int = 1) = inventory.add(item, count)
|
||||
fun removeItem(itemID: Int, count: Int = 1) = inventory.remove(ItemCodex[itemID], count)
|
||||
fun removeItem(item: InventoryItem, count: Int = 1) = inventory.remove(item, count)
|
||||
|
||||
fun hasItem(item: InventoryItem) = inventory.contains(item.id)
|
||||
fun hasItem(id: Int) = inventory.contains(id)
|
||||
|
||||
|
||||
fun consumePrimary(item: InventoryItem) {
|
||||
|
||||
@@ -16,7 +16,7 @@ class ThreadActorUpdate(val startIndex: Int, val endIndex: Int,
|
||||
if (it is Pocketed) {
|
||||
it.inventory.forEach { inventoryEntry ->
|
||||
inventoryEntry.item.effectWhileInPocket(gc, delta)
|
||||
if (it.isEquipped(inventoryEntry.item)) {
|
||||
if (it.equipped(inventoryEntry.item)) {
|
||||
inventoryEntry.item.effectWhenEquipped(gc, delta)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user