mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
crafting ui working (visuals only)
This commit is contained in:
@@ -656,6 +656,8 @@ val MaterialCodex: MaterialCodex
|
||||
get() = Terrarum.materialCodex
|
||||
val FactionCodex: FactionCodex
|
||||
get() = Terrarum.factionCodex
|
||||
val CraftingRecipeCodex: CraftingCodex
|
||||
get() = Terrarum.craftingCodex
|
||||
val Apocryphas: HashMap<String, Any>
|
||||
get() = Terrarum.apocryphas
|
||||
|
||||
|
||||
@@ -25,9 +25,10 @@ class UIItemInventoryElemSimple(
|
||||
override var quickslot: Int? = null,
|
||||
override var equippedSlot: Int? = null,
|
||||
val drawBackOnNull: Boolean = true,
|
||||
keyDownFun: (GameItem?, Long, Int) -> Unit, // Item, Amount, Keycode
|
||||
touchDownFun: (GameItem?, Long, Int) -> Unit // Item, Amount, Button
|
||||
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun) {
|
||||
keyDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Keycode, extra info
|
||||
touchDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Button, extra info
|
||||
extraInfo: Any? = null
|
||||
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun, extraInfo) {
|
||||
|
||||
companion object {
|
||||
val height = UIItemInventoryElemWide.height
|
||||
|
||||
@@ -28,9 +28,10 @@ class UIItemInventoryElemWide(
|
||||
override var quickslot: Int? = null,
|
||||
override var equippedSlot: Int? = null,
|
||||
val drawBackOnNull: Boolean = true,
|
||||
keyDownFun: (GameItem?, Long, Int) -> Unit, // Item, Amount, Keycode
|
||||
touchDownFun: (GameItem?, Long, Int) -> Unit // Item, Amount, Button
|
||||
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun) {
|
||||
keyDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Keycode, extra info
|
||||
touchDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Button, extra info
|
||||
extraInfo: Any? = null
|
||||
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun, extraInfo) {
|
||||
|
||||
companion object {
|
||||
val height = 48
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.torvald.terrarum.gameitems
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.ReferencingRanges.PREFIX_DYNAMICITEM
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
@@ -181,6 +180,8 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
||||
|
||||
@Transient var using = false // Always false when loaded from savegame
|
||||
|
||||
var tags = HashSet<String>()
|
||||
|
||||
/**
|
||||
* Mainly intended to be used by third-party modules
|
||||
*/
|
||||
|
||||
@@ -38,7 +38,7 @@ class Material {
|
||||
class MaterialCodex {
|
||||
|
||||
@Transient val materialProps = HashMap<String, Material>()
|
||||
@Transient private val nullMaterial = Material()
|
||||
@Transient internal val nullMaterial = Material()
|
||||
|
||||
internal constructor()
|
||||
|
||||
|
||||
@@ -101,6 +101,7 @@ class EntryPoint : ModuleEntryPoint() {
|
||||
|
||||
init {
|
||||
equipPosition = EquipPosition.HAND_GRIP
|
||||
tags.addAll(tile.tags)
|
||||
}
|
||||
|
||||
override fun startPrimaryUse(actor: ActorWithBody, delta: Float): Boolean {
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.PlayerBuilderSigrid
|
||||
internal object DebugFillInventory : ConsoleCommand {
|
||||
override fun execute(args: Array<String>) {
|
||||
INGAME.actorNowPlaying?.let {
|
||||
it.inventory.nuke()
|
||||
it.inventory.clear()
|
||||
PlayerBuilderSigrid.fillTestInventory(it.inventory)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,8 +120,8 @@ class ActorInventory() : FixtureInventory() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun nuke() {
|
||||
super.nuke()
|
||||
override fun clear() {
|
||||
super.clear()
|
||||
itemEquipped.fill(null)
|
||||
quickSlot.fill(null)
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ open class FixtureInventory() {
|
||||
return -(low + 1) // key not found
|
||||
}
|
||||
|
||||
open fun nuke() {
|
||||
open fun clear() {
|
||||
itemList.clear()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,8 +121,8 @@ internal class UIStorageChest : UICanvas(
|
||||
6, CELLS_VRT,
|
||||
drawScrollOnRightside = false,
|
||||
drawWallet = false,
|
||||
keyDownFun = { _, _, _ -> Unit },
|
||||
touchDownFun = { gameItem, amount, _ ->
|
||||
keyDownFun = { _, _, _, _ -> Unit },
|
||||
touchDownFun = { gameItem, amount, _, _ ->
|
||||
if (gameItem != null) {
|
||||
negotiator.reject(getFixtureInventory(), getPlayerInventory(), gameItem, amount)
|
||||
}
|
||||
@@ -142,8 +142,8 @@ internal class UIStorageChest : UICanvas(
|
||||
6, CELLS_VRT,
|
||||
drawScrollOnRightside = true,
|
||||
drawWallet = false,
|
||||
keyDownFun = { _, _, _ -> Unit },
|
||||
touchDownFun = { gameItem, amount, _ ->
|
||||
keyDownFun = { _, _, _, _ -> Unit },
|
||||
touchDownFun = { gameItem, amount, _, _ ->
|
||||
if (gameItem != null) {
|
||||
negotiator.accept(getPlayerInventory(), getFixtureInventory(), gameItem, amount)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
|
||||
/**
|
||||
* FixtureInventory except item duplicates are allowed
|
||||
*
|
||||
* Created by minjaesong on 2022-06-28.
|
||||
*/
|
||||
class InventoryItemList : FixtureInventory() {
|
||||
|
||||
override fun add(item: GameItem, count: Long) {
|
||||
|
||||
// other invalid values
|
||||
if (count == 0L)
|
||||
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Item count is zero.")
|
||||
if (count < 0L)
|
||||
throw IllegalArgumentException("Item count is negative number. If you intended removing items, use remove()\n" +
|
||||
"These commands are NOT INTERCHANGEABLE; they handle things differently according to the context.")
|
||||
if (item.originalID == "actor:${Terrarum.PLAYER_REF_ID}" || item.originalID == ("actor:${0x51621D}")) // do not delete this magic
|
||||
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Attempted to put human player into the inventory.")
|
||||
if (((Terrarum.ingame as? TerrarumIngame)?.gameFullyLoaded == true) &&
|
||||
(item.originalID == "actor:${(Terrarum.ingame as? TerrarumIngame)?.actorNowPlaying?.referenceID}"))
|
||||
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Attempted to put active player into the inventory.")
|
||||
if ((!item.stackable || item.dynamicID.startsWith("dyn:")) && count > 1)
|
||||
throw IllegalArgumentException("[${this.javaClass.canonicalName}] Attempted to adding stack of item but the item is not stackable; item: $item, count: $count")
|
||||
|
||||
|
||||
itemList.add(InventoryPair(item.dynamicID, count))
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,9 @@ import com.badlogic.gdx.graphics.Color
|
||||
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.gameitems.GameItem
|
||||
import net.torvald.terrarum.itemproperties.CraftingCodex
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.ui.*
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.listGap
|
||||
@@ -65,44 +67,14 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
||||
private val TEXT_GAP = 26
|
||||
private val LAST_LINE_IN_GRID = ((UIItemInventoryElemWide.height + listGap) * (UIInventoryFull.CELLS_VRT - 2)) + 22//359 // TEMPORARY VALUE!
|
||||
|
||||
private var recipeClicked: CraftingCodex.CraftingRecipe? = null
|
||||
|
||||
private val catAll = arrayOf(CAT_ALL)
|
||||
|
||||
init {
|
||||
val craftButtonsY = thisOffsetY + 23 + (UIItemInventoryElemWide.height + listGap) * (UIInventoryFull.CELLS_VRT - 1)
|
||||
val buttonWidth = (UIItemInventoryElemWide.height + listGap) * 3 - listGap - 2
|
||||
|
||||
// crafting list to the left
|
||||
// TODO This UIItem need to be custom-built version of UIItemInventoryItemGrid, with requirements:
|
||||
// - Takes list of [net.torvald.terrarum.itemproperties.CraftingRecipe] as an "inventory"
|
||||
// - Displays `CraftingRecipe.product` as an "inventory cell"
|
||||
// - When clicked, the cell is activated and displays its `ingredients` to the itemListIngredients
|
||||
// - The clicked status must be recorded and be accessible to this very class
|
||||
itemListCraftable = UIItemInventoryItemGrid(
|
||||
this,
|
||||
catBar,
|
||||
{ craftables },
|
||||
thisOffsetX,
|
||||
thisOffsetY,
|
||||
6, UIInventoryFull.CELLS_VRT - 2, // decrease the internal height so that craft/cancel button would fit in
|
||||
drawScrollOnRightside = false,
|
||||
drawWallet = false,
|
||||
keyDownFun = { _, _, _ -> },
|
||||
touchDownFun = { gameItem, amount, _ ->
|
||||
/*if (gameItem != null) {
|
||||
negotiator.reject(craftables, getPlayerInventory(), gameItem, amount)
|
||||
}
|
||||
itemListUpdate()*/
|
||||
}
|
||||
)
|
||||
buttonCraft = UIItemTextButton(this, "GAME_ACTION_CRAFT", thisOffsetX + 3 + buttonWidth + listGap, craftButtonsY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
|
||||
spinnerCraftCount = UIItemSpinner(this, thisOffsetX + 1, craftButtonsY, 1, 1, 100, 1, buttonWidth, numberToTextFunction = {"${it.toInt()}"})
|
||||
|
||||
buttonCraft.touchDownListener = { _,_,_,_ ->
|
||||
printdbg(this, "Craft!")
|
||||
}
|
||||
|
||||
// make grid mode buttons work together
|
||||
itemListCraftable.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
|
||||
itemListCraftable.gridModeButtons[1].touchDownListener = { _,_,_,_ -> setCompact(true) }
|
||||
|
||||
// ingredient list
|
||||
itemListIngredients = UIItemInventoryItemGrid(
|
||||
this,
|
||||
@@ -114,8 +86,8 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
||||
drawScrollOnRightside = false,
|
||||
drawWallet = false,
|
||||
hideSidebar = true,
|
||||
keyDownFun = { _, _, _ -> },
|
||||
touchDownFun = { _, _, _ -> }
|
||||
keyDownFun = { _, _, _, _ -> },
|
||||
touchDownFun = { _, _, _, _ -> }
|
||||
)
|
||||
|
||||
// make sure grid buttons for ingredients do nothing (even if they are hidden!)
|
||||
@@ -123,6 +95,63 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
||||
itemListIngredients.gridModeButtons[1].touchDownListener = { _,_,_,_ -> }
|
||||
itemListIngredients.isCompactMode = true
|
||||
|
||||
|
||||
// crafting list to the left
|
||||
// TODO This UIItem need to be custom-built version of UIItemInventoryItemGrid, with requirements:
|
||||
// - Takes list of [net.torvald.terrarum.itemproperties.CraftingRecipe] as an "inventory"
|
||||
// - Displays `CraftingRecipe.product` as an "inventory cell"
|
||||
// - When clicked, the cell is activated and displays its `ingredients` to the itemListIngredients
|
||||
// - The clicked status must be recorded and be accessible to this very class
|
||||
itemListCraftable = UIItemCraftingCandidateGrid(
|
||||
this,
|
||||
catBar,
|
||||
thisOffsetX,
|
||||
thisOffsetY,
|
||||
6, UIInventoryFull.CELLS_VRT - 2, // decrease the internal height so that craft/cancel button would fit in
|
||||
keyDownFun = { _, _, _, _ -> },
|
||||
touchDownFun = { gameItem, amount, _, recipe0 ->
|
||||
/*if (gameItem != null) {
|
||||
negotiator.reject(craftables, getPlayerInventory(), gameItem, amount)
|
||||
}
|
||||
itemListUpdate()*/
|
||||
|
||||
val playerInventory = getPlayerInventory()
|
||||
|
||||
(recipe0 as? CraftingCodex.CraftingRecipe)?.let { recipe ->
|
||||
ingredients.clear()
|
||||
recipeClicked = recipe
|
||||
printdbg(this, "Recipe selected: $recipe")
|
||||
recipe.ingredients.forEach { ingredient ->
|
||||
// TODO item tag support
|
||||
if (ingredient.keyMode == CraftingCodex.CraftingItemKeyMode.TAG) {
|
||||
// If the player has the required item, use it; otherwise, will take an item from the ItemCodex
|
||||
val selectedItem = playerInventory.itemList.filter { (itm, qty) ->
|
||||
ItemCodex[itm]?.tags?.contains(ingredient.key) == true && qty >= ingredient.qty
|
||||
}.maxByOrNull { it.qty }?.itm ?: ((ItemCodex.itemCodex.firstNotNullOfOrNull { if (it.value.tags.contains(ingredient.key)) it.key else null }) ?: throw NullPointerException("Item with tag '${ingredient.key}' not found. Possible cause: game or a module not updated or installed"))
|
||||
|
||||
printdbg(this, "Adding ingredients by tag ${selectedItem} (${ingredient.qty})")
|
||||
ingredients.add(selectedItem, ingredient.qty)
|
||||
}
|
||||
else {
|
||||
printdbg(this, "Adding ingredients by name ${ingredient.key} (${ingredient.qty})")
|
||||
ingredients.add(ingredient.key, ingredient.qty)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
itemListIngredients.rebuild(catAll)
|
||||
}
|
||||
)
|
||||
buttonCraft = UIItemTextButton(this, "GAME_ACTION_CRAFT", thisOffsetX + 3 + buttonWidth + listGap, craftButtonsY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true)
|
||||
spinnerCraftCount = UIItemSpinner(this, thisOffsetX + 1, craftButtonsY, 1, 1, 100, 1, buttonWidth, numberToTextFunction = {"${it.toInt()}"})
|
||||
|
||||
buttonCraft.touchDownListener = { _,_,_,_ ->
|
||||
printdbg(this, "Craft!")
|
||||
}
|
||||
// make grid mode buttons work together
|
||||
// itemListCraftable.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
|
||||
// itemListCraftable.gridModeButtons[1].touchDownListener = { _,_,_,_ -> setCompact(true) }
|
||||
|
||||
// player inventory to the right
|
||||
itemListPlayer = UIItemInventoryItemGrid(
|
||||
this,
|
||||
@@ -133,16 +162,17 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
||||
6, UIInventoryFull.CELLS_VRT,
|
||||
drawScrollOnRightside = true,
|
||||
drawWallet = false,
|
||||
keyDownFun = { _, _, _ -> },
|
||||
touchDownFun = { gameItem, amount, _ ->
|
||||
keyDownFun = { _, _, _, _ -> },
|
||||
touchDownFun = { gameItem, amount, _, _ ->
|
||||
/*if (gameItem != null) {
|
||||
negotiator.accept(getPlayerInventory(), getFixtureInventory(), gameItem, amount)
|
||||
}
|
||||
itemListUpdate()*/
|
||||
}
|
||||
)
|
||||
itemListPlayer.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
|
||||
itemListPlayer.gridModeButtons[1].touchDownListener = { _,_,_,_ -> setCompact(true) }
|
||||
// make grid mode buttons work together
|
||||
// itemListPlayer.gridModeButtons[0].touchDownListener = { _,_,_,_ -> setCompact(false) }
|
||||
// itemListPlayer.gridModeButtons[1].touchDownListener = { _,_,_,_ -> setCompact(true) }
|
||||
|
||||
handler.allowESCtoClose = true
|
||||
|
||||
@@ -183,8 +213,8 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
||||
}
|
||||
|
||||
// let itemlists be sorted
|
||||
itemListCraftable.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
|
||||
itemListPlayer.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
|
||||
itemListCraftable.rebuild(catAll)
|
||||
itemListPlayer.rebuild(catAll)
|
||||
encumbrancePerc = getPlayerInventory().let {
|
||||
it.capacity.toFloat() / it.maxCapacity
|
||||
}
|
||||
@@ -195,13 +225,13 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(
|
||||
itemListCraftable.gridModeButtons[0].highlighted = !yes
|
||||
itemListCraftable.gridModeButtons[1].highlighted = yes
|
||||
itemListCraftable.itemPage = 0
|
||||
itemListCraftable.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
|
||||
itemListCraftable.rebuild(catAll)
|
||||
|
||||
itemListPlayer.isCompactMode = yes
|
||||
itemListPlayer.gridModeButtons[0].highlighted = !yes
|
||||
itemListPlayer.gridModeButtons[1].highlighted = yes
|
||||
itemListPlayer.itemPage = 0
|
||||
itemListPlayer.rebuild(catBar.catIconsMeaning[catBar.selectedIcon])
|
||||
itemListPlayer.rebuild(catAll)
|
||||
|
||||
itemListUpdate()
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.gameitems.mouseInInteractableRange
|
||||
import net.torvald.terrarum.gameitems.mouseInInteractableRangeTools
|
||||
import net.torvald.terrarum.itemproperties.Calculate
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem
|
||||
@@ -113,7 +112,7 @@ object PickaxeCore {
|
||||
class PickaxeCopper(originalID: ItemID) : GameItem(originalID) {
|
||||
internal constructor() : this("-uninitialised-")
|
||||
|
||||
override val originalName = "PACKAGED_PICK"
|
||||
override val originalName = "COPPER_PICK"
|
||||
override var baseToolSize: Double? = BASE_MASS_AND_SIZE
|
||||
override var stackable = true
|
||||
override var inventoryCategory = Category.TOOL
|
||||
@@ -129,6 +128,7 @@ class PickaxeCopper(originalID: ItemID) : GameItem(originalID) {
|
||||
super.maxDurability = (TOOL_DURABILITY_BASE * material.enduranceMod).roundToInt()
|
||||
super.durability = maxDurability.toFloat()
|
||||
super.name = "Copper Pickaxe"
|
||||
super.tags.add("PICK")
|
||||
}
|
||||
|
||||
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = PickaxeCore.startPrimaryUse(actor, delta, this, Terrarum.mouseTileX, Terrarum.mouseTileY)
|
||||
@@ -141,7 +141,7 @@ class PickaxeCopper(originalID: ItemID) : GameItem(originalID) {
|
||||
class PickaxeIron(originalID: ItemID) : GameItem(originalID) {
|
||||
internal constructor() : this("-uninitialised-")
|
||||
|
||||
override val originalName = "PACKAGED_PICK"
|
||||
override val originalName = "IRON_PICK"
|
||||
override var baseToolSize: Double? = BASE_MASS_AND_SIZE
|
||||
override var stackable = true
|
||||
override var inventoryCategory = Category.TOOL
|
||||
@@ -157,6 +157,7 @@ class PickaxeIron(originalID: ItemID) : GameItem(originalID) {
|
||||
super.maxDurability = (TOOL_DURABILITY_BASE * material.enduranceMod).roundToInt()
|
||||
super.durability = maxDurability.toFloat()
|
||||
super.name = "Iron Pickaxe"
|
||||
super.tags.add("PICK")
|
||||
}
|
||||
|
||||
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = PickaxeCore.startPrimaryUse(actor , delta, this, Terrarum.mouseTileX, Terrarum.mouseTileY)
|
||||
@@ -169,7 +170,7 @@ class PickaxeIron(originalID: ItemID) : GameItem(originalID) {
|
||||
class PickaxeSteel(originalID: ItemID) : GameItem(originalID) {
|
||||
internal constructor() : this("-uninitialised-")
|
||||
|
||||
override val originalName = "PACKAGED_PICK"
|
||||
override val originalName = "STEEL_PICK"
|
||||
override var baseToolSize: Double? = BASE_MASS_AND_SIZE
|
||||
override var stackable = true
|
||||
override var inventoryCategory = Category.TOOL
|
||||
@@ -185,6 +186,7 @@ class PickaxeSteel(originalID: ItemID) : GameItem(originalID) {
|
||||
super.maxDurability = (TOOL_DURABILITY_BASE * material.enduranceMod).roundToInt()
|
||||
super.durability = maxDurability.toFloat()
|
||||
super.name = "Steel Pickaxe"
|
||||
super.tags.add("PICK")
|
||||
}
|
||||
|
||||
override fun startPrimaryUse(actor: ActorWithBody, delta: Float) = PickaxeCore.startPrimaryUse(actor, delta, this, Terrarum.mouseTileX, Terrarum.mouseTileY)
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import net.torvald.terrarum.CraftingRecipeCodex
|
||||
import net.torvald.terrarum.ItemCodex
|
||||
import net.torvald.terrarum.UIItemInventoryCatBar
|
||||
import net.torvald.terrarum.ceilInt
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.itemproperties.CraftingCodex
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.UICrafting
|
||||
|
||||
/**
|
||||
* 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?) -> Unit, // Item, Amount, Keycode, extra info
|
||||
touchDownFun: (GameItem?, Long, Int, Any?) -> Unit // Item, Amount, Button, extra info
|
||||
) : UIItemInventoryItemGrid(
|
||||
parentUI, catBar,
|
||||
{ TODO() /* UNUSED and MUST NOT BE USED! */ },
|
||||
initialX, initialY,
|
||||
horizontalCells, verticalCells,
|
||||
drawScrollOnRightside,
|
||||
drawWallet = false,
|
||||
hideSidebar = false,
|
||||
keyDownFun = keyDownFun,
|
||||
touchDownFun = touchDownFun
|
||||
) {
|
||||
|
||||
val craftingRecipes = ArrayList<CraftingCodex.CraftingRecipe>()
|
||||
|
||||
init {
|
||||
}
|
||||
|
||||
internal val recipesSortList = ArrayList<CraftingCodex.CraftingRecipe>() // a dual to the [inventorySortList] which contains the actual recipes instead of crafting recipes
|
||||
|
||||
override fun rebuild(filter: Array<String>) {
|
||||
// test fill craftingRecipes with every possible recipes in the game
|
||||
craftingRecipes.clear()
|
||||
CraftingRecipeCodex.props.forEach { (_, recipes) -> craftingRecipes.addAll(recipes) }
|
||||
|
||||
|
||||
recipesSortList.clear() // kinda like the output list
|
||||
|
||||
craftingRecipes.forEach {
|
||||
if ((filter.contains((ItemCodex[it.product]?.inventoryCategory ?: throw IllegalArgumentException("Unknown item: ${it.product}"))) || filter[0] == UIItemInventoryCatBar.CAT_ALL))
|
||||
recipesSortList.add(it)
|
||||
}
|
||||
|
||||
// map sortList to item list
|
||||
for (k in items.indices) {
|
||||
// we have an item
|
||||
try {
|
||||
val sortListItem = recipesSortList[k + itemPage * items.size]
|
||||
items[k].item = ItemCodex[sortListItem.product]
|
||||
items[k].amount = sortListItem.moq
|
||||
items[k].itemImage = ItemCodex.getItemImage(sortListItem.product)
|
||||
items[k].extraInfo = sortListItem
|
||||
|
||||
// set quickslot number
|
||||
/*if (getInventory() is ActorInventory) {
|
||||
val ainv = getInventory() as ActorInventory
|
||||
|
||||
for (qs in 1..UIQuickslotBar.SLOT_COUNT) {
|
||||
if (sortListItem.product == ainv.getQuickslotItem(qs - 1)?.itm) {
|
||||
items[k].quickslot = qs % 10 // 10 -> 0, 1..9 -> 1..9
|
||||
break
|
||||
}
|
||||
else
|
||||
items[k].quickslot = null
|
||||
}
|
||||
|
||||
// set equippedslot number
|
||||
for (eq in ainv.itemEquipped.indices) {
|
||||
if (eq < ainv.itemEquipped.size) {
|
||||
if (ainv.itemEquipped[eq] == items[k].item?.dynamicID) {
|
||||
items[k].equippedSlot = eq
|
||||
break
|
||||
}
|
||||
else
|
||||
items[k].equippedSlot = null
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
// we do not have an item, empty the slot
|
||||
catch (e: IndexOutOfBoundsException) {
|
||||
items[k].item = null
|
||||
items[k].amount = 0
|
||||
items[k].itemImage = null
|
||||
items[k].quickslot = null
|
||||
items[k].equippedSlot = null
|
||||
items[k].extraInfo = null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
itemPageCount = (recipesSortList.size.toFloat() / items.size.toFloat()).ceilInt()
|
||||
|
||||
rebuildList = false
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.GdxColorMap
|
||||
import net.torvald.terrarum.abs
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
@@ -27,20 +26,21 @@ abstract class UIItemInventoryCellBase(
|
||||
open var itemImage: TextureRegion?,
|
||||
open var quickslot: Int? = null,
|
||||
open var equippedSlot: Int? = null,
|
||||
val keyDownFun: (GameItem?, Long, Int) -> Unit, // Item, Amount, Keycode
|
||||
val touchDownFun: (GameItem?, Long, Int) -> Unit // Item, Amount, Button
|
||||
val keyDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Keycode, extra info
|
||||
val touchDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Button, extra info
|
||||
open var extraInfo: Any?
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
abstract override fun update(delta: Float)
|
||||
abstract override fun render(batch: SpriteBatch, camera: Camera)
|
||||
|
||||
override fun keyDown(keycode: Int): Boolean {
|
||||
keyDownFun(item, amount, keycode)
|
||||
keyDownFun(item, amount, keycode, extraInfo)
|
||||
super.keyDown(keycode)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
touchDownFun(item, amount, button)
|
||||
touchDownFun(item, amount, button, extraInfo)
|
||||
super.touchDown(screenX, screenY, pointer, button)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import kotlin.math.floor
|
||||
*
|
||||
* Created by minjaesong on 2017-10-21.
|
||||
*/
|
||||
class UIItemInventoryItemGrid(
|
||||
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
|
||||
@@ -42,8 +42,8 @@ class UIItemInventoryItemGrid(
|
||||
val drawScrollOnRightside: Boolean = false,
|
||||
val drawWallet: Boolean = true,
|
||||
val hideSidebar: Boolean = false,
|
||||
keyDownFun: (GameItem?, Long, Int) -> Unit, // Item, Amount, Keycode
|
||||
touchDownFun: (GameItem?, Long, Int) -> Unit // Item, Amount, Button
|
||||
keyDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Keycode, extra info
|
||||
touchDownFun: (GameItem?, Long, Int, Any?) -> Unit // Item, Amount, Button, extra info
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
// deal with the moving position
|
||||
@@ -85,13 +85,13 @@ class UIItemInventoryItemGrid(
|
||||
rebuild(currentFilter)
|
||||
}
|
||||
var itemPageCount = 1 // TODO total size of current category / items.size
|
||||
private set
|
||||
protected set
|
||||
|
||||
var inventorySortList = ArrayList<InventoryPair>()
|
||||
private var rebuildList = true
|
||||
protected var rebuildList = true
|
||||
|
||||
private val walletFont = TextureRegionPack("./assets/graphics/fonts/inventory_wallet_numbers.tga", 20, 9)
|
||||
private var walletText = ""
|
||||
protected val walletFont = TextureRegionPack("./assets/graphics/fonts/inventory_wallet_numbers.tga", 20, 9)
|
||||
protected var walletText = ""
|
||||
|
||||
|
||||
companion object {
|
||||
@@ -101,8 +101,8 @@ class UIItemInventoryItemGrid(
|
||||
fun getEstimatedW(horizontalCells: Int) = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
|
||||
fun getEstimatedH(verticalCells: Int) = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
|
||||
|
||||
fun createInvCellGenericKeyDownFun(): (GameItem?, Long, Int) -> Unit {
|
||||
return { item: GameItem?, amount: Long, keycode: Int ->
|
||||
fun createInvCellGenericKeyDownFun(): (GameItem?, Long, Int, Any?) -> Unit {
|
||||
return { item: GameItem?, amount: Long, keycode: Int, _ ->
|
||||
if (item != null && Terrarum.ingame != null && keycode in Input.Keys.NUM_0..Input.Keys.NUM_9) {
|
||||
val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
|
||||
if (player != null) {
|
||||
@@ -131,8 +131,8 @@ class UIItemInventoryItemGrid(
|
||||
}
|
||||
}
|
||||
|
||||
fun createInvCellGenericTouchDownFun(listRebuildFun: () -> Unit): (GameItem?, Long, Int) -> Unit {
|
||||
return { item: GameItem?, amount: Long, button: Int ->
|
||||
fun createInvCellGenericTouchDownFun(listRebuildFun: () -> Unit): (GameItem?, Long, Int, Any?) -> Unit {
|
||||
return { item: GameItem?, amount: Long, button: Int, _ ->
|
||||
if (item != null && Terrarum.ingame != null) {
|
||||
// equip da shit
|
||||
val itemEquipSlot = item.equipPosition
|
||||
@@ -202,7 +202,7 @@ class UIItemInventoryItemGrid(
|
||||
)
|
||||
}
|
||||
|
||||
private var items: Array<UIItemInventoryCellBase> = itemList
|
||||
protected var items: Array<UIItemInventoryCellBase> = itemList
|
||||
|
||||
var isCompactMode = false // this is INIT code
|
||||
set(value) {
|
||||
@@ -324,19 +324,20 @@ class UIItemInventoryItemGrid(
|
||||
gridModeButtons.forEach { it.render(batch, camera) }
|
||||
scrollUpButton.render(batch, camera)
|
||||
scrollDownButton.render(batch, camera)
|
||||
|
||||
// draw scroll dots
|
||||
for (i in 0 until itemPageCount) {
|
||||
val colour = if (i == itemPage) Color.WHITE else Color(0xffffff7f.toInt())
|
||||
|
||||
batch.color = colour
|
||||
batch.draw(
|
||||
catBar.catIcons.get(if (i == itemPage) 20 else 21, 0),
|
||||
scrollUpButton.posX.toFloat(),
|
||||
getScrollDotYHeight(i).toFloat()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// draw scroll dots
|
||||
for (i in 0 until itemPageCount) {
|
||||
val colour = if (i == itemPage) Color.WHITE else Color(0xffffff7f.toInt())
|
||||
|
||||
batch.color = colour
|
||||
batch.draw(
|
||||
catBar.catIcons.get(if (i == itemPage) 20 else 21, 0),
|
||||
scrollUpButton.posX.toFloat(),
|
||||
getScrollDotYHeight(i).toFloat()
|
||||
)
|
||||
}
|
||||
|
||||
// draw wallet text
|
||||
if (drawWallet) {
|
||||
@@ -398,7 +399,7 @@ class UIItemInventoryItemGrid(
|
||||
}
|
||||
|
||||
|
||||
internal fun rebuild(filter: Array<String>) {
|
||||
open internal fun rebuild(filter: Array<String>) {
|
||||
//println("Rebuilt inventory")
|
||||
//println("rebuild: actual itempage: $itemPage")
|
||||
|
||||
@@ -406,7 +407,7 @@ class UIItemInventoryItemGrid(
|
||||
//val filter = catIconsMeaning[selectedIcon]
|
||||
currentFilter = filter
|
||||
|
||||
inventorySortList = ArrayList<InventoryPair>()
|
||||
inventorySortList.clear()
|
||||
|
||||
// filter items
|
||||
getInventory().forEach {
|
||||
|
||||
Reference in New Issue
Block a user