Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
library:inventorygui:usage [2020/09/22 17:15] – created phoenix616library:inventorygui:usage [2025/04/18 12:45] (current) – [Creating the GUI] phoenix616
Line 18: Line 18:
 The GUI supports 3\*3, 5\*1 and 9\*x inventory sizes. The GUI supports 3\*3, 5\*1 and 9\*x inventory sizes.
 Sizes that do not match these are getting expanded to the next bigger one. Sizes that do not match these are getting expanded to the next bigger one.
- 
 ## Creating the GUI ## Creating the GUI
 You create GUIs assigned to an InventoryHolder like a Container or a LivingEntity.  You create GUIs assigned to an InventoryHolder like a Container or a LivingEntity. 
Line 28: Line 27:
 gui.setFiller(new ItemStack(Material.GRAY_STAINED_GLASS, 1)); // fill the empty slots with this gui.setFiller(new ItemStack(Material.GRAY_STAINED_GLASS, 1)); // fill the empty slots with this
 ``` ```
 +
 +If you want to use more advanced formatting of text with RGB colors then take a look at [[library:inventorygui:components|this page]] on how to do create an `InventoryGui` instance which can do that.
  
 ## Adding to the GUI ## Adding to the GUI
Line 81: Line 82:
 and automatically changes the ItemStack icon. and automatically changes the ItemStack icon.
 ```java ```java
-gui.addElement(new GuiStateElement('z', +GuiStateElement element = new GuiStateElement('z', 
         new GuiStateElement.State(         new GuiStateElement.State(
                 change -> {                 change -> {
Line 102: Line 103:
                 "By clicking here you will stop flying"                 "By clicking here you will stop flying"
         )         )
-)); +);
-``` +
-... you can define as many states as you want, they will cycle through on each click +
-you can also set the state directly via `GuiStateElement#setState(String key)`+
  
 +# Set the current state
 +if (player.isFlying()) {
 +    element.setState("flyingEnabled");
 +} else {
 +    element.setState("flyingDisabled");
 +}
 +
 +gui.addElement(element);
 +```
 +You can define as many states as you want, they will cycle through on each click.
 +You can also set the state directly via `GuiStateElement#setState(String key)`
 +before you show the GUI or re-draw it.
 ### Dynamic Element ### Dynamic Element
-You can also dynamically load elements each time the GUI is re-drawn. E.g. when you want to cache GUIs but not the  +You can also dynamically load elements each time the GUI is re-drawn and for each viewing player individually. E.g. when you want to cache GUIs but not the text of some buttons, display different elements per player or dynamically change them while they are open without closing and reopening them.
-text of some buttons or dynamically change them while they are open without closing and reopening them.+
  
 Dynamic elements just return one of the other elements that should be displayed each time `InventoryGui#draw` is called. Dynamic elements just return one of the other elements that should be displayed each time `InventoryGui#draw` is called.
Line 115: Line 124:
 the DynamicGuiElement's slot character though. the DynamicGuiElement's slot character though.
 ```java ```java
-gui.addElement(new DynamicGuiElement('d', () -> {+gui.addElement(new DynamicGuiElement('d', (viewer) -> {
     return new StaticGuiElement('d', new ItemStack (Material.CLOCK),      return new StaticGuiElement('d', new ItemStack (Material.CLOCK), 
         click -> {         click -> {
Line 124: Line 133:
 })); }));
 ``` ```
-As you can see you can change the content of a DynamicGuiElement after a player click on it by calling `InventoryGui#draw` in the action of the supplied element.+As you can see you can change the content of a DynamicGuiElement after a player clicks on it by calling `InventoryGui#draw` in the action of the supplied element.
  
 ### Element Group ### Element Group