Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
library:inventorygui:usage [2020/11/27 12:41] – [Dynamic Element] Add viewer phoenix616library:inventorygui:usage [2021/05/11 11:36] (current) – [Dynamic Element] Add per player info phoenix616
Line 81: Line 81:
 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 102:
                 "By clicking here you will stop flying"                 "By clicking here you will stop flying"
         )         )
-));+)
 + 
 +# 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 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)`+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.