Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/mod/gui/timedconfirmation/timedconfirmation.js
/** | function init(data) | ||||
vladislavbelov: It'd be good to have an explanation, what is going to happen in `N` seconds (also that the `N`… | |||||
Not Done Inline ActionsSo actually it doesn't wait for N seconds, it waits for N - 1 + FrameDeltaTime seconds. vladislavbelov: So actually it doesn't wait for `N` seconds, it waits for `N - 1 + FrameDeltaTime` seconds. | |||||
vladislavbelovUnsubmitted Not Done Inline ActionsWhat's the point of the init function? vladislavbelov: What's the point of the `init` function? | |||||
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… | |||||
* Currently limited to at most 3 buttons per message box. | { | ||||
* The convention is to have "cancel" appear first. | new TimedConfirmation(data); | ||||
Lint: no-use-before-define 'TimedConfirmation' was used before it was defined. Lint: no-use-before-define: 'TimedConfirmation' was used before it was defined. | |||||
Lint: no-new Do not use 'new' for side effects. Lint: no-new: Do not use 'new' for side effects. | |||||
vladislavbelovUnsubmitted Not Done Inline ActionsImportant linter warnings. vladislavbelov: Important linter warnings. | |||||
*/ | } | ||||
function init(data) | |||||
StanUnsubmitted 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… | |||||
vladislavbelovUnsubmitted Not Done Inline ActionsAgree. vladislavbelov: Agree. | |||||
{ | class TimedConfirmation | ||||
Engine.GetGUIObjectByName("tmcTitleBar").caption = data.title; | { | ||||
constructor(data) | |||||
const textObj = Engine.GetGUIObjectByName("tmcText"); | { | ||||
textObj.caption = data.message; | this.messageObject = Engine.GetGUIObjectByName("tmcText"); | ||||
this.panel = Engine.GetGUIObjectByName("tmcMain"); | |||||
updateDisplayedTimer(data.timeout); | this.panel.onTick = this.onTick.bind(this); | ||||
this.setup(data); | |||||
Engine.GetGUIObjectByName("tmcTimer").caption = data.timeout; | } | ||||
if (data.font) | |||||
textObj.font = data.font; | setup(data) | ||||
{ | |||||
const cancelHotkey = Engine.GetGUIObjectByName("tmcCancelHotkey"); | Engine.GetGUIObjectByName("tmcTitleBar").caption = data.title; | ||||
cancelHotkey.onPress = Engine.PopGuiPage; | |||||
this.timeout = +data.timeout + Date.now(); | |||||
const lRDiff = data.width / 2; | this.message = data.message; | ||||
const uDDiff = data.height / 2; | this.timeParameter = data.timeParameter; | ||||
Engine.GetGUIObjectByName("tmcMain").size = "50%-" + lRDiff + " 50%-" + uDDiff + " 50%+" + lRDiff + " 50%+" + uDDiff; | |||||
if (data.font) | |||||
const captions = data.buttonCaptions || [translate("OK")]; | this.messageObject.font = data.font; | ||||
// Set button captions and visibility | this.updateDisplayedTimer(data.timeout); | ||||
const button = []; | |||||
setButtonCaptionsAndVisibitily(button, captions, cancelHotkey, "tmcButton"); | const cancelHotkey = Engine.GetGUIObjectByName("tmcCancelHotkey"); | ||||
distributeButtonsHorizontally(button, captions); | cancelHotkey.onPress = Engine.PopGuiPage; | ||||
} | |||||
const lRDiff = data.width / 2; | |||||
function onTick() | const uDDiff = data.height / 2; | ||||
{ | this.panel.size = "50%-" + lRDiff + " 50%-" + uDDiff + " 50%+" + lRDiff + " 50%+" + uDDiff; | ||||
const timerObj = Engine.GetGUIObjectByName("tmcTimer"); | |||||
let time = +timerObj.caption; | const captions = data.buttonCaptions || [translate("OK")]; | ||||
--time; | |||||
if (time < 1) | // Set button captions and visibility | ||||
Engine.GetGUIObjectByName("tmcButton1").onPress(); | const button = []; | ||||
setButtonCaptionsAndVisibitily(button, captions, cancelHotkey, "tmcButton"); | |||||
timerObj.caption = time; | distributeButtonsHorizontally(button, captions); | ||||
updateDisplayedTimer(time); | } | ||||
} | |||||
onTick() | |||||
function updateDisplayedTimer(time) | { | ||||
{ | const remaining = this.timeout - Date.now(); | ||||
Engine.GetGUIObjectByName("tmcTimerDisplay").caption = Math.ceil(time / 100); | if (remaining < 1) | ||||
} | Engine.GetGUIObjectByName("tmcButton1").onPress(); | ||||
this.updateDisplayedTimer(remaining); | |||||
} | |||||
updateDisplayedTimer(time) | |||||
{ | |||||
this.messageObject.caption = sprintf( | |||||
this.message, | |||||
{ [this.timeParameter]: Math.ceil(time / 1000) } | |||||
); | |||||
} | |||||
} |
Wildfire Games · Phabricator
It'd be good to have an explanation, what is going to happen in N seconds (also that the N is in seconds too).