@minecraft/server-ui 2.1.0-beta.1.26.2-stable → 2.1.0-beta.1.26.20-preview.20

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.
Files changed (3) hide show
  1. package/README.md +16 -16
  2. package/index.d.ts +524 -1
  3. package/package.json +19 -19
package/README.md CHANGED
@@ -1,17 +1,17 @@
1
- # `@minecraft/server-ui`
2
-
3
- The `@minecraft/server-ui` module contains types for expressing simple dialog-based user experiences.
4
-
5
-
6
-
7
- * [*@minecraft/server-ui.ActionFormData*](../../../scriptapi/minecraft/server-ui/ActionFormData.md) contain a list of buttons with captions and images that can be used for presenting a set of options to a player.
8
-
9
- * [*@minecraft/server-ui.MessageFormData*](../../../scriptapi/minecraft/server-ui/MessageFormData.md) are simple two-button message experiences that are functional for Yes/No or OK/Cancel questions.
10
-
11
- * [*@minecraft/server-ui.ModalFormData*](../../../scriptapi/minecraft/server-ui/ModalFormData.md) allow for a more flexible "questionnaire-style" list of controls that can be used to take input.
12
-
13
- ## **NOTE: This version of this module is still in pre-release. It may change or it may be removed in future releases.**
14
-
15
- See full documentation for this module here:
16
-
1
+ # `@minecraft/server-ui`
2
+
3
+ The `@minecraft/server-ui` module contains types for expressing simple dialog-based user experiences.
4
+
5
+
6
+
7
+ * [*@minecraft/server-ui.ActionFormData*](../../../scriptapi/minecraft/server-ui/ActionFormData.md) contain a list of buttons with captions and images that can be used for presenting a set of options to a player.
8
+
9
+ * [*@minecraft/server-ui.MessageFormData*](../../../scriptapi/minecraft/server-ui/MessageFormData.md) are simple two-button message experiences that are functional for Yes/No or OK/Cancel questions.
10
+
11
+ * [*@minecraft/server-ui.ModalFormData*](../../../scriptapi/minecraft/server-ui/ModalFormData.md) allow for a more flexible "questionnaire-style" list of controls that can be used to take input.
12
+
13
+ ## **NOTE: This version of this module is still in pre-release. It may change or it may be removed in future releases.**
14
+
15
+ See full documentation for this module here:
16
+
17
17
  https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server-ui/minecraft-server-ui
package/index.d.ts CHANGED
@@ -238,6 +238,146 @@ export class ActionFormResponse extends FormResponse {
238
238
  readonly selection?: number;
239
239
  }
240
240
 
241
+ /**
242
+ * @beta
243
+ * A customizable form that lets you put buttons, labels,
244
+ * toggles, dropdowns, sliders, and more into a form! Built on
245
+ * top of Observable, the form will update when the
246
+ * Observables' value changes.
247
+ */
248
+ export declare class CustomForm {
249
+ /**
250
+ * @remarks
251
+ * Inserts a button into the Custom form. onClick is called
252
+ * when the button is pressed.
253
+ *
254
+ */
255
+ button(
256
+ label: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
257
+ onClick: () => void,
258
+ options?: ButtonOptions,
259
+ ): CustomForm;
260
+ /**
261
+ * @remarks
262
+ * Tell the client to close the form. Throws an error if the
263
+ * form is not open.
264
+ *
265
+ */
266
+ close(): void;
267
+ /**
268
+ * @remarks
269
+ * Adds a close "X" button to the form.
270
+ *
271
+ */
272
+ closeButton(): CustomForm;
273
+ /**
274
+ * @remarks
275
+ * Inserts a divider (i.e. a line) into the Custom form.
276
+ *
277
+ */
278
+ divider(options?: DividerOptions): CustomForm;
279
+ /**
280
+ * @remarks
281
+ * Inserts a dropdown into the Custom form with the provided
282
+ * items. The value is based on the items value that selected.
283
+ *
284
+ */
285
+ dropdown(
286
+ label: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
287
+ value: Observable<number>,
288
+ items: DropdownItem[],
289
+ options?: DropdownOptions,
290
+ ): CustomForm;
291
+ /**
292
+ * @remarks
293
+ * Inserts a header (i.e. large sized text) into the Custom
294
+ * form.
295
+ *
296
+ */
297
+ header(
298
+ text: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
299
+ options?: TextOptions,
300
+ ): CustomForm;
301
+ /**
302
+ * @remarks
303
+ * Returns true if the form is currently being shown to the
304
+ * player.
305
+ *
306
+ */
307
+ isShowing(): boolean;
308
+ /**
309
+ * @remarks
310
+ * Inserts a label (i.e. medium sized text) into the Custom
311
+ * form.
312
+ *
313
+ */
314
+ label(
315
+ text: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
316
+ options?: TextOptions,
317
+ ): CustomForm;
318
+ /**
319
+ * @remarks
320
+ * Shows the form to the player. Will return false if the
321
+ * client was busy (i.e. in another menu or this one is open).
322
+ * Will throw if the user disconnects.
323
+ *
324
+ * @throws
325
+ * *
326
+ */
327
+ show(): Promise<boolean>;
328
+ /**
329
+ * @remarks
330
+ * Creates a slider that lets players pick a number between
331
+ * minValue and maxValue. value must be client writable.
332
+ *
333
+ */
334
+ slider(
335
+ label: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
336
+ value: Observable<number>,
337
+ minValue: Observable<number> | number,
338
+ maxValue: Observable<number> | number,
339
+ options?: SliderOptions,
340
+ ): CustomForm;
341
+ /**
342
+ * @remarks
343
+ * Inserts a space into the Custom form.
344
+ *
345
+ */
346
+ spacer(options?: SpacingOptions): CustomForm;
347
+ /**
348
+ * @remarks
349
+ * Inserts a text field into the Custom for that players can
350
+ * enter text into.
351
+ *
352
+ */
353
+ textField(
354
+ label: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
355
+ text: Observable<string>,
356
+ options?: TextFieldOptions,
357
+ ): CustomForm;
358
+ /**
359
+ * @remarks
360
+ * Inserts an on/off toggle that players can interact with into
361
+ * the Custom form.
362
+ *
363
+ */
364
+ toggle(
365
+ label: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
366
+ toggled: Observable<boolean>,
367
+ options?: ToggleOptions,
368
+ ): CustomForm;
369
+ /**
370
+ * @remarks
371
+ * Creates a Custom form to show to the player. Use this
372
+ * instead of a constructor.
373
+ *
374
+ */
375
+ static create(
376
+ player: minecraftserver.Player,
377
+ title: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
378
+ ): CustomForm;
379
+ }
380
+
241
381
  /**
242
382
  * Base type for a form response.
243
383
  */
@@ -258,6 +398,71 @@ export class FormResponse {
258
398
  readonly canceled: boolean;
259
399
  }
260
400
 
401
+ /**
402
+ * @beta
403
+ * A simple message form UI, 2 buttons and a text body.
404
+ */
405
+ export declare class MessageBox {
406
+ /**
407
+ * @remarks
408
+ * Sets the data for the text in the body of the message box.
409
+ * It is contained within a scroll view to allow for lots of
410
+ * text.
411
+ *
412
+ */
413
+ body(text: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage): MessageBox;
414
+ /**
415
+ * @remarks
416
+ * Sets the data for the top button in the message box.
417
+ *
418
+ */
419
+ button1(
420
+ label: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
421
+ tooltip?: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
422
+ ): MessageBox;
423
+ /**
424
+ * @remarks
425
+ * Sets the data for the bottom button in the message box.
426
+ *
427
+ */
428
+ button2(
429
+ label: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
430
+ tooltip?: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
431
+ ): MessageBox;
432
+ /**
433
+ * @remarks
434
+ * Tell the client to close the message box. Throws {@link
435
+ * FormCloseError} if the message box is not open.
436
+ *
437
+ */
438
+ close(): void;
439
+ /**
440
+ * @remarks
441
+ * Returns true if the message box is currently being shown to
442
+ * the player.
443
+ *
444
+ */
445
+ isShowing(): boolean;
446
+ /**
447
+ * @remarks
448
+ * Show this message box to the player. Will return a result
449
+ * even if the client was busy (i.e. in another menu). Will
450
+ * throw if the user disconnects.
451
+ *
452
+ */
453
+ show(): Promise<MessageBoxResult>;
454
+ /**
455
+ * @remarks
456
+ * Creates a message box for a certain player. Use this instead
457
+ * of a constructor.
458
+ *
459
+ */
460
+ static create(
461
+ player: minecraftserver.Player,
462
+ title: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage,
463
+ ): MessageBox;
464
+ }
465
+
261
466
  /**
262
467
  * Builds a simple two-button modal dialog.
263
468
  * @example showBasicMessageForm.ts
@@ -653,6 +858,52 @@ export class ModalFormResponse extends FormResponse {
653
858
  readonly formValues?: (boolean | number | string | undefined)[];
654
859
  }
655
860
 
861
+ /**
862
+ * @beta
863
+ * A class that represents data that can be Observed.
864
+ * Extensively used for UI.
865
+ */
866
+ export declare class Observable<T extends string | number | boolean | UIRawMessage> {
867
+ /**
868
+ * @remarks
869
+ * Gets the data from the Observable.
870
+ *
871
+ */
872
+ getData(): T;
873
+ /**
874
+ * @remarks
875
+ * Sets the data on this Observable and notifies the
876
+ * subscribers.
877
+ *
878
+ */
879
+ setData(data: T): void;
880
+ /**
881
+ * @remarks
882
+ * Subscribes a callback to any changes that occur to the
883
+ * Observable. The return value can be passed into the
884
+ * `unsubscribe` function to stop listening to changes.
885
+ *
886
+ */
887
+ subscribe(listener: (newValue: T) => void): (newValue: T) => void;
888
+ /**
889
+ * @remarks
890
+ * Unsubscribe a callback from any changes that occur to the
891
+ * Observable. This takes the return value from the `subscribe`
892
+ * function.
893
+ *
894
+ */
895
+ unsubscribe(listener: (newValue: T) => void): void;
896
+ /**
897
+ * @remarks
898
+ * Creates an Observable, use this instead of a constructor.
899
+ *
900
+ */
901
+ static create<T extends string | number | boolean | UIRawMessage>(
902
+ data: T,
903
+ options?: ObservableOptions,
904
+ ): Observable<T>;
905
+ }
906
+
656
907
  export class UIManager {
657
908
  private constructor();
658
909
  /**
@@ -664,6 +915,116 @@ export class UIManager {
664
915
  closeAllForms(player: minecraftserver.Player): void;
665
916
  }
666
917
 
918
+ /**
919
+ * @beta
920
+ * The options for including a button in {@link CustomForm}.
921
+ */
922
+ export interface ButtonOptions {
923
+ /**
924
+ * @remarks
925
+ * Whether or not this button is disabled.
926
+ *
927
+ */
928
+ disabled?: Observable<boolean> | boolean;
929
+ /**
930
+ * @remarks
931
+ * The tooltip for this button, shown when hovering the button.
932
+ *
933
+ */
934
+ tooltip?: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage;
935
+ /**
936
+ * @remarks
937
+ * Whether or not this button is visible.
938
+ *
939
+ */
940
+ visible?: Observable<boolean> | boolean;
941
+ }
942
+
943
+ /**
944
+ * @beta
945
+ * The options for including a spacer in {@link CustomForm}.
946
+ */
947
+ export interface DividerOptions {
948
+ /**
949
+ * @remarks
950
+ * Whether or not this divider is visible
951
+ *
952
+ */
953
+ visible?: Observable<boolean> | boolean;
954
+ }
955
+
956
+ /**
957
+ * @beta
958
+ * Dropdown data for use in {@link CustomForm}.
959
+ */
960
+ export interface DropdownItem {
961
+ /**
962
+ * @remarks
963
+ * The description of the dropdown item shown when it is
964
+ * selected.
965
+ *
966
+ */
967
+ description?: UIRawMessage | string;
968
+ /**
969
+ * @remarks
970
+ * The label of the dropdown item in the dropdown.
971
+ *
972
+ */
973
+ label: UIRawMessage | string;
974
+ /**
975
+ * @remarks
976
+ * The value the dropdown will be set to when this item is
977
+ * selected.
978
+ *
979
+ */
980
+ value: number;
981
+ }
982
+
983
+ /**
984
+ * @beta
985
+ * The options for including a dropdown in {@link CustomForm}.
986
+ */
987
+ export interface DropdownOptions {
988
+ /**
989
+ * @remarks
990
+ * The description of the dropdown, shown in the UI.
991
+ *
992
+ */
993
+ description?: Observable<string> | string | UIRawMessage;
994
+ /**
995
+ * @remarks
996
+ * Whether or not this dropdown is disabled.
997
+ *
998
+ */
999
+ disabled?: Observable<boolean> | boolean;
1000
+ /**
1001
+ * @remarks
1002
+ * Whether or not this dropdown is visible.
1003
+ *
1004
+ */
1005
+ visible?: Observable<boolean> | boolean;
1006
+ }
1007
+
1008
+ /**
1009
+ * @beta
1010
+ * The result when a {@link MessageBox} is closed.
1011
+ */
1012
+ export interface MessageBoxResult {
1013
+ /**
1014
+ * @remarks
1015
+ * The button that was selected, undefined if it was closed
1016
+ * without pressing a button.
1017
+ *
1018
+ */
1019
+ selection?: number;
1020
+ /**
1021
+ * @remarks
1022
+ * Whether the message box was shown
1023
+ *
1024
+ */
1025
+ wasShown: boolean;
1026
+ }
1027
+
667
1028
  /**
668
1029
  * An interface that is passed into {@link
669
1030
  * @minecraft/Server-ui.ModalFormData.dropdown} to provide
@@ -756,6 +1117,168 @@ export interface ModalFormDataToggleOptions {
756
1117
  tooltip?: minecraftserver.RawMessage | string;
757
1118
  }
758
1119
 
1120
+ /**
1121
+ * @beta
1122
+ * An interface passed into `Observable.create`.
1123
+ */
1124
+ export interface ObservableOptions {
1125
+ /**
1126
+ * @remarks
1127
+ * If set to true, the client can update this value. This
1128
+ * should be used for things like dropdown values, toggles,
1129
+ * textfields, etc. If unset or false, the client cannot write
1130
+ * to this observable.
1131
+ *
1132
+ */
1133
+ clientWritable?: boolean;
1134
+ }
1135
+
1136
+ /**
1137
+ * @beta
1138
+ * The options for including a slider in {@link CustomForm}.
1139
+ */
1140
+ export interface SliderOptions {
1141
+ /**
1142
+ * @remarks
1143
+ * The description of the slider, shown in the UI.
1144
+ *
1145
+ */
1146
+ description?: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage;
1147
+ /**
1148
+ * @remarks
1149
+ * Whether or not this slider is disabled.
1150
+ *
1151
+ */
1152
+ disabled?: Observable<boolean> | boolean;
1153
+ /**
1154
+ * @remarks
1155
+ * The step size of the slider. For example, if this is 2 and
1156
+ * the min is 0 and the max is 10, the only selectable values
1157
+ * will be 0, 2, 4, 6, 8, 10.
1158
+ *
1159
+ */
1160
+ step?: Observable<number> | number;
1161
+ /**
1162
+ * @remarks
1163
+ * Whether or not this slider is visible.
1164
+ *
1165
+ */
1166
+ visible?: Observable<boolean> | boolean;
1167
+ }
1168
+
1169
+ /**
1170
+ * @beta
1171
+ * The options for including a spacer in {@link CustomForm}.
1172
+ */
1173
+ export interface SpacingOptions {
1174
+ /**
1175
+ * @remarks
1176
+ * Whether or not this spacer is visible
1177
+ *
1178
+ */
1179
+ visible?: Observable<boolean> | boolean;
1180
+ }
1181
+
1182
+ /**
1183
+ * @beta
1184
+ * The options for including a textfield in {@link CustomForm}.
1185
+ */
1186
+ export interface TextFieldOptions {
1187
+ /**
1188
+ * @remarks
1189
+ * The description for this text field, shown in the UI.
1190
+ *
1191
+ */
1192
+ description?: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage;
1193
+ /**
1194
+ * @remarks
1195
+ * Whether or not this text field is disabled.
1196
+ *
1197
+ */
1198
+ disabled?: Observable<boolean> | boolean;
1199
+ /**
1200
+ * @remarks
1201
+ * Whether or not this text field is visible.
1202
+ *
1203
+ */
1204
+ visible?: Observable<boolean> | boolean;
1205
+ }
1206
+
1207
+ /**
1208
+ * @beta
1209
+ * The options for including a label or header in {@link
1210
+ * CustomForm}.
1211
+ */
1212
+ export interface TextOptions {
1213
+ /**
1214
+ * @remarks
1215
+ * Whether or not this label is visible
1216
+ *
1217
+ */
1218
+ visible?: Observable<boolean> | boolean;
1219
+ }
1220
+
1221
+ /**
1222
+ * @beta
1223
+ * The options for including a toggle in {@link CustomForm}.
1224
+ */
1225
+ export interface ToggleOptions {
1226
+ /**
1227
+ * @remarks
1228
+ * The description for this toggle, shown in the UI.
1229
+ *
1230
+ */
1231
+ description?: Observable<string> | Observable<UIRawMessage> | string | UIRawMessage;
1232
+ /**
1233
+ * @remarks
1234
+ * Whether or not this toggle is disabled.
1235
+ *
1236
+ */
1237
+ disabled?: Observable<boolean> | boolean;
1238
+ /**
1239
+ * @remarks
1240
+ * Whether or not this toggle is visible.
1241
+ *
1242
+ */
1243
+ visible?: Observable<boolean> | boolean;
1244
+ }
1245
+
1246
+ /**
1247
+ * @beta
1248
+ * A message that can be sent to the client. This is a subset
1249
+ * of the RawMessage type, and is used for UI messages.
1250
+ */
1251
+ export interface UIRawMessage {
1252
+ /**
1253
+ * @remarks
1254
+ * Provides a raw-text equivalent of the current message.
1255
+ *
1256
+ */
1257
+ rawtext?: UIRawMessage[];
1258
+ /**
1259
+ * @remarks
1260
+ * Provides a string literal value to use.
1261
+ *
1262
+ */
1263
+ text?: string;
1264
+ /**
1265
+ * @remarks
1266
+ * Provides a translation token where, if the client has an
1267
+ * available resource in the players' language which matches
1268
+ * the token, will get translated on the client.
1269
+ *
1270
+ */
1271
+ translate?: string;
1272
+ /**
1273
+ * @remarks
1274
+ * Arguments for the translation token. Can be either an array
1275
+ * of strings or UIRawMessage containing an array of raw text
1276
+ * objects.
1277
+ *
1278
+ */
1279
+ with?: string[] | UIRawMessage;
1280
+ }
1281
+
759
1282
  // @ts-ignore Class inheritance allowed for native defined classes
760
1283
  export class FormRejectError extends Error {
761
1284
  private constructor();
@@ -764,7 +1287,7 @@ export class FormRejectError extends Error {
764
1287
  * This property can be read in early-execution mode.
765
1288
  *
766
1289
  */
767
- reason: FormRejectReason;
1290
+ readonly reason: FormRejectReason;
768
1291
  }
769
1292
 
770
1293
  export const uiManager: UIManager;
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
- {
2
- "name": "@minecraft/server-ui",
3
- "version": "2.1.0-beta.1.26.2-stable",
4
- "description": "",
5
- "contributors": [
6
- {
7
- "name": "Jake Shirley",
8
- "email": "jake@xbox.com"
9
- },
10
- {
11
- "name": "Mike Ammerlaan",
12
- "email": "mikeam@microsoft.com"
13
- }
14
- ],
15
- "peerDependencies": {
16
- "@minecraft/common": "^1.0.0",
17
- "@minecraft/server": "^2.0.0 || ^2.6.0-beta.1.26.2-stable"
18
- },
19
- "license": "MIT"
1
+ {
2
+ "name": "@minecraft/server-ui",
3
+ "version": "2.1.0-beta.1.26.20-preview.20",
4
+ "description": "",
5
+ "contributors": [
6
+ {
7
+ "name": "Jake Shirley",
8
+ "email": "jake@xbox.com"
9
+ },
10
+ {
11
+ "name": "Mike Ammerlaan",
12
+ "email": "mikeam@microsoft.com"
13
+ }
14
+ ],
15
+ "peerDependencies": {
16
+ "@minecraft/common": "^1.0.0",
17
+ "@minecraft/server": "^2.0.0 || ^2.8.0-beta.1.26.20-preview.20"
18
+ },
19
+ "license": "MIT"
20
20
  }