mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
generalised catbar
This commit is contained in:
@@ -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<UIItem> {
|
||||
return listOf(itemList)
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) }
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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<Array<String>>, // 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
|
||||
@@ -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
|
||||
@@ -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
|
||||
10
src/net/torvald/terrarum/ui/UITemplate.kt
Normal file
10
src/net/torvald/terrarum/ui/UITemplate.kt
Normal 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>
|
||||
|
||||
}
|
||||
36
src/net/torvald/terrarum/ui/UITemplateCatBar.kt
Normal file
36
src/net/torvald/terrarum/ui/UITemplateCatBar.kt
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user