Inventory GUI compound scroll functionality
This commit is contained in:
@@ -32,7 +32,8 @@ class InventoryGUISpaceCompound<T : ForInventory, E>(
|
|||||||
|
|
||||||
private val realInternalSlots = ArrayList<Int>()
|
private val realInternalSlots = ArrayList<Int>()
|
||||||
|
|
||||||
private val currentInternalSlots: List<Int> get() {
|
private val currentInternalSlots: List<Int>
|
||||||
|
get() {
|
||||||
|
|
||||||
val result = ArrayList(realInternalSlots)
|
val result = ArrayList(realInternalSlots)
|
||||||
|
|
||||||
@@ -46,12 +47,18 @@ class InventoryGUISpaceCompound<T : ForInventory, E>(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var scrolledLines: Int = 0
|
internal var scrolledLines: Int = 0; private set
|
||||||
set(value) {
|
|
||||||
if (((value - 1) * invType.dimensions.width) < content.size) {
|
fun scroll(distance: Int): Boolean {
|
||||||
field = value
|
val value = scrolledLines + distance
|
||||||
|
return if (
|
||||||
|
value >= 0 &&
|
||||||
|
((value - 1) * invType.dimensions.width) < content.size
|
||||||
|
) {
|
||||||
|
scrolledLines = value
|
||||||
onChange()
|
onChange()
|
||||||
}
|
true
|
||||||
|
} else false
|
||||||
}
|
}
|
||||||
|
|
||||||
private var contentSort: () -> Unit = { }
|
private var contentSort: () -> Unit = { }
|
||||||
|
@@ -0,0 +1,28 @@
|
|||||||
|
package net.axay.kspigot.inventory.elements
|
||||||
|
|
||||||
|
import net.axay.kspigot.inventory.ForInventory
|
||||||
|
import net.axay.kspigot.inventory.InventoryGUIClickEvent
|
||||||
|
import net.axay.kspigot.inventory.InventoryGUIElement
|
||||||
|
import net.axay.kspigot.runnables.task
|
||||||
|
import org.bukkit.inventory.ItemStack
|
||||||
|
|
||||||
|
class InventoryGUISpaceCompoundScrollButton<T : ForInventory>(
|
||||||
|
private val icon: ItemStack,
|
||||||
|
private val compound: InventoryGUISpaceCompound<T, *>,
|
||||||
|
private val scrollDistance: Int = compound.invType.dimensions.height,
|
||||||
|
private val reverse: Boolean = false
|
||||||
|
) : InventoryGUIElement<T>() {
|
||||||
|
|
||||||
|
override fun getItemStack(slot: Int) = icon
|
||||||
|
|
||||||
|
override fun onClickElement(clickEvent: InventoryGUIClickEvent<T>) {
|
||||||
|
task(
|
||||||
|
period = 1,
|
||||||
|
howOften = scrollDistance.toLong()
|
||||||
|
) {
|
||||||
|
val ifScrolled = if (reverse) compound.scroll(-1) else compound.scroll(1)
|
||||||
|
if (!ifScrolled) it.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user