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)
_getItemListIngredients().rebuild(catAll)
highlightCraftingCandidateButton(button)
highlightCraftingCandidateButton(recipe)
oldSelectedItems.clear()
oldSelectedItems.addAll(selectedItems)
@@ -348,8 +348,8 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
itemListIngredients.rebuild(catAll)
}
private fun highlightCraftingCandidateButton(button: UIItemInventoryCellBase?) { // a proxy function
itemListCraftable.highlightButton(button)
private fun highlightCraftingCandidateButton(recipe: CraftingCodex.CraftingRecipe?) { // a proxy function
itemListCraftable.highlightRecipe(recipe)
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
fun highlightButton(button: UIItemInventoryCellBase?) {
items.forEach { it.forceHighlighted = false }
button?.forceHighlighted = true
private var highlightedRecipe: CraftingCodex.CraftingRecipe? = null
button?.let {
printdbg(this, "highlighting button UIItemInventoryCellBase: ${it.item?.dynamicID}, ${it.amount}")
fun highlightRecipe(recipe: CraftingCodex.CraftingRecipe?) {
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 {
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>) {
// filtering policy: if the player have all the ingredient item (regardless of the amount!), make the recipe visible
craftingRecipes.clear()
@@ -68,28 +88,41 @@ class UIItemCraftingCandidateGrid(
// map sortList to item list
for (k in items.indices) {
val item = items[k]
// we have an item
try {
val sortListItem = recipesSortList[k + itemPage * items.size]
items[k].item = ItemCodex[sortListItem.product]
items[k].amount = sortListItem.moq * numberMultiplier
items[k].itemImage = ItemCodex.getItemImage(sortListItem.product)
items[k].extraInfo = sortListItem
item.item = ItemCodex[sortListItem.product]
item.amount = sortListItem.moq * numberMultiplier
item.itemImage = ItemCodex.getItemImage(sortListItem.product)
item.extraInfo = sortListItem
item.forceHighlighted = (item.extraInfo == highlightedRecipe)
}
// 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
item.item = null
item.amount = 0
item.itemImage = null
item.quickslot = null
item.equippedSlot = null
item.extraInfo = null
item.forceHighlighted = false
}
}
itemPageCount = (recipesSortList.size.toFloat() / items.size.toFloat()).ceilToInt()
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(CAT_ALL)
)*/
private var currentFilter = arrayOf(CAT_ALL)
protected var currentFilter = arrayOf(CAT_ALL)
private val inventoryUI = parentUI
@@ -183,7 +183,7 @@ open class 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(
parentUI = inventoryUI,
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 actualItemCellWidth = (listGap + UIItemInventoryElemSimple.height) * horizontalCells - listGap // in pixels
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(
parentUI = inventoryUI,
initialX = this.posX + (largeListWidth + listGap) * (it % itemListColumnCount),
@@ -221,11 +221,11 @@ open class UIItemInventoryItemGrid(
var items: Array<UIItemInventoryCellBase> = itemList
var isCompactMode = false // this is INIT code
open var isCompactMode = false // this is INIT code
set(value) {
field = value
items = if (value) itemGrid else itemList
rebuild(currentFilter)
field = value
}
private val iconPosX = if (drawScrollOnRightside)
@@ -243,7 +243,7 @@ open class UIItemInventoryItemGrid(
itemList.forEach { it.customHighlightRule2 = predicate }
}
fun scrollItemPage(relativeAmount: Int) {
open fun scrollItemPage(relativeAmount: Int) {
itemPage = if (itemPageCount == 0) 0 else (itemPage + relativeAmount).fmod(itemPageCount)
}