1 | /**
|
---|
2 | * Currently limited to at most 3 buttons per message box.
|
---|
3 | * The convention is to have "cancel" appear first.
|
---|
4 | */
|
---|
5 | function init(data)
|
---|
6 | {
|
---|
7 | // Set title
|
---|
8 | Engine.GetGUIObjectByName("mbTitleBar").caption = data.title;
|
---|
9 |
|
---|
10 | // Set subject
|
---|
11 | let mbTextObj = Engine.GetGUIObjectByName("mbText");
|
---|
12 | mbTextObj.caption = data.message;
|
---|
13 | if (data.font)
|
---|
14 | mbTextObj.font = data.font;
|
---|
15 |
|
---|
16 | // Default behaviour
|
---|
17 | let mbCancelHotkey = Engine.GetGUIObjectByName("mbCancelHotkey");
|
---|
18 | mbCancelHotkey.onPress = Engine.PopGuiPage;
|
---|
19 |
|
---|
20 | // Calculate size
|
---|
21 | let mbLRDiff = data.width / 2;
|
---|
22 | let mbUDDiff = data.height / 2;
|
---|
23 | Engine.GetGUIObjectByName("mbMain").size = "50%-" + mbLRDiff + " 50%-" + mbUDDiff + " 50%+" + mbLRDiff + " 50%+" + mbUDDiff;
|
---|
24 |
|
---|
25 | let captions = data.buttonCaptions || [translate("OK")];
|
---|
26 |
|
---|
27 | // Set button captions and visibility
|
---|
28 | let mbButton = [];
|
---|
29 | captions.forEach((caption, i) => {
|
---|
30 | mbButton[i] = Engine.GetGUIObjectByName("mbButton" + (i + 1));
|
---|
31 | mbButton[i].caption = caption;
|
---|
32 | mbButton[i].hidden = false;
|
---|
33 | mbButton[i].onPress = () => {
|
---|
34 | Engine.PopGuiPage(i);
|
---|
35 | };
|
---|
36 |
|
---|
37 | // Convention: Cancel is the first button
|
---|
38 | if (i == 0)
|
---|
39 | mbCancelHotkey.onPress = mbButton[i].onPress;
|
---|
40 | });
|
---|
41 |
|
---|
42 | // Distribute buttons horizontally
|
---|
43 | let y1 = "100%-46";
|
---|
44 | let y2 = "100%-18";
|
---|
45 | switch (captions.length)
|
---|
46 | {
|
---|
47 | case 1:
|
---|
48 | mbButton[0].size = "18 " + y1 + " 100%-18 " + y2;
|
---|
49 | break;
|
---|
50 | case 2:
|
---|
51 | mbButton[0].size = "18 " + y1 + " 50%-5 " + y2;
|
---|
52 | mbButton[1].size = "50%+5 " + y1 + " 100%-18 " + y2;
|
---|
53 | break;
|
---|
54 | case 3:
|
---|
55 | mbButton[0].size = "18 " + y1 + " 33%-5 " + y2;
|
---|
56 | mbButton[1].size = "33%+5 " + y1 + " 66%-5 " + y2;
|
---|
57 | mbButton[2].size = "66%+5 " + y1 + " 100%-18 " + y2;
|
---|
58 | break;
|
---|
59 | }
|
---|
60 | }
|
---|