From 84158319d15bccaba9fdb4668f30ae7d3f2cf77d Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 5 Jul 2022 17:25:36 +0900 Subject: [PATCH] '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 --- .../terrarum/UIItemInventoryElemWide.kt | 2 +- .../modulebasegame/gameactors/UICrafting.kt | 28 ++++++++++++++++--- .../ui/UIItemCraftingCandidateGrid.kt | 1 - .../ui/UIItemInventoryItemGrid.kt | 14 +++++----- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/net/torvald/terrarum/UIItemInventoryElemWide.kt b/src/net/torvald/terrarum/UIItemInventoryElemWide.kt index 01fbc05a7..71f7593ec 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElemWide.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElemWide.kt @@ -40,7 +40,7 @@ class UIItemInventoryElemWide( val height = 48 val UNIQUE_ITEM_HAS_NO_AMOUNT = -1L - internal val durabilityBarThickness = 3 + val durabilityBarThickness = 3 } override val height = UIItemInventoryElemWide.height diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt index 79a8ddfb6..24ea7280b 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt @@ -87,6 +87,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory { private fun _getItemListPlayer() = itemListPlayer private fun _getItemListIngredients() = itemListIngredients + private fun _getItemListCraftables() = itemListCraftable init { 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) } - _getItemListPlayer().removeFromForceHighlightList(oldSelectedItems) - _getItemListPlayer().addToForceHighlightList(selectedItems) - _getItemListPlayer().rebuild(catAll) + _getItemListPlayer().let { + it.removeFromForceHighlightList(oldSelectedItems) + it.addToForceHighlightList(selectedItems) + it.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.addAll(selectedItems) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt index ede794951..3d795e828 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemCraftingCandidateGrid.kt @@ -34,7 +34,6 @@ class UIItemCraftingCandidateGrid( val craftingRecipes = ArrayList() - internal val recipesSortList = ArrayList() // a dual to the [inventorySortList] which contains the actual recipes instead of crafting recipes fun highlightButton(button: UIItemInventoryCellBase?) { diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt index bd5cb93e6..fb6622391 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt @@ -213,7 +213,7 @@ open class UIItemInventoryItemGrid( ) } - protected var items: Array = itemList + var items: Array = itemList var isCompactMode = false // this is INIT code set(value) { @@ -231,7 +231,7 @@ open class UIItemInventoryItemGrid( posY - 1 + (4 + UIItemInventoryElemWide.height - catBar.catIcons.tileH) * index /** Long/compact mode buttons */ - internal val gridModeButtons = Array(2) { index -> + val gridModeButtons = Array(2) { index -> UIItemImageButton( parentUI, catBar.catIcons.get(index + 14, 0), @@ -424,29 +424,29 @@ open class UIItemInventoryItemGrid( private val forceHighlightList = HashSet() 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 } /** * Call before rebuild() */ - open internal fun clearForceHighlightList() { + open fun clearForceHighlightList() { forceHighlightList.clear() } /** * Call before rebuild() */ - open internal fun addToForceHighlightList(items: List) { + open fun addToForceHighlightList(items: List) { forceHighlightList.addAll(items) } - open internal fun removeFromForceHighlightList(items: List) { + open fun removeFromForceHighlightList(items: List) { forceHighlightList.removeAll(items) } - open internal fun rebuild(filter: Array) { + open fun rebuild(filter: Array) { //println("Rebuilt inventory") //println("rebuild: actual itempage: $itemPage")