generalised catbar

This commit is contained in:
minjaesong
2024-01-10 16:38:51 +09:00
parent 724a92bc18
commit ed70b16384
16 changed files with 213 additions and 116 deletions

View File

@@ -5,14 +5,14 @@ import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair 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. * Suite of objects for showing player inventory for various crafting UIs.
* *
* Created by minjaesong on 2023-10-04. * 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 val itemList: UIItemInventoryItemGrid
@@ -68,4 +68,7 @@ class CraftingPlayerInventory(val full: UIInventoryFull, val crafting: UICanvas)
itemList.getInventory = getter itemList.getInventory = getter
} }
override fun getUIitems(): List<UIItem> {
return listOf(itemList)
}
} }

View File

@@ -1,6 +1,6 @@
package net.torvald.terrarum.modulebasegame.ui 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.gameitems.GameItem
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera
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.App.* 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.gameactors.AVKey
import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID 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.FixtureInventory
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.listGap import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.listGap
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.*
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemSpinner
import net.torvald.terrarum.ui.UIItemTextButton
import net.torvald.unicode.getKeycapPC import net.torvald.unicode.getKeycapPC
import kotlin.math.ceil import kotlin.math.ceil
import kotlin.math.max import kotlin.math.max
@@ -32,7 +29,7 @@ import kotlin.math.min
*/ */
class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory { class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
private val catBar: UIItemInventoryCatBar private val catBar: UIItemCatBar
get() = full.catBar get() = full.catBar
override var width = App.scr.width override var width = App.scr.width
@@ -311,7 +308,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
addUIitem(itemListCraftable) addUIitem(itemListCraftable)
addUIitem(itemListIngredients) addUIitem(itemListIngredients)
addUIitem(playerThings.itemList) addUIitem(playerThings)
addUIitem(spinnerCraftCount) addUIitem(spinnerCraftCount)
addUIitem(buttonCraft) addUIitem(buttonCraft)
} }

View File

@@ -1,13 +1,10 @@
package net.torvald.terrarum.modulebasegame.ui package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
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.App.printdbg
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory 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.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericTouchDownFun
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemInventoryElemSimple
import org.dyn4j.geometry.Vector2 import org.dyn4j.geometry.Vector2
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min

View File

@@ -8,12 +8,10 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.App.* import net.torvald.terrarum.App.*
import net.torvald.terrarum.audio.AudioMixer import net.torvald.terrarum.audio.AudioMixer
import net.torvald.terrarum.audio.decibelsToFullscale import net.torvald.terrarum.audio.decibelsToFullscale
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.*
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIHandler
import net.torvald.terrarum.ui.UIItemHorizontalFadeSlide
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import net.torvald.unicode.* import net.torvald.unicode.*
@@ -200,13 +198,43 @@ class UIInventoryFull(
} }
fun requestTransition(target: Int) = transitionPanel.requestTransition(target) fun requestTransition(target: Int) = transitionPanel.requestTransition(target)
val catBar = UIItemInventoryCatBar( val catBar = UIItemCatBar(
this, this,
(width - catBarWidth) / 2, (width - catBarWidth) / 2,
42 - YPOS_CORRECTION + (App.scr.height - internalHeight) / 2, 42 - YPOS_CORRECTION + (scr.height - internalHeight) / 2,
internalWidth, internalWidth,
catBarWidth, catBarWidth,
true 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) } ) { i -> if (!panelTransitionLocked) requestTransition(i) }

View File

@@ -1,9 +1,8 @@
package net.torvald.terrarum.modulebasegame.ui package net.torvald.terrarum.modulebasegame.ui
import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.CraftingRecipeCodex import net.torvald.terrarum.CraftingRecipeCodex
import net.torvald.terrarum.ItemCodex 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.ceilToInt
import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID import net.torvald.terrarum.gameitems.ItemID
@@ -15,12 +14,12 @@ import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
* Created by minjaesong on 2022-06-28. * Created by minjaesong on 2022-06-28.
*/ */
class UIItemCraftingCandidateGrid( class UIItemCraftingCandidateGrid(
parentUI: UICrafting, catBar: UIItemInventoryCatBar, parentUI: UICrafting, catBar: UIItemCatBar,
initialX: Int, initialY: Int, initialX: Int, initialY: Int,
horizontalCells: Int, verticalCells: Int, horizontalCells: Int, verticalCells: Int,
drawScrollOnRightside: Boolean = false, drawScrollOnRightside: Boolean = false,
keyDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Keycode, extra info, keyed button 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 touchDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit // Item, Amount, Button, extra info, clicked button
) : UIItemInventoryItemGrid( ) : UIItemInventoryItemGrid(
parentUI, catBar, parentUI, catBar,
{ TODO() /* UNUSED and MUST NOT BE USED! */ }, { TODO() /* UNUSED and MUST NOT BE USED! */ },
@@ -99,7 +98,7 @@ class UIItemCraftingCandidateGrid(
craftingRecipes.forEach { craftingRecipes.forEach {
if ( if (
filter.contains((ItemCodex[it.product]?.inventoryCategory ?: throw IllegalArgumentException("Unknown item: ${it.product}"))) || 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) recipesSortList.add(it)
} }

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.modulebasegame.ui package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch 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.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericTouchDownFun
import net.torvald.terrarum.spriteassembler.ADProperties.Companion.EXTRA_HEADROOM_X import net.torvald.terrarum.spriteassembler.ADProperties.Companion.EXTRA_HEADROOM_X
import net.torvald.terrarum.spriteassembler.ADProperties.Companion.EXTRA_HEADROOM_Y import net.torvald.terrarum.spriteassembler.ADProperties.Companion.EXTRA_HEADROOM_Y
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.*
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem
/** /**
* Created by minjaesong on 2017-10-28. * Created by minjaesong on 2017-10-28.

View File

@@ -1,13 +1,11 @@
package net.torvald.terrarum.modulebasegame.ui package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.Input import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
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.App.printdbg import net.torvald.terrarum.ui.UIItemCatBar.Companion.CAT_ALL
import net.torvald.terrarum.UIItemInventoryCatBar.Companion.CAT_ALL
import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID 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.FixtureInventory
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.defaultInventoryCellTheme import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.defaultInventoryCellTheme
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.*
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import kotlin.math.floor import kotlin.math.floor
@@ -35,21 +31,21 @@ import kotlin.math.floor
* Created by minjaesong on 2017-10-21. * Created by minjaesong on 2017-10-21.
*/ */
open class UIItemInventoryItemGrid( open class UIItemInventoryItemGrid(
parentUI: UICanvas, parentUI: UICanvas,
val catBar: UIItemInventoryCatBar, 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 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, 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 hideSidebar: Boolean = false, val hideSidebar: Boolean = false,
keyDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Keycode, extra info, self 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 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 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 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 private val colourTheme: InventoryCellColourTheme = defaultInventoryCellTheme
) : UIItem(parentUI, initialX, initialY) { ) : UIItem(parentUI, initialX, initialY) {
// deal with the moving position // deal with the moving position

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.modulebasegame.ui package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch 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.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.getWidthOfCells import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.getWidthOfCells
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.*
import net.torvald.terrarum.ui.UICanvas
import net.torvald.unicode.getKeycapPC import net.torvald.unicode.getKeycapPC
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
@@ -46,7 +44,7 @@ internal class UIStorageChest : UICanvas(
override fun getFixtureInventory(): FixtureInventory = chestInventory override fun getFixtureInventory(): FixtureInventory = chestInventory
override fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory override fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory
private val catBar: UIItemInventoryCatBar private val catBar: UIItemCatBar
private val itemListChest: UIItemInventoryItemGrid private val itemListChest: UIItemInventoryItemGrid
private val itemListPlayer: UIItemInventoryItemGrid private val itemListPlayer: UIItemInventoryItemGrid
@@ -56,13 +54,43 @@ internal class UIStorageChest : UICanvas(
private var halfSlotOffset = (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap * 2) / 2 private var halfSlotOffset = (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap * 2) / 2
init { init {
catBar = UIItemInventoryCatBar( catBar = UIItemCatBar(
this, this,
(width - UIInventoryFull.catBarWidth) / 2, (width - UIInventoryFull.catBarWidth) / 2,
42 - UIInventoryFull.YPOS_CORRECTION + (App.scr.height - UIInventoryFull.internalHeight) / 2, 42 - UIInventoryFull.YPOS_CORRECTION + (App.scr.height - UIInventoryFull.internalHeight) / 2,
UIInventoryFull.internalWidth, UIInventoryFull.internalWidth,
UIInventoryFull.catBarWidth, 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() } catBar.selectionChangeListener = { old, new -> itemListUpdate() }
itemListChest = UIItemInventoryItemGrid( itemListChest = UIItemInventoryItemGrid(

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.modulebasegame.ui package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch 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.gameitems.GameItem
import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.*
import net.torvald.terrarum.ui.UICanvas
import net.torvald.unicode.getKeycapPC import net.torvald.unicode.getKeycapPC
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
@@ -39,7 +37,7 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
override fun getFixtureInventory(): FixtureInventory = chestInventory override fun getFixtureInventory(): FixtureInventory = chestInventory
override fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory override fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory
private val catBar: UIItemInventoryCatBar private val catBar: UIItemCatBar
private val itemListChest: UIItemInventoryItemGrid private val itemListChest: UIItemInventoryItemGrid
private val itemListPlayer: 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 private var halfSlotOffset = (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap * 2) / 2
init { init {
catBar = UIItemInventoryCatBar( catBar = UIItemCatBar(
this, this,
(width - UIInventoryFull.catBarWidth) / 2, (width - UIInventoryFull.catBarWidth) / 2,
42 - UIInventoryFull.YPOS_CORRECTION + (App.scr.height - UIInventoryFull.internalHeight) / 2, 42 - UIInventoryFull.YPOS_CORRECTION + (App.scr.height - UIInventoryFull.internalHeight) / 2,
UIInventoryFull.internalWidth, UIInventoryFull.internalWidth,
UIInventoryFull.catBarWidth, 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() } catBar.selectionChangeListener = { old, new -> itemListUpdate() }
itemListChest = UIItemInventoryItemGrid( itemListChest = UIItemInventoryItemGrid(

View File

@@ -192,6 +192,9 @@ abstract class UICanvas(
fun addUIitem(uiItem: UIItem) { fun addUIitem(uiItem: UIItem) {
if (!uiItems.contains(uiItem)) uiItems.add(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 fun mouseInScreen(x: Int, y: Int) = x in 0 until App.scr.windowW && y in 0 until App.scr.windowH

View File

@@ -1,23 +1,27 @@
package net.torvald.terrarum package net.torvald.terrarum.ui
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 net.torvald.terrarum.gameitems.GameItem import net.torvald.terrarum.*
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.ui.*
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack 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 UIItemCatBar(
parentUI: UICanvas, parentUI: UICanvas,
initialX: Int, initialX: Int,
initialY: Int, initialY: Int,
uiInternalWidth: Int, uiInternalWidth: Int,
override val width: Int, override val width: Int,
val showSideButtons: Boolean = false, val showSideButtons: Boolean = false,
val catIcons: TextureRegionPack = CommonResourcePool.getAsTextureRegionPack("inventory_category"),
private val catArrangement: IntArray, // icon order
internal val catIconsMeaning: List<Array<String>>, // sortedBy: catArrangement
internal val catIconsLabels: List<() -> String>,
val panelTransitionReqFun: (Int) -> Unit = {} // for side buttons; for the selection change, override selectionChangeListener val panelTransitionReqFun: (Int) -> Unit = {} // for side buttons; for the selection change, override selectionChangeListener
) : UIItem(parentUI, initialX, initialY) { ) : UIItem(parentUI, initialX, initialY) {
@@ -25,36 +29,6 @@ class UIItemInventoryCatBar(
const val CAT_ALL = "__all__" 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 private val inventoryUI = parentUI
override val height = catIcons.tileH + 5 override val height = catIcons.tileH + 5

View File

@@ -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.Color
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion 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.gameitems.GameItem
import net.torvald.terrarum.modulebasegame.ui.InventoryCellColourTheme import net.torvald.terrarum.modulebasegame.ui.InventoryCellColourTheme
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.defaultInventoryCellTheme import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.defaultInventoryCellTheme
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.mul
import net.torvald.terrarum.ui.UICanvas
import kotlin.math.roundToInt import kotlin.math.roundToInt
/** /**
@@ -39,8 +39,8 @@ class UIItemInventoryElemSimple(
val height = UIItemInventoryElemWide.height val height = UIItemInventoryElemWide.height
} }
override val width = UIItemInventoryElemSimple.height override val width = Companion.height
override val height = UIItemInventoryElemSimple.height override val height = Companion.height
private val imgOffsetY: Float private val imgOffsetY: Float
get() = (this.height - itemImage!!.regionHeight).div(2).toFloat() // to snap to the pixel grid get() = (this.height - itemImage!!.regionHeight).div(2).toFloat() // to snap to the pixel grid

View File

@@ -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.Color
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion 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.gameitems.GameItem
import net.torvald.terrarum.modulebasegame.ui.InventoryCellColourTheme import net.torvald.terrarum.modulebasegame.ui.InventoryCellColourTheme
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes 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.mul
import net.torvald.terrarum.ui.UICanvas
import kotlin.math.roundToInt import kotlin.math.roundToInt
/*** /***
@@ -44,7 +44,7 @@ class UIItemInventoryElemWide(
val durabilityBarThickness = 3 val durabilityBarThickness = 3
} }
override val height = UIItemInventoryElemWide.height override val height = Companion.height
private val imgOffsetY: Float private val imgOffsetY: Float
get() = (this.height - itemImage!!.regionHeight).div(2).toFloat() // to snap to the pixel grid get() = (this.height - itemImage!!.regionHeight).div(2).toFloat() // to snap to the pixel grid

View File

@@ -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<UIItem>
}

View File

@@ -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<Array<String>>, // 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<UIItem> {
return listOf(catBar)
}
}