Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.js
/** | /** | ||||
* Currently limited to at most 3 buttons per message box. | * Currently limited to at most 3 buttons per message box. | ||||
* The convention is to have "cancel" appear first. | * The convention is to have "cancel" appear first. | ||||
*/ | */ | ||||
function init(data) | function init(data) | ||||
{ | { | ||||
Engine.GetGUIObjectByName("tmcTitleBar").caption = data.title; | Engine.GetGUIObjectByName("tmcTitleBar").caption = data.title; | ||||
const textObj = Engine.GetGUIObjectByName("tmcText"); | const textObj = Engine.GetGUIObjectByName("tmcText"); | ||||
textObj.caption = data.message; | textObj.caption = data.message; | ||||
updateDisplayedTimer(data.timeout); | updateDisplayedTimer(data.timeout); | ||||
Engine.GetGUIObjectByName("tmcTimer").caption = data.timeout; | Engine.GetGUIObjectByName("tmcTimer").caption = +data.timeout + Date.now(); | ||||
if (data.font) | if (data.font) | ||||
textObj.font = data.font; | textObj.font = data.font; | ||||
const cancelHotkey = Engine.GetGUIObjectByName("tmcCancelHotkey"); | const cancelHotkey = Engine.GetGUIObjectByName("tmcCancelHotkey"); | ||||
cancelHotkey.onPress = Engine.PopGuiPage; | cancelHotkey.onPress = Engine.PopGuiPage; | ||||
const lRDiff = data.width / 2; | const lRDiff = data.width / 2; | ||||
const uDDiff = data.height / 2; | const uDDiff = data.height / 2; | ||||
Engine.GetGUIObjectByName("tmcMain").size = "50%-" + lRDiff + " 50%-" + uDDiff + " 50%+" + lRDiff + " 50%+" + uDDiff; | Engine.GetGUIObjectByName("tmcMain").size = "50%-" + lRDiff + " 50%-" + uDDiff + " 50%+" + lRDiff + " 50%+" + uDDiff; | ||||
const captions = data.buttonCaptions || [translate("OK")]; | const captions = data.buttonCaptions || [translate("OK")]; | ||||
// Set button captions and visibility | // Set button captions and visibility | ||||
const button = []; | const button = []; | ||||
setButtonCaptionsAndVisibitily(button, captions, cancelHotkey, "tmcButton"); | setButtonCaptionsAndVisibitily(button, captions, cancelHotkey, "tmcButton"); | ||||
distributeButtonsHorizontally(button, captions); | distributeButtonsHorizontally(button, captions); | ||||
} | } | ||||
function onTick() | function onTick() | ||||
{ | { | ||||
const timerObj = Engine.GetGUIObjectByName("tmcTimer"); | const timerObj = Engine.GetGUIObjectByName("tmcTimer"); | ||||
let time = +timerObj.caption; | const remaining = +timerObj.caption - Date.now(); | ||||
--time; | if (remaining < 1) | ||||
vladislavbelov: So actually it doesn't wait for `N` seconds, it waits for `N - 1 + FrameDeltaTime` seconds. | |||||
SilierAuthorUnsubmitted Done Inline ActionsYes, Silier: Yes,
Its in ms so 1 ms does not mather too much for user.
Only gui ticks can be used as… | |||||
if (time < 1) | |||||
Engine.GetGUIObjectByName("tmcButton1").onPress(); | Engine.GetGUIObjectByName("tmcButton1").onPress(); | ||||
timerObj.caption = time; | updateDisplayedTimer(remaining); | ||||
updateDisplayedTimer(time); | |||||
} | } | ||||
function updateDisplayedTimer(time) | function updateDisplayedTimer(time) | ||||
{ | { | ||||
Engine.GetGUIObjectByName("tmcTimerDisplay").caption = Math.ceil(time / 100); | Engine.GetGUIObjectByName("tmcTimerDisplay").caption = Math.ceil(time / 1000); | ||||
vladislavbelovUnsubmitted Not Done Inline ActionsIt'd be good to have an explanation, what is going to happen in N seconds (also that the N is in seconds too). vladislavbelov: It'd be good to have an explanation, what is going to happen in `N` seconds (also that the `N`… | |||||
} | } | ||||
Not Done Inline ActionsStrange the linter does not complain about a class being used before it's defined :) Bit of jsdoc wouldn't hurt too Stan: Strange the linter does not complain about a class being used before it's defined :)
Bit of… | |||||
Not Done Inline ActionsAgree. vladislavbelov: Agree. | |||||
Not Done Inline ActionsImportant linter warnings. vladislavbelov: Important linter warnings. | |||||
Not Done Inline ActionsWhat's the point of the init function? vladislavbelov: What's the point of the `init` function? |
Wildfire Games · Phabricator
So actually it doesn't wait for N seconds, it waits for N - 1 + FrameDeltaTime seconds.