two column inventory for storagechest wip

This commit is contained in:
minjaesong
2021-03-16 11:51:32 +09:00
parent 0496366057
commit 76f5d0a924
6 changed files with 115 additions and 52 deletions

View File

@@ -3,16 +3,23 @@ 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 com.badlogic.gdx.graphics.glutils.ShapeRenderer
import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.printdbg
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.UIInventoryFull.Companion.CELLS_HOR
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELLS_VRT
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_X
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.catBarWidth
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.gradEndCol
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.gradHeight
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.gradStartCol
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.internalHeight
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.internalWidth
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -41,10 +48,13 @@ internal class FixtureStorageChest : FixtureBase(
internal object UIStorageChest : UICanvas(), HasInventory {
override var width = 512
override var height = 512
override var width = AppLoader.screenW
override var height = AppLoader.screenH
override var openCloseTime: Second = 0.0f
private val shapeRenderer = ShapeRenderer()
private val negotiator = object : InventoryNegotiator() {
override fun accept(item: GameItem, amount: Int) {
printdbg(this, "Accept")
@@ -65,17 +75,16 @@ internal object UIStorageChest : UICanvas(), HasInventory {
TODO("Not yet implemented")
}
private lateinit var catBar: UIItemInventoryCatBar
private lateinit var itemList: UIItemInventoryItemGrid
private var catBar: UIItemInventoryCatBar
private var itemList: UIItemInventoryItemGrid
init {
catBar = UIItemInventoryCatBar(
this,
100,
50,
500,
500,
(AppLoader.screenW - catBarWidth) / 2,
42 + (AppLoader.screenH - internalHeight) / 2,
internalWidth,
catBarWidth,
false
)
catBar.selectionChangeListener = { old, new -> itemListUpdate() }
@@ -83,11 +92,11 @@ internal object UIStorageChest : UICanvas(), HasInventory {
this,
catBar,
Terrarum.ingame!!.actorNowPlaying!!.inventory, // just for a placeholder...
100,
100,
4, 5,
INVENTORY_CELLS_OFFSET_X,
INVENTORY_CELLS_OFFSET_Y,
CELLS_HOR / 2, CELLS_VRT,
drawScrollOnRightside = false,
drawWallet = true,
drawWallet = false,
keyDownFun = { _,_ -> Unit },
touchDownFun = { _,_,_,_,_ -> itemListUpdate() }
)
@@ -108,6 +117,28 @@ internal object UIStorageChest : UICanvas(), HasInventory {
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// background fill
batch.end()
gdxSetBlendNormal()
val gradTopStart = (AppLoader.screenH - internalHeight).div(2).toFloat()
val gradBottomEnd = AppLoader.screenH - gradTopStart
shapeRenderer.inUse {
shapeRenderer.rect(0f, gradTopStart, AppLoader.screenWf, gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
shapeRenderer.rect(0f, gradBottomEnd, AppLoader.screenWf, -gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
shapeRenderer.rect(0f, gradTopStart + gradHeight, AppLoader.screenWf, internalHeight - (2 * gradHeight), gradEndCol, gradEndCol, gradEndCol, gradEndCol)
shapeRenderer.rect(0f, 0f, AppLoader.screenWf, gradTopStart, gradStartCol, gradStartCol, gradStartCol, gradStartCol)
shapeRenderer.rect(0f, AppLoader.screenHf, AppLoader.screenWf, -(AppLoader.screenHf - gradBottomEnd), gradStartCol, gradStartCol, gradStartCol, gradStartCol)
}
batch.begin()
// UI items
batch.color = Color.WHITE
catBar.render(batch, camera)
@@ -129,7 +160,7 @@ internal object UIStorageChest : UICanvas(), HasInventory {
}
override fun dispose() {
shapeRenderer.dispose()
}
}

View File

@@ -7,6 +7,11 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELLS_HOR
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELLS_VRT
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_X
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.internalWidth
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVEN_DEBUG_MODE
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericKeyDownFun
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericTouchDownFun
@@ -34,9 +39,9 @@ internal class UIInventoryCells(
full,
full.catBar,
full.actor.inventory,
full.INVENTORY_CELLS_OFFSET_X,
full.INVENTORY_CELLS_OFFSET_Y,
full.CELLS_HOR, full.CELLS_VRT,
INVENTORY_CELLS_OFFSET_X,
INVENTORY_CELLS_OFFSET_Y,
CELLS_HOR, CELLS_VRT,
keyDownFun = createInvCellGenericKeyDownFun(),
touchDownFun = createInvCellGenericTouchDownFun { rebuildList() }
)
@@ -47,8 +52,8 @@ internal class UIInventoryCells(
full,
full.actor.inventory,
full.actor as ActorWithBody,
full.internalWidth - UIItemInventoryEquippedView.WIDTH + (AppLoader.screenW - full.internalWidth) / 2,
full.INVENTORY_CELLS_OFFSET_Y
internalWidth - UIItemInventoryEquippedView.WIDTH + (AppLoader.screenW - internalWidth) / 2,
INVENTORY_CELLS_OFFSET_Y
)
init {

View File

@@ -7,6 +7,8 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.TitleScreen
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_UI_HEIGHT
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextButtonList
import net.torvald.terrarum.ui.UIItemTextButtonList.Companion.DEFAULT_LINE_HEIGHT
@@ -23,7 +25,7 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
private val gameMenuButtons = UIItemTextButtonList(
this, gameMenu,
(AppLoader.screenW - gameMenuListWidth) / 2,
full.INVENTORY_CELLS_OFFSET_Y + (full.INVENTORY_CELLS_UI_HEIGHT - gameMenuListHeight) / 2,
INVENTORY_CELLS_OFFSET_Y + (INVENTORY_CELLS_UI_HEIGHT - gameMenuListHeight) / 2,
gameMenuListWidth, gameMenuListHeight,
readFromLang = true,
textAreaWidth = gameMenuListWidth,

View File

@@ -29,22 +29,48 @@ class UIInventoryFull(
override var height: Int = AppLoader.screenH
override var openCloseTime: Second = 0.0f
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
companion object {
const val INVEN_DEBUG_MODE = true
val CELLS_HOR = 10
val CELLS_VRT: Int; get() = (AppLoader.screenH - REQUIRED_MARGIN - 134 + UIItemInventoryItemGrid.listGap) / // 134 is another magic number
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
val CELLS_VRT: Int; get() = (AppLoader.screenH - REQUIRED_MARGIN - 134 + UIItemInventoryItemGrid.listGap) / // 134 is another magic number
(UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap)
private val itemListToEquipViewGap = UIItemInventoryItemGrid.listGap // used to be 24; figured out that the extra gap does nothig
const val itemListToEquipViewGap = UIItemInventoryItemGrid.listGap // used to be 24; figured out that the extra gap does nothig
val internalWidth: Int = UIItemInventoryItemGrid.getEstimatedW(CELLS_HOR) + UIItemInventoryEquippedView.WIDTH + itemListToEquipViewGap
val internalHeight: Int = REQUIRED_MARGIN + UIItemInventoryItemGrid.getEstimatedH(CELLS_VRT) // grad_begin..grad_end..contents..grad_begin..grad_end
val internalWidth: Int = UIItemInventoryItemGrid.getEstimatedW(CELLS_HOR) + UIItemInventoryEquippedView.WIDTH + itemListToEquipViewGap
val internalHeight: Int = REQUIRED_MARGIN + UIItemInventoryItemGrid.getEstimatedH(CELLS_VRT) // grad_begin..grad_end..contents..grad_begin..grad_end
val itemListHeight: Int = CELLS_VRT * UIItemInventoryElemSimple.height + (CELLS_VRT - 1) * net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.listGap
val itemListHeight: Int = CELLS_VRT * UIItemInventoryElemSimple.height + (CELLS_VRT - 1) * net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.listGap
val INVENTORY_CELLS_UI_HEIGHT: Int = CELLS_VRT * UIItemInventoryElemSimple.height + (CELLS_VRT - 1) * UIItemInventoryItemGrid.listGap
val INVENTORY_CELLS_OFFSET_X = 0 + (AppLoader.screenW - internalWidth) / 2
val INVENTORY_CELLS_OFFSET_Y: Int = 107 + (AppLoader.screenH - internalHeight) / 2
val INVENTORY_CELLS_UI_HEIGHT: Int = CELLS_VRT * UIItemInventoryElemSimple.height + (CELLS_VRT - 1) * UIItemInventoryItemGrid.listGap
val INVENTORY_CELLS_OFFSET_X = 0 + (AppLoader.screenW - internalWidth) / 2
val INVENTORY_CELLS_OFFSET_Y: Int = 107 + (AppLoader.screenH - internalHeight) / 2
val catBarWidth = 330
val gradStartCol = Color(0x404040_60)
val gradEndCol = Color(0x000000_70)
val gradHeight = 48f
}
//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
//val CELLS_HOR = 10
//val CELLS_VRT: Int; get() = (AppLoader.screenH - REQUIRED_MARGIN - 134 + UIItemInventoryItemGrid.listGap) / // 134 is another magic number
// (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap)
//private val itemListToEquipViewGap = UIItemInventoryItemGrid.listGap // used to be 24; figured out that the extra gap does nothig
//val internalWidth: Int = UIItemInventoryItemGrid.getEstimatedW(CELLS_HOR) + UIItemInventoryEquippedView.WIDTH + itemListToEquipViewGap
//val internalHeight: Int = REQUIRED_MARGIN + UIItemInventoryItemGrid.getEstimatedH(CELLS_VRT) // grad_begin..grad_end..contents..grad_begin..grad_end
//val itemListHeight: Int = CELLS_VRT * UIItemInventoryElemSimple.height + (CELLS_VRT - 1) * net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.listGap
//val INVENTORY_CELLS_UI_HEIGHT: Int = CELLS_VRT * UIItemInventoryElemSimple.height + (CELLS_VRT - 1) * UIItemInventoryItemGrid.listGap
//val INVENTORY_CELLS_OFFSET_X = 0 + (AppLoader.screenW - internalWidth) / 2
//val INVENTORY_CELLS_OFFSET_Y: Int = 107 + (AppLoader.screenH - internalHeight) / 2
init {
handler.allowESCtoClose = true
@@ -84,7 +110,7 @@ class UIInventoryFull(
"$gamepadLabelLT ${Lang["GAME_INVENTORY"]}"
val controlHelpHeight = AppLoader.fontGame.lineHeight
val catBarWidth = 330
//val catBarWidth = 330
val catBar = UIItemInventoryCatBar(
this,
(AppLoader.screenW - catBarWidth) / 2,
@@ -141,10 +167,10 @@ class UIInventoryFull(
transitionPanel.update(delta)
}
private val gradStartCol = Color(0x404040_60)
private val gradEndCol = Color(0x000000_70)
//private val gradStartCol = Color(0x404040_60)
//private val gradEndCol = Color(0x000000_70)
//private val gradHeight = 48f
private val shapeRenderer = ShapeRenderer()
private val gradHeight = 48f
internal var xEnd = (AppLoader.screenW + internalWidth).div(2).toFloat()
private set
@@ -236,9 +262,5 @@ class UIInventoryFull(
xEnd = (AppLoader.screenW + internalWidth).div(2).toFloat()
yEnd = (AppLoader.screenH + internalHeight).div(2).toFloat()
}
companion object {
const val INVEN_DEBUG_MODE = false
}
}

View File

@@ -7,6 +7,8 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.FrameBuffer
import net.torvald.terrarum.*
import net.torvald.terrarum.blockstats.MinimapComposer
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_UI_HEIGHT
import net.torvald.terrarum.ui.UICanvas
class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
@@ -18,7 +20,7 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
override var openCloseTime = 0.0f
private val MINIMAP_WIDTH = 800f
private val MINIMAP_HEIGHT = full.INVENTORY_CELLS_UI_HEIGHT.toFloat()
private val MINIMAP_HEIGHT = INVENTORY_CELLS_UI_HEIGHT.toFloat()
private val MINIMAP_SKYCOL = Color(0x88bbddff.toInt())
private var minimapZoom = 1f
private var minimapPanX = -MinimapComposer.totalWidth / 2f
@@ -43,7 +45,7 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
// update map panning
// if left click is down and cursor is in the map area
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("config_mouseprimary")) &&
Terrarum.mouseScreenY in full.INVENTORY_CELLS_OFFSET_Y..full.INVENTORY_CELLS_OFFSET_Y + full.INVENTORY_CELLS_UI_HEIGHT) {
Terrarum.mouseScreenY in INVENTORY_CELLS_OFFSET_Y..INVENTORY_CELLS_OFFSET_Y + INVENTORY_CELLS_UI_HEIGHT) {
minimapPanX += Terrarum.mouseDeltaX * 2f / minimapZoom
minimapPanY += Terrarum.mouseDeltaY * 2f / minimapZoom
}
@@ -113,23 +115,23 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
batch.begin()
if (debugvals) {
AppLoader.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; x$minimapZoom", (AppLoader.screenW - MINIMAP_WIDTH) / 2, -10f + full.INVENTORY_CELLS_OFFSET_Y)
AppLoader.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; x$minimapZoom", (AppLoader.screenW - MINIMAP_WIDTH) / 2, -10f + INVENTORY_CELLS_OFFSET_Y)
}
batch.projectionMatrix = camera.combined
// 1px stroke
batch.color = Color.WHITE
batch.fillRect((AppLoader.screenW - MINIMAP_WIDTH) / 2, -1 + full.INVENTORY_CELLS_OFFSET_Y.toFloat(), MINIMAP_WIDTH, 1f)
batch.fillRect((AppLoader.screenW - MINIMAP_WIDTH) / 2, full.INVENTORY_CELLS_OFFSET_Y + MINIMAP_HEIGHT, MINIMAP_WIDTH, 1f)
batch.fillRect(-1 + (AppLoader.screenW - MINIMAP_WIDTH) / 2, full.INVENTORY_CELLS_OFFSET_Y.toFloat(), 1f, MINIMAP_HEIGHT)
batch.fillRect((AppLoader.screenW - MINIMAP_WIDTH) / 2 + MINIMAP_WIDTH, full.INVENTORY_CELLS_OFFSET_Y.toFloat(), 1f, MINIMAP_HEIGHT)
batch.fillRect((AppLoader.screenW - MINIMAP_WIDTH) / 2, -1 + INVENTORY_CELLS_OFFSET_Y.toFloat(), MINIMAP_WIDTH, 1f)
batch.fillRect((AppLoader.screenW - MINIMAP_WIDTH) / 2, INVENTORY_CELLS_OFFSET_Y + MINIMAP_HEIGHT, MINIMAP_WIDTH, 1f)
batch.fillRect(-1 + (AppLoader.screenW - MINIMAP_WIDTH) / 2, INVENTORY_CELLS_OFFSET_Y.toFloat(), 1f, MINIMAP_HEIGHT)
batch.fillRect((AppLoader.screenW - MINIMAP_WIDTH) / 2 + MINIMAP_WIDTH, INVENTORY_CELLS_OFFSET_Y.toFloat(), 1f, MINIMAP_HEIGHT)
// control hints
batch.color = Color.WHITE
AppLoader.fontGame.draw(batch, full.minimapControlHelp, full.offsetX, full.yEnd - 20)
// the minimap
batch.draw(minimapFBO.colorBufferTexture, (AppLoader.screenW - MINIMAP_WIDTH) / 2, full.INVENTORY_CELLS_OFFSET_Y.toFloat())
batch.draw(minimapFBO.colorBufferTexture, (AppLoader.screenW - MINIMAP_WIDTH) / 2, INVENTORY_CELLS_OFFSET_Y.toFloat())
}
override fun doOpening(delta: Float) {}

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK_ACTIVE
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.itemListHeight
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericKeyDownFun
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericTouchDownFun
import net.torvald.terrarum.ui.Toolkit
@@ -29,7 +30,7 @@ class UIItemInventoryEquippedView(
override val width = WIDTH
override val height = parentUI.itemListHeight
override val height = itemListHeight
companion object {
val WIDTH = 2 * UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap