mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 18:14:06 +09:00
working storage chest impl
This commit is contained in:
@@ -738,7 +738,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
textureWhiteCircle.dispose();
|
textureWhiteCircle.dispose();
|
||||||
logo.getTexture().dispose();
|
logo.getTexture().dispose();
|
||||||
|
|
||||||
disposableSingletonsPool.forEach((it) -> {try { it.dispose(); } catch (GdxRuntimeException e) {}});
|
disposableSingletonsPool.forEach((it) -> {try { it.dispose(); } catch (IllegalArgumentException e) {}});
|
||||||
|
|
||||||
ModMgr.INSTANCE.disposeMods();
|
ModMgr.INSTANCE.disposeMods();
|
||||||
|
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ class UIItemInventoryElem(
|
|||||||
override var quickslot: Int? = null,
|
override var quickslot: Int? = null,
|
||||||
override var equippedSlot: Int? = null,
|
override var equippedSlot: Int? = null,
|
||||||
val drawBackOnNull: Boolean = true,
|
val drawBackOnNull: Boolean = true,
|
||||||
keyDownFun: (GameItem?, Int) -> Unit,
|
keyDownFun: (GameItem?, Int, Int) -> Unit,
|
||||||
touchDownFun: (GameItem?, Int, Int, Int, Int) -> Unit
|
touchDownFun: (GameItem?, Int, Int) -> Unit
|
||||||
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun) {
|
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ class UIItemInventoryElemSimple(
|
|||||||
override var quickslot: Int? = null,
|
override var quickslot: Int? = null,
|
||||||
override var equippedSlot: Int? = null,
|
override var equippedSlot: Int? = null,
|
||||||
val drawBackOnNull: Boolean = true,
|
val drawBackOnNull: Boolean = true,
|
||||||
keyDownFun: (GameItem?, Int) -> Unit,
|
keyDownFun: (GameItem?, Int, Int) -> Unit,
|
||||||
touchDownFun: (GameItem?, Int, Int, Int, Int) -> Unit
|
touchDownFun: (GameItem?, Int, Int) -> Unit
|
||||||
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun) {
|
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -1071,7 +1071,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
it.handler.dispose()
|
it.handler.dispose()
|
||||||
it.dispose()
|
it.dispose()
|
||||||
}
|
}
|
||||||
catch (e: GdxRuntimeException) {}
|
catch (e: IllegalArgumentException) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
super.dispose()
|
super.dispose()
|
||||||
|
|||||||
@@ -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
|
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!
|
/** Will check existence of the item using its Dynamic ID; careful with command order!
|
||||||
* e.g. re-assign after this operation */
|
* 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 ->
|
super.remove(item, count) { existingItem ->
|
||||||
// unequip, if applicable
|
// unequip, if applicable
|
||||||
actor.unequipItem(existingItem.item)
|
actor.unequipItem(existingItem.item)
|
||||||
// depleted item; remove entry from inventory
|
|
||||||
itemList.remove(existingItem)
|
|
||||||
|
|
||||||
// also unequip on the quickslot
|
// also unequip on the quickslot
|
||||||
actor.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)?.let {
|
actor.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)?.let {
|
||||||
setQuickBar(it, null)
|
setQuickBar(it, null)
|
||||||
|
|||||||
@@ -69,6 +69,9 @@ open class FixtureInventory(var maxCapacity: Int, var capacityMode: Int) {
|
|||||||
insertionSortLastElem(itemList)
|
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) =
|
open fun remove(itemID: ItemID, count: Int, unequipFun: (InventoryPair) -> Unit) =
|
||||||
remove(ItemCodex[itemID]!!, count, unequipFun)
|
remove(ItemCodex[itemID]!!, count, unequipFun)
|
||||||
/** Will check existence of the item using its Dynamic ID; careful with command order!
|
/** 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
|
existingItem.amount = newCount
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// depleted item; remove entry from inventory
|
||||||
|
itemList.remove(existingItem)
|
||||||
|
// do additional removal job (e.g. unequipping)
|
||||||
unequipFun(existingItem)
|
unequipFun(existingItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import net.torvald.terrarum.*
|
|||||||
import net.torvald.terrarum.AppLoader.printdbg
|
import net.torvald.terrarum.AppLoader.printdbg
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
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.gameactors.FixtureInventory.Companion.CAPACITY_MODE_COUNT
|
||||||
import net.torvald.terrarum.modulebasegame.ui.HasInventory
|
import net.torvald.terrarum.modulebasegame.ui.HasInventory
|
||||||
import net.torvald.terrarum.modulebasegame.ui.InventoryNegotiator
|
import net.torvald.terrarum.modulebasegame.ui.InventoryNegotiator
|
||||||
@@ -64,24 +65,20 @@ internal class UIStorageChest : UICanvas(), HasInventory {
|
|||||||
private val shapeRenderer = ShapeRenderer()
|
private val shapeRenderer = ShapeRenderer()
|
||||||
|
|
||||||
private val negotiator = object : InventoryNegotiator() {
|
private val negotiator = object : InventoryNegotiator() {
|
||||||
override fun accept(item: GameItem, amount: Int) {
|
override fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Int) {
|
||||||
printdbg(this, "Accept")
|
player.remove(item, amount)
|
||||||
|
fixture.add(item, amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun reject(item: GameItem, amount: Int) {
|
override fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Int) {
|
||||||
printdbg(this, "Reject")
|
fixture.remove(item, amount)
|
||||||
|
player.add(item, amount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getNegotiator() = negotiator
|
override fun getNegotiator() = negotiator
|
||||||
|
override fun getFixtureInventory(): FixtureInventory = chest
|
||||||
override fun getFixtureInventory() {
|
override fun getPlayerInventory(): FixtureInventory = Terrarum.ingame!!.actorNowPlaying!!.inventory
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getPlayerInventory() {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
private lateinit var catBar: UIItemInventoryCatBar
|
private lateinit var catBar: UIItemInventoryCatBar
|
||||||
private lateinit var itemListChest: UIItemInventoryItemGrid
|
private lateinit var itemListChest: UIItemInventoryItemGrid
|
||||||
@@ -118,8 +115,13 @@ internal class UIStorageChest : UICanvas(), HasInventory {
|
|||||||
6, CELLS_VRT,
|
6, CELLS_VRT,
|
||||||
drawScrollOnRightside = false,
|
drawScrollOnRightside = false,
|
||||||
drawWallet = false,
|
drawWallet = false,
|
||||||
keyDownFun = { _, _ -> Unit },
|
keyDownFun = { _, _, _ -> Unit },
|
||||||
touchDownFun = { _, _, _, _, _ -> itemListUpdate() }
|
touchDownFun = { gameItem, amount, _ ->
|
||||||
|
if (gameItem != null) {
|
||||||
|
negotiator.reject(chest, getPlayerInventory(), gameItem, amount)
|
||||||
|
}
|
||||||
|
itemListUpdate()
|
||||||
|
}
|
||||||
)
|
)
|
||||||
itemListPlayer = UIItemInventoryItemGrid(
|
itemListPlayer = UIItemInventoryItemGrid(
|
||||||
this,
|
this,
|
||||||
@@ -130,8 +132,13 @@ internal class UIStorageChest : UICanvas(), HasInventory {
|
|||||||
6, CELLS_VRT,
|
6, CELLS_VRT,
|
||||||
drawScrollOnRightside = true,
|
drawScrollOnRightside = true,
|
||||||
drawWallet = false,
|
drawWallet = false,
|
||||||
keyDownFun = { _, _ -> Unit },
|
keyDownFun = { _, _, _ -> Unit },
|
||||||
touchDownFun = { _, _, _, _, _ -> itemListUpdate() }
|
touchDownFun = { gameItem, amount, _ ->
|
||||||
|
if (gameItem != null) {
|
||||||
|
negotiator.accept(getPlayerInventory(), chest, gameItem, amount)
|
||||||
|
}
|
||||||
|
itemListUpdate()
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
handler.allowESCtoClose = true
|
handler.allowESCtoClose = true
|
||||||
@@ -180,16 +187,19 @@ internal class UIStorageChest : UICanvas(), HasInventory {
|
|||||||
|
|
||||||
override fun doOpening(delta: Float) {
|
override fun doOpening(delta: Float) {
|
||||||
Terrarum.ingame?.paused = true
|
Terrarum.ingame?.paused = true
|
||||||
|
(Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doClosing(delta: Float) {
|
override fun doClosing(delta: Float) {
|
||||||
Terrarum.ingame?.paused = false
|
Terrarum.ingame?.paused = false
|
||||||
|
(Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun endOpening(delta: Float) {
|
override fun endOpening(delta: Float) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun endClosing(delta: Float) {
|
override fun endClosing(delta: Float) {
|
||||||
|
(Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null) // required!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.ui
|
package net.torvald.terrarum.modulebasegame.ui
|
||||||
|
|
||||||
|
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||||
|
|
||||||
interface HasInventory {
|
interface HasInventory {
|
||||||
|
|
||||||
fun getNegotiator(): InventoryNegotiator
|
fun getNegotiator(): InventoryNegotiator
|
||||||
fun getFixtureInventory()
|
fun getFixtureInventory(): FixtureInventory
|
||||||
fun getPlayerInventory()
|
fun getPlayerInventory(): FixtureInventory
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package net.torvald.terrarum.modulebasegame.ui
|
|||||||
|
|
||||||
import net.torvald.terrarum.UIItemInventoryCatBar.Companion.CAT_ALL
|
import net.torvald.terrarum.UIItemInventoryCatBar.Companion.CAT_ALL
|
||||||
import net.torvald.terrarum.gameitem.GameItem
|
import net.torvald.terrarum.gameitem.GameItem
|
||||||
|
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2021-03-12.
|
* Created by minjaesong on 2021-03-12.
|
||||||
@@ -10,7 +11,7 @@ abstract class InventoryNegotiator {
|
|||||||
/** Retrieve item filter to be used to show only the acceptable items when player's own inventory is being displayed */
|
/** Retrieve item filter to be used to show only the acceptable items when player's own inventory is being displayed */
|
||||||
open fun getItemFilter(): List<String> = listOf(CAT_ALL) // GameItem.Category
|
open fun getItemFilter(): List<String> = listOf(CAT_ALL) // GameItem.Category
|
||||||
/** Accepts item from the player and pass it to right inventory (object), slot (UI), etc... */
|
/** Accepts item from the player and pass it to right inventory (object), slot (UI), etc... */
|
||||||
abstract fun accept(item: GameItem, amount: Int = 1)
|
abstract fun accept(player: FixtureInventory, fixture: FixtureInventory, item: GameItem, amount: Int = 1)
|
||||||
/** Rejects item and perhaps returns it back to the player, or make explosion, etc... */
|
/** Rejects item and perhaps returns it back to the player, or make explosion, etc... */
|
||||||
abstract fun reject(item: GameItem, amount: Int = 1)
|
abstract fun reject(fixture: FixtureInventory, player: FixtureInventory, item: GameItem, amount: Int = 1)
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ class UIInventoryFull(
|
|||||||
override var openCloseTime: Second = 0.0f
|
override var openCloseTime: Second = 0.0f
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val INVEN_DEBUG_MODE = true
|
const val INVEN_DEBUG_MODE = false
|
||||||
|
|
||||||
const val REQUIRED_MARGIN: Int = 138 // hard-coded value. Don't know the details. Range: [91-146]. I chose MAX-8 because cell gap is 8
|
const val REQUIRED_MARGIN: Int = 138 // hard-coded value. Don't know the details. Range: [91-146]. I chose MAX-8 because cell gap is 8
|
||||||
const val CELLS_HOR = 10
|
const val CELLS_HOR = 10
|
||||||
@@ -247,7 +247,6 @@ class UIInventoryFull(
|
|||||||
|
|
||||||
override fun endClosing(delta: Float) {
|
override fun endClosing(delta: Float) {
|
||||||
(Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null) // required!
|
(Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null) // required!
|
||||||
|
|
||||||
MinimapComposer.revalidateAll()
|
MinimapComposer.revalidateAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,20 +26,20 @@ abstract class UIItemInventoryCellBase(
|
|||||||
open var itemImage: TextureRegion?,
|
open var itemImage: TextureRegion?,
|
||||||
open var quickslot: Int? = null,
|
open var quickslot: Int? = null,
|
||||||
open var equippedSlot: Int? = null,
|
open var equippedSlot: Int? = null,
|
||||||
val keyDownFun: (GameItem?, Int) -> Unit,
|
val keyDownFun: (GameItem?, Int, Int) -> Unit,
|
||||||
val touchDownFun: (GameItem?, Int, Int, Int, Int) -> Unit
|
val touchDownFun: (GameItem?, Int, Int) -> Unit
|
||||||
) : UIItem(parentUI, initialX, initialY) {
|
) : UIItem(parentUI, initialX, initialY) {
|
||||||
abstract override fun update(delta: Float)
|
abstract override fun update(delta: Float)
|
||||||
abstract override fun render(batch: SpriteBatch, camera: Camera)
|
abstract override fun render(batch: SpriteBatch, camera: Camera)
|
||||||
|
|
||||||
override fun keyDown(keycode: Int): Boolean {
|
override fun keyDown(keycode: Int): Boolean {
|
||||||
keyDownFun(item, keycode)
|
keyDownFun(item, amount, keycode)
|
||||||
super.keyDown(keycode)
|
super.keyDown(keycode)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||||
touchDownFun(item, screenX, screenY, pointer, button)
|
touchDownFun(item, amount, button)
|
||||||
super.touchDown(screenX, screenY, pointer, button)
|
super.touchDown(screenX, screenY, pointer, button)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ class UIItemInventoryItemGrid(
|
|||||||
val verticalCells: Int,
|
val verticalCells: Int,
|
||||||
val drawScrollOnRightside: Boolean = false,
|
val drawScrollOnRightside: Boolean = false,
|
||||||
val drawWallet: Boolean = true,
|
val drawWallet: Boolean = true,
|
||||||
keyDownFun: (GameItem?, Int) -> Unit,
|
keyDownFun: (GameItem?, Int, Int) -> Unit,
|
||||||
touchDownFun: (GameItem?, Int, Int, Int, Int) -> Unit
|
touchDownFun: (GameItem?, Int, Int) -> Unit
|
||||||
) : UIItem(parentUI, initialX, initialY) {
|
) : UIItem(parentUI, initialX, initialY) {
|
||||||
|
|
||||||
// deal with the moving position
|
// deal with the moving position
|
||||||
@@ -108,8 +108,8 @@ class UIItemInventoryItemGrid(
|
|||||||
fun getEstimatedW(horizontalCells: Int) = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
|
fun getEstimatedW(horizontalCells: Int) = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
|
||||||
fun getEstimatedH(verticalCells: Int) = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
|
fun getEstimatedH(verticalCells: Int) = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
|
||||||
|
|
||||||
fun createInvCellGenericKeyDownFun(): (GameItem?, Int) -> Unit {
|
fun createInvCellGenericKeyDownFun(): (GameItem?, Int, Int) -> Unit {
|
||||||
return { item: GameItem?, keycode: Int ->
|
return { item: GameItem?, amount: Int, keycode: Int ->
|
||||||
if (item != null && Terrarum.ingame != null && keycode in Input.Keys.NUM_0..Input.Keys.NUM_9) {
|
if (item != null && Terrarum.ingame != null && keycode in Input.Keys.NUM_0..Input.Keys.NUM_9) {
|
||||||
val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
|
val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
@@ -138,8 +138,8 @@ class UIItemInventoryItemGrid(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createInvCellGenericTouchDownFun(listRebuildFun: () -> Unit): (GameItem?, Int, Int, Int, Int) -> Unit {
|
fun createInvCellGenericTouchDownFun(listRebuildFun: () -> Unit): (GameItem?, Int, Int) -> Unit {
|
||||||
return { item: GameItem?, screenX: Int, screenY: Int, pointer: Int, button: Int ->
|
return { item: GameItem?, amount: Int, button: Int ->
|
||||||
if (item != null && Terrarum.ingame != null) {
|
if (item != null && Terrarum.ingame != null) {
|
||||||
// equip da shit
|
// equip da shit
|
||||||
val itemEquipSlot = item.equipPosition
|
val itemEquipSlot = item.equipPosition
|
||||||
|
|||||||
Reference in New Issue
Block a user