Index: binaries/data/mods/mod/gui/common/utilities.js =================================================================== --- binaries/data/mods/mod/gui/common/utilities.js +++ binaries/data/mods/mod/gui/common/utilities.js @@ -1,35 +1,56 @@ -function distributeButtonsHorizontally(button, captions) +function packButtonsHorizontally(buttons, yLevel) { - const y1 = "100%-46"; - const y2 = "100%-18"; - switch (captions.length) + // Layout dimensions + const padding = 18; // px + const linePadding = 5; // px + const margin = 5; // px + const width = +((100 / buttons.length).toFixed()); // % + + let maxLineHeight = -Infinity; + + for (let i = 0; i < buttons.length; ++i) + { + const leftOffset = i == 0 ? padding : margin; + const rightOffset = i == buttons.length - 1 ? padding : margin; + + const size = buttons[i].size; + + size.rtop = yLevel; + size.top = -padding; + + size.rbottom = yLevel; + size.bottom = -padding; + + size.rleft = width * i; + size.left = leftOffset; + + size.rright = width * (i + 1); + size.right = -rightOffset; + + buttons[i].size = size; + + maxLineHeight = Math.max(buttons[i].getTextSize().height, maxLineHeight); + } + + for (let button of buttons) { - case 1: - button[0].size = "18 " + y1 + " 100%-18 " + y2; - break; - case 2: - button[0].size = "18 " + y1 + " 50%-5 " + y2; - button[1].size = "50%+5 " + y1 + " 100%-18 " + y2; - break; - case 3: - button[0].size = "18 " + y1 + " 33%-5 " + y2; - button[1].size = "33%+5 " + y1 + " 66%-5 " + y2; - button[2].size = "66%+5 " + y1 + " 100%-18 " + y2; - break; + const size = button.size; + size.top -= maxLineHeight + (2 * linePadding); + button.size = size; } } -function setButtonCaptionsAndVisibitily(button, captions, cancelHotkey, name) +function setButtonCaptionsAndVisibitily(buttons, captions, cancelHotkey, name) { captions.forEach((caption, i) => { - button[i] = Engine.GetGUIObjectByName(name + (i + 1)); - button[i].caption = caption; - button[i].hidden = false; - button[i].onPress = () => { + buttons[i] = Engine.GetGUIObjectByName(name + (i + 1)); + buttons[i].caption = caption; + buttons[i].hidden = false; + buttons[i].onPress = () => { Engine.PopGuiPage(i); }; if (i == 0) - cancelHotkey.onPress = button[i].onPress; + cancelHotkey.onPress = buttons[i].onPress; }); } Index: binaries/data/mods/mod/gui/msgbox/msgbox.js =================================================================== --- binaries/data/mods/mod/gui/msgbox/msgbox.js +++ binaries/data/mods/mod/gui/msgbox/msgbox.js @@ -26,5 +26,5 @@ let mbButton = []; setButtonCaptionsAndVisibitily(mbButton, captions, mbCancelHotkey, "mbButton"); - distributeButtonsHorizontally(mbButton, captions); + packButtonsHorizontally(mbButton, 100); } Index: binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.js =================================================================== --- binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.js +++ binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.js @@ -47,7 +47,7 @@ const button = []; setButtonCaptionsAndVisibitily(button, captions, cancelHotkey, "tmcButton"); - distributeButtonsHorizontally(button, captions); + packButtonsHorizontally(button, 100); } onTick()