mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-16 00:26:07 +09:00
ui itemlist scrolls with wheel
This commit is contained in:
@@ -62,6 +62,10 @@ class UIItemInventoryDynamicList(
|
|||||||
private val compactViewCat = setOf(3, 4, 6, 7, 9) // ingredients, potions, blocks, walls, all (spritesheet order)
|
private val compactViewCat = setOf(3, 4, 6, 7, 9) // ingredients, potions, blocks, walls, all (spritesheet order)
|
||||||
|
|
||||||
var itemPage = 0
|
var itemPage = 0
|
||||||
|
set(value) {
|
||||||
|
field = if (itemPageCount == 0) 0 else (value).fmod(itemPageCount)
|
||||||
|
rebuild()
|
||||||
|
}
|
||||||
var itemPageCount = 1 // TODO total size of current category / items.size
|
var itemPageCount = 1 // TODO total size of current category / items.size
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@@ -152,6 +156,9 @@ class UIItemInventoryDynamicList(
|
|||||||
highlightable = false
|
highlightable = false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun scrollItemPage(relativeAmount: Int) {
|
||||||
|
itemPage = if (itemPageCount == 0) 0 else (itemPage + relativeAmount).fmod(itemPageCount)
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// initially highlight grid mode buttons
|
// initially highlight grid mode buttons
|
||||||
@@ -174,14 +181,12 @@ class UIItemInventoryDynamicList(
|
|||||||
}
|
}
|
||||||
|
|
||||||
scrollUpButton.clickOnceListener = { _, _, _ ->
|
scrollUpButton.clickOnceListener = { _, _, _ ->
|
||||||
itemPage = if (itemPageCount == 0) 0 else (itemPage - 1).fmod(itemPageCount)
|
|
||||||
scrollUpButton.highlighted = false
|
scrollUpButton.highlighted = false
|
||||||
rebuild()
|
scrollItemPage(-1)
|
||||||
}
|
}
|
||||||
scrollDownButton.clickOnceListener = { _, _, _ ->
|
scrollDownButton.clickOnceListener = { _, _, _ ->
|
||||||
itemPage = if (itemPageCount == 0) 0 else (itemPage + 1).fmod(itemPageCount)
|
|
||||||
scrollDownButton.highlighted = false
|
scrollDownButton.highlighted = false
|
||||||
rebuild()
|
scrollItemPage(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (is.mouseUp) handled by this.touchDown()
|
// if (is.mouseUp) handled by this.touchDown()
|
||||||
@@ -336,6 +341,8 @@ class UIItemInventoryDynamicList(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||||
|
super.touchUp(screenX, screenY, pointer, button)
|
||||||
|
|
||||||
items.forEach { if (it.mouseUp) it.touchUp(screenX, screenY, pointer, button) }
|
items.forEach { if (it.mouseUp) it.touchUp(screenX, screenY, pointer, button) }
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@@ -358,4 +365,15 @@ class UIItemInventoryDynamicList(
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun scrolled(amount: Int): Boolean {
|
||||||
|
super.scrolled(amount)
|
||||||
|
|
||||||
|
// scroll the item list (for now)
|
||||||
|
if (mouseUp) {
|
||||||
|
scrollItemPage(amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,8 +44,10 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
|||||||
abstract val width: Int
|
abstract val width: Int
|
||||||
abstract val height: Int
|
abstract val height: Int
|
||||||
|
|
||||||
|
/** Position of mouse relative to this item */
|
||||||
protected val relativeMouseX: Int
|
protected val relativeMouseX: Int
|
||||||
get() = (Terrarum.mouseScreenX - (parentUI.posX) - this.posX)
|
get() = (Terrarum.mouseScreenX - (parentUI.posX) - this.posX)
|
||||||
|
/** Position of mouse relative to this item */
|
||||||
protected val relativeMouseY: Int
|
protected val relativeMouseY: Int
|
||||||
get() = (Terrarum.mouseScreenY - (parentUI.posY) - this.posY)
|
get() = (Terrarum.mouseScreenY - (parentUI.posY) - this.posY)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user