0ad/binaries/data/mods/mod/gui/msgbox/msgbox.js
phosit 36b9fd7b42 Return a promise from setButtonCaptionsAndVisibility
Now It's not hardcoded what is done if a button is pressed. The caller
can decide that.
Previously one had to call this function and then overwrite the on Press
attribute of each button.

Rename "Visibitily" to "Visibility" in setButtonCaptionsAndVisibility.
2024-10-17 20:47:54 +02:00

31 lines
954 B
JavaScript

/**
* Currently limited to at most 3 buttons per message box.
* The convention is to have "cancel" appear first.
*/
async function init(data)
{
// Set title
Engine.GetGUIObjectByName("mbTitleBar").caption = data.title;
// Set subject
let mbTextObj = Engine.GetGUIObjectByName("mbText");
mbTextObj.caption = data.message;
if (data.font)
mbTextObj.font = data.font;
// Default behaviour
let mbCancelHotkey = Engine.GetGUIObjectByName("mbCancelHotkey");
// Calculate size
let mbLRDiff = data.width / 2;
let mbUDDiff = data.height / 2;
Engine.GetGUIObjectByName("mbMain").size = "50%-" + mbLRDiff + " 50%-" + mbUDDiff + " 50%+" + mbLRDiff + " 50%+" + mbUDDiff;
let captions = data.buttonCaptions || [translate("OK")];
let mbButton = [];
const closePromise = setButtonCaptionsAndVisibility(mbButton, captions, mbCancelHotkey, "mbButton");
distributeButtonsHorizontally(mbButton, captions);
Engine.PopGuiPage(await closePromise);
}