ui itemlist scrolls with wheel

This commit is contained in:
minjaesong
2019-01-16 01:37:44 +09:00
parent b10e8aa777
commit 6e33dbdfaf
2 changed files with 24 additions and 4 deletions

View File

@@ -62,6 +62,10 @@ class UIItemInventoryDynamicList(
private val compactViewCat = setOf(3, 4, 6, 7, 9) // ingredients, potions, blocks, walls, all (spritesheet order)
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
private set
@@ -152,6 +156,9 @@ class UIItemInventoryDynamicList(
highlightable = false
)
fun scrollItemPage(relativeAmount: Int) {
itemPage = if (itemPageCount == 0) 0 else (itemPage + relativeAmount).fmod(itemPageCount)
}
init {
// initially highlight grid mode buttons
@@ -174,14 +181,12 @@ class UIItemInventoryDynamicList(
}
scrollUpButton.clickOnceListener = { _, _, _ ->
itemPage = if (itemPageCount == 0) 0 else (itemPage - 1).fmod(itemPageCount)
scrollUpButton.highlighted = false
rebuild()
scrollItemPage(-1)
}
scrollDownButton.clickOnceListener = { _, _, _ ->
itemPage = if (itemPageCount == 0) 0 else (itemPage + 1).fmod(itemPageCount)
scrollDownButton.highlighted = false
rebuild()
scrollItemPage(1)
}
// 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 {
super.touchUp(screenX, screenY, pointer, button)
items.forEach { if (it.mouseUp) it.touchUp(screenX, screenY, pointer, button) }
return true
@@ -358,4 +365,15 @@ class UIItemInventoryDynamicList(
return true
}
override fun scrolled(amount: Int): Boolean {
super.scrolled(amount)
// scroll the item list (for now)
if (mouseUp) {
scrollItemPage(amount)
}
return true
}
}

View File

@@ -44,8 +44,10 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
abstract val width: Int
abstract val height: Int
/** Position of mouse relative to this item */
protected val relativeMouseX: Int
get() = (Terrarum.mouseScreenX - (parentUI.posX) - this.posX)
/** Position of mouse relative to this item */
protected val relativeMouseY: Int
get() = (Terrarum.mouseScreenY - (parentUI.posY) - this.posY)