Move some utility functions from the public mod to the mod mod in preparation for upcoming commit.
Small fixes and improvement while I'm at it, by temple and elexis. This was SVN commit r21754.
This commit is contained in:
parent
81e21ea53d
commit
364eaa34c6
48
binaries/data/mods/mod/gui/common/functions_msgbox.js
Normal file
48
binaries/data/mods/mod/gui/common/functions_msgbox.js
Normal file
@ -0,0 +1,48 @@
|
||||
// We want to pass callback functions for the different buttons in a convenient way.
|
||||
// Because passing functions accross compartment boundaries is a pain, we just store them here together with some optional arguments.
|
||||
// The messageBox page will return the code of the pressed button and the according function will be called.
|
||||
var g_MessageBoxBtnFunctions = [];
|
||||
var g_MessageBoxCallbackArgs = [];
|
||||
|
||||
function messageBoxCallbackFunction(btnCode)
|
||||
{
|
||||
if (btnCode !== undefined && g_MessageBoxBtnFunctions[btnCode])
|
||||
{
|
||||
// Cache the variables to make it possible to call a messageBox from a callback function.
|
||||
let callbackFunction = g_MessageBoxBtnFunctions[btnCode];
|
||||
let callbackArgs = g_MessageBoxCallbackArgs[btnCode];
|
||||
|
||||
g_MessageBoxBtnFunctions = [];
|
||||
g_MessageBoxCallbackArgs = [];
|
||||
|
||||
if (callbackArgs !== undefined)
|
||||
callbackFunction(callbackArgs);
|
||||
else
|
||||
callbackFunction();
|
||||
return;
|
||||
}
|
||||
|
||||
g_MessageBoxBtnFunctions = [];
|
||||
g_MessageBoxCallbackArgs = [];
|
||||
};
|
||||
|
||||
function messageBox(mbWidth, mbHeight, mbMessage, mbTitle, mbButtonCaptions, mbBtnCode, mbCallbackArgs)
|
||||
{
|
||||
if (g_MessageBoxBtnFunctions && g_MessageBoxBtnFunctions.length)
|
||||
{
|
||||
warn("A messagebox was called when a previous callback function is still set, aborting!");
|
||||
return;
|
||||
}
|
||||
|
||||
g_MessageBoxBtnFunctions = mbBtnCode;
|
||||
g_MessageBoxCallbackArgs = mbCallbackArgs || g_MessageBoxCallbackArgs;
|
||||
|
||||
Engine.PushGuiPage("page_msgbox.xml", {
|
||||
"width": mbWidth,
|
||||
"height": mbHeight,
|
||||
"message": mbMessage,
|
||||
"title": mbTitle,
|
||||
"buttonCaptions": mbButtonCaptions,
|
||||
"callback": mbBtnCode && "messageBoxCallbackFunction"
|
||||
});
|
||||
}
|
@ -1,3 +1,16 @@
|
||||
/**
|
||||
* Convert time in milliseconds to [HH:]mm:ss string representation.
|
||||
*
|
||||
* @param time Time period in milliseconds (integer)
|
||||
* @return String representing time period
|
||||
*/
|
||||
function timeToString(time)
|
||||
{
|
||||
return Engine.FormatMillisecondsIntoDateStringGMT(time, time < 1000 * 60 * 60 ?
|
||||
// Translation: Time-format string. See http://userguide.icu-project.org/formatparse/datetime for a guide to the meaning of the letters.
|
||||
translate("mm:ss") : translate("HH:mm:ss"));
|
||||
}
|
||||
|
||||
/**
|
||||
* These functions rely on the JS cache where possible and
|
||||
* should be prefered over the Engine.Translate ones to optimize the performance.
|
||||
@ -44,7 +57,7 @@ function translatePlural(singularMessage, pluralMessage, number)
|
||||
function translateWithContext(context, message)
|
||||
{
|
||||
if (!g_TranslationsWithContext[context])
|
||||
g_TranslationsWithContext[context] = {}
|
||||
g_TranslationsWithContext[context] = {};
|
||||
|
||||
if (!g_TranslationsWithContext[context][message])
|
||||
g_TranslationsWithContext[context][message] = Engine.TranslateWithContext(context, message);
|
||||
|
@ -5,5 +5,4 @@
|
||||
<include>common/modern/sprites.xml</include>
|
||||
|
||||
<include>msgbox/msgbox.xml</include>
|
||||
<include>common/global.xml</include>
|
||||
</page>
|
@ -8,7 +8,7 @@
|
||||
{
|
||||
"extractor": "javascript",
|
||||
"filemasks": [
|
||||
"gui/modmod/**.js"
|
||||
"gui/**.js"
|
||||
],
|
||||
"options": {
|
||||
"format": "javascript-format",
|
||||
@ -28,7 +28,7 @@
|
||||
{
|
||||
"extractor": "xml",
|
||||
"filemasks": [
|
||||
"gui/modmod/**.xml"
|
||||
"gui/**.xml"
|
||||
],
|
||||
"options": {
|
||||
"format": "none",
|
||||
|
@ -1,52 +1,3 @@
|
||||
// We want to pass callback functions for the different buttons in a convenient way.
|
||||
// Because passing functions accross compartment boundaries is a pain, we just store them here together with some optional arguments.
|
||||
// The messageBox page will return the code of the pressed button and the according function will be called.
|
||||
var g_MessageBoxBtnFunctions = [];
|
||||
var g_MessageBoxCallbackArgs = [];
|
||||
|
||||
var g_MessageBoxCallbackFunction = function(btnCode)
|
||||
{
|
||||
if (btnCode !== undefined && g_MessageBoxBtnFunctions[btnCode])
|
||||
{
|
||||
// Cache the variables to make it possible to call a messageBox from a callback function.
|
||||
let callbackFunction = g_MessageBoxBtnFunctions[btnCode];
|
||||
let callbackArgs = g_MessageBoxCallbackArgs[btnCode];
|
||||
|
||||
g_MessageBoxBtnFunctions = [];
|
||||
g_MessageBoxCallbackArgs = [];
|
||||
|
||||
if (callbackArgs !== undefined)
|
||||
callbackFunction(callbackArgs);
|
||||
else
|
||||
callbackFunction();
|
||||
return;
|
||||
}
|
||||
|
||||
g_MessageBoxBtnFunctions = [];
|
||||
g_MessageBoxCallbackArgs = [];
|
||||
};
|
||||
|
||||
function messageBox(mbWidth, mbHeight, mbMessage, mbTitle, mbButtonCaptions, mbBtnCode, mbCallbackArgs)
|
||||
{
|
||||
if (g_MessageBoxBtnFunctions && g_MessageBoxBtnFunctions.length)
|
||||
{
|
||||
warn("A messagebox was called when a previous callback function is still set, aborting!");
|
||||
return;
|
||||
}
|
||||
|
||||
g_MessageBoxBtnFunctions = mbBtnCode;
|
||||
g_MessageBoxCallbackArgs = mbCallbackArgs || g_MessageBoxCallbackArgs;
|
||||
|
||||
Engine.PushGuiPage("page_msgbox.xml", {
|
||||
"width": mbWidth,
|
||||
"height": mbHeight,
|
||||
"message": mbMessage,
|
||||
"title": mbTitle,
|
||||
"buttonCaptions": mbButtonCaptions,
|
||||
"callback": mbBtnCode && "g_MessageBoxCallbackFunction"
|
||||
});
|
||||
}
|
||||
|
||||
function openURL(url)
|
||||
{
|
||||
Engine.OpenURL(url);
|
||||
|
@ -105,17 +105,6 @@ function translateMapTitle(mapTitle)
|
||||
return mapTitle == "random" ? translateWithContext("map selection", "Random") : translate(mapTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert time in milliseconds to [hh:]mm:ss string representation.
|
||||
* @param time Time period in milliseconds (integer)
|
||||
* @return String representing time period
|
||||
*/
|
||||
function timeToString(time)
|
||||
{
|
||||
return Engine.FormatMillisecondsIntoDateStringGMT(time, time < 1000 * 60 * 60 ?
|
||||
translate("mm:ss") : translate("HH:mm:ss"));
|
||||
}
|
||||
|
||||
function removeDupes(array)
|
||||
{
|
||||
// loop backwards to make splice operations cheaper
|
||||
|
@ -240,7 +240,6 @@
|
||||
"gui/common/**.js",
|
||||
"gui/credits/**.js",
|
||||
"gui/locale/**.js",
|
||||
"gui/msgbox/**.js",
|
||||
"gui/options/**.js",
|
||||
"gui/pregame/**.js",
|
||||
"gui/reference/common/**.js",
|
||||
@ -276,7 +275,6 @@
|
||||
"gui/common/**.xml",
|
||||
"gui/credits/**.xml",
|
||||
"gui/locale/**.xml",
|
||||
"gui/msgbox/**.xml",
|
||||
"gui/options/**.xml",
|
||||
"gui/pregame/**.xml",
|
||||
"gui/reference/structree/**.xml",
|
||||
|
Loading…
Reference in New Issue
Block a user