diff --git a/src/net/torvald/terrarum/UIItemInventoryCatBar.kt b/src/net/torvald/terrarum/UIItemInventoryCatBar.kt index 988a0a325..495706efa 100644 --- a/src/net/torvald/terrarum/UIItemInventoryCatBar.kt +++ b/src/net/torvald/terrarum/UIItemInventoryCatBar.kt @@ -5,26 +5,48 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Pixmap import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.terrarum.gameitem.GameItem import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull +import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UIItem import net.torvald.terrarum.ui.UIItemImageButton import net.torvald.terrarum.ui.UIUtils +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import kotlin.math.roundToInt /** * Created by minjaesong on 2017-10-20. */ class UIItemInventoryCatBar( - parentUI: UIInventoryFull, + parentUI: UICanvas, initialX: Int, initialY: Int, - override val width: Int + uiInternalWidth: Int, + override val width: Int, + val transitionReqFun: (Int) -> Unit, + val showSideButtons: Boolean ) : UIItem(parentUI, initialX, initialY) { - private val parentInventory = parentUI + companion object { + const val CAT_ALL = "__all__" + } - private val catIcons = parentUI.catIcons - private val catArrangement = parentUI.catArrangement + //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 + 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 @@ -66,8 +88,8 @@ class UIItemInventoryCatBar( // side buttons // 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 - val relativeStartX = posX - (parentUI.internalWidth - width) / 2 - val sideButtonsGap = (((parentUI.internalWidth - width) / 2) - 2f * catIcons.tileW) / 3f + val relativeStartX = posX - (uiInternalWidth - width) / 2 + val sideButtonsGap = (((uiInternalWidth - width) / 2) - 2f * catIcons.tileW) / 3f val iconIndex = arrayOf(12, 16, 17, 13) @@ -196,33 +218,35 @@ class UIItemInventoryCatBar( } } - sideButtons[0].update(delta) - sideButtons[3].update(delta) + if (showSideButtons) { + 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 (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 - } - - - if (transitionFired) { - transitionFired = false - parentInventory.requestTransition(selectedPanel) + if (transitionFired) { + transitionFired = false + //parentInventory.requestTransition(selectedPanel) + transitionReqFun(selectedPanel) + } } } @@ -232,7 +256,7 @@ class UIItemInventoryCatBar( // button // colour determined by UI items themselves mainButtons.forEach { it.render(batch, camera) } - sideButtons.forEach { it.render(batch, camera) } + if (showSideButtons) sideButtons.forEach { it.render(batch, camera) } blendNormal(batch) diff --git a/src/net/torvald/terrarum/UIItemInventoryElem.kt b/src/net/torvald/terrarum/UIItemInventoryElem.kt index ff02a7dcb..6558ec5d1 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElem.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElem.kt @@ -16,6 +16,7 @@ import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.Toolkit.DEFAULT_BOX_BORDER_COL +import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UIItemTextButton /*** @@ -24,7 +25,7 @@ import net.torvald.terrarum.ui.UIItemTextButton * Created by minjaesong on 2017-03-16. */ class UIItemInventoryElem( - parentUI: UIInventoryFull, + parentUI: UICanvas, initialX: Int, initialY: Int, override val width: Int, @@ -39,7 +40,8 @@ class UIItemInventoryElem( val backBlendMode: String = BlendMode.NORMAL, override var quickslot: 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) { companion object { @@ -49,8 +51,6 @@ class UIItemInventoryElem( internal val durabilityBarThickness = 3f } - private val inventoryUI = parentUI - override val height = UIItemInventoryElem.height private val imgOffset: Float @@ -219,7 +219,7 @@ class UIItemInventoryElem( } } - inventoryUI.rebuildList() + listRebuildFun() return super.touchDown(screenX, screenY, pointer, button) } diff --git a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt index 867b9049f..aa8433bc8 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt @@ -15,13 +15,14 @@ import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.Toolkit.DEFAULT_BOX_BORDER_COL +import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UIItemTextButton /** * Created by minjaesong on 2017-10-20. */ class UIItemInventoryElemSimple( - parentUI: UIInventoryFull, + parentUI: UICanvas, initialX: Int, initialY: Int, override var item: GameItem?, @@ -36,15 +37,14 @@ class UIItemInventoryElemSimple( val highlightCol: Color = UIItemTextButton.defaultHighlightCol, override var quickslot: 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) { companion object { val height = UIItemInventoryElem.height } - private val inventoryUI = parentUI - override val width = UIItemInventoryElemSimple.height override val height = UIItemInventoryElemSimple.height @@ -191,7 +191,7 @@ class UIItemInventoryElemSimple( } } - inventoryUI.rebuildList() + listRebuildFun() return super.touchDown(screenX, screenY, pointer, button) } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureCraftingTable.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureCraftingTable.kt index 6be73a6c1..68a0d145f 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureCraftingTable.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureCraftingTable.kt @@ -42,6 +42,15 @@ internal object UICraftingTable : UICanvas() { 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) { } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt index 779bcc3fb..db292fe80 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt @@ -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) { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt index 5f466be27..261b00316 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt @@ -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() } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt index b3dbe8580..6032cc455 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt @@ -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?, diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt index ea8cc579c..2c07d6da8 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt @@ -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 ) } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt similarity index 94% rename from src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt rename to src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt index 40b2a73f3..d8dd1aa35 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryDynamicList.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt @@ -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(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(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() )