inventory ui itemgrid:removed inventoryfull dependency

This commit is contained in:
minjaesong
2021-03-12 10:38:53 +09:00
parent ae3bf663e0
commit bd89ca67fb
9 changed files with 123 additions and 106 deletions

View File

@@ -9,7 +9,6 @@ import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVEN_DEBUG_MODE
import net.torvald.terrarum.ui.UICanvas
import kotlin.math.roundToInt
internal class UIInventoryCells(
val full: UIInventoryFull
@@ -20,7 +19,7 @@ internal class UIInventoryCells(
override var openCloseTime: Second = 0.0f
private val weightBarWidth = UIItemInventoryElemSimple.height * 2f + UIItemInventoryDynamicList.listGap
private val weightBarWidth = UIItemInventoryElemSimple.height * 2f + UIItemInventoryItemGrid.listGap
internal var encumbrancePerc = 0f
private set
@@ -28,13 +27,15 @@ internal class UIInventoryCells(
private set
internal val itemList: UIItemInventoryDynamicList =
UIItemInventoryDynamicList(
internal val itemList: UIItemInventoryItemGrid =
UIItemInventoryItemGrid(
full,
full.catBar,
full.actor.inventory,
full.INVENTORY_CELLS_OFFSET_X,
full.INVENTORY_CELLS_OFFSET_Y,
full.CELLS_HOR, full.CELLS_VRT
full.CELLS_HOR, full.CELLS_VRT,
listRebuildFun = { rebuildList() }
)
@@ -55,7 +56,7 @@ internal class UIInventoryCells(
fun rebuildList() {
AppLoader.printdbg(this, "rebuilding list")
itemList.rebuild(full.catIconsMeaning[full.categoryBar.selectedIcon])
itemList.rebuild(full.catBar.catIconsMeaning[full.catBar.selectedIcon])
equipped.rebuild()
encumbrancePerc = full.actor.inventory.capacity.toFloat() / full.actor.inventory.maxCapacity
@@ -64,7 +65,7 @@ internal class UIInventoryCells(
fun resetStatusAsCatChanges(oldcat: Int?, newcat: Int) {
itemList.itemPage = 0 // set scroll to zero
itemList.rebuild(full.catIconsMeaning[full.catArrangement[newcat]]) // have to manually rebuild, too!
itemList.rebuild(full.catBar.catIconsMeaning[full.catBar.catArrangement[newcat]]) // have to manually rebuild, too!
}
override fun updateUI(delta: Float) {

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
@@ -8,13 +7,10 @@ import net.torvald.ENDASH
import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.*
import net.torvald.terrarum.blockstats.MinimapComposer
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryDynamicList.Companion.CAT_ALL
import net.torvald.terrarum.ui.*
import net.torvald.terrarum.ui.UIItemTextButtonList.Companion.DEFAULT_LINE_HEIGHT
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
@@ -36,17 +32,17 @@ class UIInventoryFull(
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 + UIItemInventoryDynamicList.listGap) / // 134 is another magic number
(UIItemInventoryElemSimple.height + UIItemInventoryDynamicList.listGap)
val CELLS_VRT: Int; get() = (AppLoader.screenH - REQUIRED_MARGIN - 134 + UIItemInventoryItemGrid.listGap) / // 134 is another magic number
(UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap)
private val itemListToEquipViewGap = UIItemInventoryDynamicList.listGap // used to be 24; figured out that the extra gap does nothig
private val itemListToEquipViewGap = UIItemInventoryItemGrid.listGap // used to be 24; figured out that the extra gap does nothig
val internalWidth: Int = UIItemInventoryDynamicList.getEstimatedW(CELLS_HOR) + UIItemInventoryEquippedView.WIDTH + itemListToEquipViewGap
val internalHeight: Int = REQUIRED_MARGIN + UIItemInventoryDynamicList.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.UIItemInventoryDynamicList.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) * UIItemInventoryDynamicList.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
@@ -58,22 +54,6 @@ class UIInventoryFull(
CommonResourcePool.loadAll()
}
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
arrayOf(GameItem.Category.WEAPON),
arrayOf(GameItem.Category.TOOL, GameItem.Category.WIRE),
arrayOf(GameItem.Category.ARMOUR),
arrayOf(GameItem.Category.GENERIC),
arrayOf(GameItem.Category.POTION),
arrayOf(GameItem.Category.MAGIC),
arrayOf(GameItem.Category.BLOCK),
arrayOf(GameItem.Category.WALL),
arrayOf(GameItem.Category.MISC),
arrayOf(CAT_ALL)
)
private val SP = "${0x3000.toChar()} "
val listControlHelp: String
get() = if (AppLoader.environment == RunningEnvironment.PC)
@@ -105,11 +85,14 @@ class UIInventoryFull(
val controlHelpHeight = AppLoader.fontGame.lineHeight
val catBarWidth = 330
val categoryBar = UIItemInventoryCatBar(
val catBar = UIItemInventoryCatBar(
this,
(AppLoader.screenW - catBarWidth) / 2,
42 + (AppLoader.screenH - internalHeight) / 2,
catBarWidth
internalWidth,
catBarWidth,
{ i -> requestTransition(i) },
true
)
@@ -128,10 +111,10 @@ class UIInventoryFull(
init {
addUIitem(categoryBar)
addUIitem(catBar)
addUIitem(transitionPanel)
categoryBar.selectionChangeListener = { old, new ->
catBar.selectionChangeListener = { old, new ->
rebuildList()
transitionalItemCells.resetStatusAsCatChanges(old, new)
}
@@ -154,7 +137,7 @@ class UIInventoryFull(
rebuildList()
}
categoryBar.update(delta)
catBar.update(delta)
transitionPanel.update(delta)
}
@@ -193,7 +176,7 @@ class UIInventoryFull(
batch.begin()
// UI items
categoryBar.render(batch, camera)
catBar.render(batch, camera)
transitionPanel.render(batch, camera)
}
@@ -216,7 +199,7 @@ class UIInventoryFull(
}
override fun dispose() {
categoryBar.dispose()
catBar.dispose()
transitionPanel.dispose()
}

View File

@@ -8,6 +8,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.GdxColorMap
import net.torvald.terrarum.abs
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem
import kotlin.math.roundToInt
@@ -17,7 +18,7 @@ import kotlin.math.roundToInt
* Created by minjaesong on 2017-10-22.
*/
abstract class UIItemInventoryCellBase(
parentUI: UIInventoryFull,
parentUI: UICanvas,
initialX: Int,
initialY: Int,
open var item: GameItem?,

View File

@@ -13,7 +13,6 @@ import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BL
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.Toolkit.DEFAULT_BOX_BORDER_COL
import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
* Created by minjaesong on 2017-10-28.
@@ -31,7 +30,7 @@ class UIItemInventoryEquippedView(
override val height = parentUI.itemListHeight
companion object {
val WIDTH = 2 * UIItemInventoryElemSimple.height + UIItemInventoryDynamicList.listGap
val WIDTH = 2 * UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap
//val HEIGHT = UIItemInventoryDynamicList.HEIGHT
val SPRITE_DRAW_COL = Color(0xddddddff.toInt())
}
@@ -62,7 +61,8 @@ class UIItemInventoryEquippedView(
mouseoverBackBlendMode = BlendMode.SCREEN,
backCol = CELLCOLOUR_BLACK,
backBlendMode = BlendMode.NORMAL,
drawBackOnNull = true
drawBackOnNull = true,
listRebuildFun = { parentUI.rebuildList() } // to "unselect" the equipped item and main item grid would "untick" accordingly
)
}

View File

@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
import net.torvald.terrarum.UIItemInventoryCatBar.Companion.CAT_ALL
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.TerrarumIngame
@@ -12,6 +13,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
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.INVEN_DEBUG_MODE
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarum.ui.UIItemImageButton
import net.torvald.terrarum.ui.UIItemTextButton.Companion.defaultActiveCol
@@ -29,15 +31,17 @@ import java.util.*
*
* Created by minjaesong on 2017-10-21.
*/
class UIItemInventoryDynamicList(
parentUI: UIInventoryFull,
class UIItemInventoryItemGrid(
parentUI: UICanvas,
val catBar: UIItemInventoryCatBar,
val inventory: ActorInventory, // when you're going to display List of Craftables, you could implement a Delegator...? Or just build a virtual inventory
initialX: Int,
initialY: Int,
val horizontalCells: Int,
val verticalCells: Int,
val drawScrollOnRightside: Boolean = false,
val drawWallet: Boolean = true
val drawWallet: Boolean = true,
val listRebuildFun: () -> Unit
) : UIItem(parentUI, initialX, initialY) {
// deal with the moving position
@@ -50,8 +54,6 @@ class UIItemInventoryDynamicList(
val largeListWidth = (horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 2) * listGap) / 2
val backColour = CELLCOLOUR_BLACK
private val catArrangement = parentUI.catArrangement
init {
CommonResourcePool.addToLoadingList("inventory_walletnumberfont") {
TextureRegionPack("./assets/graphics/fonts/inventory_wallet_numbers.tga", 20, 9)
@@ -76,9 +78,6 @@ class UIItemInventoryDynamicList(
private val inventoryUI = parentUI
//private val selectedIcon: Int
// get() = inventoryUI.catSelectedIcon
var itemPage = 0
set(value) {
field = if (itemPageCount == 0) 0 else (value).fmod(itemPageCount)
@@ -109,8 +108,6 @@ class UIItemInventoryDynamicList(
fun getEstimatedW(horizontalCells: Int) = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
fun getEstimatedH(verticalCells: Int) = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
const val CAT_ALL = "__all__"
}
private val itemGrid = Array<UIItemInventoryCellBase>(horizontalCells * verticalCells) {
@@ -126,7 +123,8 @@ class UIItemInventoryDynamicList(
backCol = backColour,
backBlendMode = BlendMode.NORMAL,
drawBackOnNull = true,
inactiveTextCol = defaultTextColour
inactiveTextCol = defaultTextColour,
listRebuildFun = listRebuildFun
)
}
// TODO automatically determine how much columns are needed. Minimum Width = 5 grids
@@ -144,7 +142,8 @@ class UIItemInventoryDynamicList(
backCol = backColour,
backBlendMode = BlendMode.NORMAL,
drawBackOnNull = true,
inactiveTextCol = defaultTextColour
inactiveTextCol = defaultTextColour,
listRebuildFun = listRebuildFun
)
}
@@ -160,16 +159,16 @@ class UIItemInventoryDynamicList(
private val iconPosX = if (drawScrollOnRightside)
posX + width + LIST_TO_CONTROL_GAP
else
posX - LIST_TO_CONTROL_GAP - parentUI.catIcons.tileW + 2
posX - LIST_TO_CONTROL_GAP - catBar.catIcons.tileW + 2
private fun getIconPosY(index: Int) =
posY - 2 + (4 + UIItemInventoryElem.height - (parentUI as UIInventoryFull).catIcons.tileH) * index
posY - 2 + (4 + UIItemInventoryElem.height - catBar.catIcons.tileH) * index
/** Long/compact mode buttons */
private val gridModeButtons = Array<UIItemImageButton>(2) { index ->
UIItemImageButton(
parentUI,
parentUI.catIcons.get(index + 14, 0),
catBar.catIcons.get(index + 14, 0),
backgroundCol = Color(0),
activeBackCol = Color(0),
highlightBackCol = Color(0),
@@ -183,7 +182,7 @@ class UIItemInventoryDynamicList(
private val scrollUpButton = UIItemImageButton(
parentUI,
parentUI.catIcons.get(18, 0),
catBar.catIcons.get(18, 0),
backgroundCol = Color(0),
activeBackCol = Color(0),
activeBackBlendMode = BlendMode.NORMAL,
@@ -195,7 +194,7 @@ class UIItemInventoryDynamicList(
private val scrollDownButton = UIItemImageButton(
parentUI,
parentUI.catIcons.get(19, 0),
catBar.catIcons.get(19, 0),
backgroundCol = Color(0),
activeBackCol = Color(0),
activeBackBlendMode = BlendMode.NORMAL,
@@ -272,7 +271,7 @@ class UIItemInventoryDynamicList(
batch.color = colour
batch.draw(
(parentUI as UIInventoryFull).catIcons.get(if (i == itemPage) 20 else 21, 0),
catBar.catIcons.get(if (i == itemPage) 20 else 21, 0),
scrollUpButton.posX.toFloat(),
getScrollDotYHeight(i).toFloat()
)