Index: binaries/data/mods/mod/gui/common/functions_msgbox.js
===================================================================
--- binaries/data/mods/mod/gui/common/functions_msgbox.js
+++ binaries/data/mods/mod/gui/common/functions_msgbox.js
@@ -15,7 +15,7 @@
});
}
-function timedConfirmation(width, height, message, timeout, title, buttonCaptions, btnCode, callbackArgs)
+function timedConfirmation(width, height, message, timeParameter, timeout, title, buttonCaptions, btnCode, callbackArgs)
{
Engine.PushGuiPage(
"page_timedconfirmation.xml",
@@ -23,6 +23,7 @@
"width": width,
"height": height,
"message": message,
+ "timeParameter": timeParameter,
"timeout": timeout,
"title": title,
"buttonCaptions": buttonCaptions
Index: binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.js
===================================================================
--- binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.js
+++ binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.js
@@ -1,48 +1,60 @@
-/**
- * Currently limited to at most 3 buttons per message box.
- * The convention is to have "cancel" appear first.
- */
-function init(data)
-{
- Engine.GetGUIObjectByName("tmcTitleBar").caption = data.title;
-
- const textObj = Engine.GetGUIObjectByName("tmcText");
- textObj.caption = data.message;
-
- updateDisplayedTimer(data.timeout);
-
- Engine.GetGUIObjectByName("tmcTimer").caption = data.timeout;
- if (data.font)
- textObj.font = data.font;
-
- const cancelHotkey = Engine.GetGUIObjectByName("tmcCancelHotkey");
- cancelHotkey.onPress = Engine.PopGuiPage;
-
- const lRDiff = data.width / 2;
- const uDDiff = data.height / 2;
- Engine.GetGUIObjectByName("tmcMain").size = "50%-" + lRDiff + " 50%-" + uDDiff + " 50%+" + lRDiff + " 50%+" + uDDiff;
-
- const captions = data.buttonCaptions || [translate("OK")];
-
- // Set button captions and visibility
- const button = [];
- setButtonCaptionsAndVisibitily(button, captions, cancelHotkey, "tmcButton");
- distributeButtonsHorizontally(button, captions);
-}
-
-function onTick()
-{
- const timerObj = Engine.GetGUIObjectByName("tmcTimer");
- let time = +timerObj.caption;
- --time;
- if (time < 1)
- Engine.GetGUIObjectByName("tmcButton1").onPress();
-
- timerObj.caption = time;
- updateDisplayedTimer(time);
-}
-
-function updateDisplayedTimer(time)
-{
- Engine.GetGUIObjectByName("tmcTimerDisplay").caption = Math.ceil(time / 100);
-}
+function init(data)
+{
+ new TimedConfirmation(data);
+}
+
+class TimedConfirmation
+{
+ constructor(data)
+ {
+ this.messageObject = Engine.GetGUIObjectByName("tmcText");
+ this.panel = Engine.GetGUIObjectByName("tmcMain");
+ this.panel.onTick = this.onTick.bind(this);
+ this.setup(data);
+ }
+
+ setup(data)
+ {
+ Engine.GetGUIObjectByName("tmcTitleBar").caption = data.title;
+
+ this.timeout = +data.timeout + Date.now();
+ this.message = data.message;
+ this.timeParameter = data.timeParameter;
+
+ if (data.font)
+ this.messageObject.font = data.font;
+
+ this.updateDisplayedTimer(data.timeout);
+
+ const cancelHotkey = Engine.GetGUIObjectByName("tmcCancelHotkey");
+ cancelHotkey.onPress = Engine.PopGuiPage;
+
+ const lRDiff = data.width / 2;
+ const uDDiff = data.height / 2;
+ this.panel.size = "50%-" + lRDiff + " 50%-" + uDDiff + " 50%+" + lRDiff + " 50%+" + uDDiff;
+
+ const captions = data.buttonCaptions || [translate("OK")];
+
+ // Set button captions and visibility
+ const button = [];
+ setButtonCaptionsAndVisibitily(button, captions, cancelHotkey, "tmcButton");
+ distributeButtonsHorizontally(button, captions);
+ }
+
+ onTick()
+ {
+ const remaining = this.timeout - Date.now();
+ if (remaining < 1)
+ Engine.GetGUIObjectByName("tmcButton1").onPress();
+
+ this.updateDisplayedTimer(remaining);
+ }
+
+ updateDisplayedTimer(time)
+ {
+ this.messageObject.caption = sprintf(
+ this.message,
+ { [this.timeParameter]: Math.ceil(time / 1000) }
+ );
+ }
+}
Index: binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.xml
===================================================================
--- binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.xml
+++ binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.xml
@@ -12,45 +12,36 @@
style="ModernDialog"
type="image"
>
-
- onTick();
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
Index: binaries/data/mods/public/gui/options/options.js
===================================================================
--- binaries/data/mods/public/gui/options/options.js
+++ binaries/data/mods/public/gui/options/options.js
@@ -167,8 +167,9 @@
return;
timedConfirmation(
500, 200,
- translate("Do you want to keep changes?"),
- 500,
+ translate("Changes will be reverted in %(time)s seconds. Do you want to keep changes?"),
+ "time",
+ option.timeout,
translate("Warning"),
[translate("No"), translate("Yes")],
[() => {this.revertChange(option, +oldValue, hasChanges);}, null]
Index: binaries/data/mods/public/gui/options/options.json
===================================================================
--- binaries/data/mods/public/gui/options/options.json
+++ binaries/data/mods/public/gui/options/options.json
@@ -154,7 +154,7 @@
{
"type": "dropdownNumber",
"label": "GUI scale",
- "timeout": 500,
+ "timeout": 5000,
"tooltip": "GUI scale",
"config": "gui.scale",
"function": "SetGUIScale",