mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-16 16:46:07 +09:00
inventory ui: getting actor is now dynamic
This commit is contained in:
@@ -136,7 +136,7 @@ internal class UIStorageChest : UICanvas(
|
|||||||
itemListChest = UIItemInventoryItemGrid(
|
itemListChest = UIItemInventoryItemGrid(
|
||||||
this,
|
this,
|
||||||
catBar,
|
catBar,
|
||||||
getFixtureInventory(),
|
{ getFixtureInventory() },
|
||||||
INVENTORY_CELLS_OFFSET_X - halfSlotOffset,
|
INVENTORY_CELLS_OFFSET_X - halfSlotOffset,
|
||||||
INVENTORY_CELLS_OFFSET_Y,
|
INVENTORY_CELLS_OFFSET_Y,
|
||||||
6, CELLS_VRT,
|
6, CELLS_VRT,
|
||||||
@@ -153,7 +153,7 @@ internal class UIStorageChest : UICanvas(
|
|||||||
itemListPlayer = UIItemInventoryItemGrid(
|
itemListPlayer = UIItemInventoryItemGrid(
|
||||||
this,
|
this,
|
||||||
catBar,
|
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_X - halfSlotOffset + (listGap + UIItemInventoryElem.height) * 7,
|
||||||
INVENTORY_CELLS_OFFSET_Y,
|
INVENTORY_CELLS_OFFSET_Y,
|
||||||
6, CELLS_VRT,
|
6, CELLS_VRT,
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ internal class UIInventoryCells(
|
|||||||
UIItemInventoryItemGrid(
|
UIItemInventoryItemGrid(
|
||||||
full,
|
full,
|
||||||
full.catBar,
|
full.catBar,
|
||||||
full.actor.inventory,
|
{ full.actor.inventory },
|
||||||
INVENTORY_CELLS_OFFSET_X,
|
INVENTORY_CELLS_OFFSET_X,
|
||||||
INVENTORY_CELLS_OFFSET_Y,
|
INVENTORY_CELLS_OFFSET_Y,
|
||||||
CELLS_HOR, CELLS_VRT,
|
CELLS_HOR, CELLS_VRT,
|
||||||
@@ -53,8 +53,6 @@ internal class UIInventoryCells(
|
|||||||
private val equipped: UIItemInventoryEquippedView =
|
private val equipped: UIItemInventoryEquippedView =
|
||||||
UIItemInventoryEquippedView(
|
UIItemInventoryEquippedView(
|
||||||
full,
|
full,
|
||||||
full.actor.inventory,
|
|
||||||
full.actor as ActorWithBody,
|
|
||||||
internalWidth - UIItemInventoryEquippedView.WIDTH + (AppLoader.screenSize.screenW - internalWidth) / 2,
|
internalWidth - UIItemInventoryEquippedView.WIDTH + (AppLoader.screenSize.screenW - internalWidth) / 2,
|
||||||
INVENTORY_CELLS_OFFSET_Y,
|
INVENTORY_CELLS_OFFSET_Y,
|
||||||
{ rebuildList() }
|
{ rebuildList() }
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ import net.torvald.terrarum.ui.UIItem
|
|||||||
*/
|
*/
|
||||||
class UIItemInventoryEquippedView(
|
class UIItemInventoryEquippedView(
|
||||||
parentUI: UICanvas,
|
parentUI: UICanvas,
|
||||||
val inventory: ActorInventory,
|
|
||||||
val theActor: ActorWithBody,
|
|
||||||
initialX: Int,
|
initialX: Int,
|
||||||
initialY: Int,
|
initialY: Int,
|
||||||
inventoryListRebuildFun: () -> Unit
|
inventoryListRebuildFun: () -> Unit
|
||||||
@@ -92,7 +90,7 @@ class UIItemInventoryEquippedView(
|
|||||||
|
|
||||||
|
|
||||||
// sprite
|
// sprite
|
||||||
val sprite = theActor.sprite
|
val sprite = Terrarum.ingame!!.actorNowPlaying?.sprite
|
||||||
sprite?.let {
|
sprite?.let {
|
||||||
blendNormal(batch)
|
blendNormal(batch)
|
||||||
|
|
||||||
@@ -121,28 +119,30 @@ class UIItemInventoryEquippedView(
|
|||||||
internal fun rebuild() {
|
internal fun rebuild() {
|
||||||
rebuildList = false
|
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
|
// fill the grid from fastest index, make no gap in-between of slots
|
||||||
for (k in itemGrid.indices) {
|
for (k in itemGrid.indices) {
|
||||||
val item = inventory.itemEquipped[k]
|
val item = it.itemEquipped[k]
|
||||||
|
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
|
|
||||||
itemGrid[k].item = null
|
itemGrid[k].item = null
|
||||||
itemGrid[k].amount = 0
|
itemGrid[k].amount = 0
|
||||||
itemGrid[k].itemImage = null
|
itemGrid[k].itemImage = null
|
||||||
itemGrid[k].quickslot = null
|
itemGrid[k].quickslot = null
|
||||||
itemGrid[k].equippedSlot = null
|
itemGrid[k].equippedSlot = null
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val itemRecord = inventory.invSearchByDynamicID(item)!!
|
val itemRecord = it.invSearchByDynamicID(item)!!
|
||||||
|
|
||||||
itemGrid[k].item = ItemCodex[item]
|
itemGrid[k].item = ItemCodex[item]
|
||||||
itemGrid[k].amount = itemRecord.qty
|
itemGrid[k].amount = itemRecord.qty
|
||||||
itemGrid[k].itemImage = ItemCodex.getItemImage(item)
|
itemGrid[k].itemImage = ItemCodex.getItemImage(item)
|
||||||
itemGrid[k].quickslot = null // don't need to be displayed
|
itemGrid[k].quickslot = null // don't need to be displayed
|
||||||
itemGrid[k].equippedSlot = null // don't need to be displayed
|
itemGrid[k].equippedSlot = null // don't need to be displayed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ import kotlin.math.floor
|
|||||||
class UIItemInventoryItemGrid(
|
class UIItemInventoryItemGrid(
|
||||||
parentUI: UICanvas,
|
parentUI: UICanvas,
|
||||||
val catBar: UIItemInventoryCatBar,
|
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,
|
initialX: Int,
|
||||||
initialY: Int,
|
initialY: Int,
|
||||||
val horizontalCells: Int,
|
val horizontalCells: Int,
|
||||||
@@ -411,7 +411,7 @@ class UIItemInventoryItemGrid(
|
|||||||
inventorySortList = ArrayList<InventoryPair>()
|
inventorySortList = ArrayList<InventoryPair>()
|
||||||
|
|
||||||
// filter items
|
// filter items
|
||||||
inventory.forEach {
|
getInventory().forEach {
|
||||||
if ((filter.contains(ItemCodex[it.itm]!!.inventoryCategory) || filter[0] == CAT_ALL))
|
if ((filter.contains(ItemCodex[it.itm]!!.inventoryCategory) || filter[0] == CAT_ALL))
|
||||||
inventorySortList.add(it)
|
inventorySortList.add(it)
|
||||||
}
|
}
|
||||||
@@ -430,9 +430,11 @@ class UIItemInventoryItemGrid(
|
|||||||
items[k].itemImage = ItemCodex.getItemImage(sortListItem.itm)
|
items[k].itemImage = ItemCodex.getItemImage(sortListItem.itm)
|
||||||
|
|
||||||
// set quickslot number
|
// set quickslot number
|
||||||
if (inventory is ActorInventory) {
|
if (getInventory() is ActorInventory) {
|
||||||
|
val ainv = getInventory() as ActorInventory
|
||||||
|
|
||||||
for (qs in 1..UIQuickslotBar.SLOT_COUNT) {
|
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
|
items[k].quickslot = qs % 10 // 10 -> 0, 1..9 -> 1..9
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -441,9 +443,9 @@ class UIItemInventoryItemGrid(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set equippedslot number
|
// set equippedslot number
|
||||||
for (eq in inventory.itemEquipped.indices) {
|
for (eq in ainv.itemEquipped.indices) {
|
||||||
if (eq < inventory.itemEquipped.size) {
|
if (eq < ainv.itemEquipped.size) {
|
||||||
if (inventory.itemEquipped[eq] == items[k].item?.dynamicID) {
|
if (ainv.itemEquipped[eq] == items[k].item?.dynamicID) {
|
||||||
items[k].equippedSlot = eq
|
items[k].equippedSlot = eq
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -471,7 +473,7 @@ class UIItemInventoryItemGrid(
|
|||||||
// ¤ 6969g
|
// ¤ 6969g
|
||||||
// ¤ 2147483647g
|
// ¤ 2147483647g
|
||||||
// g is read as "grave" /ɡraːv/ or /ɡɹeɪv/, because it isn't gram.
|
// 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
|
rebuildList = false
|
||||||
|
|||||||
Reference in New Issue
Block a user