diff --git a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt index 7697adde0..ae9314142 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt @@ -25,8 +25,8 @@ class UIItemInventoryElemSimple( override var quickslot: Int? = null, override var equippedSlot: Int? = null, val drawBackOnNull: Boolean = true, - keyDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Keycode, extra info - touchDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Button, extra info + 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 extraInfo: Any? = null ) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun, extraInfo) { @@ -55,7 +55,7 @@ class UIItemInventoryElemSimple( Toolkit.fillArea(batch, posX, posY, width, height) } // cell border - batch.color = if (equippedSlot != null) Toolkit.Theme.COL_HIGHLIGHT + batch.color = if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT else if (mouseUp) Toolkit.Theme.COL_ACTIVE else Toolkit.Theme.COL_INVENTORY_CELL_BORDER Toolkit.drawBoxBorder(batch, posX, posY, width, height) @@ -95,7 +95,7 @@ class UIItemInventoryElemSimple( // if mouse is over, text lights up // highlight item count (blocks/walls) if the item is equipped batch.color = item!!.nameColour mul ( - if (equippedSlot != null) Toolkit.Theme.COL_HIGHLIGHT + if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT else if (mouseUp) Toolkit.Theme.COL_ACTIVE else Color.WHITE ) diff --git a/src/net/torvald/terrarum/UIItemInventoryElemWide.kt b/src/net/torvald/terrarum/UIItemInventoryElemWide.kt index 26f479f4a..5f582d2de 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElemWide.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElemWide.kt @@ -28,8 +28,8 @@ class UIItemInventoryElemWide( override var quickslot: Int? = null, override var equippedSlot: Int? = null, val drawBackOnNull: Boolean = true, - keyDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Keycode, extra info - touchDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Button, extra info + 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 extraInfo: Any? = null ) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun, extraInfo) { @@ -73,7 +73,7 @@ class UIItemInventoryElemWide( Toolkit.fillArea(batch, posX, posY, width, height) } // cell border - batch.color = if (equippedSlot != null) Toolkit.Theme.COL_HIGHLIGHT + batch.color = if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT else if (mouseUp) Toolkit.Theme.COL_ACTIVE else Toolkit.Theme.COL_INVENTORY_CELL_BORDER Toolkit.drawBoxBorder(batch, posX, posY, width, height) @@ -91,7 +91,7 @@ class UIItemInventoryElemWide( // if mouse is over, text lights up // highlight item name and count (blocks/walls) if the item is equipped batch.color = item!!.nameColour mul ( - if (equippedSlot != null) Toolkit.Theme.COL_HIGHLIGHT + if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT else if (mouseUp) Toolkit.Theme.COL_ACTIVE else Color.WHITE ) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt index 113ce5c6d..d3176258e 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt @@ -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) } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt index 1d90660b0..6498c41a9 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt @@ -34,7 +34,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas( override var openCloseTime: Second = 0.0f private val itemListPlayer: UIItemInventoryItemGrid - private val itemListCraftable: UIItemInventoryItemGrid // might be changed to something else + private val itemListCraftable: UIItemCraftingCandidateGrid // might be changed to something else private val itemListIngredients: UIItemInventoryItemGrid // this one is definitely not to be changed private val buttonCraft: UIItemTextButton private val spinnerCraftCount: UIItemSpinner @@ -86,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!) @@ -108,8 +108,8 @@ class UICrafting(val full: UIInventoryFull) : UICanvas( thisOffsetX, thisOffsetY, 6, UIInventoryFull.CELLS_VRT - 2, // decrease the internal height so that craft/cancel button would fit in - keyDownFun = { _, _, _, _ -> }, - touchDownFun = { gameItem, amount, _, recipe0 -> + keyDownFun = { _, _, _, _, _ -> }, + touchDownFun = { gameItem, amount, _, recipe0, button -> /*if (gameItem != null) { negotiator.reject(craftables, getPlayerInventory(), gameItem, amount) } @@ -120,7 +120,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas( (recipe0 as? CraftingCodex.CraftingRecipe)?.let { recipe -> ingredients.clear() recipeClicked = recipe - printdbg(this, "Recipe selected: $recipe") +// printdbg(this, "Recipe selected: $recipe") recipe.ingredients.forEach { ingredient -> // TODO item tag support if (ingredient.keyMode == CraftingCodex.CraftingItemKeyMode.TAG) { @@ -129,17 +129,18 @@ class UICrafting(val full: UIInventoryFull) : UICanvas( 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})") +// 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})") +// printdbg(this, "Adding ingredients by name ${ingredient.key} (${ingredient.qty})") ingredients.add(ingredient.key, ingredient.qty) } } } itemListIngredients.rebuild(catAll) + highlightCraftingCandidateButton(button) } ) buttonCraft = UIItemTextButton(this, "GAME_ACTION_CRAFT", thisOffsetX + 3 + buttonWidth + listGap, craftButtonsY, buttonWidth, true, alignment = UIItemTextButton.Companion.Alignment.CENTRE, hasBorder = true) @@ -162,8 +163,8 @@ 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) } @@ -183,6 +184,10 @@ class UICrafting(val full: UIInventoryFull) : UICanvas( addUIitem(buttonCraft) } + private fun highlightCraftingCandidateButton(button: UIItemInventoryCellBase) { // a proxy function + itemListCraftable.highlightButton(button) + } + // reset whatever player has selected to null and bring UI to its initial state fun resetUI() { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt index e5e95a785..00277b09d 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt @@ -16,8 +16,8 @@ class UIItemCraftingCandidateGrid( 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 + 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! */ }, @@ -37,6 +37,11 @@ class UIItemCraftingCandidateGrid( internal val recipesSortList = ArrayList() // a dual to the [inventorySortList] which contains the actual recipes instead of crafting recipes + fun highlightButton(button: UIItemInventoryCellBase) { + items.forEach { it.forceHighlighted = false } + button.forceHighlighted = true + } + override fun rebuild(filter: Array) { // test fill craftingRecipes with every possible recipes in the game craftingRecipes.clear() diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt index 9e9453925..3c18ddbb7 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryCellBase.kt @@ -26,21 +26,23 @@ abstract class UIItemInventoryCellBase( open var itemImage: TextureRegion?, open var quickslot: Int? = null, open var equippedSlot: Int? = null, - val keyDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Keycode, extra info - val touchDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Button, extra info + val keyDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Keycode, extra info, self + val touchDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Button, extra info, self open var extraInfo: Any? ) : UIItem(parentUI, initialX, initialY) { abstract override fun update(delta: Float) abstract override fun render(batch: SpriteBatch, camera: Camera) + var forceHighlighted = false + override fun keyDown(keycode: Int): Boolean { - keyDownFun(item, amount, keycode, extraInfo) + keyDownFun(item, amount, keycode, extraInfo, this) super.keyDown(keycode) return true } override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { - touchDownFun(item, amount, button, extraInfo) + touchDownFun(item, amount, button, extraInfo, this) super.touchDown(screenX, screenY, pointer, button) return true } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt index ffbb99a45..37581a02f 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt @@ -42,8 +42,8 @@ open class UIItemInventoryItemGrid( val drawScrollOnRightside: Boolean = false, val drawWallet: Boolean = true, val hideSidebar: Boolean = false, - keyDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Keycode, extra info - touchDownFun: (GameItem?, Long, Int, Any?) -> Unit // Item, Amount, Button, extra info + 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 ) : UIItem(parentUI, initialX, initialY) { // deal with the moving position @@ -101,8 +101,8 @@ open 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, Any?) -> Unit { - return { item: GameItem?, amount: Long, keycode: Int, _ -> + fun createInvCellGenericKeyDownFun(): (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> 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 @@ open class UIItemInventoryItemGrid( } } - fun createInvCellGenericTouchDownFun(listRebuildFun: () -> Unit): (GameItem?, Long, Int, Any?) -> Unit { - return { item: GameItem?, amount: Long, button: Int, _ -> + fun createInvCellGenericTouchDownFun(listRebuildFun: () -> Unit): (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit { + return { item: GameItem?, amount: Long, button: Int, _, _ -> if (item != null && Terrarum.ingame != null) { // equip da shit val itemEquipSlot = item.equipPosition