mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
fixed a bug where selected recipe does not highlight
This commit is contained in:
@@ -210,6 +210,9 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
||||
buttonCraft.touchDownListener = { _,_,_,_ ->
|
||||
getPlayerInventory().let { player -> recipeClicked?.let { recipe ->
|
||||
val mult = spinnerCraftCount.value.toLong()
|
||||
|
||||
// TODO check if player has enough amount of ingredients
|
||||
|
||||
itemListIngredients.getInventory().itemList.forEach { (itm, qty) ->
|
||||
player.remove(itm, qty * mult)
|
||||
}
|
||||
@@ -252,6 +255,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
||||
|
||||
private fun highlightCraftingCandidateButton(button: UIItemInventoryCellBase?) { // a proxy function
|
||||
itemListCraftable.highlightButton(button)
|
||||
itemListCraftable.rebuild(catAll)
|
||||
}
|
||||
|
||||
// reset whatever player has selected to null and bring UI to its initial state
|
||||
@@ -292,22 +296,6 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setCompact(yes: Boolean) {
|
||||
itemListCraftable.isCompactMode = yes
|
||||
itemListCraftable.gridModeButtons[0].highlighted = !yes
|
||||
itemListCraftable.gridModeButtons[1].highlighted = yes
|
||||
itemListCraftable.itemPage = 0
|
||||
itemListCraftable.rebuild(catAll)
|
||||
|
||||
itemListPlayer.isCompactMode = yes
|
||||
itemListPlayer.gridModeButtons[0].highlighted = !yes
|
||||
itemListPlayer.gridModeButtons[1].highlighted = yes
|
||||
itemListPlayer.itemPage = 0
|
||||
itemListPlayer.rebuild(catAll)
|
||||
|
||||
itemListUpdate()
|
||||
}
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
if (!openingClickLatched) {
|
||||
return super.touchDown(screenX, screenY, pointer, button)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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
|
||||
@@ -27,7 +28,8 @@ class UIItemCraftingCandidateGrid(
|
||||
drawWallet = false,
|
||||
hideSidebar = false,
|
||||
keyDownFun = keyDownFun,
|
||||
touchDownFun = touchDownFun
|
||||
touchDownFun = touchDownFun,
|
||||
useHighlightingManager = false
|
||||
) {
|
||||
|
||||
val craftingRecipes = ArrayList<CraftingCodex.CraftingRecipe>()
|
||||
@@ -38,13 +40,18 @@ class UIItemCraftingCandidateGrid(
|
||||
fun highlightButton(button: UIItemInventoryCellBase?) {
|
||||
items.forEach { it.forceHighlighted = false }
|
||||
button?.forceHighlighted = true
|
||||
|
||||
button?.let {
|
||||
printdbg(this, "highlighting button UIItemInventoryCellBase: ${it.item?.dynamicID}, ${it.amount}")
|
||||
}
|
||||
}
|
||||
|
||||
override fun rebuild(filter: Array<String>) {
|
||||
// test fill craftingRecipes with every possible recipes in the game
|
||||
// TODO test fill craftingRecipes with every possible recipes in the game
|
||||
// filtering policy: if the player have all the ingredient item (regardless of the amount!), make the recipe visible
|
||||
craftingRecipes.clear()
|
||||
CraftingRecipeCodex.props.forEach { (_, recipes) -> craftingRecipes.addAll(recipes) }
|
||||
|
||||
// end of test fill
|
||||
|
||||
recipesSortList.clear() // kinda like the output list
|
||||
|
||||
@@ -62,32 +69,6 @@ class UIItemCraftingCandidateGrid(
|
||||
items[k].amount = sortListItem.moq * numberMultiplier
|
||||
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) {
|
||||
|
||||
@@ -34,6 +34,13 @@ abstract class UIItemInventoryCellBase(
|
||||
abstract override fun render(batch: SpriteBatch, camera: Camera)
|
||||
|
||||
var forceHighlighted = false
|
||||
/*set(value) {
|
||||
if (field != value) {
|
||||
printdbg(this, "forceHighlighted: ${field} -> ${value}; ${App.GLOBAL_RENDER_TIMER}")
|
||||
printStackTrace(this)
|
||||
}
|
||||
field = value
|
||||
}*/
|
||||
|
||||
override fun keyDown(keycode: Int): Boolean {
|
||||
keyDownFun(item, amount, keycode, extraInfo, this)
|
||||
|
||||
@@ -44,7 +44,8 @@ open class UIItemInventoryItemGrid(
|
||||
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
|
||||
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
|
||||
) : UIItem(parentUI, initialX, initialY) {
|
||||
|
||||
// deal with the moving position
|
||||
@@ -322,7 +323,7 @@ open class UIItemInventoryItemGrid(
|
||||
|
||||
// define each button's highlighted status from the list of forceHighlighted, then render the button
|
||||
items.forEach {
|
||||
it.forceHighlighted = forceHighlightList.contains(it.item?.dynamicID)
|
||||
if (useHighlightingManager) it.forceHighlighted = forceHighlightList.contains(it.item?.dynamicID)
|
||||
it.render(batch, camera)
|
||||
}
|
||||
|
||||
@@ -405,6 +406,10 @@ open class UIItemInventoryItemGrid(
|
||||
}
|
||||
|
||||
private val forceHighlightList = HashSet<ItemID>()
|
||||
get() {
|
||||
if (!useHighlightingManager) throw IllegalStateException("useHighlightingManager is set to false")
|
||||
return field
|
||||
}
|
||||
|
||||
/**
|
||||
* Call before rebuild()
|
||||
@@ -481,11 +486,6 @@ open class UIItemInventoryItemGrid(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// highlight if matches
|
||||
if (forceHighlightList.contains(item.item?.dynamicID)) {
|
||||
item.forceHighlighted = true
|
||||
}
|
||||
}
|
||||
// we do not have an item, empty the slot
|
||||
catch (e: IndexOutOfBoundsException) {
|
||||
|
||||
Reference in New Issue
Block a user