NichtStudioCode / InvUI

A spigot library for creating custom inventory-based GUIs.
MIT License
242 stars 19 forks source link

Inventories PagedGui pagination behavior is abnormal #43

Closed ShellWen closed 1 year ago

ShellWen commented 1 year ago

The pagination of Inventories PagedGui is not functioning correctly. The result of "${gui.currentPage} / ${gui.pageAmount}" is always 0 / 1.

Below is a code snippet that reliably reproduces the issue:

import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import xyz.xenondevs.invui.gui.PagedGui
import xyz.xenondevs.invui.gui.structure.Markers
import xyz.xenondevs.invui.inventory.VirtualInventory
import xyz.xenondevs.invui.inventory.event.UpdateReason
import xyz.xenondevs.invui.item.ItemProvider
import xyz.xenondevs.invui.item.builder.ItemBuilder
import xyz.xenondevs.invui.item.impl.SimpleItem
import xyz.xenondevs.invui.item.impl.controlitem.PageItem
import xyz.xenondevs.invui.window.Window

private fun openTestGui(player: Player) {
    val inv = VirtualInventory(999)
    repeat(999) {
        inv.addItem(UpdateReason.SUPPRESSED, ItemStack(Material.STONE, 64))
    }

    val gui = PagedGui.inventories().apply {
        setStructure(
            "xxxxxxxxx",
            "xxxxxxxxx",
            "xxxxxxxxx",
            "xxxxxxxxx",
            "xxxxxxxxx",
            "###<#>###"
        )
        addIngredient('x', Markers.CONTENT_LIST_SLOT_VERTICAL)
        addIngredient('#', SimpleItem(ItemStack(Material.GRAY_STAINED_GLASS_PANE)))
        addIngredient('<', object : PageItem(false) {
            override fun getItemProvider(gui: PagedGui<*>): ItemProvider =
                ItemBuilder(Material.RED_STAINED_GLASS_PANE).apply {
                    setDisplayName("Back")
                        .addLoreLines(
                            "Back ${gui.currentPage} / ${gui.pageAmount}"
                        )
                }
        })
        addIngredient('>', object : PageItem(true) {
            override fun getItemProvider(gui: PagedGui<*>): ItemProvider =
                ItemBuilder(Material.GREEN_STAINED_GLASS_PANE).apply {
                    setDisplayName("Forward")
                        .addLoreLines(
                            "Forward ${gui.currentPage} / ${gui.pageAmount}"
                        )
                }
        })
        setContent(listOf(inv))
    }.build()

    val window = Window.single().apply {
        setViewer(player)
        setTitle("InvUI Test")
        setGui(gui)
    }.build()

    window.open()
}

Image

NichtStudioCode commented 1 year ago

Pages start at 0.

ShellWen commented 1 year ago

Apologies, what I didn't mention is that when I press the button, there's no paging happening, nothing occurs, which is very strange. Additionally, as seen in the code I provided, I'm using 999 slots, but there's only one page (perhaps two?). Clearly, this is not normal.

ShellWen commented 1 year ago

@NichtStudioCode I apologize for bothering you, but this issue was accidentally closed.

NichtStudioCode commented 1 year ago

No, you only defined one page, so you only have one page. The current implementation is not intended to have slots that cannot be displayed in one page overflow to another page. I guess this could be implemented, but it requires some more in-depth changes in order for it to work properly with resizing of Virtual Inventories. You can just create your own PagedGui implementation by extending AbstractPagedGui, though.