0ad/binaries/data/mods/mod/gui/msgbox/msgbox.js
Ralph Sennhauser 7684e12717
Fix eslint rule 'prefer-const' in modmod
eslint --no-config-lookup --fix --rule '"prefer-const": 1' \
    binaries/data/mods/mod

Ref: #7812
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-05-06 13:49:13 +02:00

31 lines
942 B
JavaScript

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