Apply requested changes
This commit is contained in:
@@ -113,15 +113,29 @@ class GUIPageBuilder<T : ForInventory>(
|
||||
* This is a button which loads the specified
|
||||
* [toPage] if clicked.
|
||||
*/
|
||||
@Deprecated("Use the new function instead.", ReplaceWith("pageChanger(slots, icon, toPage, null, onChange)"))
|
||||
fun pageChanger(
|
||||
slots: InventorySlotCompound<T>,
|
||||
icon: ItemStack,
|
||||
toPage: Int,
|
||||
onChange: ((GUIClickEvent<T>) -> Unit)? = null
|
||||
) = pageChanger(slots, icon, toPage, null, onChange)
|
||||
|
||||
/**
|
||||
* This is a button which loads the specified
|
||||
* [toPage] if clicked.
|
||||
*/
|
||||
fun pageChanger(
|
||||
slots: InventorySlotCompound<T>,
|
||||
icon: ItemStack,
|
||||
toPage: Int,
|
||||
shouldChange: ((GUIClickEvent<T>) -> Boolean)? = null,
|
||||
onChange: ((GUIClickEvent<T>) -> Unit)? = null
|
||||
) = defineSlots(
|
||||
slots, GUIButtonPageChange(
|
||||
icon,
|
||||
GUIPageChangeCalculator.GUIConsistentPageCalculator(toPage),
|
||||
shouldChange,
|
||||
onChange
|
||||
)
|
||||
)
|
||||
@@ -131,14 +145,28 @@ class GUIPageBuilder<T : ForInventory>(
|
||||
* page if clicked, and if a previous page
|
||||
* exists it is loaded.
|
||||
*/
|
||||
@Deprecated("Use the new function instead.", ReplaceWith("previousPage(slots, icon, null, onChange)"))
|
||||
fun previousPage(
|
||||
slots: InventorySlotCompound<T>,
|
||||
icon: ItemStack,
|
||||
onChange: ((GUIClickEvent<T>) -> Unit)? = null
|
||||
) = previousPage(slots, icon, null, onChange)
|
||||
|
||||
/**
|
||||
* This button always tries to find the previous
|
||||
* page if clicked, and if a previous page
|
||||
* exists it is loaded.
|
||||
*/
|
||||
fun previousPage(
|
||||
slots: InventorySlotCompound<T>,
|
||||
icon: ItemStack,
|
||||
shouldChange: ((GUIClickEvent<T>) -> Boolean)? = null,
|
||||
onChange: ((GUIClickEvent<T>) -> Unit)? = null
|
||||
) = defineSlots(
|
||||
slots, GUIButtonPageChange(
|
||||
icon,
|
||||
GUIPageChangeCalculator.GUIPreviousPageCalculator,
|
||||
shouldChange,
|
||||
onChange
|
||||
)
|
||||
)
|
||||
@@ -148,14 +176,28 @@ class GUIPageBuilder<T : ForInventory>(
|
||||
* page if clicked, and if a next page
|
||||
* exists it is loaded.
|
||||
*/
|
||||
@Deprecated("Use the new function instead.", ReplaceWith("nextPage(slots, icon, null, onChange)"))
|
||||
fun nextPage(
|
||||
slots: InventorySlotCompound<T>,
|
||||
icon: ItemStack,
|
||||
onChange: ((GUIClickEvent<T>) -> Unit)? = null
|
||||
) = nextPage(slots, icon, null, onChange)
|
||||
|
||||
/**
|
||||
* This button always tries to find the next
|
||||
* page if clicked, and if a next page
|
||||
* exists it is loaded.
|
||||
*/
|
||||
fun nextPage(
|
||||
slots: InventorySlotCompound<T>,
|
||||
icon: ItemStack,
|
||||
shouldChange: ((GUIClickEvent<T>) -> Boolean)? = null,
|
||||
onChange: ((GUIClickEvent<T>) -> Unit)? = null
|
||||
) = defineSlots(
|
||||
slots, GUIButtonPageChange(
|
||||
icon,
|
||||
GUIPageChangeCalculator.GUINextPageCalculator,
|
||||
shouldChange,
|
||||
onChange
|
||||
)
|
||||
)
|
||||
@@ -289,4 +331,4 @@ class GUIPageBuilder<T : ForInventory>(
|
||||
GUISpaceCompoundScrollButton(icon, compound, scrollTimes, reverse)
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -6,8 +6,8 @@ import org.bukkit.inventory.ItemStack
|
||||
class GUIButtonPageChange<T : ForInventory>(
|
||||
icon: ItemStack,
|
||||
calculator: GUIPageChangeCalculator,
|
||||
beforeChange: ((GUIClickEvent<T>) -> Boolean)?,
|
||||
afterChange: ((GUIClickEvent<T>) -> Unit)?
|
||||
shouldChange: ((GUIClickEvent<T>) -> Boolean)?,
|
||||
onChange: ((GUIClickEvent<T>) -> Unit)?
|
||||
) : GUIButton<T>(icon, {
|
||||
|
||||
val currentPage = it.guiInstance.currentPage
|
||||
@@ -19,14 +19,14 @@ class GUIButtonPageChange<T : ForInventory>(
|
||||
)
|
||||
if (newPage != null) {
|
||||
|
||||
val changePage = beforeChange?.invoke(it) ?: true
|
||||
val changePage = shouldChange?.invoke(it) ?: true
|
||||
|
||||
if (changePage) {
|
||||
val effect = (newPage.transitionTo ?: currentPage.transitionFrom)
|
||||
?: PageChangeEffect.INSTANT
|
||||
|
||||
it.guiInstance.changePage(effect, currentPage, newPage)
|
||||
afterChange?.invoke(it)
|
||||
onChange?.invoke(it)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user