source: ps/trunk/binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.js@ 25966

Last change on this file since 25966 was 25966, checked in by Silier, 3 years ago

There have been quite a bit of number of questions how to change scale of the gui, because this option is hidden from the user.

Use dropdown with values. Implement confirmation box with countdown to revert scale change because buttons can get unable to click.

Differential revision: D3037
Comments by: @vladislavbelov, @Stan, @wraitii, @pieq, @sera
Tested by: @Langbart

File size: 1.3 KB
Line 
1/**
2 * Currently limited to at most 3 buttons per message box.
3 * The convention is to have "cancel" appear first.
4 */
5function 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
33function 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
45function updateDisplayedTimer(time)
46{
47 Engine.GetGUIObjectByName("tmcTimerDisplay").caption = Math.ceil(time / 100);
48}
Note: See TracBrowser for help on using the repository browser.