mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
storage chest wip
This commit is contained in:
@@ -31,8 +31,6 @@ class UIItemInventoryCatBar(
|
||||
const val CAT_ALL = "__all__"
|
||||
}
|
||||
|
||||
//private val parentInventory = parentUI
|
||||
|
||||
internal val catIcons: TextureRegionPack = CommonResourcePool.getAsTextureRegionPack("inventory_caticons")
|
||||
internal val catArrangement: IntArray = intArrayOf(9,6,7,1,0,2,3,4,5,8)
|
||||
internal val catIconsMeaning = listOf( // sortedBy: catArrangement
|
||||
@@ -244,7 +242,6 @@ class UIItemInventoryCatBar(
|
||||
|
||||
if (transitionFired) {
|
||||
transitionFired = false
|
||||
//parentInventory.requestTransition(selectedPanel)
|
||||
transitionReqFun(selectedPanel)
|
||||
}
|
||||
}
|
||||
@@ -280,7 +277,7 @@ class UIItemInventoryCatBar(
|
||||
|
||||
override fun dispose() {
|
||||
underlineIndTex.dispose()
|
||||
catIcons.dispose()
|
||||
//catIcons.dispose() // disposed of by the AppLoader
|
||||
mainButtons.forEach { it.dispose() }
|
||||
sideButtons.forEach { it.dispose() }
|
||||
}
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2019-07-08.
|
||||
*/
|
||||
internal class FixtureCraftingTable : FixtureBase(
|
||||
BlockBox(BlockBox.ALLOW_MOVE_DOWN, 1, 1),
|
||||
mainUI = UICraftingTable
|
||||
) {
|
||||
|
||||
init {
|
||||
setHitboxDimension(16, 16, 0, 0)
|
||||
|
||||
makeNewSprite(TextureRegionPack(CommonResourcePool.getAsTextureRegion("itemplaceholder_16").texture, 16, 16))
|
||||
sprite!!.setRowsAndFrames(1, 1)
|
||||
|
||||
actorValue[AVKey.BASEMASS] = MASS
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val MASS = 2.0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal object UICraftingTable : UICanvas() {
|
||||
override var width = 512
|
||||
override var height = 512
|
||||
override var openCloseTime: Second = 0.0f
|
||||
|
||||
init {
|
||||
handler.allowESCtoClose = true
|
||||
}
|
||||
|
||||
/*private val itemList = UIItemInventoryDynamicList =
|
||||
UIItemInventoryDynamicList(
|
||||
full,
|
||||
full.actor.inventory,
|
||||
full.INVENTORY_CELLS_OFFSET_X,
|
||||
full.INVENTORY_CELLS_OFFSET_Y,
|
||||
full.CELLS_HOR, full.CELLS_VRT
|
||||
)*/
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
|
||||
batch.color = Color.WHITE
|
||||
batch.draw(CommonResourcePool.getAsTextureRegion("test_texture"), 0f, 0f)
|
||||
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
Terrarum.ingame?.paused = true
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
Terrarum.ingame?.paused = false
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.UIItemInventoryCatBar
|
||||
import net.torvald.terrarum.UIItemInventoryCatBar.Companion.CAT_ALL
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameitem.GameItem
|
||||
import net.torvald.terrarum.modulebasegame.ui.HasInventory
|
||||
import net.torvald.terrarum.modulebasegame.ui.InventoryNegotiator
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2019-07-08.
|
||||
*/
|
||||
internal class FixtureStorageChest : FixtureBase(
|
||||
BlockBox(BlockBox.ALLOW_MOVE_DOWN, 1, 1),
|
||||
mainUI = UIStorageChest
|
||||
) {
|
||||
|
||||
init {
|
||||
setHitboxDimension(16, 16, 0, 0)
|
||||
|
||||
makeNewSprite(TextureRegionPack(CommonResourcePool.getAsTextureRegion("itemplaceholder_16").texture, 16, 16))
|
||||
sprite!!.setRowsAndFrames(1, 1)
|
||||
|
||||
actorValue[AVKey.BASEMASS] = MASS
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val MASS = 2.0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal object UIStorageChest : UICanvas(), HasInventory {
|
||||
override var width = 512
|
||||
override var height = 512
|
||||
override var openCloseTime: Second = 0.0f
|
||||
|
||||
private val negotiator = object : InventoryNegotiator {
|
||||
override fun getItemFilter(): List<String> = listOf(CAT_ALL)
|
||||
|
||||
override fun accept(item: GameItem, amount: Int) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun reject(item: GameItem, amount: Int) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
|
||||
override fun getNegotiator() = negotiator
|
||||
|
||||
override fun getFixtureInventory() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getPlayerInventory() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
init {
|
||||
handler.allowESCtoClose = true
|
||||
}
|
||||
|
||||
private val catBar = UIItemInventoryCatBar(
|
||||
this,
|
||||
100,
|
||||
50,
|
||||
500,
|
||||
500,
|
||||
{},
|
||||
false
|
||||
)
|
||||
|
||||
private val itemList = UIItemInventoryItemGrid(
|
||||
this,
|
||||
catBar,
|
||||
Terrarum.ingame!!.actorNowPlaying!!.inventory, // just for a placeholder...
|
||||
100,
|
||||
100,
|
||||
4, 5,
|
||||
drawScrollOnRightside = true,
|
||||
drawWallet = true,
|
||||
listRebuildFun = { itemListUpdate() }
|
||||
)
|
||||
|
||||
private fun itemListUpdate() {
|
||||
itemList.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
catBar.update(delta)
|
||||
itemList.update(delta)
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
batch.color = Color.WHITE
|
||||
|
||||
itemList.render(batch, camera)
|
||||
}
|
||||
|
||||
override fun doOpening(delta: Float) {
|
||||
Terrarum.ingame?.paused = true
|
||||
}
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
Terrarum.ingame?.paused = false
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,13 @@ import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameitem.GameItem
|
||||
import net.torvald.terrarum.gameitem.ItemID
|
||||
import net.torvald.terrarum.itemproperties.Material
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureCraftingTable
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureStorageChest
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureTikiTorch
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2019-07-08.
|
||||
*/
|
||||
class ItemCraftingTable(originalID: ItemID) : GameItem(originalID) {
|
||||
class ItemStorageChest(originalID: ItemID) : GameItem(originalID) {
|
||||
|
||||
override var dynamicID: ItemID = originalID
|
||||
override val originalName = "ITEM_CRAFTING_TABLE"
|
||||
@@ -22,7 +22,7 @@ class ItemCraftingTable(originalID: ItemID) : GameItem(originalID) {
|
||||
override val isUnique = false
|
||||
override val isDynamic = false
|
||||
override val material = Material()
|
||||
override val itemImage: TextureRegion?
|
||||
override val itemImage: TextureRegion
|
||||
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_16")
|
||||
override var baseToolSize: Double? = baseMass
|
||||
|
||||
@@ -31,7 +31,7 @@ class ItemCraftingTable(originalID: ItemID) : GameItem(originalID) {
|
||||
}
|
||||
|
||||
override fun startPrimaryUse(delta: Float): Boolean {
|
||||
val item = FixtureCraftingTable()
|
||||
val item = FixtureStorageChest()
|
||||
|
||||
return item.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - item.blockBox.height + 1)
|
||||
// return true when placed, false when cannot be placed
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
interface HasInventory {
|
||||
|
||||
fun getNegotiator(): InventoryNegotiator
|
||||
fun getFixtureInventory()
|
||||
fun getPlayerInventory()
|
||||
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user