Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
library:inventorygui:usage [2020/09/22 17:15] – created phoenix616 | library:inventorygui:usage [2020/11/28 12:55] – [State Element] phoenix616 | ||
---|---|---|---|
Line 81: | Line 81: | ||
and automatically changes the ItemStack icon. | and automatically changes the ItemStack icon. | ||
```java | ```java | ||
- | gui.addElement(new GuiStateElement(' | + | GuiStateElement element = new GuiStateElement(' |
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(" | ||
+ | } else { | ||
+ | element.setState(" | ||
+ | } | ||
+ | |||
+ | 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# | + | You can also set the state directly via `GuiStateElement# |
+ | before you show the GUI or re-draw it. | ||
### Dynamic Element | ### Dynamic Element | ||
Line 115: | Line 125: | ||
the DynamicGuiElement' | the DynamicGuiElement' | ||
```java | ```java | ||
- | gui.addElement(new DynamicGuiElement(' | + | gui.addElement(new DynamicGuiElement(' |
return new StaticGuiElement(' | return new StaticGuiElement(' | ||
click -> { | click -> { |