a cell for items to craft will highlight when selected

This commit is contained in:
minjaesong
2022-06-29 00:02:18 +09:00
parent b34502ebd3
commit 9edfc90ad8
7 changed files with 46 additions and 34 deletions

View File

@@ -16,8 +16,8 @@ class UIItemCraftingCandidateGrid(
initialX: Int, initialY: Int,
horizontalCells: Int, verticalCells: Int,
drawScrollOnRightside: Boolean = false,
keyDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Keycode, extra info
touchDownFun: (GameItem?, Long, Int, Any?) -> Unit // Item, Amount, Button, extra info
keyDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Keycode, extra info, keyed button
touchDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit // Item, Amount, Button, extra info, clicked button
) : UIItemInventoryItemGrid(
parentUI, catBar,
{ TODO() /* UNUSED and MUST NOT BE USED! */ },
@@ -37,6 +37,11 @@ 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
}
override fun rebuild(filter: Array<String>) {
// test fill craftingRecipes with every possible recipes in the game
craftingRecipes.clear()

View File

@@ -26,21 +26,23 @@ abstract class UIItemInventoryCellBase(
open var itemImage: TextureRegion?,
open var quickslot: Int? = null,
open var equippedSlot: Int? = null,
val keyDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Keycode, extra info
val touchDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Button, extra info
val keyDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Keycode, extra info, self
val touchDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Button, extra info, self
open var extraInfo: Any?
) : UIItem(parentUI, initialX, initialY) {
abstract override fun update(delta: Float)
abstract override fun render(batch: SpriteBatch, camera: Camera)
var forceHighlighted = false
override fun keyDown(keycode: Int): Boolean {
keyDownFun(item, amount, keycode, extraInfo)
keyDownFun(item, amount, keycode, extraInfo, this)
super.keyDown(keycode)
return true
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
touchDownFun(item, amount, button, extraInfo)
touchDownFun(item, amount, button, extraInfo, this)
super.touchDown(screenX, screenY, pointer, button)
return true
}

View File

@@ -42,8 +42,8 @@ open class UIItemInventoryItemGrid(
val drawScrollOnRightside: Boolean = false,
val drawWallet: Boolean = true,
val hideSidebar: Boolean = false,
keyDownFun: (GameItem?, Long, Int, Any?) -> Unit, // Item, Amount, Keycode, extra info
touchDownFun: (GameItem?, Long, Int, Any?) -> Unit // Item, Amount, Button, extra info
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
) : UIItem(parentUI, initialX, initialY) {
// deal with the moving position
@@ -101,8 +101,8 @@ open class UIItemInventoryItemGrid(
fun getEstimatedW(horizontalCells: Int) = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
fun getEstimatedH(verticalCells: Int) = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
fun createInvCellGenericKeyDownFun(): (GameItem?, Long, Int, Any?) -> Unit {
return { item: GameItem?, amount: Long, keycode: Int, _ ->
fun createInvCellGenericKeyDownFun(): (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit {
return { item: GameItem?, amount: Long, keycode: Int, _, _ ->
if (item != null && Terrarum.ingame != null && keycode in Input.Keys.NUM_0..Input.Keys.NUM_9) {
val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player != null) {
@@ -131,8 +131,8 @@ open class UIItemInventoryItemGrid(
}
}
fun createInvCellGenericTouchDownFun(listRebuildFun: () -> Unit): (GameItem?, Long, Int, Any?) -> Unit {
return { item: GameItem?, amount: Long, button: Int, _ ->
fun createInvCellGenericTouchDownFun(listRebuildFun: () -> Unit): (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit {
return { item: GameItem?, amount: Long, button: Int, _, _ ->
if (item != null && Terrarum.ingame != null) {
// equip da shit
val itemEquipSlot = item.equipPosition