From ed70b1638417f0db5a65b286625bc67c15b73867 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 10 Jan 2024 16:38:51 +0900 Subject: [PATCH] generalised catbar --- .../ui/CraftingPlayerInventory.kt | 7 ++- .../ui/InventoryTransactionNegotiator.kt | 2 +- .../terrarum/modulebasegame/ui/UICrafting.kt | 11 ++-- .../modulebasegame/ui/UIInventoryCells.kt | 4 +- .../modulebasegame/ui/UIInventoryFull.kt | 50 +++++++++++++++---- .../ui/UIItemCraftingCandidateGrid.kt | 17 +++---- .../ui/UIItemInventoryEquippedView.kt | 5 +- .../ui/UIItemInventoryItemGrid.kt | 38 +++++++------- .../modulebasegame/ui/UIStorageChest.kt | 40 ++++++++++++--- .../modulebasegame/ui/UIWorldPortalCargo.kt | 40 ++++++++++++--- src/net/torvald/terrarum/ui/UICanvas.kt | 3 ++ .../UIItemCatBar.kt} | 44 ++++------------ .../{ => ui}/UIItemInventoryElemSimple.kt | 12 ++--- .../{ => ui}/UIItemInventoryElemWide.kt | 10 ++-- src/net/torvald/terrarum/ui/UITemplate.kt | 10 ++++ .../torvald/terrarum/ui/UITemplateCatBar.kt | 36 +++++++++++++ 16 files changed, 213 insertions(+), 116 deletions(-) rename src/net/torvald/terrarum/{UIItemInventoryCatBar.kt => ui/UIItemCatBar.kt} (87%) rename src/net/torvald/terrarum/{ => ui}/UIItemInventoryElemSimple.kt (95%) rename src/net/torvald/terrarum/{ => ui}/UIItemInventoryElemWide.kt (97%) create mode 100644 src/net/torvald/terrarum/ui/UITemplate.kt create mode 100644 src/net/torvald/terrarum/ui/UITemplateCatBar.kt diff --git a/src/net/torvald/terrarum/modulebasegame/ui/CraftingPlayerInventory.kt b/src/net/torvald/terrarum/modulebasegame/ui/CraftingPlayerInventory.kt index 2122d76cc..b4dfaffa7 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/CraftingPlayerInventory.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/CraftingPlayerInventory.kt @@ -5,14 +5,14 @@ import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.gameitems.ItemID import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair -import net.torvald.terrarum.ui.UICanvas +import net.torvald.terrarum.ui.* /** * Suite of objects for showing player inventory for various crafting UIs. * * Created by minjaesong on 2023-10-04. */ -class CraftingPlayerInventory(val full: UIInventoryFull, val crafting: UICanvas) { +class CraftingPlayerInventory(val full: UIInventoryFull, val crafting: UICanvas) : UITemplate(crafting) { val itemList: UIItemInventoryItemGrid @@ -68,4 +68,7 @@ class CraftingPlayerInventory(val full: UIInventoryFull, val crafting: UICanvas) itemList.getInventory = getter } + override fun getUIitems(): List { + return listOf(itemList) + } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/InventoryTransactionNegotiator.kt b/src/net/torvald/terrarum/modulebasegame/ui/InventoryTransactionNegotiator.kt index 9486f9c47..6babac6e9 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/InventoryTransactionNegotiator.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/InventoryTransactionNegotiator.kt @@ -1,6 +1,6 @@ package net.torvald.terrarum.modulebasegame.ui -import net.torvald.terrarum.UIItemInventoryCatBar.Companion.CAT_ALL +import net.torvald.terrarum.ui.UIItemCatBar.Companion.CAT_ALL import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt b/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt index 6945760c9..53ac014b1 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UICrafting.kt @@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.* import net.torvald.terrarum.App.* -import net.torvald.terrarum.UIItemInventoryCatBar.Companion.CAT_ALL +import net.torvald.terrarum.ui.UIItemCatBar.Companion.CAT_ALL import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.gameitems.ItemID @@ -16,10 +16,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.CraftingStation import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.listGap -import net.torvald.terrarum.ui.Toolkit -import net.torvald.terrarum.ui.UICanvas -import net.torvald.terrarum.ui.UIItemSpinner -import net.torvald.terrarum.ui.UIItemTextButton +import net.torvald.terrarum.ui.* import net.torvald.unicode.getKeycapPC import kotlin.math.ceil import kotlin.math.max @@ -32,7 +29,7 @@ import kotlin.math.min */ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory { - private val catBar: UIItemInventoryCatBar + private val catBar: UIItemCatBar get() = full.catBar override var width = App.scr.width @@ -311,7 +308,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory { addUIitem(itemListCraftable) addUIitem(itemListIngredients) - addUIitem(playerThings.itemList) + addUIitem(playerThings) addUIitem(spinnerCraftCount) addUIitem(buttonCraft) } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt index d939d391d..e157a38c1 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt @@ -1,13 +1,10 @@ package net.torvald.terrarum.modulebasegame.ui import com.badlogic.gdx.Gdx -import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.* -import net.torvald.terrarum.App.printdbg -import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory @@ -21,6 +18,7 @@ import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion. import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericTouchDownFun import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.UICanvas +import net.torvald.terrarum.ui.UIItemInventoryElemSimple import org.dyn4j.geometry.Vector2 import kotlin.math.max import kotlin.math.min diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt index f2a4625f8..fee0b171c 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt @@ -8,12 +8,10 @@ import net.torvald.terrarum.* import net.torvald.terrarum.App.* import net.torvald.terrarum.audio.AudioMixer import net.torvald.terrarum.audio.decibelsToFullscale +import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid -import net.torvald.terrarum.ui.Toolkit -import net.torvald.terrarum.ui.UICanvas -import net.torvald.terrarum.ui.UIHandler -import net.torvald.terrarum.ui.UIItemHorizontalFadeSlide +import net.torvald.terrarum.ui.* import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import net.torvald.unicode.* @@ -200,13 +198,43 @@ class UIInventoryFull( } fun requestTransition(target: Int) = transitionPanel.requestTransition(target) - val catBar = UIItemInventoryCatBar( - this, - (width - catBarWidth) / 2, - 42 - YPOS_CORRECTION + (App.scr.height - internalHeight) / 2, - internalWidth, - catBarWidth, - true + val catBar = UIItemCatBar( + this, + (width - catBarWidth) / 2, + 42 - YPOS_CORRECTION + (scr.height - internalHeight) / 2, + internalWidth, + catBarWidth, + true, + + catIcons = CommonResourcePool.getAsTextureRegionPack("inventory_category"), + catArrangement = intArrayOf(9,6,7,1,0,2,1_011,3,4,5,8), // icon order + catIconsMeaning = listOf( // sortedBy: catArrangement + arrayOf(UIItemCatBar.CAT_ALL), + arrayOf(GameItem.Category.BLOCK), + arrayOf(GameItem.Category.WALL), + arrayOf(GameItem.Category.TOOL, GameItem.Category.WIRE), + arrayOf(GameItem.Category.WEAPON), + arrayOf(GameItem.Category.ARMOUR), + arrayOf(GameItem.Category.FIXTURE), + arrayOf(GameItem.Category.GENERIC), + arrayOf(GameItem.Category.POTION), + arrayOf(GameItem.Category.MAGIC), + arrayOf(GameItem.Category.MISC), + ), + catIconsLabels = listOf( + { Lang["MENU_LABEL_ALL"] }, + { Lang["GAME_INVENTORY_BLOCKS"] }, + { Lang["GAME_INVENTORY_WALLS"] }, + { Lang["CONTEXT_ITEM_TOOL_PLURAL"] }, + { Lang["GAME_INVENTORY_WEAPONS"] }, + { Lang["CONTEXT_ITEM_ARMOR"] }, + { Lang["CONTEXT_ITEM_FIXTURES"] }, + { Lang["GAME_INVENTORY_INGREDIENTS"] }, + { Lang["GAME_INVENTORY_POTIONS"] }, + { Lang["CONTEXT_ITEM_MAGIC"] }, + { Lang["GAME_GENRE_MISC"] }, + ), + ) { i -> if (!panelTransitionLocked) requestTransition(i) } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt index ad772a0b8..091a659ba 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt @@ -1,9 +1,8 @@ package net.torvald.terrarum.modulebasegame.ui -import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.CraftingRecipeCodex import net.torvald.terrarum.ItemCodex -import net.torvald.terrarum.UIItemInventoryCatBar +import net.torvald.terrarum.ui.UIItemCatBar import net.torvald.terrarum.ceilToInt import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.gameitems.ItemID @@ -15,12 +14,12 @@ import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair * Created by minjaesong on 2022-06-28. */ class UIItemCraftingCandidateGrid( - parentUI: UICrafting, catBar: UIItemInventoryCatBar, - initialX: Int, initialY: Int, - horizontalCells: Int, verticalCells: Int, - drawScrollOnRightside: Boolean = false, - keyDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Keycode, extra info, keyed button - touchDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit // Item, Amount, Button, extra info, clicked button + parentUI: UICrafting, catBar: UIItemCatBar, + initialX: Int, initialY: Int, + horizontalCells: Int, verticalCells: Int, + drawScrollOnRightside: Boolean = false, + keyDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Keycode, extra info, keyed button + touchDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit // Item, Amount, Button, extra info, clicked button ) : UIItemInventoryItemGrid( parentUI, catBar, { TODO() /* UNUSED and MUST NOT BE USED! */ }, @@ -99,7 +98,7 @@ class UIItemCraftingCandidateGrid( craftingRecipes.forEach { if ( filter.contains((ItemCodex[it.product]?.inventoryCategory ?: throw IllegalArgumentException("Unknown item: ${it.product}"))) || - filter[0] == UIItemInventoryCatBar.CAT_ALL + filter[0] == UIItemCatBar.CAT_ALL ) { recipesSortList.add(it) } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt index f1ddf74ef..19d33d5a0 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt @@ -1,6 +1,5 @@ package net.torvald.terrarum.modulebasegame.ui -import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch @@ -13,9 +12,7 @@ import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion. import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericTouchDownFun import net.torvald.terrarum.spriteassembler.ADProperties.Companion.EXTRA_HEADROOM_X import net.torvald.terrarum.spriteassembler.ADProperties.Companion.EXTRA_HEADROOM_Y -import net.torvald.terrarum.ui.Toolkit -import net.torvald.terrarum.ui.UICanvas -import net.torvald.terrarum.ui.UIItem +import net.torvald.terrarum.ui.* /** * Created by minjaesong on 2017-10-28. diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt index 13c7f432e..4749b55bb 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt @@ -1,13 +1,11 @@ package net.torvald.terrarum.modulebasegame.ui import com.badlogic.gdx.Input -import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.* -import net.torvald.terrarum.App.printdbg -import net.torvald.terrarum.UIItemInventoryCatBar.Companion.CAT_ALL +import net.torvald.terrarum.ui.UIItemCatBar.Companion.CAT_ALL import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.gameitems.ItemID @@ -17,9 +15,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.defaultInventoryCellTheme -import net.torvald.terrarum.ui.Toolkit -import net.torvald.terrarum.ui.UICanvas -import net.torvald.terrarum.ui.UIItem +import net.torvald.terrarum.ui.* import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import kotlin.math.floor @@ -35,21 +31,21 @@ import kotlin.math.floor * Created by minjaesong on 2017-10-21. */ open class UIItemInventoryItemGrid( - parentUI: UICanvas, - val catBar: UIItemInventoryCatBar, - var getInventory: () -> FixtureInventory, // 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 hideSidebar: Boolean = false, - keyDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Keycode, extra info, self - touchDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Button, extra info, self - protected val useHighlightingManager: Boolean = true, // only used by UIItemCraftingCandidateGrid which addresses buttons directly to set highlighting - open protected val highlightEquippedItem: Boolean = true, // for some UIs that only cares about getting equipped slot number but not highlighting - private val colourTheme: InventoryCellColourTheme = defaultInventoryCellTheme + parentUI: UICanvas, + val catBar: UIItemCatBar, + var getInventory: () -> FixtureInventory, // 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 hideSidebar: Boolean = false, + keyDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Keycode, extra info, self + touchDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Button, extra info, self + protected val useHighlightingManager: Boolean = true, // only used by UIItemCraftingCandidateGrid which addresses buttons directly to set highlighting + open protected val highlightEquippedItem: Boolean = true, // for some UIs that only cares about getting equipped slot number but not highlighting + private val colourTheme: InventoryCellColourTheme = defaultInventoryCellTheme ) : UIItem(parentUI, initialX, initialY) { // deal with the moving position diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIStorageChest.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIStorageChest.kt index d0f043bd1..899ed0eb8 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIStorageChest.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIStorageChest.kt @@ -1,6 +1,5 @@ package net.torvald.terrarum.modulebasegame.ui -import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch @@ -10,8 +9,7 @@ import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.getWidthOfCells -import net.torvald.terrarum.ui.Toolkit -import net.torvald.terrarum.ui.UICanvas +import net.torvald.terrarum.ui.* import net.torvald.unicode.getKeycapPC import kotlin.math.max import kotlin.math.min @@ -46,7 +44,7 @@ internal class UIStorageChest : UICanvas( override fun getFixtureInventory(): FixtureInventory = chestInventory override fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory - private val catBar: UIItemInventoryCatBar + private val catBar: UIItemCatBar private val itemListChest: UIItemInventoryItemGrid private val itemListPlayer: UIItemInventoryItemGrid @@ -56,13 +54,43 @@ internal class UIStorageChest : UICanvas( private var halfSlotOffset = (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap * 2) / 2 init { - catBar = UIItemInventoryCatBar( + catBar = UIItemCatBar( this, (width - UIInventoryFull.catBarWidth) / 2, 42 - UIInventoryFull.YPOS_CORRECTION + (App.scr.height - UIInventoryFull.internalHeight) / 2, UIInventoryFull.internalWidth, UIInventoryFull.catBarWidth, - false + false, + + catIcons = CommonResourcePool.getAsTextureRegionPack("inventory_category"), + catArrangement = intArrayOf(9,6,7,1,0,2,1_011,3,4,5,8), // icon order + catIconsMeaning = listOf( // sortedBy: catArrangement + arrayOf(UIItemCatBar.CAT_ALL), + arrayOf(GameItem.Category.BLOCK), + arrayOf(GameItem.Category.WALL), + arrayOf(GameItem.Category.TOOL, GameItem.Category.WIRE), + arrayOf(GameItem.Category.WEAPON), + arrayOf(GameItem.Category.ARMOUR), + arrayOf(GameItem.Category.FIXTURE), + arrayOf(GameItem.Category.GENERIC), + arrayOf(GameItem.Category.POTION), + arrayOf(GameItem.Category.MAGIC), + arrayOf(GameItem.Category.MISC), + ), + catIconsLabels = listOf( + { Lang["MENU_LABEL_ALL"] }, + { Lang["GAME_INVENTORY_BLOCKS"] }, + { Lang["GAME_INVENTORY_WALLS"] }, + { Lang["CONTEXT_ITEM_TOOL_PLURAL"] }, + { Lang["GAME_INVENTORY_WEAPONS"] }, + { Lang["CONTEXT_ITEM_ARMOR"] }, + { Lang["CONTEXT_ITEM_FIXTURES"] }, + { Lang["GAME_INVENTORY_INGREDIENTS"] }, + { Lang["GAME_INVENTORY_POTIONS"] }, + { Lang["CONTEXT_ITEM_MAGIC"] }, + { Lang["GAME_GENRE_MISC"] }, + ), + ) catBar.selectionChangeListener = { old, new -> itemListUpdate() } itemListChest = UIItemInventoryItemGrid( diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalCargo.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalCargo.kt index a4d289616..1f2aeaf70 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalCargo.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIWorldPortalCargo.kt @@ -1,6 +1,5 @@ package net.torvald.terrarum.modulebasegame.ui -import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch @@ -9,8 +8,7 @@ import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory -import net.torvald.terrarum.ui.Toolkit -import net.torvald.terrarum.ui.UICanvas +import net.torvald.terrarum.ui.* import net.torvald.unicode.getKeycapPC import kotlin.math.max import kotlin.math.min @@ -39,7 +37,7 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory { override fun getFixtureInventory(): FixtureInventory = chestInventory override fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory - private val catBar: UIItemInventoryCatBar + private val catBar: UIItemCatBar private val itemListChest: UIItemInventoryItemGrid private val itemListPlayer: UIItemInventoryItemGrid @@ -49,13 +47,43 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory { private var halfSlotOffset = (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap * 2) / 2 init { - catBar = UIItemInventoryCatBar( + catBar = UIItemCatBar( this, (width - UIInventoryFull.catBarWidth) / 2, 42 - UIInventoryFull.YPOS_CORRECTION + (App.scr.height - UIInventoryFull.internalHeight) / 2, UIInventoryFull.internalWidth, UIInventoryFull.catBarWidth, - false + false, + + catIcons = CommonResourcePool.getAsTextureRegionPack("inventory_category"), + catArrangement = intArrayOf(9,6,7,1,0,2,1_011,3,4,5,8), // icon order + catIconsMeaning = listOf( // sortedBy: catArrangement + arrayOf(UIItemCatBar.CAT_ALL), + arrayOf(GameItem.Category.BLOCK), + arrayOf(GameItem.Category.WALL), + arrayOf(GameItem.Category.TOOL, GameItem.Category.WIRE), + arrayOf(GameItem.Category.WEAPON), + arrayOf(GameItem.Category.ARMOUR), + arrayOf(GameItem.Category.FIXTURE), + arrayOf(GameItem.Category.GENERIC), + arrayOf(GameItem.Category.POTION), + arrayOf(GameItem.Category.MAGIC), + arrayOf(GameItem.Category.MISC), + ), + catIconsLabels = listOf( + { Lang["MENU_LABEL_ALL"] }, + { Lang["GAME_INVENTORY_BLOCKS"] }, + { Lang["GAME_INVENTORY_WALLS"] }, + { Lang["CONTEXT_ITEM_TOOL_PLURAL"] }, + { Lang["GAME_INVENTORY_WEAPONS"] }, + { Lang["CONTEXT_ITEM_ARMOR"] }, + { Lang["CONTEXT_ITEM_FIXTURES"] }, + { Lang["GAME_INVENTORY_INGREDIENTS"] }, + { Lang["GAME_INVENTORY_POTIONS"] }, + { Lang["CONTEXT_ITEM_MAGIC"] }, + { Lang["GAME_GENRE_MISC"] }, + ), + ) catBar.selectionChangeListener = { old, new -> itemListUpdate() } itemListChest = UIItemInventoryItemGrid( diff --git a/src/net/torvald/terrarum/ui/UICanvas.kt b/src/net/torvald/terrarum/ui/UICanvas.kt index ee71e1d68..3ac0a814d 100644 --- a/src/net/torvald/terrarum/ui/UICanvas.kt +++ b/src/net/torvald/terrarum/ui/UICanvas.kt @@ -192,6 +192,9 @@ abstract class UICanvas( fun addUIitem(uiItem: UIItem) { if (!uiItems.contains(uiItem)) uiItems.add(uiItem) } + fun addUIitem(template: UITemplate) { + template.getUIitems().forEach { addUIitem(it) } + } fun mouseInScreen(x: Int, y: Int) = x in 0 until App.scr.windowW && y in 0 until App.scr.windowH diff --git a/src/net/torvald/terrarum/UIItemInventoryCatBar.kt b/src/net/torvald/terrarum/ui/UIItemCatBar.kt similarity index 87% rename from src/net/torvald/terrarum/UIItemInventoryCatBar.kt rename to src/net/torvald/terrarum/ui/UIItemCatBar.kt index a90bc4f86..6b69b7c02 100644 --- a/src/net/torvald/terrarum/UIItemInventoryCatBar.kt +++ b/src/net/torvald/terrarum/ui/UIItemCatBar.kt @@ -1,23 +1,27 @@ -package net.torvald.terrarum +package net.torvald.terrarum.ui import com.badlogic.gdx.graphics.* import com.badlogic.gdx.graphics.g2d.SpriteBatch -import net.torvald.terrarum.gameitems.GameItem -import net.torvald.terrarum.langpack.Lang -import net.torvald.terrarum.ui.* +import net.torvald.terrarum.* import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import kotlin.math.roundToInt /** * Created by minjaesong on 2017-10-20. */ -class UIItemInventoryCatBar( +class UIItemCatBar( parentUI: UICanvas, initialX: Int, initialY: Int, uiInternalWidth: Int, override val width: Int, val showSideButtons: Boolean = false, + + val catIcons: TextureRegionPack = CommonResourcePool.getAsTextureRegionPack("inventory_category"), + private val catArrangement: IntArray, // icon order + internal val catIconsMeaning: List>, // sortedBy: catArrangement + internal val catIconsLabels: List<() -> String>, + val panelTransitionReqFun: (Int) -> Unit = {} // for side buttons; for the selection change, override selectionChangeListener ) : UIItem(parentUI, initialX, initialY) { @@ -25,36 +29,6 @@ class UIItemInventoryCatBar( const val CAT_ALL = "__all__" } - internal val catIcons: TextureRegionPack = CommonResourcePool.getAsTextureRegionPack("inventory_category") - private val catArrangement: IntArray = intArrayOf(9,6,7,1,0,2,1_011,3,4,5,8) // icon order - internal val catIconsMeaning = listOf( // sortedBy: catArrangement - arrayOf(CAT_ALL), - arrayOf(GameItem.Category.BLOCK), - arrayOf(GameItem.Category.WALL), - arrayOf(GameItem.Category.TOOL, GameItem.Category.WIRE), - arrayOf(GameItem.Category.WEAPON), - arrayOf(GameItem.Category.ARMOUR), - arrayOf(GameItem.Category.FIXTURE), - arrayOf(GameItem.Category.GENERIC), - arrayOf(GameItem.Category.POTION), - arrayOf(GameItem.Category.MAGIC), - arrayOf(GameItem.Category.MISC), - ) - - internal val catIconsLabels = listOf( - { Lang["MENU_LABEL_ALL"] }, - { Lang["GAME_INVENTORY_BLOCKS"] }, - { Lang["GAME_INVENTORY_WALLS"] }, - { Lang["CONTEXT_ITEM_TOOL_PLURAL"] }, - { Lang["GAME_INVENTORY_WEAPONS"] }, - { Lang["CONTEXT_ITEM_ARMOR"] }, - { Lang["CONTEXT_ITEM_FIXTURES"] }, - { Lang["GAME_INVENTORY_INGREDIENTS"] }, - { Lang["GAME_INVENTORY_POTIONS"] }, - { Lang["CONTEXT_ITEM_MAGIC"] }, - { Lang["GAME_GENRE_MISC"] }, - ) - private val inventoryUI = parentUI override val height = catIcons.tileH + 5 diff --git a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt b/src/net/torvald/terrarum/ui/UIItemInventoryElemSimple.kt similarity index 95% rename from src/net/torvald/terrarum/UIItemInventoryElemSimple.kt rename to src/net/torvald/terrarum/ui/UIItemInventoryElemSimple.kt index ba119a87f..2d92078f0 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt +++ b/src/net/torvald/terrarum/ui/UIItemInventoryElemSimple.kt @@ -1,18 +1,18 @@ -package net.torvald.terrarum +package net.torvald.terrarum.ui -import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion +import net.torvald.terrarum.App +import net.torvald.terrarum.blendNormalStraightAlpha import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.modulebasegame.ui.InventoryCellColourTheme import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.defaultInventoryCellTheme import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText -import net.torvald.terrarum.ui.Toolkit -import net.torvald.terrarum.ui.UICanvas +import net.torvald.terrarum.mul import kotlin.math.roundToInt /** @@ -39,8 +39,8 @@ class UIItemInventoryElemSimple( val height = UIItemInventoryElemWide.height } - override val width = UIItemInventoryElemSimple.height - override val height = UIItemInventoryElemSimple.height + override val width = Companion.height + override val height = Companion.height private val imgOffsetY: Float get() = (this.height - itemImage!!.regionHeight).div(2).toFloat() // to snap to the pixel grid diff --git a/src/net/torvald/terrarum/UIItemInventoryElemWide.kt b/src/net/torvald/terrarum/ui/UIItemInventoryElemWide.kt similarity index 97% rename from src/net/torvald/terrarum/UIItemInventoryElemWide.kt rename to src/net/torvald/terrarum/ui/UIItemInventoryElemWide.kt index e12c8805d..3060b89f4 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElemWide.kt +++ b/src/net/torvald/terrarum/ui/UIItemInventoryElemWide.kt @@ -1,17 +1,17 @@ -package net.torvald.terrarum +package net.torvald.terrarum.ui -import com.badlogic.gdx.graphics.Camera import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion +import net.torvald.terrarum.App +import net.torvald.terrarum.blendNormalStraightAlpha import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.modulebasegame.ui.InventoryCellColourTheme import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase 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.UICanvas +import net.torvald.terrarum.mul import kotlin.math.roundToInt /*** @@ -44,7 +44,7 @@ class UIItemInventoryElemWide( val durabilityBarThickness = 3 } - override val height = UIItemInventoryElemWide.height + override val height = Companion.height private val imgOffsetY: Float get() = (this.height - itemImage!!.regionHeight).div(2).toFloat() // to snap to the pixel grid diff --git a/src/net/torvald/terrarum/ui/UITemplate.kt b/src/net/torvald/terrarum/ui/UITemplate.kt new file mode 100644 index 000000000..f92079abe --- /dev/null +++ b/src/net/torvald/terrarum/ui/UITemplate.kt @@ -0,0 +1,10 @@ +package net.torvald.terrarum.ui + +/** + * Created by minjaesong on 2024-01-10. + */ +abstract class UITemplate(val parent: UICanvas) { + + abstract fun getUIitems(): List + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/UITemplateCatBar.kt b/src/net/torvald/terrarum/ui/UITemplateCatBar.kt new file mode 100644 index 000000000..94d9609f4 --- /dev/null +++ b/src/net/torvald/terrarum/ui/UITemplateCatBar.kt @@ -0,0 +1,36 @@ +package net.torvald.terrarum.ui + +import net.torvald.terrarum.App +import net.torvald.terrarum.CommonResourcePool +import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack + +/** + * Basically a UIItemInventoryCatBar placed on a set position for your convenience + * + * Created by minjaesong on 2024-01-10. + */ +class UITemplateCatBar( + parent: UICanvas, + + catIcons: TextureRegionPack = CommonResourcePool.getAsTextureRegionPack("inventory_category"), + catArrangement: IntArray, // icon order + catIconsMeaning: List>, // sortedBy: catArrangement + catIconsLabels: List<() -> String>, + +) : UITemplate(parent) { + + val catBar = UIItemCatBar( + parent, + (parent.width - UIInventoryFull.catBarWidth) / 2, + 42 - UIInventoryFull.YPOS_CORRECTION + (App.scr.height - UIInventoryFull.internalHeight) / 2, + UIInventoryFull.internalWidth, + UIInventoryFull.catBarWidth, + true, + catIcons, catArrangement, catIconsMeaning, catIconsLabels + ) + + override fun getUIitems(): List { + return listOf(catBar) + } +} \ No newline at end of file