-
Notifications
You must be signed in to change notification settings - Fork 0
/
DynamicDialog.mjs
60 lines (53 loc) · 2.04 KB
/
DynamicDialog.mjs
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
/* Dialog test script
*/
var DynamicDialog = {};
import {DialogUtils} from 'DialogUtils.mjs';
DynamicDialog.drawUI = function (dialog, state) {
dialog.clear();
dialog.windowTitle = "Dynamic Dialog";
dialog.newRowMode = Dialog.ManualRows;
dialog.addHeading(`A dialog which changes based on user input.`, true);
dialog.addSeparator("Color Mappings");
dialog.addNewRow();
for (var colorIndex = 0; colorIndex < state.colors.length; colorIndex++) {
dialog.addNewRow();
state.colorButtons[colorIndex] = dialog.addColorButton(`Color #${colorIndex}`);
state.colors[colorIndex] = "#ffffff";
state.colorButtons[colorIndex].colorChanged.connect((newColor) => {
tiled.log(`Color button #${colorIndex} value changed to ${newColor}`);
state.colors[colorIndex] = newColor;
});
state.tileInputs[colorIndex] = dialog.addNumberInput(`Tile ID #${colorIndex}`);
state.tileInputs[colorIndex].decimals = 0;
state.tileInputs[colorIndex].valueChanged.connect((newValue) => {
tiled.log(`ID input #${colorIndex} value changed to ${newValue}`);
state.tileIds[colorIndex] = newValue;
});
state.tileIds[colorIndex] = 1;
}
dialog.addNewRow();
state.addColorButton = dialog.addButton("+");
state.addColorButton.toolTip = "Add a new color-ID mapping.";
state.addColorButton.clicked.connect(() => {
state.colors.push("#ffffff");
DynamicDialog.drawUI(dialog, state);
});
dialog.show();
};
DynamicDialog.testPromptAction = tiled.registerAction("DynamicDialog", function (action) {
var state = {
colorButtons: [],
tileInputs: [],
colors: [],
tileIds: [],
addColorButton: undefined,
removeColorButton: undefined
}
var dialog = new Dialog();
DynamicDialog.drawUI(dialog, state);
});
DynamicDialog.testPromptAction.text = "Dynamic Dialog";
tiled.extendMenu("Edit", [
{ action: "DynamicDialog", before: "SelectAll" },
{ separator: true }
]);