Inventory GUI compound scroll functionality
This commit is contained in:
@@ -32,28 +32,35 @@ class InventoryGUISpaceCompound<T : ForInventory, E>(
|
||||
|
||||
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)
|
||||
|
||||
var more = 1
|
||||
while (content.size > result.size) {
|
||||
result += realInternalSlots.mapTo(ArrayList()) { it + (more * invType.dimensions.slotAmount) }
|
||||
more++
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
}
|
||||
|
||||
internal var scrolledLines: Int = 0
|
||||
set(value) {
|
||||
if (((value - 1) * invType.dimensions.width) < content.size) {
|
||||
field = value
|
||||
onChange()
|
||||
var more = 1
|
||||
while (content.size > result.size) {
|
||||
result += realInternalSlots.mapTo(ArrayList()) { it + (more * invType.dimensions.slotAmount) }
|
||||
more++
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
}
|
||||
|
||||
internal var scrolledLines: Int = 0; private set
|
||||
|
||||
fun scroll(distance: Int): Boolean {
|
||||
val value = scrolledLines + distance
|
||||
return if (
|
||||
value >= 0 &&
|
||||
((value - 1) * invType.dimensions.width) < content.size
|
||||
) {
|
||||
scrolledLines = value
|
||||
onChange()
|
||||
true
|
||||
} else false
|
||||
}
|
||||
|
||||
private var contentSort: () -> Unit = { }
|
||||
|
||||
private val registeredGUIs = HashSet<InventoryGUI<*>>()
|
||||
|
@@ -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