-
Notifications
You must be signed in to change notification settings - Fork 12
GuiWindow
WolfyScript edited this page Feb 20, 2022
·
7 revisions
They contain local Buttons and manage the logic to render the Buttons into the inventory.
Similar to the GuiCluster you need to create a class and extend it with your CustomCache type.
public class YourWindow extends GuiWindow<YourCache> {
//These constants can be private because the Buttons are local and can only be accessed inside this GuiWindow!
private static final String YOUR_LOCAL_BUTTON = "your_local_button";
public YourWindow(GuiCluster<YourCache> guiCluster) {
super(guiCluster, YourCluster.YOUR_WINDOW.getKey(), 54); //Use the constant you defined in the the GuiCluster
}
@Override
public void onInit() {
//Called on initialization. Used to register Buttons.
//For example create a dummy button and use the constant you defined on top!
registerButton(new DummyButton(YOUR_LOCAL_BUTTON, Material.BARRIER));
}
@Override
public void onUpdateSync(GuiUpdate<YourCache> update) {
//Updated sync
update.setButton(1, YOUR_LOCAL_BUTTON);
update.setButton(2, YourCluster.YOUR_GLOBAL_BUTTON);
//As you can see... it can get quite messy if you don't use constants!
//You would have duplicate Strings everywhere and it makes it more difficult to maintain!
}
@Override
public void onUpdateAsync(GuiUpdate<YourCache> update) {
//Updated async
}
}
Buttons registered inside a GuiWindow are only accessable in that GuiWindow.
They can be registered using registerButton(Button button).
To make it easier to access the data of the one who caused the Update there is the GuiUpdate class. It contains all the required data like CustomCache, GuiHandler, Player, etc. that you can use to update the inventory.
To set Buttons into the chat use: the
- setButton(int slot, String id) to set a local Button.
- setButton(int slot, NamespacedKey namespacedKey) to set a global Button.
| Home
| Registry
-
Introduction
- Structure
- InventoryAPI
- Register GuiCluster
- CustomCache
- GuiClusters
- GuiWindow
-
Buttons
- Dummy
- Action
- Toggle
- ChatInput
- MultipleChoice
-
ButtonStates
- ButtonFunctions
- ButtonAction
- ButtonPostAction
- ButtonPreRender
- ButtonRender
- ButtonFunctions