Index: ps/trunk/binaries/data/mods/mod/gui/common/functions_msgbox.js
===================================================================
--- ps/trunk/binaries/data/mods/mod/gui/common/functions_msgbox.js
+++ ps/trunk/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: ps/trunk/binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.js
===================================================================
--- ps/trunk/binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.js
+++ ps/trunk/binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.js
@@ -1,48 +1,74 @@
/**
- * Currently limited to at most 3 buttons per message box.
- * The convention is to have "cancel" appear first.
+ * @class TimedConfirmation
+ * This class displays confirmation box, which will be closed after defined time in miliseconds.
*/
-function init(data)
+class TimedConfirmation
{
- 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);
+ /**
+ * @param {Object} data
+ * @param {Number} data.width - The width of the confirmation box
+ * @param {Number} data.height - The height of the confirmation box
+ * @param {String} data.message - The message to be displayed with parameter for time which will be displayed in seconds
+ * @param {String} data.timeParameter - The string used in 'message' for time, e.g 'time' with %(time)s in message
+ * @param {Number} data.timeout - The time in miliseconds after which confirmation box closes itself
+ * @param {String} data.title - The string displayed in header
+ * @param {String|undefined} data.buttonCaptions - The captions used for buttons (if not defined, defaults to 'OK')
+ * @param {String|undefined} data.font - The used font
+ */
+ 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")];
+
+ 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) }
+ );
+ }
}
-function updateDisplayedTimer(time)
+function init(data)
{
- Engine.GetGUIObjectByName("tmcTimerDisplay").caption = Math.ceil(time / 100);
+ new TimedConfirmation(data);
}
Index: ps/trunk/binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.xml
===================================================================
--- ps/trunk/binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.xml
+++ ps/trunk/binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.xml
@@ -12,45 +12,36 @@
style="ModernDialog"
type="image"
>
-
- onTick();
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
Index: ps/trunk/binaries/data/mods/public/gui/options/options.js
===================================================================
--- ps/trunk/binaries/data/mods/public/gui/options/options.js
+++ ps/trunk/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: ps/trunk/binaries/data/mods/public/gui/options/options.json
===================================================================
--- ps/trunk/binaries/data/mods/public/gui/options/options.json
+++ ps/trunk/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",