2016-05-14 21:04:31 -07:00
|
|
|
/**
|
|
|
|
|
* Currently limited to at most 3 buttons per message box.
|
|
|
|
|
* The convention is to have "cancel" appear first.
|
|
|
|
|
*/
|
2024-09-21 11:20:35 -07:00
|
|
|
function init(data)
|
2014-04-20 13:51:48 -07:00
|
|
|
{
|
2016-05-14 21:04:31 -07:00
|
|
|
// Set title
|
|
|
|
|
Engine.GetGUIObjectByName("mbTitleBar").caption = data.title;
|
2014-04-20 13:51:48 -07:00
|
|
|
|
2016-05-14 21:04:31 -07:00
|
|
|
// Set subject
|
2025-05-06 04:49:01 -07:00
|
|
|
const mbTextObj = Engine.GetGUIObjectByName("mbText");
|
2016-05-14 21:04:31 -07:00
|
|
|
mbTextObj.caption = data.message;
|
|
|
|
|
if (data.font)
|
|
|
|
|
mbTextObj.font = data.font;
|
2014-04-20 13:51:48 -07:00
|
|
|
|
2014-07-30 02:27:46 -07:00
|
|
|
// Default behaviour
|
2025-05-06 04:49:01 -07:00
|
|
|
const mbCancelHotkey = Engine.GetGUIObjectByName("mbCancelHotkey");
|
2014-07-30 02:27:46 -07:00
|
|
|
|
2014-04-20 13:51:48 -07:00
|
|
|
// Calculate size
|
2025-05-06 04:49:01 -07:00
|
|
|
const mbLRDiff = data.width / 2;
|
|
|
|
|
const mbUDDiff = data.height / 2;
|
2016-05-14 21:04:31 -07:00
|
|
|
Engine.GetGUIObjectByName("mbMain").size = "50%-" + mbLRDiff + " 50%-" + mbUDDiff + " 50%+" + mbLRDiff + " 50%+" + mbUDDiff;
|
2014-04-20 13:51:48 -07:00
|
|
|
|
2025-05-06 04:49:01 -07:00
|
|
|
const captions = data.buttonCaptions || [translate("OK")];
|
2014-07-30 02:27:46 -07:00
|
|
|
|
2025-05-06 04:49:01 -07:00
|
|
|
const mbButton = [];
|
2024-08-24 08:15:50 -07:00
|
|
|
const closePromise = setButtonCaptionsAndVisibility(mbButton, captions, mbCancelHotkey, "mbButton");
|
2021-10-17 03:58:51 -07:00
|
|
|
distributeButtonsHorizontally(mbButton, captions);
|
2024-08-24 08:15:50 -07:00
|
|
|
|
2024-09-21 11:20:35 -07:00
|
|
|
return closePromise;
|
2014-04-20 13:51:48 -07:00
|
|
|
}
|