Index: ps/trunk/binaries/data/mods/mod/gui/common/functions_msgbox.js =================================================================== --- ps/trunk/binaries/data/mods/mod/gui/common/functions_msgbox.js +++ ps/trunk/binaries/data/mods/mod/gui/common/functions_msgbox.js @@ -15,6 +15,24 @@ }); } +function timedConfirmation(width, height, message, timeout, title, buttonCaptions, btnCode, callbackArgs) +{ + Engine.PushGuiPage( + "page_timedconfirmation.xml", + { + "width": width, + "height": height, + "message": message, + "timeout": timeout, + "title": title, + "buttonCaptions": buttonCaptions + }, + button => { + if (btnCode !== undefined && btnCode[button]) + btnCode[button](callbackArgs ? callbackArgs[button] : undefined); + }); +} + function openURL(url) { Engine.OpenURL(url); Index: ps/trunk/binaries/data/mods/mod/gui/common/utilities.js =================================================================== --- ps/trunk/binaries/data/mods/mod/gui/common/utilities.js +++ ps/trunk/binaries/data/mods/mod/gui/common/utilities.js @@ -0,0 +1,35 @@ +function distributeButtonsHorizontally(button, captions) +{ + const y1 = "100%-46"; + const y2 = "100%-18"; + switch (captions.length) + { + 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; + } +} + +function setButtonCaptionsAndVisibitily(button, 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 = () => { + Engine.PopGuiPage(i); + }; + + if (i == 0) + cancelHotkey.onPress = button[i].onPress; + }); +} Index: ps/trunk/binaries/data/mods/mod/gui/msgbox/msgbox.js =================================================================== --- ps/trunk/binaries/data/mods/mod/gui/msgbox/msgbox.js +++ ps/trunk/binaries/data/mods/mod/gui/msgbox/msgbox.js @@ -24,37 +24,7 @@ let captions = data.buttonCaptions || [translate("OK")]; - // Set button captions and visibility let mbButton = []; - captions.forEach((caption, i) => { - mbButton[i] = Engine.GetGUIObjectByName("mbButton" + (i + 1)); - mbButton[i].caption = caption; - mbButton[i].hidden = false; - mbButton[i].onPress = () => { - Engine.PopGuiPage(i); - }; - - // Convention: Cancel is the first button - if (i == 0) - mbCancelHotkey.onPress = mbButton[i].onPress; - }); - - // Distribute buttons horizontally - let y1 = "100%-46"; - let y2 = "100%-18"; - switch (captions.length) - { - case 1: - mbButton[0].size = "18 " + y1 + " 100%-18 " + y2; - break; - case 2: - mbButton[0].size = "18 " + y1 + " 50%-5 " + y2; - mbButton[1].size = "50%+5 " + y1 + " 100%-18 " + y2; - break; - case 3: - mbButton[0].size = "18 " + y1 + " 33%-5 " + y2; - mbButton[1].size = "33%+5 " + y1 + " 66%-5 " + y2; - mbButton[2].size = "66%+5 " + y1 + " 100%-18 " + y2; - break; - } + setButtonCaptionsAndVisibitily(mbButton, captions, mbCancelHotkey, "mbButton"); + distributeButtonsHorizontally(mbButton, captions); } Index: ps/trunk/binaries/data/mods/mod/gui/page_timedconfirmation.xml =================================================================== --- ps/trunk/binaries/data/mods/mod/gui/page_timedconfirmation.xml +++ ps/trunk/binaries/data/mods/mod/gui/page_timedconfirmation.xml @@ -0,0 +1,8 @@ + + + common/modern/setup.xml + common/modern/styles.xml + common/modern/sprites.xml + + timedconfirmation/timedconfirmation.xml + Index: ps/trunk/binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.js =================================================================== --- ps/trunk/binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.js +++ ps/trunk/binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.js @@ -0,0 +1,48 @@ +/** + * Currently limited to at most 3 buttons per message box. + * The convention is to have "cancel" appear first. + */ +function init(data) +{ + Engine.GetGUIObjectByName("tmcTitleBar").caption = data.title; + + const textObj = Engine.GetGUIObjectByName("tmcText"); + textObj.caption = data.message; + + updateDisplayedTimer(data.timeout); + + Engine.GetGUIObjectByName("tmcTimer").caption = data.timeout; + if (data.font) + textObj.font = data.font; + + const cancelHotkey = Engine.GetGUIObjectByName("tmcCancelHotkey"); + cancelHotkey.onPress = Engine.PopGuiPage; + + const lRDiff = data.width / 2; + const uDDiff = data.height / 2; + Engine.GetGUIObjectByName("tmcMain").size = "50%-" + lRDiff + " 50%-" + uDDiff + " 50%+" + lRDiff + " 50%+" + uDDiff; + + const captions = data.buttonCaptions || [translate("OK")]; + + // Set button captions and visibility + const button = []; + setButtonCaptionsAndVisibitily(button, captions, cancelHotkey, "tmcButton"); + distributeButtonsHorizontally(button, captions); +} + +function onTick() +{ + const timerObj = Engine.GetGUIObjectByName("tmcTimer"); + let time = +timerObj.caption; + --time; + if (time < 1) + Engine.GetGUIObjectByName("tmcButton1").onPress(); + + timerObj.caption = time; + updateDisplayedTimer(time); +} + +function updateDisplayedTimer(time) +{ + Engine.GetGUIObjectByName("tmcTimerDisplay").caption = Math.ceil(time / 100); +} Index: ps/trunk/binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.xml =================================================================== --- ps/trunk/binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.xml +++ ps/trunk/binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.xml @@ -0,0 +1,56 @@ + + + + +