Class PagedComponent
java.lang.Object
io.github.toberocat.guiengine.components.AbstractGuiComponent
io.github.toberocat.guiengine.components.provided.embedded.EmbeddedGuiComponent
io.github.toberocat.guiengine.components.provided.paged.PagedComponent
- All Implemented Interfaces:
ContextContainer
,GuiComponent
,GuiComponentContainer
,GuiEvents
public class PagedComponent
extends EmbeddedGuiComponent
implements GuiComponentContainer, ContextContainer
A custom GUI component that represents a paged GUI.
It allows displaying multiple pages of components in a specific pattern on a GUI.
This component can be navigated using NextPageAction and PreviousPageAction actions.
Created: 30.04.2023
- Author:
- Tobias Madlberger (Tobias)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final @NotNull ParserContext
protected final int[]
protected int
static final String
Fields inherited from class io.github.toberocat.guiengine.components.provided.embedded.EmbeddedGuiComponent
copyAir, embedded, interactions, targetGui
Fields inherited from class io.github.toberocat.guiengine.components.AbstractGuiComponent
api, clickFunctions, closeFunctions, context, dragFunctions, height, id, offsetX, offsetY, priority, width
-
Constructor Summary
ConstructorsConstructorDescriptionPagedComponent
(int offsetX, int offsetY, int width, int height, @NotNull RenderPriority priority, @NotNull String id, @NotNull List<GuiFunction> clickFunctions, @NotNull List<GuiFunction> dragFunctions, @NotNull List<GuiFunction> closeFunctions, boolean hidden, @NotNull String targetGui, boolean copyAir, boolean interactions, @NotNull ParserContext parent, int[] pattern, int showingPage) Constructs a new PagedComponent instance with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addActions
(@NotNull Set<io.github.toberocat.toberocore.action.Action> actions) Add actions to the GUI component.void
addComponent
(@NotNull GuiComponent component) Adds a new component to the current page.void
addContext
(GuiContext context) void
Creates a new empty pagevoid
addPage
(@NotNull GuiContext page) Adds a new page to the paged component.void
addPage
(@NotNull GuiContext page, int position) Adds a new page to the paged component at the specified position.void
int
Gets the total number of available pages in the paged component.int
getPage()
Gets the current page number of the paged component.int
Gets the index of the currently showing page of the paged component.@NotNull String
getType()
Get the type of the GUI component.void
onViewInit
(@NotNull Map<String, String> placeholders) Called when the GUI is initialized and the viewer (player) opens it.void
render
(@NotNull org.bukkit.entity.Player viewer, @NotNull org.bukkit.inventory.ItemStack[][] buffer) Render the GUI component for a specific player and inventory configuration.void
Resets the pattern.void
serialize
(@NotNull GeneratorContext gen, @NotNull com.fasterxml.jackson.databind.SerializerProvider serializers) Serialize the GUI component using the provided GeneratorContext and SerializerProvider.void
setShowingPage
(int page) Sets the currently showing page index of the paged component.Methods inherited from class io.github.toberocat.guiengine.components.provided.embedded.EmbeddedGuiComponent
clickedComponent, closedComponent, draggedComponent
Methods inherited from class io.github.toberocat.guiengine.components.AbstractGuiComponent
getClickFunctions, getCloseFunctions, getDragFunctions, getId, height, hidden, offsetX, offsetY, renderPriority, setApi, setContext, setHidden, setOffsetX, setOffsetY, width
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.github.toberocat.guiengine.components.GuiComponent
isInComponent
-
Field Details
-
TYPE
- See Also:
-
parent
-
pattern
protected final int[] pattern -
showingPage
protected int showingPage
-
-
Constructor Details
-
PagedComponent
public PagedComponent(int offsetX, int offsetY, int width, int height, @NotNull @NotNull RenderPriority priority, @NotNull @NotNull String id, @NotNull @NotNull List<GuiFunction> clickFunctions, @NotNull @NotNull List<GuiFunction> dragFunctions, @NotNull @NotNull List<GuiFunction> closeFunctions, boolean hidden, @NotNull @NotNull String targetGui, boolean copyAir, boolean interactions, @NotNull @NotNull ParserContext parent, int[] pattern, int showingPage) Constructs a new PagedComponent instance with the specified parameters.- Parameters:
offsetX
- The X-axis offset of the component within the GUI.offsetY
- The Y-axis offset of the component within the GUI.width
- The width of the component.height
- The height of the component.priority
- The rendering priority of the component.id
- The unique ID of the component.clickFunctions
- The list of click functions associated with the component.dragFunctions
- The list of drag functions associated with the component.closeFunctions
- The list of close functions associated with the component.hidden
- Whether the component is hidden or not.targetGui
- The target GUI to display when this component is clicked.copyAir
- Whether to copy air items to the target GUI.interactions
- Whether to enable interactions between this component and the target GUI.parent
- The parent parser context that contains the GUI definition.pattern
- The pattern of slots on the GUI to arrange the components.showingPage
- The index of the currently showing page.
-
-
Method Details
-
serialize
public void serialize(@NotNull @NotNull GeneratorContext gen, @NotNull @NotNull com.fasterxml.jackson.databind.SerializerProvider serializers) throws IOException Description copied from interface:GuiComponent
Serialize the GUI component using the provided GeneratorContext and SerializerProvider. This method is used to serialize the component's properties to a JSON representation.- Specified by:
serialize
in interfaceGuiComponent
- Overrides:
serialize
in classEmbeddedGuiComponent
- Parameters:
gen
- The GeneratorContext used for serialization.serializers
- The SerializerProvider used for serialization.- Throws:
IOException
- If there is an error during serialization.
-
onViewInit
Description copied from interface:GuiEvents
Called when the GUI is initialized and the viewer (player) opens it. This method is intended to handle any necessary initialization tasks before the GUI is shown to the player. The `placeholders` parameter can be used to store additional information specific to the GUI. The default behavior is to do nothing.- Specified by:
onViewInit
in interfaceGuiEvents
- Overrides:
onViewInit
in classEmbeddedGuiComponent
- Parameters:
placeholders
- A map containing placeholder data for the GUI.
-
addPage
Adds a new page to the paged component.- Parameters:
page
- The new page to add.
-
addPage
Adds a new page to the paged component at the specified position.- Parameters:
page
- The new page to add.position
- The position at which to add the page.
-
addComponent
Adds a new component to the current page.- Specified by:
addComponent
in interfaceGuiComponentContainer
- Parameters:
component
- The component to add.
-
clearContainer
public void clearContainer()- Specified by:
clearContainer
in interfaceContextContainer
- Specified by:
clearContainer
in interfaceGuiComponentContainer
-
addContext
- Specified by:
addContext
in interfaceContextContainer
-
getType
Description copied from interface:GuiComponent
Get the type of the GUI component.- Specified by:
getType
in interfaceGuiComponent
- Overrides:
getType
in classEmbeddedGuiComponent
- Returns:
- The type of the GUI component.
-
render
public void render(@NotNull @NotNull org.bukkit.entity.Player viewer, @NotNull @NotNull org.bukkit.inventory.ItemStack[][] buffer) Description copied from interface:GuiComponent
Render the GUI component for a specific player and inventory configuration. This method is responsible for rendering the component to the graphical user interface.- Specified by:
render
in interfaceGuiComponent
- Overrides:
render
in classEmbeddedGuiComponent
- Parameters:
viewer
- The player for whom the component should be rendered.buffer
- The inventory configuration used for rendering the GUI.
-
addActions
Description copied from interface:GuiComponent
Add actions to the GUI component. This method allows adding GUI actions that can be triggered by the player interacting with the component.- Specified by:
addActions
in interfaceGuiComponent
- Parameters:
actions
- A set of actions to be added to the component.
-
setShowingPage
public void setShowingPage(int page) Sets the currently showing page index of the paged component.- Parameters:
page
- The index of the page to show.- Throws:
IllegalArgumentException
- If the specified page is not within the valid bounds.
-
getShowingPage
public int getShowingPage()Gets the index of the currently showing page of the paged component.- Returns:
- The index of the currently showing page.
-
getPage
public int getPage()Gets the current page number of the paged component.- Returns:
- The current page number (1-based index).
-
getAvailablePages
public int getAvailablePages()Gets the total number of available pages in the paged component.- Returns:
- The total number of available pages.
-
addEmptyPage
public void addEmptyPage()Creates a new empty page -
resetPatternOnPage
public void resetPatternOnPage()Resets the pattern. This will break stuff with the automated paging if used wrong
-