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

@@ -5,26 +5,48 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Pixmap import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarum.ui.UIItemImageButton import net.torvald.terrarum.ui.UIItemImageButton
import net.torvald.terrarum.ui.UIUtils import net.torvald.terrarum.ui.UIUtils
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import kotlin.math.roundToInt import kotlin.math.roundToInt
/** /**
* Created by minjaesong on 2017-10-20. * Created by minjaesong on 2017-10-20.
*/ */
class UIItemInventoryCatBar( class UIItemInventoryCatBar(
parentUI: UIInventoryFull, parentUI: UICanvas,
initialX: Int, initialX: Int,
initialY: Int, initialY: Int,
override val width: Int uiInternalWidth: Int,
override val width: Int,
val transitionReqFun: (Int) -> Unit,
val showSideButtons: Boolean
) : UIItem(parentUI, initialX, initialY) { ) : UIItem(parentUI, initialX, initialY) {
private val parentInventory = parentUI companion object {
const val CAT_ALL = "__all__"
}
private val catIcons = parentUI.catIcons //private val parentInventory = parentUI
private val catArrangement = parentUI.catArrangement
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 inventoryUI = parentUI private val inventoryUI = parentUI
@@ -66,8 +88,8 @@ class UIItemInventoryCatBar(
// side buttons // side buttons
// NOTE: < > arrows must "highlightable = false"; "true" otherwise // NOTE: < > arrows must "highlightable = false"; "true" otherwise
// determine gaps: hacky way exploiting that we already know the catbar is always at the c of the ui // determine gaps: hacky way exploiting that we already know the catbar is always at the c of the ui
val relativeStartX = posX - (parentUI.internalWidth - width) / 2 val relativeStartX = posX - (uiInternalWidth - width) / 2
val sideButtonsGap = (((parentUI.internalWidth - width) / 2) - 2f * catIcons.tileW) / 3f val sideButtonsGap = (((uiInternalWidth - width) / 2) - 2f * catIcons.tileW) / 3f
val iconIndex = arrayOf(12, 16, 17, 13) val iconIndex = arrayOf(12, 16, 17, 13)
@@ -196,33 +218,35 @@ class UIItemInventoryCatBar(
} }
} }
sideButtons[0].update(delta) if (showSideButtons) {
sideButtons[3].update(delta) sideButtons[0].update(delta)
sideButtons[3].update(delta)
// more transition stuffs
if (sideButtons[0].mousePushed) {
if (selectedPanel != 0) transitionFired = true
mainButtons.forEach { it.highlighted = false }
selectedPanel = 0
sideButtons[0].highlighted = true
sideButtons[3].highlighted = false
}
else if (sideButtons[3].mousePushed) {
if (selectedPanel != 2) transitionFired = true
mainButtons.forEach { it.highlighted = false }
selectedPanel = 2
transitionFired = true
sideButtons[0].highlighted = false
sideButtons[3].highlighted = true
}
// more transition stuffs if (transitionFired) {
if (sideButtons[0].mousePushed) { transitionFired = false
if (selectedPanel != 0) transitionFired = true //parentInventory.requestTransition(selectedPanel)
mainButtons.forEach { it.highlighted = false } transitionReqFun(selectedPanel)
selectedPanel = 0 }
sideButtons[0].highlighted = true
sideButtons[3].highlighted = false
}
else if (sideButtons[3].mousePushed) {
if (selectedPanel != 2) transitionFired = true
mainButtons.forEach { it.highlighted = false }
selectedPanel = 2
transitionFired = true
sideButtons[0].highlighted = false
sideButtons[3].highlighted = true
}
if (transitionFired) {
transitionFired = false
parentInventory.requestTransition(selectedPanel)
} }
} }
@@ -232,7 +256,7 @@ class UIItemInventoryCatBar(
// button // button
// colour determined by UI items themselves // colour determined by UI items themselves
mainButtons.forEach { it.render(batch, camera) } mainButtons.forEach { it.render(batch, camera) }
sideButtons.forEach { it.render(batch, camera) } if (showSideButtons) sideButtons.forEach { it.render(batch, camera) }
blendNormal(batch) blendNormal(batch)

View File

@@ -16,6 +16,7 @@ import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.Toolkit.DEFAULT_BOX_BORDER_COL import net.torvald.terrarum.ui.Toolkit.DEFAULT_BOX_BORDER_COL
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextButton import net.torvald.terrarum.ui.UIItemTextButton
/*** /***
@@ -24,7 +25,7 @@ import net.torvald.terrarum.ui.UIItemTextButton
* Created by minjaesong on 2017-03-16. * Created by minjaesong on 2017-03-16.
*/ */
class UIItemInventoryElem( class UIItemInventoryElem(
parentUI: UIInventoryFull, parentUI: UICanvas,
initialX: Int, initialX: Int,
initialY: Int, initialY: Int,
override val width: Int, override val width: Int,
@@ -39,7 +40,8 @@ class UIItemInventoryElem(
val backBlendMode: String = BlendMode.NORMAL, val backBlendMode: String = BlendMode.NORMAL,
override var quickslot: Int? = null, override var quickslot: Int? = null,
override var equippedSlot: Int? = null, override var equippedSlot: Int? = null,
val drawBackOnNull: Boolean = true val drawBackOnNull: Boolean = true,
val listRebuildFun: () -> Unit
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot) { ) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot) {
companion object { companion object {
@@ -49,8 +51,6 @@ class UIItemInventoryElem(
internal val durabilityBarThickness = 3f internal val durabilityBarThickness = 3f
} }
private val inventoryUI = parentUI
override val height = UIItemInventoryElem.height override val height = UIItemInventoryElem.height
private val imgOffset: Float private val imgOffset: Float
@@ -219,7 +219,7 @@ class UIItemInventoryElem(
} }
} }
inventoryUI.rebuildList() listRebuildFun()
return super.touchDown(screenX, screenY, pointer, button) return super.touchDown(screenX, screenY, pointer, button)
} }

View File

@@ -15,13 +15,14 @@ import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.Toolkit.DEFAULT_BOX_BORDER_COL import net.torvald.terrarum.ui.Toolkit.DEFAULT_BOX_BORDER_COL
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextButton import net.torvald.terrarum.ui.UIItemTextButton
/** /**
* Created by minjaesong on 2017-10-20. * Created by minjaesong on 2017-10-20.
*/ */
class UIItemInventoryElemSimple( class UIItemInventoryElemSimple(
parentUI: UIInventoryFull, parentUI: UICanvas,
initialX: Int, initialX: Int,
initialY: Int, initialY: Int,
override var item: GameItem?, override var item: GameItem?,
@@ -36,15 +37,14 @@ class UIItemInventoryElemSimple(
val highlightCol: Color = UIItemTextButton.defaultHighlightCol, val highlightCol: Color = UIItemTextButton.defaultHighlightCol,
override var quickslot: Int? = null, override var quickslot: Int? = null,
override var equippedSlot: Int? = null, override var equippedSlot: Int? = null,
val drawBackOnNull: Boolean = true val drawBackOnNull: Boolean = true,
val listRebuildFun: () -> Unit
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot) { ) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot) {
companion object { companion object {
val height = UIItemInventoryElem.height val height = UIItemInventoryElem.height
} }
private val inventoryUI = parentUI
override val width = UIItemInventoryElemSimple.height override val width = UIItemInventoryElemSimple.height
override val height = UIItemInventoryElemSimple.height override val height = UIItemInventoryElemSimple.height
@@ -191,7 +191,7 @@ class UIItemInventoryElemSimple(
} }
} }
inventoryUI.rebuildList() listRebuildFun()
return super.touchDown(screenX, screenY, pointer, button) return super.touchDown(screenX, screenY, pointer, button)
} }

View File

@@ -42,6 +42,15 @@ internal object UICraftingTable : UICanvas() {
handler.allowESCtoClose = true 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 updateUI(delta: Float) {
} }

View File

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

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.modulebasegame.ui package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.* import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShapeRenderer import com.badlogic.gdx.graphics.glutils.ShapeRenderer
@@ -8,13 +7,10 @@ import net.torvald.ENDASH
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.* import net.torvald.terrarum.AppLoader.*
import net.torvald.terrarum.blockstats.MinimapComposer import net.torvald.terrarum.blockstats.MinimapComposer
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.TerrarumIngame import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed 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.*
import net.torvald.terrarum.ui.UIItemTextButtonList.Companion.DEFAULT_LINE_HEIGHT
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack 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 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_HOR = 10
val CELLS_VRT: Int; get() = (AppLoader.screenH - REQUIRED_MARGIN - 134 + UIItemInventoryDynamicList.listGap) / // 134 is another magic number val CELLS_VRT: Int; get() = (AppLoader.screenH - REQUIRED_MARGIN - 134 + UIItemInventoryItemGrid.listGap) / // 134 is another magic number
(UIItemInventoryElemSimple.height + UIItemInventoryDynamicList.listGap) (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 internalWidth: Int = UIItemInventoryItemGrid.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 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_X = 0 + (AppLoader.screenW - internalWidth) / 2
val INVENTORY_CELLS_OFFSET_Y: Int = 107 + (AppLoader.screenH - internalHeight) / 2 val INVENTORY_CELLS_OFFSET_Y: Int = 107 + (AppLoader.screenH - internalHeight) / 2
@@ -58,22 +54,6 @@ class UIInventoryFull(
CommonResourcePool.loadAll() 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()} " private val SP = "${0x3000.toChar()} "
val listControlHelp: String val listControlHelp: String
get() = if (AppLoader.environment == RunningEnvironment.PC) get() = if (AppLoader.environment == RunningEnvironment.PC)
@@ -105,11 +85,14 @@ class UIInventoryFull(
val controlHelpHeight = AppLoader.fontGame.lineHeight val controlHelpHeight = AppLoader.fontGame.lineHeight
val catBarWidth = 330 val catBarWidth = 330
val categoryBar = UIItemInventoryCatBar( val catBar = UIItemInventoryCatBar(
this, this,
(AppLoader.screenW - catBarWidth) / 2, (AppLoader.screenW - catBarWidth) / 2,
42 + (AppLoader.screenH - internalHeight) / 2, 42 + (AppLoader.screenH - internalHeight) / 2,
catBarWidth internalWidth,
catBarWidth,
{ i -> requestTransition(i) },
true
) )
@@ -128,10 +111,10 @@ class UIInventoryFull(
init { init {
addUIitem(categoryBar) addUIitem(catBar)
addUIitem(transitionPanel) addUIitem(transitionPanel)
categoryBar.selectionChangeListener = { old, new -> catBar.selectionChangeListener = { old, new ->
rebuildList() rebuildList()
transitionalItemCells.resetStatusAsCatChanges(old, new) transitionalItemCells.resetStatusAsCatChanges(old, new)
} }
@@ -154,7 +137,7 @@ class UIInventoryFull(
rebuildList() rebuildList()
} }
categoryBar.update(delta) catBar.update(delta)
transitionPanel.update(delta) transitionPanel.update(delta)
} }
@@ -193,7 +176,7 @@ class UIInventoryFull(
batch.begin() batch.begin()
// UI items // UI items
categoryBar.render(batch, camera) catBar.render(batch, camera)
transitionPanel.render(batch, camera) transitionPanel.render(batch, camera)
} }
@@ -216,7 +199,7 @@ class UIInventoryFull(
} }
override fun dispose() { override fun dispose() {
categoryBar.dispose() catBar.dispose()
transitionPanel.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.GdxColorMap
import net.torvald.terrarum.abs import net.torvald.terrarum.abs
import net.torvald.terrarum.gameitem.GameItem import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem import net.torvald.terrarum.ui.UIItem
import kotlin.math.roundToInt import kotlin.math.roundToInt
@@ -17,7 +18,7 @@ import kotlin.math.roundToInt
* Created by minjaesong on 2017-10-22. * Created by minjaesong on 2017-10-22.
*/ */
abstract class UIItemInventoryCellBase( abstract class UIItemInventoryCellBase(
parentUI: UIInventoryFull, parentUI: UICanvas,
initialX: Int, initialX: Int,
initialY: Int, initialY: Int,
open var item: GameItem?, 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
import net.torvald.terrarum.ui.Toolkit.DEFAULT_BOX_BORDER_COL import net.torvald.terrarum.ui.Toolkit.DEFAULT_BOX_BORDER_COL
import net.torvald.terrarum.ui.UIItem import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/** /**
* Created by minjaesong on 2017-10-28. * Created by minjaesong on 2017-10-28.
@@ -31,7 +30,7 @@ class UIItemInventoryEquippedView(
override val height = parentUI.itemListHeight override val height = parentUI.itemListHeight
companion object { companion object {
val WIDTH = 2 * UIItemInventoryElemSimple.height + UIItemInventoryDynamicList.listGap val WIDTH = 2 * UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap
//val HEIGHT = UIItemInventoryDynamicList.HEIGHT //val HEIGHT = UIItemInventoryDynamicList.HEIGHT
val SPRITE_DRAW_COL = Color(0xddddddff.toInt()) val SPRITE_DRAW_COL = Color(0xddddddff.toInt())
} }
@@ -62,7 +61,8 @@ class UIItemInventoryEquippedView(
mouseoverBackBlendMode = BlendMode.SCREEN, mouseoverBackBlendMode = BlendMode.SCREEN,
backCol = CELLCOLOUR_BLACK, backCol = CELLCOLOUR_BLACK,
backBlendMode = BlendMode.NORMAL, 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.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.* import net.torvald.terrarum.*
import net.torvald.terrarum.UIItemInventoryCatBar.Companion.CAT_ALL
import net.torvald.terrarum.gameworld.fmod import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.TerrarumIngame 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
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK_ACTIVE 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.modulebasegame.ui.UIInventoryFull.Companion.INVEN_DEBUG_MODE
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarum.ui.UIItemImageButton import net.torvald.terrarum.ui.UIItemImageButton
import net.torvald.terrarum.ui.UIItemTextButton.Companion.defaultActiveCol import net.torvald.terrarum.ui.UIItemTextButton.Companion.defaultActiveCol
@@ -29,15 +31,17 @@ import java.util.*
* *
* Created by minjaesong on 2017-10-21. * Created by minjaesong on 2017-10-21.
*/ */
class UIItemInventoryDynamicList( class UIItemInventoryItemGrid(
parentUI: UIInventoryFull, 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 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, initialX: Int,
initialY: Int, initialY: Int,
val horizontalCells: Int, val horizontalCells: Int,
val verticalCells: Int, val verticalCells: Int,
val drawScrollOnRightside: Boolean = false, val drawScrollOnRightside: Boolean = false,
val drawWallet: Boolean = true val drawWallet: Boolean = true,
val listRebuildFun: () -> Unit
) : UIItem(parentUI, initialX, initialY) { ) : UIItem(parentUI, initialX, initialY) {
// deal with the moving position // deal with the moving position
@@ -50,8 +54,6 @@ class UIItemInventoryDynamicList(
val largeListWidth = (horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 2) * listGap) / 2 val largeListWidth = (horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 2) * listGap) / 2
val backColour = CELLCOLOUR_BLACK val backColour = CELLCOLOUR_BLACK
private val catArrangement = parentUI.catArrangement
init { init {
CommonResourcePool.addToLoadingList("inventory_walletnumberfont") { CommonResourcePool.addToLoadingList("inventory_walletnumberfont") {
TextureRegionPack("./assets/graphics/fonts/inventory_wallet_numbers.tga", 20, 9) TextureRegionPack("./assets/graphics/fonts/inventory_wallet_numbers.tga", 20, 9)
@@ -76,9 +78,6 @@ class UIItemInventoryDynamicList(
private val inventoryUI = parentUI private val inventoryUI = parentUI
//private val selectedIcon: Int
// get() = inventoryUI.catSelectedIcon
var itemPage = 0 var itemPage = 0
set(value) { set(value) {
field = if (itemPageCount == 0) 0 else (value).fmod(itemPageCount) 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 getEstimatedW(horizontalCells: Int) = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
fun getEstimatedH(verticalCells: Int) = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap fun getEstimatedH(verticalCells: Int) = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
const val CAT_ALL = "__all__"
} }
private val itemGrid = Array<UIItemInventoryCellBase>(horizontalCells * verticalCells) { private val itemGrid = Array<UIItemInventoryCellBase>(horizontalCells * verticalCells) {
@@ -126,7 +123,8 @@ class UIItemInventoryDynamicList(
backCol = backColour, backCol = backColour,
backBlendMode = BlendMode.NORMAL, backBlendMode = BlendMode.NORMAL,
drawBackOnNull = true, drawBackOnNull = true,
inactiveTextCol = defaultTextColour inactiveTextCol = defaultTextColour,
listRebuildFun = listRebuildFun
) )
} }
// TODO automatically determine how much columns are needed. Minimum Width = 5 grids // TODO automatically determine how much columns are needed. Minimum Width = 5 grids
@@ -144,7 +142,8 @@ class UIItemInventoryDynamicList(
backCol = backColour, backCol = backColour,
backBlendMode = BlendMode.NORMAL, backBlendMode = BlendMode.NORMAL,
drawBackOnNull = true, drawBackOnNull = true,
inactiveTextCol = defaultTextColour inactiveTextCol = defaultTextColour,
listRebuildFun = listRebuildFun
) )
} }
@@ -160,16 +159,16 @@ class UIItemInventoryDynamicList(
private val iconPosX = if (drawScrollOnRightside) private val iconPosX = if (drawScrollOnRightside)
posX + width + LIST_TO_CONTROL_GAP posX + width + LIST_TO_CONTROL_GAP
else else
posX - LIST_TO_CONTROL_GAP - parentUI.catIcons.tileW + 2 posX - LIST_TO_CONTROL_GAP - catBar.catIcons.tileW + 2
private fun getIconPosY(index: Int) = 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 */ /** Long/compact mode buttons */
private val gridModeButtons = Array<UIItemImageButton>(2) { index -> private val gridModeButtons = Array<UIItemImageButton>(2) { index ->
UIItemImageButton( UIItemImageButton(
parentUI, parentUI,
parentUI.catIcons.get(index + 14, 0), catBar.catIcons.get(index + 14, 0),
backgroundCol = Color(0), backgroundCol = Color(0),
activeBackCol = Color(0), activeBackCol = Color(0),
highlightBackCol = Color(0), highlightBackCol = Color(0),
@@ -183,7 +182,7 @@ class UIItemInventoryDynamicList(
private val scrollUpButton = UIItemImageButton( private val scrollUpButton = UIItemImageButton(
parentUI, parentUI,
parentUI.catIcons.get(18, 0), catBar.catIcons.get(18, 0),
backgroundCol = Color(0), backgroundCol = Color(0),
activeBackCol = Color(0), activeBackCol = Color(0),
activeBackBlendMode = BlendMode.NORMAL, activeBackBlendMode = BlendMode.NORMAL,
@@ -195,7 +194,7 @@ class UIItemInventoryDynamicList(
private val scrollDownButton = UIItemImageButton( private val scrollDownButton = UIItemImageButton(
parentUI, parentUI,
parentUI.catIcons.get(19, 0), catBar.catIcons.get(19, 0),
backgroundCol = Color(0), backgroundCol = Color(0),
activeBackCol = Color(0), activeBackCol = Color(0),
activeBackBlendMode = BlendMode.NORMAL, activeBackBlendMode = BlendMode.NORMAL,
@@ -272,7 +271,7 @@ class UIItemInventoryDynamicList(
batch.color = colour batch.color = colour
batch.draw( 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(), scrollUpButton.posX.toFloat(),
getScrollDotYHeight(i).toFloat() getScrollDotYHeight(i).toFloat()
) )