File tree 3 files changed +29
-29
lines changed
triumph-gui/4_x_x/1-started
3 files changed +29
-29
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,8 @@ setting custom [renderer](/renderer)s.
20
20
21
21
Let's create a GUI with a ` 1 ` row and an item the middle that sends the ` player ` a message when clicking.
22
22
23
- -+-
24
- +Java+
23
+ -+-
24
+ +Java+
25
25
26
26
``` java
27
27
final var gui = Gui . of(1 )
@@ -40,7 +40,7 @@ final var gui = Gui.of(1)
40
40
gui. open(player);
41
41
```
42
42
+++
43
- +Kotlin+
43
+ +Kotlin+
44
44
``` kotlin
45
45
val gui = buildGui {
46
46
// If not set, defaults to chest - 1 row
@@ -64,8 +64,8 @@ val gui = buildGui {
64
64
// Now that the GUI is built, we can open it for the player.
65
65
gui.open(player)
66
66
```
67
- +++
68
- -+-
67
+ +++
68
+ -+-
69
69
70
70
Now that the GUI is created, we can dive into something more complex by utilizing [ States] ( /states ) .
71
71
We can continue onto the next example [ here] ( /using-states ) .
Original file line number Diff line number Diff line change @@ -24,8 +24,8 @@ command class.
24
24
For this state it's nice to make it so it can only be updated if the clicks are higher than the stored value. Thankfully
25
25
we can use a [ StateMutationPolicy] ( /mutation-policy ) for that, so let's create a new one!
26
26
27
- -+-
28
- +Java+
27
+ -+-
28
+ +Java+
29
29
30
30
``` java
31
31
public final class HighScoreMutationPolicy implements StateMutationPolicy<Integer > {
@@ -38,8 +38,8 @@ public final class HighScoreMutationPolicy implements StateMutationPolicy<Intege
38
38
}
39
39
}
40
40
```
41
- +++
42
- +Kotlin+
41
+ +++
42
+ +Kotlin+
43
43
44
44
``` kotlin
45
45
class HighScoreMutationPolicy : StateMutationPolicy <Int ?> {
@@ -51,33 +51,33 @@ class HighScoreMutationPolicy : StateMutationPolicy<Int?> {
51
51
}
52
52
}
53
53
```
54
- +++
55
- -+-
54
+ +++
55
+ -+-
56
56
57
57
_ The mutation policy in this example is not really needed; this is just an example of how it can be used._
58
58
59
59
Now let's create a state with the new policy.
60
60
61
- -+-
62
- +Java+
61
+ -+-
62
+ +Java+
63
63
64
64
``` java
65
65
private final MutableState<Integer > highScoreState = MutableState . of(0 , new HighScoreMutationPolicy ());
66
66
```
67
67
68
- +++
69
- +Kotlin+
68
+ +++
69
+ +Kotlin+
70
70
71
71
``` kotlin
72
72
private val highScoreState = mutableStateOf(0 , HighScoreMutationPolicy ())
73
73
```
74
- +++
75
- -+-
74
+ +++
75
+ -+-
76
76
77
77
Then we can change the GUI to support it.
78
78
79
- -+-
80
- +Java+
79
+ -+-
80
+ +Java+
81
81
82
82
``` java
83
83
final var gui = Gui . of(1 )
@@ -122,8 +122,8 @@ final var gui = Gui.of(1)
122
122
123
123
gui. open(player);
124
124
```
125
- +++
126
- +Kotlin+
125
+ +++
126
+ +Kotlin+
127
127
128
128
``` kotlin
129
129
val gui = buildGui {
@@ -177,8 +177,8 @@ val gui = buildGui {
177
177
178
178
gui.open(player)
179
179
```
180
- +++
181
- -+-
180
+ +++
181
+ -+-
182
182
183
183
When the GUI is opened for the first time the title will update with the clicks, once you close and re-open it, it'll
184
184
only update once you reach a new high score.
Original file line number Diff line number Diff line change @@ -19,8 +19,8 @@ modifier cause the component to re-render.
19
19
Let's take the previous example and add some a state to it. We can create a state that'll keep track of how many times
20
20
a ` player ` has clicked on the item.
21
21
22
- -+-
23
- +Java+
22
+ -+-
23
+ +Java+
24
24
25
25
``` java
26
26
final var gui = Gui . of(1 )
@@ -51,8 +51,8 @@ final var gui = Gui.of(1)
51
51
gui. open(player);
52
52
```
53
53
54
- +++
55
- +Kotlin+
54
+ +++
55
+ +Kotlin+
56
56
``` kotlin
57
57
val gui = buildGui {
58
58
// If not set, defaults to chest - 1 row
@@ -87,7 +87,7 @@ val gui = buildGui {
87
87
88
88
gui.open(player)
89
89
```
90
- +++
91
- -+-
90
+ +++
91
+ -+-
92
92
Congratulations you have built the most simple cookie clicker game!
93
93
But we can improve it even more, let's add title updating into the mix, read more in [ here] ( /updating-title ) .
You can’t perform that action at this time.
0 commit comments