@minecraft/server-ui 1.2.0-beta.1.20.70-preview.21 → 1.2.0-beta.1.20.70-preview.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +164 -0
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -63,6 +63,30 @@ export enum FormRejectReason {
|
|
|
63
63
|
/**
|
|
64
64
|
* Builds a simple player form with buttons that let the player
|
|
65
65
|
* take action.
|
|
66
|
+
* @example actionFormAskFavoriteMonth.ts
|
|
67
|
+
* ```typescript
|
|
68
|
+
* import { Player } from '@minecraft/server';
|
|
69
|
+
* import { ActionFormData, ActionFormResponse } from '@minecraft/server-ui';
|
|
70
|
+
*
|
|
71
|
+
* function askFavoriteMonth(player: Player) {
|
|
72
|
+
* const form = new ActionFormData()
|
|
73
|
+
* .title('Months')
|
|
74
|
+
* .body('Choose your favorite month!')
|
|
75
|
+
* .button('January')
|
|
76
|
+
* .button('February')
|
|
77
|
+
* .button('March')
|
|
78
|
+
* .button('April')
|
|
79
|
+
* .button('May');
|
|
80
|
+
*
|
|
81
|
+
* form.show(player).then((response: ActionFormResponse) => {
|
|
82
|
+
* if (response.selection === 3) {
|
|
83
|
+
* player.sendMessage('I like April too!');
|
|
84
|
+
* } else {
|
|
85
|
+
* player.sendMessage('Nah, April is the best.');
|
|
86
|
+
* }
|
|
87
|
+
* });
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
66
90
|
*/
|
|
67
91
|
export class ActionFormData {
|
|
68
92
|
/**
|
|
@@ -102,6 +126,30 @@ export class ActionFormData {
|
|
|
102
126
|
/**
|
|
103
127
|
* Returns data about the player results from a modal action
|
|
104
128
|
* form.
|
|
129
|
+
* @example actionFormAskFavoriteMonth.ts
|
|
130
|
+
* ```typescript
|
|
131
|
+
* import { Player } from '@minecraft/server';
|
|
132
|
+
* import { ActionFormData, ActionFormResponse } from '@minecraft/server-ui';
|
|
133
|
+
*
|
|
134
|
+
* function askFavoriteMonth(player: Player) {
|
|
135
|
+
* const form = new ActionFormData()
|
|
136
|
+
* .title('Months')
|
|
137
|
+
* .body('Choose your favorite month!')
|
|
138
|
+
* .button('January')
|
|
139
|
+
* .button('February')
|
|
140
|
+
* .button('March')
|
|
141
|
+
* .button('April')
|
|
142
|
+
* .button('May');
|
|
143
|
+
*
|
|
144
|
+
* form.show(player).then((response: ActionFormResponse) => {
|
|
145
|
+
* if (response.selection === 3) {
|
|
146
|
+
* player.sendMessage('I like April too!');
|
|
147
|
+
* } else {
|
|
148
|
+
* player.sendMessage('Nah, April is the best.');
|
|
149
|
+
* }
|
|
150
|
+
* });
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
105
153
|
*/
|
|
106
154
|
// @ts-ignore Class inheritance allowed for native defined classes
|
|
107
155
|
export class ActionFormResponse extends FormResponse {
|
|
@@ -136,6 +184,33 @@ export class FormResponse {
|
|
|
136
184
|
|
|
137
185
|
/**
|
|
138
186
|
* Builds a simple two-button modal dialog.
|
|
187
|
+
* @example messageFormSimple.ts
|
|
188
|
+
* ```typescript
|
|
189
|
+
* import { Player } from '@minecraft/server';
|
|
190
|
+
* import { MessageFormResponse, MessageFormData } from '@minecraft/server-ui';
|
|
191
|
+
*
|
|
192
|
+
* function showMessage(player: Player) {
|
|
193
|
+
* const messageForm = new MessageFormData()
|
|
194
|
+
* .title({ translate: 'permissions.removeplayer' }) // "Remove player"
|
|
195
|
+
* .body({ translate: 'accessibility.list.or.two', with: ['Player 1', 'Player 2'] }) // "Player 1 or Player 2"
|
|
196
|
+
* .button1('Player 1')
|
|
197
|
+
* .button2('Player 2');
|
|
198
|
+
*
|
|
199
|
+
* messageForm
|
|
200
|
+
* .show(player)
|
|
201
|
+
* .then((formData: MessageFormResponse) => {
|
|
202
|
+
* // player canceled the form, or another dialog was up and open.
|
|
203
|
+
* if (formData.canceled || formData.selection === undefined) {
|
|
204
|
+
* return;
|
|
205
|
+
* }
|
|
206
|
+
*
|
|
207
|
+
* player.sendMessage(`You selected ${formData.selection === 0 ? 'Player 1' : 'Player 2'}`);
|
|
208
|
+
* })
|
|
209
|
+
* .catch((error: Error) => {
|
|
210
|
+
* player.sendMessage('Failed to show form: ' + error);
|
|
211
|
+
* });
|
|
212
|
+
* }
|
|
213
|
+
* ```
|
|
139
214
|
*/
|
|
140
215
|
export class MessageFormData {
|
|
141
216
|
/**
|
|
@@ -182,6 +257,33 @@ export class MessageFormData {
|
|
|
182
257
|
/**
|
|
183
258
|
* Returns data about the player results from a modal message
|
|
184
259
|
* form.
|
|
260
|
+
* @example messageFormSimple.ts
|
|
261
|
+
* ```typescript
|
|
262
|
+
* import { Player } from '@minecraft/server';
|
|
263
|
+
* import { MessageFormResponse, MessageFormData } from '@minecraft/server-ui';
|
|
264
|
+
*
|
|
265
|
+
* function showMessage(player: Player) {
|
|
266
|
+
* const messageForm = new MessageFormData()
|
|
267
|
+
* .title({ translate: 'permissions.removeplayer' }) // "Remove player"
|
|
268
|
+
* .body({ translate: 'accessibility.list.or.two', with: ['Player 1', 'Player 2'] }) // "Player 1 or Player 2"
|
|
269
|
+
* .button1('Player 1')
|
|
270
|
+
* .button2('Player 2');
|
|
271
|
+
*
|
|
272
|
+
* messageForm
|
|
273
|
+
* .show(player)
|
|
274
|
+
* .then((formData: MessageFormResponse) => {
|
|
275
|
+
* // player canceled the form, or another dialog was up and open.
|
|
276
|
+
* if (formData.canceled || formData.selection === undefined) {
|
|
277
|
+
* return;
|
|
278
|
+
* }
|
|
279
|
+
*
|
|
280
|
+
* player.sendMessage(`You selected ${formData.selection === 0 ? 'Player 1' : 'Player 2'}`);
|
|
281
|
+
* })
|
|
282
|
+
* .catch((error: Error) => {
|
|
283
|
+
* player.sendMessage('Failed to show form: ' + error);
|
|
284
|
+
* });
|
|
285
|
+
* }
|
|
286
|
+
* ```
|
|
185
287
|
*/
|
|
186
288
|
// @ts-ignore Class inheritance allowed for native defined classes
|
|
187
289
|
export class MessageFormResponse extends FormResponse {
|
|
@@ -197,6 +299,37 @@ export class MessageFormResponse extends FormResponse {
|
|
|
197
299
|
/**
|
|
198
300
|
* Used to create a fully customizable pop-up form for a
|
|
199
301
|
* player.
|
|
302
|
+
* @example modalFormSimple.ts
|
|
303
|
+
* ```typescript
|
|
304
|
+
* import { Player } from '@minecraft/server';
|
|
305
|
+
* import { ModalFormData } from '@minecraft/server-ui';
|
|
306
|
+
*
|
|
307
|
+
* function showExampleModal(player: Player) {
|
|
308
|
+
* const modalForm = new ModalFormData().title('Example Modal Controls for §o§7ModalFormData§r');
|
|
309
|
+
*
|
|
310
|
+
* modalForm.toggle('Toggle w/o default');
|
|
311
|
+
* modalForm.toggle('Toggle w/ default', true);
|
|
312
|
+
*
|
|
313
|
+
* modalForm.slider('Slider w/o default', 0, 50, 5);
|
|
314
|
+
* modalForm.slider('Slider w/ default', 0, 50, 5, 30);
|
|
315
|
+
*
|
|
316
|
+
* modalForm.dropdown('Dropdown w/o default', ['option 1', 'option 2', 'option 3']);
|
|
317
|
+
* modalForm.dropdown('Dropdown w/ default', ['option 1', 'option 2', 'option 3'], 2);
|
|
318
|
+
*
|
|
319
|
+
* modalForm.textField('Input w/o default', 'type text here');
|
|
320
|
+
* modalForm.textField('Input w/ default', 'type text here', 'this is default');
|
|
321
|
+
*
|
|
322
|
+
* modalForm
|
|
323
|
+
* .show(player)
|
|
324
|
+
* .then(formData => {
|
|
325
|
+
* player.sendMessage(`Modal form results: ${JSON.stringify(formData.formValues, undefined, 2)}`);
|
|
326
|
+
* })
|
|
327
|
+
* .catch((error: Error) => {
|
|
328
|
+
* player.sendMessage('Failed to show form: ' + error);
|
|
329
|
+
* return -1;
|
|
330
|
+
* });
|
|
331
|
+
* }
|
|
332
|
+
* ```
|
|
200
333
|
*/
|
|
201
334
|
export class ModalFormData {
|
|
202
335
|
/**
|
|
@@ -260,6 +393,37 @@ export class ModalFormData {
|
|
|
260
393
|
|
|
261
394
|
/**
|
|
262
395
|
* Returns data about player responses to a modal form.
|
|
396
|
+
* @example modalFormSimple.ts
|
|
397
|
+
* ```typescript
|
|
398
|
+
* import { Player } from '@minecraft/server';
|
|
399
|
+
* import { ModalFormData } from '@minecraft/server-ui';
|
|
400
|
+
*
|
|
401
|
+
* function showExampleModal(player: Player) {
|
|
402
|
+
* const modalForm = new ModalFormData().title('Example Modal Controls for §o§7ModalFormData§r');
|
|
403
|
+
*
|
|
404
|
+
* modalForm.toggle('Toggle w/o default');
|
|
405
|
+
* modalForm.toggle('Toggle w/ default', true);
|
|
406
|
+
*
|
|
407
|
+
* modalForm.slider('Slider w/o default', 0, 50, 5);
|
|
408
|
+
* modalForm.slider('Slider w/ default', 0, 50, 5, 30);
|
|
409
|
+
*
|
|
410
|
+
* modalForm.dropdown('Dropdown w/o default', ['option 1', 'option 2', 'option 3']);
|
|
411
|
+
* modalForm.dropdown('Dropdown w/ default', ['option 1', 'option 2', 'option 3'], 2);
|
|
412
|
+
*
|
|
413
|
+
* modalForm.textField('Input w/o default', 'type text here');
|
|
414
|
+
* modalForm.textField('Input w/ default', 'type text here', 'this is default');
|
|
415
|
+
*
|
|
416
|
+
* modalForm
|
|
417
|
+
* .show(player)
|
|
418
|
+
* .then(formData => {
|
|
419
|
+
* player.sendMessage(`Modal form results: ${JSON.stringify(formData.formValues, undefined, 2)}`);
|
|
420
|
+
* })
|
|
421
|
+
* .catch((error: Error) => {
|
|
422
|
+
* player.sendMessage('Failed to show form: ' + error);
|
|
423
|
+
* return -1;
|
|
424
|
+
* });
|
|
425
|
+
* }
|
|
426
|
+
* ```
|
|
263
427
|
*/
|
|
264
428
|
// @ts-ignore Class inheritance allowed for native defined classes
|
|
265
429
|
export class ModalFormResponse extends FormResponse {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minecraft/server-ui",
|
|
3
|
-
"version": "1.2.0-beta.1.20.70-preview.
|
|
3
|
+
"version": "1.2.0-beta.1.20.70-preview.24",
|
|
4
4
|
"description": "",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@minecraft/common": "^1.0.0",
|
|
17
|
-
"@minecraft/server": "^1.8.0
|
|
17
|
+
"@minecraft/server": "^1.8.0"
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT"
|
|
20
20
|
}
|