mirror of
https://github.com/Auxilor/EcoMenus.git
synced 2025-12-19 15:09:20 +00:00
Added pagination
This commit is contained in:
@@ -24,11 +24,12 @@ class ConfigurableSlot(
|
|||||||
) : PositionedComponent {
|
) : PositionedComponent {
|
||||||
override val row: Int = config.getInt("location.row")
|
override val row: Int = config.getInt("location.row")
|
||||||
override val column: Int = config.getInt("location.column")
|
override val column: Int = config.getInt("location.column")
|
||||||
|
val page: Int = config.getInt("location.page")
|
||||||
|
|
||||||
override val layer = runCatching { enumValueOf<MenuLayer>(config.getString("layer")) }
|
override val layer = runCatching { enumValueOf<MenuLayer>(config.getString("layer")) }
|
||||||
.getOrElse { MenuLayer.MIDDLE }
|
.getOrElse { MenuLayer.MIDDLE }
|
||||||
|
|
||||||
val context = baseContext.with("slot at row ${row}, column $column")
|
val context = baseContext.with("slot at row ${row}, column $column, page $page")
|
||||||
|
|
||||||
private val conditions = Conditions.compile(
|
private val conditions = Conditions.compile(
|
||||||
config.getSubsections("conditions"),
|
config.getSubsections("conditions"),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.willfp.ecomenus.components
|
|||||||
import com.willfp.eco.core.gui.GUIComponent
|
import com.willfp.eco.core.gui.GUIComponent
|
||||||
import com.willfp.eco.core.gui.menu.MenuBuilder
|
import com.willfp.eco.core.gui.menu.MenuBuilder
|
||||||
import com.willfp.eco.core.gui.menu.MenuLayer
|
import com.willfp.eco.core.gui.menu.MenuLayer
|
||||||
|
import com.willfp.eco.core.gui.page.PageBuilder
|
||||||
|
|
||||||
interface PositionedComponent : GUIComponent {
|
interface PositionedComponent : GUIComponent {
|
||||||
val row: Int
|
val row: Int
|
||||||
@@ -23,11 +24,13 @@ interface PositionedComponent : GUIComponent {
|
|||||||
override fun getColumns() = columnSize
|
override fun getColumns() = columnSize
|
||||||
}
|
}
|
||||||
|
|
||||||
fun MenuBuilder.addComponent(
|
// Little hack to prevent two identical methods
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
fun <T : PageBuilder> T.addComponent(
|
||||||
component: PositionedComponent
|
component: PositionedComponent
|
||||||
) = if (component.isEnabled) addComponent(
|
): T = if (component.isEnabled) addComponent(
|
||||||
component.layer,
|
component.layer,
|
||||||
component.row,
|
component.row,
|
||||||
component.column,
|
component.column,
|
||||||
component
|
component
|
||||||
) else this
|
) as T else this
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.willfp.ecomenus.components.impl
|
|||||||
|
|
||||||
import com.willfp.eco.core.config.interfaces.Config
|
import com.willfp.eco.core.config.interfaces.Config
|
||||||
import com.willfp.eco.core.gui.menu.Menu
|
import com.willfp.eco.core.gui.menu.Menu
|
||||||
|
import com.willfp.eco.core.gui.menu.MenuLayer
|
||||||
import com.willfp.eco.core.gui.page.PageChanger
|
import com.willfp.eco.core.gui.page.PageChanger
|
||||||
import com.willfp.eco.core.items.Items
|
import com.willfp.eco.core.items.Items
|
||||||
import com.willfp.ecomenus.components.PositionedComponent
|
import com.willfp.ecomenus.components.PositionedComponent
|
||||||
@@ -18,6 +19,7 @@ class PositionedPageChanger(
|
|||||||
|
|
||||||
override val row: Int = config.getInt("location.row")
|
override val row: Int = config.getInt("location.row")
|
||||||
override val column: Int = config.getInt("location.column")
|
override val column: Int = config.getInt("location.column")
|
||||||
|
override val layer = MenuLayer.TOP
|
||||||
|
|
||||||
override val isEnabled = config.getBool("enabled")
|
override val isEnabled = config.getBool("enabled")
|
||||||
|
|
||||||
|
|||||||
@@ -37,15 +37,26 @@ fun Menu.close(player: Player) =
|
|||||||
this.previousMenus[player].popOrNull()?.open(player) ?: player.closeInventory()
|
this.previousMenus[player].popOrNull()?.open(player) ?: player.closeInventory()
|
||||||
|
|
||||||
fun buildMenu(plugin: EcoPlugin, menu: EcoMenu, config: Config): Menu {
|
fun buildMenu(plugin: EcoPlugin, menu: EcoMenu, config: Config): Menu {
|
||||||
val mask = FillerMask(
|
val pageConfigs = config.getSubsections("pages")
|
||||||
MaskItems.fromItemNames(config.getStrings("mask.materials")),
|
|
||||||
*config.getStrings("mask.pattern").toTypedArray()
|
val slots = mutableListOf<ConfigurableSlot>()
|
||||||
|
|
||||||
|
for (slotConfig in config.getSubsections("slots")) {
|
||||||
|
val slot = ConfigurableSlot(
|
||||||
|
plugin,
|
||||||
|
ViolationContext(plugin, "menu ${menu.id}"),
|
||||||
|
slotConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
return menu(mask.rows) {
|
slots += slot
|
||||||
|
}
|
||||||
|
|
||||||
|
return menu(config.getInt("rows")) {
|
||||||
title = config.getFormattedString("title")
|
title = config.getFormattedString("title")
|
||||||
|
|
||||||
setMask(mask)
|
allowChangingHeldItem()
|
||||||
|
|
||||||
|
maxPages(pageConfigs.size)
|
||||||
|
|
||||||
addComponent(
|
addComponent(
|
||||||
PositionedPageChanger(
|
PositionedPageChanger(
|
||||||
@@ -61,19 +72,26 @@ fun buildMenu(plugin: EcoPlugin, menu: EcoMenu, config: Config): Menu {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
for (page in config.getSubsections("pages")) {
|
for (page in pageConfigs) {
|
||||||
addPage(page.getInt("page")) {
|
val mask = FillerMask(
|
||||||
for (slotConfig in config.getSubsections("slots")) {
|
MaskItems.fromItemNames(page.getStrings("mask.items")),
|
||||||
val slot = ConfigurableSlot(
|
*page.getStrings("mask.pattern").toTypedArray()
|
||||||
plugin,
|
|
||||||
ViolationContext(plugin, "menu ${menu.id}"),
|
|
||||||
slotConfig
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val pageNumber = page.getInt("page")
|
||||||
|
|
||||||
|
addPage(pageNumber) {
|
||||||
|
setMask(mask)
|
||||||
|
|
||||||
|
for (slot in slots) {
|
||||||
|
if (pageNumber != slot.page) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addComponent(slot)
|
this.addComponent(slot)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
slot.context.log(ConfigViolation("location", "The location of the slot is invalid!"))
|
slot.context.log(ConfigViolation("location", "Invalid location!"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,30 +10,8 @@ title: "Example GUI"
|
|||||||
# (Optional) The command to open the GUI, if not set, there will be no command.
|
# (Optional) The command to open the GUI, if not set, there will be no command.
|
||||||
command: examplemenu
|
command: examplemenu
|
||||||
|
|
||||||
mask:
|
# The size of the GUI, between 1 and 6
|
||||||
# The way the mask works is by having a list of materials
|
rows: 6
|
||||||
# And then a pattern to use those materials.
|
|
||||||
|
|
||||||
# The size of the GUI is determined by the size of the mask.
|
|
||||||
|
|
||||||
# The pattern is the rows in the GUI
|
|
||||||
# Each line must be 9 long, and the amount of rows should be the amount of rows in the GUI
|
|
||||||
# A zero represents nothing
|
|
||||||
# A 1 represents the first material
|
|
||||||
# A 2 represents the second material
|
|
||||||
# And so on, you can add up to 9.
|
|
||||||
|
|
||||||
materials:
|
|
||||||
- gray_stained_glass_pane
|
|
||||||
- black_stained_glass_pane
|
|
||||||
pattern:
|
|
||||||
- "211101112"
|
|
||||||
- "211111112"
|
|
||||||
- "210000012"
|
|
||||||
- "210010012"
|
|
||||||
- "211111112"
|
|
||||||
- "211101112"
|
|
||||||
|
|
||||||
|
|
||||||
# Read https://plugins.auxilor.io/effects/configuring-a-condition
|
# Read https://plugins.auxilor.io/effects/configuring-a-condition
|
||||||
# The conditions required to open the GUI
|
# The conditions required to open the GUI
|
||||||
@@ -62,12 +40,36 @@ backwards-arrow:
|
|||||||
|
|
||||||
pages:
|
pages:
|
||||||
- page: 1
|
- page: 1
|
||||||
|
mask:
|
||||||
|
# The way the mask works is by having a list of materials
|
||||||
|
# And then a pattern to use those materials.
|
||||||
|
|
||||||
|
# The pattern is the rows in the GUI
|
||||||
|
# Each line must be 9 long, and the amount of rows should be the amount of rows in the GUI
|
||||||
|
# A zero represents nothing
|
||||||
|
# A 1 represents the first material
|
||||||
|
# A 2 represents the second material
|
||||||
|
# And so on, you can add up to 9.
|
||||||
|
|
||||||
|
items:
|
||||||
|
- gray_stained_glass_pane
|
||||||
|
- black_stained_glass_pane
|
||||||
|
pattern:
|
||||||
|
- "211101112"
|
||||||
|
- "211111112"
|
||||||
|
- "210000012"
|
||||||
|
- "210010012"
|
||||||
|
- "211111112"
|
||||||
|
- "211101112"
|
||||||
|
|
||||||
slots:
|
slots:
|
||||||
- item: barrier name:"&cClose"
|
- item: barrier name:"&cClose"
|
||||||
lore: [ ]
|
lore: [ ]
|
||||||
location:
|
location:
|
||||||
row: 6
|
row: 6
|
||||||
column: 5
|
column: 5
|
||||||
|
page: 1
|
||||||
|
|
||||||
# (Optional) You can specify the layer of the slot.
|
# (Optional) You can specify the layer of the slot.
|
||||||
# The layer can be any of: lower, middle, upper, or top (defaults to middle)
|
# The layer can be any of: lower, middle, upper, or top (defaults to middle)
|
||||||
# This is useful if you want to have a slot on top of another slot, and
|
# This is useful if you want to have a slot on top of another slot, and
|
||||||
|
|||||||
Reference in New Issue
Block a user