mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
catbar: larger hitbox
This commit is contained in:
@@ -58,7 +58,7 @@ class UIItemCatBar(
|
|||||||
val iconIndexX = iconIndex % 1000
|
val iconIndexX = iconIndex % 1000
|
||||||
val iconIndexY = iconIndex / 1000
|
val iconIndexY = iconIndex / 1000
|
||||||
|
|
||||||
UIItemImageButton(
|
object : UIItemImageButton(
|
||||||
inventoryUI,
|
inventoryUI,
|
||||||
catIcons.get(iconIndexX, iconIndexY),
|
catIcons.get(iconIndexX, iconIndexY),
|
||||||
activeBackCol = Color(0),
|
activeBackCol = Color(0),
|
||||||
@@ -68,7 +68,10 @@ class UIItemCatBar(
|
|||||||
initialX = posX + iconPosX,
|
initialX = posX + iconPosX,
|
||||||
initialY = posY + iconPosY,
|
initialY = posY + iconPosY,
|
||||||
highlightable = true
|
highlightable = true
|
||||||
)
|
) {
|
||||||
|
override val mouseUp: Boolean // true if mouse is on its occupying section on the bar, not just on the icon's bounding box
|
||||||
|
get() = getButtonIndexUnderMouseOnTray() == index && itemRelativeMouseY in 0 until height
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -171,6 +174,15 @@ class UIItemCatBar(
|
|||||||
* Indices are raw index. That is, not re-arranged. */
|
* Indices are raw index. That is, not re-arranged. */
|
||||||
var selectionChangeListener: ((Int?, Int) -> Unit)? = null
|
var selectionChangeListener: ((Int?, Int) -> Unit)? = null
|
||||||
|
|
||||||
|
// returns the index of the button under mouse by checkig if cursur is on the "virtual rectangle" on the tray,
|
||||||
|
// rather than if the cursor is directly above the button
|
||||||
|
private fun getButtonIndexUnderMouseOnTray(): Int? {
|
||||||
|
return if (itemRelativeMouseX in 0 until width) {
|
||||||
|
(itemRelativeMouseX / (width.toFloat() / mainButtons.size)).toInt()
|
||||||
|
}
|
||||||
|
else null
|
||||||
|
}
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
super.update(delta)
|
super.update(delta)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user