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 | Engine.GetGUIObjectByName("tmcTitleBar").caption = data.title;
|
---|
8 |
|
---|
9 | const textObj = Engine.GetGUIObjectByName("tmcText");
|
---|
10 | textObj.caption = data.message;
|
---|
11 |
|
---|
12 | updateDisplayedTimer(data.timeout);
|
---|
13 |
|
---|
14 | Engine.GetGUIObjectByName("tmcTimer").caption = data.timeout;
|
---|
15 | if (data.font)
|
---|
16 | textObj.font = data.font;
|
---|
17 |
|
---|
18 | const cancelHotkey = Engine.GetGUIObjectByName("tmcCancelHotkey");
|
---|
19 | cancelHotkey.onPress = Engine.PopGuiPage;
|
---|
20 |
|
---|
21 | const lRDiff = data.width / 2;
|
---|
22 | const uDDiff = data.height / 2;
|
---|
23 | Engine.GetGUIObjectByName("tmcMain").size = "50%-" + lRDiff + " 50%-" + uDDiff + " 50%+" + lRDiff + " 50%+" + uDDiff;
|
---|
24 |
|
---|
25 | const captions = data.buttonCaptions || [translate("OK")];
|
---|
26 |
|
---|
27 | // Set button captions and visibility
|
---|
28 | const button = [];
|
---|
29 | setButtonCaptionsAndVisibitily(button, captions, cancelHotkey, "tmcButton");
|
---|
30 | distributeButtonsHorizontally(button, captions);
|
---|
31 | }
|
---|
32 |
|
---|
33 | function onTick()
|
---|
34 | {
|
---|
35 | const timerObj = Engine.GetGUIObjectByName("tmcTimer");
|
---|
36 | let time = +timerObj.caption;
|
---|
37 | --time;
|
---|
38 | if (time < 1)
|
---|
39 | Engine.GetGUIObjectByName("tmcButton1").onPress();
|
---|
40 |
|
---|
41 | timerObj.caption = time;
|
---|
42 | updateDisplayedTimer(time);
|
---|
43 | }
|
---|
44 |
|
---|
45 | function updateDisplayedTimer(time)
|
---|
46 | {
|
---|
47 | Engine.GetGUIObjectByName("tmcTimerDisplay").caption = Math.ceil(time / 100);
|
---|
48 | }
|
---|