crafting ui: highlighting should work after mode change and scroll

This commit is contained in:
minjaesong
2023-09-17 17:05:28 +09:00
parent 596328688c
commit cd13696116
3 changed files with 57 additions and 24 deletions

View File

@@ -274,7 +274,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
_getItemListPlayer().rebuild(catAll) _getItemListPlayer().rebuild(catAll)
_getItemListIngredients().rebuild(catAll) _getItemListIngredients().rebuild(catAll)
highlightCraftingCandidateButton(button) highlightCraftingCandidateButton(recipe)
oldSelectedItems.clear() oldSelectedItems.clear()
oldSelectedItems.addAll(selectedItems) oldSelectedItems.addAll(selectedItems)
@@ -348,8 +348,8 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
itemListIngredients.rebuild(catAll) itemListIngredients.rebuild(catAll)
} }
private fun highlightCraftingCandidateButton(button: UIItemInventoryCellBase?) { // a proxy function private fun highlightCraftingCandidateButton(recipe: CraftingCodex.CraftingRecipe?) { // a proxy function
itemListCraftable.highlightButton(button) itemListCraftable.highlightRecipe(recipe)
itemListCraftable.rebuild(catAll) itemListCraftable.rebuild(catAll)
} }

View File

@@ -36,19 +36,39 @@ class UIItemCraftingCandidateGrid(
internal val recipesSortList = ArrayList<CraftingCodex.CraftingRecipe>() // a dual to the [inventorySortList] which contains the actual recipes instead of crafting recipes internal val recipesSortList = ArrayList<CraftingCodex.CraftingRecipe>() // a dual to the [inventorySortList] which contains the actual recipes instead of crafting recipes
fun highlightButton(button: UIItemInventoryCellBase?) { private var highlightedRecipe: CraftingCodex.CraftingRecipe? = null
items.forEach { it.forceHighlighted = false }
button?.forceHighlighted = true
button?.let { fun highlightRecipe(recipe: CraftingCodex.CraftingRecipe?) {
printdbg(this, "highlighting button UIItemInventoryCellBase: ${it.item?.dynamicID}, ${it.amount}") items.forEach { it.forceHighlighted = false }
highlightedRecipe = recipe
recipe?.let {
items.find { it.extraInfo == recipe }?.let { buttonFound ->
buttonFound.forceHighlighted = true
}
} }
} }
override var isCompactMode = false // this is INIT code
set(value) {
field = value
items = if (value) itemGrid else itemList
highlightRecipe(highlightedRecipe)
rebuild(currentFilter)
}
private fun isCraftable(player: FixtureInventory, recipe: CraftingCodex.CraftingRecipe, nearbyCraftingStations: List<String>): Boolean { private fun isCraftable(player: FixtureInventory, recipe: CraftingCodex.CraftingRecipe, nearbyCraftingStations: List<String>): Boolean {
return UICrafting.recipeToIngredientRecord(player, recipe, nearbyCraftingStations).none { it.howManyPlayerHas <= 0L || !it.craftingStationAvailable } return UICrafting.recipeToIngredientRecord(player, recipe, nearbyCraftingStations).none { it.howManyPlayerHas <= 0L || !it.craftingStationAvailable }
} }
override fun scrollItemPage(relativeAmount: Int) {
super.scrollItemPage(relativeAmount)
// update highlighter status
highlightRecipe(highlightedRecipe)
}
override fun rebuild(filter: Array<String>) { override fun rebuild(filter: Array<String>) {
// filtering policy: if the player have all the ingredient item (regardless of the amount!), make the recipe visible // filtering policy: if the player have all the ingredient item (regardless of the amount!), make the recipe visible
craftingRecipes.clear() craftingRecipes.clear()
@@ -68,28 +88,41 @@ class UIItemCraftingCandidateGrid(
// map sortList to item list // map sortList to item list
for (k in items.indices) { for (k in items.indices) {
val item = items[k]
// we have an item // we have an item
try { try {
val sortListItem = recipesSortList[k + itemPage * items.size] val sortListItem = recipesSortList[k + itemPage * items.size]
items[k].item = ItemCodex[sortListItem.product] item.item = ItemCodex[sortListItem.product]
items[k].amount = sortListItem.moq * numberMultiplier item.amount = sortListItem.moq * numberMultiplier
items[k].itemImage = ItemCodex.getItemImage(sortListItem.product) item.itemImage = ItemCodex.getItemImage(sortListItem.product)
items[k].extraInfo = sortListItem item.extraInfo = sortListItem
item.forceHighlighted = (item.extraInfo == highlightedRecipe)
} }
// we do not have an item, empty the slot // we do not have an item, empty the slot
catch (e: IndexOutOfBoundsException) { catch (e: IndexOutOfBoundsException) {
items[k].item = null item.item = null
items[k].amount = 0 item.amount = 0
items[k].itemImage = null item.itemImage = null
items[k].quickslot = null item.quickslot = null
items[k].equippedSlot = null item.equippedSlot = null
items[k].extraInfo = null item.extraInfo = null
item.forceHighlighted = false
} }
} }
itemPageCount = (recipesSortList.size.toFloat() / items.size.toFloat()).ceilToInt() itemPageCount = (recipesSortList.size.toFloat() / items.size.toFloat()).ceilToInt()
rebuildList = false rebuildList = false
} }
override fun scrolled(amountX: Float, amountY: Float): Boolean {
super.scrolled(amountX, amountY)
return true
}
} }

View File

@@ -81,7 +81,7 @@ open class UIItemInventoryItemGrid(
arrayOf(GameItem.Category.MISC), arrayOf(GameItem.Category.MISC),
arrayOf(CAT_ALL) arrayOf(CAT_ALL)
)*/ )*/
private var currentFilter = arrayOf(CAT_ALL) protected var currentFilter = arrayOf(CAT_ALL)
private val inventoryUI = parentUI private val inventoryUI = parentUI
@@ -183,7 +183,7 @@ open class UIItemInventoryItemGrid(
val tooltipShowing = HashMap<Long, Boolean>() // Long: `hash` field on UIItemInventoryItemGrid val tooltipShowing = HashMap<Long, Boolean>() // Long: `hash` field on UIItemInventoryItemGrid
} }
private val itemGrid = Array<UIItemInventoryCellBase>(horizontalCells * verticalCells) { protected val itemGrid = Array<UIItemInventoryCellBase>(horizontalCells * verticalCells) {
UIItemInventoryElemSimple( UIItemInventoryElemSimple(
parentUI = inventoryUI, parentUI = inventoryUI,
initialX = this.posX + (UIItemInventoryElemSimple.height + listGap) * (it % horizontalCells), initialX = this.posX + (UIItemInventoryElemSimple.height + listGap) * (it % horizontalCells),
@@ -202,7 +202,7 @@ open class UIItemInventoryItemGrid(
private val itemListColumnCount = floor(horizontalCells / 5f).toInt().coerceAtLeast(1) private val itemListColumnCount = floor(horizontalCells / 5f).toInt().coerceAtLeast(1)
private val actualItemCellWidth = (listGap + UIItemInventoryElemSimple.height) * horizontalCells - listGap // in pixels private val actualItemCellWidth = (listGap + UIItemInventoryElemSimple.height) * horizontalCells - listGap // in pixels
private val largeListWidth = ((listGap + actualItemCellWidth) / itemListColumnCount) - (itemListColumnCount - 1).coerceAtLeast(1) * listGap private val largeListWidth = ((listGap + actualItemCellWidth) / itemListColumnCount) - (itemListColumnCount - 1).coerceAtLeast(1) * listGap
private val itemList = Array<UIItemInventoryCellBase>(verticalCells * itemListColumnCount) { protected val itemList = Array<UIItemInventoryCellBase>(verticalCells * itemListColumnCount) {
UIItemInventoryElemWide( UIItemInventoryElemWide(
parentUI = inventoryUI, parentUI = inventoryUI,
initialX = this.posX + (largeListWidth + listGap) * (it % itemListColumnCount), initialX = this.posX + (largeListWidth + listGap) * (it % itemListColumnCount),
@@ -221,11 +221,11 @@ open class UIItemInventoryItemGrid(
var items: Array<UIItemInventoryCellBase> = itemList var items: Array<UIItemInventoryCellBase> = itemList
var isCompactMode = false // this is INIT code open var isCompactMode = false // this is INIT code
set(value) { set(value) {
field = value
items = if (value) itemGrid else itemList items = if (value) itemGrid else itemList
rebuild(currentFilter) rebuild(currentFilter)
field = value
} }
private val iconPosX = if (drawScrollOnRightside) private val iconPosX = if (drawScrollOnRightside)
@@ -243,7 +243,7 @@ open class UIItemInventoryItemGrid(
itemList.forEach { it.customHighlightRule2 = predicate } itemList.forEach { it.customHighlightRule2 = predicate }
} }
fun scrollItemPage(relativeAmount: Int) { open fun scrollItemPage(relativeAmount: Int) {
itemPage = if (itemPageCount == 0) 0 else (itemPage + relativeAmount).fmod(itemPageCount) itemPage = if (itemPageCount == 0) 0 else (itemPage + relativeAmount).fmod(itemPageCount)
} }