|
| 1 | +// Script example for ScriptAPI |
| 2 | +// Author: Jayly#1397 <Jayly Discord> |
| 3 | +// Project: https://github.com/JaylyDev/ScriptAPI |
| 4 | + |
| 5 | +// Type definitions for Minecraft Bedrock Edition script APIs |
| 6 | +// Project: https://docs.microsoft.com/minecraft/creator/ |
| 7 | +// Definitions by: Jake Shirley <https://github.com/JakeShirley> |
| 8 | +// Mike Ammerlaan <https://github.com/mammerla> |
| 9 | + |
| 10 | +/* ***************************************************************************** |
| 11 | + Copyright (c) Microsoft Corporation. |
| 12 | + ***************************************************************************** */ |
| 13 | +/** |
| 14 | + * @beta |
| 15 | + * @packageDocumentation |
| 16 | + * The `@minecraft/server-ui` module contains types for |
| 17 | + * expressing simple dialog-based user experiences. |
| 18 | + * |
| 19 | + * * {@link ActionFormData} contain a list of buttons with |
| 20 | + * captions and images that can be used for presenting a set of |
| 21 | + * options to a player. |
| 22 | + * * {@link MessageFormData} are simple two-button message |
| 23 | + * experiences that are functional for Yes/No or OK/Cancel |
| 24 | + * questions. |
| 25 | + * * {@link ModalFormData} allow for a more flexible |
| 26 | + * "questionnaire-style" list of controls that can be used to |
| 27 | + * take input. |
| 28 | + * @example createActionForm.js |
| 29 | + * ```typescript |
| 30 | + * const form = new ActionFormData() |
| 31 | + * .title("Months") |
| 32 | + * .body("Choose your favorite month!") |
| 33 | + * .button("January") |
| 34 | + * .button("February") |
| 35 | + * .button("March") |
| 36 | + * .button("April") |
| 37 | + * .button("May"); |
| 38 | + * |
| 39 | + * form.show(players[0]).then((response) => { |
| 40 | + * if (response.selection === 3) { |
| 41 | + * dimension.runCommand("say I like April too!"); |
| 42 | + * } |
| 43 | + * }); |
| 44 | + * |
| 45 | + * ``` |
| 46 | + * |
| 47 | + * Manifest Details |
| 48 | + * ```json |
| 49 | + * { |
| 50 | + * "module_name": "@minecraft/server-ui", |
| 51 | + * "version": "0.1.0" |
| 52 | + * } |
| 53 | + * ``` |
| 54 | + * |
| 55 | + */ |
| 56 | +import * as minecraftserver from '@minecraft/server'; |
| 57 | +export enum FormCancelationReason { |
| 58 | + userBusy = 'userBusy', |
| 59 | + userClosed = 'userClosed', |
| 60 | +} |
| 61 | +/** |
| 62 | + * Builds a simple player form with buttons that let the player |
| 63 | + * take action. |
| 64 | + */ |
| 65 | +export class ActionFormData { |
| 66 | + /** |
| 67 | + * @remarks |
| 68 | + * Method that sets the body text for the modal form. |
| 69 | + * @param bodyText |
| 70 | + */ |
| 71 | + body(bodyText: string): ActionFormData; |
| 72 | + /** |
| 73 | + * @remarks |
| 74 | + * Adds a button to this form with an icon from a resource |
| 75 | + * pack. |
| 76 | + * @param text |
| 77 | + * @param iconPath |
| 78 | + */ |
| 79 | + button(text: string, iconPath?: string): ActionFormData; |
| 80 | + /** |
| 81 | + * @remarks |
| 82 | + * Creates and shows this modal popup form. Returns |
| 83 | + * asynchronously when the player confirms or cancels the |
| 84 | + * dialog. |
| 85 | + * @param player |
| 86 | + * Player to show this dialog to. |
| 87 | + * @throws This function can throw errors. |
| 88 | + */ |
| 89 | + show(player: minecraftserver.Player): Promise<ActionFormResponse>; |
| 90 | + /** |
| 91 | + * @remarks |
| 92 | + * This builder method sets the title for the modal dialog. |
| 93 | + * @param titleText |
| 94 | + */ |
| 95 | + title(titleText: string): ActionFormData; |
| 96 | +} |
| 97 | +/** |
| 98 | + * Returns data about the player results from a modal action |
| 99 | + * form. |
| 100 | + */ |
| 101 | +export class ActionFormResponse extends FormResponse { |
| 102 | + protected constructor(); |
| 103 | + /** |
| 104 | + * Contains additional details as to why a form was canceled. |
| 105 | + */ |
| 106 | + readonly cancelationReason?: FormCancelationReason; |
| 107 | + /** |
| 108 | + * If true, the form was canceled by the player (e.g., they |
| 109 | + * selected the pop-up X close button). |
| 110 | + */ |
| 111 | + readonly canceled: boolean; |
| 112 | + /** |
| 113 | + * Returns the index of the button that was pushed. |
| 114 | + */ |
| 115 | + readonly selection?: number; |
| 116 | +} |
| 117 | +/** |
| 118 | + * Base type for a form response. |
| 119 | + */ |
| 120 | +export class FormResponse { |
| 121 | + protected constructor(); |
| 122 | + /** |
| 123 | + * Contains additional details as to why a form was canceled. |
| 124 | + */ |
| 125 | + readonly cancelationReason?: FormCancelationReason; |
| 126 | + /** |
| 127 | + * If true, the form was canceled by the player (e.g., they |
| 128 | + * selected the pop-up X close button). |
| 129 | + */ |
| 130 | + readonly canceled: boolean; |
| 131 | +} |
| 132 | +/** |
| 133 | + * Builds a simple two-button modal dialog. |
| 134 | + */ |
| 135 | +export class MessageFormData { |
| 136 | + /** |
| 137 | + * @remarks |
| 138 | + * Method that sets the body text for the modal form. |
| 139 | + * @param bodyText |
| 140 | + */ |
| 141 | + body(bodyText: string): MessageFormData; |
| 142 | + /** |
| 143 | + * @remarks |
| 144 | + * Method that sets the text for the first button of the |
| 145 | + * dialog. |
| 146 | + * @param text |
| 147 | + */ |
| 148 | + button1(text: string): MessageFormData; |
| 149 | + /** |
| 150 | + * @remarks |
| 151 | + * This method sets the text for the second button on the |
| 152 | + * dialog. |
| 153 | + * @param text |
| 154 | + */ |
| 155 | + button2(text: string): MessageFormData; |
| 156 | + /** |
| 157 | + * @remarks |
| 158 | + * Creates and shows this modal popup form. Returns |
| 159 | + * asynchronously when the player confirms or cancels the |
| 160 | + * dialog. |
| 161 | + * @param player |
| 162 | + * Player to show this dialog to. |
| 163 | + * @throws This function can throw errors. |
| 164 | + */ |
| 165 | + show(player: minecraftserver.Player): Promise<MessageFormResponse>; |
| 166 | + /** |
| 167 | + * @remarks |
| 168 | + * This builder method sets the title for the modal dialog. |
| 169 | + * @param titleText |
| 170 | + */ |
| 171 | + title(titleText: string): MessageFormData; |
| 172 | +} |
| 173 | +/** |
| 174 | + * Returns data about the player results from a modal message |
| 175 | + * form. |
| 176 | + */ |
| 177 | +export class MessageFormResponse extends FormResponse { |
| 178 | + protected constructor(); |
| 179 | + /** |
| 180 | + * Contains additional details as to why a form was canceled. |
| 181 | + */ |
| 182 | + readonly cancelationReason?: FormCancelationReason; |
| 183 | + /** |
| 184 | + * If true, the form was canceled by the player (e.g., they |
| 185 | + * selected the pop-up X close button). |
| 186 | + */ |
| 187 | + readonly canceled: boolean; |
| 188 | + /** |
| 189 | + * Returns the index of the button that was pushed. |
| 190 | + */ |
| 191 | + readonly selection?: number; |
| 192 | +} |
| 193 | +/** |
| 194 | + * Used to create a fully customizable pop-up form for a |
| 195 | + * player. |
| 196 | + */ |
| 197 | +export class ModalFormData { |
| 198 | + /** |
| 199 | + * @remarks |
| 200 | + * Adds a dropdown with choices to the form. |
| 201 | + * @param label |
| 202 | + * @param options |
| 203 | + * @param defaultValueIndex |
| 204 | + */ |
| 205 | + dropdown(label: string, options: string[], defaultValueIndex?: number): ModalFormData; |
| 206 | + /** |
| 207 | + * @remarks |
| 208 | + * Creates and shows this modal popup form. Returns |
| 209 | + * asynchronously when the player confirms or cancels the |
| 210 | + * dialog. |
| 211 | + * @param player |
| 212 | + * Player to show this dialog to. |
| 213 | + * @throws This function can throw errors. |
| 214 | + */ |
| 215 | + show(player: minecraftserver.Player): Promise<ModalFormResponse>; |
| 216 | + /** |
| 217 | + * @remarks |
| 218 | + * Adds a numeric slider to the form. |
| 219 | + * @param label |
| 220 | + * @param minimumValue |
| 221 | + * @param maximumValue |
| 222 | + * @param valueStep |
| 223 | + * @param defaultValue |
| 224 | + */ |
| 225 | + slider( |
| 226 | + label: string, |
| 227 | + minimumValue: number, |
| 228 | + maximumValue: number, |
| 229 | + valueStep: number, |
| 230 | + defaultValue?: number, |
| 231 | + ): ModalFormData; |
| 232 | + /** |
| 233 | + * @remarks |
| 234 | + * Adds a textbox to the form. |
| 235 | + * @param label |
| 236 | + * @param placeholderText |
| 237 | + * @param defaultValue |
| 238 | + */ |
| 239 | + textField(label: string, placeholderText: string, defaultValue?: string): ModalFormData; |
| 240 | + /** |
| 241 | + * @remarks |
| 242 | + * This builder method sets the title for the modal dialog. |
| 243 | + * @param titleText |
| 244 | + */ |
| 245 | + title(titleText: string): ModalFormData; |
| 246 | + /** |
| 247 | + * @remarks |
| 248 | + * Adds a toggle checkbox button to the form. |
| 249 | + * @param label |
| 250 | + * @param defaultValue |
| 251 | + */ |
| 252 | + toggle(label: string, defaultValue?: boolean): ModalFormData; |
| 253 | +} |
| 254 | +/** |
| 255 | + * Returns data about player responses to a modal form. |
| 256 | + */ |
| 257 | +export class ModalFormResponse extends FormResponse { |
| 258 | + protected constructor(); |
| 259 | + /** |
| 260 | + * Contains additional details as to why a form was canceled. |
| 261 | + */ |
| 262 | + readonly cancelationReason?: FormCancelationReason; |
| 263 | + /** |
| 264 | + * If true, the form was canceled by the player (e.g., they |
| 265 | + * selected the pop-up X close button). |
| 266 | + */ |
| 267 | + readonly canceled: boolean; |
| 268 | + /** |
| 269 | + * An ordered set of values based on the order of controls |
| 270 | + * specified by ModalFormData. |
| 271 | + */ |
| 272 | + readonly formValues?: any[]; |
| 273 | +} |
0 commit comments