Applied kotlin style conventions
This commit is contained in:
@@ -64,8 +64,8 @@ object InventoryGUIHolder : AutoCloseable {
|
||||
// EVENT
|
||||
|
||||
class InventoryGUIClickEvent<T : ForInventory>(
|
||||
val bukkitEvent: InventoryClickEvent,
|
||||
val gui: InventoryGUI<T>
|
||||
val bukkitEvent: InventoryClickEvent,
|
||||
val gui: InventoryGUI<T>
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -84,16 +84,22 @@ class InventoryGUIData<T : ForInventory>(
|
||||
)
|
||||
|
||||
abstract class InventoryGUI<T : ForInventory>(
|
||||
val data: InventoryGUIData<T>
|
||||
val data: InventoryGUIData<T>
|
||||
) {
|
||||
|
||||
var currentPageInt: Int = DEFAULT_PAGE; protected set
|
||||
val currentPage get() = getPage(currentPageInt)
|
||||
val currentPage
|
||||
get() = getPage(currentPageInt)
|
||||
?: throw IllegalStateException("The currentPageInt has no associated page!")
|
||||
|
||||
internal abstract val bukkitInventory: Inventory
|
||||
|
||||
internal abstract fun loadPageUnsafe(page: InventoryGUIPage<*>, offsetHorizontally: Int = 0, offsetVertically: Int = 0)
|
||||
internal abstract fun loadPageUnsafe(
|
||||
page: InventoryGUIPage<*>,
|
||||
offsetHorizontally: Int = 0,
|
||||
offsetVertically: Int = 0
|
||||
)
|
||||
|
||||
internal abstract fun loadPageUnsafe(page: Int, offsetHorizontally: Int = 0, offsetVertically: Int = 0)
|
||||
|
||||
/**
|
||||
@@ -135,12 +141,14 @@ abstract class InventoryGUI<T : ForInventory>(
|
||||
// Inventory GUI implementations
|
||||
|
||||
class InventoryGUIShared<T : ForInventory>(
|
||||
inventoryGUIData: InventoryGUIData<T>
|
||||
inventoryGUIData: InventoryGUIData<T>
|
||||
) : InventoryGUI<T>(inventoryGUIData) {
|
||||
|
||||
override val bukkitInventory = data.inventoryType.createBukkitInv(null, data.title)
|
||||
|
||||
init { loadPageUnsafe(DEFAULT_PAGE) }
|
||||
init {
|
||||
loadPageUnsafe(DEFAULT_PAGE)
|
||||
}
|
||||
|
||||
override fun isThisInv(inventory: Inventory) = inventory == bukkitInventory
|
||||
|
||||
|
@@ -6,12 +6,12 @@ import net.axay.kspigot.inventory.elements.*
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
fun <T : ForInventory> inventoryGUI(
|
||||
type: InventoryType<T>,
|
||||
builder: InventoryGUIBuilder<T>.() -> Unit,
|
||||
type: InventoryType<T>,
|
||||
builder: InventoryGUIBuilder<T>.() -> Unit,
|
||||
) = InventoryGUIBuilder(type).apply(builder).build()
|
||||
|
||||
class InventoryGUIBuilder<T : ForInventory>(
|
||||
val type: InventoryType<T>
|
||||
val type: InventoryType<T>
|
||||
) {
|
||||
|
||||
var title: String = ""
|
||||
@@ -37,14 +37,14 @@ class InventoryGUIBuilder<T : ForInventory>(
|
||||
}
|
||||
|
||||
internal fun build() = InventoryGUIShared(
|
||||
InventoryGUIData(type, title, guiSlots, transitionTo, transitionFrom, onClickElement)
|
||||
InventoryGUIData(type, title, guiSlots, transitionTo, transitionFrom, onClickElement)
|
||||
).apply { register() }
|
||||
|
||||
}
|
||||
|
||||
class InventoryGUIPageBuilder<T : ForInventory>(
|
||||
val type: InventoryType<T>,
|
||||
val page: Int
|
||||
val type: InventoryType<T>,
|
||||
val page: Int
|
||||
) {
|
||||
|
||||
private val guiSlots = HashMap<Int, InventoryGUISlot<T>>()
|
||||
@@ -59,74 +59,96 @@ class InventoryGUIPageBuilder<T : ForInventory>(
|
||||
* actions. If clicked, the specified [onClick]
|
||||
* function is invoked.
|
||||
*/
|
||||
fun button(slots: InventorySlotCompound<T>, itemStack: ItemStack, onClick: (InventoryGUIClickEvent<T>) -> Unit)
|
||||
= defineSlots(slots, InventoryGUIButton(InventoryGUIElementData(itemStack), onClick))
|
||||
fun button(slots: InventorySlotCompound<T>, itemStack: ItemStack, onClick: (InventoryGUIClickEvent<T>) -> Unit) =
|
||||
defineSlots(slots, InventoryGUIButton(InventoryGUIElementData(itemStack), onClick))
|
||||
|
||||
/**
|
||||
* An item protected from any player actions.
|
||||
* This is not a button.
|
||||
*/
|
||||
fun placeholder(slots: InventorySlotCompound<T>, itemStack: ItemStack)
|
||||
= defineSlots(slots, InventoryGUIPlaceholder(InventoryGUIElementData(itemStack)))
|
||||
fun placeholder(slots: InventorySlotCompound<T>, itemStack: ItemStack) =
|
||||
defineSlots(slots, InventoryGUIPlaceholder(InventoryGUIElementData(itemStack)))
|
||||
|
||||
/**
|
||||
* A free slot does not block any player actions.
|
||||
* The player can put items in this slot or take
|
||||
* items out of it.
|
||||
*/
|
||||
fun freeSlot(slots: InventorySlotCompound<T>)
|
||||
= defineSlots(slots, InventoryGUIFreeSlot())
|
||||
fun freeSlot(slots: InventorySlotCompound<T>) = defineSlots(slots, InventoryGUIFreeSlot())
|
||||
|
||||
/**
|
||||
* This is a button which loads the specified
|
||||
* [toPage] if clicked.
|
||||
*/
|
||||
fun pageChanger(slots: InventorySlotCompound<T>, itemStack: ItemStack, toPage: Int, onChange: ((InventoryGUIClickEvent<T>) -> Unit)? = null)
|
||||
= defineSlots(slots, InventoryGUIButtonPageChange(
|
||||
fun pageChanger(
|
||||
slots: InventorySlotCompound<T>,
|
||||
itemStack: ItemStack,
|
||||
toPage: Int,
|
||||
onChange: ((InventoryGUIClickEvent<T>) -> Unit)? = null
|
||||
) = defineSlots(
|
||||
slots, InventoryGUIButtonPageChange(
|
||||
InventoryGUIElementData(itemStack),
|
||||
InventoryGUIPageChangeCalculator.InventoryGUIConsistentPageCalculator(toPage),
|
||||
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>, itemStack: ItemStack, onChange: ((InventoryGUIClickEvent<T>) -> Unit)? = null)
|
||||
= defineSlots(slots, InventoryGUIButtonPageChange(
|
||||
fun previousPage(
|
||||
slots: InventorySlotCompound<T>,
|
||||
itemStack: ItemStack,
|
||||
onChange: ((InventoryGUIClickEvent<T>) -> Unit)? = null
|
||||
) = defineSlots(
|
||||
slots, InventoryGUIButtonPageChange(
|
||||
InventoryGUIElementData(itemStack),
|
||||
InventoryGUIPageChangeCalculator.InventoryGUIPreviousPageCalculator,
|
||||
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>, itemStack: ItemStack, onChange: ((InventoryGUIClickEvent<T>) -> Unit)? = null)
|
||||
= defineSlots(slots, InventoryGUIButtonPageChange(
|
||||
fun nextPage(
|
||||
slots: InventorySlotCompound<T>,
|
||||
itemStack: ItemStack,
|
||||
onChange: ((InventoryGUIClickEvent<T>) -> Unit)? = null
|
||||
) = defineSlots(
|
||||
slots, InventoryGUIButtonPageChange(
|
||||
InventoryGUIElementData(itemStack),
|
||||
InventoryGUIPageChangeCalculator.InventoryGUINextPageCalculator,
|
||||
onChange
|
||||
))
|
||||
)
|
||||
)
|
||||
|
||||
/**
|
||||
* By pressing this button, the player switches to another
|
||||
* InventoryGUI. The transition effect is applied.
|
||||
*/
|
||||
fun changeGUI(slots: InventorySlotCompound<T>, itemStack: ItemStack, newGUI: () -> InventoryGUI<*>, newPage: Int? = null, onChange: ((InventoryGUIClickEvent<T>) -> Unit)? = null)
|
||||
= defineSlots(slots, InventoryGUIButtonInventoryChange(
|
||||
fun changeGUI(
|
||||
slots: InventorySlotCompound<T>,
|
||||
itemStack: ItemStack,
|
||||
newGUI: () -> InventoryGUI<*>,
|
||||
newPage: Int? = null,
|
||||
onChange: ((InventoryGUIClickEvent<T>) -> Unit)? = null
|
||||
) = defineSlots(
|
||||
slots, InventoryGUIButtonInventoryChange(
|
||||
InventoryGUIElementData(itemStack),
|
||||
newGUI,
|
||||
newPage,
|
||||
onChange
|
||||
))
|
||||
)
|
||||
)
|
||||
|
||||
private fun defineSlots(slots: InventorySlotCompound<T>, element: InventoryGUISlot<T>)
|
||||
= slots.withInvType(type).forEach { curSlot ->
|
||||
curSlot.realSlotIn(type.dimensions)?.let { guiSlots[it] = element }
|
||||
private fun defineSlots(slots: InventorySlotCompound<T>, element: InventoryGUISlot<T>) =
|
||||
slots.withInvType(type).forEach { curSlot ->
|
||||
curSlot.realSlotIn(type.dimensions)?.let { guiSlots[it] = element }
|
||||
}
|
||||
|
||||
}
|
@@ -9,11 +9,11 @@ abstract class InventoryGUISlot<T : ForInventory> {
|
||||
// ELEMENT
|
||||
|
||||
class InventoryGUIElementData(
|
||||
val itemStack: ItemStack
|
||||
val itemStack: ItemStack
|
||||
)
|
||||
|
||||
abstract class InventoryGUIElement<T : ForInventory>(
|
||||
val inventoryGUIElementData: InventoryGUIElementData
|
||||
val inventoryGUIElementData: InventoryGUIElementData
|
||||
) : InventoryGUISlot<T>() {
|
||||
|
||||
final override fun onClick(clickEvent: InventoryGUIClickEvent<T>) {
|
||||
|
@@ -7,13 +7,13 @@ abstract class InventoryGUIPageChangeCalculator {
|
||||
abstract fun calculateNewPage(currentPage: Int, pages: Collection<Int>): Int?
|
||||
|
||||
object InventoryGUIPreviousPageCalculator : InventoryGUIPageChangeCalculator() {
|
||||
override fun calculateNewPage(currentPage: Int, pages: Collection<Int>)
|
||||
= pages.sortedDescending().find { it < currentPage }
|
||||
override fun calculateNewPage(currentPage: Int, pages: Collection<Int>) =
|
||||
pages.sortedDescending().find { it < currentPage }
|
||||
}
|
||||
|
||||
object InventoryGUINextPageCalculator : InventoryGUIPageChangeCalculator() {
|
||||
override fun calculateNewPage(currentPage: Int, pages: Collection<Int>)
|
||||
= pages.sorted().find { it > currentPage }
|
||||
override fun calculateNewPage(currentPage: Int, pages: Collection<Int>) =
|
||||
pages.sorted().find { it > currentPage }
|
||||
}
|
||||
|
||||
class InventoryGUIConsistentPageCalculator(private val toPage: Int) : InventoryGUIPageChangeCalculator() {
|
||||
@@ -119,19 +119,19 @@ internal fun InventoryGUI<*>.changeGUI(
|
||||
) = changePage(effect.effect, fromPage, toPage)
|
||||
|
||||
private inline fun changePageEffect(
|
||||
fromPage: Int,
|
||||
toPage: Int,
|
||||
doFor: Int,
|
||||
crossinline effect: (currentOffset: Int, ifInverted: Boolean) -> Unit,
|
||||
fromPage: Int,
|
||||
toPage: Int,
|
||||
doFor: Int,
|
||||
crossinline effect: (currentOffset: Int, ifInverted: Boolean) -> Unit,
|
||||
) {
|
||||
|
||||
val ifInverted = fromPage >= toPage
|
||||
|
||||
var currentOffset = 1
|
||||
task(
|
||||
sync = true,
|
||||
period = 1,
|
||||
howOften = doFor.toLong()
|
||||
sync = true,
|
||||
period = 1,
|
||||
howOften = doFor.toLong()
|
||||
) {
|
||||
|
||||
effect.invoke(currentOffset, ifInverted)
|
||||
|
@@ -10,10 +10,11 @@ data class InventoryDimensions(val width: Int, val heigth: Int) {
|
||||
|
||||
val invSlots by lazy {
|
||||
ArrayList<InventorySlot>().apply {
|
||||
(1 .. heigth).forEach { row ->
|
||||
(1 .. width).forEach { slotInRow ->
|
||||
(1..heigth).forEach { row ->
|
||||
(1..width).forEach { slotInRow ->
|
||||
this += InventorySlot(row, slotInRow)
|
||||
} }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +41,8 @@ data class InventoryDimensions(val width: Int, val heigth: Int) {
|
||||
data class InventorySlot(val row: Int, val slotInRow: Int) : Comparable<InventorySlot> {
|
||||
|
||||
companion object {
|
||||
fun fromRealSlot(realSlot: Int, dimensions: InventoryDimensions)
|
||||
= dimensions.invSlotsWithRealSlots.toList().find { it.second == realSlot }?.first
|
||||
fun fromRealSlot(realSlot: Int, dimensions: InventoryDimensions) =
|
||||
dimensions.invSlotsWithRealSlots.toList().find { it.second == realSlot }?.first
|
||||
}
|
||||
|
||||
override fun compareTo(other: InventorySlot) = when {
|
||||
@@ -61,12 +62,12 @@ data class InventorySlot(val row: Int, val slotInRow: Int) : Comparable<Inventor
|
||||
return ((rowsUnder * inventoryDimensions.width) + slotInRow) - 1
|
||||
}
|
||||
|
||||
fun isInDimension(inventoryDimensions: InventoryDimensions)
|
||||
= (1 .. inventoryDimensions.width).contains(slotInRow) && (1 .. inventoryDimensions.heigth).contains(row)
|
||||
fun isInDimension(inventoryDimensions: InventoryDimensions) =
|
||||
(1..inventoryDimensions.width).contains(slotInRow) && (1..inventoryDimensions.heigth).contains(row)
|
||||
|
||||
fun add(offsetHorizontally: Int, offsetVertically: Int) = InventorySlot(
|
||||
row + offsetVertically,
|
||||
slotInRow + offsetHorizontally
|
||||
row + offsetVertically,
|
||||
slotInRow + offsetHorizontally
|
||||
)
|
||||
|
||||
}
|
||||
@@ -75,13 +76,13 @@ interface InventorySlotCompound<out T : ForInventory> {
|
||||
|
||||
fun withInvType(invType: InventoryType<T>): Collection<InventorySlot>
|
||||
|
||||
fun realSlotsWithInvType(invType: InventoryType<T>)
|
||||
= withInvType(invType).mapNotNull { it.realSlotIn(invType.dimensions) }
|
||||
fun realSlotsWithInvType(invType: InventoryType<T>) =
|
||||
withInvType(invType).mapNotNull { it.realSlotIn(invType.dimensions) }
|
||||
|
||||
}
|
||||
|
||||
open class SingleInventorySlot<T : ForInventory> internal constructor(
|
||||
val inventorySlot: InventorySlot
|
||||
val inventorySlot: InventorySlot
|
||||
) : InventorySlotCompound<T> {
|
||||
|
||||
constructor(row: Int, slotInRow: Int) : this(InventorySlot(row, slotInRow))
|
||||
@@ -99,10 +100,10 @@ internal enum class InventorySlotRangeType {
|
||||
|
||||
class InventorySlotRange<out T : ForInventory> internal constructor(
|
||||
|
||||
startSlot: SingleInventorySlot<out T>,
|
||||
endSlot: SingleInventorySlot<out T>,
|
||||
startSlot: SingleInventorySlot<out T>,
|
||||
endSlot: SingleInventorySlot<out T>,
|
||||
|
||||
private val type: InventorySlotRangeType
|
||||
private val type: InventorySlotRangeType
|
||||
|
||||
) : InventorySlotCompound<T>, ClosedRange<InventorySlot> {
|
||||
|
||||
@@ -115,40 +116,39 @@ class InventorySlotRange<out T : ForInventory> internal constructor(
|
||||
endInclusive = minMaxPair.max
|
||||
}
|
||||
|
||||
override fun withInvType(invType: InventoryType<T>)
|
||||
= LinkedHashSet<InventorySlot>().apply {
|
||||
when (type) {
|
||||
|
||||
InventorySlotRangeType.RECTANGLE -> {
|
||||
// all possible combinations between the two slots
|
||||
// -> form a rectangle
|
||||
for (row in start.row .. endInclusive.row)
|
||||
for (slotInRow in start.slotInRow .. endInclusive.slotInRow)
|
||||
this += InventorySlot(row, slotInRow)
|
||||
}
|
||||
|
||||
InventorySlotRangeType.LINEAR -> {
|
||||
if (endInclusive.row > start.row) {
|
||||
// from start --->| to end of row
|
||||
for (slotInRow in start.slotInRow .. invType.dimensions.width)
|
||||
this += InventorySlot(start.row, slotInRow)
|
||||
// all rows in between
|
||||
if (endInclusive.row > start.row + 1)
|
||||
for (row in start.row + 1 until endInclusive.row)
|
||||
for (slotInRow in 1 .. invType.dimensions.width)
|
||||
this += InventorySlot(row, slotInRow)
|
||||
// from start of row |----> to endInclusive
|
||||
for (slotInRow in 1 .. endInclusive.slotInRow)
|
||||
this += InventorySlot(endInclusive.row, slotInRow)
|
||||
} else if (endInclusive.row == start.row) {
|
||||
// from start ---> to endInclusive in the same row
|
||||
for (slotInRow in start.slotInRow .. endInclusive.slotInRow)
|
||||
this += InventorySlot(start.row, slotInRow)
|
||||
}
|
||||
}
|
||||
override fun withInvType(invType: InventoryType<T>) = LinkedHashSet<InventorySlot>().apply {
|
||||
when (type) {
|
||||
|
||||
InventorySlotRangeType.RECTANGLE -> {
|
||||
// all possible combinations between the two slots
|
||||
// -> form a rectangle
|
||||
for (row in start.row..endInclusive.row)
|
||||
for (slotInRow in start.slotInRow..endInclusive.slotInRow)
|
||||
this += InventorySlot(row, slotInRow)
|
||||
}
|
||||
|
||||
InventorySlotRangeType.LINEAR -> {
|
||||
if (endInclusive.row > start.row) {
|
||||
// from start --->| to end of row
|
||||
for (slotInRow in start.slotInRow..invType.dimensions.width)
|
||||
this += InventorySlot(start.row, slotInRow)
|
||||
// all rows in between
|
||||
if (endInclusive.row > start.row + 1)
|
||||
for (row in start.row + 1 until endInclusive.row)
|
||||
for (slotInRow in 1..invType.dimensions.width)
|
||||
this += InventorySlot(row, slotInRow)
|
||||
// from start of row |----> to endInclusive
|
||||
for (slotInRow in 1..endInclusive.slotInRow)
|
||||
this += InventorySlot(endInclusive.row, slotInRow)
|
||||
} else if (endInclusive.row == start.row) {
|
||||
// from start ---> to endInclusive in the same row
|
||||
for (slotInRow in start.slotInRow..endInclusive.slotInRow)
|
||||
this += InventorySlot(start.row, slotInRow)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -156,40 +156,40 @@ class InventorySlotRange<out T : ForInventory> internal constructor(
|
||||
* This range contains all slots having an index between
|
||||
* the indeces of the two given slots.
|
||||
*/
|
||||
infix fun <T : ForInventory> SingleInventorySlot<out T>.linTo(slot: SingleInventorySlot<out T>)
|
||||
= InventorySlotRange(this, slot, InventorySlotRangeType.LINEAR)
|
||||
infix fun <T : ForInventory> SingleInventorySlot<out T>.linTo(slot: SingleInventorySlot<out T>) =
|
||||
InventorySlotRange(this, slot, InventorySlotRangeType.LINEAR)
|
||||
|
||||
/**
|
||||
* This range contains all slots inside of a thought rectangle
|
||||
* with the two given slots as two opposite corners of the rectangle.
|
||||
*/
|
||||
infix fun <T : ForInventory> SingleInventorySlot<out T>.rectTo(slot: SingleInventorySlot<out T>)
|
||||
= InventorySlotRange(this, slot, InventorySlotRangeType.RECTANGLE)
|
||||
infix fun <T : ForInventory> SingleInventorySlot<out T>.rectTo(slot: SingleInventorySlot<out T>) =
|
||||
InventorySlotRange(this, slot, InventorySlotRangeType.RECTANGLE)
|
||||
|
||||
class InventoryRowSlots<T : ForInventory> internal constructor(
|
||||
val row: Int
|
||||
val row: Int
|
||||
) : InventorySlotCompound<T> {
|
||||
|
||||
override fun withInvType(invType: InventoryType<T>) = HashSet<InventorySlot>().apply {
|
||||
for (slotInRow in 1 .. invType.dimensions.width)
|
||||
for (slotInRow in 1..invType.dimensions.width)
|
||||
this += InventorySlot(row, slotInRow)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class InventoryColumnSlots<T : ForInventory> internal constructor(
|
||||
val column: Int
|
||||
val column: Int
|
||||
) : InventorySlotCompound<T> {
|
||||
|
||||
override fun withInvType(invType: InventoryType<T>) = HashSet<InventorySlot>().apply {
|
||||
for (row in 1 .. invType.dimensions.heigth)
|
||||
for (row in 1..invType.dimensions.heigth)
|
||||
this += InventorySlot(row, column)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class InventoryBorderSlots<T : ForInventory> internal constructor(
|
||||
val padding: Int
|
||||
val padding: Int
|
||||
) : InventorySlotCompound<T> {
|
||||
|
||||
override fun withInvType(invType: InventoryType<T>) = HashSet<InventorySlot>().apply {
|
||||
@@ -197,7 +197,7 @@ class InventoryBorderSlots<T : ForInventory> internal constructor(
|
||||
val dimensions = invType.dimensions
|
||||
|
||||
for (currentPadding in 0 until padding) {
|
||||
for (slotInRow in 1 + currentPadding .. dimensions.width - currentPadding) {
|
||||
for (slotInRow in 1 + currentPadding..dimensions.width - currentPadding) {
|
||||
this += InventorySlot(1, slotInRow)
|
||||
this += InventorySlot(dimensions.heigth, slotInRow)
|
||||
}
|
||||
@@ -212,11 +212,11 @@ class InventoryBorderSlots<T : ForInventory> internal constructor(
|
||||
}
|
||||
|
||||
class InventoryCornerSlots<T : ForInventory> internal constructor(
|
||||
val ifBottomLeft: Boolean = false,
|
||||
val ifBottomRight: Boolean = false,
|
||||
val ifTopLeft: Boolean = false,
|
||||
val ifTopRight: Boolean = false
|
||||
) : InventorySlotCompound<T> {
|
||||
val ifBottomLeft: Boolean = false,
|
||||
val ifBottomRight: Boolean = false,
|
||||
val ifTopLeft: Boolean = false,
|
||||
val ifTopRight: Boolean = false
|
||||
) : InventorySlotCompound<T> {
|
||||
|
||||
override fun withInvType(invType: InventoryType<T>) = HashSet<InventorySlot>().apply {
|
||||
|
||||
@@ -247,20 +247,28 @@ interface ForColumnNine : ForInventoryWidthNine
|
||||
|
||||
// ROWS
|
||||
|
||||
interface ForRowOne : ForInventoryOneByNine, ForInventoryTwoByNine, ForInventoryThreeByNine, ForInventoryFourByNine, ForInventoryFiveByNine, ForInventorySixByNine
|
||||
interface ForRowTwo : ForInventoryTwoByNine, ForInventoryThreeByNine, ForInventoryFourByNine, ForInventoryFiveByNine, ForInventorySixByNine
|
||||
interface ForRowOne : ForInventoryOneByNine, ForInventoryTwoByNine, ForInventoryThreeByNine, ForInventoryFourByNine,
|
||||
ForInventoryFiveByNine, ForInventorySixByNine
|
||||
|
||||
interface ForRowTwo : ForInventoryTwoByNine, ForInventoryThreeByNine, ForInventoryFourByNine, ForInventoryFiveByNine,
|
||||
ForInventorySixByNine
|
||||
|
||||
interface ForRowThree : ForInventoryThreeByNine, ForInventoryFourByNine, ForInventoryFiveByNine, ForInventorySixByNine
|
||||
interface ForRowFour : ForInventoryFourByNine, ForInventoryFiveByNine, ForInventorySixByNine
|
||||
interface ForRowFive : ForInventoryFiveByNine, ForInventorySixByNine
|
||||
interface ForRowSix : ForInventorySixByNine
|
||||
|
||||
// EDGE CASES:
|
||||
// ROW ONE
|
||||
interface ForRowOneSlotOneToThree : ForRowOne, ForInventoryOneByFive, ForInventoryThreeByThree
|
||||
interface ForRowOneSlotFourToFive : ForRowOne, ForInventoryOneByFive
|
||||
|
||||
// ROW TWO
|
||||
interface ForRowTwoSlotOneToThree : ForRowTwo, ForInventoryThreeByThree
|
||||
|
||||
// ROW THREE
|
||||
interface ForRowThreeSlotOneToThree : ForRowThree, ForInventoryThreeByThree
|
||||
|
||||
// COMPLETE ROWS (including the edge cases)
|
||||
interface ForCompleteRowOne : ForRowOne, ForRowOneSlotOneToThree, ForRowOneSlotFourToFive
|
||||
interface ForCompleteRowTwo : ForRowTwo, ForRowTwoSlotOneToThree
|
||||
@@ -278,6 +286,7 @@ object Slots {
|
||||
val RowOneSlotSeven = SingleInventorySlot<ForRowOne>(1, 7)
|
||||
val RowOneSlotEight = SingleInventorySlot<ForRowOne>(1, 8)
|
||||
val RowOneSlotNine = SingleInventorySlot<ForRowOne>(1, 9)
|
||||
|
||||
// ROW TWO
|
||||
val RowTwoSlotOne = SingleInventorySlot<ForRowTwoSlotOneToThree>(2, 1)
|
||||
val RowTwoSlotTwo = SingleInventorySlot<ForRowTwoSlotOneToThree>(2, 2)
|
||||
@@ -288,6 +297,7 @@ object Slots {
|
||||
val RowTwoSlotSeven = SingleInventorySlot<ForRowTwo>(2, 7)
|
||||
val RowTwoSlotEight = SingleInventorySlot<ForRowTwo>(2, 8)
|
||||
val RowTwoSlotNine = SingleInventorySlot<ForRowTwo>(2, 9)
|
||||
|
||||
// ROW THREE
|
||||
val RowThreeSlotOne = SingleInventorySlot<ForRowThreeSlotOneToThree>(3, 1)
|
||||
val RowThreeSlotTwo = SingleInventorySlot<ForRowThreeSlotOneToThree>(3, 2)
|
||||
@@ -298,6 +308,7 @@ object Slots {
|
||||
val RowThreeSlotSeven = SingleInventorySlot<ForRowThree>(3, 7)
|
||||
val RowThreeSlotEight = SingleInventorySlot<ForRowThree>(3, 8)
|
||||
val RowThreeSlotNine = SingleInventorySlot<ForRowThree>(3, 9)
|
||||
|
||||
// ROW FOUR
|
||||
val RowFourSlotOne = SingleInventorySlot<ForRowFour>(4, 1)
|
||||
val RowFourSlotTwo = SingleInventorySlot<ForRowFour>(4, 2)
|
||||
@@ -308,6 +319,7 @@ object Slots {
|
||||
val RowFourSlotSeven = SingleInventorySlot<ForRowFour>(4, 7)
|
||||
val RowFourSlotEight = SingleInventorySlot<ForRowFour>(4, 8)
|
||||
val RowFourSlotNine = SingleInventorySlot<ForRowFour>(4, 9)
|
||||
|
||||
// ROW FIVE
|
||||
val RowFiveSlotOne = SingleInventorySlot<ForRowFive>(5, 1)
|
||||
val RowFiveSlotTwo = SingleInventorySlot<ForRowFive>(5, 2)
|
||||
@@ -318,6 +330,7 @@ object Slots {
|
||||
val RowFiveSlotSeven = SingleInventorySlot<ForRowFive>(5, 7)
|
||||
val RowFiveSlotEight = SingleInventorySlot<ForRowFive>(5, 8)
|
||||
val RowFiveSlotNine = SingleInventorySlot<ForRowFive>(5, 9)
|
||||
|
||||
// ROW SIX
|
||||
val RowSixSlotOne = SingleInventorySlot<ForRowSix>(6, 1)
|
||||
val RowSixSlotTwo = SingleInventorySlot<ForRowSix>(6, 2)
|
||||
|
@@ -8,8 +8,8 @@ import org.bukkit.inventory.Inventory
|
||||
import org.bukkit.inventory.InventoryHolder
|
||||
|
||||
class InventoryType<in T : ForInventory>(
|
||||
val dimensions: InventoryDimensions,
|
||||
val bukkitType: InventoryType? = null
|
||||
val dimensions: InventoryDimensions,
|
||||
val bukkitType: InventoryType? = null
|
||||
) {
|
||||
|
||||
private val size = dimensions.width * dimensions.heigth
|
||||
@@ -22,8 +22,10 @@ class InventoryType<in T : ForInventory>(
|
||||
val FOUR_BY_NINE = InventoryType<ForInventoryFourByNine>(InventoryDimensions(9, 4))
|
||||
val FIVE_BY_NINE = InventoryType<ForInventoryFiveByNine>(InventoryDimensions(9, 5))
|
||||
val SIX_BY_NINE = InventoryType<ForInventorySixByNine>(InventoryDimensions(9, 6))
|
||||
val ONE_BY_FIVE = InventoryType<ForInventoryOneByFive>(InventoryDimensions(5, 1), bukkitType = InventoryType.HOPPER)
|
||||
val THREE_BY_THREE = InventoryType<ForInventoryThreeByThree>(InventoryDimensions(3, 3), bukkitType = InventoryType.DROPPER)
|
||||
val ONE_BY_FIVE =
|
||||
InventoryType<ForInventoryOneByFive>(InventoryDimensions(5, 1), bukkitType = InventoryType.HOPPER)
|
||||
val THREE_BY_THREE =
|
||||
InventoryType<ForInventoryThreeByThree>(InventoryDimensions(3, 3), bukkitType = InventoryType.DROPPER)
|
||||
|
||||
}
|
||||
|
||||
@@ -52,9 +54,10 @@ interface ForInventorySixByNine : ForInventory
|
||||
|
||||
interface ForEveryInventory
|
||||
: ForInventoryOneByNine, ForInventoryTwoByNine, ForInventoryThreeByNine,
|
||||
ForInventoryFourByNine, ForInventoryFiveByNine, ForInventorySixByNine,
|
||||
ForInventoryThreeByThree, ForInventoryOneByFive
|
||||
ForInventoryFourByNine, ForInventoryFiveByNine, ForInventorySixByNine,
|
||||
ForInventoryThreeByThree, ForInventoryOneByFive
|
||||
|
||||
interface ForInventoryWidthThree : ForInventoryThreeByThree
|
||||
interface ForInventoryWidthFive : ForInventoryOneByFive
|
||||
interface ForInventoryWidthNine : ForInventoryOneByNine, ForInventoryTwoByNine, ForInventoryThreeByNine, ForInventoryFourByNine, ForInventoryFiveByNine, ForInventorySixByNine
|
||||
interface ForInventoryWidthNine : ForInventoryOneByNine, ForInventoryTwoByNine, ForInventoryThreeByNine,
|
||||
ForInventoryFourByNine, ForInventoryFiveByNine, ForInventorySixByNine
|
@@ -6,8 +6,8 @@ import net.axay.kspigot.inventory.InventoryGUIElement
|
||||
import net.axay.kspigot.inventory.InventoryGUIElementData
|
||||
|
||||
open class InventoryGUIButton<T : ForInventory>(
|
||||
inventoryGUIElementData: InventoryGUIElementData,
|
||||
val action: (InventoryGUIClickEvent<T>) -> Unit,
|
||||
inventoryGUIElementData: InventoryGUIElementData,
|
||||
val action: (InventoryGUIClickEvent<T>) -> Unit,
|
||||
) : InventoryGUIElement<T>(inventoryGUIElementData) {
|
||||
|
||||
override fun onClickElement(clickEvent: InventoryGUIClickEvent<T>) {
|
||||
|
@@ -3,17 +3,16 @@ package net.axay.kspigot.inventory.elements
|
||||
import net.axay.kspigot.inventory.*
|
||||
|
||||
class InventoryGUIButtonInventoryChange<T : ForInventory>(
|
||||
inventoryGUIElementData: InventoryGUIElementData,
|
||||
changeToGUICallback: () -> InventoryGUI<*>,
|
||||
changeToPageInt: Int?,
|
||||
onChange: ((InventoryGUIClickEvent<T>) -> Unit)?
|
||||
)
|
||||
: InventoryGUIButton<T>(inventoryGUIElementData, {
|
||||
inventoryGUIElementData: InventoryGUIElementData,
|
||||
changeToGUICallback: () -> InventoryGUI<*>,
|
||||
changeToPageInt: Int?,
|
||||
onChange: ((InventoryGUIClickEvent<T>) -> Unit)?
|
||||
) : InventoryGUIButton<T>(inventoryGUIElementData, {
|
||||
|
||||
val changeToGUI = changeToGUICallback.invoke()
|
||||
|
||||
val effect = (changeToGUI.data.transitionTo ?: it.gui.data.transitionFrom)
|
||||
?: InventoryChangeEffect.INSTANT
|
||||
?: InventoryChangeEffect.INSTANT
|
||||
|
||||
val changeToPage = changeToGUI.getPage(changeToPageInt) ?: changeToGUI.currentPage
|
||||
|
||||
|
@@ -3,18 +3,17 @@ package net.axay.kspigot.inventory.elements
|
||||
import net.axay.kspigot.inventory.*
|
||||
|
||||
class InventoryGUIButtonPageChange<T : ForInventory>(
|
||||
inventoryGUIElementData: InventoryGUIElementData,
|
||||
calculator: InventoryGUIPageChangeCalculator,
|
||||
onChange: ((InventoryGUIClickEvent<T>) -> Unit)?
|
||||
)
|
||||
: InventoryGUIButton<T>(inventoryGUIElementData, {
|
||||
inventoryGUIElementData: InventoryGUIElementData,
|
||||
calculator: InventoryGUIPageChangeCalculator,
|
||||
onChange: ((InventoryGUIClickEvent<T>) -> Unit)?
|
||||
) : InventoryGUIButton<T>(inventoryGUIElementData, {
|
||||
|
||||
val currentPage = it.gui.currentPage
|
||||
val newPage = it.gui.getPage(calculator.calculateNewPage(it.gui.currentPageInt, it.gui.data.pages.keys))
|
||||
if (newPage != null) {
|
||||
|
||||
val effect = (newPage.transitionTo ?: currentPage.transitionFrom)
|
||||
?: PageChangeEffect.INSTANT
|
||||
?: PageChangeEffect.INSTANT
|
||||
|
||||
it.gui.changePage(effect, currentPage, newPage)
|
||||
|
||||
|
@@ -5,5 +5,7 @@ import net.axay.kspigot.inventory.InventoryGUIClickEvent
|
||||
import net.axay.kspigot.inventory.InventoryGUISlot
|
||||
|
||||
class InventoryGUIFreeSlot<T : ForInventory> : InventoryGUISlot<T>() {
|
||||
override fun onClick(clickEvent: InventoryGUIClickEvent<T>) { /* do nothing */ }
|
||||
override fun onClick(clickEvent: InventoryGUIClickEvent<T>) {
|
||||
/* do nothing */
|
||||
}
|
||||
}
|
@@ -6,7 +6,7 @@ import net.axay.kspigot.inventory.InventoryGUIElement
|
||||
import net.axay.kspigot.inventory.InventoryGUIElementData
|
||||
|
||||
class InventoryGUIPlaceholder<T : ForInventory>(
|
||||
inventoryGUIElementData: InventoryGUIElementData
|
||||
inventoryGUIElementData: InventoryGUIElementData
|
||||
) : InventoryGUIElement<T>(inventoryGUIElementData) {
|
||||
|
||||
override fun onClickElement(clickEvent: InventoryGUIClickEvent<T>) {
|
||||
|
Reference in New Issue
Block a user