forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModalForm.js
More file actions
88 lines (88 loc) · 2.68 KB
/
ModalForm.js
File metadata and controls
88 lines (88 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { ModalFormData } from "@minecraft/server-ui";
export class ModalFormDropdown {
constructor(label, options, defaultValueIndex) {
this.label = label;
this.options = options;
this.defaultValueIndex = defaultValueIndex;
}
;
}
;
export class ModalFormSlider {
constructor(label, minimumValue, maximumValue, valueStep, defaultValue) {
this.label = label;
this.minimumValue = minimumValue;
this.maximumValue = maximumValue;
this.valueStep = valueStep;
this.defaultValue = defaultValue;
}
;
}
;
export class ModalFormTextField {
constructor(label, placeholderText, defaultValue) {
this.label = label;
this.placeholderText = placeholderText;
this.defaultValue = defaultValue;
}
;
}
;
export class ModalFormToggle {
constructor(label, defaultValue) {
this.label = label;
this.defaultValue = defaultValue;
}
;
}
;
/**
* Used to create a fully customizable pop-up form for a
* player.
*/
export class ModalFormBuilder {
constructor() {
/**
* Content of the pop-up form.
*/
this.content = [];
}
dropdown(label, options, defaultValueIndex) {
this.content.push(new ModalFormDropdown(label, options, defaultValueIndex));
return this;
}
show(player) {
const form = new ModalFormData();
if (!!this.titleText)
form.title(this.titleText);
for (const item of this.content) {
if (item instanceof ModalFormDropdown)
form.dropdown(item.label, item.options, item.defaultValueIndex);
else if (item instanceof ModalFormSlider)
form.slider(item.label, item.minimumValue, item.maximumValue, item.valueStep, item.defaultValue);
else if (item instanceof ModalFormTextField)
form.textField(item.label, item.placeholderText, item.defaultValue);
else if (item instanceof ModalFormToggle)
form.toggle(item.label, item.defaultValue);
}
;
return form.show(player);
}
slider(label, minimumValue, maximumValue, valueStep = 1, defaultValue) {
this.content.push(new ModalFormSlider(label, minimumValue, maximumValue, valueStep, defaultValue));
return this;
}
textField(label, placeholderText, defaultValue) {
this.content.push(new ModalFormTextField(label, placeholderText, defaultValue));
return this;
}
title(titleText) {
this.titleText = titleText;
return this;
}
toggle(label, defaultValue) {
this.content.push(new ModalFormToggle(label, defaultValue));
return this;
}
}
;