mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
working storage chest impl
This commit is contained in:
@@ -32,16 +32,13 @@ class ActorInventory(@Transient val actor: Pocketed, maxCapacity: Int, capacityM
|
||||
val quickSlot = Array<ItemID?>(UIQuickslotBar.SLOT_COUNT) { null } // 0: Slot 1, 9: Slot 10
|
||||
|
||||
|
||||
fun remove(itemID: ItemID, count: Int) = remove(ItemCodex[itemID]!!, count)
|
||||
override fun remove(itemID: ItemID, count: Int) = remove(ItemCodex[itemID]!!, count)
|
||||
/** Will check existence of the item using its Dynamic ID; careful with command order!
|
||||
* e.g. re-assign after this operation */
|
||||
fun remove(item: GameItem, count: Int = 1) {
|
||||
override fun remove(item: GameItem, count: Int) {
|
||||
super.remove(item, count) { existingItem ->
|
||||
// unequip, if applicable
|
||||
actor.unequipItem(existingItem.item)
|
||||
// depleted item; remove entry from inventory
|
||||
itemList.remove(existingItem)
|
||||
|
||||
// also unequip on the quickslot
|
||||
actor.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)?.let {
|
||||
setQuickBar(it, null)
|
||||
|
||||
@@ -69,6 +69,9 @@ open class FixtureInventory(var maxCapacity: Int, var capacityMode: Int) {
|
||||
insertionSortLastElem(itemList)
|
||||
}
|
||||
|
||||
open fun remove(itemID: ItemID, count: Int) = remove(ItemCodex[itemID]!!, count) {}
|
||||
open fun remove(item: GameItem, count: Int = 1) = remove(item, count) {}
|
||||
|
||||
open fun remove(itemID: ItemID, count: Int, unequipFun: (InventoryPair) -> Unit) =
|
||||
remove(ItemCodex[itemID]!!, count, unequipFun)
|
||||
/** Will check existence of the item using its Dynamic ID; careful with command order!
|
||||
@@ -97,6 +100,9 @@ open class FixtureInventory(var maxCapacity: Int, var capacityMode: Int) {
|
||||
existingItem.amount = newCount
|
||||
}
|
||||
else {
|
||||
// depleted item; remove entry from inventory
|
||||
itemList.remove(existingItem)
|
||||
// do additional removal job (e.g. unequipping)
|
||||
unequipFun(existingItem)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.AppLoader.printdbg
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameitem.GameItem
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory.Companion.CAPACITY_MODE_COUNT
|
||||
import net.torvald.terrarum.modulebasegame.ui.HasInventory
|
||||
import net.torvald.terrarum.modulebasegame.ui.InventoryNegotiator
|
||||
@@ -64,24 +65,20 @@ internal class UIStorageChest : UICanvas(), HasInventory {
|
||||
private val shapeRenderer = ShapeRenderer()
|
||||
|
||||
private val negotiator = object : InventoryNegotiator() {
|
||||
override fun accept(item: GameItem, amount: Int) {
|
||||
printdbg(this, "Accept")
|
||||
override fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Int) {
|
||||
player.remove(item, amount)
|
||||
fixture.add(item, amount)
|
||||
}
|
||||
|
||||
override fun reject(item: GameItem, amount: Int) {
|
||||
printdbg(this, "Reject")
|
||||
override fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Int) {
|
||||
fixture.remove(item, amount)
|
||||
player.add(item, amount)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getNegotiator() = negotiator
|
||||
|
||||
override fun getFixtureInventory() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getPlayerInventory() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
override fun getFixtureInventory(): FixtureInventory = chest
|
||||
override fun getPlayerInventory(): FixtureInventory = Terrarum.ingame!!.actorNowPlaying!!.inventory
|
||||
|
||||
private lateinit var catBar: UIItemInventoryCatBar
|
||||
private lateinit var itemListChest: UIItemInventoryItemGrid
|
||||
@@ -118,8 +115,13 @@ internal class UIStorageChest : UICanvas(), HasInventory {
|
||||
6, CELLS_VRT,
|
||||
drawScrollOnRightside = false,
|
||||
drawWallet = false,
|
||||
keyDownFun = { _, _ -> Unit },
|
||||
touchDownFun = { _, _, _, _, _ -> itemListUpdate() }
|
||||
keyDownFun = { _, _, _ -> Unit },
|
||||
touchDownFun = { gameItem, amount, _ ->
|
||||
if (gameItem != null) {
|
||||
negotiator.reject(chest, getPlayerInventory(), gameItem, amount)
|
||||
}
|
||||
itemListUpdate()
|
||||
}
|
||||
)
|
||||
itemListPlayer = UIItemInventoryItemGrid(
|
||||
this,
|
||||
@@ -130,8 +132,13 @@ internal class UIStorageChest : UICanvas(), HasInventory {
|
||||
6, CELLS_VRT,
|
||||
drawScrollOnRightside = true,
|
||||
drawWallet = false,
|
||||
keyDownFun = { _, _ -> Unit },
|
||||
touchDownFun = { _, _, _, _, _ -> itemListUpdate() }
|
||||
keyDownFun = { _, _, _ -> Unit },
|
||||
touchDownFun = { gameItem, amount, _ ->
|
||||
if (gameItem != null) {
|
||||
negotiator.accept(getPlayerInventory(), chest, gameItem, amount)
|
||||
}
|
||||
itemListUpdate()
|
||||
}
|
||||
)
|
||||
|
||||
handler.allowESCtoClose = true
|
||||
@@ -142,7 +149,7 @@ internal class UIStorageChest : UICanvas(), HasInventory {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
catBar.update(delta)
|
||||
itemListChest.update(delta)
|
||||
itemListPlayer.update(delta)
|
||||
@@ -180,16 +187,19 @@ internal class UIStorageChest : UICanvas(), HasInventory {
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
Terrarum.ingame?.paused = true
|
||||
(Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null)
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
Terrarum.ingame?.paused = false
|
||||
(Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null)
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
(Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null) // required!
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user