storagechests (actually all fixtures) now has their own inventory

This commit is contained in:
minjaesong
2021-03-16 15:01:17 +09:00
parent 76f5d0a924
commit 0fa889bc55
10 changed files with 331 additions and 263 deletions

View File

@@ -7,6 +7,7 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELLS_HOR
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELLS_VRT
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_X
@@ -53,7 +54,8 @@ internal class UIInventoryCells(
full.actor.inventory,
full.actor as ActorWithBody,
internalWidth - UIItemInventoryEquippedView.WIDTH + (AppLoader.screenW - internalWidth) / 2,
INVENTORY_CELLS_OFFSET_Y
INVENTORY_CELLS_OFFSET_Y,
{ rebuildList() }
)
init {
@@ -124,7 +126,7 @@ internal class UIInventoryCells(
batch.color = encumbCol
batch.fillRect(
encumbBarXPos, encumbBarYPos,
if (full.actor.inventory.capacityMode == ActorInventory.CAPACITY_MODE_NO_ENCUMBER)
if (full.actor.inventory.capacityMode == FixtureInventory.CAPACITY_MODE_NO_ENCUMBER)
1f
else // make sure 1px is always be seen
minOf(weightBarWidth, maxOf(1f, weightBarWidth * encumbrancePerc)),

View File

@@ -15,17 +15,19 @@ import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericTouchDownFun
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.Toolkit.DEFAULT_BOX_BORDER_COL
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem
/**
* Created by minjaesong on 2017-10-28.
*/
class UIItemInventoryEquippedView(
parentUI: UIInventoryFull,
parentUI: UICanvas,
val inventory: ActorInventory,
val theActor: ActorWithBody,
initialX: Int,
initialY: Int
initialY: Int,
inventoryListRebuildFun: () -> Unit
) : UIItem(parentUI, initialX, initialY) {
@@ -66,7 +68,7 @@ class UIItemInventoryEquippedView(
backBlendMode = BlendMode.NORMAL,
drawBackOnNull = true,
keyDownFun = createInvCellGenericKeyDownFun(),
touchDownFun = createInvCellGenericTouchDownFun { parentUI.rebuildList() } // to "unselect" the equipped item and main item grid would "untick" accordingly
touchDownFun = createInvCellGenericTouchDownFun(inventoryListRebuildFun) // to "unselect" the equipped item and main item grid would "untick" accordingly
)
}

View File

@@ -12,6 +12,7 @@ import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK_ACTIVE
@@ -38,7 +39,7 @@ import kotlin.math.floor
class UIItemInventoryItemGrid(
parentUI: UICanvas,
val catBar: UIItemInventoryCatBar,
val inventory: ActorInventory, // when you're going to display List of Craftables, you could implement a Delegator...? Or just build a virtual inventory
val inventory: 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,
@@ -192,7 +193,8 @@ class UIItemInventoryItemGrid(
}
// automatically determine how much columns are needed. Minimum Width = 5 grids
private val itemListColumnCount = floor(horizontalCells / 5f).toInt().coerceAtLeast(1)
private val largeListWidth = (horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 2) * listGap) / itemListColumnCount
private val actualItemCellWidth = (listGap + UIItemInventoryElemSimple.height) * horizontalCells - listGap // in pixels
private val largeListWidth = ((listGap + actualItemCellWidth) / itemListColumnCount) - (itemListColumnCount - 1).coerceAtLeast(1) * listGap
private val itemList = Array<UIItemInventoryCellBase>(verticalCells * itemListColumnCount) {
UIItemInventoryElem(
parentUI = inventoryUI,
@@ -428,24 +430,26 @@ class UIItemInventoryItemGrid(
items[k].itemImage = ItemCodex.getItemImage(sortListItem.item)
// set quickslot number
for (qs in 1..UIQuickslotBar.SLOT_COUNT) {
if (sortListItem.item == inventory.getQuickslot(qs - 1)?.item) {
items[k].quickslot = qs % 10 // 10 -> 0, 1..9 -> 1..9
break
}
else
items[k].quickslot = null
}
// set equippedslot number
for (eq in inventory.itemEquipped.indices) {
if (eq < inventory.itemEquipped.size) {
if (inventory.itemEquipped[eq] == items[k].item?.dynamicID) {
items[k].equippedSlot = eq
if (inventory is ActorInventory) {
for (qs in 1..UIQuickslotBar.SLOT_COUNT) {
if (sortListItem.item == inventory.getQuickslot(qs - 1)?.item) {
items[k].quickslot = qs % 10 // 10 -> 0, 1..9 -> 1..9
break
}
else
items[k].equippedSlot = null
items[k].quickslot = null
}
// set equippedslot number
for (eq in inventory.itemEquipped.indices) {
if (eq < inventory.itemEquipped.size) {
if (inventory.itemEquipped[eq] == items[k].item?.dynamicID) {
items[k].equippedSlot = eq
break
}
else
items[k].equippedSlot = null
}
}
}
}