Skip to content

Commit fecc8f4

Browse files
committed
Add dialog closing section and refactor preview videos
1 parent 7bacd34 commit fecc8f4

File tree

9 files changed

+33
-23
lines changed

9 files changed

+33
-23
lines changed
2.51 MB
Loading
-144 KB
Binary file not shown.
2.46 MB
Loading
Binary file not shown.
5.84 MB
Loading
Binary file not shown.
8.16 MB
Loading
-289 KB
Binary file not shown.

src/content/docs/paper/dev/api/dialogs.mdx

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ sidebar:
1111

1212
import Video from "/src/components/Video.astro";
1313

14-
import InputBooleanMp4 from "./assets/dialogs/input-boolean.mp4?url";
15-
import InputMultiOptionMp4 from "./assets/dialogs/input-multi-options.mp4?url";
16-
import InputTextMp4 from "./assets/dialogs/input-text.mp4?url";
17-
import InputNumberRange from "./assets/dialogs/input-number-range.mp4?url";
1814
import DialogShowcaseMp4 from "./assets/dialogs/dialog-showcase.mp4?url";
1915
import InputDialogShowcaseMp4 from "./assets/dialogs/input-dialog-showcase.mp4?url";
2016

@@ -66,6 +62,12 @@ can be declared in the builder. You can either create a new dialog or alternativ
6662
[registry-registered](#registering-dialogs-in-the-registry) dialog as a base instead.
6763

6864
For reference, a very simple (notice-type) dialog can be constructed and shown to a player with the following code:
65+
66+
<details>
67+
<summary>In-game preview</summary>
68+
![A dialog with only a title and an ok button](./assets/dialogs/notice-dialog.png)
69+
</details>
70+
6971
```java
7072
Dialog dialog = Dialog.create(builder -> builder.empty()
7173
.base(DialogBase.builder(Component.text("Title")).build())
@@ -74,11 +76,6 @@ Dialog dialog = Dialog.create(builder -> builder.empty()
7476
player.showDialog(dialog);
7577
```
7678

77-
<details>
78-
<summary>In-game preview</summary>
79-
![A dialog with only a title and an ok button](./assets/dialogs/notice-dialog.png)
80-
</details>
81-
8279
### Dialog base
8380
You can create a dialog base using its [builder](jd:paper:io.papermc.paper.registry.data.dialog.DialogBase$Builder), which can be created
8481
using [`DialogBase.builder(Component title)`](jd:paper:io.papermc.paper.registry.data.dialog.DialogBase#builder(net.kyori.adventure.text.Component)).
@@ -104,25 +101,25 @@ There are four ways to gather input:
104101

105102
A simple tick box representing a true or false state
106103

107-
<Video src={InputBooleanMp4} />
104+
![](./assets/dialogs/input-boolean.gif)
108105

109106
- [`DialogInput.singleOption`](jd:paper:io.papermc.paper.registry.data.dialog.input.DialogInput#singleOption(java.lang.String,net.kyori.adventure.text.Component,java.util.List))
110107

111108
A multiple-choice button
112109

113-
<Video src={InputMultiOptionMp4} />
110+
![](./assets/dialogs/input-multi-options.gif)
114111

115112
- [`DialogInput.text`](jd:paper:io.papermc.paper.registry.data.dialog.input.DialogInput#text(java.lang.String,net.kyori.adventure.text.Component))
116113

117114
A simple string input field
118115

119-
<Video src={InputTextMp4} />
116+
![](./assets/dialogs/input-text.gif)
120117

121118
- [`DialogInput.numberRange`](jd:paper:io.papermc.paper.registry.data.dialog.input.DialogInput#numberRange(java.lang.String,net.kyori.adventure.text.Component,float,float))
122119

123120
A slider for number input
124121

125-
<Video src={InputNumberRange}/>
122+
![](./assets/dialogs/input-number-range.gif)
126123

127124

128125
### Dialog type
@@ -166,6 +163,17 @@ public void bootstrap(BootstrapContext context) {
166163
}
167164
```
168165

166+
## Closing dialogs
167+
Dialogs can be closed from the API. There are two ways to achieve that:
168+
169+
- The intended way of using [`Adventure#closeDialog()`](https://jd.advntr.dev/api/latest/net/kyori/adventure/audience/Audience.html#closeDialog()).
170+
- The slightly hacky way of using [`Player#closeInventory()](jd:paper:org.bukkit.entity.HumanEntity#closeInventory()).
171+
172+
Using `closeDialog()` will result in the dialog being closed and the player returning to the previous non-dialog or game menu screen they were on.
173+
This means any previously open inventories will be kept open.
174+
175+
In contrast, `closeInventory()` will close not only the currently open dialog, but also any other screens, like an open inventory.
176+
169177
## Example: A blocking confirmation dialog
170178
If you want your players to read some information, agree to something, or give general input before they join your server,
171179
you can send them a dialog during the configuration phase. For this example, we will be creating the dialog shown at
@@ -214,6 +222,12 @@ this by constructing a `CompletableFuture`, putting it into a map, and waiting u
214222
completed, will only happen as soon the player pressed one of the two confirmation buttons of the dialog.
215223

216224
The code for that would look something like this:
225+
226+
<details>
227+
<summary>In-game preview</summary>
228+
<Video src={DialogShowcaseMp4} />
229+
</details>
230+
217231
```java title="ServerJoinListener.java" showLineNumbers
218232
@NullMarked
219233
public class ServerJoinListener implements Listener {
@@ -284,11 +298,6 @@ public class ServerJoinListener implements Listener {
284298
And that's all there is to it. You can use this code to block players from joining your server before they should
285299
be allowed to.
286300

287-
<details>
288-
<summary>In-game preview</summary>
289-
<Video src={DialogShowcaseMp4} />
290-
</details>
291-
292301
## Example: Retrieving and parsing user input
293302
The dialog for this example will be fairly simple: We once again create a confirmation-type dialog which contains two number range inputs.
294303
The top input will be for setting the level, the bottom input for setting the experience percentage towards the next level.
@@ -343,6 +352,12 @@ to cast the connection retrievable from [`PlayerCustomClickEvent#getCommonConnec
343352
to a [`PlayerGameConnection`](jd:paper:io.papermc.paper.connection.PlayerGameConnection), from which we can get the player.
344353

345354
The full event handler code looks like this:
355+
356+
<details>
357+
<summary>In-game preview</summary>
358+
<Video src={InputDialogShowcaseMp4} />
359+
</details>
360+
346361
```java
347362
@EventHandler
348363
void handleLevelsDialog(PlayerCustomClickEvent event) {
@@ -400,8 +415,3 @@ DialogAction.customClick(
400415
.build()
401416
)
402417
```
403-
404-
<details>
405-
<summary>In-game preview</summary>
406-
<Video src={InputDialogShowcaseMp4} />
407-
</details>

0 commit comments

Comments
 (0)