|
22 | 22 | var DOM;
|
23 | 23 |
|
24 | 24 | var constants, windowLevels, screenLevels;
|
25 |
| - var CB_EXECUTED, WIN_LOADING, lockedUpdate; |
| 25 | + var CB_EXECUTED, WIN_LOADING; |
26 | 26 |
|
27 | 27 | if (!J) throw new Error('GameWindow: JSUS not found');
|
28 | 28 | DOM = J.require('DOM');
|
|
36 | 36 |
|
37 | 37 | WIN_LOADING = windowLevels.LOADING;
|
38 | 38 |
|
39 |
| - // Allows just one update at the time to the counter of loading frames. |
40 |
| - lockedUpdate = false; |
41 |
| - |
42 | 39 | GameWindow.prototype = DOM;
|
43 | 40 | GameWindow.prototype.constructor = GameWindow;
|
44 | 41 |
|
|
62 | 59 | var iframeWin;
|
63 | 60 | iframeWin = iframe.contentWindow;
|
64 | 61 |
|
65 |
| - function completed(event) { |
66 |
| - var iframeDoc; |
67 |
| - iframeDoc = J.getIFrameDocument(iframe); |
68 |
| - |
| 62 | + function completed() { |
69 | 63 | // Detaching the function to avoid double execution.
|
70 | 64 | iframe.removeEventListener('load', completed, false);
|
71 | 65 | iframeWin.removeEventListener('load', completed, false);
|
|
853 | 847 | *
|
854 | 848 | * Appends a configurable div element at to "top" of the page
|
855 | 849 | *
|
856 |
| - * @param {object} opts Optional. Configuration options: TODO |
| 850 | + * @param {object} opts Optional. Configuration options: |
857 | 851 | *
|
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'. |
862 | 863 | *
|
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 |
866 | 866 | *
|
867 | 867 | * @return {InfoPanel} A reference to the InfoPanel object
|
868 | 868 | *
|
|
888 | 888 | opts.toggleBtn = false;
|
889 | 889 | }
|
890 | 890 | }
|
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.') |
896 | 892 | }
|
897 | 893 | else {
|
898 | 894 | this.infoPanel = new node.InfoPanel(opts);
|
|
902 | 898 |
|
903 | 899 | root = opts.root;
|
904 | 900 | if (root) {
|
| 901 | + if ('string' === typeof root) root = W.gid(root); |
905 | 902 | if (!J.isElement(root)) {
|
906 | 903 | throw new Error('GameWindow.generateInfoPanel: root must be ' +
|
907 | 904 | 'undefined or HTMLElement. Found: ' + root);
|
|
2369 | 2366 | * @param {GameWindow} that A reference to the GameWindow instance
|
2370 | 2367 | * @param {number} update The number to add to the counter
|
2371 | 2368 | *
|
2372 |
| - * @see GameWindow.lockedUpdate |
2373 |
| - * |
2374 | 2369 | * @api private
|
2375 | 2370 | */
|
2376 | 2371 | function updateAreLoading(that, update) {
|
|
2911 | 2906 | countdown);
|
2912 | 2907 | }
|
2913 | 2908 | this.setScreenLevel('LOCKING');
|
2914 |
| - text = text || 'Screen locked. Please wait...'; |
2915 | 2909 | this.waitScreen.lock(text, countdown);
|
2916 | 2910 | this.setScreenLevel('LOCKED');
|
2917 | 2911 | };
|
|
3082 | 3076 |
|
3083 | 3077 | /**
|
3084 | 3078 | * # WaitScreen
|
3085 |
| - * Copyright(c) 2018 Stefano Balietti |
| 3079 | + * Copyright(c) 2021 Stefano Balietti |
3086 | 3080 | * MIT Licensed
|
3087 | 3081 | *
|
3088 | 3082 | * Overlays the screen, disables inputs, and displays a message/timer
|
|
3098 | 3092 |
|
3099 | 3093 | // ## Meta-data
|
3100 | 3094 |
|
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'; |
3103 | 3097 |
|
3104 | 3098 | // ## Helper functions
|
3105 | 3099 |
|
|
3206 | 3200 | *
|
3207 | 3201 | * Instantiates a new WaitScreen object
|
3208 | 3202 | *
|
3209 |
| - * @param {object} options Optional. Configuration options |
| 3203 | + * @param {object} opts Optional. Configuration options |
3210 | 3204 | */
|
3211 |
| - function WaitScreen(options) { |
3212 |
| - options = options || {}; |
| 3205 | + function WaitScreen(opts) { |
| 3206 | + opts = opts || {}; |
3213 | 3207 |
|
3214 | 3208 | /**
|
3215 | 3209 | * ### WaitScreen.id
|
|
3218 | 3212 | *
|
3219 | 3213 | * @see WaitScreen.waitingDiv
|
3220 | 3214 | */
|
3221 |
| - this.id = options.id || 'ng_waitScreen'; |
| 3215 | + this.id = opts.id || 'ng_waitScreen'; |
3222 | 3216 |
|
3223 | 3217 | /**
|
3224 | 3218 | * ### WaitScreen.root
|
|
3227 | 3221 | *
|
3228 | 3222 | * @see WaitScreen.waitingDiv
|
3229 | 3223 | */
|
3230 |
| - this.root = options.root || null; |
| 3224 | + this.root = opts.root || null; |
3231 | 3225 |
|
3232 | 3226 | /**
|
3233 | 3227 | * ### WaitScreen.waitingDiv
|
|
3285 | 3279 | * ### WaitScreen.countdown
|
3286 | 3280 | *
|
3287 | 3281 | * Countdown of max waiting time
|
3288 |
| - * |
3289 |
| - * @see WaitScreen.countdown |
3290 | 3282 | */
|
3291 | 3283 | this.countdown = null;
|
3292 | 3284 |
|
| 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 | + |
3293 | 3296 | /**
|
3294 | 3297 | * ### WaitScreen.text
|
3295 | 3298 | *
|
3296 | 3299 | * Default texts for default events
|
3297 | 3300 | */
|
3298 | 3301 | 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 || |
3300 | 3309 | '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 || |
3302 | 3313 | '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 | + } |
3305 | 3336 | };
|
3306 | 3337 |
|
3307 | 3338 | /**
|
|
3368 | 3399 | * @see WaitScren.updateText
|
3369 | 3400 | */
|
3370 | 3401 | 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; |
3372 | 3405 | if ('undefined' === typeof document.getElementsByTagName) {
|
3373 |
| - node.warn('WaitScreen.lock: cannot lock inputs.'); |
| 3406 | + node.warn('WaitScreen.lock: cannot lock inputs'); |
3374 | 3407 | }
|
3375 | 3408 | // Disables all input forms in the page.
|
3376 | 3409 | lockUnlockedInputs(document);
|
|
3392 | 3425 | }
|
3393 | 3426 | this.contentDiv.innerHTML = text;
|
3394 | 3427 |
|
3395 |
| - if (countdown) { |
| 3428 | + if (this.displayCountdown && countdown) { |
| 3429 | + |
3396 | 3430 | if (!this.countdownDiv) {
|
3397 | 3431 | this.countdownDiv = W.add('div', this.waitingDiv,
|
3398 | 3432 | 'ng_waitscreen-countdown-div');
|
3399 | 3433 |
|
3400 |
| - this.countdownDiv.innerHTML = '<br>Do not refresh the page!' + |
3401 |
| - '<br>Maximum Waiting Time: '; |
| 3434 | + this.countdownDiv.innerHTML = t.countdown; |
3402 | 3435 |
|
3403 | 3436 | this.countdownSpan = W.add('span', this.countdownDiv,
|
3404 | 3437 | 'ng_waitscreen-countdown-span');
|
3405 | 3438 | }
|
3406 | 3439 |
|
3407 | 3440 | this.countdown = countdown;
|
3408 |
| - this.countdownSpan.innerHTML = formatCountdown(countdown); |
| 3441 | + this.countdownSpan.innerHTML = t.formatCountdown(countdown); |
3409 | 3442 | this.countdownDiv.style.display = '';
|
3410 | 3443 |
|
3411 | 3444 | this.countdownInterval = setInterval(function() {
|
|
3420 | 3453 | if (w.countdown < 0) {
|
3421 | 3454 | clearInterval(w.countdownInterval);
|
3422 | 3455 | w.countdownDiv.style.display = 'none';
|
3423 |
| - w.contentDiv.innerHTML = 'Resuming soon...'; |
| 3456 | + w.contentDiv.innerHTML = t.countdownResuming; |
3424 | 3457 | }
|
3425 | 3458 | else {
|
3426 |
| - w.countdownSpan.innerHTML = formatCountdown(w.countdown); |
| 3459 | + w.countdownSpan.innerHTML = t.formatCountdown(w.countdown); |
3427 | 3460 | }
|
3428 | 3461 | }, 1000);
|
3429 | 3462 | }
|
|
3505 | 3538 | this.disable();
|
3506 | 3539 | };
|
3507 | 3540 |
|
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 |
| - |
3521 | 3541 | })(
|
3522 | 3542 | ('undefined' !== typeof node) ? node : module.parent.exports.node,
|
3523 | 3543 | ('undefined' !== typeof window) ? window : module.parent.exports.window
|
3524 | 3544 | );
|
3525 | 3545 |
|
3526 | 3546 | /**
|
3527 | 3547 | * # InfoPanel
|
3528 |
| - * Copyright(c) 2017 Stefano Balietti <ste@nodegame.org> |
| 3548 | + * Copyright(c) 2021 Stefano Balietti <ste@nodegame.org> |
3529 | 3549 | * MIT Licensed
|
3530 | 3550 | *
|
3531 | 3551 | * Adds a configurable extra panel at the top of the screen
|
|
3834 | 3854 | * @see InfoPanel.toggleBtn
|
3835 | 3855 | * @see InfoPanel.toggle
|
3836 | 3856 | */
|
3837 |
| - InfoPanel.prototype.createToggleBtn = |
| 3857 | + InfoPanel.prototype.createToggleBtn = |
3838 | 3858 | InfoPanel.prototype.createToggleButton = function(label) {
|
3839 | 3859 | var that, button;
|
3840 | 3860 |
|
|
3861 | 3881 | })(
|
3862 | 3882 | ('undefined' !== typeof node) ? node : module.parent.exports.node,
|
3863 | 3883 | ('undefined' !== typeof window) ? window : module.parent.exports.window
|
3864 |
| -);; |
| 3884 | +); |
3865 | 3885 |
|
3866 | 3886 | /**
|
3867 | 3887 | * # selector
|
|
0 commit comments