Skip to content

Commit 041d60d

Browse files
committed
feat(event): add CancellableLynxEvent
1 parent 9687cd4 commit 041d60d

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

content/docs/lynx/latest/modules/display/examples/custom-gui.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ Now that we have both the background and title done this is how it looks:
126126

127127
![Custom GUI Progress](https://cdn.undefinedcreations.com/lynx/display/custom-gui-progress.png)
128128

129-
# Add Button Logic
129+
`# Add Button Logic
130130

131131
Next step is adding the button logic. First step to this is creating the visual of the button.
132132

133-
# Visual Logic
133+
### Visual Logic
134134

135135
The button visual contains out of two entities, a `BlockDisplay` and `TextDisplay`. We will start by creating the `BlockDisplay`
136136
We will create it and then set the scale:
@@ -230,7 +230,7 @@ private fun addButton(location: Location) {
230230
}
231231
```
232232

233-
# Interaction
233+
### Interaction
234234
Now that the visual is done we will work of the interaction of the button.
235235
We will start by creating the `Interaction` entity and positioning it correctly:
236236

content/docs/lynx/latest/modules/event/custom-event.mdx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,37 @@ class GameStateChangeEvent(
5151
): LynxEvent() {}
5252
```
5353

54-
Now we have the custom event.
54+
## Cancellable Event
55+
56+
If you want to make you event cancellable you need to change the extensions from `LynxEvent` to `CancellableLynxEvent`:
57+
58+
```java tab="Java"
59+
public class GameStateChangeEvent extends CancellableLynxEvent {
60+
61+
private final GameState oldState;
62+
private final GameState newState;
63+
64+
public GameStateChangeEvent(GameState oldState, GameState newState) {
65+
this.oldState = oldState;
66+
this.newState = newState;
67+
}
68+
69+
public GameState getOldState() {
70+
return oldState;
71+
}
72+
73+
public GameState getNewState() {
74+
return newState;
75+
}
76+
77+
}
78+
```
79+
```kotlin tab="Kotlin"
80+
class GameStateChangeEvent(
81+
val oldState: GameState,
82+
val newState: GameState
83+
): CancellableLynxEvent() {}
84+
```
5585

5686
# Calling Events
5787

0 commit comments

Comments
 (0)