'recipe for the recipe' selected by the game will also update the UI accordingly so that players would know the other recipe has been selected

This commit is contained in:
minjaesong
2022-07-05 17:25:36 +09:00
parent f2e690b936
commit 84158319d1
4 changed files with 32 additions and 13 deletions

View File

@@ -40,7 +40,7 @@ class UIItemInventoryElemWide(
val height = 48 val height = 48
val UNIQUE_ITEM_HAS_NO_AMOUNT = -1L val UNIQUE_ITEM_HAS_NO_AMOUNT = -1L
internal val durabilityBarThickness = 3 val durabilityBarThickness = 3
} }
override val height = UIItemInventoryElemWide.height override val height = UIItemInventoryElemWide.height

View File

@@ -87,6 +87,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
private fun _getItemListPlayer() = itemListPlayer private fun _getItemListPlayer() = itemListPlayer
private fun _getItemListIngredients() = itemListIngredients private fun _getItemListIngredients() = itemListIngredients
private fun _getItemListCraftables() = itemListCraftable
init { init {
val craftButtonsY = thisOffsetY + 23 + (UIItemInventoryElemWide.height + listGap) * (UIInventoryFull.CELLS_VRT - 1) val craftButtonsY = thisOffsetY + 23 + (UIItemInventoryElemWide.height + listGap) * (UIInventoryFull.CELLS_VRT - 1)
@@ -163,12 +164,31 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
ingredients.add(itm, qty) ingredients.add(itm, qty)
} }
_getItemListPlayer().removeFromForceHighlightList(oldSelectedItems) _getItemListPlayer().let {
_getItemListPlayer().addToForceHighlightList(selectedItems) it.removeFromForceHighlightList(oldSelectedItems)
_getItemListPlayer().rebuild(catAll) it.addToForceHighlightList(selectedItems)
it.rebuild(catAll)
}
_getItemListIngredients().rebuild(catAll) _getItemListIngredients().rebuild(catAll)
// TODO highlightCraftingCandidateButton by searching for the buttons that has the recipe // highlighting CraftingCandidateButton by searching for the buttons that has the recipe
_getItemListCraftables().let {
// turn the highlights off
it.items.forEach { it.forceHighlighted = false }
// search for the recipe
// also need to find what "page" the recipe might be in
// use it.isCompactMode to find out the current mode
var ord = 0
while (ord < it.craftingRecipes.indices.last) {
if (recipeClicked == it.craftingRecipes[ord]) break
ord += 1
}
val itemSize = it.items.size
it.itemPage = ord / itemSize
it.items[ord % itemSize].forceHighlighted = true
}
oldSelectedItems.clear() oldSelectedItems.clear()
oldSelectedItems.addAll(selectedItems) oldSelectedItems.addAll(selectedItems)

View File

@@ -34,7 +34,6 @@ class UIItemCraftingCandidateGrid(
val craftingRecipes = ArrayList<CraftingCodex.CraftingRecipe>() val craftingRecipes = ArrayList<CraftingCodex.CraftingRecipe>()
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?) { fun highlightButton(button: UIItemInventoryCellBase?) {

View File

@@ -213,7 +213,7 @@ open class UIItemInventoryItemGrid(
) )
} }
protected var items: Array<UIItemInventoryCellBase> = itemList var items: Array<UIItemInventoryCellBase> = itemList
var isCompactMode = false // this is INIT code var isCompactMode = false // this is INIT code
set(value) { set(value) {
@@ -231,7 +231,7 @@ open class UIItemInventoryItemGrid(
posY - 1 + (4 + UIItemInventoryElemWide.height - catBar.catIcons.tileH) * index posY - 1 + (4 + UIItemInventoryElemWide.height - catBar.catIcons.tileH) * index
/** Long/compact mode buttons */ /** Long/compact mode buttons */
internal val gridModeButtons = Array<UIItemImageButton>(2) { index -> val gridModeButtons = Array<UIItemImageButton>(2) { index ->
UIItemImageButton( UIItemImageButton(
parentUI, parentUI,
catBar.catIcons.get(index + 14, 0), catBar.catIcons.get(index + 14, 0),
@@ -424,29 +424,29 @@ open class UIItemInventoryItemGrid(
private val forceHighlightList = HashSet<ItemID>() private val forceHighlightList = HashSet<ItemID>()
get() { get() {
if (!useHighlightingManager) throw IllegalStateException("useHighlightingManager is set to false") if (!useHighlightingManager) throw IllegalStateException("useHighlightingManager is set to false; you the programmer are in charge of managing the highlighting status of buttons by yourself!")
return field return field
} }
/** /**
* Call before rebuild() * Call before rebuild()
*/ */
open internal fun clearForceHighlightList() { open fun clearForceHighlightList() {
forceHighlightList.clear() forceHighlightList.clear()
} }
/** /**
* Call before rebuild() * Call before rebuild()
*/ */
open internal fun addToForceHighlightList(items: List<ItemID>) { open fun addToForceHighlightList(items: List<ItemID>) {
forceHighlightList.addAll(items) forceHighlightList.addAll(items)
} }
open internal fun removeFromForceHighlightList(items: List<ItemID>) { open fun removeFromForceHighlightList(items: List<ItemID>) {
forceHighlightList.removeAll(items) forceHighlightList.removeAll(items)
} }
open internal fun rebuild(filter: Array<String>) { open fun rebuild(filter: Array<String>) {
//println("Rebuilt inventory") //println("Rebuilt inventory")
//println("rebuild: actual itempage: $itemPage") //println("rebuild: actual itempage: $itemPage")