mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 19:14:05 +09:00
working storage chest impl
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||
|
||||
interface HasInventory {
|
||||
|
||||
fun getNegotiator(): InventoryNegotiator
|
||||
fun getFixtureInventory()
|
||||
fun getPlayerInventory()
|
||||
fun getFixtureInventory(): FixtureInventory
|
||||
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.gameitem.GameItem
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||
|
||||
/**
|
||||
* 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 */
|
||||
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... */
|
||||
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... */
|
||||
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
|
||||
|
||||
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 CELLS_HOR = 10
|
||||
@@ -247,7 +247,6 @@ class UIInventoryFull(
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
(Terrarum.ingame as? TerrarumIngame)?.setTooltipMessage(null) // required!
|
||||
|
||||
MinimapComposer.revalidateAll()
|
||||
}
|
||||
|
||||
|
||||
@@ -26,20 +26,20 @@ abstract class UIItemInventoryCellBase(
|
||||
open var itemImage: TextureRegion?,
|
||||
open var quickslot: Int? = null,
|
||||
open var equippedSlot: Int? = null,
|
||||
val keyDownFun: (GameItem?, Int) -> Unit,
|
||||
val touchDownFun: (GameItem?, Int, Int, Int, Int) -> Unit
|
||||
val keyDownFun: (GameItem?, Int, Int) -> Unit,
|
||||
val touchDownFun: (GameItem?, Int, Int) -> Unit
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
abstract override fun update(delta: Float)
|
||||
abstract override fun render(batch: SpriteBatch, camera: Camera)
|
||||
|
||||
override fun keyDown(keycode: Int): Boolean {
|
||||
keyDownFun(item, keycode)
|
||||
keyDownFun(item, amount, keycode)
|
||||
super.keyDown(keycode)
|
||||
return true
|
||||
}
|
||||
|
||||
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)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ class UIItemInventoryItemGrid(
|
||||
val verticalCells: Int,
|
||||
val drawScrollOnRightside: Boolean = false,
|
||||
val drawWallet: Boolean = true,
|
||||
keyDownFun: (GameItem?, Int) -> Unit,
|
||||
touchDownFun: (GameItem?, Int, Int, Int, Int) -> Unit
|
||||
keyDownFun: (GameItem?, Int, Int) -> Unit,
|
||||
touchDownFun: (GameItem?, Int, Int) -> Unit
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
// deal with the moving position
|
||||
@@ -108,8 +108,8 @@ class UIItemInventoryItemGrid(
|
||||
fun getEstimatedW(horizontalCells: Int) = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
|
||||
fun getEstimatedH(verticalCells: Int) = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
|
||||
|
||||
fun createInvCellGenericKeyDownFun(): (GameItem?, Int) -> Unit {
|
||||
return { item: GameItem?, keycode: Int ->
|
||||
fun createInvCellGenericKeyDownFun(): (GameItem?, Int, Int) -> Unit {
|
||||
return { item: GameItem?, amount: Int, keycode: Int ->
|
||||
if (item != null && Terrarum.ingame != null && keycode in Input.Keys.NUM_0..Input.Keys.NUM_9) {
|
||||
val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
|
||||
if (player != null) {
|
||||
@@ -138,8 +138,8 @@ class UIItemInventoryItemGrid(
|
||||
}
|
||||
}
|
||||
|
||||
fun createInvCellGenericTouchDownFun(listRebuildFun: () -> Unit): (GameItem?, Int, Int, Int, Int) -> Unit {
|
||||
return { item: GameItem?, screenX: Int, screenY: Int, pointer: Int, button: Int ->
|
||||
fun createInvCellGenericTouchDownFun(listRebuildFun: () -> Unit): (GameItem?, Int, Int) -> Unit {
|
||||
return { item: GameItem?, amount: Int, button: Int ->
|
||||
if (item != null && Terrarum.ingame != null) {
|
||||
// equip da shit
|
||||
val itemEquipSlot = item.equipPosition
|
||||
|
||||
Reference in New Issue
Block a user