crafting ui item cell highlighting works as intended

This commit is contained in:
minjaesong
2022-07-02 18:06:52 +09:00
parent 60497e4201
commit 4eb3ad07f3
5 changed files with 22 additions and 13 deletions

View File

@@ -23,12 +23,13 @@ class UIItemInventoryElemSimple(
override var amount: Long,
override var itemImage: TextureRegion?,
override var quickslot: Int? = null,
override var equippedSlot: Int? = null,
override var equippedSlot: Int? = null, // remnants of wide cell displaying slot number and highlighting; in this style of cell this field only determines highlightedness at render
val drawBackOnNull: Boolean = true,
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
extraInfo: Any? = null
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun, extraInfo) {
extraInfo: Any? = null,
highlightEquippedItem: Boolean = true // for some UIs that only cares about getting equipped slot number but not highlighting
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun, extraInfo, highlightEquippedItem) {
companion object {
val height = UIItemInventoryElemWide.height
@@ -55,7 +56,7 @@ class UIItemInventoryElemSimple(
Toolkit.fillArea(batch, posX, posY, width, height)
}
// cell border
batch.color = if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
batch.color = if ((equippedSlot != null && highlightEquippedItem) || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
else if (mouseUp && item != null) Toolkit.Theme.COL_ACTIVE
else Toolkit.Theme.COL_INVENTORY_CELL_BORDER
Toolkit.drawBoxBorder(batch, posX, posY, width, height)
@@ -95,7 +96,7 @@ class UIItemInventoryElemSimple(
// if mouse is over, text lights up
// highlight item count (blocks/walls) if the item is equipped
batch.color = item!!.nameColour mul (
if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
if ((equippedSlot != null && highlightEquippedItem) || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
else if (mouseUp && item != null) Toolkit.Theme.COL_ACTIVE
else Color.WHITE
)

View File

@@ -30,8 +30,9 @@ class UIItemInventoryElemWide(
val drawBackOnNull: Boolean = true,
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
extraInfo: Any? = null
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun, extraInfo) {
extraInfo: Any? = null,
highlightEquippedItem: Boolean = true // for some UIs that only cares about getting equipped slot number but not highlighting
) : UIItemInventoryCellBase(parentUI, initialX, initialY, item, amount, itemImage, quickslot, equippedSlot, keyDownFun, touchDownFun, extraInfo, highlightEquippedItem) {
companion object {
val height = 48
@@ -73,7 +74,7 @@ class UIItemInventoryElemWide(
Toolkit.fillArea(batch, posX, posY, width, height)
}
// cell border
batch.color = if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
batch.color = if ((equippedSlot != null && highlightEquippedItem) || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
else if (mouseUp && item != null) Toolkit.Theme.COL_ACTIVE
else Toolkit.Theme.COL_INVENTORY_CELL_BORDER
Toolkit.drawBoxBorder(batch, posX, posY, width, height)
@@ -91,7 +92,7 @@ class UIItemInventoryElemWide(
// if mouse is over, text lights up
// highlight item name and count (blocks/walls) if the item is equipped
batch.color = item!!.nameColour mul (
if (equippedSlot != null || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
if ((equippedSlot != null && highlightEquippedItem) || forceHighlighted) Toolkit.Theme.COL_HIGHLIGHT
else if (mouseUp && item != null) Toolkit.Theme.COL_ACTIVE
else Color.WHITE
)

View File

@@ -116,6 +116,7 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
6, UIInventoryFull.CELLS_VRT,
drawScrollOnRightside = true,
drawWallet = false,
highlightEquippedItem = false,
keyDownFun = { _, _, _, _, _ -> },
touchDownFun = { gameItem, amount, _, _, button -> recipeClicked?.let { recipe -> gameItem?.let { gameItem ->
val itemID = gameItem.dynamicID
@@ -239,7 +240,9 @@ class UICrafting(val full: UIInventoryFull) : UICanvas(), HasInventory {
private fun changeIngredient(old: InventoryPair, new: ItemID) {
itemListPlayer.removeFromForceHighlightList(oldSelectedItems)
oldSelectedItems.remove(old.itm)
oldSelectedItems.add(new)
itemListPlayer.addToForceHighlightList(oldSelectedItems)
itemListPlayer.rebuild(catAll)

View File

@@ -28,7 +28,8 @@ abstract class UIItemInventoryCellBase(
open var equippedSlot: Int? = null,
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?
open var extraInfo: Any?,
open protected val highlightEquippedItem: Boolean = true // for some UIs that only cares about getting equipped slot number but not highlighting
) : UIItem(parentUI, initialX, initialY) {
abstract override fun update(delta: Float)
abstract override fun render(batch: SpriteBatch, camera: Camera)

View File

@@ -45,7 +45,8 @@ open class UIItemInventoryItemGrid(
val hideSidebar: Boolean = false,
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
protected val useHighlightingManager: Boolean = true // only used by UIItemCraftingCandidateGrid which addresses buttons directly to set highlighting
protected val useHighlightingManager: Boolean = true, // only used by UIItemCraftingCandidateGrid which addresses buttons directly to set highlighting
open protected val highlightEquippedItem: Boolean = true // for some UIs that only cares about getting equipped slot number but not highlighting
) : UIItem(parentUI, initialX, initialY) {
// deal with the moving position
@@ -184,7 +185,8 @@ open class UIItemInventoryItemGrid(
itemImage = null,
drawBackOnNull = true,
keyDownFun = keyDownFun,
touchDownFun = touchDownFun
touchDownFun = touchDownFun,
highlightEquippedItem = highlightEquippedItem
)
}
// automatically determine how much columns are needed. Minimum Width = 5 grids
@@ -202,7 +204,8 @@ open class UIItemInventoryItemGrid(
itemImage = null,
drawBackOnNull = true,
keyDownFun = keyDownFun,
touchDownFun = touchDownFun
touchDownFun = touchDownFun,
highlightEquippedItem = highlightEquippedItem
)
}