Skip to content

Commit 2fc1965

Browse files
committed
waitScreen texts are all parameters now, countdown may be hidden
1 parent c6a46f9 commit 2fc1965

File tree

4 files changed

+144
-99
lines changed

4 files changed

+144
-99
lines changed

build/nodegame-window.js

Lines changed: 82 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
var DOM;
2323

2424
var constants, windowLevels, screenLevels;
25-
var CB_EXECUTED, WIN_LOADING, lockedUpdate;
25+
var CB_EXECUTED, WIN_LOADING;
2626

2727
if (!J) throw new Error('GameWindow: JSUS not found');
2828
DOM = J.require('DOM');
@@ -36,9 +36,6 @@
3636

3737
WIN_LOADING = windowLevels.LOADING;
3838

39-
// Allows just one update at the time to the counter of loading frames.
40-
lockedUpdate = false;
41-
4239
GameWindow.prototype = DOM;
4340
GameWindow.prototype.constructor = GameWindow;
4441

@@ -62,10 +59,7 @@
6259
var iframeWin;
6360
iframeWin = iframe.contentWindow;
6461

65-
function completed(event) {
66-
var iframeDoc;
67-
iframeDoc = J.getIFrameDocument(iframe);
68-
62+
function completed() {
6963
// Detaching the function to avoid double execution.
7064
iframe.removeEventListener('load', completed, false);
7165
iframeWin.removeEventListener('load', completed, false);
@@ -853,16 +847,22 @@
853847
*
854848
* Appends a configurable div element at to "top" of the page
855849
*
856-
* @param {object} opts Optional. Configuration options: TODO
850+
* @param {object} opts Optional. Configuration options:
857851
*
858-
* - toggleBtn
859-
* - toggleBtnLabel
860-
* - toggleBtnRoot:
861-
* - force: destroys current Info Panel
852+
* - root: The HTML element (or its id) under which the Info Panel
853+
* will be appended. Default: above the main frame, or below the
854+
* the header, or under document.body.
855+
* - innerHTML: the content of the Info Panel.
856+
* - force: It destroys current frame, if existing.
857+
* - toggleBtn: If TRUE, it creates a button to toggle the Info Panel.
858+
* Default: TRUE.
859+
* - toggleBtnRoot: the HTML element (or its id) under which the button
860+
* to toggle the Info Panel will be appended. Default: the header.
861+
* - toggleBtnLabel: The text on the button to toggle the Info Panel.
862+
* Default: 'Info'.
862863
*
863-
* @param {boolean} force Optional. Will create the frame even if an
864-
* existing one is found. Deprecated, use force flag in options.
865-
* Default: FALSE
864+
* @param {boolean} force Optional. Deprecated, use force flag in
865+
* options. Default: FALSE
866866
*
867867
* @return {InfoPanel} A reference to the InfoPanel object
868868
*
@@ -888,11 +888,7 @@
888888
opts.toggleBtn = false;
889889
}
890890
}
891-
// if (!force) {
892-
// throw new Error('GameWindow.generateInfoPanel: info panel is ' +
893-
// 'already existing. Use force to regenerate.');
894-
// }
895-
891+
node.warn('W.generateInfoPanel: Info Panel already existing.')
896892
}
897893
else {
898894
this.infoPanel = new node.InfoPanel(opts);
@@ -902,6 +898,7 @@
902898

903899
root = opts.root;
904900
if (root) {
901+
if ('string' === typeof root) root = W.gid(root);
905902
if (!J.isElement(root)) {
906903
throw new Error('GameWindow.generateInfoPanel: root must be ' +
907904
'undefined or HTMLElement. Found: ' + root);
@@ -2369,8 +2366,6 @@
23692366
* @param {GameWindow} that A reference to the GameWindow instance
23702367
* @param {number} update The number to add to the counter
23712368
*
2372-
* @see GameWindow.lockedUpdate
2373-
*
23742369
* @api private
23752370
*/
23762371
function updateAreLoading(that, update) {
@@ -2911,7 +2906,6 @@
29112906
countdown);
29122907
}
29132908
this.setScreenLevel('LOCKING');
2914-
text = text || 'Screen locked. Please wait...';
29152909
this.waitScreen.lock(text, countdown);
29162910
this.setScreenLevel('LOCKED');
29172911
};
@@ -3082,7 +3076,7 @@
30823076

30833077
/**
30843078
* # WaitScreen
3085-
* Copyright(c) 2018 Stefano Balietti
3079+
* Copyright(c) 2021 Stefano Balietti
30863080
* MIT Licensed
30873081
*
30883082
* Overlays the screen, disables inputs, and displays a message/timer
@@ -3098,8 +3092,8 @@
30983092

30993093
// ## Meta-data
31003094

3101-
WaitScreen.version = '0.9.0';
3102-
WaitScreen.description = 'Shows a standard waiting screen';
3095+
WaitScreen.version = '0.10.0';
3096+
WaitScreen.description = 'Shows a waiting screen';
31033097

31043098
// ## Helper functions
31053099

@@ -3206,10 +3200,10 @@
32063200
*
32073201
* Instantiates a new WaitScreen object
32083202
*
3209-
* @param {object} options Optional. Configuration options
3203+
* @param {object} opts Optional. Configuration options
32103204
*/
3211-
function WaitScreen(options) {
3212-
options = options || {};
3205+
function WaitScreen(opts) {
3206+
opts = opts || {};
32133207

32143208
/**
32153209
* ### WaitScreen.id
@@ -3218,7 +3212,7 @@
32183212
*
32193213
* @see WaitScreen.waitingDiv
32203214
*/
3221-
this.id = options.id || 'ng_waitScreen';
3215+
this.id = opts.id || 'ng_waitScreen';
32223216

32233217
/**
32243218
* ### WaitScreen.root
@@ -3227,7 +3221,7 @@
32273221
*
32283222
* @see WaitScreen.waitingDiv
32293223
*/
3230-
this.root = options.root || null;
3224+
this.root = opts.root || null;
32313225

32323226
/**
32333227
* ### WaitScreen.waitingDiv
@@ -3285,23 +3279,60 @@
32853279
* ### WaitScreen.countdown
32863280
*
32873281
* Countdown of max waiting time
3288-
*
3289-
* @see WaitScreen.countdown
32903282
*/
32913283
this.countdown = null;
32923284

3285+
/**
3286+
* ### WaitScreen.displayCountdown
3287+
*
3288+
* If FALSE, countdown is never displayed by lock
3289+
*
3290+
* @see WaitScreen.lock
3291+
*/
3292+
this.displayCountdown =
3293+
'undefined' !== typeof opts.displayCountdown ?
3294+
!!opts.displayCountdown : true;
3295+
32933296
/**
32943297
* ### WaitScreen.text
32953298
*
32963299
* Default texts for default events
32973300
*/
32983301
this.defaultTexts = {
3299-
waiting: options.waitingText ||
3302+
3303+
// Default text for locked screen.
3304+
locked: opts.lockedText ||
3305+
'Screen locked. Please wait...',
3306+
3307+
// When player is DONE and waiting for others.
3308+
waiting: opts.waitingText ||
33003309
'Waiting for other players to be done...',
3301-
stepping: options.steppingText ||
3310+
3311+
// When entering a new step after DONE (displayed quickly usually).
3312+
stepping: opts.steppingText ||
33023313
'Initializing game step, will be ready soon...',
3303-
paused: options.pausedText ||
3304-
'Game is paused. Please wait.'
3314+
3315+
// Game paused.
3316+
paused: opts.pausedText ||
3317+
'Game is paused. Please wait.',
3318+
3319+
// Countdown text displayed under waiting text.
3320+
countdown: opts.countdownResumingText ||
3321+
'<br>Do not refresh the page!<br>Maximum Waiting Time: ',
3322+
3323+
// Displayed after resuming from waiting.
3324+
countdownResuming: opts.countdownResumingText ||
3325+
'Resuming soon...',
3326+
3327+
// Formats the countdown in minutes and seconds.
3328+
formatCountdown: function(time) {
3329+
var out;
3330+
out = '';
3331+
time = J.parseMilliseconds(time);
3332+
if (time[2]) out += time[2] + ' min ';
3333+
if (time[3]) out += time[3] + ' sec';
3334+
return out || 0;
3335+
}
33053336
};
33063337

33073338
/**
@@ -3368,9 +3399,11 @@
33683399
* @see WaitScren.updateText
33693400
*/
33703401
WaitScreen.prototype.lock = function(text, countdown) {
3371-
var frameDoc;
3402+
var frameDoc, t;
3403+
t = this.defaultTexts;
3404+
if ('undefined' === typeof text) text = t.locked;
33723405
if ('undefined' === typeof document.getElementsByTagName) {
3373-
node.warn('WaitScreen.lock: cannot lock inputs.');
3406+
node.warn('WaitScreen.lock: cannot lock inputs');
33743407
}
33753408
// Disables all input forms in the page.
33763409
lockUnlockedInputs(document);
@@ -3392,20 +3425,20 @@
33923425
}
33933426
this.contentDiv.innerHTML = text;
33943427

3395-
if (countdown) {
3428+
if (this.displayCountdown && countdown) {
3429+
33963430
if (!this.countdownDiv) {
33973431
this.countdownDiv = W.add('div', this.waitingDiv,
33983432
'ng_waitscreen-countdown-div');
33993433

3400-
this.countdownDiv.innerHTML = '<br>Do not refresh the page!' +
3401-
'<br>Maximum Waiting Time: ';
3434+
this.countdownDiv.innerHTML = t.countdown;
34023435

34033436
this.countdownSpan = W.add('span', this.countdownDiv,
34043437
'ng_waitscreen-countdown-span');
34053438
}
34063439

34073440
this.countdown = countdown;
3408-
this.countdownSpan.innerHTML = formatCountdown(countdown);
3441+
this.countdownSpan.innerHTML = t.formatCountdown(countdown);
34093442
this.countdownDiv.style.display = '';
34103443

34113444
this.countdownInterval = setInterval(function() {
@@ -3420,10 +3453,10 @@
34203453
if (w.countdown < 0) {
34213454
clearInterval(w.countdownInterval);
34223455
w.countdownDiv.style.display = 'none';
3423-
w.contentDiv.innerHTML = 'Resuming soon...';
3456+
w.contentDiv.innerHTML = t.countdownResuming;
34243457
}
34253458
else {
3426-
w.countdownSpan.innerHTML = formatCountdown(w.countdown);
3459+
w.countdownSpan.innerHTML = t.formatCountdown(w.countdown);
34273460
}
34283461
}, 1000);
34293462
}
@@ -3505,27 +3538,14 @@
35053538
this.disable();
35063539
};
35073540

3508-
3509-
// ## Helper functions.
3510-
3511-
function formatCountdown(time) {
3512-
var out;
3513-
out = '';
3514-
time = J.parseMilliseconds(time);
3515-
if (time[2]) out += time[2] + ' min ';
3516-
if (time[3]) out += time[3] + ' sec';
3517-
return out || 0;
3518-
}
3519-
3520-
35213541
})(
35223542
('undefined' !== typeof node) ? node : module.parent.exports.node,
35233543
('undefined' !== typeof window) ? window : module.parent.exports.window
35243544
);
35253545

35263546
/**
35273547
* # InfoPanel
3528-
* Copyright(c) 2017 Stefano Balietti <ste@nodegame.org>
3548+
* Copyright(c) 2021 Stefano Balietti <ste@nodegame.org>
35293549
* MIT Licensed
35303550
*
35313551
* Adds a configurable extra panel at the top of the screen
@@ -3834,7 +3854,7 @@
38343854
* @see InfoPanel.toggleBtn
38353855
* @see InfoPanel.toggle
38363856
*/
3837-
InfoPanel.prototype.createToggleBtn =
3857+
InfoPanel.prototype.createToggleBtn =
38383858
InfoPanel.prototype.createToggleButton = function(label) {
38393859
var that, button;
38403860

@@ -3861,7 +3881,7 @@
38613881
})(
38623882
('undefined' !== typeof node) ? node : module.parent.exports.node,
38633883
('undefined' !== typeof window) ? window : module.parent.exports.window
3864-
);;
3884+
);
38653885

38663886
/**
38673887
* # selector

build/nodegame-window.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)