inventory ui: getting actor is now dynamic

This commit is contained in:
minjaesong
2021-08-28 17:10:36 +09:00
parent b84a0a770b
commit 043bd3a1db
4 changed files with 34 additions and 34 deletions

View File

@@ -136,7 +136,7 @@ internal class UIStorageChest : UICanvas(
itemListChest = UIItemInventoryItemGrid(
this,
catBar,
getFixtureInventory(),
{ getFixtureInventory() },
INVENTORY_CELLS_OFFSET_X - halfSlotOffset,
INVENTORY_CELLS_OFFSET_Y,
6, CELLS_VRT,
@@ -153,7 +153,7 @@ internal class UIStorageChest : UICanvas(
itemListPlayer = UIItemInventoryItemGrid(
this,
catBar,
Terrarum.ingame!!.actorNowPlaying!!.inventory, // literally a player's inventory
{ Terrarum.ingame!!.actorNowPlaying!!.inventory }, // literally a player's inventory
INVENTORY_CELLS_OFFSET_X - halfSlotOffset + (listGap + UIItemInventoryElem.height) * 7,
INVENTORY_CELLS_OFFSET_Y,
6, CELLS_VRT,

View File

@@ -41,7 +41,7 @@ internal class UIInventoryCells(
UIItemInventoryItemGrid(
full,
full.catBar,
full.actor.inventory,
{ full.actor.inventory },
INVENTORY_CELLS_OFFSET_X,
INVENTORY_CELLS_OFFSET_Y,
CELLS_HOR, CELLS_VRT,
@@ -53,8 +53,6 @@ internal class UIInventoryCells(
private val equipped: UIItemInventoryEquippedView =
UIItemInventoryEquippedView(
full,
full.actor.inventory,
full.actor as ActorWithBody,
internalWidth - UIItemInventoryEquippedView.WIDTH + (AppLoader.screenSize.screenW - internalWidth) / 2,
INVENTORY_CELLS_OFFSET_Y,
{ rebuildList() }

View File

@@ -23,8 +23,6 @@ import net.torvald.terrarum.ui.UIItem
*/
class UIItemInventoryEquippedView(
parentUI: UICanvas,
val inventory: ActorInventory,
val theActor: ActorWithBody,
initialX: Int,
initialY: Int,
inventoryListRebuildFun: () -> Unit
@@ -92,7 +90,7 @@ class UIItemInventoryEquippedView(
// sprite
val sprite = theActor.sprite
val sprite = Terrarum.ingame!!.actorNowPlaying?.sprite
sprite?.let {
blendNormal(batch)
@@ -121,28 +119,30 @@ class UIItemInventoryEquippedView(
internal fun rebuild() {
rebuildList = false
// sort by equip position
Terrarum.ingame!!.actorNowPlaying?.inventory?.let {
// sort by equip position
// fill the grid from fastest index, make no gap in-between of slots
for (k in itemGrid.indices) {
val item = inventory.itemEquipped[k]
// fill the grid from fastest index, make no gap in-between of slots
for (k in itemGrid.indices) {
val item = it.itemEquipped[k]
if (item == null) {
if (item == null) {
itemGrid[k].item = null
itemGrid[k].amount = 0
itemGrid[k].itemImage = null
itemGrid[k].quickslot = null
itemGrid[k].equippedSlot = null
}
else {
val itemRecord = inventory.invSearchByDynamicID(item)!!
itemGrid[k].item = null
itemGrid[k].amount = 0
itemGrid[k].itemImage = null
itemGrid[k].quickslot = null
itemGrid[k].equippedSlot = null
}
else {
val itemRecord = it.invSearchByDynamicID(item)!!
itemGrid[k].item = ItemCodex[item]
itemGrid[k].amount = itemRecord.qty
itemGrid[k].itemImage = ItemCodex.getItemImage(item)
itemGrid[k].quickslot = null // don't need to be displayed
itemGrid[k].equippedSlot = null // don't need to be displayed
itemGrid[k].item = ItemCodex[item]
itemGrid[k].amount = itemRecord.qty
itemGrid[k].itemImage = ItemCodex.getItemImage(item)
itemGrid[k].quickslot = null // don't need to be displayed
itemGrid[k].equippedSlot = null // don't need to be displayed
}
}
}
}

View File

@@ -39,7 +39,7 @@ import kotlin.math.floor
class UIItemInventoryItemGrid(
parentUI: UICanvas,
val catBar: UIItemInventoryCatBar,
val inventory: FixtureInventory, // when you're going to display List of Craftables, you could implement a Delegator...? Or just build a virtual inventory
var getInventory: () -> FixtureInventory, // when you're going to display List of Craftables, you could implement a Delegator...? Or just build a virtual inventory
initialX: Int,
initialY: Int,
val horizontalCells: Int,
@@ -411,7 +411,7 @@ class UIItemInventoryItemGrid(
inventorySortList = ArrayList<InventoryPair>()
// filter items
inventory.forEach {
getInventory().forEach {
if ((filter.contains(ItemCodex[it.itm]!!.inventoryCategory) || filter[0] == CAT_ALL))
inventorySortList.add(it)
}
@@ -430,9 +430,11 @@ class UIItemInventoryItemGrid(
items[k].itemImage = ItemCodex.getItemImage(sortListItem.itm)
// set quickslot number
if (inventory is ActorInventory) {
if (getInventory() is ActorInventory) {
val ainv = getInventory() as ActorInventory
for (qs in 1..UIQuickslotBar.SLOT_COUNT) {
if (sortListItem.itm == inventory.getQuickslot(qs - 1)?.itm) {
if (sortListItem.itm == ainv.getQuickslot(qs - 1)?.itm) {
items[k].quickslot = qs % 10 // 10 -> 0, 1..9 -> 1..9
break
}
@@ -441,9 +443,9 @@ class UIItemInventoryItemGrid(
}
// set equippedslot number
for (eq in inventory.itemEquipped.indices) {
if (eq < inventory.itemEquipped.size) {
if (inventory.itemEquipped[eq] == items[k].item?.dynamicID) {
for (eq in ainv.itemEquipped.indices) {
if (eq < ainv.itemEquipped.size) {
if (ainv.itemEquipped[eq] == items[k].item?.dynamicID) {
items[k].equippedSlot = eq
break
}
@@ -471,7 +473,7 @@ class UIItemInventoryItemGrid(
// ¤ 6969g
// ¤ 2147483647g
// g is read as "grave" /ɡraːv/ or /ɡɹeɪv/, because it isn't gram.
walletText = "<;?" + inventory.wallet.toString().padStart(4, '?') + ":"
walletText = "<;?" + getInventory().wallet.toString().padStart(4, '?') + ":"
rebuildList = false