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