storage chest wip

This commit is contained in:
minjaesong
2021-03-12 12:44:27 +09:00
parent bd89ca67fb
commit b57486e9d7
7 changed files with 163 additions and 95 deletions

View File

@@ -0,0 +1,9 @@
package net.torvald.terrarum.modulebasegame.ui
interface HasInventory {
fun getNegotiator(): InventoryNegotiator
fun getFixtureInventory()
fun getPlayerInventory()
}

View File

@@ -0,0 +1,15 @@
package net.torvald.terrarum.modulebasegame.ui
import net.torvald.terrarum.gameitem.GameItem
/**
* Created by minjaesong on 2021-03-12.
*/
interface InventoryNegotiator {
/** Retrieve item filter to be used to show only the acceptable items when player's own inventory is being displayed */
fun getItemFilter(): List<String> // GameItem.Category
/** Accepts item from the player and pass it to right inventory (object), slot (UI), etc... */
fun accept(item: GameItem, amount: Int = 1)
/** Rejects item and perhaps returns it back to the player, or make explosion, etc... */
fun reject(item: GameItem, amount: Int = 1)
}

View File

@@ -19,6 +19,7 @@ import net.torvald.terrarum.ui.UIItemImageButton
import net.torvald.terrarum.ui.UIItemTextButton.Companion.defaultActiveCol
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import java.util.*
import kotlin.math.floor
/**
* Display either extended or compact list
@@ -51,7 +52,6 @@ class UIItemInventoryItemGrid(
override val width = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
override val height = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
val largeListWidth = (horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 2) * listGap) / 2
val backColour = CELLCOLOUR_BLACK
init {
@@ -128,11 +128,13 @@ class UIItemInventoryItemGrid(
)
}
// TODO automatically determine how much columns are needed. Minimum Width = 5 grids
private val itemList = Array<UIItemInventoryCellBase>(verticalCells * 2) {
private val itemListColumnCount = floor(horizontalCells / 4f).toInt().coerceAtLeast(1)
private val largeListWidth = (horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 2) * listGap) / itemListColumnCount
private val itemList = Array<UIItemInventoryCellBase>(verticalCells * itemListColumnCount) {
UIItemInventoryElem(
parentUI = inventoryUI,
initialX = this.posX + (largeListWidth + listGap) * (it % 2),
initialY = this.posY + (UIItemInventoryElem.height + listGap) * (it / 2),
initialX = this.posX + (largeListWidth + listGap) * (it % itemListColumnCount),
initialY = this.posY + (UIItemInventoryElem.height + listGap) * (it / itemListColumnCount),
width = largeListWidth,
item = null,
amount = UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT,