From d67d720786818281413840737292ee3491e01a08 Mon Sep 17 00:00:00 2001 From: DKPlugins Date: Thu, 28 Jun 2018 16:29:21 +0300 Subject: [PATCH] Version 3.1.0 --- DKTools.js | 21340 +++++++++++++++++++++++++-------------------------- README.md | 14 +- 2 files changed, 10662 insertions(+), 10692 deletions(-) diff --git a/DKTools.js b/DKTools.js index 11f665f..e124838 100644 --- a/DKTools.js +++ b/DKTools.js @@ -3,7 +3,7 @@ Title: DKTools Author: DK (Denis Kuznetsov) Site: https://dk-plugins.ru E-mail: kuznetsovdenis96@gmail.com -Version: 3.0.0 +Version: 3.1.0 Release: 02.06.2018 First release: 13.01.2016 Supported languages: Russian, English @@ -14,14 +14,14 @@ Supported languages: Russian, English Автор: DK (Денис Кузнецов) Сайт: https://dk-plugins.ru E-mail: kuznetsovdenis96@gmail.com -Версия: 3.0.0 +Версия: 3.1.0 Релиз: 02.06.2018 Первый релиз: 13.01.2016 Поддерживаемые языки: Русский, Английский */ /*: -* @plugindesc v.3.0.0 Library for RPG Maker. Made with ♥ by DKPlugins +* @plugindesc v.3.1.0 Library for RPG Maker. Made with ♥ by DKPlugins * @author DK (Denis Kuznetsov) * @help @@ -29,7 +29,7 @@ E-mail: kuznetsovdenis96@gmail.com Title: DKTools Author: DK (Denis Kuznetsov) Site: https://dk-plugins.ru - Version: 3.0.0 + Version: 3.1.0 Release: 02.06.2018 First release: 13.01.2016 Supported languages: Russian, English @@ -57,6 +57,13 @@ E-mail: kuznetsovdenis96@gmail.com %minutes - Minutes %seconds - Seconds + ### Plugin commands ### + 1. Checks for plugins updates from DKPlugins + DKPluginsCheckUpdates + + 2. Open the debug console + OpenDebugConsole + ### Elements ### DKTools.Utils DKTools.Utils.String @@ -104,7 +111,9 @@ E-mail: kuznetsovdenis96@gmail.com DKTools.Window.Selectable DKTools.Scene - ### License and terms of use ### + ### Licenses and terms of use ### + + DKTools uses a third-party library "lodash": https://lodash.com/license Recent information about the terms of use: https://dk-plugins.ru/terms-of-use @@ -119,16 +128,9 @@ E-mail: kuznetsovdenis96@gmail.com * @param Debugging * @default --------------------------------- - * @param Open Console - * @parent Debug - * @text Debug console - * @desc Open the debug console when the game test starts ? - * @type boolean - * @default false - * @param Show FPS * @parent Debug - * @desc Show the FPS counter when the game starts ? + * @desc Show the FPS counter when the game test starts ? * @type boolean * @default false @@ -139,13 +141,19 @@ E-mail: kuznetsovdenis96@gmail.com * @parent Functions * @desc Check updates * @type struct - * @default {"Enabled":"false"} + * @default {"Enabled":"false","Show New Plugins":"false"} + + * @param Debug Console + * @parent Functions + * @desc Debug console + * @type struct + * @default {"Enabled":"None","Open On Error":"false"} * @param Screen Resolution * @parent Functions - * @desc Screen settings + * @desc Screen resolution * @type struct - * @default {"Enabled":"false","Screen Width":"816","Screen Height":"624"} + * @default {"Enabled":"false","Width":"816","Height":"624"} * @param Quick Start * @parent Functions @@ -169,17 +177,24 @@ E-mail: kuznetsovdenis96@gmail.com * @parent Functions * @desc Screenshots * @type struct - * @default {"Enabled":"false","Key Code":"44","Screenshot Path":"screenshots/","Screenshot Filename":"%year_%month_%day_%hours_%minutes_%seconds.png"} + * @default {"Enabled":"false","Key Code":"44","Path":"screenshots/","Filename":"%year_%month_%day_%hours_%minutes_%seconds.png","Type":"png","Quality":"0.9"} * @param Errors Log * @parent Functions + * @desc Errors logging * @type struct * @default {"Enabled":"None","Filename":"errors_log.txt","File Size":"10"} + * @param Tile Size + * @parent Functions + * @desc Tile size + * @type struct + * @default {"Enabled":"false","Size":"48"} + */ /*:ru -* @plugindesc v.3.0.0 Библиотека для RPG Maker. Сделано с ♥ от DKPlugins +* @plugindesc v.3.1.0 Библиотека для RPG Maker. Сделано с ♥ от DKPlugins * @author DK (Денис Кузнецов) * @help @@ -187,7 +202,7 @@ E-mail: kuznetsovdenis96@gmail.com Название: DKTools Автор: DK (Денис Кузнецов) Сайт: https://dk-plugins.ru - Версия: 3.0.0 + Версия: 3.1.0 Релиз: 02.06.2018 Первый релиз: 13.01.2016 Поддерживаемые языки: Русский, Английский @@ -215,6 +230,13 @@ E-mail: kuznetsovdenis96@gmail.com %minutes - Минуты %seconds - Секунды + ### Команды плагина ### + 1. Проверить обновления плагинов от DKPlugins + DKPluginsCheckUpdates + + 2. Открыть отладочную консоль + OpenDebugConsole + ### Элементы ### DKTools.Utils DKTools.Utils.String @@ -262,7 +284,9 @@ E-mail: kuznetsovdenis96@gmail.com DKTools.Window.Selectable DKTools.Scene - ### Лицензия и правила использования плагина ### + ### Лицензии и правила использования плагина ### + + DKTools использует стороннюю библиотеку "lodash": https://lodash.com/license Актуальная информация о правилах использования: https://dk-plugins.ru/terms-of-use @@ -278,13 +302,6 @@ E-mail: kuznetsovdenis96@gmail.com * @text Отладка * @default --------------------------------- - * @param Open Console - * @text Отладочная консоль - * @parent Debugging - * @desc Открыть отладочную консоль при запуске теста игры ? - * @type boolean - * @default false - * @param Show FPS * @text Отобразить FPS * @parent Debugging @@ -301,14 +318,21 @@ E-mail: kuznetsovdenis96@gmail.com * @parent Functions * @desc Проверка обновлений * @type struct - * @default {"Enabled":"false"} + * @default {"Enabled":"false","Show New Plugins":"false"} + + * @param Debug Console + * @text Отладочная консоль + * @parent Functions + * @desc Отладочная консоль + * @type struct + * @default {"Enabled":"None","Open On Error":"false"} * @param Screen Resolution * @text Разрешение экрана * @parent Functions * @desc Настройки разрешения экрана * @type struct - * @default {"Enabled":"false","Screen Width":"816","Screen Height":"624"} + * @default {"Enabled":"false","Width":"816","Height":"624"} * @param Quick Start * @text Быстрый старт @@ -336,7 +360,7 @@ E-mail: kuznetsovdenis96@gmail.com * @parent Functions * @desc Скриншоты * @type struct - * @default {"Enabled":"false","Key Code":"44","Screenshot Path":"screenshots/","Screenshot Filename":"%year_%month_%day_%hours_%minutes_%seconds.png"} + * @default {"Enabled":"false","Key Code":"44","Path":"screenshots/","Filename":"%year_%month_%day_%hours_%minutes_%seconds.png","Type":"png","Quality":"0.9"} * @param Errors Log * @text Логирование ошибок @@ -345,6 +369,13 @@ E-mail: kuznetsovdenis96@gmail.com * @type struct * @default {"Enabled":"None","Filename":"errors_log.txt","File Size":"10"} + * @param Tile Size + * @text Размер тайла + * @parent Functions + * @desc Размер тайла + * @type struct + * @default {"Enabled":"false","Size":"48"} + */ /*~struct~CheckUpdates: @@ -354,6 +385,12 @@ E-mail: kuznetsovdenis96@gmail.com * @type boolean * @default false + * @param Show New Plugins + * @text Show new plugins + * @desc Show new plugins ? Information is displayed in the console during the game test + * @type boolean + * @default false + */ /*~struct~CheckUpdates:ru @@ -364,6 +401,55 @@ E-mail: kuznetsovdenis96@gmail.com * @type boolean * @default false + * @param Show New Plugins + * @text Показать новые плагины + * @desc Показывать новые плагины ? Информация выводится в консоль при тесте игры + * @type boolean + * @default false + + */ + +/*~struct~DebugConsole: + + * @param Enabled + * @desc Open the debug console when the game starts ? + * @type select + * @option None + * @option Only Test + * @option Only Game + * @option Always + * @default None + + * @param Open On Error + * @text Open on error + * @desc Enable the debugging console when an error is received ? + * @type boolean + * @default false + + */ + +/*~struct~DebugConsole:ru + + * @param Enabled + * @text Включено + * @desc Открыть отладочную консоль при запуске игры ? + * @type select + * @option Никогда + * @value None + * @option Только тест + * @value Only Test + * @option Только игра + * @value Only Game + * @option Всегда + * @value Always + * @default None + + * @param Open On Error + * @text Открытие при ошибке + * @desc Включить отладочную консоль при получении ошибки ? + * @type boolean + * @default false + */ /*~struct~ScreenResolution: @@ -373,14 +459,14 @@ E-mail: kuznetsovdenis96@gmail.com * @type boolean * @default false - * @param Screen Width - * @desc Screen Width + * @param Width + * @desc Screen width * @type number * @min 0 * @default 816 - * @param Screen Height - * @desc Screen Height + * @param Height + * @desc Screen height * @type number * @min 0 * @default 624 @@ -395,14 +481,14 @@ E-mail: kuznetsovdenis96@gmail.com * @type boolean * @default false - * @param Screen Width + * @param Width * @text Ширина экрана * @desc Ширина экрана * @type number * @min 0 * @default 816 - * @param Screen Height + * @param Height * @text Высота экрана * @desc Высота экрана * @type number @@ -575,25 +661,51 @@ E-mail: kuznetsovdenis96@gmail.com /*~struct~Screenshots: * @param Enabled - * @desc Enable the Take Screenshot function ? + * @desc Enable the Screenshots function ? * @type boolean * @default false * @param Key Code - * @text Key Code - * @desc The key code that is responsible for saving the screenshot. 44 - PrintScreen + * @text Key code + * @desc The key code that is responsible for saving the screenshot. 122 - F11 * @type number - * @default 44 + * @default 122 - * @param Screenshot Path + * @param Path * @text Path for saving screenshots * @desc Local path for saving screenshots * @default screenshots/ - * @param Screenshot Filename + * @param Filename * @desc The entire list of templates is given in the help (1) * @default %year_%month_%day_%hours_%minutes_%seconds.png + * @param Type + * @text Screenshot type + * @desc Screenshot type + * @type select + * @option png + * @option jpeg + * @option webp + * @default png + + * @param Quality + * @text Screenshot quality + * @desc Screenshot quality + * @type select + * @option 0% + * @option 10% + * @option 20% + * @option 30% + * @option 40% + * @option 50% + * @option 60% + * @option 70% + * @option 80% + * @option 90% + * @option 100% + * @default 90% + */ /*~struct~Screenshots:ru @@ -606,20 +718,57 @@ E-mail: kuznetsovdenis96@gmail.com * @param Key Code * @text Код клавиши - * @desc Код клавиши, которая отвечает за сохранение скриншота. 44 - PrintScreen + * @desc Код клавиши, которая отвечает за сохранение скриншота. 122 - F11 * @type number - * @default 44 + * @default 122 - * @param Screenshot Path + * @param Path * @text Путь для сохранения скриншотов * @desc Локальный путь для сохранения скриншотов * @default screenshots/ - * @param Screenshot Filename + * @param Filename * @text Название файла скриншота * @desc Весь список шаблонов приведен в справке (1) * @default %year_%month_%day_%hours_%minutes_%seconds.png + * @param Type + * @text Тип скриншота + * @desc Тип скриншота + * @type select + * @option png + * @option jpeg + * @option webp + * @default png + + * @param Quality + * @text Качество скриншота + * @desc Качество скриншота + * @type select + * @option 0% + * @value 0 + * @option 10% + * @value 0.1 + * @option 20% + * @value 0.2 + * @option 30% + * @value 0.3 + * @option 40% + * @value 0.4 + * @option 50% + * @value 0.5 + * @option 60% + * @value 0.6 + * @option 70% + * @value 0.7 + * @option 80% + * @value 0.8 + * @option 90% + * @value 0.9 + * @option 100% + * @value 1 + * @default 90% + */ /*~struct~ErrorsLog: @@ -671,6 +820,38 @@ E-mail: kuznetsovdenis96@gmail.com */ +/*~struct~TileSize: + + * @param Enabled + * @desc Enable the function of resizing tiles ? + * @type boolean + * @default false + + * @param Size + * @desc Tile size + * @type number + * @min 1 + * @default 48 + + */ + +/*~struct~TileSize:ru + + * @param Enabled + * @text Включено + * @desc Включить функцию изменения размера тайла ? + * @type boolean + * @default false + + * @param Size + * @text Размер тайла + * @desc Размер тайла + * @type number + * @min 1 + * @default 48 + + */ + 'use strict'; //=========================================================================== @@ -828,7 +1009,7 @@ E-mail: kuznetsovdenis96@gmail.com * @type {Object} */ var Imported = Imported || {}; -Imported.DKTools = '3.0.0'; +Imported.DKTools = '3.1.0'; @@ -1131,7 +1312,9 @@ DKTools.Utils = class { constructor() { return DKTools.Utils; - }; + } + + // initialize methods /** * Initializes the utils @@ -1155,6 +1338,13 @@ DKTools.Utils = class { */ this._isNwjs = Utils.isNwjs(); + /** + * @private + * @readonly + * @type {Boolean} + */ + this._isTest = Utils.isOptionValid('test'); + /** * @private * @readonly @@ -1177,15 +1367,14 @@ DKTools.Utils = class { this._isAndroidChrome = Utils.isAndroidChrome(); this._sayHello(); - - if (DKToolsParam.get('Open Console')) { - this.openConsole(); - } + this.openConsole(); if (DKToolsParam.get('Check Updates', 'Enabled')) { this._checkUpdates(); } - }; + } + + // private methods /** * Displays information about the plugin in the debug console @@ -1213,7 +1402,7 @@ DKTools.Utils = class { } this._saidHello = true; - }; + } /** * Checks the updates @@ -1223,110 +1412,74 @@ DKTools.Utils = class { * @static */ static _checkUpdates() { - if (!this.isNwjs() || !Utils.isOptionValid('test')) { + if (!this.isNwjs() || !DKTools.Utils.isTest()) { return; } const xhr = new XMLHttpRequest(); - xhr.open('GET', 'https://api.github.com/repos/DKPlugins/DKTools/releases'); + xhr.open('GET', 'https://dk-plugins.ru/plugins.php'); xhr.overrideMimeType('application/json'); xhr.onload = function() { if (xhr.status < 400) { const response = JSON.parse(xhr.responseText); - if (response) { - const data = response[0]; - const newestVersion = data['tag_name']; + if (!Array.isArray(response)) { + return; + } + + _.forEach(response, function(plugin) { + const newVersion = plugin.version; - if (newestVersion > DKTools.version) { - const args = [`Available a new version of DKTools: ${newestVersion} \n`, - `Changelog: ${data['html_url']} \n`, - 'Download: http://dk-plugins.ru/download/DKTools.js']; + if (DKTools.PluginManager.isRegistered(plugin.name)) { + const currentVersion = DKTools.PluginManager.getVersion(plugin.name); + + if (newVersion > currentVersion) { + const args = [`Available a new version of ${plugin.name}: ${newVersion} \n`, + `Visit site: ${plugin.url} \n`, + `Download: http://dk-plugins.ru/download/${plugin.name}.js`]; + + console.log.apply(console, args); + } + } else if (DKToolsParam.get('Check Updates', 'Show New Plugins')) { + const args = [ + `Try the new plugin: ${plugin.name} \n`, + `Description: ${plugin.description} \n`, + `Visit site: ${plugin.url} \n`, + `Download: http://dk-plugins.ru/download/${plugin.name}.js`]; console.log.apply(console, args); } - } + }); } }; xhr.send(); - }; - - /** - * Copies properties of one object to another. - * Handles get/set properties correctly. - * Doesn't clone sub-objects - * - * @static - * @param {Object} target - A target to copy properties - * @param {Object} source - The source of properties - */ - static mixin(target, source) { - const properties = Object.getOwnPropertyNames(source); - - _.forEach(properties, function(property) { - const descriptor = Object.getOwnPropertyDescriptor(source, property); - - Object.defineProperty(target, property, descriptor); - }); - }; + } /** - * Opens the console - * + * Opens the debug console + * + * @since 3.1.0 + * @private * @static */ - static openConsole() { - if (!this.isNwjs() || !Utils.isOptionValid('test')) { + static _openConsole() { + if (!this.isNwjs()) { return; } try { const window = require('nw.gui').Window.get(); - window.showDevTools(null, function() { + window.showDevTools(null, function () { window.focus(); }); - } catch(e) { + } catch (e) { + this.logError(e); console.error('DKTools can not open the console'); } - }; - - /** - * Makes a screenshot - * - * @static - */ - static makeScreenshot() { - if (!DKTools.Utils.isNwjs()) { - return; - } - - const date = new Date(); - const snap = SceneManager.snap(); - const urlData = snap._canvas.toDataURL(); - const data = urlData.replace(/^data:image\/png;base64,/, ''); - const path = DKToolsParam.get('Screenshots', 'Screenshot Path'); - - let filename = DKToolsParam.get('Screenshots', 'Screenshot Filename'); - filename = filename.replace(/%year/gi, date.getFullYear()); - filename = filename.replace(/%month/gi, date.getMonth() + 1); - filename = filename.replace(/%day/gi, date.getDate()); - filename = filename.replace(/%hours/gi, date.getHours()); - filename = filename.replace(/%minutes/gi, date.getMinutes()); - filename = filename.replace(/%seconds/gi, date.getSeconds()); - - const fullPath = DKTools.IO.normalizePath(path + '/' + filename); - - const file = new DKTools.IO.File(fullPath); + } - file.save(data, { - createDirectory: true, - options: 'base64', - callback: function() { - console.log('The screenshot is saved with the name: ' + filename); - } - }); - }; + // is methods /** * Checks whether the platform is NW.js @@ -1336,7 +1489,18 @@ DKTools.Utils = class { */ static isNwjs() { return this._isNwjs; - }; + } + + /** + * Returns true if the game test is running + * + * @since 3.1.0 + * @static + * @returns {Boolean} Game test is running + */ + static isTest() { + return this._isTest; + } /** * Checks whether the platform is a mobile device. @@ -1346,7 +1510,7 @@ DKTools.Utils = class { */ static isMobileDevice() { return this._isMobileDevice; - }; + } /** * Checks whether the browser is Mobile Safari @@ -1356,7 +1520,7 @@ DKTools.Utils = class { */ static isMobileSafari() { return this._isMobileSafari; - }; + } /** * Checks whether the browser is Android Chrome @@ -1366,7 +1530,7 @@ DKTools.Utils = class { */ static isAndroidChrome() { return this._isAndroidChrome; - }; + } /** * Returns true if the value is array or object Arguments @@ -1382,7 +1546,7 @@ DKTools.Utils = class { } return String(value) === '[object Arguments]'; - }; + } /** * Returns true if the value is string @@ -1394,7 +1558,7 @@ DKTools.Utils = class { */ static isString(value) { return !!value && typeof value === 'string'; - }; + } /** * Returns true if the value is boolean @@ -1406,7 +1570,7 @@ DKTools.Utils = class { */ static isBoolean(value) { return typeof value === 'boolean'; - }; + } /** * Returns true if the value is function @@ -1418,54 +1582,208 @@ DKTools.Utils = class { */ static isFunction(value) { return typeof value === 'function'; - }; - -}; - - - + } + // other methods -//=========================================================================== -// DKTools.Utils.String -//=========================================================================== + /** + * Copies properties of one object to another. + * Handles get/set properties correctly. + * Doesn't clone sub-objects + * + * @static + * @param {Object} target - A target to copy properties + * @param {Object} source - The source of properties + */ + static mixin(target, source) { + const properties = Object.getOwnPropertyNames(source); -/** - * The static class that defines utility methods for String class - * - * @class DKTools.Utils.String - * @memberof DKTools.Utils - */ -DKTools.Utils.String = class { + _.forEach(properties, function(property) { + const descriptor = Object.getOwnPropertyDescriptor(source, property); - constructor() { - return DKTools.Utils.String; - }; + Object.defineProperty(target, property, descriptor); + }); + } /** - * Splits a string by commas into an array of string + * Opens the debug console * + * @version 3.1.0 * @static - * @param {String} string - String - * - * @example - * var array = DKTools.Utils.String.toStringArray('1, 2, 3'); - * => ['1', '2', '3'] - * - * var array = DKTools.Utils.String.toStringArray('1,2,3'); - * => ['1', '2', '3'] - * - * @returns {String[]} Array of strings */ - static toStringArray(string) { - return string.replace(/\s*\,\s*/g, ',').split(','); - }; + static openConsole() { + const param = DKToolsParam.get('Debug Console'); + const isTest = DKTools.Utils.isTest(); + const enabled = param.Enabled; + + if (enabled === 'None' || + enabled === 'Only Game' && isTest || + enabled === 'Only Test' && !isTest) { + return; + } + + this._openConsole(); + } /** - * Splits a string by commas into an array of numbers + * Makes a screenshot * + * @version 3.1.0 * @static - * @param {String} string - String + */ + static makeScreenshot() { + if (!this.isNwjs()) { + return; + } + + const path = DKToolsParam.get('Screenshots', 'Path'); + const type = DKToolsParam.get('Screenshots', 'Type'); + const quality = DKToolsParam.get('Screenshots', 'Quality'); + const snap = SceneManager.snap(); + const urlData = snap._canvas.toDataURL('image/' + type, quality); + const regex = new RegExp(`^data:image\/${type};base64,`); + const data = urlData.replace(regex, ''); + const date = new Date(); + + let filename = DKToolsParam.get('Screenshots', 'Filename'); + filename = filename.replace(/%year/gi, date.getFullYear()); + filename = filename.replace(/%month/gi, date.getMonth() + 1); + filename = filename.replace(/%day/gi, date.getDate()); + filename = filename.replace(/%hours/gi, date.getHours()); + filename = filename.replace(/%minutes/gi, date.getMinutes()); + filename = filename.replace(/%seconds/gi, date.getSeconds()); + + const fullName = filename + '.' + type; + const fullPath = DKTools.IO.normalizePath(path + '/' + fullName); + + const file = new DKTools.IO.File(fullPath); + + file.save(data, { + createDirectory: true, + options: 'base64', + callback: function() { + console.log('The screenshot is saved with the name: ' + fullName); + } + }); + } + + /** + * Logs the error to file + * + * @since 3.1.0 + * @param {Object | String} e - Error + * @static + */ + static logError(e) { + if (!e || !this.isNwjs()) { + return; + } + + const param = DKToolsParam.get('Errors Log'); + const isTest = DKTools.Utils.isTest(); + const enabled = param['Enabled']; + + if (enabled === 'None' || + enabled === 'Only Game' && isTest || + enabled === 'Only Test' && !isTest) { + return; + } + + const fs = DKTools.IO.fs; + const os = require('os'); + + if (!fs || !os) { + return; + } + + const fileSize = param['File Size'] * 1024 * 1024; + const filename = param['Filename']; + const file = new DKTools.IO.File(filename); + const stats = file.getStats({ sync: true }).data; + let fileDescription = fs.openSync(filename, 'a'); + + if (stats && stats.size > fileSize) { + fs.closeSync(fileDescription); + file.remove({ sync: true }); + fileDescription = fs.openSync(filename, 'a'); + } + + if (e instanceof Object) { + let data = `Date: ${new Date().toString()}` + os.EOL + + `Name: ${e.name}` + os.EOL + + `Message: ${e.message}` + os.EOL; + + if (e.filename !== undefined) { + data += `Filename: ${e.filename}` + os.EOL; + } + + if (e.lineNumber !== undefined) { + data += `Line: ${e.lineNumber}` + os.EOL; + } + + if (e.columnNumber !== undefined) { + data += `Column: ${e.columnNumber}` + os.EOL; + } + + data += `Stack: ${e.stack}` + os.EOL + os.EOL; + + fs.writeSync(fileDescription, data); + } else { + const data = `Date: ${new Date().toString()}` + os.EOL + + `Error: ${e}` + os.EOL + os.EOL; + + fs.writeSync(fileDescription, data); + } + + fs.closeSync(fileDescription); + } + +}; + + + + + +//=========================================================================== +// DKTools.Utils.String +//=========================================================================== + +/** + * The static class that defines utility methods for String class + * + * @class DKTools.Utils.String + * @memberof DKTools.Utils + */ +DKTools.Utils.String = class { + + constructor() { + return DKTools.Utils.String; + } + + /** + * Splits a string by commas into an array of string + * + * @static + * @param {String} string - String + * + * @example + * var array = DKTools.Utils.String.toStringArray('1, 2, 3'); + * => ['1', '2', '3'] + * + * var array = DKTools.Utils.String.toStringArray('1,2,3'); + * => ['1', '2', '3'] + * + * @returns {String[]} Array of strings + */ + static toStringArray(string) { + return string.replace(/\s*\,\s*/g, ',').split(','); + } + + /** + * Splits a string by commas into an array of numbers + * + * @static + * @param {String} string - String * * @example * var array = DKTools.Utils.String.toNumberArray('1, 2, 3'); @@ -1475,11 +1793,12 @@ DKTools.Utils.String = class { * => [1, 2, 3] * * @see DKTools.Utils.String.toStringArray + * * @returns {Number[]} Array of numbers */ static toNumberArray(string) { return _.map(this.toStringArray(string), Number); - }; + } /** * Splits a string by commas into an array of booleans @@ -1495,11 +1814,12 @@ DKTools.Utils.String = class { * => [true, true, false] * * @see DKTools.Utils.String.toStringArray + * * @returns {Boolean[]} Array of booleans */ static toBooleanArray(string) { return _.map(this.toStringArray(string), Boolean); - }; + } }; @@ -1521,7 +1841,7 @@ DKTools.Utils.Array = class { constructor() { return DKTools.Utils.Array; - }; + } /** * Checks whether the array contains a given item @@ -1544,7 +1864,7 @@ DKTools.Utils.Array = class { */ static contains(array, item) { return _.includes(array, item); - }; + } /** * Returns the number of item in the array @@ -1568,7 +1888,7 @@ DKTools.Utils.Array = class { */ static count(array, item) { return _.size(array) - _.size(_.without(array, item)); - }; + } /** * Returns the sum of the number of items in the array @@ -1588,7 +1908,7 @@ DKTools.Utils.Array = class { */ static counts(array, items) { return _.size(array) - _.size(_.difference(array, items)); - }; + } /** * Removes '', null, undefined and NaN from the array. @@ -1606,7 +1926,7 @@ DKTools.Utils.Array = class { */ static compact(array) { return _.pull(array, '', null, undefined, Number.NaN); - }; + } /** * Removes item from the array. @@ -1626,7 +1946,7 @@ DKTools.Utils.Array = class { */ static remove(array, item) { return _.pull(array, item); - }; + } /** * Inserts the item into the array. @@ -1645,7 +1965,7 @@ DKTools.Utils.Array = class { */ static insert(array, item, index) { array.splice(index || 0, 0, item); - }; + } /** * Checks whether the array is empty @@ -1657,7 +1977,7 @@ DKTools.Utils.Array = class { */ static isEmpty(array) { return _.isEmpty(array); - }; + } /** * Checks whether all elements of the array are of type Number @@ -1678,7 +1998,7 @@ DKTools.Utils.Array = class { */ static isNumberArray(array) { return _.every(array, Number.isFinite); - }; + } /** * Checks whether all elements of the array are of type Boolean @@ -1699,7 +2019,7 @@ DKTools.Utils.Array = class { */ static isBooleanArray(array) { return _.every(array, DKTools.Utils.isBoolean); - }; + } /** * Checks whether all elements of the array are of type String @@ -1721,7 +2041,7 @@ DKTools.Utils.Array = class { */ static isStringArray(array) { return _.every(array, DKTools.Utils.isString); - }; + } /** * Checks whether all elements of the array are of type Bitmap @@ -1744,7 +2064,7 @@ DKTools.Utils.Array = class { return _.every(array, function(item) { return item instanceof Bitmap; }); - }; + } /** * Checks whether all elements of the array are of type Sprite @@ -1767,7 +2087,7 @@ DKTools.Utils.Array = class { return _.every(array, function(item) { return item instanceof Sprite; }); - }; + } /** * Checks whether all elements of the array are of type Window @@ -1790,7 +2110,7 @@ DKTools.Utils.Array = class { return _.every(array, function(item) { return item instanceof Window; }); - }; + } /** * Performs a logical operation of the disjunction @@ -1811,7 +2131,7 @@ DKTools.Utils.Array = class { */ static disjunction(array) { return _.some(array, _.isEqual.bind(this, true)); - }; + } /** * Performs a logical operation of the conjunction @@ -1832,7 +2152,7 @@ DKTools.Utils.Array = class { */ static conjunction(array) { return _.every(array, _.isEqual.bind(this, true)); - }; + } }; @@ -1854,7 +2174,7 @@ DKTools.Utils.Bitmap = class { constructor() { return DKTools.Utils.Bitmap; - }; + } // load methods @@ -1902,7 +2222,7 @@ DKTools.Utils.Bitmap = class { } return bitmap; - }; + } /** * Loads the bitmaps and call the callback function when all bitmaps are ready @@ -1922,7 +2242,7 @@ DKTools.Utils.Bitmap = class { * filename: 'IconSet' * }; * - * DKTools.Utils.Bitmap.loadBitmaps(bitmaps, function(loadedBitmap, loadedBitmaps, allBitmaps) { + * DKTools.Utils.Bitmap.loadBitmaps(bitmaps, function(allBitmaps) { * // all loaded bitmaps * }); * @@ -1963,7 +2283,7 @@ DKTools.Utils.Bitmap = class { loadListener(index, bitmap); } }.bind(this)); - }; + } // reserve methods @@ -2011,7 +2331,7 @@ DKTools.Utils.Bitmap = class { } return bitmap; - }; + } /** * Loads and reserves the bitmaps and call the callback function when all bitmaps are ready @@ -2031,8 +2351,8 @@ DKTools.Utils.Bitmap = class { * filename: 'IconSet' * }; * - * DKTools.Utils.Bitmap.reserveBitmaps(bitmaps, function(loadedBitmap, loadedBitmaps, allBitmaps) { - * // your code here + * DKTools.Utils.Bitmap.reserveBitmaps(bitmaps, function(allBitmaps) { + * // all loaded bitmaps * }); * * @see DKTools.Utils.Bitmap.reserve @@ -2072,7 +2392,7 @@ DKTools.Utils.Bitmap = class { loadListener(index, bitmap); } }.bind(this)); - }; + } // draw methods @@ -2093,6 +2413,7 @@ DKTools.Utils.Bitmap = class { */ static drawLine(bitmap, x1, y1, x2, y2, color, lineWidth) { const context = bitmap._context; + context.save(); context.strokeStyle = color || 'white'; context.lineWidth = lineWidth || 1; @@ -2101,8 +2422,9 @@ DKTools.Utils.Bitmap = class { context.lineTo(x2, y2); context.stroke(); context.restore(); + bitmap._setDirty(); - }; + } /** * Draws a rectangle without fill @@ -2121,13 +2443,15 @@ DKTools.Utils.Bitmap = class { */ static strokeRect(bitmap, x, y, width, height, color, lineWidth) { const context = bitmap._context; + context.save(); context.strokeStyle = color || 'white'; context.lineWidth = lineWidth || 1; context.strokeRect(x, y, width, height); context.restore(); + bitmap._setDirty(); - }; + } /** * Draws an arc and fills it with color @@ -2147,14 +2471,16 @@ DKTools.Utils.Bitmap = class { */ static fillArc(bitmap, x, y, radius, startAngle, endAngle, color, anticlockwise) { const context = bitmap._context; + context.save(); context.fillStyle = color || 'white'; context.beginPath(); context.arc(x, y, radius, startAngle, endAngle, anticlockwise); context.fill(); context.restore(); + bitmap._setDirty(); - }; + } /** * Draws an arc without fill @@ -2175,6 +2501,7 @@ DKTools.Utils.Bitmap = class { */ static strokeArc(bitmap, x, y, radius, startAngle, endAngle, color, lineWidth, anticlockwise) { const context = bitmap._context; + context.save(); context.strokeStyle = color || 'white'; context.lineWidth = lineWidth || 1; @@ -2182,8 +2509,9 @@ DKTools.Utils.Bitmap = class { context.arc(x, y, radius, startAngle, endAngle, anticlockwise); context.stroke(); context.restore(); + bitmap._setDirty(); - }; + } // other methods @@ -2206,7 +2534,7 @@ DKTools.Utils.Bitmap = class { newContext.drawImage(canvas, 0, 0); return newBitmap; - }; + } }; @@ -2228,7 +2556,7 @@ DKTools.Utils.Point = class { constructor() { return DKTools.Utils.Point; - }; + } /** * Converts arguments to Point, if possible @@ -2276,7 +2604,7 @@ DKTools.Utils.Point = class { } return null; - }; + } /** * Converts the point into an array @@ -2295,7 +2623,7 @@ DKTools.Utils.Point = class { */ static toArray(point) { return [point.x, point.y]; - }; + } /** * Compares the coordinates of the points @@ -2320,7 +2648,7 @@ DKTools.Utils.Point = class { */ static equals(point1, point2) { return point1.x === point2.x && point1.y === point2.y; - }; + } /** * Clones the point @@ -2335,7 +2663,7 @@ DKTools.Utils.Point = class { newPoint.copy(point); return newPoint; - }; + } }; @@ -2357,7 +2685,7 @@ DKTools.Utils.Rectangle = class { constructor() { return DKTools.Utils.Rectangle; - }; + } /** * Converts arguments to Rectangle, if possible @@ -2413,7 +2741,7 @@ DKTools.Utils.Rectangle = class { } return null; - }; + } /** * Converts the rect into an array @@ -2432,7 +2760,7 @@ DKTools.Utils.Rectangle = class { */ static toArray(rect) { return [rect.x, rect.y, rect.width, rect.height]; - }; + } /** * Compares the coordinates, width and height of the rectangles @@ -2458,7 +2786,7 @@ DKTools.Utils.Rectangle = class { static equals(rect1, rect2) { return rect1.x === rect2.x && rect1.y === rect2.y && rect1.width === rect2.width && rect1.height === rect2.height; - }; + } /** * Checks whether the rect is empty (0, 0, 0, 0) @@ -2481,7 +2809,7 @@ DKTools.Utils.Rectangle = class { */ static isEmpty(rect) { return this.equals(rect, Rectangle.emptyRectangle); - }; + } /** * Clones the rect @@ -2496,7 +2824,7 @@ DKTools.Utils.Rectangle = class { newRect.copy(rect); return newRect; - }; + } }; @@ -2518,7 +2846,7 @@ DKTools.Utils.Random = class { constructor() { return DKTools.Utils.Random; - }; + } /** * Returns a random integer not exceeding max @@ -2529,7 +2857,7 @@ DKTools.Utils.Random = class { */ static getInt(max) { return _.random(0, max || 1); - }; + } /** * Returns a random float number not exceeding max @@ -2540,7 +2868,7 @@ DKTools.Utils.Random = class { */ static getFloat(max) { return _.random(0, max || 1, true); - }; + } /** * Returns a random boolean @@ -2550,7 +2878,7 @@ DKTools.Utils.Random = class { */ static getBoolean() { return this.getInt(1) % 2 === 0; - }; + } /** * Returns a random color in rgba format @@ -2570,7 +2898,7 @@ DKTools.Utils.Random = class { } return 'rgba(%1, %2, %3, %4)'.format(r, g, b, a); - }; + } /** * Returns a random color in hex format @@ -2580,7 +2908,7 @@ DKTools.Utils.Random = class { */ static getHexColor() { return '#' + (Math.random() * 0xFFFFFF << 0).toString(16); - }; + } }; @@ -2602,7 +2930,7 @@ DKTools.Utils.Sequence = class { constructor() { return DKTools.Utils.Sequence; - }; + } /** * Generator. Generates a sequence of integers. The number of values is limited by max. @@ -2617,12 +2945,12 @@ DKTools.Utils.Sequence = class { while (count <= max) { yield count++; } - }; + } /** * Generator. Generates a sequence of booleans. * - * @param [Boolean} [start=false] - The initial value of the sequence + * @param {Boolean} [start=false] - The initial value of the sequence * @returns {Boolean} The next value of the sequence */ static *Boolean(start) { @@ -2632,7 +2960,7 @@ DKTools.Utils.Sequence = class { value = !value; yield value; } - }; + } }; @@ -2654,7 +2982,7 @@ DKTools.Utils.Sequence.Alphabet = class { constructor() { return DKTools.Utils.Sequence.Alphabet; - }; + } /** * Generator. Generates a sequence of characters of the Russian alphabet @@ -2670,7 +2998,7 @@ DKTools.Utils.Sequence.Alphabet = class { } yield* alphabet; - }; + } /** * Generator. Generates a sequence of characters of the English alphabet @@ -2686,7 +3014,7 @@ DKTools.Utils.Sequence.Alphabet = class { } yield* alphabet; - }; + } }; @@ -2710,7 +3038,8 @@ DKTools.Utils.Event = class { /** * Returns the comments of the current page - * + * + * @version 3.1.0 * @static * * @param {Number | Game_Event} event - Event ID or Game_Event @@ -2722,7 +3051,7 @@ DKTools.Utils.Event = class { event = $gameMap.events()[event]; } - if (!event) { + if (!event || !event.page()) { return []; } @@ -2733,7 +3062,7 @@ DKTools.Utils.Event = class { return comments; }, []); - }; + } /** * Returns the comments of the all pages @@ -2768,7 +3097,7 @@ DKTools.Utils.Event = class { return acc; }, {}); - }; + } }; @@ -2886,35 +3215,37 @@ DKTools.IO = class { return false; }; - // other methods + // get methods /** - * Returns a normalized path + * Returns the absolute path to file or directory * + * @since 3.0.0 * @static * - * @param {String} path - Path for normalize - * - * @see Path.normalize + * @param {String} [path] - Path * - * @returns {String} Normalized path + * @returns {String} Absolute path to file or directory */ - static normalizePath(path) { - return this._path.normalize(path); + static getAbsolutePath(path) { + return this.normalizePath(this._path.join(this._projectPath, (path || ''))); }; + // other methods + /** - * Returns the absolute path to file or directory + * Returns a normalized path * - * @since 3.0.0 * @static * - * @param {String} [path] - Path + * @param {String} path - Path for normalize * - * @returns {String} Absolute path to file or directory + * @see Path.normalize + * + * @returns {String} Normalized path */ - static getAbsolutePath(path) { - return this.normalizePath(this._path.join(this._projectPath, (path || ''))); + static normalizePath(path) { + return this._path.normalize(path); }; /** @@ -3091,6 +3422,16 @@ Object.defineProperties(DKTools.IO, { */ ERROR_KEY_IS_NOT_AVAILABLE: { value: 8 }, + /** + * The options is not available for an operation + * + * @readonly + * @constant + * @type {Number} + * @memberof DKTools.IO + */ + ERROR_OPTIONS_IS_NOT_AVAILABLE: { value: 9 } + }); @@ -3270,8 +3611,9 @@ DKTools.IO.Entity = class { * DKTools.IO.ERROR_NOT_LOCAL_MODE * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE + * DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE * - * @version 3.0.0 + * @version 3.1.0 * @since 2.0.0 * * @param {Object} [object] - Options of an operation @@ -3285,6 +3627,10 @@ DKTools.IO.Entity = class { * @returns {Object} Loaded stats */ getStats(object) { + if (!object) { + return { data: null, status: DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE }; + } + if (!DKTools.IO.isLocalMode()) { return { data: null, status: DKTools.IO.ERROR_NOT_LOCAL_MODE }; } @@ -3329,7 +3675,7 @@ DKTools.IO.Entity = class { }; /** - * Renames the file + * Renames the file or directory * * Possible results: * DKTools.IO.OK @@ -3337,12 +3683,13 @@ DKTools.IO.Entity = class { * DKTools.IO.ERROR_NOT_LOCAL_MODE * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST * DKTools.IO.ERROR_NEW_NAME_IS_NOT_AVAILABLE + * DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE * - * @version 3.0.0 + * @version 3.1.0 * * @param {Object} object - Options of an operation * - * @param {String} object.newName - New name of file + * @param {String} object.newName - New name of entity without the extension * @param {Boolean} [object.sync] - Use synchronous version of rename * @param {String | Object} [object.options] - Options for rename or renameSync * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) @@ -3353,6 +3700,10 @@ DKTools.IO.Entity = class { * @returns {Number} Code of the result of an operation */ rename(object) { + if (!object) { + return DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE; + } + if (!DKTools.IO.isLocalMode()) { return DKTools.IO.ERROR_NOT_LOCAL_MODE; } @@ -3368,7 +3719,8 @@ DKTools.IO.Entity = class { const fs = DKTools.IO.fs; const newName = object.newName; const oldAbsolutePath = this.getAbsolutePath(); - const newAbsolutePath = DKTools.IO.getAbsolutePath(this._basePath, newName); + const newPath = DKTools.IO.normalizePath(this._path + '/' + newName + '.' + this._extension); + const newAbsolutePath = DKTools.IO.getAbsolutePath(newPath); if (!DKTools.IO.absolutePathExists(newAbsolutePath)) { if (object.sync) { @@ -3552,6 +3904,9 @@ DKTools.IO.File = class extends DKTools.IO.Entity { * DKTools.IO.ERROR_NOT_LOCAL_MODE * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE + * DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE + * + * @version 3.1.0 * * @param {Object} object - Options of an operation * @@ -3559,14 +3914,20 @@ DKTools.IO.File = class extends DKTools.IO.Entity { * @param {String | Object} [object.options] - Options for readFile or readFileSync * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) * @param {Boolean} [object.decompress] - Use LZString.decompressFromBase64 for a data - * @param {Boolean} [object.parse] - Use JSON.parse for a data + * @param {Boolean | Object} [object.parse] - Use JSON.parse for a data * + * @param {Function} [object.parse.reviver] - A function that transforms the results + * * @see FileSystem.readFile * @see FileSystem.readFileSync * * @returns {Object} Loaded data */ load(object) { + if (!object) { + return { data: null, status: DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE }; + } + if (!DKTools.IO.isLocalMode()) { return { data: null, status: DKTools.IO.ERROR_NOT_LOCAL_MODE }; } @@ -3584,7 +3945,9 @@ DKTools.IO.File = class extends DKTools.IO.Entity { data = LZString.decompressFromBase64(data); } - if (object.parse) { + if (object.parse instanceof Object) { + data = JSON.parse(data, object.parse.reviver); + } else if (object.parse) { data = JSON.parse(data); } } @@ -3628,11 +3991,17 @@ DKTools.IO.File = class extends DKTools.IO.Entity { /** * Loads the JSON file * + * @version 3.1.0 * @since 3.0.0 + * + * @param {Function} reviver - A function that transforms the results + * + * @see DKTools.IO.File.prototype.load + * * @returns {Object | null} Object or null */ - loadJson() { - return this.load({ sync: true, parse: true }).data; + loadJson(reviver) { + return this.load({ sync: true, parse: { reviver } }).data; }; /** @@ -3718,7 +4087,7 @@ DKTools.IO.File = class extends DKTools.IO.Entity { * DKTools.IO.ERROR_NOT_LOCAL_MODE * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST * - * @version 3.0.0 + * @version 3.1.0 * * @param {*} data - Data to save * @param {Object} object - Options of an operation @@ -3730,8 +4099,12 @@ DKTools.IO.File = class extends DKTools.IO.Entity { * @param {String | Object} [object.options] - Options for writeFile or writeFileSync * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) * + * @param {Function | Array} [object.stringify.replacer] - A function that transforms the results + * @param {Number | String} [object.stringify.space] - Insert white space into the output JSON string for readability purposes + * * @see FileSystem.writeFile * @see FileSystem.writeFileSync + * @see JSON.stringify * * @returns {Number} Code of the result of an operation */ @@ -3746,14 +4119,6 @@ DKTools.IO.File = class extends DKTools.IO.Entity { object = object || {}; - if (object.stringify) { - data = JSON.stringify(data); - } - - if (object.compress) { - data = LZString.compressToBase64(data); - } - if (object.createDirectory && !directory.exists()) { directory.create(); } @@ -3762,6 +4127,16 @@ DKTools.IO.File = class extends DKTools.IO.Entity { return DKTools.IO.ERROR_PATH_DOES_NOT_EXIST; } + if (object.stringify instanceof Object) { + data = JSON.stringify(data, object.stringify.replacer, object.stringify.space); + } else if (object.stringify) { + data = JSON.stringify(data); + } + + if (object.compress) { + data = LZString.compressToBase64(data); + } + if (object.sync) { fs.writeFileSync(absolutePath, data, object.options); @@ -3904,12 +4279,15 @@ DKTools.IO.Directory = class extends DKTools.IO.Entity { * DKTools.IO.ERROR_NOT_LOCAL_MODE * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE + * DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE * + * @version 3.1.0 + * * @param {Object} object - Options of an operation * * @param {Boolean} [object.sync] - Use synchronous version of readdir * @param {String | Object} [object.options] - Options for readdir or readdirSync - * @param {RegExp} [object.template] - Template for filtering + * @param {RegExp | String} [object.template] - Template for filtering * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) * * @see FileSystem.readdir @@ -3918,6 +4296,10 @@ DKTools.IO.Directory = class extends DKTools.IO.Entity { * @returns {Object} All files and directories */ getAll(object) { + if (!object) { + return { data: null, status: DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE }; + } + if (!DKTools.IO.isLocalMode()) { return { data: null, status: DKTools.IO.ERROR_NOT_LOCAL_MODE }; } @@ -3934,6 +4316,10 @@ DKTools.IO.Directory = class extends DKTools.IO.Entity { names = _.filter(names, function(name) { return object.template.test(name); }); + } else if (DKTools.Utils.isString(object.template)) { + names = _.filter(names, function(name) { + return name === object.template; + }); } return _.reduce(names, function(acc, name) { @@ -3953,7 +4339,6 @@ DKTools.IO.Directory = class extends DKTools.IO.Entity { const names = fs.readdirSync(absolutePath, object.options); return { data: processData(names) , status: DKTools.IO.OK }; - } else if (DKTools.Utils.isFunction(object.callback)) { fs.readdir(absolutePath, object.options, function(error, names) { if (error) { @@ -3983,6 +4368,9 @@ DKTools.IO.Directory = class extends DKTools.IO.Entity { * DKTools.IO.ERROR_NOT_LOCAL_MODE * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE + * DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE + * + * @version 3.1.0 * * @param {Object} object - Options of an operation * @@ -4039,6 +4427,9 @@ DKTools.IO.Directory = class extends DKTools.IO.Entity { * DKTools.IO.ERROR_NOT_LOCAL_MODE * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE + * DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE + * + * @version 3.1.0 * * @param {Object} object - Options of an operation * @@ -4095,7 +4486,9 @@ DKTools.IO.Directory = class extends DKTools.IO.Entity { * DKTools.IO.ERROR_NOT_LOCAL_MODE * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE - * + * DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE + * + * @version 3.1.0 * @since 3.0.0 * * @param {Object} object - Options of an operation @@ -4131,7 +4524,9 @@ DKTools.IO.Directory = class extends DKTools.IO.Entity { * DKTools.IO.ERROR_NOT_LOCAL_MODE * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE - * + * DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE + * + * @version 3.1.0 * @since 3.0.0 * * @param {Object} object - Options of an operation @@ -4167,7 +4562,9 @@ DKTools.IO.Directory = class extends DKTools.IO.Entity { * DKTools.IO.ERROR_NOT_LOCAL_MODE * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE + * DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE * + * @version 3.1.0 * @since 3.0.0 * * @param {Object} object - Options of an operation @@ -4203,7 +4600,9 @@ DKTools.IO.Directory = class extends DKTools.IO.Entity { * DKTools.IO.ERROR_NOT_LOCAL_MODE * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE - * + * DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE + * + * @version 3.1.0 * @since 3.0.0 * * @param {Object} object - Options of an operation @@ -4225,6 +4624,221 @@ DKTools.IO.Directory = class extends DKTools.IO.Entity { }); }; + // find methods + + /** + * Finds the files + * + * Returns an object with 2 properties: + * status - Result of an operation + * data - Array with files (only if the status is equal to DKTools.IO.OK) + * if the status is not equal to DKTools.IO.OK then data will be null + * + * Possible results: + * DKTools.IO.OK + * DKTools.IO.WAIT_FOR_ASYNC_OPERATION + * DKTools.IO.ERROR_NOT_LOCAL_MODE + * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST + * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE + * DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE + * + * @since 3.1.0 + * + * @param {Object} object - Options of an operation + * + * @param {Boolean} [object.sync] - Use synchronous version of readdir + * @param {String | Object} [object.options] - Options for readdir or readdirSync + * @param {RegExp | String} [object.template] - Template for filtering + * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) + * @param {Boolean} [object.cyclical] - Search in subdirectories + * + * @example + * var directory = new DKTools.IO.Directory('img/'); + * var directories = directory.findFiles({ sync: true, cyclical: true, template: 'Window.png' }); + * + * @see DKTools.IO.Directory.prototype.getAll + * + * @returns {Object} All files + */ + findFiles(object) { + if (!object) { + return { data: null, status: DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE }; + } + + if (!DKTools.IO.isLocalMode()) { + return { data: null, status: DKTools.IO.ERROR_NOT_LOCAL_MODE }; + } + + if (!this.exists()) { + return { data: null, status: DKTools.IO.ERROR_PATH_DOES_NOT_EXIST }; + } + + if (!object.sync && !DKTools.Utils.isFunction(object.callback)) { + return { data: null, status: DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE }; + } + + const files = []; + let total = 1, processed = 0; + + const processData = function(data) { + _.forEach(data, function(entity) { + if (entity.isFile()) { + const fullName = entity.getFullName(); + + if (object.template instanceof RegExp && object.template.test(fullName)) { + files.push(entity); + } else if (!object.template || fullName === object.template) { + files.push(entity); + } + } else if (entity.isDirectory()) { + total++; + + if (object.cyclical) { + processDirectory(entity); + } + } + }); + }; + + const processDirectory = function(directory) { + if (object.sync) { + const data = directory.getAll({ + sync: true, + options: object.options + }).data; + + processData(data); + } else { + directory.getAll({ + options: object.options, + callback: function(data) { + processed++; + + processData(data); + + if (total === processed) { + object.callback(files); + } + } + }); + } + }; + + processDirectory(this); + + if (object.sync) { + return { data: files, status: DKTools.IO.OK }; + } else { + return { data: null, status: DKTools.IO.WAIT_FOR_ASYNC_OPERATION }; + } + }; + + /** + * Finds the directories + * + * Returns an object with 2 properties: + * status - Result of an operation + * data - Array with directories (only if the status is equal to DKTools.IO.OK) + * if the status is not equal to DKTools.IO.OK then data will be null + * + * Possible results: + * DKTools.IO.OK + * DKTools.IO.WAIT_FOR_ASYNC_OPERATION + * DKTools.IO.ERROR_NOT_LOCAL_MODE + * DKTools.IO.ERROR_PATH_DOES_NOT_EXIST + * DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE + * DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE + * + * @since 3.1.0 + * + * @param {Object} object - Options of an operation + * + * @param {Boolean} [object.sync] - Use synchronous version of readdir + * @param {String | Object} [object.options] - Options for readdir or readdirSync + * @param {RegExp | String} [object.template] - Template for filtering + * @param {Function} [object.callback] - Callback function upon completion of an operation (only for object.sync == false) + * @param {Boolean} [object.cyclical] - Search in subdirectories + * + * @example + * var directory = new DKTools.IO.Directory('img/'); + * var directories = directory.findDirectories({ sync: true, template: 'system' }); + * + * @see DKTools.IO.Directory.prototype.getDirectories + * + * @returns {Object} All directories + */ + findDirectories(object) { + if (!object) { + return { data: null, status: DKTools.IO.ERROR_OPTIONS_IS_NOT_AVAILABLE }; + } + + if (!DKTools.IO.isLocalMode()) { + return { data: null, status: DKTools.IO.ERROR_NOT_LOCAL_MODE }; + } + + if (!this.exists()) { + return { data: null, status: DKTools.IO.ERROR_PATH_DOES_NOT_EXIST }; + } + + if (!object.sync && !DKTools.Utils.isFunction(object.callback)) { + return { data: null, status: DKTools.IO.ERROR_CALLBACK_IS_NOT_AVAILABLE }; + } + + const directories = []; + let total = 1, processed = 0; + + const processData = function(data) { + _.forEach(data, function(directory) { + const fullName = directory.getFullName(); + + if (object.template instanceof RegExp && object.template.test(fullName)) { + directories.push(directory); + } else if (!object.template || fullName === object.template) { + directories.push(directory); + } + + total++; + + if (object.cyclical) { + processDirectory(directory); + } + }); + }; + + const processDirectory = function(directory) { + if (object.sync) { + const data = directory.getDirectories({ + sync: true, + options: object.options + }).data; + + processData(data); + } else { + directory.getDirectories({ + options: object.options, + template: object.template, + callback: function(data) { + processed++; + + processData(data); + + if (total === processed) { + object.callback(directories); + } + } + }); + } + }; + + processDirectory(this); + + if (object.sync) { + return { data: directories, status: DKTools.IO.OK }; + } else { + return { data: null, status: DKTools.IO.WAIT_FOR_ASYNC_OPERATION }; + } + }; + // audio methods /** @@ -4556,8 +5170,8 @@ DKTools.IO.WebStorage = class { * DKTools.IO.ERROR_NEW_NAME_IS_NOT_AVAILABLE * * @static - * @param {String} oldkey - Old key - * @param {String} newkey - New key + * @param {String} oldKey - Old key + * @param {String} newKey - New key * @returns {Number} Code of the result of an operation */ static rename(oldKey, newKey) { @@ -4816,7 +5430,7 @@ DKTools.PluginManager = class { static _checkRequirements() { _.forEach(this._requirements, function(pluginInfo, pluginName) { const maxVersion = _.max(pluginInfo); - const pluginVersion = this.pluginVersion(pluginName); + const pluginVersion = this.getVersion(pluginName); if (pluginVersion === undefined) { const error = 'Required to install the plugin "%1". Minimal version: %2'.format(pluginName, maxVersion); @@ -4926,14 +5540,17 @@ DKTools.PluginManager = class { /** * Returns a version of plugin * + * @since 3.1.0 + * @static + * + * @param {String} pluginName - Name of plugin + * * @example - * DKTools.PluginManager.pluginVersion('DKTools'); // => '3.0.0' + * DKTools.PluginManager.getVersion('DKTools'); // => '3.1.0' * - * @static - * @param {String | String} pluginName - Name of plugin * @returns {Number | String | undefined} Version of plugin */ - static pluginVersion(pluginName) { + static getVersion(pluginName) { return this._plugins[pluginName]; }; @@ -5134,7 +5751,7 @@ DKTools.PreloadManager = class { static _log(message) { if (!DKToolsParam.get('Preload Manager', 'Enabled') || !DKToolsParam.get('Preload Manager', 'Debugging') || - !Utils.isOptionValid('test') || !message) { + !DKTools.Utils.isTest() || !message) { return; } @@ -5274,6 +5891,7 @@ DKTools.PreloadManager = class { * @static * * @param {String} path - Path of the cached bitmap + * @param {Number} [hue] - Hue * * @see DKTools.PreloadManager.releaseByKey */ @@ -5301,7 +5919,7 @@ DKTools.PreloadManager = class { * * @static * - * @param {Object} - Object with parameters + * @param {Object} object - Object with parameters * * @param {String} object.path - Path to file or directory * @param {Number} [object.hue] - Hue @@ -6613,11 +7231,12 @@ DKTools.Event = class { /** * Updates the pause * + * @version 3.1.0 * @private */ _updatePause() { - this._updateRemainingPauseTime(); this._callOnPauseHandler(); + this._updateRemainingPauseTime(); }; /** @@ -7183,6 +7802,7 @@ DKTools.Animation.Action = class extends DKTools.Event { const rotation = (this._data - target.rotation) / remainingTime; const newRotation = target.rotation + rotation; + target.setRotation(newRotation); }.bind(action)); @@ -7211,6 +7831,7 @@ DKTools.Animation.Action = class extends DKTools.Event { const opacity = (this._data - target.opacity) / remainingTime; const newOpacity = target.opacity + opacity; + target.setOpacity(newOpacity); }.bind(action)); @@ -7241,12 +7862,14 @@ DKTools.Animation.Action = class extends DKTools.Event { const contentsOpacity = (this._data.contentsOpacity - target.contentsOpacity) / remainingTime; const frameOpacity = (this._data.frameOpacity - target.frameOpacity) / remainingTime; const backOpacity = (this._data.backOpacity - target.backOpacity) / remainingTime; + const newOpacity = { windowOpacity: target.windowOpacity + windowOpacity, contentsOpacity: target.contentsOpacity + contentsOpacity, frameOpacity: target.frameOpacity + frameOpacity, backOpacity: target.backOpacity + backOpacity }; + target.setOpacity(newOpacity); }.bind(action)); @@ -7274,6 +7897,7 @@ DKTools.Animation.Action = class extends DKTools.Event { const tint = (this._data - target.tint) / remainingTime; const newTint = target.tint + tint; + target.setTint(newTint); }.bind(action)); @@ -7297,6 +7921,7 @@ DKTools.Animation.Action = class extends DKTools.Event { action.setOnUpdateHandler(function() { const audio = this._data; + if (!audio.isPlaying()) { audio.play(); } @@ -7328,6 +7953,7 @@ DKTools.Animation.Action = class extends DKTools.Event { const y = (this._data.y - target.y) / remainingTime; const newX = target.x + x; const newY = target.y + y; + target.move(newX, newY); }.bind(action)); @@ -7360,6 +7986,7 @@ DKTools.Animation.Action = class extends DKTools.Event { const y = (data.y - scale.y) / remainingTime; const newX = scale.x + x; const newY = scale.y + y; + target.setScale(newX, newY); }.bind(action)); @@ -7391,6 +8018,7 @@ DKTools.Animation.Action = class extends DKTools.Event { const y = (data.y - pivot.y) / remainingTime; const newX = pivot.x + x; const newY = pivot.y + y; + target.setPivot(newX, newY); }.bind(action)); @@ -7422,6 +8050,7 @@ DKTools.Animation.Action = class extends DKTools.Event { const y = (data.y - skew.y) / remainingTime; const newX = skew.x + x; const newY = skew.y + y; + target.setSkew(newX, newY); }.bind(action)); @@ -7455,6 +8084,7 @@ DKTools.Animation.Action = class extends DKTools.Event { const width = (data.width - frame.width) / remainingTime; const height = (data.height - frame.height) / remainingTime; const newFrame = new Rectangle(frame.x + x, frame.y + y, frame.width + width, frame.height + height); + target.setFrame(newFrame); }.bind(action)); @@ -7487,6 +8117,7 @@ DKTools.Animation.Action = class extends DKTools.Event { const y = (data.y - anchor.y) / remainingTime; const newX = anchor.x + x; const newY = anchor.y + y; + target.setAnchor(newX, newY); }.bind(action)); @@ -7521,6 +8152,7 @@ DKTools.Animation.Action = class extends DKTools.Event { const newR = tone[0] + toneR; const newG = tone[1] + toneG; const newB = tone[2] + toneB; + target.setTone([newR, newG, newB]); }.bind(action)); @@ -7546,10 +8178,9 @@ DKTools.Animation.Action = class extends DKTools.Event { action.setOnUpdateHandler(function() { const remainingTime = this.getRemainingTime(); const target = this._target; - const openness = (255 - target.openness) / remainingTime; - const newOpennes = target.openness + openness; - target.openness = newOpennes; + + target.openness = target.openness + openness; }.bind(action)); return action; @@ -7577,6 +8208,7 @@ DKTools.Animation.Action = class extends DKTools.Event { const openness = -target.openness / remainingTime; const newOpennes = target.openness + openness; + target.openness = newOpennes; }.bind(action)); @@ -10117,7 +10749,7 @@ DKTools.Base = class { * @param {Boolean} [object.visible] - Visibility of the object * @param {Boolean} [object.active] - Activity of the object * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [object.scale] - Scale of the object - * @param {PPIXI.Point | PIXI.ObservablePoint | Point | Object} [object.pivot] - Pivot of the object + * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [object.pivot] - Pivot of the object * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [object.skew] - Skew of the object * @param {Number} [object.rotation] - Rotation of the object * @param {Number} [object.tint] - Tint of the object @@ -10291,7 +10923,7 @@ DKTools.Base = class { * @param {Boolean} [object.visible] - Visibility of the object * @param {Boolean} [object.active] - Activity of the object * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [object.scale] - Scale of the object - * @param {PPIXI.Point | PIXI.ObservablePoint | Point | Object} [object.pivot] - Pivot of the object + * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [object.pivot] - Pivot of the object * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [object.skew] - Skew of the object * @param {Number} [object.rotation] - Rotation of the object * @param {Number} [object.tint] - Tint of the object @@ -11468,7 +12100,7 @@ DKTools.Base = class { * * @since 2.0.0 * @param {Sprite | Window} object - Object - * @returns {Bboolean} Object (parameter) is parent of this object + * @returns {Boolean} Object (parameter) is parent of this object */ isParent(object) { return object && this.parent === object; @@ -11491,7 +12123,7 @@ DKTools.Base = class { * @param {Object} [options={}] - Options for drawing * * @param {Object} [options.wrap] - Options for text wrap - * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [object.pos] - Position of the text + * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [options.pos] - Position of the text * @param {Number} [options.x=0] - The X coordinate (if object.pos is undefined or null) * @param {Number | String} [options.y=0] - The Y coordinate or line number (String) (if object.pos is undefined or null) * @@ -11499,8 +12131,8 @@ DKTools.Base = class { * @param {Number} [options.wrap.maxLines] - Max lines * @param {Boolean} [options.wrap.breakWords] - Breaks a words for the wrapping * - * @param {Number} [object.pos.x=0] - The X coordinate - * @param {Number | String} [object.pos.y=0] - The Y coordinate or line number (String) + * @param {Number} [options.pos.x=0] - The X coordinate + * @param {Number | String} [options.pos.y=0] - The Y coordinate or line number (String) * * @see DKTools.Base.prototype.hasBitmap * @see DKTools.Base.prototype.textWrap @@ -12171,8 +12803,10 @@ DKTools.Base = class { * Fills the bitmap with gradient * Returns true if bitmap exists * - * @param {String} [object.color1='black'] - First color - * @param {String} [object.color2='white'] - Second color + * @version 3.1.0 + * + * @param {String} [color1='black'] - First color + * @param {String} [color2='white'] - Second color * @param {Boolean} [vertical=false] - Vertical gradient * * @see DKTools.Base.prototype.gradientFillRect @@ -12180,7 +12814,7 @@ DKTools.Base = class { * @returns {Boolean} Bitmap exists */ gradientFillAll(color1, color2, vertical) { - return this.gradientFillAll({ color1, color2, vartical }); + return this.gradientFillRect({ color1, color2, vartical }); }; // draw text ex methods @@ -12485,2690 +13119,2276 @@ DKTools.Base = class { return Window_Base.prototype.obtainEscapeParam.call(this, textState); }; - // load methods + // options methods /** - * Loads a bitmap from img/animations/ - * Returns true if the bitmap of the object has been changed - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap + * Clears the options * - * @see Bitmap.prototype.addLoadListener + * @since 2.0.0 * - * @returns {Boolean} Bitmap of the object has been changed + * @see DKTools.OptionManager.prototype.clear */ - loadAnimation(object, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap('img/animations/', object.filename, object.listener, object.hue, object.smooth); - } + clearOptions() { + this._optionManager.clear(); + }; - // object - String - return this.loadBitmap('img/animations/', object, listener, hue, smooth); + /** + * Returns true if the option is enabled + * + * @version 2.0.0 + * + * @param {String} option - Name of the option + * + * @see DKTools.OptionManager.prototype.isOptionEnabled + * + * @returns {Boolean} Option is enabled + */ + isOptionEnabled(option) { + return this._optionManager.isOptionEnabled(option); }; /** - * Loads a bitmap from img/battlebacks1/ - * Returns true if the bitmap of the object has been changed + * Returns conjunction of the options * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see Bitmap.prototype.addLoadListener - * - * @returns {Boolean} Bitmap of the object has been changed + * @version 2.0.0 + * + * @param {String[] | ...String} object - Names of the options + * + * @see DKTools.OptionManager.prototype.isOptionsEnabled + * + * @returns {Boolean} Conjunction of the options */ - loadBattleback1(object, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap('img/battlebacks1/', object.filename, object.listener, object.hue, object.smooth); - } - - // object - String - return this.loadBitmap('img/battlebacks1/', object, listener, hue, smooth); + isOptionsEnabled(object) { + return this._optionManager.isOptionsEnabled.apply(this._optionManager, arguments); }; /** - * Loads a bitmap from img/battlebacks2/ - * Returns true if the bitmap of the object has been changed + * Returns disjunction of the options * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @since 2.0.0 * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {String[] | ...String} object - Names of the options * - * @see Bitmap.prototype.addLoadListener + * @see DKTools.OptionManager.prototype.isSomeOptionsEnabled * - * @returns {Boolean} Bitmap of the object has been changed + * @returns {Boolean} Disjunction of the options */ - loadBattleback2(object, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap('img/battlebacks2/', object.filename, object.listener, object.hue, object.smooth); - } - - // object - String - return this.loadBitmap('img/battlebacks2/', object, listener, hue, smooth); + isSomeOptionsEnabled(object) { + return this._optionManager.isSomeOptionsEnabled.apply(this._optionManager, arguments); }; /** - * Loads a bitmap from img/enemies/ - * Returns true if the bitmap of the object has been changed + * Returns true if the option is disabled * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @version 2.0.0 * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {String} option - Name of the option * - * @see Bitmap.prototype.addLoadListener + * @see DKTools.OptionManager.prototype.isOptionDisabled * - * @returns {Boolean} Bitmap of the object has been changed + * @returns {Boolean} Option is disabled */ - loadEnemy(object, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap('img/enemies/', object.filename, object.listener, object.hue, object.smooth); - } - - // object - String - return this.loadBitmap('img/enemies/', object, listener, hue, smooth); + isOptionDisabled(option) { + return this._optionManager.isOptionDisabled(option); }; /** - * Loads a bitmap from img/characters/ - * Returns true if the bitmap of the object has been changed - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see Bitmap.prototype.addLoadListener + * Returns conjunction of the options * - * @returns {Boolean} Bitmap of the object has been changed + * @version 2.0.0 + * + * @param {String[] | ...String} object - Names of the options + * + * @see DKTools.OptionManager.prototype.isOptionsDisabled + * + * @returns {Boolean} Conjunction of the options */ - loadCharacter(object, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap('img/characters/', object.filename, object.listener, object.hue, object.smooth); - } - - // object - String - return this.loadBitmap('img/characters/', object, listener, hue, smooth); + isOptionsDisabled(object) { + return this._optionManager.isOptionsDisabled.apply(this._optionManager, arguments); }; /** - * Loads a bitmap from img/faces/ - * Returns true if the bitmap of the object has been changed + * Returns disjunction of the options * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @since 2.0.0 * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {String[] | ...String} object - Names of the options * - * @see Bitmap.prototype.addLoadListener + * @see DKTools.OptionManager.prototype.isSomeOptionsDisabled * - * @returns {Boolean} Bitmap of the object has been changed + * @returns {Boolean} Disjunction of the options */ - loadFace(object, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap('img/faces/', object.filename, object.listener, object.hue, object.smooth); - } - - // object - String - return this.loadBitmap('img/faces/', object, listener, hue, smooth); + isSomeOptionsDisabled(object) { + return this._optionManager.isSomeOptionsDisabled.apply(this._optionManager, arguments); }; /** - * Loads a bitmap from img/parallaxes/ - * Returns true if the bitmap of the object has been changed - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * Returns true if some option is enabled * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap + * @since 2.0.0 * - * @see Bitmap.prototype.addLoadListener + * @see DKTools.OptionManager.prototype.isSomeOptionEnabled * - * @returns {Boolean} Bitmap of the object has been changed + * @returns {Boolean} Some option is enabled */ - loadParallax(object, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap('img/parallaxes/', object.filename, object.listener, object.hue, object.smooth); - } - - // object - String - return this.loadBitmap('img/parallaxes/', object, listener, hue, smooth); + isSomeOptionEnabled() { + return this._optionManager.isSomeOptionEnabled(); }; /** - * Loads a bitmap from img/pictures/ - * Returns true if the bitmap of the object has been changed - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see Bitmap.prototype.addLoadListener + * Adds a listener of change of the option * - * @returns {Boolean} Bitmap of the object has been changed + * @version 2.0.0 + * + * @param {String} option - Name of the option + * @param {Function} listener - Listener + * + * @see DKTools.OptionManager.prototype.addOptionChangeListener */ - loadPicture(object, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap('img/pictures/', object.filename, object.listener, object.hue, object.smooth); - } - - // object - String - return this.loadBitmap('img/pictures/', object, listener, hue, smooth); + addOptionChangeListener(option, listener) { + this._optionManager.addOptionChangeListener(options, listener); }; /** - * Loads a bitmap from img/sv_actors/ - * Returns true if the bitmap of the object has been changed - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see Bitmap.prototype.addLoadListener - * - * @returns {Boolean} Bitmap of the object has been changed + * Removes the listener of change of the option + * + * @since 2.0.0 + * + * @param {String} option - Name of the option + * @param {Function} listener - Listener + * + * @see DKTools.OptionManager.prototype.removeOptionChangeListener */ - loadSvActor(object, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap('img/sv_actors/', object.filename, object.listener, object.hue, object.smooth); - } - - // object - String - return this.loadBitmap('img/sv_actors/', object, listener, hue, smooth); + removeOptionChangeListener(option, listener) { + this._optionManager.removeOptionsChangeListener(option, listener); }; /** - * Loads a bitmap from img/sv_enemies/ - * Returns true if the bitmap of the object has been changed - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see Bitmap.prototype.addLoadListener + * Turns on the option * - * @returns {Boolean} Bitmap of the object has been changed + * @version 2.0.0 + * + * @param {String} option - Name of the option + * + * @see DKTools.OptionManager.prototype.enableOption */ - loadSvEnemy(object, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap('img/sv_enemies/', object.filename, object.listener, object.hue, object.smooth); - } - - // object - String - return this.loadBitmap('img/sv_enemies/', object, listener, hue, smooth); + enableOption(option) { + this._optionManager.enableOption(option); }; /** - * Loads a bitmap from img/system/ - * Returns true if the bitmap of the object has been changed - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see Bitmap.prototype.addLoadListener + * Turns on the options * - * @returns {Boolean} Bitmap of the object has been changed + * @version 2.0.0 + * + * @param {String[] | ...String} object - Names of the options + * + * @see DKTools.OptionManager.prototype.enableOptions */ - loadSystem(object, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap('img/system/', object.filename, object.listener, object.hue, object.smooth); - } - - // object - String - return this.loadBitmap('img/system/', object, listener, hue, smooth); + enableOptions(object) { + this._optionManager.enableOptions.apply(this._optionManager, arguments); }; /** - * Loads a bitmap from img/tilesets/ - * Returns true if the bitmap of the object has been changed - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see Bitmap.prototype.addLoadListener + * Turns off the option * - * @returns {Boolean} Bitmap of the object has been changed + * @version 2.0.0 + * + * @param {String} option - Name of the option + * + * @see DKTools.OptionManager.prototype.disableOption */ - loadTileset(object, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap('img/tilesets/', object.filename, object.listener, object.hue, object.smooth); - } - - // object - String - return this.loadBitmap('img/tilesets/', object, listener, hue, smooth); + disableOption(option) { + this._optionManager.disableOption(option); }; /** - * Loads a bitmap from img/titles1/ - * Returns true if the bitmap of the object has been changed - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see Bitmap.prototype.addLoadListener + * Turns off the options * - * @returns {Boolean} Bitmap of the object has been changed + * @version 2.0.0 + * + * @param {String[] | ...String} object - Names of the options + * + * @see DKTools.OptionManager.prototype.disableOptions */ - loadTitle1(object, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap('img/titles1/', object.filename, object.listener, object.hue, object.smooth); - } - - // object - String - return this.loadBitmap('img/titles1/', object, listener, hue, smooth); + disableOptions(object) { + this._optionManager.disableOptions.apply(this._optionManager, arguments); }; /** - * Loads a bitmap from img/titles2/ - * Returns true if the bitmap of the object has been changed + * Switches the option * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see Bitmap.prototype.addLoadListener - * - * @returns {Boolean} Bitmap of the object has been changed + * @version 2.0.0 + * + * @param {String} option - Name of the option + * + * @see DKTools.OptionManager.prototype.switchOption */ - loadTitle2(object, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadBitmap('img/titles2/', object.filename, object.listener, object.hue, object.smooth); - } - - // object - String - return this.loadBitmap('img/titles2/', object, listener, hue, smooth); + switchOption(option) { + this._optionManager.switchOption(option); }; /** - * Loads a windowskin from img/system/ - * Returns true if the bitmap of the object has been changed - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see Bitmap.prototype.addLoadListener + * Switches the options * - * @returns {Boolean} Bitmap of the object has been changed + * @version 2.0.0 + * + * @param {String[] | ...String} object - Names of the options + * + * @see DKTools.OptionManager.prototype.switchOptions */ - loadWindowskin(object, listener, hue, smooth) { - if (object instanceof Object) { - return this.loadSystem(object.filename || this.standardWindowskin(), object.listener, object.hue, object.smooth); - } - - // object - String - return this.loadSystem(object || this.standardWindowskin(), listener, hue, smooth); + switchOptions(object) { + this._optionManager.switchOptions.apply(this._optionManager, arguments); }; - // reserve methods + // events methods /** - * Loads and reserves a bitmap from img/animations/ - * Returns true if the bitmap of the object has been changed - * - * @version 3.0.0 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) + * Clears the events * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * @version 2.0.0 * - * @see Bitmap.prototype.addLoadListener + * @param {String[] | String} object Array with event types or event type * - * @returns {Boolean} Bitmap of the object has been changed + * @see DKTools.EventManager.prototype.clearEvents */ - reserveAnimation(object, listener, hue, smooth, reservationId) { - if (object instanceof Object) { - return this.reserveBitmap('img/animations/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); - } - - // object - String - return this.reserveBitmap('img/animations/', object, listener, hue, smooth, reservationId); + clearEvents(object) { + this._eventManager.clearEvents(object); }; /** - * Loads and reserves a bitmap from img/battlebacks1/ - * Returns true if the bitmap of the object has been changed - * - * @version 3.0.0 + * Removes the event from a container + * Returns true if the event was removed * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) + * @version 2.0.0 * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * @param {DKTools.Event | DKTools.Animation} event - Event * - * @see Bitmap.prototype.addLoadListener + * @see DKTools.EventManager.prototype.removeEvent * - * @returns {Boolean} Bitmap of the object has been changed + * @returns {Boolean} Event was removed */ - reserveBattleback1(object, listener, hue, smooth, reservationId) { - if (object instanceof Object) { - return this.reserveBitmap('img/battlebacks1/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); - } - - // object - String - return this.reserveBitmap('img/battlebacks1/', object, listener, hue, smooth, reservationId); + removeEvent(event) { + return this._eventManager.removeEvent(event); }; /** - * Loads and reserves a bitmap from img/battlebacks2/ - * Returns true if the bitmap of the object has been changed - * - * @version 3.0.0 + * Performs a callback function for the events * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) + * @version 2.0.0 * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID - * - * @see Bitmap.prototype.addLoadListener + * @param {String} type - Type of the events + * @param {Function} callback - Event processing function * - * @returns {Boolean} Bitmap of the object has been changed + * @see DKTools.EventManager.prototype.iterateEventsContainer */ - reserveBattleback2(object, listener, hue, smooth, reservationId) { - if (object instanceof Object) { - return this.reserveBitmap('img/battlebacks2/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); - } - - // object - String - return this.reserveBitmap('img/battlebacks2/', object, listener, hue, smooth, reservationId); + iterateEventsContainer(type, callback) { + this._eventManager.iterateEventsContainer(type, callback); }; /** - * Loads and reserves a bitmap from img/enemies/ - * Returns true if the bitmap of the object has been changed + * Checks the events for pause + * Returns the conjunction of pauses of the events * - * @version 3.0.0 + * @version 2.0.0 * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) + * @param {String} type - Type of the events * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID - * - * @see Bitmap.prototype.addLoadListener + * @see DKTools.EventManager.prototype.isEventsPaused * - * @returns {Boolean} Bitmap of the object has been changed + * @returns {Boolean} Conjunction of pauses of the events */ - reserveEnemy(object, listener, hue, smooth, reservationId) { - if (object instanceof Object) { - return this.reserveBitmap('img/enemies/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); - } - - // object - String - return this.reserveBitmap('img/enemies/', object, listener, hue, smooth, reservationId); + isEventsPaused(type) { + return this._eventManager.isEventsPaused(type); }; /** - * Loads and reserves a bitmap from img/characters/ - * Returns true if the bitmap of the object has been changed - * - * @version 3.0.0 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) + * Pauses the events * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * @version 2.0.0 * - * @see Bitmap.prototype.addLoadListener + * @param {String} type - Type of the events + * @param {Number} duration - Duration of pause * - * @returns {Boolean} Bitmap of the object has been changed + * @see DKTools.EventManager.prototype.pauseEvents */ - reserveCharacter(object, listener, hue, smooth, reservationId) { - if (object instanceof Object) { - return this.reserveBitmap('img/characters/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); - } - - // object - String - return this.reserveBitmap('img/characters/', object, listener, hue, smooth, reservationId); + pauseEvents(type, duration) { + this._eventManager.pauseEvents(type, duration); }; /** - * Loads and reserves a bitmap from img/faces/ - * Returns true if the bitmap of the object has been changed - * - * @version 3.0.0 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) + * Resumes the events * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * @version 2.0.0 * - * @see Bitmap.prototype.addLoadListener + * @param {String} type - Type of the events * - * @returns {Boolean} Bitmap of the object has been changed + * @see DKTools.EventManager.prototype.resumeEvents */ - reserveFace(object, listener, hue, smooth, reservationId) { - if (object instanceof Object) { - return this.reserveBitmap('img/faces/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); - } - - // object - String - return this.reserveBitmap('img/faces/', object, listener, hue, smooth, reservationId); + resumeEvents(type) { + this._eventManager.resumeEvents(type); }; /** - * Loads and reserves a bitmap from img/parallaxes/ - * Returns true if the bitmap of the object has been changed - * - * @version 3.0.0 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) + * Finishes the events * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * @version 2.0.0 * - * @see Bitmap.prototype.addLoadListener + * @param {String} type - Type of the events + * @param {Boolean} [forcedSuccess] - Forced success for the finish of the events * - * @returns {Boolean} Bitmap of the object has been changed + * @see DKTools.EventManager.prototype.finishEvents */ - reserveParallax(object, listener, hue, smooth, reservationId) { - if (object instanceof Object) { - return this.reserveBitmap('img/parallaxes/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); - } - - // object - String - return this.reserveBitmap('img/parallaxes/', object, listener, hue, smooth, reservationId); + finishEvents(type, forcedSuccess) { + this._eventManager.finishEvents(type, forcedSuccess); }; /** - * Loads and reserves a bitmap from img/pictures/ - * Returns true if the bitmap of the object has been changed - * - * @version 3.0.0 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) + * Stops the events * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * @version 2.0.0 * - * @see Bitmap.prototype.addLoadListener + * @param {String} type - Type of the events + * @param {Boolean} [forcedSuccess] - Forced success for the finish of the events * - * @returns {Boolean} Bitmap of the object has been changed + * @see DKTools.EventManager.prototype.stopEvents */ - reservePicture(object, listener, hue, smooth, reservationId) { - if (object instanceof Object) { - return this.reserveBitmap('img/pictures/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); - } - - // object - String - return this.reserveBitmap('img/pictures/', object, listener, hue, smooth, reservationId); + stopEvents(type, forcedSuccess) { + this._eventManager.stopEvents(type, forcedSuccess); }; /** - * Loads and reserves a bitmap from img/sv_actors/ - * Returns true if the bitmap of the object has been changed - * - * @version 3.0.0 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * Updates the events * - * @see Bitmap.prototype.addLoadListener + * @version 2.0.0 * - * @returns {Boolean} Bitmap of the object has been changed + * @see DKTools.EventManager.prototype.update + * @see DKTools.Base.protoype.updateReadyEvents + * @see DKTools.Base.protoype.updateUpdateEvents + * @see DKTools.Base.protoype.updateQueueEvents + * @see DKTools.Base.protoype.updateWheelEvents */ - reserveSvActor(object, listener, hue, smooth, reservationId) { - if (object instanceof Object) { - return this.reserveBitmap('img/sv_actors/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); - } - - // object - String - return this.reserveBitmap('img/sv_actors/', object, listener, hue, smooth, reservationId); + updateEvents() { + this._eventManager.update(); + this.updateReadyEvents(); + this.updateUpdateEvents(); + this.updateQueueEvents(); }; /** - * Loads and reserves a bitmap from img/sv_enemies/ - * Returns true if the bitmap of the object has been changed + * Updates the event * - * @version 3.0.0 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID - * - * @see Bitmap.prototype.addLoadListener + * @param {DKTools.Event | DKTools.Animation} event - Event * - * @returns {Boolean} Bitmap of the object has been changed + * @see DKTools.EventManager.prototype.updateEvent */ - reserveSvEnemy(object, listener, hue, smooth, reservationId) { - if (object instanceof Object) { - return this.reserveBitmap('img/sv_enemies/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); - } - - // object - String - return this.reserveBitmap('img/sv_enemies/', object, listener, hue, smooth, reservationId); + updateEvent(event) { + this._eventManager.updateEvent(event); }; /** - * Loads and reserves a bitmap from img/system/ - * Returns true if the bitmap of the object has been changed - * - * @version 3.0.0 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) + * Updates the events from container * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * @version 2.0.0 * - * @see Bitmap.prototype.addLoadListener + * @param {String} type - Type of the events * - * @returns {Boolean} Bitmap of the object has been changed + * @see DKTools.EventManager.prototype.updateEventsContainer */ - reserveSystem(object, listener, hue, smooth, reservationId) { - if (object instanceof Object) { - return this.reserveBitmap('img/system/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); - } - - // object - String - return this.reserveBitmap('img/system/', object, listener, hue, smooth, reservationId); + updateEventsContainer(type) { + this._eventManager.updateEventsContainer(type); }; /** - * Loads and reserves a bitmap from img/tilesets/ - * Returns true if the bitmap of the object has been changed - * - * @version 3.0.0 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * Updates the events with type: remove-all-children * - * @see Bitmap.prototype.addLoadListener + * @version 2.0.0 * - * @returns {Boolean} Bitmap of the object has been changed + * @see DKTools.EventManager.prototype.updateEventsContainer */ - reserveTileset(object, listener, hue, smooth, reservationId) { - if (object instanceof Object) { - return this.reserveBitmap('img/tilesets/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); - } - - // object - String - return this.reserveBitmap('img/tilesets/', object, listener, hue, smooth, reservationId); + updateRemoveAllChildrenEvents() { + this.updateEventsContainer('remove-all-children'); }; /** - * Loads and reserves a bitmap from img/titles1/ - * Returns true if the bitmap of the object has been changed - * - * @version 3.0.0 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * Updates the events with type: terminate-all-children * - * @see Bitmap.prototype.addLoadListener + * @version 2.0.0 * - * @returns {Boolean} Bitmap of the object has been changed + * @see DKTools.EventManager.prototype.updateEventsContainer */ - reserveTitle1(object, listener, hue, smooth, reservationId) { - if (object instanceof Object) { - return this.reserveBitmap('img/titles1/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); - } - - // object - String - return this.reserveBitmap('img/titles1/', object, listener, hue, smooth, reservationId); + updateTerminateAllEvents() { + this.updateEventsContainer('terminate-all-children'); }; /** - * Loads and reserves a bitmap from img/titles2/ - * Returns true if the bitmap of the object has been changed - * - * @version 3.0.0 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * Updates the events with type: remove-all * - * @see DKTools.Base.prototype.reserveBitmap - * @see Bitmap.prototype.addLoadListener + * @version 2.0.0 * - * @returns {Boolean} Bitmap of the object has been changed + * @see DKTools.EventManager.prototype.updateEventsContainer */ - reserveTitle2(object, listener, hue, smooth, reservationId) { - if (object instanceof Object) { - return this.reserveBitmap('img/titles2/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); - } - - // object - String - return this.reserveBitmap('img/titles2/', object, listener, hue, smooth, reservationId); + updateRemoveAllEvents() { + this.updateEventsContainer('remove-all'); }; /** - * Loads and reserves a windowskin from img/system/ - * Returns true if the bitmap of the object has been changed - * - * @version 3.0.0 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * Updates the events with type: check-all * - * @see DKTools.Base.prototype.standardWindowskin - * @see DKTools.Base.prototype.reserveSystem - * @see Bitmap.prototype.addLoadListener + * @version 2.0.0 * - * @returns {Boolean} Bitmap of the object has been changed + * @see DKTools.EventManager.prototype.updateEventsContainer */ - reserveWindowskin(object, listener, hue, smooth, reservationId) { - if (object instanceof Object) { - return this.reserveSystem(object.filename || this.standardWindowskin(), object.listener, object.hue, object.smooth, object.reservationId); - } - - // object - String - return this.reserveSystem(object || this.standardWindowskin(), listener, hue, smooth, reservationId); + updateCheckAllEvents() { + this.updateEventsContainer('check-all'); }; - // options methods - /** - * Clears the options + * Updates the events with type: create-all * - * @since 2.0.0 + * @version 2.0.0 * - * @see DKTools.OptionManager.prototype.clear + * @see DKTools.EventManager.prototype.updateEventsContainer */ - clearOptions() { - this._optionManager.clear(); + updateCreateAllEvents() { + this.updateEventsContainer('create-all'); }; /** - * Returns true if the option is enabled + * Updates the events with type: start-all * * @version 2.0.0 - * - * @param {String} option - Name of the option - * - * @see DKTools.OptionManager.prototype.isOptionEnabled - * - * @returns {Boolean} Option is enabled + * + * @see DKTools.EventManager.prototype.updateEventsContainer */ - isOptionEnabled(option) { - return this._optionManager.isOptionEnabled(option); + updateStartAllEvents() { + this.updateEventsContainer('start-all'); }; /** - * Returns conjunction of the options + * Updates the events with type: add-all-children * * @version 2.0.0 - * - * @param {String[] | ...String} object - Names of the options - * - * @see DKTools.OptionManager.prototype.isOptionsEnabled - * - * @returns {Boolean} Conjunction of the options + * + * @see DKTools.EventManager.prototype.updateEventsContainer */ - isOptionsEnabled(object) { - return this._optionManager.isOptionsEnabled.apply(this._optionManager, arguments); + updateAddAllChildrenEvents() { + this.updateEventsContainer('add-all-children'); }; /** - * Returns disjunction of the options - * - * @since 2.0.0 - * - * @param {String[] | ...String} object - Names of the options + * Updates the events with type: refresh-all * - * @see DKTools.OptionManager.prototype.isSomeOptionsEnabled + * @version 2.0.0 * - * @returns {Boolean} Disjunction of the options + * @see DKTools.EventManager.prototype.updateEventsContainer */ - isSomeOptionsEnabled(object) { - return this._optionManager.isSomeOptionsEnabled.apply(this._optionManager, arguments); + updateRefreshAllEvents() { + this.updateEventsContainer('refresh-all'); }; /** - * Returns true if the option is disabled + * Updates the events with type: update-all * * @version 2.0.0 * - * @param {String} option - Name of the option - * - * @see DKTools.OptionManager.prototype.isOptionDisabled - * - * @returns {Boolean} Option is disabled + * @see DKTools.EventManager.prototype.updateEventsContainer */ - isOptionDisabled(option) { - return this._optionManager.isOptionDisabled(option); + updateUpdateAllEvents() { + this.updateEventsContainer('update-all'); }; /** - * Returns conjunction of the options + * Updates the events with type: redraw-all * * @version 2.0.0 - * - * @param {String[] | ...String} object - Names of the options - * - * @see DKTools.OptionManager.prototype.isOptionsDisabled - * - * @returns {Boolean} Conjunction of the options + * + * @see DKTools.EventManager.prototype.updateEventsContainer */ - isOptionsDisabled(object) { - return this._optionManager.isOptionsDisabled.apply(this._optionManager, arguments); + updateRedrawAllEvents() { + this.updateEventsContainer('redraw-all'); }; /** - * Returns disjunction of the options - * - * @since 2.0.0 - * - * @param {String[] | ...String} object - Names of the options - * - * @see DKTools.OptionManager.prototype.isSomeOptionsDisabled + * Updates the events with type: start * - * @returns {Boolean} Disjunction of the options + * @see DKTools.EventManager.prototype.updateEventsContainer */ - isSomeOptionsDisabled(object) { - return this._optionManager.isSomeOptionsDisabled.apply(this._optionManager, arguments); + updateStartEvents() { + if (this.isStarted()) { + this.updateEventsContainer('start'); + } }; /** - * Returns true if some option is enabled - * - * @since 2.0.0 - * - * @see DKTools.OptionManager.prototype.isSomeOptionEnabled + * Updates the events with type: ready * - * @returns {Boolean} Some option is enabled + * @see DKTools.EventManager.prototype.updateEventsContainer */ - isSomeOptionEnabled() { - return this._optionManager.isSomeOptionEnabled(); + updateReadyEvents() { + if (this.isReady()) { + this.updateEventsContainer('ready'); + } }; /** - * Adds a listener of change of the option + * Updates the events with type: update * - * @version 2.0.0 - * - * @param {String} option - Name of the option - * @param {Function} listener - Listener - * - * @see DKTools.OptionManager.prototype.addOptionChangeListener + * @see DKTools.EventManager.prototype.updateEventsContainer */ - addOptionChangeListener(option, listener) { - this._optionManager.addOptionChangeListener(options, listener); + updateUpdateEvents() { + this.updateEventsContainer('update'); }; /** - * Removes the listener of change of the option - * - * @since 2.0.0 - * - * @param {String} option - Name of the option - * @param {Function} listener - Listener - * - * @see DKTools.OptionManager.prototype.removeOptionChangeListener + * Updates the events with type: queue + * + * @see DKTools.EventManager.prototype.updateEventsContainer */ - removeOptionChangeListener(option, listener) { - this._optionManager.removeOptionsChangeListener(option, listener); + updateQueueEvents() { + const container = this.getEventsContainerByType('queue'); + const event = container[0]; + this.updateEvent(event); }; /** - * Turns on the option + * Updates the events with type: activate * - * @version 2.0.0 - * - * @param {String} option - Name of the option - * - * @see DKTools.OptionManager.prototype.enableOption + * @see DKTools.EventManager.prototype.updateEventsContainer */ - enableOption(option) { - this._optionManager.enableOption(option); + updateActivateEvents() { + this.updateEventsContainer('activate'); }; /** - * Turns on the options + * Updates the events with type: deactivate * - * @version 2.0.0 - * - * @param {String[] | ...String} object - Names of the options - * - * @see DKTools.OptionManager.prototype.enableOptions + * @see DKTools.EventManager.prototype.updateEventsContainer */ - enableOptions(object) { - this._optionManager.enableOptions.apply(this._optionManager, arguments); + updateDeactivateEvents() { + this.updateEventsContainer('deactivate'); }; /** - * Turns off the option + * Updates the events with type: show * - * @version 2.0.0 - * - * @param {String} option - Name of the option - * - * @see DKTools.OptionManager.prototype.disableOption + * @see DKTools.EventManager.prototype.updateEventsContainer */ - disableOption(option) { - this._optionManager.disableOption(option); + updateShowEvents() { + this.updateEventsContainer('show'); }; /** - * Turns off the options + * Updates the events with type: hide * - * @version 2.0.0 - * - * @param {String[] | ...String} object - Names of the options - * - * @see DKTools.OptionManager.prototype.disableOptions + * @see DKTools.EventManager.prototype.updateEventsContainer */ - disableOptions(object) { - this._optionManager.disableOptions.apply(this._optionManager, arguments); + updateHideEvents() { + this.updateEventsContainer('hide'); }; /** - * Switches the option + * Updates the events with type: mouse-enter * * @version 2.0.0 - * - * @param {String} option - Name of the option - * - * @see DKTools.OptionManager.prototype.switchOption + * + * @see DKTools.EventManager.prototype.updateEventsContainer */ - switchOption(option) { - this._optionManager.switchOption(option); + updateMouseEnterEvents() { + this.updateEventsContainer('mouse-enter'); }; /** - * Switches the options + * Updates the events with type: mouse-inside * - * @version 2.0.0 - * - * @param {String[] | ...String} object - Names of the options - * - * @see DKTools.OptionManager.prototype.switchOptions + * @since 2.0.0 + * + * @see DKTools.EventManager.prototype.updateEventsContainer */ - switchOptions(object) { - this._optionManager.switchOptions.apply(this._optionManager, arguments); + updateMouseInsideEvents() { + this.updateEventsContainer('mouse-inside'); }; - // events methods - /** - * Clears the events - * - * @version 2.0.0 + * Updates the events with type: mouse-move * - * @param {String[] | String} object Array with event types or event type + * @since 2.0.0 * - * @see DKTools.EventManager.prototype.clearEvents + * @see DKTools.EventManager.prototype.updateEventsContainer */ - clearEvents(object) { - this._eventManager.clearEvents(object); + updateMouseMoveEvents() { + this.updateEventsContainer('mouse-move'); }; /** - * Removes the event from a container - * Returns true if the event was removed + * Updates the events with type: mouse-leave * * @version 2.0.0 * - * @param {DKTools.Event | DKTools.Animation} event - Event + * @see DKTools.EventManager.prototype.updateEventsContainer + */ + updateMouseLeaveEvents() { + this.updateEventsContainer('mouse-leave'); + }; + + /** + * Updates the events with type: mouse-outside * - * @see DKTools.EventManager.prototype.removeEvent + * @since 2.0.0 * - * @returns {Boolean} Event was removed + * @see DKTools.EventManager.prototype.updateEventsContainer */ - removeEvent(event) { - return this._eventManager.removeEvent(event); + updateMouseOutsideEvents() { + this.updateEventsContainer('mouse-outside'); }; /** - * Performs a callback function for the events + * Updates the events with type: wheel-X-inside or wheel-X-outside * * @version 2.0.0 * - * @param {String} type - Type of the events - * @param {Function} callback - Event processing function + * @param {String} type Type of the wheel event (inside or outside) * - * @see DKTools.EventManager.prototype.iterateEventsContainer + * @see DKTools.EventManager.prototype.updateEventsContainer */ - iterateEventsContainer(type, callback) { - this._eventManager.iterateEventsContainer(type, callback); + updateWheelXEvents(type) { + this.updateEventsContainer('wheel-X-' + type); }; /** - * Checks the events for pause - * Returns the conjunction of pauses of the events + * Updates the events with type: wheel-Y-inside or wheel-Y-outside * * @version 2.0.0 * - * @param {String} type - Type of the events - * - * @see DKTools.EventManager.prototype.isEventsPaused + * @param {String} type - Type of the wheel event (inside or outside) * - * @returns {Boolean} Conjunction of pauses of the events + * @see DKTools.EventManager.prototype.updateEventsContainer */ - isEventsPaused(type) { - return this._eventManager.isEventsPaused(type); + updateWheelYEvents(type) { + this.updateEventsContainer('wheel-Y-' + type); }; /** - * Pauses the events + * Returns a container for the events by event type * * @version 2.0.0 * * @param {String} type - Type of the events - * @param {Number} duration - Duration of pause * - * @see DKTools.EventManager.prototype.pauseEvents + * @see DKTools.EventManager.prototype.getEventsContainerByType + * + * @returns {Array} Container for the events */ - pauseEvents(type, duration) { - this._eventManager.pauseEvents(type, duration); + getEventsContainerByType(type) { + return this._eventManager.getEventsContainerByType(type); }; /** - * Resumes the events + * Returns a container for the events by event * * @version 2.0.0 * - * @param {String} type - Type of the events + * @param {DKTools.Event | DKTools.Animation} event - Event * - * @see DKTools.EventManager.prototype.resumeEvents + * @see DKTools.EventManager.prototype.getEventsContainer + * + * @returns {Array} Container for the events */ - resumeEvents(type) { - this._eventManager.resumeEvents(type); + getEventsContainer(event) { + return this._eventManager.getEventsContainer(event); }; /** - * Finishes the events + * Returns an index of the event in its container * * @version 2.0.0 * - * @param {String} type - Type of the events - * @param {Boolean} [forcedSuccess] - Forced success for the finish of the events + * @param {DKTools.Event | DKTools.Animation} event - Event * - * @see DKTools.EventManager.prototype.finishEvents + * @see DKTools.EventManager.prototype.getEventIndex + * + * @returns {Number} Index of the event in its container */ - finishEvents(type, forcedSuccess) { - this._eventManager.finishEvents(type, forcedSuccess); + getEventIndex(event) { + return this._eventManager.getEventIndex(event); }; /** - * Stops the events + * Returns an array with the all events or events of a certain type * * @version 2.0.0 * - * @param {String} type - Type of the events - * @param {Boolean} [forcedSuccess] - Forced success for the finish of the events + * @param {String} [type] - Type of the events * - * @see DKTools.EventManager.prototype.stopEvents + * @see DKTools.EventManager.prototype.getEvents + * + * @returns {Array} Array with the events */ - stopEvents(type, forcedSuccess) { - this._eventManager.stopEvents(type, forcedSuccess); + getEvents(type) { + return this._eventManager.getEvents(type); }; /** - * Updates the events + * Returns an array with the all animations or animations of a certain type * * @version 2.0.0 * - * @see DKTools.EventManager.prototype.update - * @see DKTools.Base.protoype.updateReadyEvents - * @see DKTools.Base.protoype.updateUpdateEvents - * @see DKTools.Base.protoype.updateQueueEvents - * @see DKTools.Base.protoype.updateWheelEvents + * @param {String} [type] - Type of animation + * + * @see DKTools.EventManager.prototype.getAnimations + * + * @returns {Array} Array with the animations */ - updateEvents() { - this._eventManager.update(); - this.updateReadyEvents(); - this.updateUpdateEvents(); - this.updateQueueEvents(); + getAnimations(type) { + return this._eventManager.getAnimations(type); }; /** - * Updates the event + * Checks for existence of the event in the object + * Returns true if the event exists + * + * @version 2.0.0 * * @param {DKTools.Event | DKTools.Animation} event - Event * - * @see DKTools.EventManager.prototype.updateEvent + * @see DKTools.EventManager.prototype.hasEvent + * + * @returns {Boolean} Event exists */ - updateEvent(event) { - this._eventManager.updateEvent(event); + hasEvent(event) { + return this._eventManager.hasEvent(event); }; /** - * Updates the events from container + * Checks for existence of the events of a certain type + * Returns true if the events exists * * @version 2.0.0 * - * @param {String} type - Type of the events + * @param {String} [type] - Type of the Events * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @see DKTools.EventManager.prototype.hasEvents + * + * @returns {Boolean} Events exists */ - updateEventsContainer(type) { - this._eventManager.updateEventsContainer(type); + hasEvents(type) { + return this._eventManager.hasEvents(type); }; /** - * Updates the events with type: remove-all-children + * Checks for existence of the animation in the object + * Returns true if the animation exists * * @version 2.0.0 * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @param {DKTools.Animation} animation - Animation + * + * @see DKTools.EventManager.prototype.hasAnimation + * + * @returns {Boolean} Animation exists */ - updateRemoveAllChildrenEvents() { - this.updateEventsContainer('remove-all-children'); + hasAnimation(animation) { + return this._eventManager.hasAnimation(animation); }; /** - * Updates the events with type: terminate-all-children + * Checks for existence of the animations of a certain type + * Returns true if the animations exists * * @version 2.0.0 * - * @see DKTools.EventManager.prototype.updateEventsContainer - */ - updateTerminateAllEvents() { - this.updateEventsContainer('terminate-all-children'); - }; - - /** - * Updates the events with type: remove-all + * @param {String} [type] - Type of the animations * - * @version 2.0.0 + * @see DKTools.EventManager.prototype.hasAnimations * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @returns {Boolean} Animations exists */ - updateRemoveAllEvents() { - this.updateEventsContainer('remove-all'); + hasAnimations(type) { + return this._eventManager.hasAnimations(type); }; /** - * Updates the events with type: check-all + * Adds the event * * @version 2.0.0 * - * @see DKTools.EventManager.prototype.updateEventsContainer - */ - updateCheckAllEvents() { - this.updateEventsContainer('check-all'); - }; - - /** - * Updates the events with type: create-all - * - * @version 2.0.0 + * @param {DKTools.Event | Object} object - Event or object with parameters for the event * - * @see DKTools.EventManager.prototype.updateEventsContainer - */ - updateCreateAllEvents() { - this.updateEventsContainer('create-all'); - }; - - /** - * Updates the events with type: start-all + * @param {String} [object.type] - Type of the event + * @param {Number} [object.repeatTime] - Time of one repeat + * @param {Number} [object.repeats] - Amount of repeats + * @param {Number} [object.remainingPauseTime] - Remaining time of pause + * @param {Function} [object.onStart] - Handler of the event start + * @param {Function} [object.onUpdate] - Handler of the event update + * @param {Function} [object.onPause] - Handler of the event pause + * @param {Function} [object.onReset] - Handler of the event reset + * @param {Function} [object.onRepeat] - Handler of the event repeat + * @param {Function} [object.onSuccess] - Handler of the event success + * @param {Function} [object.onFail] - Handler of the event fail * - * @version 2.0.0 + * @see DKTools.Event + * @see DKTools.EventManager.prototype.addEvent * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @returns {DKTools.Event} Added event */ - updateStartAllEvents() { - this.updateEventsContainer('start-all'); + addEvent(object) { + return this._eventManager.addEvent(object); }; /** - * Updates the events with type: add-all-children + * Adds the one time event * * @version 2.0.0 * - * @see DKTools.EventManager.prototype.updateEventsContainer - */ - updateAddAllChildrenEvents() { - this.updateEventsContainer('add-all-children'); - }; - - /** - * Updates the events with type: refresh-all + * @param {DKTools.Event | Object} object - Event or object with parameters for the event * - * @version 2.0.0 + * @param {String} [object.type] - Type of the event + * @param {Number} [object.remainingPauseTime] - Remaining time of pause + * @param {Function} [object.onStart] - Handler of the event start + * @param {Function} [object.onUpdate] - Handler of the event update + * @param {Function} [object.onPause] - Handler of the event pause + * @param {Function} [object.onReset] - Handler of the event reset + * @param {Function} [object.onRepeat] - Handler of the event repeat + * @param {Function} [object.onSuccess] - Handler of the event success + * @param {Function} [object.onFail] - Handler of the event fail * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @see DKTools.Event + * @see DKTools.EventManager.prototype.addOneTimeEvent + * + * @returns {DKTools.Event} Added event */ - updateRefreshAllEvents() { - this.updateEventsContainer('refresh-all'); + addOneTimeEvent(object) { + return this._eventManager.addOneTimeEvent(object); }; /** - * Updates the events with type: update-all + * Adds the animation * * @version 2.0.0 * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @param {DKTools.Animation} animation - Animation to add + * + * @see DKTools.EventManager.addAnimation */ - updateUpdateAllEvents() { - this.updateEventsContainer('update-all'); + addAnimation(animation) { + this._eventManager.addAnimation(animation); }; + // process methods + /** - * Updates the events with type: redraw-all + * Processes all * * @version 2.0.0 * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @see DKTools.Base.prototype.processMouse + * @see DKTools.Base.prototype.processWheel */ - updateRedrawAllEvents() { - this.updateEventsContainer('redraw-all'); + processAll() { + this.processMouse(); + this.processWheel(); }; /** - * Updates the events with type: start + * Processes a mouse * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @since 2.0.0 */ - updateStartEvents() { - if (this.isStarted()) { - this.updateEventsContainer('start'); + processMouse() { + if (this.isOptionEnabled('process-mouse') && this.isVisible() && + (this.isActive() || this.isOptionEnabled('process-mouse-ignore-active'))) { + if (this.isMouseInside()) { + if (this._mouseEnterTime === 0) { + this.updateMouseEnterEvents(); + } + + this.updateMouseInsideEvents(); + + if (TouchInput.isMouseMoved()) { + this.updateMouseMoveEvents(); + } + + this._mouseEnterTime++; + } else { + if (this._mouseEnterTime > 0) { + this.updateMouseLeaveEvents(); + } + + this.updateMouseOutsideEvents(); + this._clearMouseEnterTime(); + } + } else { + this._clearMouseEnterTime(); } }; /** - * Updates the events with type: ready - * - * @see DKTools.EventManager.prototype.updateEventsContainer + * Processes a wheel + * + * @since 2.0.0 */ - updateReadyEvents() { - if (this.isReady()) { - this.updateEventsContainer('ready'); + processWheel() { + this._wheelX = TouchInput.wheelX; + this._wheelY = TouchInput.wheelY; + + if (this._wheelX !== 0 || this._wheelY !== 0) { + let type; + + if (this.isMouseInside()) { + type = 'inside'; + } else { + type = 'outside'; + } + + if (this._wheelX !== 0) { + this.updateWheelXEvents(type); + } + + if (this._wheelY !== 0) { + this.updateWheelYEvents(type); + } } }; + // update methods + /** - * Updates the events with type: update + * Updates all * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @version 1.1.0 + * + * @see DKTools.Base.prototype.updateOpacity + * @see DKTools.Base.prototype.updateUpdateAllEvents */ - updateUpdateEvents() { - this.updateEventsContainer('update'); + updateAll() { + this.updateOpacity(); + this.updateUpdateAllEvents(); }; /** - * Updates the events with type: queue - * - * @see DKTools.EventManager.prototype.updateEventsContainer + * Updates the object + * + * @see DKTools.Base.prototype.updateChildren + * @see DKTools.Base.prototype.processAll + * @see DKTools.Base.prototype.updateEvents */ - updateQueueEvents() { - const container = this.getEventsContainerByType('queue'); - const event = container[0]; - this.updateEvent(event); + update() { + this.updateChildren(); + this.processAll(); + this.updateEvents(); }; /** - * Updates the events with type: activate - * - * @see DKTools.EventManager.prototype.updateEventsContainer + * Updates the opacity of the object */ - updateActivateEvents() { - this.updateEventsContainer('activate'); + updateOpacity() { + // to be overriden by plugins }; /** - * Updates the events with type: deactivate + * Updates input data * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @see SceneManager.updateInputData */ - updateDeactivateEvents() { - this.updateEventsContainer('deactivate'); + updateInputData() { + SceneManager.updateInputData(); }; +}; + +// properties + +Object.defineProperties(DKTools.Base.prototype, { + /** - * Updates the events with type: show + * The object ID * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @readonly + * @type {Number | String | null} + * @memberof DKTools.Base.prototype */ - updateShowEvents() { - this.updateEventsContainer('show'); - }; + id : { + get: function() { + return this._id; + }, + configurable: true + }, /** - * Updates the events with type: hide + * The X coordinate of mouse inside the object * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @readonly + * @type {Number} + * @memberof DKTools.Base.prototype */ - updateHideEvents() { - this.updateEventsContainer('hide'); - }; + mouseX : { + get: function() { + return this.canvasToLocalX(TouchInput.mouseX); + }, + configurable: true + }, /** - * Updates the events with type: mouse-enter - * - * @version 2.0.0 + * The Y coordinate of mouse inside the object * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @readonly + * @type {Number} + * @memberof DKTools.Base.prototype */ - updateMouseEnterEvents() { - this.updateEventsContainer('mouse-enter'); - }; + mouseY : { + get: function() { + return this.canvasToLocalY(TouchInput.mouseY); + }, + configurable: true + }, /** - * Updates the events with type: mouse-inside - * - * @since 2.0.0 + * Number of pixels scrolling mouse on X axis * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @readonly + * @type {Number} + * @memberof DKTools.Base.prototype */ - updateMouseInsideEvents() { - this.updateEventsContainer('mouse-inside'); - }; + wheelX: { + get: function() { + return this._wheelX; + }, + configurable: true + }, /** - * Updates the events with type: mouse-move - * - * @since 2.0.0 + * Number of pixels scrolling mouse on Y axis * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @readonly + * @type {Number} + * @memberof DKTools.Base.prototype */ - updateMouseMoveEvents() { - this.updateEventsContainer('mouse-move'); - }; + wheelY: { + get: function() { + return this._wheelY; + }, + configurable: true + }, /** - * Updates the events with type: mouse-leave - * - * @version 2.0.0 + * Time of mouse enter inside the object * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @readonly + * @type {Number} + * @memberof DKTools.Base.prototype */ - updateMouseLeaveEvents() { - this.updateEventsContainer('mouse-leave'); - }; + mouseEnterTime: { + get: function() { + return this._mouseEnterTime; + }, + configurable: true + } + +}); + + + + +//=========================================================================== +// DKTools.Sprite +//=========================================================================== + +DKTools.Sprite.prototype = Object.create(Sprite.prototype); +DKTools.Utils.mixin(DKTools.Sprite.prototype, DKTools.Base.prototype); +DKTools.Sprite.prototype.constructor = DKTools.Sprite; + +// properties + +Object.defineProperties(DKTools.Sprite.prototype, { /** - * Updates the events with type: mouse-outside - * - * @since 2.0.0 + * Window skin * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @readonly + * @type {Bitmap | null} + * @memberof DKTools.Sprite.prototype */ - updateMouseOutsideEvents() { - this.updateEventsContainer('mouse-outside'); - }; + windowskin: { + get: function() { + return this._windowskin; + }, + configurable: true + }, /** - * Updates the events with type: wheel-X-inside or wheel-X-outside - * - * @version 2.0.0 - * - * @param {String} type Type of the wheel event (inside or outside) + * Frame of the sprite * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @readonly + * @type {Rectangle} + * @memberof DKTools.Sprite.prototype */ - updateWheelXEvents(type) { - this.updateEventsContainer('wheel-X-' + type); - }; + frame: { + get: function() { + return this._frame; + }, + configurable: true + }, /** - * Updates the events with type: wheel-Y-inside or wheel-Y-outside - * - * @version 2.0.0 - * - * @param {String} type - Type of the wheel event (inside or outside) + * Real width of the sprite (not including scaling) * - * @see DKTools.EventManager.prototype.updateEventsContainer + * @type {Number} + * @memberof DKTools.Sprite.prototype */ - updateWheelYEvents(type) { - this.updateEventsContainer('wheel-Y-' + type); - }; + realWidth: { + get: function() { + return this._frame.width; + }, + set: function(value) { + this._frame.width = value; + this._refresh(); + }, + configurable: true + }, /** - * Returns a container for the events by event type - * - * @version 2.0.0 - * - * @param {String} type - Type of the events - * - * @see DKTools.EventManager.prototype.getEventsContainerByType + * Real height of the sprite (not including scaling) * - * @returns {Array} Container for the events + * @type {Number} + * @memberof DKTools.Sprite.prototype */ - getEventsContainerByType(type) { - return this._eventManager.getEventsContainerByType(type); - }; + realHeight: { + get: function() { + return this._frame.height; + }, + set: function(value) { + this._frame.height = value; + this._refresh(); + }, + configurable: true + }, /** - * Returns a container for the events by event - * - * @version 2.0.0 - * - * @param {DKTools.Event | DKTools.Animation} event - Event - * - * @see DKTools.EventManager.prototype.getEventsContainer + * Width of the sprite (taking into account the scaling) * - * @returns {Array} Container for the events + * @type {Number} + * @memberof DKTools.Sprite.prototype */ - getEventsContainer(event) { - return this._eventManager.getEventsContainer(event); - }; + width: { + get: function() { + return this.realWidth * this.scale.x; + }, + set: function(value) { + this.realWidth = Math.floor(value / this.scale.x); + }, + configurable: true + }, /** - * Returns an index of the event in its container - * - * @version 2.0.0 - * - * @param {DKTools.Event | DKTools.Animation} event - Event - * - * @see DKTools.EventManager.prototype.getEventIndex + * Height of the sprite (taking into account the scaling) * - * @returns {Number} Index of the event in its container + * @type {Number} + * @memberof DKTools.Sprite.prototype */ - getEventIndex(event) { - return this._eventManager.getEventIndex(event); - }; + height: { + get: function() { + return this.realHeight * this.scale.y; + }, + set: function(value) { + this.realHeight = Math.floor(value / this.scale.y); + }, + configurable: true + }, /** - * Returns an array with the all events or events of a certain type - * - * @version 2.0.0 - * - * @param {String} [type] - Type of the events - * - * @see DKTools.EventManager.prototype.getEvents + * Text font * - * @returns {Array} Array with the events + * @readonly + * @type {Object} + * @memberof DKTools.Sprite.prototype */ - getEvents(type) { - return this._eventManager.getEvents(type); - }; + font: { + get: function() { + return this._font; + }, + configurable: true + }, /** - * Returns an array with the all animations or animations of a certain type - * - * @version 2.0.0 - * - * @param {String} [type] - Type of animation - * - * @see DKTools.EventManager.prototype.getAnimations + * Text color * - * @returns {Array} Array with the animations + * @readonly + * @type {String} + * @memberof DKTools.Sprite.prototype */ - getAnimations(type) { - return this._eventManager.getAnimations(type); - }; + textColor: { + get: function() { + return this._textColor; + }, + configurable: true + }, /** - * Checks for existence of the event in the object - * Returns true if the event exists - * - * @version 2.0.0 - * - * @param {DKTools.Event | DKTools.Animation} event - Event - * - * @see DKTools.EventManager.prototype.hasEvent + * Paint opacity * - * @returns {Boolean} Event exists + * @readonly + * @type {Number} + * @memberof DKTools.Sprite.prototype */ - hasEvent(event) { - return this._eventManager.hasEvent(event); - }; + paintOpacity: { + get: function() { + return this._paintOpacity; + }, + configurable: true + }, /** - * Checks for existence of the events of a certain type - * Returns true if the events exists - * - * @version 2.0.0 - * - * @param {String} [type] - Type of the Events - * - * @see DKTools.EventManager.prototype.hasEvents + * Fill color * - * @returns {Boolean} Events exists + * @readonly + * @type {String | null} + * @memberof DKTools.Sprite.prototype */ - hasEvents(type) { - return this._eventManager.hasEvents(type); - }; + fillColor: { + get: function() { + return this._fillColor; + }, + configurable: true + }, /** - * Checks for existence of the animation in the object - * Returns true if the animation exists - * - * @version 2.0.0 - * - * @param {DKTools.Animation} animation - Animation - * - * @see DKTools.EventManager.prototype.hasAnimation + * Text align * - * @returns {Boolean} Animation exists + * @readonly + * @type {String} + * @memberof DKTools.Sprite.prototype */ - hasAnimation(animation) { - return this._eventManager.hasAnimation(animation); - }; + align: { + get: function() { + return this._align; + }, + configurable: true + }, /** - * Checks for existence of the animations of a certain type - * Returns true if the animations exists - * - * @version 2.0.0 - * - * @param {String} [type] - Type of the animations - * - * @see DKTools.EventManager.prototype.hasAnimations + * Texts * - * @returns {Boolean} Animations exists + * @readonly + * @type {Object[]} + * @memberof DKTools.Sprite.prototype */ - hasAnimations(type) { - return this._eventManager.hasAnimations(type); - }; + texts: { + get: function() { + return this._texts; + }, + configurable: true + }, /** - * Adds the event - * - * @version 2.0.0 - * - * @param {DKTools.Event | Object} object - Event or object with parameters for the event - * - * @param {String} [object.type] - Type of the event - * @param {Number} [object.repeatTime] - Time of one repeat - * @param {Number} [object.repeats] - Amount of repeats - * @param {Number} [object.remainingPauseTime] - Remaining time of pause - * @param {Function} [object.onStart] - Handler of the event start - * @param {Function} [object.onUpdate] - Handler of the event update - * @param {Function} [object.onPause] - Handler of the event pause - * @param {Function} [object.onReset] - Handler of the event reset - * @param {Function} [object.onRepeat] - Handler of the event repeat - * @param {Function} [object.onSuccess] - Handler of the event success - * @param {Function} [object.onFail] - Handler of the event fail - * - * @see DKTools.Event - * @see DKTools.EventManager.prototype.addEvent + * Graphic folder * - * @returns {DKTools.Event} Added event + * @readonly + * @type {String} + * @memberof DKTools.Sprite.prototype */ - addEvent(object) { - return this._eventManager.addEvent(object); - }; + graphicFolder: { + get: function() { + return this._graphicFolder; + }, + configurable: true + }, /** - * Adds the one time event - * - * @version 2.0.0 - * - * @param {DKTools.Event | Object} object - Event or object with parameters for the event - * - * @param {String} [object.type] - Type of the event - * @param {Number} [object.remainingPauseTime] - Remaining time of pause - * @param {Function} [object.onStart] - Handler of the event start - * @param {Function} [object.onUpdate] - Handler of the event update - * @param {Function} [object.onPause] - Handler of the event pause - * @param {Function} [object.onReset] - Handler of the event reset - * @param {Function} [object.onRepeat] - Handler of the event repeat - * @param {Function} [object.onSuccess] - Handler of the event success - * @param {Function} [object.onFail] - Handler of the event fail - * - * @see DKTools.Event - * @see DKTools.EventManager.prototype.addOneTimeEvent + * Graphic name * - * @returns {DKTools.Event} Added event + * @readonly + * @type {String} + * @memberof DKTools.Sprite.prototype */ - addOneTimeEvent(object) { - return this._eventManager.addOneTimeEvent(object); - }; + graphicName: { + get: function() { + return this._graphicName; + }, + configurable: true + } - /** - * Adds the animation - * - * @version 2.0.0 - * - * @param {DKTools.Animation} animation - Animation to add - * - * @see DKTools.EventManager.addAnimation - */ - addAnimation(animation) { - this._eventManager.addAnimation(animation); - }; +}); - // process methods +// initialize methods - /** - * Processes all - * - * @version 2.0.0 - * - * @see DKTools.Base.prototype.processMouse - * @see DKTools.Base.prototype.processWheel - */ - processAll() { - this.processMouse(); - this.processWheel(); - }; +/** + * Initializes a class object + * + * @version 3.0.0 + * + * @override + * + * @param {Number | DKTools.Sprite | Bitmap | PIXI.Rectangle | Rectangle | Object} [object] - The X coordinate or Sprite or Bitmap or Rectangle or object with properties + * @param {Number} [y] - The Y coordinate (if object is Number) + * @param {Number} [width] - Width of the bitmap (if object is Number) + * @param {Number} [height] - Height of the bitmap (if object is Number) + * + * @param {Number} [object.x] - The X coordinate + * @param {Number} [object.y] - The Y coordinate + * @param {Number} [object.width] - Width of the bitmap + * @param {Number} [object.height] - Height of the bitmap + * @param {Bitmap | Object} [object] - Bitmap or object with parameters + * + * @param {String} object.folder - Path to file + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see Sprite.prototype.initialize + * @see DKTools.Base.prototype.initialize + * @see DKTools.Sprite.prototype.setupAll + * @see DKTools.Sprite.prototype.setupSize + * @see DKTools.Sprite.prototype.setupBitmap + * @see DKTools.Sprite.prototype.updateBitmap + */ +DKTools.Sprite.prototype.initialize = function(object, y, width, height) { + Sprite.prototype.initialize.call(this); + DKTools.Base.prototype.initialize.call(this, object, y, width, height); - /** - * Processes a mouse - * - * @since 2.0.0 - */ - processMouse() { - if (this.isOptionEnabled('process-mouse') && this.isVisible() && - (this.isActive() || this.isOptionEnabled('process-mouse-ignore-active'))) { - if (this.isMouseInside()) { - if (this._mouseEnterTime === 0) { - this.updateMouseEnterEvents(); - } + if (object instanceof DKTools.Sprite && !object.isStarted() && !object.hasFixedBitmap()) { + this.setupSize(object._getBitmapWidth(), object._getBitmapHeight()); + } else if (object instanceof Bitmap) { + this.setupBitmap(object); + } - this.updateMouseInsideEvents(); + this.updateBitmap(); +}; - if (TouchInput.isMouseMoved()) { - this.updateMouseMoveEvents(); - } +// _clear methods - this._mouseEnterTime++; - } else { - if (this._mouseEnterTime > 0) { - this.updateMouseLeaveEvents(); - } - - this.updateMouseOutsideEvents(); - this._clearMouseEnterTime(); - } - } else { - this._clearMouseEnterTime(); - } - }; +/** + * Clears all data + * + * @private + * @override + * + * @see DKTools.Base.prototype._clearAll + * @see DKTools.Sprite.prototype._clearTexts + */ +DKTools.Sprite.prototype._clearAll = function() { + DKTools.Base.prototype._clearAll.call(this); + this._clearTexts(); +}; +/** + * Clears all texts + * + * @private + */ +DKTools.Sprite.prototype._clearTexts = function() { /** - * Processes a wheel - * - * @since 2.0.0 + * @private + * @readonly + * @type {Object[]} */ - processWheel() { - this._wheelX = TouchInput.wheelX; - this._wheelY = TouchInput.wheelY; - - if (this._wheelX !== 0 || this._wheelY !== 0) { - let type; + this._texts = []; +}; - if (this.isMouseInside()) { - type = 'inside'; - } else { - type = 'outside'; - } +// standard methods - if (this._wheelX !== 0) { - this.updateWheelXEvents(type); - } +/** + * Returns the standard font face + * + * @returns {String} Standard font face + */ +DKTools.Sprite.prototype.standardFontFace = function() { + return 'GameFont'; +}; - if (this._wheelY !== 0) { - this.updateWheelYEvents(type); - } - } - }; +/** + * Returns the standard font size + * + * @returns {String} Standard font size + */ +DKTools.Sprite.prototype.standardFontSize = function() { + return 28; +}; - // update methods +/** + * Returns the standard font italic + * + * @returns {String} Standard font italic + */ +DKTools.Sprite.prototype.standardFontItalic = function() { + return false; +}; - /** - * Updates all - * - * @version 1.1.0 - * - * @see DKTools.Base.prototype.updateOpacity - * @see DKTools.Base.prototype.updateUpdateAllEvents - */ - updateAll() { - this.updateOpacity(); - this.updateUpdateAllEvents(); +/** + * Returns the standard font + * + * @see DKTools.Sprite.prototype.standardFontFace + * @see DKTools.Sprite.prototype.standardFontSize + * @see DKTools.Sprite.prototype.standardFontItalic + * + * @returns {Object} Standard font + */ +DKTools.Sprite.prototype.standardFont = function() { + return { + fontFace: this.standardFontFace(), + fontSize: this.standardFontSize(), + fontItalic: this.standardFontItalic() }; +}; - /** - * Updates the object - * - * @see DKTools.Base.prototype.updateChildren - * @see DKTools.Base.prototype.processAll - * @see DKTools.Base.prototype.updateEvents - */ - update() { - this.updateChildren(); - this.processAll(); - this.updateEvents(); - }; +/** + * Returns the standard text color + * + * @returns {String} Standard text color + */ +DKTools.Sprite.prototype.standardTextColor = function() { + return '#ffffff'; +}; - /** - * Updates the opacity of the object - */ - updateOpacity() { - // to be overriden by plugins - }; +/** + * Returns the standard paint opacity + * + * @returns {Number} Standard paint opacity + */ +DKTools.Sprite.prototype.standardPaintOpacity = function() { + return 255; +}; - /** - * Updates input data - * - * @see SceneManager.updateInputData - */ - updateInputData() { - SceneManager.updateInputData(); - }; +/** + * Returns the standard fill color + * + * @returns {String | null} Standard fill color + */ +DKTools.Sprite.prototype.standardFillColor = function() { + return null; +}; +/** + * Returns the standard text align + * + * @returns {String} Standard text align + */ +DKTools.Sprite.prototype.standardAlign = function() { + return 'center'; }; -// properties +/** + * Returns the standard graphic folder + * + * @returns {String} Standard graphic folder + */ +DKTools.Sprite.prototype.standardGraphicFolder = function() { + return 'img/system/'; +}; -Object.defineProperties(DKTools.Base.prototype, { +/** + * Returns the standard graphic name + * + * @returns {String} standard graphic name + */ +DKTools.Sprite.prototype.standardGraphicName = function() { + return ''; +}; - /** - * The object ID - * - * @readonly - * @type {Number | String | null} - * @memberof DKTools.Base.prototype - */ - id : { - get: function() { - return this._id; - }, - configurable: true - }, +/** + * Returns the standard opacity + * + * @returns {Number} Standard opacity + */ +DKTools.Sprite.prototype.standardOpacity = function() { + return 255; +}; - /** - * The X coordinate of mouse inside the object - * - * @readonly - * @type {Number} - * @memberof DKTools.Base.prototype - */ - mouseX : { - get: function() { - return this.canvasToLocalX(TouchInput.mouseX); - }, - configurable: true - }, +/** + * Returns the standard frame + * + * @version 3.1.0 + * @returns {Rectangle} Standard frame + */ +DKTools.Sprite.prototype.standardFrame = function() { + return new Rectangle(0, 0, this.realWidth, this.realHeight); +}; - /** - * The Y coordinate of mouse inside the object - * - * @readonly - * @type {Number} - * @memberof DKTools.Base.prototype - */ - mouseY : { - get: function() { - return this.canvasToLocalY(TouchInput.mouseY); - }, - configurable: true - }, +/** + * Returns the standard anchor + * + * @returns {Point} Standard anchor + */ +DKTools.Sprite.prototype.standardAnchor = function() { + return new Point(0, 0); +}; - /** - * Number of pixels scrolling mouse on X axis - * - * @readonly - * @type {Number} - * @memberof DKTools.Base.prototype - */ - wheelX: { - get: function() { - return this._wheelX; - }, - configurable: true - }, +// setup methods - /** - * Number of pixels scrolling mouse on Y axis - * - * @readonly - * @type {Number} - * @memberof DKTools.Base.prototype - */ - wheelY: { - get: function() { - return this._wheelY; - }, - configurable: true - }, +/** + * Sets all parameters + * + * @override + * + * @param {Object} [object] - Parameters + * + * @param {Bitmap | Object} [object.bitmap] - Bitmap or object with parameters + * @param {PIXI.Rectangle | Rectangle | Object} [object.frame] - Rectangle or object with parameters + * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [object.anchor] - Anchor of the sprite + * @param {Object} [object.font] - Text font + * @param {String} [object.textColor] - Text color + * @param {Number} [object.paintOpacity] - Paint opacity + * @param {String} [object.fillColor] - Fill color + * @param {String} [object.align] - Text align + * @param {Number} [object.opacity] - Opacity + * @param {String} [object.graphicFolder] - Graphic folder + * @param {String} [object.graphicName] - Graphic name + * + * @param {String} object.folder - Path to file + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @param {String} [object.font.fontFace] - Font face + * @param {Number} [object.font.fontSize] - Font size + * @param {Boolean} [object.font.fontItalic] - Font italic + * + * @param {Number} [object.frame.x] - The X coordinate + * @param {Number} [object.frame.y] - The Y coordinate + * @param {Number} [object.frame.width] - Width of the frame + * @param {Number} [object.frame.height] - Height of the frame + * + * @param {Number} [object.anchor.x] - The X coordinate + * @param {Number} [object.anchor.y] - The Y coordinate + * + * @see DKTools.Base.prototype.setupAll + * @see DKTools.Sprite.prototype.setupBitmap + * @see DKTools.Sprite.prototype.setupFrame + * @see DKTools.Sprite.prototype.setupAnchor + * @see DKTools.Sprite.prototype.setupFont + * @see DKTools.Sprite.prototype.setupTextColor + * @see DKTools.Sprite.prototype.setupPaintOpacity + * @see DKTools.Sprite.prototype.setupFillColor + * @see DKTools.Sprite.prototype.setupAlign + * @see DKTools.Sprite.prototype.setupOpacity + * @see DKTools.Sprite.prototype.setupGraphicFolder + * @see DKTools.Sprite.prototype.setupGraphicName + */ +DKTools.Sprite.prototype.setupAll = function(object) { + object = object || {}; + DKTools.Base.prototype.setupAll.call(this, object); + this.setupBitmap(object); + this.setupFrame(object.frame); + this.setupAnchor(object.anchor); + this.setupFont(object.font); + this.setupTextColor(object.textColor); + this.setupPaintOpacity(object.paintOpacity); + this.setupFillColor(object.fillColor); + this.setupAlign(object.align); + this.setupOpacity(object.opacity); + this.setupGraphicFolder(object.graphicFolder); + this.setupGraphicName(object.graphicName); +}; +/** + * Sets the width of the bitmap + * + * @param {Number} [width] - Width of the bitmap + * + * @see DKTools.Base.prototype._checkWidth + */ +DKTools.Sprite.prototype.setupWidth = function(width) { /** - * Time of mouse enter inside the object - * + * @private * @readonly * @type {Number} - * @memberof DKTools.Base.prototype */ - mouseEnterTime: { - get: function() { - return this._mouseEnterTime; - }, - configurable: true + this._bitmapWidth = this._checkWidth(width); +}; + +/** + * Sets the height of the bitmap + * + * @param {Number | String} [height] - Height of the bitmap or number of lines + * + * @see DKTools.Base.prototype.getLineHeight + * @see DKTools.Base.prototype._checkHeight + */ +DKTools.Sprite.prototype.setupHeight = function(height) { + if (DKTools.Utils.isString(height)) { + height = this.getLineHeight() * Number(height); } -}); + /** + * @private + * @readonly + * @type {Number} + */ + this._bitmapHeight = this._checkHeight(height); +}; + +/** + * Sets the size of the bitmap + * + * @param {Number | Object} [object] - Width of the bitmap or object with parameters + * @param {Number} [height] - Height of the bitmap (if object is Object) + * + * @param {Number} [object.width] - Width of the bitmap + * @param {Number} [object.height] - Height of the bitmap + * + * @see DKTools.Sprite.prototype.setupWidth + * @see DKTools.Sprite.prototype.setupHeight + */ +DKTools.Sprite.prototype.setupSize = function(object, height) { + if (object instanceof Object) { + return this.setupSize(object.width, object.height); + } + this.setupWidth(object); + this.setupHeight(height); +}; +/** + * Sets the bitmap + * + * @version 3.1.0 + * + * @param {Bitmap | Object} [object] - Bitmap or object with parameters + * + * @param {String} object.folder - Path to file + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Utils.Bitmap.load + */ +DKTools.Sprite.prototype.setupBitmap = function(object) { + let bitmap = null; + if (object instanceof DKTools.Sprite && + object.hasFixedBitmap() && + object.canCloneFixedBitmap()) { + bitmap = DKTools.Utils.Bitmap.clone(object.bitmap); + } else if (object instanceof Object) { + bitmap = DKTools.Utils.Bitmap.load(object.bitmap || object); + } -//=========================================================================== -// DKTools.Sprite -//=========================================================================== + if (bitmap) { + this.bitmap = bitmap; + this.bitmap.addLoadListener(this.setupSize.bind(this)); + } else { + this.bitmap = null; + } -DKTools.Sprite.prototype = Object.create(Sprite.prototype); -DKTools.Utils.mixin(DKTools.Sprite.prototype, DKTools.Base.prototype); -DKTools.Sprite.prototype.constructor = DKTools.Sprite; + /** + * @private + * @readonly + * @type {Boolean} + */ + this._fixedBitmap = !!this.bitmap; +}; /** - * Counter of created sprites + * Sets the frame of the sprite * - * @private - * @readonly - * @type {Number} - * @memberof DKTools.Sprite + * @version 3.1.0 + * + * @param {Number | Rectangle | Object} [object] - The X coordinate or Rectangle or object with parameters + * @param {Number} [y] - The Y coordinate (if object is Number) + * @param {Number} [width] - Width of the frame (if object is Number) + * @param {Number} [height] - Height of the frame (if object is Number) + * + * @param {Number} [object.x] - The X coordinate + * @param {Number} [object.y] - The Y coordinate + * @param {Number} [object.width] - Width of the frame + * @param {Number} [object.height] - Height of the frame + * + * @see DKTools.Utils.Rectangle.toRectangle + * @see DKTools.Sprite.prototype.standardFrame + * @see Sprite.prototype.setFrame + * @see DKTools.Sprite.prototype.hasFixedBitmap */ -DKTools.Sprite._counter = 0; +DKTools.Sprite.prototype.setupFrame = function(object, y, width, height) { + const frame = DKTools.Utils.Rectangle.toRectangle(object, y, width, height); + const newFrame = Object.assign(this.standardFrame(), frame); -// properties + Sprite.prototype.setFrame.call(this, newFrame.x, newFrame.y, newFrame.width, newFrame.height); +}; -Object.defineProperties(DKTools.Sprite.prototype, { +/** + * Sets the anchor of the sprite + * + * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object=this.standardAnchor()] - The X coordinate or Point or object with parameters + * @param {Number} [y] - The Y coordinate (is object is Number) + * + * @param {Number} [object.x] - The X coordinate + * @param {Number} [object.y] - The Y coordinate + * + * @see DKTools.Utils.Point.toPoint + * @see DKTools.Sprite.prototype.standardAnchor + */ +DKTools.Sprite.prototype.setupAnchor = function(object, y) { + const anchor = DKTools.Utils.Point.toPoint(object, y); + const newAnchor = Object.assign(this.standardAnchor(), anchor); /** - * Window skin - * - * @readonly - * @type {Bitmap | null} - * @memberof DKTools.Sprite.prototype + * @type {PIXI.ObservablePoint} */ - windowskin: { - get: function() { - return this._windowskin; - }, - configurable: true - }, + this.anchor.copy(newAnchor); +}; +/** + * Sets the font of the bitmap + * + * @param {Object} [font=this.standardFont()] - Text font + * + * @param {String} [font.fontFace] - Font face + * @param {Number} [font.fontSize] - Font size + * @param {Boolean} [font.fontItalic] - Font italic + * + * @see DKTools.Sprite.prototype.standardFont + */ +DKTools.Sprite.prototype.setupFont = function(font) { /** - * Frame of the sprite - * + * @private * @readonly - * @type {Rectangle} - * @memberof DKTools.Sprite.prototype + * @type {Object} */ - frame: { - get: function() { - return this._frame; - }, - configurable: true - }, + this._font = Object.assign(this.standardFont(), font); +}; +/** + * Sets the color of the text + * + * @param {String} [color=this.standardTextColor()] - Text color + * + * @see DKTools.Sprite.prototype.standardTextColor + */ +DKTools.Sprite.prototype.setupTextColor = function(color) { /** - * Real width of the sprite (not including scaling) - * - * @type {Number} - * @memberof DKTools.Sprite.prototype - */ - realWidth: { - get: function() { - return this._frame.width; - }, - set: function(value) { - this._frame.width = value; - this._refresh(); - }, - configurable: true - }, - - /** - * Real height of the sprite (not including scaling) - * - * @type {Number} - * @memberof DKTools.Sprite.prototype - */ - realHeight: { - get: function() { - return this._frame.height; - }, - set: function(value) { - this._frame.height = value; - this._refresh(); - }, - configurable: true - }, - - /** - * Width of the sprite (taking into account the scaling) - * - * @type {Number} - * @memberof DKTools.Sprite.prototype - */ - width: { - get: function() { - return this.realWidth * this.scale.x; - }, - set: function(value) { - this.realWidth = Math.floor(value / this.scale.x); - }, - configurable: true - }, - - /** - * Height of the sprite (taking into account the scaling) - * - * @type {Number} - * @memberof DKTools.Sprite.prototype - */ - height: { - get: function() { - return this.realHeight * this.scale.y; - }, - set: function(value) { - this.realHeight = Math.floor(value / this.scale.y); - }, - configurable: true - }, - - /** - * Text font - * - * @readonly - * @type {Object} - * @memberof DKTools.Sprite.prototype - */ - font: { - get: function() { - return this._font; - }, - configurable: true - }, - - /** - * Text color - * + * @private * @readonly * @type {String} - * @memberof DKTools.Sprite.prototype */ - textColor: { - get: function() { - return this._textColor; - }, - configurable: true - }, + this._textColor = color || this.standardTextColor(); +}; +/** + * Sets the paint opacity + * + * @param {Number} [opacity=this.standardPaintOpacity()] - Paint opacity + * + * @see DKTools.Sprite.prototype.standardPaintOpacity + */ +DKTools.Sprite.prototype.setupPaintOpacity = function(opacity) { /** - * Paint opacity - * + * @private * @readonly * @type {Number} - * @memberof DKTools.Sprite.prototype */ - paintOpacity: { - get: function() { - return this._paintOpacity; - }, - configurable: true - }, + this._paintOpacity = (opacity == null ? this.standardPaintOpacity() : opacity); +}; +/** + * Sets the fill color + * + * @param {String} [color=this.standardFillColor()] - Fill color + * + * @see DKTools.Sprite.prototype.standardFillColor + */ +DKTools.Sprite.prototype.setupFillColor = function(color) { /** - * Fill color - * + * @private * @readonly * @type {String | null} - * @memberof DKTools.Sprite.prototype */ - fillColor: { - get: function() { - return this._fillColor; - }, - configurable: true - }, + this._fillColor = (color == null ? this.standardFillColor() : color); +}; +/** + * Sets the align + * + * @param {String} [align=this.standardAlign()] - Text align + * + * @see DKTools.Sprite.prototype.standardAlign + */ +DKTools.Sprite.prototype.setupAlign = function(align) { /** - * Text align - * + * @private * @readonly * @type {String} - * @memberof DKTools.Sprite.prototype */ - align: { - get: function() { - return this._align; - }, - configurable: true - }, + this._align = align || this.standardAlign(); +}; +/** + * Sets the opacity of the sprite + * + * @param {Number} [opacity=this.standardOpacity()] - Opacity + * + * @see DKTools.Sprite.prototype.standardOpacity + */ +DKTools.Sprite.prototype.setupOpacity = function(opacity) { /** - * Texts - * + * @private * @readonly - * @type {Object[]} - * @memberof DKTools.Sprite.prototype + * @type {Number} */ - texts: { - get: function() { - return this._texts; - }, - configurable: true - }, + this._opacity = (opacity == null ? this.standardOpacity() : opacity); +}; +/** + * Sets the graphic folder + * + * @param {String} [folder=this.standardGraphicFolder()] - Path to folder + * + * @see DKTools.Sprite.prototype.standardGraphicFolder + */ +DKTools.Sprite.prototype.setupGraphicFolder = function(folder) { /** - * Graphic folder - * + * @private * @readonly * @type {String} - * @memberof DKTools.Sprite.prototype */ - graphicFolder: { - get: function() { - return this._graphicFolder; - }, - configurable: true - }, + this._graphicFolder = (folder == null ? this.standardGraphicFolder() : folder); +}; +/** + * Sets the graphic name + * + * @param {String} [graphicName=this.standardGraphicName()] - Graphic name + * + * @see DKTools.Sprite.prototype.standardGraphicName + */ +DKTools.Sprite.prototype.setupGraphicName = function(graphicName) { /** - * Graphic name - * + * @private * @readonly * @type {String} - * @memberof DKTools.Sprite.prototype */ - graphicName: { - get: function() { - return this._graphicName; - }, - configurable: true - } - -}); + this._graphicName = (graphicName == null ? this.standardGraphicName() : graphicName); +}; -// initialize methods +/** + * Sets the mask + * + * @since 2.0.0 + * @param {PIXI.Graphics} [mask] - Mask + */ +DKTools.Sprite.prototype.setupMask = function(mask) { + this.mask = mask || null; +}; /** - * Initializes a class object + * Sets the listener on load of graphic * - * @version 3.0.0 + * @param {Function} listener - Listener + */ +DKTools.Sprite.prototype.setupGraphicLoadListener = function(listener) { + /** + * @private + * @readonly + * @type {Function} + */ + this._graphicLoadListener = listener || null; +}; + +// set methods + +/** + * Changes all parameters + * Returns the number of changed parameters * * @override * - * @param {Number | DKTools.Sprite | Bitmap | PIXI.Rectangle | Rectangle | Object} [object] - The X coordinate or Sprite or Bitmap or Rectangle or object with properties - * @param {Number} [y] - The Y coordinate (if object is Number) - * @param {Number} [width] - Width of the bitmap (if object is Number) - * @param {Number} [height] - Height of the bitmap (if object is Number) - * - * @param {Number} [object.x] - The X coordinate - * @param {Number} [object.y] - The Y coordinate - * @param {Number} [object.width] - Width of the bitmap - * @param {Number} [object.height] - Height of the bitmap - * @param {Bitmap | Object} [object] - Bitmap or object with parameters + * @param {Object} [object={}] - Parameters + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the sprite * - * @param {String} object.folder - Path to file - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Object} [object.font] - Text font + * @param {String} [object.textColor] - Text color + * @param {Number} [object.paintOpacity] - Paint opacity + * @param {String} [object.fillColor] - Fill color + * @param {String} [object.align] - Text align + * @param {Number} [object.opacity] - Opacity + * @param {String} [object.graphicFolder] - Graphic folder + * @param {String} [object.graphicName] - Graphic name * - * @see Sprite.prototype.initialize - * @see DKTools.Base.prototype.initialize - * @see DKTools.Sprite.prototype.setupAll - * @see DKTools.Sprite.prototype.setupSize - * @see DKTools.Sprite.prototype.setupBitmap - * @see DKTools.Sprite.prototype.updateBitmap + * @param {String} [object.font.fontFace] - Font face + * @param {Number} [object.font.fontSize] - Font size + * @param {Boolean} [object.font.fontItalic] - Font italic + * + * @see DKTools.Base.prototype.setAll + * @see DKTools.Sprite.prototype.setFont + * @see DKTools.Sprite.prototype.setTextColor + * @see DKTools.Sprite.prototype.setPaintOpacity + * @see DKTools.Sprite.prototype.setFillColor + * @see DKTools.Sprite.prototype.setAlign + * @see DKTools.Sprite.prototype.setOpacity + * @see DKTools.Sprite.prototype.setGraphicFolder + * @see DKTools.Sprite.prototype.setGraphicName + * @see DKTools.Sprite.prototype.start + * @see DKTools.Sprite.prototype.activate + * + * @returns {Number} Number of changed parameters */ -DKTools.Sprite.prototype.initialize = function(object, y, width, height) { - Sprite.prototype.initialize.call(this); - DKTools.Base.prototype.initialize.call(this, object, y, width, height); +DKTools.Sprite.prototype.setAll = function(object, blockStart, activate) { + object = object || {}; + const block = true; + let changed = DKTools.Base.prototype.setAll.call(this, object, block); - if (object instanceof DKTools.Sprite && !object.isStarted() && !object.hasFixedBitmap()) { - this.setupSize(object._getBitmapWidth(), object._getBitmapHeight()); - } else if (object instanceof Bitmap) { - this.setupBitmap(object); + if (this.setFont(object.font, block)) { + changed++; } - this.updateBitmap(); - DKTools.Sprite._counter++; -}; + if (this.setTextColor(object.textColor, block)) { + changed++; + } -// _clear methods + if (this.setPaintOpacity(object.paintOpacity, block)) { + changed++; + } -/** - * Clears all data - * - * @private - * @override - * - * @see DKTools.Base.prototype._clearAll - * @see DKTools.Sprite.prototype._clearTexts - */ -DKTools.Sprite.prototype._clearAll = function() { - DKTools.Base.prototype._clearAll.call(this); - this._clearTexts(); -}; + if (this.setFillColor(object.fillColor, block)) { + changed++; + } -/** - * Clears all texts - * - * @private - */ -DKTools.Sprite.prototype._clearTexts = function() { - /** - * @private - * @readonly - * @type {Object[]} - */ - this._texts = []; -}; + if (this.setAlign(object.align, block)) { + changed++; + } -// standard methods + if (this.setOpacity(object.opacity, block)) { + changed++; + } -/** - * Returns the standard font face - * - * @returns {String} Standard font face - */ -DKTools.Sprite.prototype.standardFontFace = function() { - return 'GameFont'; -}; + if (this.setGraphicFolder(object.graphicFolder), block) { + changed++; + } -/** - * Returns the standard font size - * - * @returns {String} Standard font size - */ -DKTools.Sprite.prototype.standardFontSize = function() { - return 28; -}; + if (this.setGraphicName(object.graphicName, block)) { + changed++; + } -/** - * Returns the standard font italic - * - * @returns {String} Standard font italic - */ -DKTools.Sprite.prototype.standardFontItalic = function() { - return false; + if (changed) { + if (!blockStart) { + this.start(); + } + + if (activate) { + this.activate(); + } + } + + return changed; }; /** - * Returns the standard font + * Changes the width of the bitmap + * Returns true if the change occurred * - * @see DKTools.Sprite.prototype.standardFontFace - * @see DKTools.Sprite.prototype.standardFontSize - * @see DKTools.Sprite.prototype.standardFontItalic + * @version 3.1.0 * - * @returns {Object} Standard font + * @param {Number} [width] - Width of the bitmap + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Sprite.prototype._getBitmapHeight + * @see DKTools.Sprite.prototype.resize + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.standardFont = function() { - return { - fontFace: this.standardFontFace(), - fontSize: this.standardFontSize(), - fontItalic: this.standardFontItalic() - }; +DKTools.Sprite.prototype.setWidth = function(width, blockStart) { + return this.resize(width, this._getBitmapHeight(), blockStart); }; /** - * Returns the standard text color + * Changes the height of the bitmap + * Returns true if the change occurred * - * @returns {String} Standard text color + * @version 3.1.0 + * + * @param {Number} [height] - Height of the bitmap + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Sprite.prototype._getBitmapWidth + * @see DKTools.Sprite.prototype.resize + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.standardTextColor = function() { - return '#ffffff'; +DKTools.Sprite.prototype.setHeight = function(height, blockStart) { + return this.resize(this._getBitmapWidth(), height, blockStart); }; /** - * Returns the standard paint opacity + * Changes the bitmap + * Returns true if the change occurred * - * @returns {Number} Standard paint opacity + * @param {Bitmap | Object} [object] - Bitmap or object with parameters + * + * @param {String} object.folder - Path to file + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Sprite.prototype.setupBitmap + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.standardPaintOpacity = function() { - return 255; +DKTools.Sprite.prototype.setBitmap = function(object) { + if (this.bitmap == object) { + return false; + } + + this.setupBitmap(object); + + return true; }; /** - * Returns the standard fill color + * Changes the font of the bitmap + * Returns true if the change occurred * - * @returns {String | null} Standard fill color + * @param {Object} [font] - Text font + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @param {String} [font.fontFace] - Font face + * @param {Number} [font.fontSize] - Font size + * @param {Boolean} [font.fontItalic] - Font italic + * + * @see DKTools.Sprite.prototype.standardFont + * @see DKTools.Sprite.prototype.setupFont + * @see DKTools.Sprite.prototype.start + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.standardFillColor = function() { - return null; +DKTools.Sprite.prototype.setFont = function(font, blockStart) { + if (_.isEqual(this._font, Object.assign(this.standardFont(), font))) { + return false; + } + + this.setupFont(font); + + if (!blockStart) { + this.start(); + } + + return true; }; /** - * Returns the standard text align + * Changes the text color + * Returns true if the change occurred * - * @returns {String} Standard text align + * @param {String} [color] - Text color + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.prototype.setupTextColor + * @see DKTools.Sprite.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.standardAlign = function() { - return 'center'; +DKTools.Sprite.prototype.setTextColor = function(color, blockRefreshAll) { + if (this._textColor === color) { + return false; + } + + const lastColor = this._textColor; + this.setupTextColor(color); + + if (this._textColor === lastColor) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Returns the standard graphic folder + * Changes the paint opacity + * Returns true if the change occurred * - * @returns {String} Standard graphic folder - */ -DKTools.Sprite.prototype.standardGraphicFolder = function() { - return 'img/system/'; -}; - -/** - * Returns the standard graphic name + * @param {Number} [opacity] - Paint opacity + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @returns {String} standard graphic name - */ -DKTools.Sprite.prototype.standardGraphicName = function() { - return ''; -}; - -/** - * Returns the standard opacity + * @see DKTools.Sprite.prototype.setupPaintOpacity + * @see DKTools.Sprite.prototype.refreshAll * - * @returns {Number} Standard opacity + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.standardOpacity = function() { - return 255; -}; +DKTools.Sprite.prototype.setPaintOpacity = function(opacity, blockRefreshAll) { + if (this._paintOpacity === opacity) { + return false; + } -/** - * Returns the standard frame - * - * @returns {Rectangle} Standard frame - */ -DKTools.Sprite.prototype.standardFrame = function() { - return new Rectangle(0, 0, this.width, this.height); -}; + const lastOpacity = this._paintOpacity; + this.setupPaintOpacity(opacity); -/** - * Returns the standard anchor - * - * @returns {Point} Standard anchor - */ -DKTools.Sprite.prototype.standardAnchor = function() { - return new Point(0, 0); -}; + if (this._paintOpacity === lastOpacity) { + return false; + } -// setup methods + if (!blockRefreshAll) { + this.refreshAll(); + } -/** - * Sets all parameters - * - * @override - * - * @param {Object} [object] - Parameters - * - * @param {Bitmap | Object} [object.bitmap] - Bitmap or object with parameters - * @param {Object} [object.font] - Text font - * @param {String} [object.textColor] - Text color - * @param {Number} [object.paintOpacity] - Paint opacity - * @param {String} [object.fillColor] - Fill color - * @param {String} [object.align] - Text align - * @param {Number} [object.opacity] - Opacity - * @param {String} [object.graphicFolder] - Graphic folder - * @param {String} [object.graphicName] - Graphic name - * @param {PIXI.Rectangle | Rectangle | Object} [object.frame] - Rectangle or object with parameters - * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [object.anchor] - Anchor of the sprite - * - * @param {String} object.folder - Path to file - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @param {String} [object.font.fontFace] - Font face - * @param {Number} [object.font.fontSize] - Font size - * @param {Boolean} [object.font.fontItalic] - Font italic - * - * @param {Number} [object.frame.x] - The X coordinate - * @param {Number} [object.frame.y] - The Y coordinate - * @param {Number} [object.frame.width] - Width of the frame - * @param {Number} [object.frame.height] - Height of the frame - * - * @param {Number} [object.anchor.x] - The X coordinate - * @param {Number} [object.anchor.y] - The Y coordinate - * - * @see DKTools.Base.prototype.setupAll - * @see DKTools.Sprite.prototype.setupBitmap - * @see DKTools.Sprite.prototype.setupFont - * @see DKTools.Sprite.prototype.setupTextColor - * @see DKTools.Sprite.prototype.setupPaintOpacity - * @see DKTools.Sprite.prototype.setupFillColor - * @see DKTools.Sprite.prototype.setupAlign - * @see DKTools.Sprite.prototype.setupOpacity - * @see DKTools.Sprite.prototype.setupGraphicFolder - * @see DKTools.Sprite.prototype.setupGraphicName - * @see DKTools.Sprite.prototype.setupFrame - * @see DKTools.Sprite.prototype.setupAnchor - */ -DKTools.Sprite.prototype.setupAll = function(object) { - object = object || {}; - DKTools.Base.prototype.setupAll.call(this, object); - this.setupBitmap(object); - this.setupFont(object.font); - this.setupTextColor(object.textColor); - this.setupPaintOpacity(object.paintOpacity); - this.setupFillColor(object.fillColor); - this.setupAlign(object.align); - this.setupOpacity(object.opacity); - this.setupGraphicFolder(object.graphicFolder); - this.setupGraphicName(object.graphicName); - this.setupFrame(object.frame); - this.setupAnchor(object.anchor); + return true; }; /** - * Sets the width of the bitmap - * - * @param {Number} [width] - Width of the bitmap + * Changes the fill color + * Returns true if the change occurred * - * @see DKTools.Base.prototype._checkWidth - */ -DKTools.Sprite.prototype.setupWidth = function(width) { - /** - * @private - * @readonly - * @type {Number} - */ - this._bitmapWidth = this._checkWidth(width); -}; - -/** - * Sets the height of the bitmap + * @param {String} [color] - Fill color + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @param {Number | String} [height] - Height of the bitmap or number of lines + * @see DKTools.Sprite.prototype.setupFillColor + * @see DKTools.Sprite.prototype.refreshAll * - * @see DKTools.Base.prototype.getLineHeight - * @see DKTools.Base.prototype._checkHeight + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupHeight = function(height) { - if (DKTools.Utils.isString(height)) { - height = this.getLineHeight() * Number(height); +DKTools.Sprite.prototype.setFillColor = function(color, blockRefreshAll) { + if (this._fillColor === color) { + return false; } - /** - * @private - * @readonly - * @type {Number} - */ - this._bitmapHeight = this._checkHeight(height); + const lastColor = this._fillColor; + this.setupFillColor(color); + + if (this._fillColor === lastColor) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Sets the size of the bitmap + * Changes the align + * Returns true if the change occurred * - * @param {Number | Object} [object] - Width of the bitmap or object with parameters - * @param {Number} [height] - Height of the bitmap (if object is Object) + * @param {String} [align] - Text align + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @param {Number} [object.width] - Width of the bitmap - * @param {Number} [object.height] - Height of the bitmap + * @see DKTools.Sprite.prototype.setupAlign + * @see DKTools.Sprite.prototype.refreshAll * - * @see DKTools.Sprite.prototype.setupWidth - * @see DKTools.Sprite.prototype.setupHeight + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupSize = function(object, height) { - if (object instanceof Object) { - return this.setupSize(object.width, object.height); +DKTools.Sprite.prototype.setAlign = function(align, blockRefreshAll) { + if (this._align === align) { + return false; } - this.setupWidth(object); - this.setupHeight(height); + const lastAlign = this._align; + this.setupAlign(align); + + if (this._align === lastAlign) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Sets the bitmap - * - * @version 2.0.1 + * Changes the opacity of the sprite + * Returns true if the change occurred * - * @param {Bitmap | Object} [object] - Bitmap or object with parameters + * @param {Number} [opacity] - Opacity of the sprite + * @param {Boolean} [blockUpdateOpacity=false] - Blocking the call of the "updateOpacity" function * - * @param {String} object.folder - Path to file - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap + * @see DKTools.Sprite.prototype.setupOpacity + * @see DKTools.Sprite.prototype.updateOpacity * - * @see DKTools.Utils.Bitmap.load + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupBitmap = function(object) { - let bitmap = null; +DKTools.Sprite.prototype.setOpacity = function(opacity, blockUpdateOpacity) { + if (this._opacity === opacity) { + return false; + } - if (object instanceof DKTools.Sprite && - object.hasFixedBitmap() && - object.canCloneFixedBitmap()) { - bitmap = DKTools.Utils.Bitmap.clone(object.bitmap); - } else { - bitmap = DKTools.Utils.Bitmap.load(object); + const lastOpacity = this._opacity; + this.setupOpacity(opacity); + + if (this._opacity === lastOpacity) { + return false; } - if (bitmap) { - this.bitmap = bitmap; - this.bitmap.addLoadListener(this.setupSize.bind(this)); - } else { - this.bitmap = null; + if (!blockUpdateOpacity) { + this.updateOpacity(); } - /** - * @private - * @readonly - * @type {Boolean} - */ - this._fixedBitmap = !!this.bitmap; + return true; }; /** - * Sets the font of the bitmap - * - * @param {Object} [font=this.standardFont()] - Text font + * Changes the graphic folder + * Returns true if the change occurred * - * @param {String} [object.font.fontFace] - Font face - * @param {Number} [object.font.fontSize] - Font size - * @param {Boolean} [object.font.fontItalic] - Font italic + * @param {String} [folder] - Graphic folder + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Sprite.prototype.standardFont - */ -DKTools.Sprite.prototype.setupFont = function(font) { - /** - * @private - * @readonly - * @type {Object} - */ - this._font = Object.assign(this.standardFont(), font); -}; - -/** - * Sets the color of the text - * - * @param {String} [color=this.standardTextColor()] - Text color + * @see DKTools.Sprite.prototype.setupGraphicFolder + * @see DKTools.Sprite.prototype.start * - * @see DKTools.Sprite.prototype.standardTextColor + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupTextColor = function(color) { - /** - * @private - * @readonly - * @type {String} - */ - this._textColor = color || this.standardTextColor(); -}; +DKTools.Sprite.prototype.setGraphicFolder = function(folder, blockStart) { + if (this._graphicFolder === folder) { + return false; + } -/** - * Sets the paint opacity - * - * @param {Number} [opacity=this.standardPaintOpacity()] - Paint opacity - * - * @see DKTools.Sprite.prototype.standardPaintOpacity - */ -DKTools.Sprite.prototype.setupPaintOpacity = function(opacity) { - /** - * @private - * @readonly - * @type {Number} - */ - this._paintOpacity = (opacity == null ? this.standardPaintOpacity() : opacity); -}; + const lastFolder = this._graphicFolder; + this.setupGraphicFolder(folder); -/** - * Sets the fill color - * - * @param {String} [color=this.standardFillColor()] - Fill color - * - * @see DKTools.Sprite.prototype.standardFillColor - */ -DKTools.Sprite.prototype.setupFillColor = function(color) { - /** - * @private - * @readonly - * @type {String | null} - */ - this._fillColor = (color == null ? this.standardFillColor() : color); -}; + if (this._graphicFolder === lastFolder) { + return false; + } -/** - * Sets the align - * - * @param {String} [align=this.standardAlign()] - Text align - * - * @see DKTools.Sprite.prototype.standardAlign - */ -DKTools.Sprite.prototype.setupAlign = function(align) { - /** - * @private - * @readonly - * @type {String} - */ - this._align = align || this.standardAlign(); -}; + if (!blockStart) { + this.start(); + } -/** - * Sets the opacity of the sprite - * - * @param {Number} [opacity=this.standardOpacity()] - Opacity - * - * @see DKTools.Sprite.prototype.standardOpacity - */ -DKTools.Sprite.prototype.setupOpacity = function(opacity) { - /** - * @private - * @readonly - * @type {Number} - */ - this._opacity = (opacity == null ? this.standardOpacity() : opacity); + return true; }; /** - * Sets the graphic folder - * - * @param {String} [folder=this.standardGraphicFolder()] - Path to folder + * Changes the graphic name + * Returns true if the change occurred * - * @see DKTools.Sprite.prototype.standardGraphicFolder - */ -DKTools.Sprite.prototype.setupGraphicFolder = function(folder) { - /** - * @private - * @readonly - * @type {String} - */ - this._graphicFolder = (folder == null ? this.standardGraphicFolder() : folder); -}; - -/** - * Sets the graphic name + * @param {String} [graphicName] - Graphic name + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @param {String} [graphicName=this.standardGraphicName()] - Graphic name + * @see DKTools.Sprite.prototype.setupGraphicName + * @see DKTools.Sprite.prototype.start * - * @see DKTools.Sprite.prototype.standardGraphicName + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupGraphicName = function(graphicName) { - /** - * @private - * @readonly - * @type {String} - */ - this._graphicName = (graphicName == null ? this.standardGraphicName() : graphicName); +DKTools.Sprite.prototype.setGraphicName = function(graphicName, blockStart) { + if (this._graphicName === graphicName) { + return false; + } + + const lastGraphic = this._graphicName; + this.setupGraphicName(graphicName); + + if (this._graphicName === lastGraphic) { + return false; + } + + if (!blockStart) { + this.start(); + } + + return true; }; /** - * Sets the frame of the sprite + * Changes the frame of the sprite + * Returns true if the change occurred * - * @version 1.1.0 + * @override * * @param {Number | Rectangle | Object} [object] - The X coordinate or Rectangle or object with parameters * @param {Number} [y] - The Y coordinate (if object is Number) @@ -15181,450 +15401,429 @@ DKTools.Sprite.prototype.setupGraphicName = function(graphicName) { * @param {Number} [object.height] - Height of the frame * * @see DKTools.Utils.Rectangle.toRectangle - * @see DKTools.Sprite.prototype.standardFrame - * @see Sprite.prototype.setFrame - * @see DKTools.Sprite.prototype.hasFixedBitmap + * @see DKTools.Utils.Rectangle.equals + * @see DKTools.Utils.Rectangle.clone + * @see DKTools.Sprite.prototype.setupFrame + * @see DKTools.Utils.Rectangle.equals + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupFrame = function(object, y, width, height) { - const frame = DKTools.Utils.Rectangle.toRectangle(object, y, width, height); - const newFrame = Object.assign(this.standardFrame(), frame); - - Sprite.prototype.setFrame.call(this, newFrame.x, newFrame.y, newFrame.width, newFrame.height); +DKTools.Sprite.prototype.setFrame = function(object, y, width, height) { + if (object instanceof Object) { + return this.setFrame(object.x, object.y, object.width, object.height); + } + + // object - Number + const newFrame = DKTools.Utils.Rectangle.toRectangle(object, y, width, height); - if (this.hasFixedBitmap() && !this.bitmap.isReady()) { - this._refreshFrame = true; + if (DKTools.Utils.Rectangle.equals(this._frame, newFrame)) { + return false; } + + const lastFrame = DKTools.Utils.Rectangle.clone(this._frame); + this.setupFrame(newFrame); + + return !DKTools.Utils.Rectangle.equals(this._frame, lastFrame); }; /** - * Sets the anchor of the sprite + * Changes the anchor of the sprite + * Returns true if the change occurred * - * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object=this.standardAnchor()] - The X coordinate or Point or object with parameters - * @param {Number} [y=undefined] - The Y coordinate (is object is Number) + * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - The X coordinate or Point or object with parameters + * @param {Number} [y] - The Y coordinate (is object is Number) * * @param {Number} [object.x] - The X coordinate * @param {Number} [object.y] - The Y coordinate * * @see DKTools.Utils.Point.toPoint - * @see DKTools.Sprite.prototype.standardAnchor + * @see DKTools.Utils.Point.clone + * @see DKTools.Sprite.prototype.setupAnchor + * @see DKTools.Utils.Point.equals + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupAnchor = function(object, y) { - const anchor = DKTools.Utils.Point.toPoint(object, y); - const newAnchor = Object.assign(this.standardAnchor(), anchor); +DKTools.Sprite.prototype.setAnchor = function(object, y) { + if (object instanceof Object) { + return this.setAnchor(object.x, object.y); + } - /** - * @type {PIXI.ObservablePoint} - */ - this.anchor.copy(newAnchor); + // object - Number + const newAnchor = DKTools.Utils.Point.toPoint(object, y); + + if (DKTools.Utils.Point.equals(this.anchor, newAnchor)) { + return false; + } + + const lastAnchor = DKTools.Utils.Point.clone(this.anchor); + this.setupAnchor(newAnchor); + + return !DKTools.Utils.Point.equals(this.anchor, lastAnchor); }; /** - * Sets the mask + * Changes the mask + * Returns true if the change occurred * * @since 2.0.0 * @param {PIXI.Graphics} [mask] - Mask + * + * @see DKTools.Sprite.prototype.setupMask + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setupMask = function(mask) { - this.mask = mask || null; +DKTools.Sprite.prototype.setMask = function(mask) { + if (this.mask == mask) { + return false; + } + + this.setupMask(mask); + + return true; }; +// remove methods + /** - * Sets the listener on load of graphic - * - * @param {Function} listener - Listener + * Removes the bitmap + * + * @see DKTools.Sprite.prototype.hasBitmap + * @see DKTools.Sprite.prototype.setBitmap */ -DKTools.Sprite.prototype.setupGraphicLoadListener = function(listener) { - /** - * @private - * @readonly - * @type {Function} - */ - this._graphicLoadListener = listener || null; +DKTools.Sprite.prototype.removeBitmap = function() { + if (this.hasBitmap()) { + this.setBitmap(); + } }; -// set methods - /** - * Changes all parameters - * Returns the number of changed parameters - * - * @override - * - * @param {Object} [object={}] - Parameters - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the sprite - * - * @param {Object} [object.font] - Text font - * @param {String} [object.textColor] - Text color - * @param {Number} [object.paintOpacity] - Paint opacity - * @param {String} [object.fillColor] - Fill color - * @param {String} [object.align] - Text align - * @param {Number} [object.opacity] - Opacity - * @param {String} [object.graphicFolder] - Graphic folder - * @param {String} [object.graphicName] - Graphic name - * - * @param {String} [object.font.fontFace] - Название шрифта - * @param {Number} [object.font.fontSize] - Размер шрифта - * @param {Boolean} [object.font.fontItalic] - Курсив шрифта - * - * @see DKTools.Base.prototype.setAll - * @see DKTools.Sprite.prototype.setFont - * @see DKTools.Sprite.prototype.setTextColor - * @see DKTools.Sprite.prototype.setPaintOpacity - * @see DKTools.Sprite.prototype.setFillColor - * @see DKTools.Sprite.prototype.setAlign - * @see DKTools.Sprite.prototype.setOpacity - * @see DKTools.Sprite.prototype.setGraphicFolder + * Removes the graphic name + * + * @see DKTools.Sprite.prototype.hasGraphicName * @see DKTools.Sprite.prototype.setGraphicName - * @see DKTools.Sprite.prototype.start - * @see DKTools.Sprite.prototype.activate - * - * @returns {Number} Number of changed parameters */ -DKTools.Sprite.prototype.setAll = function(object, blockStart, activate) { - object = object || {}; - const block = true; - let changed = DKTools.Base.prototype.setAll.call(this, object, block); - - if (this.setFont(object.font, block)) { - changed++; +DKTools.Sprite.prototype.removeGraphicName = function() { + if (this.hasGraphicName()) { + this.setGraphicName(); } +}; - if (this.setTextColor(object.textColor, block)) { - changed++; - } +/** + * Removes the text by ID + * + * @param {Number | String | *} id - ID of the text + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.prototype.getTextById + * @see DKTools.Sprite.prototype.refreshAll + * @see DKTools.Utils.Array.remove + */ +DKTools.Sprite.prototype.removeText = function(id, blockRefreshAll) { + const textObj = this.getTextById(id); - if (this.setPaintOpacity(object.paintOpacity, block)) { - changed++; - } + if (textObj) { + DKTools.Utils.Array.remove(this._texts, textObj); - if (this.setFillColor(object.fillColor, block)) { - changed++; + if (!blockRefreshAll) { + this.refreshAll(); + } } +}; - if (this.setAlign(object.align, block)) { - changed++; - } +// check methods - if (this.setOpacity(object.opacity, block)) { - changed++; - } +/** + * Checks the size of the sprirte + * Returns the number of changed parameters + * + * @override + * + * @see DKTools.Sprite.prototype.getMinWidth + * @see DKTools.Sprite.prototype.getMinHeight + * @see DKTools.Sprite.prototype.setupWidth + * @see DKTools.Sprite.prototype.setupHeight + * + * @returns {Number} Number of changed parameters + */ +DKTools.Sprite.prototype.checkSize = function() { + const minWidth = this.getMinWidth(); + const minHeight = this.getMinHeight(); + let changed = 0; - if (this.setGraphicFolder(object.graphicFolder), block) { + if (this._bitmapWidth < minWidth) { + this.setupWidth(minWidth); changed++; } - if (this.setGraphicName(object.graphicName, block)) { + if (this._bitmapHeight < minHeight) { + this.setupHeight(minHeight); changed++; } - if (changed) { - if (!blockStart) { - this.start(); - } - - if (activate) { - this.activate(); - } - } - - return changed; + return changed; }; +// create methods + /** - * Changes the width of the bitmap - * Returns true if the change occurred + * Creates all objects * - * @param {Number} [width] - Width of the bitmap - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @version 2.0.0 * - * @see DKTools.Sprite.prototype.resize + * @override * - * @returns {Boolean} Change occurred + * @see DKTools.Base.prototype.createAll + * @see DKTools.Sprite.prototype.createBitmap + * @see DKTools.Sprite.prototype.createMask */ -DKTools.Sprite.prototype.setWidth = function(width, blockStart) { - return this.resize(width, this._bitmapHeight, blockStart); +DKTools.Sprite.prototype.createAll = function() { + DKTools.Base.prototype.createAll.call(this); + this.createBitmap(); + this.createMask(); }; /** - * hanges the width of the bitmap - * Returns true if the change occurred - * - * @param {Number} [height] - Height of the bitmap - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * Loads an image by graphic name (if exists) or create the bitmap (if the fixed bitmap does not exist) * - * @see DKTools.Sprite.prototype.resize + * @version 1.1.0 * - * @returns {Boolean} Change occurred + * @see DKTools.Sprite.prototype.hasGraphicName + * @see DKTools.Sprite.prototype._loadGraphic + * @see DKTools.Sprite.prototype.hasFixedBitmap + * @see DKTools.Sprite.prototype._getBitmapWidth + * @see DKTools.Sprite.prototype._getBitmapHeight + * @see Bitmap */ -DKTools.Sprite.prototype.setHeight = function(height, blockStart) { - return this.resize(this._bitmapWidth, height, blockStart); +DKTools.Sprite.prototype.createBitmap = function() { + if (this.hasGraphicName()) { + this._loadGraphic(); + } else if (!this.hasFixedBitmap()) { + this.bitmap = new Bitmap(this._getBitmapWidth(), this._getBitmapHeight()); + } }; /** - * Changes the bitmap - * Returns true if the change occurred - * - * @param {Bitmap | Object} [object] - Bitmap or object with parameters - * - * @param {String} object.folder - Path to file - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see DKTools.Sprite.prototype.setupBitmap - * - * @returns {Boolean} Change occurred + * Creates a mask + * + * @since 2.0.0 + * + * @see DKTools.Sprite.prototype.createRectMask + * @see DKTools.Sprite.prototype.createCircleMask + * @see DKTools.Sprite.prototype.createEllipseMask */ -DKTools.Sprite.prototype.setBitmap = function(object) { - if (this.bitmap == object) { - return false; +DKTools.Sprite.prototype.createMask = function(maskShape) { + switch (maskShape) { + case 'rect': + this.createRectMask(); + break; + case 'circle': + this.createCircleMask(); + break; + case 'ellipse': + this.createEllipseMask(); + break; } - - this.setupBitmap(object); - - return true; }; /** - * Changes the font of the bitmap - * Returns true if the change occurred - * - * @param {Object} [font] - Text font - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @param {String} [object.font.fontFace] - Font face - * @param {Number} [object.font.fontSize] - Font size - * @param {Boolean} [object.font.fontItalic] - Font italic - * - * @see DKTools.Sprite.prototype.standardFont - * @see DKTools.Sprite.prototype.setupFont - * @see DKTools.Sprite.prototype.start + * Creates a mask in the form of a rectangle * - * @returns {Boolean} Change occurred + * @since 2.0.0 + * + * @see DKTools.Sprite.prototype.setMask + * @see PIXI.Graphics */ -DKTools.Sprite.prototype.setFont = function(font, blockStart) { - if (_.isEqual(this._font, Object.assign(this.standardFont(), font))) { - return false; - } - - this.setupFont(font); +DKTools.Sprite.prototype.createRectMask = function() { + const mask = new PIXI.Graphics(); - if (!blockStart) { - this.start(); - } + mask.beginFill(); + mask.drawRect(this.x, this.y, this.bitmap.width, this.bitmap.height); + mask.endFill(); - return true; + this.setMask(mask); }; /** - * Changes the text color - * Returns true if the change occurred - * - * @param {String} [color] - Text color - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.prototype.setupTextColor - * @see DKTools.Sprite.prototype.refreshAll + * Creates a mask in the form of a circle * - * @returns {Boolean} Change occurred + * @since 2.0.0 + * + * @see DKTools.Sprite.prototype.setMask + * @see PIXI.Graphics */ -DKTools.Sprite.prototype.setTextColor = function(color, blockRefreshAll) { - if (this._textColor === color) { - return false; - } +DKTools.Sprite.prototype.createCircleMask = function() { + const mask = new PIXI.Graphics(); + const radius = this.bitmap.width / 2; + const centerX = this.x + radius; + const centerY = this.y + radius; - const lastColor = this._textColor; - this.setupTextColor(color); + mask.beginFill(); + mask.drawCircle(centerX, centerY, radius); + mask.endFill(); - if (this._textColor === lastColor) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return true; -}; + this.setMask(mask); +}; /** - * Changes the paint opacity - * Returns true if the change occurred - * - * @param {Number} [opacity] - Paint opacity - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.prototype.setupPaintOpacity - * @see DKTools.Sprite.prototype.refreshAll + * Creates a mask in the form of an ellipse * - * @returns {Boolean} Change occurred + * @since 2.0.0 + * + * @see DKTools.Sprite.prototype.setMask + * @see PIXI.Graphics */ -DKTools.Sprite.prototype.setPaintOpacity = function(opacity, blockRefreshAll) { - if (this._paintOpacity === opacity) { - return false; - } - - const lastOpacity = this._paintOpacity; - this.setupPaintOpacity(opacity); - - if (this._paintOpacity === lastOpacity) { - return false; - } +DKTools.Sprite.prototype.createEllipseMask = function() { + const mask = new PIXI.Graphics(); + const width = this.bitmap.width / 2; + const height = this.bitmap.height / 2; + const centerX = this.x + width; + const centerY = this.y + height; - if (!blockRefreshAll) { - this.refreshAll(); - } + mask.beginFill(); + mask.drawEllipse(centerX, centerY, width, height); + mask.endFill(); - return true; + this.setMask(mask); }; +// add methods + /** - * Changes the fill color - * Returns true if the change occurred + * Adds the text * - * @param {String} [color] - Fill color - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {String | Number} text - Text + * @param {Object} options - Options + * @param {Boolean} [refreshAll=false] - Refreshes all * - * @see DKTools.Sprite.prototype.setupFillColor - * @see DKTools.Sprite.prototype.refreshAll + * @param {String | Number} [options.id] - ID of the text + * @param {String} [options.type='drawText'] - Type of the text ('drawText' or 'drawTextEx') * - * @returns {Boolean} Change occurred + * @see DKTools.Sprite.prototype.drawTextEx + * @see DKTools.Sprite.prototype.drawText */ -DKTools.Sprite.prototype.setFillColor = function(color, blockRefreshAll) { - if (this._fillColor === color) { - return false; +DKTools.Sprite.prototype.addText = function(text, options, refreshAll) { + if (text == null) { + return; } - const lastColor = this._fillColor; - this.setupFillColor(color); + text = String(text); + options = options || {}; - if (this._fillColor === lastColor) { - return false; - } + this._texts.push({ + text, + options, + id: options.id, + type: options.type || 'drawText' + }); - if (!blockRefreshAll) { + if (refreshAll) { this.refreshAll(); } - - return true; }; +// redraw methods + /** - * Changes the align - * Returns true if the change occurred - * - * @param {String} [align] - Text align - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.prototype.setupAlign - * @see DKTools.Sprite.prototype.refreshAll + * Redraws all * - * @returns {Boolean} Change occurred + * @version 1.1.0 + * @override + * + * @see DKTools.Sprite.prototype.clear + * @see DKTools.Sprite.prototype.drawAll + * @see DKTools.Sprite.prototype.updateRedrawAllEvents */ -DKTools.Sprite.prototype.setAlign = function(align, blockRefreshAll) { - if (this._align === align) { - return false; - } - - const lastAlign = this._align; - this.setupAlign(align); - - if (this._align === lastAlign) { - return false; - } +DKTools.Sprite.prototype.redrawAll = function() { + this.clear(); + this.drawAll(); + this.updateRedrawAllEvents(); +}; - if (!blockRefreshAll) { - this.refreshAll(); - } +// _get methods - return true; +/** + * Returns the width of the bitmap + * + * @since 2.0.0 + * @private + * @returns {Number} Width of the bitmap + */ +DKTools.Sprite.prototype._getBitmapWidth = function() { + return this._bitmapWidth; }; /** - * Changes the opacity of the sprite - * Returns true if the change occurred - * - * @param {Number} [opacity] - Opacity of the sprite - * @param {Boolean} [blockUpdateOpacity=false] - Blocking the call of the "updateOpacity" function - * - * @see DKTools.Sprite.prototype.setupOpacity - * @see DKTools.Sprite.prototype.updateOpacity - * - * @returns {Boolean} Change occurred + * Returns the height of the bitmap + * + * @since 2.0.0 + * @private + * @returns {Number} Height of the bitmap */ -DKTools.Sprite.prototype.setOpacity = function(opacity, blockUpdateOpacity) { - if (this._opacity === opacity) { - return false; - } +DKTools.Sprite.prototype._getBitmapHeight = function() { + return this._bitmapHeight; +}; - const lastOpacity = this._opacity; - this.setupOpacity(opacity); - - if (this._opacity === lastOpacity) { - return false; - } +// get methods - if (!blockUpdateOpacity) { - this.updateOpacity(); - } +/** + * Returns an object of text by its ID + * + * @param {Number | String | *} id - ID of object of text + * @returns {Object} Object of text + */ +DKTools.Sprite.prototype.getTextById = function(id) { + return _.find(this._texts, { id }); +}; - return true; +/** + * Returns the current opacity of the sprite + * + * @returns {Number} Current opacity of the sprite + */ +DKTools.Sprite.prototype.getCurrentOpacity = function() { + return this.alpha * 255; }; +// size methods + /** - * Changes the graphic folder + * Changes the width and height of the sprite * Returns true if the change occurred * - * @param {String} [graphicName] - Graphic folder + * @param {Number} [width] - Width of the sprite + * @param {Number | String} [height] - Height of the sprite or number of lines * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Sprite.prototype.setupGraphicFolder + * @see DKTools.Sprite.prototype.isResizable + * @see DKTools.Sprite.prototype.getMinWidth + * @see DKTools.Sprite.prototype.getMinHeight + * @see DKTools.Sprite.prototype.setupSize * @see DKTools.Sprite.prototype.start * * @returns {Boolean} Change occurred */ -DKTools.Sprite.prototype.setGraphicFolder = function(folder, blockStart) { - if (this._graphicFolder === folder) { +DKTools.Sprite.prototype.resize = function(width, height, blockStart) { + if (!this.isResizable()) { return false; } - const lastFolder = this._graphicFolder; - this.setupGraphicFolder(folder); - - if (this._graphicFolder === lastFolder) { - return false; - } + width = (width == null ? this.getMinWidth() : width); + height = (height == null ? this.getMinHeight() : height); - if (!blockStart) { - this.start(); + if (DKTools.Utils.isString(height)) { + height = this.getLineHeight() * Number(height); } - return true; -}; - -/** - * Changes the graphic name - * Returns true if the change occurred - * - * @param {String} [graphicName] - Graphic name - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @see DKTools.Sprite.prototype.setupGraphicName - * @see DKTools.Sprite.prototype.start - * - * @returns {Boolean} Change occurred - */ -DKTools.Sprite.prototype.setGraphicName = function(graphicName, blockStart) { - if (this._graphicName === graphicName) { + if (this._bitmapWidth === width && this._bitmapHeight === height) { return false; } - const lastGraphic = this._graphicName; - this.setupGraphicName(graphicName); + const lastWidth = this._bitmapWidth; + const lastHeight = this._bitmapHeight; - if (this._graphicName === lastGraphic) { + this.setupSize(width, height); + + if (this._bitmapWidth === lastWidth && this._bitmapHeight === lastHeight) { return false; } @@ -15635,1011 +15834,1438 @@ DKTools.Sprite.prototype.setGraphicName = function(graphicName, blockStart) { return true; }; +// can methods + /** - * Changes the frame of the sprite - * Returns true if the change occurred + * Returns true if the sprite can be updated and redrawn * - * @override + * @since 1.1.0 * - * @param {Number | Rectangle | Object} [object] - The X coordinate or Rectangle or object with parameters - * @param {Number} [y] - The Y coordinate (if object is Number) - * @param {Number} [width] - Width of the frame (if object is Number) - * @param {Number} [height] - Height of the frame (if object is Number) + * @override * - * @param {Number} [object.x] - The X coordinate - * @param {Number} [object.y] - The Y coordinate - * @param {Number} [object.width] - Width of the frame - * @param {Number} [object.height] - Height of the frame + * @see DKTools.Base.prototype.canRedrawAll + * @see DKTools.Sprite.prototype.hasGraphicName + * @see DKTools.Sprite.prototype.hasFixedBitmap * - * @see DKTools.Utils.Rectangle.toRectangle - * @see DKTools.Utils.Rectangle.equals - * @see DKTools.Utils.Rectangle.clone - * @see DKTools.Sprite.prototype.setupFrame - * @see DKTools.Utils.Rectangle.equals + * @returns {Boolean} Sprite can be updated and redrawn + */ +DKTools.Sprite.prototype.canRedrawAll = function() { + return DKTools.Base.prototype.canRedrawAll.call(this) && !this.hasGraphicName() && !this.hasFixedBitmap(); +}; + +/** + * Returns true if the sprite can clone the fixed bitmap * - * @returns {Boolean} Change occurred + * @returns {Boolean} Sprite can clone the fixed bitmap */ -DKTools.Sprite.prototype.setFrame = function(object, y, width, height) { - if (object instanceof Object) { - return this.setFrame(object.x, object.y, object.width, object.height); - } +DKTools.Sprite.prototype.canCloneFixedBitmap = function() { + return true; +}; - // object - Number - const newFrame = DKTools.Utils.Rectangle.toRectangle(object, y, width, height); +// effects methods - if (DKTools.Utils.Rectangle.equals(this._frame, newFrame)) { +/** + * Changes the tone of the bitmap + * Returns true if bitmap exists + * + * @param {Number[]} tone - Tone (RGB) + * + * @see DKTools.Sprite.prototype.hasBitmap + * @see Bitmap.prototype.adjustTone + * + * @returns {Boolean} Bitmap exists + */ +DKTools.Sprite.prototype.adjustTone = function(tone) { + if (!this.hasBitmap()) { return false; } - const lastFrame = DKTools.Utils.Rectangle.clone(this._frame); - this.setupFrame(newFrame); + if (DKTools.Utils.Array.isNumberArray(tone) && tone.length === 3) { + Bitmap.prototype.adjustTone.apply(this.bitmap, tone); + return true; + } - return !DKTools.Utils.Rectangle.equals(this._frame, lastFrame); + return false; }; /** - * Changes the anchor of the sprite - * Returns true if the change occurred - * - * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - The X coordinate or Point or object with parameters - * @param {Number} [y=undefined] - The Y coordinate (is object is Number) - * - * @param {Number} [object.x] - The X coordinate - * @param {Number} [object.y] - The Y coordinate - * - * @see DKTools.Utils.Point.toPoint - * @see DKTools.Utils.Point.clone - * @see DKTools.Sprite.prototype.setupAnchor - * @see DKTools.Utils.Point.equals + * Rotates the hue of the bitmap + * Returns true if bitmap exists * - * @returns {Boolean} Change occurred + * @param {Number} offset - Offset + * + * @see DKTools.Sprite.prototype.hasBitmap + * @see Bitmap.prototype.rotateHue + * + * @returns {Boolean} Bitmap exists */ -DKTools.Sprite.prototype.setAnchor = function(object, y) { - if (object instanceof Object) { - return this.setAnchor(object.x, object.y); - } - - // object - Number - const newAnchor = DKTools.Utils.Point.toPoint(object, y); - - if (DKTools.Utils.Point.equals(this.anchor, newAnchor)) { +DKTools.Sprite.prototype.rotateHue = function(offset) { + if (!this.hasBitmap()) { return false; } - const lastAnchor = DKTools.Utils.Point.clone(this.anchor); - this.setupAnchor(newAnchor); + this.bitmap.rotateHue(offset); - return !DKTools.Utils.Point.equals(this.anchor, lastAnchor); + return true; }; /** - * Changes the mask - * Returns true if the change occurred - * - * @since 2.0.0 - * @param {PIXI.Graphics} [mask] - Mask + * Imposes a blur effect on the bitmap + * Returns true if bitmap exists + * + * @see DKTools.Sprite.prototype.hasBitmap + * @see Bitmap.prototype.blur * - * @returns {Boolean} Change occurred + * @returns {Boolean} Bitmap exists */ -DKTools.Sprite.prototype.setMask = function(mask) { - if (this.mask == mask) { +DKTools.Sprite.prototype.blur = function() { + if (!this.hasBitmap()) { return false; } - this.setupMask(mask); + this.bitmap.blur(); return true; }; -// remove methods +// change methods /** - * Removes the bitmap - * + * Changes the font of the bitmap + * + * @param {Object} font - Text font + * + * @param {String} [font.fontFace] - Font face + * @param {Number} [font.fontSize] - Font size + * @param {Boolean} [font.fontItalic] - Font italic + * * @see DKTools.Sprite.prototype.hasBitmap - * @see DKTools.Sprite.prototype.setBitmap + * @see DKTools.Sprite.prototype.updateFont */ -DKTools.Sprite.prototype.removeBitmap = function() { +DKTools.Sprite.prototype.changeFont = function(font) { if (this.hasBitmap()) { - this.setBitmap(); + this.updateFont(font); } }; /** - * Removes the graphic name - * - * @see DKTools.Sprite.prototype.hasGraphicName - * @see DKTools.Sprite.prototype.setGraphicName + * Changes the text color + * + * @param {String} textColor - Text color + * + * @see DKTools.Sprite.prototype.hasBitmap + * @see DKTools.Sprite.prototype.updateTextColor */ -DKTools.Sprite.prototype.removeGraphicName = function() { - if (this.hasGraphicName()) { - this.setGraphicName(); +DKTools.Sprite.prototype.changeTextColor = function(textColor) { + if (this.hasBitmap()) { + this.updateTextColor(textColor); } }; /** - * Removes the text by ID + * Changes the paint opacity * - * @param {Number | String | *} id - ID of the text - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {Number} paintOpacity - Paint opacity * - * @see DKTools.Sprite.prototype.getTextById - * @see DKTools.Sprite.prototype.refreshAll - * @see DKTools.Utils.Array.remove + * @see DKTools.Sprite.prototype.hasBitmap + * @see DKTools.Sprite.prototype.updatePaintOpacity */ -DKTools.Sprite.prototype.removeText = function(id, blockRefreshAll) { - const textObj = this.getTextById(id); - - if (textObj) { - DKTools.Utils.Array.remove(this._texts, textObj); - - if (!blockRefreshAll) { - this.refreshAll(); - } +DKTools.Sprite.prototype.changePaintOpacity = function(paintOpacity) { + if (this.hasBitmap()) { + this.updatePaintOpacity(paintOpacity); } }; -// check methods +// reset methods /** - * Checks the size of the sprirte - * Returns the number of changed parameters - * - * @override - * - * @see DKTools.Sprite.prototype.getMinWidth - * @see DKTools.Sprite.prototype.getMinHeight - * @see DKTools.Sprite.prototype.setupWidth - * @see DKTools.Sprite.prototype.setupHeight + * Resets all * - * @returns {Number} Number of changed parameters + * @see DKTools.Sprite.prototype.resetFont + * @see DKTools.Sprite.prototype.resetTextColor + * @see DKTools.Sprite.prototype.resetPaintOpacity */ -DKTools.Sprite.prototype.checkSize = function() { - const minWidth = this.getMinWidth(); - const minHeight = this.getMinHeight(); - let changed = 0; - - if (this._bitmapWidth < minWidth) { - this.setupWidth(minWidth); - changed++; - } - - if (this._bitmapHeight < minHeight) { - this.setupHeight(minHeight); - changed++; - } - - return changed; +DKTools.Sprite.prototype.resetAll = function() { + this.resetFont(); + this.resetTextColor(); + this.resetPaintOpacity(); }; -// create methods - /** - * Creates all objects - * - * @version 2.0.0 - * - * @override + * Resets the font * - * @see DKTools.Base.prototype.createAll - * @see DKTools.Sprite.prototype.createBitmap - * @see DKTools.Sprite.prototype.createMask + * @see DKTools.Sprite.prototype.changeFont */ -DKTools.Sprite.prototype.createAll = function() { - DKTools.Base.prototype.createAll.call(this); - this.createBitmap(); - this.createMask(); +DKTools.Sprite.prototype.resetFont = function() { + this.changeFont(this.font); }; /** - * Loads an image by graphic name (if exists) or create the bitmap (if the fixed bitmap does not exist) - * - * @version 1.1.0 + * Resets the text color * - * @see DKTools.Sprite.prototype.hasGraphicName - * @see DKTools.Sprite.prototype._loadGraphic - * @see DKTools.Sprite.prototype.hasFixedBitmap - * @see DKTools.Sprite.prototype._getBitmapWidth - * @see DKTools.Sprite.prototype._getBitmapHeight - * @see Bitmap + * @see DKTools.Sprite.prototype.changeTextColor */ -DKTools.Sprite.prototype.createBitmap = function() { - if (this.hasGraphicName()) { - this._loadGraphic(); - } else if (!this.hasFixedBitmap()) { - this.bitmap = new Bitmap(this._getBitmapWidth(), this._getBitmapHeight()); - } +DKTools.Sprite.prototype.resetTextColor = function() { + this.changeTextColor(this.textColor); }; /** - * Creates a mask - * - * @since 2.0.0 - * - * @see DKTools.Sprite.prototype.createRectMask - * @see DKTools.Sprite.prototype.createCircleMask - * @see DKTools.Sprite.prototype.createEllipseMask + * Resets the paint opacity + * + * @see DKTools.Sprite.prototype.changePaintOpacity */ -DKTools.Sprite.prototype.createMask = function(maskShape) { - switch (maskShape) { - case 'rect': - this.createRectMask(); - break; - case 'circle': - this.createCircleMask(); - break; - case 'ellipse': - this.createEllipseMask(); - break; - } +DKTools.Sprite.prototype.resetPaintOpacity = function() { + this.changePaintOpacity(this.paintOpacity); }; +// has methods + /** - * Creates a mask in the form of a rectangle + * Returns true if the sprite has fixed bitmap (setted using setupBitmap or setBitmap) * - * @since 2.0.0 - * - * @see DKTools.Sprite.prototype.setMask - * @see PIXI.Graphics + * @since 1.1.0 + * @returns {Boolean} Sprite has fixed bitmap (setted using setupBitmap or setBitmap) */ -DKTools.Sprite.prototype.createRectMask = function() { - const mask = new PIXI.Graphics(); - - mask.beginFill(); - mask.drawRect(this.x, this.y, this.bitmap.width, this.bitmap.height); - mask.endFill(); - - this.setMask(mask); +DKTools.Sprite.prototype.hasFixedBitmap = function() { + return !!this._fixedBitmap; }; /** - * Creates a mask in the form of a circle + * Returns true if the sprite has the fill color * - * @since 2.0.0 - * - * @see DKTools.Sprite.prototype.setMask - * @see PIXI.Graphics + * @returns {Boolean} Sprite has the fill color */ -DKTools.Sprite.prototype.createCircleMask = function() { - const mask = new PIXI.Graphics(); - const radius = this.bitmap.width / 2; - const centerX = this.x + radius; - const centerY = this.y + radius; - - mask.beginFill(); - mask.drawCircle(centerX, centerY, radius); - mask.endFill(); - - this.setMask(mask); +DKTools.Sprite.prototype.hasFillColor = function() { + return !!this._fillColor; }; /** - * Creates a mask in the form of an ellipse + * Returns true if the sprite has the texts * - * @since 2.0.0 - * - * @see DKTools.Sprite.prototype.setMask - * @see PIXI.Graphics + * @returns {Boolean} Sprite has the texts */ -DKTools.Sprite.prototype.createEllipseMask = function() { - const mask = new PIXI.Graphics(); - const width = this.bitmap.width / 2; - const height = this.bitmap.height / 2; - const centerX = this.x + width; - const centerY = this.y + height; - - mask.beginFill(); - mask.drawEllipse(centerX, centerY, width, height); - mask.endFill(); - - this.setMask(mask); +DKTools.Sprite.prototype.hasTexts = function() { + return this._texts.length > 0; }; -// add methods - /** - * Adds the text - * - * @param {String | Number} text - Text - * @param {Object} options - Options - * @param {Boolean} [refreshAll=false] - Refreshes all - * - * @param {String | Number} [options.id] - ID of the text - * @param {String} [options.type='drawText'] - Type of the text ('drawText' or 'drawTextEx') + * Returns true if the sprite has the graphic folder * - * @see DKTools.Sprite.prototype.drawTextEx - * @see DKTools.Sprite.prototype.drawText + * @returns {Boolean} Sprite has the graphic folder */ -DKTools.Sprite.prototype.addText = function(text, options, refreshAll) { - if (text == null) { - return; - } - - text = String(text); - options = options || {}; - - this._texts.push({ - text, - options, - id: options.id, - type: options.type || 'drawText' - }); - - if (refreshAll) { - this.refreshAll(); - } +DKTools.Sprite.prototype.hasGraphicFolder = function() { + return !!this._graphicFolder; }; -// redraw methods - /** - * Redraws all + * Returns true if the sprite has the graphic name * - * @version 1.1.0 - * @override - * - * @see DKTools.Sprite.prototype.clear - * @see DKTools.Sprite.prototype.drawAll - * @see DKTools.Sprite.prototype.updateRedrawAllEvents + * @returns {Boolean} Sprite has the graphic name */ -DKTools.Sprite.prototype.redrawAll = function() { - this.clear(); - this.drawAll(); - this.updateRedrawAllEvents(); +DKTools.Sprite.prototype.hasGraphicName = function() { + return !!this._graphicName; }; -// _get methods +// is methods /** - * Returns the width of the bitmap + * Returns true if you can change the size of the sprite + * + * @version 1.1.0 * - * @since 2.0.0 - * @private - * @returns {Number} Width of the bitmap + * @see DKTools.Sprite.prototype.hasGraphicName + * @see DKTools.Sprite.prototype.hasFixedBitmap + * + * @returns {Boolean} You can change the size of the sprite */ -DKTools.Sprite.prototype._getBitmapWidth = function() { - return this._bitmapWidth; +DKTools.Sprite.prototype.isResizable = function() { + return !this.hasGraphicName() && !this.hasFixedBitmap(); }; /** - * Returns the height of the bitmap + * Returns true if the coordinates is inside the sprite + * + * @override + * + * @param {Number} x - The X coordinate + * @param {Number} y - The Y coordinate * - * @since 2.0.0 - * @private - * @returns {Number} Height of the bitmap + * @see DKTools.Sprite.prototype.canvasToLocalX + * @see DKTools.Sprite.prototype.canvasToLocalY + * + * @returns {Boolean} Coordinates is inside the sprite */ -DKTools.Sprite.prototype._getBitmapHeight = function() { - return this._bitmapHeight; +DKTools.Sprite.prototype.isInside = function(x, y) { + const localX = this.canvasToLocalX(x); + const localY = this.canvasToLocalY(y); + const width = this.width; + const height = this.height; + const anchor = this.anchor; + const frame = new Rectangle(-width * anchor.x, -height * anchor.y, width, height); + + return frame.contains(localX, localY); }; -// get methods +// draw methods /** - * Returns an object of text by its ID + * Draws all * - * @param {Number | String | *} id - ID of object of text - * @returns {Object} Object of text + * @version 1.1.0 + * @override + * + * @see DKTools.Sprite.prototype.updateFill + * @see DKTools.Sprite.prototype.drawAllTexts + * @see DKTools.Sprite.prototype.updateDrawAllEvents */ -DKTools.Sprite.prototype.getTextById = function(id) { - return _.find(this._texts, { id }); +DKTools.Sprite.prototype.drawAll = function() { + this.updateFill(); + this.drawAllTexts(); + this.updateDrawAllEvents(); }; /** - * Returns the current opacity of the sprite - * - * @returns {Number} Current opacity of the sprite + * Draws all texts */ -DKTools.Sprite.prototype.getCurrentOpacity = function() { - return this.alpha * 255; +DKTools.Sprite.prototype.drawAllTexts = function() { + _.forEach(this._texts, function(obj) { + this[obj.type](obj.text, obj.options); + }.bind(this)); }; -// size methods - /** - * Changes the width and height of the sprite - * Returns true if the change occurred + * Draws the text + * Returns true if bitmap exists * - * @param {Number} [width] - Width of the sprite - * @param {Number | String} [height] - Height of the sprite or number of lines - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {String} text - Text + * @param {Object} [options={}] - Options for drawing * - * @see DKTools.Sprite.prototype.isResizable - * @see DKTools.Sprite.prototype.getMinWidth - * @see DKTools.Sprite.prototype.getMinHeight - * @see DKTools.Sprite.prototype.setupSize - * @see DKTools.Sprite.prototype.start + * @param {Object} [options.font=this.font] - Use custom font + * @param {String} [options.textColor=this.textColor] - Use custom text color + * @param {Number} [options.paintOpacity=this.paintOpacity] - Use custom paint opacity + * @param {String} [options.align=this.align] - Align + * @param {Boolean} [options.resetFont=false] - Use standard font after drawing the text + * @param {String} [options.resetTextColor=false] - Use standard text color after drawing the text + * @param {String} [options.resetPaintOpacity=false] - Use standard paint opacity after drawing the text + * @param {Number} [options.x=0] - The X coordinate + * @param {Number | String} [options.y=0] - The Y coordinate or line number (String) + * @param {Number | String} [options.width=this.standardDrawingWidth()] - Width of the rectangle + * @param {Number | String} [options.height=this.getLineHeight()] - Height of the rectangle or number of lines (String) + * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [options.pos] - Position of the text (ignores other parameters of position: x, y, width, height) + * @param {PIXI.Rectangle | Rectangle | Object} [options.rect] - Rectangle for drawing (ignores other parameters of position: x, y, width, height, pos) * - * @returns {Boolean} Change occurred + * @param {Number} [options.pos.x=0] - The X coordinate + * @param {Number | String} [options.pos.y=0] - The Y coordinate or line number (String) + * + * @param {Number} [options.rect.x=0] - The X coordinate + * @param {Number | String} [options.rect.y=0] - The Y coordinate or line number (String) + * @param {Number | String} [options.rect.width=this.standardDrawingWidth()] - Width of the rectangle + * @param {Number | String} [options.rect.height=this.getLineHeight()] - Height of the rectangle or number of lines (String) + * + * @example + * var sprite = new DKTools.Sprite(0, 0, 100, 36); + * sprite.start(); + * sprite.drawText('Text', { + * y: '1' + * }); + * + * @see DKTools.Base.prototype.hasBitmap + * @see DKTools.Sprite.prototype.changeFont + * @see DKTools.Sprite.prototype.changeTextColor + * @see DKTools.Sprite.prototype.changePaintOpacity + * @see DKTools.Base.prototype.standardDrawingWidth + * @see DKTools.Base.prototype.standardDrawingHeight + * @see DKTools.Base.prototype.getLineHeight + * @see DKTools.Sprite.prototype.resetFont + * @see DKTools.Sprite.prototype.resetTextColor + * @see DKTools.Sprite.prototype.resetPaintOpacity + * @see Bitmap.prototype.drawText + * + * @returns {Boolean} Bitmap exists */ -DKTools.Sprite.prototype.resize = function(width, height, blockStart) { - if (!this.isResizable()) { +DKTools.Sprite.prototype.drawText = function(text, options) { + text = String(text); + options = options || {}; + + if (!this.hasBitmap() || !text) { return false; } - width = (width == null ? this.getMinWidth() : width); - height = (height == null ? this.getMinHeight() : height); - - if (DKTools.Utils.isString(height)) { - height = this.getLineHeight() * Number(height); + if (options.font) { + this.changeFont(options.font); } - if (this._bitmapWidth === width && this._bitmapHeight === height) { - return false; + if (options.textColor) { + this.changeTextColor(options.textColor); } - const lastWidth = this._bitmapWidth; - const lastHeight = this._bitmapHeight; + if (options.paintOpacity) { + this.changePaintOpacity(options.paintOpacity); + } - this.setupSize(width, height); + let x = options.x; + let y = options.y; + let width = options.width; + let height = options.height; + const pos = options.pos; + const rect = options.rect; - if (this._bitmapWidth === lastWidth && this._bitmapHeight === lastHeight) { - return false; + if (pos instanceof Object) { + x = pos.x; + y = pos.y; } - if (!blockStart) { - this.start(); + if (rect instanceof Object) { + x = rect.x; + y = rect.y; + width = rect.width; + height = rect.height; + } + + if (DKTools.Utils.isString(y)) { // line number + y = this.getLineHeight() * Number(y); + } + + if (DKTools.Utils.isString(height)) { // number of lines + height = this.getLineHeight() * Number(height); + } + + x = x || 0; + y = y || 0; + width = width || this.standardDrawingWidth(); + height = height || this.getLineHeight(); + + const align = options.align || this.align; + + this.bitmap.drawText(text, x, y, width, height, align); + + if (options.resetFont) { + this.resetFont(); + } + + if (options.resetTextColor) { + this.resetTextColor(); + } + + if (options.resetPaintOpacity) { + this.resetPaintOpacity(); } return true; }; -// can methods +// load methods /** - * Returns true if the sprite can be updated and redrawn + * Loads a bitmap from img/animations/ + * Returns true if the bitmap has been changed * - * @since 1.1.0 + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * - * @override + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap * - * @see DKTools.Base.prototype.canRedrawAll - * @see DKTools.Sprite.prototype.hasGraphicName - * @see DKTools.Sprite.prototype.hasFixedBitmap + * @see Bitmap.prototype.addLoadListener * - * @returns {Boolean} Sprite can be updated and redrawn + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.canRedrawAll = function() { - return DKTools.Base.prototype.canRedrawAll.call(this) && !this.hasGraphicName() && !this.hasFixedBitmap(); -}; +DKTools.Sprite.prototype.loadAnimation = function(object, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap('img/animations/', object.filename, object.listener, object.hue, object.smooth); + } -/** - * Returns true if the sprite can clone the fixed bitmap - * - * @returns {Boolean} Sprite can clone the fixed bitmap - */ -DKTools.Sprite.prototype.canCloneFixedBitmap = function() { - return true; + // object - String + return this.loadBitmap('img/animations/', object, listener, hue, smooth); }; -// effects methods - /** - * Changes the tone of the bitmap - * Returns true if bitmap exists + * Loads a bitmap from img/battlebacks1/ + * Returns true if the bitmap has been changed * - * @param {Number[]} tone - Tone (RGB) - * - * @see DKTools.Sprite.prototype.hasBitmap - * @see Bitmap.prototype.adjustTone - * - * @returns {Boolean} Bitmap exists + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.adjustTone = function(tone) { - if (!this.hasBitmap()) { - return false; - } - - if (DKTools.Utils.Array.isNumberArray(tone) && tone.length === 3) { - Bitmap.prototype.adjustTone.apply(this.bitmap, tone); - return true; +DKTools.Sprite.prototype.loadBattleback1 = function(object, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap('img/battlebacks1/', object.filename, object.listener, object.hue, object.smooth); } - return false; + // object - String + return this.loadBitmap('img/battlebacks1/', object, listener, hue, smooth); }; /** - * Rotates the hue of the bitmap - * Returns true if bitmap exists + * Loads a bitmap from img/battlebacks2/ + * Returns true if the bitmap has been changed * - * @param {Number} offset - Offset - * - * @see DKTools.Sprite.prototype.hasBitmap - * @see Bitmap.prototype.rotateHue - * - * @returns {Boolean} Bitmap exists + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.rotateHue = function(offset) { - if (!this.hasBitmap()) { - return false; +DKTools.Sprite.prototype.loadBattleback2 = function(object, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap('img/battlebacks2/', object.filename, object.listener, object.hue, object.smooth); } - this.bitmap.rotateHue(offset); - - return true; + // object - String + return this.loadBitmap('img/battlebacks2/', object, listener, hue, smooth); }; /** - * Imposes a blur effect on the bitmap - * Returns true if bitmap exists + * Loads a bitmap from img/characters/ + * Returns true if the bitmap has been changed * - * @see DKTools.Sprite.prototype.hasBitmap - * @see Bitmap.prototype.blur - * - * @returns {Boolean} Bitmap exists + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.blur = function() { - if (!this.hasBitmap()) { - return false; +DKTools.Sprite.prototype.loadCharacter = function(object, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap('img/characters/', object.filename, object.listener, object.hue, object.smooth); } - this.bitmap.blur(); - - return true; + // object - String + return this.loadBitmap('img/characters/', object, listener, hue, smooth); }; -// change methods - /** - * Changes the font of the bitmap + * Loads a bitmap from img/enemies/ + * Returns true if the bitmap has been changed * - * @param {Object} font - Text font + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * - * @param {String} [object.font.fontFace] - Font face - * @param {Number} [object.font.fontSize] - Font size - * @param {Boolean} [object.font.fontItalic] - Font italic + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap * - * @see DKTools.Sprite.prototype.hasBitmap - * @see DKTools.Sprite.prototype.updateFont + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.changeFont = function(font) { - if (this.hasBitmap()) { - this.updateFont(font); +DKTools.Sprite.prototype.loadEnemy = function(object, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap('img/enemies/', object.filename, object.listener, object.hue, object.smooth); } + + // object - String + return this.loadBitmap('img/enemies/', object, listener, hue, smooth); }; /** - * Changes the text color + * Loads a bitmap from img/faces/ + * Returns true if the bitmap has been changed * - * @param {String} textColor - Text color + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * - * @see DKTools.Sprite.prototype.hasBitmap - * @see DKTools.Sprite.prototype.updateTextColor + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.changeTextColor = function(textColor) { - if (this.hasBitmap()) { - this.updateTextColor(textColor); +DKTools.Sprite.prototype.loadFace = function(object, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap('img/faces/', object.filename, object.listener, object.hue, object.smooth); } + + // object - String + return this.loadBitmap('img/faces/', object, listener, hue, smooth); }; /** - * Changes the paint opacity + * Loads a bitmap from img/parallaxes/ + * Returns true if the bitmap has been changed * - * @param {Number} paintOpacity - Paint opacity + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) * - * @see DKTools.Sprite.prototype.hasBitmap - * @see DKTools.Sprite.prototype.updatePaintOpacity + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.changePaintOpacity = function(paintOpacity) { - if (this.hasBitmap()) { - this.updatePaintOpacity(paintOpacity); +DKTools.Sprite.prototype.loadParallax = function(object, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap('img/parallaxes/', object.filename, object.listener, object.hue, object.smooth); } -}; -// reset methods + // object - String + return this.loadBitmap('img/parallaxes/', object, listener, hue, smooth); +}; /** - * Resets all + * Loads a bitmap from img/pictures/ + * Returns true if the bitmap has been changed * - * @see DKTools.Sprite.prototype.resetFont - * @see DKTools.Sprite.prototype.resetTextColor - * @see DKTools.Sprite.prototype.resetPaintOpacity + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.resetAll = function() { - this.resetFont(); - this.resetTextColor(); - this.resetPaintOpacity(); +DKTools.Sprite.prototype.loadPicture = function(object, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap('img/pictures/', object.filename, object.listener, object.hue, object.smooth); + } + + // object - String + return this.loadBitmap('img/pictures/', object, listener, hue, smooth); }; /** - * Resets the font + * Loads a bitmap from img/sv_actors/ + * Returns true if the bitmap has been changed * - * @see DKTools.Sprite.prototype.changeFont + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.resetFont = function() { - this.changeFont(this.font); +DKTools.Sprite.prototype.loadSvActor = function(object, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap('img/sv_actors/', object.filename, object.listener, object.hue, object.smooth); + } + + // object - String + return this.loadBitmap('img/sv_actors/', object, listener, hue, smooth); }; /** - * Resets the text color + * Loads a bitmap from img/sv_enemies/ + * Returns true if the bitmap has been changed * - * @see DKTools.Sprite.prototype.changeTextColor + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.resetTextColor = function() { - this.changeTextColor(this.textColor); +DKTools.Sprite.prototype.loadSvEnemy = function(object, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap('img/sv_enemies/', object.filename, object.listener, object.hue, object.smooth); + } + + // object - String + return this.loadBitmap('img/sv_enemies/', object, listener, hue, smooth); }; /** - * Resets the paint opacity + * Loads a bitmap from img/system/ + * Returns true if the bitmap has been changed * - * @see DKTools.Sprite.prototype.changePaintOpacity + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.resetPaintOpacity = function() { - this.changePaintOpacity(this.paintOpacity); -}; +DKTools.Sprite.prototype.loadSystem = function(object, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap('img/system/', object.filename, object.listener, object.hue, object.smooth); + } -// has methods + // object - String + return this.loadBitmap('img/system/', object, listener, hue, smooth); +}; /** - * Returns true if the sprite has fixed bitmap (setted using setupBitmap or setBitmap) + * Loads a bitmap from img/tilesets/ + * Returns true if the bitmap has been changed * - * @since 1.1.0 - * @returns {Boolean} Sprite has fixed bitmap (setted using setupBitmap or setBitmap) + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.hasFixedBitmap = function() { - return !!this._fixedBitmap; +DKTools.Sprite.prototype.loadTileset = function(object, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap('img/tilesets/', object.filename, object.listener, object.hue, object.smooth); + } + + // object - String + return this.loadBitmap('img/tilesets/', object, listener, hue, smooth); }; /** - * Returns true if the sprite has the fill color + * Loads a bitmap from img/titles1/ + * Returns true if the bitmap has been changed * - * @returns {Boolean} Sprite has the fill color + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.hasFillColor = function() { - return !!this._fillColor; +DKTools.Sprite.prototype.loadTitle1 = function(object, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap('img/titles1/', object.filename, object.listener, object.hue, object.smooth); + } + + // object - String + return this.loadBitmap('img/titles1/', object, listener, hue, smooth); }; /** - * Returns true if the sprite has the texts + * Loads a bitmap from img/titles2/ + * Returns true if the bitmap has been changed * - * @returns {Boolean} Sprite has the texts + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.hasTexts = function() { - return this._texts.length > 0; +DKTools.Sprite.prototype.loadTitle2 = function(object, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap('img/titles2/', object.filename, object.listener, object.hue, object.smooth); + } + + // object - String + return this.loadBitmap('img/titles2/', object, listener, hue, smooth); }; /** - * Returns true if the sprite has the graphic folder + * Loads a windowskin from img/system/ + * Returns true if the bitmap has been changed * - * @returns {Boolean} Sprite has the graphic folder + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Sprite.prototype.standardWindowskin + * @see DKTools.Sprite.prototype.loadSystem + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.hasGraphicFolder = function() { - return !!this._graphicFolder; +DKTools.Sprite.prototype.loadWindowskin = function(object, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadSystem(object.filename || this.standardWindowskin(), object.listener, object.hue, object.smooth); + } + + // object - String + return this.loadSystem(object || this.standardWindowskin(), listener, hue, smooth); }; /** - * Returns true if the sprite has the graphic name + * Loads a bitmap + * Returns true if the bitmap has been changed * - * @returns {Boolean} Sprite has the graphic name + * @version 3.0.0 + * + * @param {String | Object} object - Path to file or object with parameters + * @param {String} filename - Name of file (if object is String) + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * + * @param {String} object.folder - Path to file + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * + * @see DKTools.Sprite.prototype.setBitmap + * @see DKTools.Utils.Bitmap.load + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.hasGraphicName = function() { - return !!this._graphicName; +DKTools.Sprite.prototype.loadBitmap = function(object, filename, listener, hue, smooth) { + if (object instanceof Object) { + return this.loadBitmap(object.folder, object.filename, object.listener, object.hue, object.smooth); + } + + // object - String (folder) + const bitmap = DKTools.Utils.Bitmap.load(object, filename, hue, smooth); + + if (this.setBitmap(bitmap)) { + if (DKTools.Utils.isFunction(listener)) { + this.bitmap.addLoadListener(listener); + } + + return true; + } + + return false; }; -// is methods +// reserve methods /** - * Returns true if you can change the size of the sprite + * Loads and reserves a bitmap from img/animations/ + * Returns true if the bitmap has been changed * - * @version 1.1.0 - * - * @see DKTools.Sprite.prototype.hasGraphicName - * @see DKTools.Sprite.prototype.hasFixedBitmap + * @version 3.0.0 * - * @returns {Boolean} You can change the size of the sprite + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.isResizable = function() { - return !this.hasGraphicName() && !this.hasFixedBitmap(); +DKTools.Sprite.prototype.reserveAnimation = function(object, listener, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveBitmap('img/animations/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); + } + + // object - String + return this.reserveBitmap('img/animations/', object, listener, hue, smooth, reservationId); }; /** - * Returns true if the coordinates is inside the sprite + * Loads and reserves a bitmap from img/battlebacks1/ + * Returns true if the bitmap has been changed * - * @override + * @version 3.0.0 * - * @param {Number} x - The X coordinate - * @param {Number} y - The Y coordinate - * - * @see DKTools.Sprite.prototype.canvasToLocalX - * @see DKTools.Sprite.prototype.canvasToLocalY + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * - * @returns {Boolean} Coordinates is inside the sprite + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.isInside = function(x, y) { - const localX = this.canvasToLocalX(x); - const localY = this.canvasToLocalY(y); - const width = this.width; - const height = this.height; - const anchor = this.anchor; - const frame = new Rectangle(-width * anchor.x, -height * anchor.y, width, height); +DKTools.Sprite.prototype.reserveBattleback1 = function(object, listener, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveBitmap('img/battlebacks1/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); + } - return frame.contains(localX, localY); + // object - String + return this.reserveBitmap('img/battlebacks1/', object, listener, hue, smooth, reservationId); }; -// draw methods - /** - * Draws all + * Loads and reserves a bitmap from img/battlebacks2/ + * Returns true if the bitmap has been changed * - * @version 1.1.0 - * @override + * @version 3.0.0 + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * - * @see DKTools.Sprite.prototype.updateFill - * @see DKTools.Sprite.prototype.drawAllTexts - * @see DKTools.Sprite.prototype.updateDrawAllEvents + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.drawAll = function() { - this.updateFill(); - this.drawAllTexts(); - this.updateDrawAllEvents(); -}; +DKTools.Sprite.prototype.reserveBattleback2 = function(object, listener, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveBitmap('img/battlebacks2/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); + } -/** - * Draws all texts - */ -DKTools.Sprite.prototype.drawAllTexts = function() { - _.forEach(this._texts, function(obj) { - this[obj.type](obj.text, obj.options); - }.bind(this)); + // object - String + return this.reserveBitmap('img/battlebacks2/', object, listener, hue, smooth, reservationId); }; /** - * Draws the text - * Returns true if bitmap exists - * - * @param {String} text - Text - * @param {Object} [options={}] - Options for drawing - * - * @param {Object} [options.font=this.font] - Use custom font - * @param {String} [options.textColor=this.textColor] - Use custom text color - * @param {Number} [options.paintOpacity=this.paintOpacity] - Use custom paint opacity - * @param {String} [options.align=this.align] - Align - * @param {Boolean} [options.resetFont=false] - Use standard font after drawing the text - * @param {String} [options.resetTextColor=false] - Use standard text color after drawing the text - * @param {String} [options.resetPaintOpacity=false] - Use standard paint opacity after drawing the text - * @param {Number} [options.x=0] - The X coordinate - * @param {Number | String} [options.y=0] - The Y coordinate or line number (String) - * @param {Number | String} [options.width=this.standardDrawingWidth()] - Width of the rectangle - * @param {Number | String} [options.height=this.getLineHeight()] - Height of the rectangle or number of lines (String) - * @param {PIXI.Point | PIXI.ObservablePoint | Point | Object} [options.pos] - Position of the text (ignores other parameters of position: x, y, width, height) - * @param {PIXI.Rectangle | Rectangle | Object} [options.rect] - Rectangle for drawing (ignores other parameters of position: x, y, width, height, pos) + * Loads and reserves a bitmap from img/characters/ + * Returns true if the bitmap has been changed * - * @param {Number} [options.pos.x=0] - The X coordinate - * @param {Number | String} [options.pos.y=0] - The Y coordinate or line number (String) + * @version 3.0.0 * - * @param {Number} [options.rect.x=0] - The X coordinate - * @param {Number | String} [options.rect.y=0] - The Y coordinate or line number (String) - * @param {Number | String} [options.rect.width=this.standardDrawingWidth()] - Width of the rectangle - * @param {Number | String} [options.rect.height=this.getLineHeight()] - Height of the rectangle or number of lines (String) + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * - * @example - * var sprite = new DKTools.Sprite(0, 0, 100, 36); - * sprite.start(); - * sprite.drawText('Text', { - * y: '1' - * }); + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID * - * @see DKTools.Base.prototype.hasBitmap - * @see DKTools.Sprite.prototype.changeFont - * @see DKTools.Sprite.prototype.changeTextColor - * @see DKTools.Sprite.prototype.changePaintOpacity - * @see DKTools.Base.prototype.standardDrawingWidth - * @see DKTools.Base.prototype.standardDrawingHeight - * @see DKTools.Base.prototype.getLineHeight - * @see DKTools.Sprite.prototype.resetFont - * @see DKTools.Sprite.prototype.resetTextColor - * @see DKTools.Sprite.prototype.resetPaintOpacity - * @see Bitmap.prototype.drawText + * @see Bitmap.prototype.addLoadListener * - * @returns {Boolean} Bitmap exists + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.drawText = function(text, options) { - text = String(text); - options = options || {}; - - if (!this.hasBitmap() || !text) { - return false; - } - - if (options.font) { - this.changeFont(options.font); - } - - if (options.textColor) { - this.changeTextColor(options.textColor); - } - - if (options.paintOpacity) { - this.changePaintOpacity(options.paintOpacity); - } - - let x = options.x; - let y = options.y; - let width = options.width; - let height = options.height; - const pos = options.pos; - const rect = options.rect; - - if (pos instanceof Object) { - x = pos.x; - y = pos.y; - } - - if (rect instanceof Object) { - x = rect.x; - y = rect.y; - width = rect.width; - height = rect.height; - } - - if (DKTools.Utils.isString(y)) { // line number - y = this.getLineHeight() * Number(y); - } - - if (DKTools.Utils.isString(height)) { // number of lines - height = this.getLineHeight() * Number(height); - } - - x = x || 0; - y = y || 0; - width = width || this.standardDrawingWidth(); - height = height || this.getLineHeight(); - - const align = options.align || this.align; - - this.bitmap.drawText(text, x, y, width, height, align); - - if (options.resetFont) { - this.resetFont(); - } - - if (options.resetTextColor) { - this.resetTextColor(); - } - - if (options.resetPaintOpacity) { - this.resetPaintOpacity(); +DKTools.Sprite.prototype.reserveCharacter = function(object, listener, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveBitmap('img/characters/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } - return true; + // object - String + return this.reserveBitmap('img/characters/', object, listener, hue, smooth, reservationId); }; -// load methods - /** - * Loads a bitmap - * Returns true if the bitmap of the sprite has been changed + * Loads and reserves a bitmap from img/enemies/ + * Returns true if the bitmap has been changed * * @version 3.0.0 * - * @param {String | Object} object - Path to file or object with parameters - * @param {String} filename - Name of file - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * - * @param {String} object.folder - Path to file * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see Bitmap.prototype.addLoadListener * - * @see DKTools.Sprite.prototype.setBitmap - * @see DKTools.Utils.Bitmap.load - * - * @returns {Boolean} Bitmap of the sprite has been changed + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.loadBitmap = function(object, filename, listener, hue, smooth) { +DKTools.Sprite.prototype.reserveEnemy = function(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.loadBitmap(object.folder, object.filename, object.listener, object.hue, object.smooth); - } - - // object - String (folder) - const bitmap = DKTools.Utils.Bitmap.load(object, filename, hue, smooth); - - if (this.setBitmap(bitmap)) { - if (listener) { - this.bitmap.addLoadListener(listener); - } - - return true; + return this.reserveBitmap('img/enemies/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } - return false; + // object - String + return this.reserveBitmap('img/enemies/', object, listener, hue, smooth, reservationId); }; -// reserve methods - /** - * Loads and reserves a bitmap - * Returns true if the bitmap of the sprite has been changed + * Loads and reserves a bitmap from img/faces/ + * Returns true if the bitmap has been changed * * @version 3.0.0 * - * @param {String | Object} object - Path to file or object with parameters - * @param {String} filename - Name of file - * @param {Function} [listener] - Function of processing after loading a bitmap - * @param {Number} [hue] - Hue of bitmap - * @param {Boolean} [smooth] - Smooth of bitmap - * @param {Number} [reservationId] - Reservation ID + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) * - * @param {String} object.folder - Path to file * @param {String} object.filename - Name of file * @param {Function} [object.listener] - Function of processing after loading a bitmap * @param {Number} [object.hue] - Hue of bitmap * @param {Boolean} [object.smooth] - Smooth of bitmap * @param {Number} [object.reservationId] - Reservation ID * - * @see DKTools.Sprite.prototype.setBitmap - * @see DKTools.Utils.Bitmap.reserve + * @see Bitmap.prototype.addLoadListener * - * @returns {Boolean} Bitmap of the sprite has been changed + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.reserveBitmap = function(object, filename, listener, hue, smooth, reservationId) { +DKTools.Sprite.prototype.reserveFace = function(object, listener, hue, smooth, reservationId) { if (object instanceof Object) { - return this.reserveBitmap(object.folder, object.filename, object.listener, object.hue, object.smooth, object.reservationId); + return this.reserveBitmap('img/faces/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } // object - String - const bitmap = DKTools.Utils.Bitmap.reserve(object, filename, listener, hue, smooth, reservationId) - - if (this.setBitmap(bitmap)) { - if (listener) { - this.bitmap.addLoadListener(listener); - } - - return true; - } - - return false; + return this.reserveBitmap('img/faces/', object, listener, hue, smooth, reservationId); }; -// graphic methods - /** - * Loads the graphic (using graphic folder and graphic name) + * Loads and reserves a bitmap from img/parallaxes/ + * Returns true if the bitmap has been changed * - * @private + * @version 3.0.0 * - * @see DKTools.Sprite.prototype.hasGraphicFolder - * @see DKTools.Sprite.prototype.hasGraphicName - * @see DKTools.Sprite.prototype.loadBitmap - * @see DKTools.Sprite.prototype.hasBitmap - * @see DKTools.Sprite.prototype.updateReadyEvents + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype._loadGraphic = function() { - if (this.hasGraphicFolder() && this.hasGraphicName()) { - const folder = this.graphicFolder; - const filename = this.graphicName; - const listener = this._graphicLoadListener; - - this.loadBitmap(folder, filename); - - if (listener && this.hasBitmap()) { - this.bitmap.addLoadListener(listener); - } - - this.updateReadyEvents(); +DKTools.Sprite.prototype.reserveParallax = function(object, listener, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveBitmap('img/parallaxes/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); } -}; -// event methods + // object - String + return this.reserveBitmap('img/parallaxes/', object, listener, hue, smooth, reservationId); +}; /** - * Updates the events with type: draw-all + * Loads and reserves a bitmap from img/pictures/ + * Returns true if the bitmap has been changed * - * @see DKTools.Sprite.prototype.updateEventsContainer + * @version 3.0.0 + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed */ -DKTools.Sprite.prototype.updateDrawAllEvents = function() { - this.updateEventsContainer('draw-all'); -}; +DKTools.Sprite.prototype.reservePicture = function(object, listener, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveBitmap('img/pictures/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); + } -// update methods + // object - String + return this.reserveBitmap('img/pictures/', object, listener, hue, smooth, reservationId); +}; /** - * Updates all + * Loads and reserves a bitmap from img/sv_actors/ + * Returns true if the bitmap has been changed * - * @override - * + * @version 3.0.0 + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed + */ +DKTools.Sprite.prototype.reserveSvActor = function(object, listener, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveBitmap('img/sv_actors/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); + } + + // object - String + return this.reserveBitmap('img/sv_actors/', object, listener, hue, smooth, reservationId); +}; + +/** + * Loads and reserves a bitmap from img/sv_enemies/ + * Returns true if the bitmap has been changed + * + * @version 3.0.0 + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed + */ +DKTools.Sprite.prototype.reserveSvEnemy = function(object, listener, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveBitmap('img/sv_enemies/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); + } + + // object - String + return this.reserveBitmap('img/sv_enemies/', object, listener, hue, smooth, reservationId); +}; + +/** + * Loads and reserves a bitmap from img/system/ + * Returns true if the bitmap has been changed + * + * @version 3.0.0 + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed + */ +DKTools.Sprite.prototype.reserveSystem = function(object, listener, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveBitmap('img/system/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); + } + + // object - String + return this.reserveBitmap('img/system/', object, listener, hue, smooth, reservationId); +}; + +/** + * Loads and reserves a bitmap from img/tilesets/ + * Returns true if the bitmap has been changed + * + * @version 3.0.0 + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed + */ +DKTools.Sprite.prototype.reserveTileset = function(object, listener, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveBitmap('img/tilesets/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); + } + + // object - String + return this.reserveBitmap('img/tilesets/', object, listener, hue, smooth, reservationId); +}; + +/** + * Loads and reserves a bitmap from img/titles1/ + * Returns true if the bitmap has been changed + * + * @version 3.0.0 + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed + */ +DKTools.Sprite.prototype.reserveTitle1 = function(object, listener, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveBitmap('img/titles1/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); + } + + // object - String + return this.reserveBitmap('img/titles1/', object, listener, hue, smooth, reservationId); +}; + +/** + * Loads and reserves a bitmap from img/titles2/ + * Returns true if the bitmap has been changed + * + * @version 3.0.0 + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Base.prototype.reserveBitmap + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed + */ +DKTools.Sprite.prototype.reserveTitle2 = function(object, listener, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveBitmap('img/titles2/', object.filename, object.listener, object.hue, object.smooth, object.reservationId); + } + + // object - String + return this.reserveBitmap('img/titles2/', object, listener, hue, smooth, reservationId); +}; + +/** + * Loads and reserves a windowskin from img/system/ + * Returns true if the bitmap has been changed + * + * @version 3.0.0 + * + * @param {String | Object} object - Name of file or object with parameters + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Sprite.prototype.standardWindowskin + * @see DKTools.Sprite.prototype.reserveSystem + * @see Bitmap.prototype.addLoadListener + * + * @returns {Boolean} Bitmap has been changed + */ +DKTools.Sprite.prototype.reserveWindowskin = function(object, listener, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveSystem(object.filename || this.standardWindowskin(), object.listener, object.hue, object.smooth, object.reservationId); + } + + // object - String + return this.reserveSystem(object || this.standardWindowskin(), listener, hue, smooth, reservationId); +}; + +/** + * Loads and reserves a bitmap + * Returns true if the bitmap has been changed + * + * @version 3.0.0 + * + * @param {String | Object} object - Path to file or object with parameters + * @param {String} filename - Name of file (if object is String) + * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) + * @param {Number} [hue] - Hue of bitmap (if object is String) + * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * @param {Number} [reservationId] - Reservation ID (if object is String) + * + * @param {String} object.folder - Path to file + * @param {String} object.filename - Name of file + * @param {Function} [object.listener] - Function of processing after loading a bitmap + * @param {Number} [object.hue] - Hue of bitmap + * @param {Boolean} [object.smooth] - Smooth of bitmap + * @param {Number} [object.reservationId] - Reservation ID + * + * @see DKTools.Sprite.prototype.setBitmap + * @see DKTools.Utils.Bitmap.reserve + * + * @returns {Boolean} Bitmap has been changed + */ +DKTools.Sprite.prototype.reserveBitmap = function(object, filename, listener, hue, smooth, reservationId) { + if (object instanceof Object) { + return this.reserveBitmap(object.folder, object.filename, object.listener, object.hue, object.smooth, object.reservationId); + } + + // object - String + const bitmap = DKTools.Utils.Bitmap.reserve(object, filename, listener, hue, smooth, reservationId); + + if (this.setBitmap(bitmap)) { + if (DKTools.Utils.isFunction(listener)) { + this.bitmap.addLoadListener(listener); + } + + return true; + } + + return false; +}; + +// graphic methods + +/** + * Loads the graphic (using graphic folder and graphic name) + * + * @private + * + * @see DKTools.Sprite.prototype.hasGraphicFolder + * @see DKTools.Sprite.prototype.hasGraphicName + * @see DKTools.Sprite.prototype.loadBitmap + * @see DKTools.Sprite.prototype.hasBitmap + * @see DKTools.Sprite.prototype.updateReadyEvents + */ +DKTools.Sprite.prototype._loadGraphic = function() { + if (this.hasGraphicFolder() && this.hasGraphicName()) { + const folder = this._graphicFolder; + const filename = this._graphicName; + const listener = this._graphicLoadListener; + + this.loadBitmap(folder, filename); + + if (DKTools.Utils.isFunction(listener) && this.hasBitmap()) { + this.bitmap.addLoadListener(listener); + } + + this.updateReadyEvents(); + } +}; + +// event methods + +/** + * Updates the events with type: draw-all + * + * @see DKTools.Sprite.prototype.updateEventsContainer + */ +DKTools.Sprite.prototype.updateDrawAllEvents = function() { + this.updateEventsContainer('draw-all'); +}; + +// update methods + +/** + * Updates all + * + * @override + * * @see DKTools.Base.prototype.updateAll * @see DKTools.Sprite.prototype.updateBitmap */ @@ -18162,824 +18788,450 @@ Object.defineProperties(DKTools.Sprite.Selectable.prototype, { * @private * @override * - * @see DKTools.Sprite.Button.prototype._clearAll - * @see DKTools.Sprite.Selectable.prototype._clearItems - * @see DKTools.Sprite.Selectable.prototype._clearHandlers - * @see DKTools.Sprite.Selectable.prototype._clearTopRow - * @see DKTools.Sprite.Selectable.prototype._clearTopCol - */ -DKTools.Sprite.Selectable.prototype._clearAll = function() { - DKTools.Sprite.Button.prototype._clearAll.call(this); - this._clearItems(); - this._clearHandlers(); - this._clearTopRow(); - this._clearTopCol(); -}; - -/** - * Clears items - * - * @private - */ -DKTools.Sprite.Selectable.prototype._clearItems = function() { - /** - * @private - * @readonly - * @type {Object[]} - */ - this._items = []; -}; - -/** - * Clears the selection handlers - * - * @private - */ -DKTools.Sprite.Selectable.prototype._clearHandlers = function() { - /** - * @readonly - * @private - * @type {Object} - */ - this._handlers = {}; -}; - -/** - * Clears the top row - * - * @private - */ -DKTools.Sprite.Selectable.prototype._clearTopRow = function() { - /** - * @private - * @readonly - * @type {Number} - */ - this._topRow = 0; -}; - -/** - * Clears the top col - * - * @private - */ -DKTools.Sprite.Selectable.prototype._clearTopCol = function() { - /** - * @private - * @readonly - * @type {Number} - */ - this._topCol = 0; -}; - -// _create methods - -/** - * Creates all - * - * @private - * @override - * - * @see DKTools.Sprite.Button.prototype._createAll - * @see DKTools.Sprite.Selectable.prototype._createCursorSprite - */ -DKTools.Sprite.Selectable.prototype._createAll = function() { - DKTools.Sprite.Button.prototype._createAll.call(this); - this._createCursorSprite(); -}; - -/** - * Creates sprite of the cursor - * - * @private - * - * @see DKTools.Sprite.Cursor - */ -DKTools.Sprite.Selectable.prototype._createCursorSprite = function() { - /** - * @private - * @readonly - * @type {DKTools.Sprite.Cursor} - */ - this._cursorSprite = new DKTools.Sprite.Cursor(); -}; - -// _setup methods - -/** - * Sets the events - * - * @version 3.0.0 - * @private - * @override - * - * @see DKTools.Sprite.Button.prototype._setupEvents - * @see DKTools.Sprite.Selectable.prototype._setupMouseClickEvent - * @see DKTools.Sprite.Selectable.prototype._setupMouseLongPressEvent - * @see DKTools.Sprite.Selectable.prototype._setupMouseHoverEvents - * @see DKTools.Sprite.Selectable.prototype._setupWheelScrollEvents - */ -DKTools.Sprite.Selectable.prototype._setupEvents = function() { - DKTools.Sprite.Button.prototype._setupEvents.call(this); - this._setupMouseClickEvent(); - this._setupMouseLongPressEvent(); - this._setupMouseHoverEvents(); - this._setupWheelScrollEvents(); -}; - -/** - * Sets the event of the click (mouse-click-left) - * - * @private - * - * @see DKTools.Sprite.Selectable.prototype.addEvent - */ -DKTools.Sprite.Selectable.prototype._setupMouseClickEvent = function() { - this.addEvent({ - type: 'mouse-click-left', - onUpdate: this._onTouch.bind(this, true) - }); -}; - -/** - * Sets the event of the long press (mouse-long-press-left) - * - * @private - * - * @see DKTools.Sprite.Selectable.prototype.addEvent - */ -DKTools.Sprite.Selectable.prototype._setupMouseLongPressEvent = function() { - this.addEvent({ - type: 'mouse-long-press-left', - onUpdate: this._onTouch.bind(this, false) - }); -}; - -/** - * Sets the events of the mouse hover (mouse-enter and mouse-move) - * - * @private - * - * @see DKTools.Sprite.Selectable.prototype.addEvent - */ -DKTools.Sprite.Selectable.prototype._setupMouseHoverEvents = function() { - this.addEvent({ - type: 'mouse-enter', - onUpdate: this.processMouseHover.bind(this) - }); - - this.addEvent({ - type: 'mouse-move', - onUpdate: this.processMouseHover.bind(this) - }); -}; - -/** - * Sets the events of the wheel scrolling (wheel-Y-inside and wheel-Y-outside) - * - * @private - * - * @see DKTools.Sprite.Selectable.prototype.addEvent - */ -DKTools.Sprite.Selectable.prototype._setupWheelScrollEvents = function() { - this.addEvent({ - type: 'wheel-Y-inside', - onUpdate: this.processWheelScroll.bind(this) - }); - - this.addEvent({ - type: 'wheel-Y-outside', - onUpdate: this.processWheelScroll.bind(this) - }); -}; - -// _add methods - -/** - * Adds children objects to processing - * - * @private - * @override - * - * @see DKTools.Sprite.Button.prototype._addAllChildren - * @see DKTools.Sprite.Selectable.prototype._addCursorSprite - */ -DKTools.Sprite.Selectable.prototype._addAllChildren = function() { - DKTools.Sprite.Button.prototype._addAllChildren.call(this); - this._addCursorSprite(); -}; - -/** - * Adds sprite of the cursor to processing - * - * @private - */ -DKTools.Sprite.Selectable.prototype._addCursorSprite = function() { - this.addChild(this._cursorSprite); -}; - -// standard methods - -/** - * Returns the standard index - * - * @returns {Number} Standard index - */ -DKTools.Sprite.Selectable.prototype.standardIndex = function() { - return 0; -}; - -/** - * Returns the standard number of the columns - * - * @returns {Number} Standard number of the columns - */ -DKTools.Sprite.Selectable.prototype.standardMaxCols = function() { - return 1; -}; - -/** - * Returns the standard fixed cursor - * - * @returns {Boolean} Standard fixed cursor - */ -DKTools.Sprite.Selectable.prototype.standardCursorFixed = function() { - return false; -}; - -/** - * Returns the standard cursor all - * - * @returns {Boolean} Standard cursor all - */ -DKTools.Sprite.Selectable.prototype.standardCursorAll = function() { - return false; -}; - -/** - * Returns the standard fixed horizontal position - * - * @returns {Boolean} Standard fixed horizontal position - */ -DKTools.Sprite.Selectable.prototype.standardFixedHorizontal = function() { - return false; -}; - -/** - * Returns the standard horizontal spacing - * - * @returns {Number} Standard horizontal spacing - */ -DKTools.Sprite.Selectable.prototype.standardHorizontalSpacing = function() { - return 0; -}; - -/** - * Returns the standard vertical spacing - * - * @returns {Number} Standard vertical spacing - */ -DKTools.Sprite.Selectable.prototype.standardVerticalSpacing = function() { - return 0; -}; - -/** - * Returns the standard text padding - * - * @returns {Number} Standard text padding - */ -DKTools.Sprite.Selectable.prototype.standardTextPadding = function() { - return 6; -}; - -/** - * Returns the standard list of the items - * - * @returns {Array} Standard list of the items + * @see DKTools.Sprite.Button.prototype._clearAll + * @see DKTools.Sprite.Selectable.prototype._clearItems + * @see DKTools.Sprite.Selectable.prototype._clearHandlers + * @see DKTools.Sprite.Selectable.prototype._clearTopRow + * @see DKTools.Sprite.Selectable.prototype._clearTopCol */ -DKTools.Sprite.Selectable.prototype.standardItems = function() { - return []; +DKTools.Sprite.Selectable.prototype._clearAll = function() { + DKTools.Sprite.Button.prototype._clearAll.call(this); + this._clearItems(); + this._clearHandlers(); + this._clearTopRow(); + this._clearTopCol(); }; /** - * Returns the standard handler of draw of the item + * Clears items * - * @returns {Function} Standard handler of draw of the item + * @private */ -DKTools.Sprite.Selectable.prototype.standardDrawItemHandler = function() { - return function(index) { - const name = this.getItemName(index); - const font = this.getItemFontByIndex(index); - const textColor = this.getItemTextColorByIndex(index); - const paintOpacity = this.getItemPaintOpacityByIndex(index); - const align = this.getItemAlignByIndex(index); - const rect = this.getItemRectForTextByIndex(index); - - this.drawText(name, { - font, - textColor, - paintOpacity, - align, - rect, - resetFont: true, - resetTextColor: true, - resetPaintOpacity: true - }); - }.bind(this); +DKTools.Sprite.Selectable.prototype._clearItems = function() { + /** + * @private + * @readonly + * @type {Object[]} + */ + this._items = []; }; /** - * Returns the standard item width + * Clears the selection handlers * - * @returns {Function} Standard item width + * @private */ -DKTools.Sprite.Selectable.prototype.standardItemWidth = function() { - return function() { - const spacing = this._horizontalSpacing; - return Math.floor((this.realWidth + spacing) / this.getMaxCols() - spacing); - }.bind(this); +DKTools.Sprite.Selectable.prototype._clearHandlers = function() { + /** + * @readonly + * @private + * @type {Object} + */ + this._handlers = {}; }; /** - * Returns the standard item height + * Clears the top row * - * @returns {Function} Standard item height + * @private */ -DKTools.Sprite.Selectable.prototype.standardItemHeight = function() { - return this.getLineHeight(); +DKTools.Sprite.Selectable.prototype._clearTopRow = function() { + /** + * @private + * @readonly + * @type {Number} + */ + this._topRow = 0; }; /** - * Returns the standard item rect + * Clears the top col * - * @returns {Function} Standard item rect + * @private */ -DKTools.Sprite.Selectable.prototype.standardItemRect = function() { - return function(index) { - const rect = new Rectangle(); - const maxCols = this.getMaxCols(); - - rect.width = this.getItemWidth(); - rect.height = this.getItemHeight(); - - if (this.isHorizontal()) { - rect.x = (index - this.getTopCol()) * (rect.width + this._horizontalSpacing); - rect.y = 0; - } else { - rect.x = index % maxCols * (rect.width + this._horizontalSpacing); - rect.y = (Math.floor(index / maxCols) - this.getTopRow()) * (rect.height + this._verticalSpacing); - } - - return rect; - }.bind(this); +DKTools.Sprite.Selectable.prototype._clearTopCol = function() { + /** + * @private + * @readonly + * @type {Number} + */ + this._topCol = 0; }; +// _create methods + /** - * Returns the standard item font + * Creates all * - * @returns {Object} Standard item font + * @private + * @override + * + * @see DKTools.Sprite.Button.prototype._createAll + * @see DKTools.Sprite.Selectable.prototype._createCursorSprite */ -DKTools.Sprite.Selectable.prototype.standardItemFont = function() { - return this.font; +DKTools.Sprite.Selectable.prototype._createAll = function() { + DKTools.Sprite.Button.prototype._createAll.call(this); + this._createCursorSprite(); }; /** - * Returns the standard text color of the item + * Creates sprite of the cursor * - * @returns {String} Standard text color of the item + * @private + * + * @see DKTools.Sprite.Cursor */ -DKTools.Sprite.Selectable.prototype.standardItemTextColor = function() { - return this.textColor; +DKTools.Sprite.Selectable.prototype._createCursorSprite = function() { + /** + * @private + * @readonly + * @type {DKTools.Sprite.Cursor} + */ + this._cursorSprite = new DKTools.Sprite.Cursor(); }; +// _setup methods + /** - * Returns the standard paint opacity of the item + * Sets the events * - * @returns {Number} Standard paint opacity of the item + * @version 3.0.0 + * @private + * @override + * + * @see DKTools.Sprite.Button.prototype._setupEvents + * @see DKTools.Sprite.Selectable.prototype._setupMouseClickEvent + * @see DKTools.Sprite.Selectable.prototype._setupMouseLongPressEvent + * @see DKTools.Sprite.Selectable.prototype._setupMouseHoverEvents + * @see DKTools.Sprite.Selectable.prototype._setupWheelScrollEvents */ -DKTools.Sprite.Selectable.prototype.standardItemPaintOpacity = function() { - return function(index) { - if (this.isItemEnabled(index)) { - return this.standardEnabledItemPaintOpacity(); - } else { - return this.standardDisabledItemPaintOpacity(); - } - }.bind(this); +DKTools.Sprite.Selectable.prototype._setupEvents = function() { + DKTools.Sprite.Button.prototype._setupEvents.call(this); + this._setupMouseClickEvent(); + this._setupMouseLongPressEvent(); + this._setupMouseHoverEvents(); + this._setupWheelScrollEvents(); }; /** - * Returns the standard paint opacity of the enabled item + * Sets the event of the click (mouse-click-left) * - * @returns {Number} Standard paint opacity of the enabled item + * @private + * + * @see DKTools.Sprite.Selectable.prototype.addEvent */ -DKTools.Sprite.Selectable.prototype.standardEnabledItemPaintOpacity = function() { - return 255; +DKTools.Sprite.Selectable.prototype._setupMouseClickEvent = function() { + this.addEvent({ + type: 'mouse-click-left', + onUpdate: this._onTouch.bind(this, true) + }); }; /** - * Returns the standard paint opacity of the disabled item + * Sets the event of the long press (mouse-long-press-left) * - * @returns {Number} Standard paint opacity of the disabled item + * @private + * + * @see DKTools.Sprite.Selectable.prototype.addEvent */ -DKTools.Sprite.Selectable.prototype.standardDisabledItemPaintOpacity = function() { - try { - return Window_Base.prototype.translucentOpacity.call(this); - } catch(e) { - return 160; - } +DKTools.Sprite.Selectable.prototype._setupMouseLongPressEvent = function() { + this.addEvent({ + type: 'mouse-long-press-left', + onUpdate: this._onTouch.bind(this, false) + }); }; /** - * Returns the standard item align + * Sets the events of the mouse hover (mouse-enter and mouse-move) * - * @returns {String} Standard item align + * @private + * + * @see DKTools.Sprite.Selectable.prototype.addEvent */ -DKTools.Sprite.Selectable.prototype.standardItemAlign = function() { - return this.align; -}; +DKTools.Sprite.Selectable.prototype._setupMouseHoverEvents = function() { + this.addEvent({ + type: 'mouse-enter', + onUpdate: this.processMouseHover.bind(this) + }); -// setup methods + this.addEvent({ + type: 'mouse-move', + onUpdate: this.processMouseHover.bind(this) + }); +}; /** - * Sets all parameters - * - * @override - * - * @param {Object} [object] - Parameters - * - * @param {Number} [object.index] - Index - * @param {Number} [object.maxCols] - Number of the columns - * @param {Boolean} [object.fixedHorizontal] - Fixed horizontal position - * @param {Boolean} [object.cursorFixed] - Fixed cursor - * @param {Boolean} [object.cursorAll] - Cursor all - * @param {Number} [object.horizontalSpacing] - Horizontal spacing - * @param {Number} [object.verticalSpacing] - Vertical spacing - * @param {Number} [object.textPadding] - Text padding - * @param {Object[]} [object.items] - List of the items - * @param {Function} [object.drawItemHandler] - Handler of draw of the item - * @param {Function | Number} [object.itemWidth] - Width of the item - * @param {Function | Number} [object.itemHeight] - Height of the item - * @param {Function} [object.itemRect] - Rectangle of the item - * @param {Function | Object} [object.itemFont] - Font of the item - * @param {Function | String} [object.itemTextColor] - Text color of the item - * @param {Function | Number} [object.itemPaintOpacity] - Paint opacity of the item - * @param {Function | String} [object.itemAlign] - Align of the item - * - * @param {String} [object.font.fontFace] - Font face - * @param {Number} [object.font.fontSize] - Font size - * @param {Boolean} [object.font.fontItalic] - Font italic - * - * @see DKTools.Sprite.Button.prototype.setupAll - * @see DKTools.Sprite.Selectable.prototype.setupIndex - * @see DKTools.Sprite.Selectable.prototype.setupMaxCols - * @see DKTools.Sprite.Selectable.prototype.setupFixedHorizontal - * @see DKTools.Sprite.Selectable.prototype.setupCursorFixed - * @see DKTools.Sprite.Selectable.prototype.setupCursorAll - * @see DKTools.Sprite.Selectable.prototype.setupSpacing - * @see DKTools.Sprite.Selectable.prototype.setupTextPadding - * @see DKTools.Sprite.Selectable.prototype.setupItems - * @see DKTools.Sprite.Selectable.prototype.setupDrawItemHandler - * @see DKTools.Sprite.Selectable.prototype.setupItemWidth - * @see DKTools.Sprite.Selectable.prototype.setupItemHeight - * @see DKTools.Sprite.Selectable.prototype.setupItemRect - * @see DKTools.Sprite.Selectable.prototype.setupItemFont - * @see DKTools.Sprite.Selectable.prototype.setupItemTextColor - * @see DKTools.Sprite.Selectable.prototype.setupItemPaintOpacity - * @see DKTools.Sprite.Selectable.prototype.setupItemAlign + * Sets the events of the wheel scrolling (wheel-Y-inside and wheel-Y-outside) + * + * @private + * + * @see DKTools.Sprite.Selectable.prototype.addEvent */ -DKTools.Sprite.Selectable.prototype.setupAll = function(object) { - object = object || {}; - DKTools.Sprite.Button.prototype.setupAll.call(this, object); - this.setupIndex(object.index); - this.setupMaxCols(object.maxCols); - this.setupFixedHorizontal(object.fixedHorizontal); - this.setupCursorFixed(object.cursorFixed); - this.setupCursorAll(object.cursorAll); - this.setupSpacing(object.horizontalSpacing, object.verticalSpacing); - this.setupTextPadding(object.textPadding); - this.setupItems(object.items); - this.setupDrawItemHandler(object.drawItemHandler); - this.setupItemWidth(object.itemWidth); - this.setupItemHeight(object.itemHeight); - this.setupItemRect(object.itemRect); - this.setupItemFont(object.itemFont); - this.setupItemTextColor(object.itemTextColor); - this.setupItemPaintOpacity(object.itemPaintOpacity); - this.setupItemAlign(object.itemAlign); +DKTools.Sprite.Selectable.prototype._setupWheelScrollEvents = function() { + this.addEvent({ + type: 'wheel-Y-inside', + onUpdate: this.processWheelScroll.bind(this) + }); + + this.addEvent({ + type: 'wheel-Y-outside', + onUpdate: this.processWheelScroll.bind(this) + }); }; +// _add methods + /** - * Sets the index + * Adds children objects to processing * - * @param {Number} [index=this.standardIndex()] - Index + * @private + * @override + * + * @see DKTools.Sprite.Button.prototype._addAllChildren + * @see DKTools.Sprite.Selectable.prototype._addCursorSprite + */ +DKTools.Sprite.Selectable.prototype._addAllChildren = function() { + DKTools.Sprite.Button.prototype._addAllChildren.call(this); + this._addCursorSprite(); +}; + +/** + * Adds sprite of the cursor to processing * - * @see DKTools.Sprite.Selectable.prototype.standardIndex + * @private */ -DKTools.Sprite.Selectable.prototype.setupIndex = function(index) { - /** - * @private - * @readonly - * @type {Number} - */ - this._index = (index == null ? this.standardIndex() : index); +DKTools.Sprite.Selectable.prototype._addCursorSprite = function() { + this.addChild(this._cursorSprite); }; +// standard methods + /** - * Sets the number of the columns + * Returns the standard index * - * @param {Number} [cols=this.standardMaxCols()] - Number of the columns + * @returns {Number} Standard index + */ +DKTools.Sprite.Selectable.prototype.standardIndex = function() { + return 0; +}; + +/** + * Returns the standard number of the columns * - * @see DKTools.Sprite.Selectable.prototype.standardMaxCols + * @returns {Number} Standard number of the columns */ -DKTools.Sprite.Selectable.prototype.setupMaxCols = function(cols) { - /** - * @private - * @readonly - * @type {Number} - */ - this._maxCols = cols || this.standardMaxCols(); +DKTools.Sprite.Selectable.prototype.standardMaxCols = function() { + return 1; }; /** - * Sets the fixed horizontal position - * - * @param {Boolean} [fixedHorizontal=this.standardFixedHorizontal()] - Fixed horizontal position - * - * @see DKTools.Sprite.Selectable.prototype.standardFixedHorizontal + * Returns the standard fixed cursor + * + * @returns {Boolean} Standard fixed cursor */ -DKTools.Sprite.Selectable.prototype.setupFixedHorizontal = function(fixedHorizontal) { - /** - * @private - * @readonly - * @type {Boolean} - */ - this._fixedHorizontal = (fixedHorizontal == null ? this.standardFixedHorizontal() : fixedHorizontal); +DKTools.Sprite.Selectable.prototype.standardCursorFixed = function() { + return false; }; /** - * Sets the fixed cursor - * - * @param {Boolean} [cursorFixed=this.standardCursorFixed()] - Fixed cursor - * - * @see DKTools.Sprite.Selectable.prototype.standardCursorFixed + * Returns the standard cursor all + * + * @returns {Boolean} Standard cursor all */ -DKTools.Sprite.Selectable.prototype.setupCursorFixed = function(cursorFixed) { - /** - * @private - * @readonly - * @type {Boolean} - */ - this._cursorFixed = (cursorFixed == null ? this.standardCursorFixed() : cursorFixed); +DKTools.Sprite.Selectable.prototype.standardCursorAll = function() { + return false; }; /** - * Sets the cursor all - * - * @param {Boolean} [cursorAll=this.standardCursorAll()] - Cursor all + * Returns the standard fixed horizontal position * - * @see DKTools.Sprite.Selectable.prototype.standardCursorAll + * @returns {Boolean} Standard fixed horizontal position */ -DKTools.Sprite.Selectable.prototype.setupCursorAll = function(cursorAll) { - /** - * @private - * @readonly - * @type {Boolean} - */ - this._cursorAll = (cursorAll == null ? this.standardCursorAll() : cursorAll); +DKTools.Sprite.Selectable.prototype.standardFixedHorizontal = function() { + return false; }; /** - * Sets the horizontal spacing - * - * @param {Number} [spacing=this.standardHorizontalSpacing()] - Horizontal spacing + * Returns the standard horizontal spacing * - * @see DKTools.Sprite.Selectable.prototype.standardHorizontalSpacing + * @returns {Number} Standard horizontal spacing */ -DKTools.Sprite.Selectable.prototype.setupHorizontalSpacing = function(spacing) { - /** - * @private - * @readonly - * @type {Number} - */ - this._horizontalSpacing = (spacing == null ? this.standardHorizontalSpacing() : spacing); +DKTools.Sprite.Selectable.prototype.standardHorizontalSpacing = function() { + return 0; }; /** - * Sets the vertical spacing - * - * @param {Number} [spacing=this.standardVerticalSpacing()] - Vertical spacing + * Returns the standard vertical spacing * - * @see DKTools.Sprite.Selectable.prototype.standardVerticalSpacing + * @returns {Number} Standard vertical spacing */ -DKTools.Sprite.Selectable.prototype.setupVerticalSpacing = function(spacing) { - /** - * @private - * @readonly - * @type {Number} - */ - this._verticalSpacing = (spacing == null ? this.standardVerticalSpacing() : spacing); +DKTools.Sprite.Selectable.prototype.standardVerticalSpacing = function() { + return 0; }; /** - * Sets the horizontal and vertical spacings + * Returns the standard text padding * - * @param {Number} [horizontalSpacing] - Horizontal spacing - * @param {Number} [verticalSpacing] - Vertical spacing - * - * @see DKTools.Sprite.Selectable.prototype.setupHorizontalSpacing - * @see DKTools.Sprite.Selectable.prototype.setupVerticalSpacing + * @returns {Number} Standard text padding */ -DKTools.Sprite.Selectable.prototype.setupSpacing = function(horizontalSpacing, verticalSpacing) { - this.setupHorizontalSpacing(horizontalSpacing); - this.setupVerticalSpacing(verticalSpacing); +DKTools.Sprite.Selectable.prototype.standardTextPadding = function() { + return 6; }; /** - * Sets the text padding + * Returns the standard list of the items * - * @param {Number} [textPadding=this.standardTextPadding()] - Text padding - * - * @see DKTools.Sprite.Selectable.prototype.standardTextPadding + * @returns {Array} Standard list of the items */ -DKTools.Sprite.Selectable.prototype.setupTextPadding = function(textPadding) { - /** - * @private - * @readonly - * @type {Number} - */ - this._textPadding = (textPadding == null ? this.standardTextPadding() : textPadding); +DKTools.Sprite.Selectable.prototype.standardItems = function() { + return []; }; /** - * Sets the list of the items + * Returns the standard handler of draw of the item * - * @param {Object[]} items - Items - * - * @param {Function | String} [items[].name] - Item name - * @param {Function | String} [items[].align] - Item align - * @param {Function | String} [items[].textColor] - Item text color - * @param {Function | Object} [items[].font] - Item font - * @param {Function | Number} [items[].paintOpacity] - Item paint opacity - * @param {Function | Boolean} [items[].enabled] - Item activity - * @param {String} [items[].symbol] - Item symbol - * @param {Function} [items[].handler] - Item handler - * @param {String} [items[].font.fontFace] - Font face - * @param {Number} [items[].font.fontSize] - Font size - * @param {Boolean} [items[].font.fontItalic] - Font italic + * @returns {Function} Standard handler of draw of the item */ -DKTools.Sprite.Selectable.prototype.setupItems = function(items) { - if (items == null) { - items = this.standardItems(); - } - - _.forEach(items, this._checkItem.bind(this)); +DKTools.Sprite.Selectable.prototype.standardDrawItemHandler = function() { + return function(index) { + const name = this.getItemName(index); + const font = this.getItemFontByIndex(index); + const textColor = this.getItemTextColorByIndex(index); + const paintOpacity = this.getItemPaintOpacityByIndex(index); + const align = this.getItemAlignByIndex(index); + const rect = this.getItemRectForTextByIndex(index); - this._items = items; + this.drawText(name, { + font, + textColor, + paintOpacity, + align, + rect, + resetFont: true, + resetTextColor: true, + resetPaintOpacity: true + }); + }.bind(this); }; /** - * Sets the handler of draw of the item + * Returns the standard item width * - * @param {Function} [handler=this.standardDrawItemHandler()] - Handler of draw of the item - * - * @see DKTools.Sprite.Selectable.prototype.standardDrawItemHandler + * @returns {Function} Standard item width */ -DKTools.Sprite.Selectable.prototype.setupDrawItemHandler = function(handler) { - /** - * @private - * @readonly - * @type {Function | null} - */ - this._drawItemHandler = handler || this.standardDrawItemHandler(); +DKTools.Sprite.Selectable.prototype.standardItemWidth = function() { + return function() { + const spacing = this._horizontalSpacing; + return Math.floor((this.realWidth + spacing) / this.getMaxCols() - spacing); + }.bind(this); +}; + +/** + * Returns the standard item height + * + * @returns {Function} Standard item height + */ +DKTools.Sprite.Selectable.prototype.standardItemHeight = function() { + return this.getLineHeight(); }; /** - * Sets the width of the item + * Returns the standard item rect * - * @param {Function | Number} [itemWidth=this.standardItemWidth()] - Width of the item - * - * @see DKTools.Sprite.Selectable.prototype.standardItemWidth + * @returns {Function} Standard item rect */ -DKTools.Sprite.Selectable.prototype.setupItemWidth = function(itemWidth) { - /** - * @private - * @readonly - * @type {Function | Number} - */ - this._itemWidth = itemWidth || this.standardItemWidth(); +DKTools.Sprite.Selectable.prototype.standardItemRect = function() { + return function(index) { + const rect = new Rectangle(); + const maxCols = this.getMaxCols(); + + rect.width = this.getItemWidth(); + rect.height = this.getItemHeight(); + + if (this.isHorizontal()) { + rect.x = (index - this.getTopCol()) * (rect.width + this._horizontalSpacing); + rect.y = 0; + } else { + rect.x = index % maxCols * (rect.width + this._horizontalSpacing); + rect.y = (Math.floor(index / maxCols) - this.getTopRow()) * (rect.height + this._verticalSpacing); + } + + return rect; + }.bind(this); }; /** - * Sets the height of the item + * Returns the standard item font * - * @param {Function | Number} [itemHeight=this.standardItemHeight()] - Height of the item - * - * @see DKTools.Sprite.Selectable.prototype.standardItemHeight + * @returns {Object} Standard item font */ -DKTools.Sprite.Selectable.prototype.setupItemHeight = function(itemHeight) { - /** - * @private - * @readonly - * @type {Function | Number} - */ - this._itemHeight = itemHeight || this.standardItemHeight(); +DKTools.Sprite.Selectable.prototype.standardItemFont = function() { + return this.font; }; /** - * Sets the rectangle of the item - * - * @param {Function} [itemRect=this.standardItemRect()] - Rectangle of the item - * - * @see DKTools.Sprite.Selectable.prototype.standardItemRect + * Returns the standard text color of the item + * + * @returns {String} Standard text color of the item */ -DKTools.Sprite.Selectable.prototype.setupItemRect = function(itemRect) { - /** - * @private - * @readonly - * @type {Function} - */ - this._itemRect = itemRect || this.standardItemRect(); +DKTools.Sprite.Selectable.prototype.standardItemTextColor = function() { + return this.textColor; }; /** - * Sets the font of the item - * - * @param {Function | Object} [itemFont=this.standardItemFont()] - Font of the item + * Returns the standard paint opacity of the item * - * @param {String} [itemFont.fontFace] - Font face - * @param {Number} [itemFont.fontSize] - Font size - * @param {Boolean} [itemFont.fontItalic] - Font italic - * - * @see DKTools.Sprite.Selectable.prototype.standardItemFont + * @returns {Number} Standard paint opacity of the item */ -DKTools.Sprite.Selectable.prototype.setupItemFont = function(itemFont) { - /** - * @private - * @readonly - * @type {Function | Object} - */ - this._itemFont = itemFont || this.standardItemFont(); +DKTools.Sprite.Selectable.prototype.standardItemPaintOpacity = function() { + return function(index) { + if (this.isItemEnabled(index)) { + return this.standardEnabledItemPaintOpacity(); + } else { + return this.standardDisabledItemPaintOpacity(); + } + }.bind(this); }; /** - * Sets the text color of the item + * Returns the standard paint opacity of the enabled item * - * @param {Function | String} [itemTextColor=this.standardItemTextColor()] - Text color of the item - * - * @see DKTools.Sprite.Selectable.prototype.standardItemTextColor + * @returns {Number} Standard paint opacity of the enabled item */ -DKTools.Sprite.Selectable.prototype.setupItemTextColor = function(itemTextColor) { - /** - * @private - * @readonly - * @type {Function | String} - */ - this._itemTextColor = itemTextColor || this.standardItemTextColor(); +DKTools.Sprite.Selectable.prototype.standardEnabledItemPaintOpacity = function() { + return 255; }; /** - * Sets the paint opacity of the item + * Returns the standard paint opacity of the disabled item * - * @param {Function | Number} [itemPaintOpacity=this.standardItemPaintOpacity()] - Paint opacity of the item - * - * @see DKTools.Sprite.Selectable.prototype.standardItemPaintOpacity + * @returns {Number} Standard paint opacity of the disabled item */ -DKTools.Sprite.Selectable.prototype.setupItemPaintOpacity = function(itemPaintOpacity) { - /** - * @private - * @readonly - * @type {Function | Number} - */ - this._itemPaintOpacity = itemPaintOpacity || this.standardItemPaintOpacity(); +DKTools.Sprite.Selectable.prototype.standardDisabledItemPaintOpacity = function() { + try { + return Window_Base.prototype.translucentOpacity.call(this); + } catch(e) { + return 160; + } }; /** - * Sets the align of the item + * Returns the standard item align * - * @param {Function | String} [itemAlign=this.standardItemAlign()] - Align of the item - * - * @see DKTools.Sprite.Selectable.prototype.standardItemAlign + * @returns {String} Standard item align */ -DKTools.Sprite.Selectable.prototype.setupItemAlign = function(itemAlign) { - /** - * @private - * @readonly - * @type {Function | String} - */ - this._itemAlign = itemAlign || this.standardItemAlign(); +DKTools.Sprite.Selectable.prototype.standardItemAlign = function() { + return this.align; }; -// set methods +// setup methods /** - * Changes all parameters - * Returns the number of changed parameters + * Sets all parameters * * @override * - * @param {Object} [object={}] - Parameters - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the object + * @param {Object} [object] - Parameters * * @param {Number} [object.index] - Index * @param {Number} [object.maxCols] - Number of the columns @@ -18999,594 +19251,507 @@ DKTools.Sprite.Selectable.prototype.setupItemAlign = function(itemAlign) { * @param {Function | Number} [object.itemPaintOpacity] - Paint opacity of the item * @param {Function | String} [object.itemAlign] - Align of the item * - * @param {String} [object.font.fontFace] - Font face - * @param {Number} [object.font.fontSize] - Font size - * @param {Boolean} [object.font.fontItalic] - Font italic - * - * @see DKTools.Sprite.Button.prototype.setAll - * @see DKTools.Sprite.Selectable.prototype.setIndex - * @see DKTools.Sprite.Selectable.prototype.setMaxCols - * @see DKTools.Sprite.Selectable.prototype.setFixedHorizontal - * @see DKTools.Sprite.Selectable.prototype.setCursorFixed - * @see DKTools.Sprite.Selectable.prototype.setCursorAll - * @see DKTools.Sprite.Selectable.prototype.setSpacing - * @see DKTools.Sprite.Selectable.prototype.setTextPadding - * @see DKTools.Sprite.Selectable.prototype.setItems - * @see DKTools.Sprite.Selectable.prototype.setDrawItemHandler - * @see DKTools.Sprite.Selectable.prototype.setItemWidth - * @see DKTools.Sprite.Selectable.prototype.setItemHeight - * @see DKTools.Sprite.Selectable.prototype.setItemRect - * @see DKTools.Sprite.Selectable.prototype.setItemFont - * @see DKTools.Sprite.Selectable.prototype.setItemTextColor - * @see DKTools.Sprite.Selectable.prototype.setItemPaintOpacity - * @see DKTools.Sprite.Selectable.prototype.setItemAlign - * @see DKTools.Sprite.Selectable.prototype.start - * @see DKTools.Sprite.Selectable.prototype.activate - * - * @returns {Number} Number of changed parameters - */ -DKTools.Sprite.Selectable.prototype.setAll = function(object, blockStart, activate) { - object = object || {}; - const block = true; - let changed = DKTools.Sprite.Button.prototype.setAll.call(this, object, block); - - if (this.setIndex(object.index, block)) { - changed++; - } - - if (this.setMaxCols(object.maxCols, block)) { - changed++; - } - - if (this.setFixedHorizontal(object.fixedHorizontal, block)) { - changed++; - } - - if (this.setCursorFixed(object.cursorFixed, block)) { - changed++; - } - - if (this.setCursorAll(object.cursorAll, block)) { - changed++; - } - - changed += this.setSpacing(object.horizontalSpacing, object.verticalSpacing, block); - - if (this.setTextPadding(object.textPadding, block)) { - changed++; - } - - if (this.setItems(object.items, block)) { - changed++; - } - - if (this.setDrawItemHandler(object.drawItemHandler, block)) { - changed++; - } - - if (this.setItemWidth(object.itemWidth, block)) { - changed++; - } - - if (this.setItemHeight(object.itemHeight, block)) { - changed++; - } - - if (this.setItemRect(object.itemRect, block)) { - changed++; - } - - if (this.setItemFont(object.itemFont, block)) { - changed++; - } - - if (this.setItemTextColor(object.itemTextColor, block)) { - changed++; - } - - if (this.setItemPaintOpacity(object.itemPaintOpacity, block)) { - changed++; - } - - if (this.setItemAlign(object.itemAlign, block)) { - changed++; - } - - if (changed) { - if (!blockStart) { - this.start(); - } - - if (activate) { - this.activate(); - } - } - - return changed; + * @param {String} [object.font.fontFace] - Font face + * @param {Number} [object.font.fontSize] - Font size + * @param {Boolean} [object.font.fontItalic] - Font italic + * + * @see DKTools.Sprite.Button.prototype.setupAll + * @see DKTools.Sprite.Selectable.prototype.setupIndex + * @see DKTools.Sprite.Selectable.prototype.setupMaxCols + * @see DKTools.Sprite.Selectable.prototype.setupFixedHorizontal + * @see DKTools.Sprite.Selectable.prototype.setupCursorFixed + * @see DKTools.Sprite.Selectable.prototype.setupCursorAll + * @see DKTools.Sprite.Selectable.prototype.setupSpacing + * @see DKTools.Sprite.Selectable.prototype.setupTextPadding + * @see DKTools.Sprite.Selectable.prototype.setupItems + * @see DKTools.Sprite.Selectable.prototype.setupDrawItemHandler + * @see DKTools.Sprite.Selectable.prototype.setupItemWidth + * @see DKTools.Sprite.Selectable.prototype.setupItemHeight + * @see DKTools.Sprite.Selectable.prototype.setupItemRect + * @see DKTools.Sprite.Selectable.prototype.setupItemFont + * @see DKTools.Sprite.Selectable.prototype.setupItemTextColor + * @see DKTools.Sprite.Selectable.prototype.setupItemPaintOpacity + * @see DKTools.Sprite.Selectable.prototype.setupItemAlign + */ +DKTools.Sprite.Selectable.prototype.setupAll = function(object) { + object = object || {}; + DKTools.Sprite.Button.prototype.setupAll.call(this, object); + this.setupIndex(object.index); + this.setupMaxCols(object.maxCols); + this.setupFixedHorizontal(object.fixedHorizontal); + this.setupCursorFixed(object.cursorFixed); + this.setupCursorAll(object.cursorAll); + this.setupSpacing(object.horizontalSpacing, object.verticalSpacing); + this.setupTextPadding(object.textPadding); + this.setupItems(object.items); + this.setupDrawItemHandler(object.drawItemHandler); + this.setupItemWidth(object.itemWidth); + this.setupItemHeight(object.itemHeight); + this.setupItemRect(object.itemRect); + this.setupItemFont(object.itemFont); + this.setupItemTextColor(object.itemTextColor); + this.setupItemPaintOpacity(object.itemPaintOpacity); + this.setupItemAlign(object.itemAlign); }; /** - * Changes the index - * Returns true if the change occurred + * Sets the index * - * @param {Number} [index] - Index - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {Number} [index=this.standardIndex()] - Index * - * @see DKTools.Sprite.Selectable.prototype.setupIndex - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Boolean} Change occurred + * @see DKTools.Sprite.Selectable.prototype.standardIndex */ -DKTools.Sprite.Selectable.prototype.setIndex = function(index, blockRefreshAll) { - if (this._index === index) { - return false; - } - - const lastIndex = this._index; - this.setupIndex(index); - - if (this._index === lastIndex) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return true; +DKTools.Sprite.Selectable.prototype.setupIndex = function(index) { + /** + * @private + * @readonly + * @type {Number} + */ + this._index = (index == null ? this.standardIndex() : index); }; /** - * Changes the number of the columns - * Returns true if the change occurred + * Sets the number of the columns * - * @param {Number} [cols] - Number of the columns - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {Number} [cols=this.standardMaxCols()] - Number of the columns * - * @see DKTools.Sprite.Selectable.prototype.setupMaxCols - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Boolean} Change occurred + * @see DKTools.Sprite.Selectable.prototype.standardMaxCols */ -DKTools.Sprite.Selectable.prototype.setMaxCols = function(cols, blockRefreshAll) { - if (this._maxCols === cols) { - return false; - } - - const lastCols = this._maxCols; - this.setupMaxCols(cols); - - if (this._maxCols === lastCols) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return true; +DKTools.Sprite.Selectable.prototype.setupMaxCols = function(cols) { + /** + * @private + * @readonly + * @type {Number} + */ + this._maxCols = cols || this.standardMaxCols(); }; /** - * Changes the fixed horizontal position - * Returns true if the change occurred - * - * @param {Boolean} [fixedHorizontal] - * @param {Boolean} [blockRefreshAll=false] Blocking the call of the "refreshAll" function + * Sets the fixed horizontal position * - * @see DKTools.Sprite.Selectable.prototype.setupFixedHorizontal - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @param {Boolean} [fixedHorizontal=this.standardFixedHorizontal()] - Fixed horizontal position * - * @returns {Boolean} Change occurred + * @see DKTools.Sprite.Selectable.prototype.standardFixedHorizontal */ -DKTools.Sprite.Selectable.prototype.setFixedHorizontal = function(fixedHorizontal, blockRefreshAll) { - if (this._fixedHorizontal === fixedHorizontal) { - return false; - } +DKTools.Sprite.Selectable.prototype.setupFixedHorizontal = function(fixedHorizontal) { + /** + * @private + * @readonly + * @type {Boolean} + */ + this._fixedHorizontal = (fixedHorizontal == null ? this.standardFixedHorizontal() : fixedHorizontal); +}; - const lastFixed = this._fixedHorizontal; - this.setupFixedHorizontal(fixedHorizontal); +/** + * Sets the fixed cursor + * + * @param {Boolean} [cursorFixed=this.standardCursorFixed()] - Fixed cursor + * + * @see DKTools.Sprite.Selectable.prototype.standardCursorFixed + */ +DKTools.Sprite.Selectable.prototype.setupCursorFixed = function(cursorFixed) { + /** + * @private + * @readonly + * @type {Boolean} + */ + this._cursorFixed = (cursorFixed == null ? this.standardCursorFixed() : cursorFixed); +}; - if (this._fixedHorizontal === lastFixed) { - return false; - } +/** + * Sets the cursor all + * + * @param {Boolean} [cursorAll=this.standardCursorAll()] - Cursor all + * + * @see DKTools.Sprite.Selectable.prototype.standardCursorAll + */ +DKTools.Sprite.Selectable.prototype.setupCursorAll = function(cursorAll) { + /** + * @private + * @readonly + * @type {Boolean} + */ + this._cursorAll = (cursorAll == null ? this.standardCursorAll() : cursorAll); +}; - if (!blockRefreshAll) { - this.refreshAll(); - } +/** + * Sets the horizontal spacing + * + * @param {Number} [spacing=this.standardHorizontalSpacing()] - Horizontal spacing + * + * @see DKTools.Sprite.Selectable.prototype.standardHorizontalSpacing + */ +DKTools.Sprite.Selectable.prototype.setupHorizontalSpacing = function(spacing) { + /** + * @private + * @readonly + * @type {Number} + */ + this._horizontalSpacing = (spacing == null ? this.standardHorizontalSpacing() : spacing); +}; - return true; +/** + * Sets the vertical spacing + * + * @param {Number} [spacing=this.standardVerticalSpacing()] - Vertical spacing + * + * @see DKTools.Sprite.Selectable.prototype.standardVerticalSpacing + */ +DKTools.Sprite.Selectable.prototype.setupVerticalSpacing = function(spacing) { + /** + * @private + * @readonly + * @type {Number} + */ + this._verticalSpacing = (spacing == null ? this.standardVerticalSpacing() : spacing); }; /** - * Changes the fixed cursor - * Returns true if the change occurred - * - * @param {Boolean} [cursorFixed] - Fixed cursor - * @param {Boolean} [blockRefreshAll=false] Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupCursorFixed - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * Sets the horizontal and vertical spacings + * + * @param {Number} [horizontalSpacing] - Horizontal spacing + * @param {Number} [verticalSpacing] - Vertical spacing * - * @returns {Boolean} Change occurred + * @see DKTools.Sprite.Selectable.prototype.setupHorizontalSpacing + * @see DKTools.Sprite.Selectable.prototype.setupVerticalSpacing */ -DKTools.Sprite.Selectable.prototype.setCursorFixed = function(cursorFixed, blockRefreshAll) { - if (this._cursorFixed === cursorFixed) { - return false; - } +DKTools.Sprite.Selectable.prototype.setupSpacing = function(horizontalSpacing, verticalSpacing) { + this.setupHorizontalSpacing(horizontalSpacing); + this.setupVerticalSpacing(verticalSpacing); +}; - const lastFixed = this._cursorFixed; - this.setupCursorFixed(cursorFixed); +/** + * Sets the text padding + * + * @param {Number} [textPadding=this.standardTextPadding()] - Text padding + * + * @see DKTools.Sprite.Selectable.prototype.standardTextPadding + */ +DKTools.Sprite.Selectable.prototype.setupTextPadding = function(textPadding) { + /** + * @private + * @readonly + * @type {Number} + */ + this._textPadding = (textPadding == null ? this.standardTextPadding() : textPadding); +}; - if (this._cursorFixed === lastFixed) { - return false; +/** + * Sets the list of the items + * + * @param {Object[]} items - Items + * + * @param {Function | String} [items[].name] - Item name + * @param {Function | String} [items[].align] - Item align + * @param {Function | String} [items[].textColor] - Item text color + * @param {Function | Object} [items[].font] - Item font + * @param {Function | Number} [items[].paintOpacity] - Item paint opacity + * @param {Function | Boolean} [items[].enabled] - Item activity + * @param {String} [items[].symbol] - Item symbol + * @param {Function} [items[].handler] - Item handler + * @param {String} [items[].font.fontFace] - Font face + * @param {Number} [items[].font.fontSize] - Font size + * @param {Boolean} [items[].font.fontItalic] - Font italic + */ +DKTools.Sprite.Selectable.prototype.setupItems = function(items) { + if (items == null) { + items = this.standardItems(); } - if (!blockRefreshAll) { - this.refreshAll(); - } + _.forEach(items, this._checkItem.bind(this)); - return true; + this._items = items; }; /** - * Changes the cursor all - * Returns true if the change occurred - * - * @param {Boolean} [cursorAll] - Cursor all - * @param {Boolean} [blockRefreshAll=false] Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupCursorAll - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * Sets the handler of draw of the item + * + * @param {Function} [handler=this.standardDrawItemHandler()] - Handler of draw of the item * - * @returns {Boolean} Change occurred + * @see DKTools.Sprite.Selectable.prototype.standardDrawItemHandler */ -DKTools.Sprite.Selectable.prototype.setCursorAll = function(cursorAll, blockRefreshAll) { - if (this._cursorAll === cursorAll) { - return false; - } - - const lastAll = this._cursorAll; - this.setupCursorAll(cursorAll); - - if (this._cursorAll === lastAll) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return true; +DKTools.Sprite.Selectable.prototype.setupDrawItemHandler = function(handler) { + /** + * @private + * @readonly + * @type {Function | null} + */ + this._drawItemHandler = handler || this.standardDrawItemHandler(); }; /** - * Changes the horizontal spacing - * Returns true if the change occurred - * - * @param {Number} [spacing] - Horizontal spacing - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupHorizontalSpacing - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * Sets the width of the item * - * @returns {Boolean} Change occurred + * @param {Function | Number} [itemWidth=this.standardItemWidth()] - Width of the item + * + * @see DKTools.Sprite.Selectable.prototype.standardItemWidth */ -DKTools.Sprite.Selectable.prototype.setHorizontalSpacing = function(spacing, blockRefreshAll) { - if (this._horizontalSpacing === spacing) { - return false; - } - - const lastSpacing = this._horizontalSpacing; - this.setupHorizontalSpacing(spacing); - - if (this._horizontalSpacing === lastSpacing) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return true; +DKTools.Sprite.Selectable.prototype.setupItemWidth = function(itemWidth) { + /** + * @private + * @readonly + * @type {Function | Number} + */ + this._itemWidth = itemWidth || this.standardItemWidth(); }; /** - * Changes the vertical spacing - * Returns true if the change occurred - * - * @param {Number} [spacing] - Vertical spacing - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupVerticalSpacing - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * Sets the height of the item * - * @returns {Boolean} Change occurred + * @param {Function | Number} [itemHeight=this.standardItemHeight()] - Height of the item + * + * @see DKTools.Sprite.Selectable.prototype.standardItemHeight */ -DKTools.Sprite.Selectable.prototype.setVerticalSpacing = function(spacing, blockRefreshAll) { - if (this._verticalSpacing === spacing) { - return false; - } - - const lastSpacing = this._verticalSpacing; - this.setupVerticalSpacing(spacing); - - if (this._verticalSpacing === lastSpacing) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } +DKTools.Sprite.Selectable.prototype.setupItemHeight = function(itemHeight) { + /** + * @private + * @readonly + * @type {Function | Number} + */ + this._itemHeight = itemHeight || this.standardItemHeight(); +}; - return true; +/** + * Sets the rectangle of the item + * + * @param {Function} [itemRect=this.standardItemRect()] - Rectangle of the item + * + * @see DKTools.Sprite.Selectable.prototype.standardItemRect + */ +DKTools.Sprite.Selectable.prototype.setupItemRect = function(itemRect) { + /** + * @private + * @readonly + * @type {Function} + */ + this._itemRect = itemRect || this.standardItemRect(); }; /** - * Changes the horizontal and vertical spacings - * Returns the number of changed parameters + * Sets the font of the item * - * @param {Number} [horizontalSpacing] - Horizontal spacing - * @param {Number} [verticalSpacing] - Vertical spacing - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {Function | Object} [itemFont=this.standardItemFont()] - Font of the item * - * @see DKTools.Sprite.Selectable.prototype.setHorizontalSpacing - * @see DKTools.Sprite.Selectable.prototype.setVerticalSpacing + * @param {String} [itemFont.fontFace] - Font face + * @param {Number} [itemFont.fontSize] - Font size + * @param {Boolean} [itemFont.fontItalic] - Font italic * - * @returns {Number} Number of changed parameters + * @see DKTools.Sprite.Selectable.prototype.standardItemFont */ -DKTools.Sprite.Selectable.prototype.setSpacing = function(horizontalSpacing, verticalSpacing, blockRefreshAll) { - const block = true; - let changed = 0; - - if (this.setHorizontalSpacing(horizontalSpacing, block)) { - changed++; - } - - if (this.setVerticalSpacing(verticalSpacing, block)) { - changed++; - } - - if (changed && !blockRefreshAll) { - this.refreshAll(); - } - - return changed; +DKTools.Sprite.Selectable.prototype.setupItemFont = function(itemFont) { + /** + * @private + * @readonly + * @type {Function | Object} + */ + this._itemFont = itemFont || this.standardItemFont(); }; /** - * Changes the text padding - * Returns true if the change occurred - * - * @param {Number} [textPadding] - Text padding - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupTextPadding - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * Sets the text color of the item * - * @returns {Boolean} Change occurred + * @param {Function | String} [itemTextColor=this.standardItemTextColor()] - Text color of the item + * + * @see DKTools.Sprite.Selectable.prototype.standardItemTextColor */ -DKTools.Sprite.Selectable.prototype.setTextPadding = function(textPadding, blockRefreshAll) { - if (this._textPadding === textPadding) { - return false; - } - - const lastPadding = this._textPadding; - this.setupTextPadding(textPadding); - - if (this._textPadding === lastPadding) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return true; +DKTools.Sprite.Selectable.prototype.setupItemTextColor = function(itemTextColor) { + /** + * @private + * @readonly + * @type {Function | String} + */ + this._itemTextColor = itemTextColor || this.standardItemTextColor(); }; /** - * Changes the items - * Returns true if the change occurred - * - * @param {Object[]} [items] - List of the items - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupItems - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * Sets the paint opacity of the item * - * @returns {Boolean} Change occurred + * @param {Function | Number} [itemPaintOpacity=this.standardItemPaintOpacity()] - Paint opacity of the item + * + * @see DKTools.Sprite.Selectable.prototype.standardItemPaintOpacity */ -DKTools.Sprite.Selectable.prototype.setItems = function(items, blockRefreshAll) { - if (this._items == items) { - return false; - } - - this.setupItems(items); - - if (!blockRefreshAll) { - this.refreshAll(); - } +DKTools.Sprite.Selectable.prototype.setupItemPaintOpacity = function(itemPaintOpacity) { + /** + * @private + * @readonly + * @type {Function | Number} + */ + this._itemPaintOpacity = itemPaintOpacity || this.standardItemPaintOpacity(); +}; - return true; +/** + * Sets the align of the item + * + * @param {Function | String} [itemAlign=this.standardItemAlign()] - Align of the item + * + * @see DKTools.Sprite.Selectable.prototype.standardItemAlign + */ +DKTools.Sprite.Selectable.prototype.setupItemAlign = function(itemAlign) { + /** + * @private + * @readonly + * @type {Function | String} + */ + this._itemAlign = itemAlign || this.standardItemAlign(); }; +// set methods + /** - * Changes the handler of draw of the item - * Returns true if the change occurred + * Changes all parameters + * Returns the number of changed parameters * - * @param {Function} [handler] - Handler of draw of the item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @override * - * @see DKTools.Sprite.Selectable.prototype.setupDrawItemHandler - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @param {Object} [object={}] - Parameters + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the object * - * @returns {Boolean} Change occurred - */ -DKTools.Sprite.Selectable.prototype.setDrawItemHandler = function(handler, blockRefreshAll) { - if (this._drawItemHandler === handler) { - return false; - } - - const lastHandler = this._drawItemHandler; - this.setupDrawItemHandler(handler); - - if (this._drawItemHandler === lastHandler) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return true; -}; - -/** - * Changes the width of the item - * Returns true if the change occurred + * @param {Number} [object.index] - Index + * @param {Number} [object.maxCols] - Number of the columns + * @param {Boolean} [object.fixedHorizontal] - Fixed horizontal position + * @param {Boolean} [object.cursorFixed] - Fixed cursor + * @param {Boolean} [object.cursorAll] - Cursor all + * @param {Number} [object.horizontalSpacing] - Horizontal spacing + * @param {Number} [object.verticalSpacing] - Vertical spacing + * @param {Number} [object.textPadding] - Text padding + * @param {Object[]} [object.items] - List of the items + * @param {Function} [object.drawItemHandler] - Handler of draw of the item + * @param {Function | Number} [object.itemWidth] - Width of the item + * @param {Function | Number} [object.itemHeight] - Height of the item + * @param {Function} [object.itemRect] - Rectangle of the item + * @param {Function | Object} [object.itemFont] - Font of the item + * @param {Function | String} [object.itemTextColor] - Text color of the item + * @param {Function | Number} [object.itemPaintOpacity] - Paint opacity of the item + * @param {Function | String} [object.itemAlign] - Align of the item * - * @param {Function | Number} [itemWidth] - Width of the item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {String} [object.font.fontFace] - Font face + * @param {Number} [object.font.fontSize] - Font size + * @param {Boolean} [object.font.fontItalic] - Font italic * - * @see DKTools.Sprite.Selectable.prototype.setupItemWidth - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @see DKTools.Sprite.Button.prototype.setAll + * @see DKTools.Sprite.Selectable.prototype.setIndex + * @see DKTools.Sprite.Selectable.prototype.setMaxCols + * @see DKTools.Sprite.Selectable.prototype.setFixedHorizontal + * @see DKTools.Sprite.Selectable.prototype.setCursorFixed + * @see DKTools.Sprite.Selectable.prototype.setCursorAll + * @see DKTools.Sprite.Selectable.prototype.setSpacing + * @see DKTools.Sprite.Selectable.prototype.setTextPadding + * @see DKTools.Sprite.Selectable.prototype.setItems + * @see DKTools.Sprite.Selectable.prototype.setDrawItemHandler + * @see DKTools.Sprite.Selectable.prototype.setItemWidth + * @see DKTools.Sprite.Selectable.prototype.setItemHeight + * @see DKTools.Sprite.Selectable.prototype.setItemRect + * @see DKTools.Sprite.Selectable.prototype.setItemFont + * @see DKTools.Sprite.Selectable.prototype.setItemTextColor + * @see DKTools.Sprite.Selectable.prototype.setItemPaintOpacity + * @see DKTools.Sprite.Selectable.prototype.setItemAlign + * @see DKTools.Sprite.Selectable.prototype.start + * @see DKTools.Sprite.Selectable.prototype.activate * - * @returns {Boolean} Change occurred + * @returns {Number} Number of changed parameters */ -DKTools.Sprite.Selectable.prototype.setItemWidth = function(itemWidth, blockRefreshAll) { - if (this._itemWidth === itemWidth) { - return false; - } +DKTools.Sprite.Selectable.prototype.setAll = function(object, blockStart, activate) { + object = object || {}; + const block = true; + let changed = DKTools.Sprite.Button.prototype.setAll.call(this, object, block); - const lastWidth = this._itemWidth; - this.setupItemWidth(itemWidth); + if (this.setIndex(object.index, block)) { + changed++; + } - if (this._itemWidth === lastWidth) { - return false; + if (this.setMaxCols(object.maxCols, block)) { + changed++; } - if (!blockRefreshAll) { - this.refreshAll(); + if (this.setFixedHorizontal(object.fixedHorizontal, block)) { + changed++; } - return true; -}; + if (this.setCursorFixed(object.cursorFixed, block)) { + changed++; + } -/** - * Changes the height of the item - * Returns true if the change occurred - * - * @param {Function | Number} [itemHeight] - Height of the item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupItemHeight - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Boolean} Change occured - */ -DKTools.Sprite.Selectable.prototype.setItemHeight = function(itemHeight, blockRefreshAll) { - if (this._itemHeight === itemHeight) { - return false; + if (this.setCursorAll(object.cursorAll, block)) { + changed++; } - const lastHeight = this._itemHeight; - this.setupItemHeight(itemHeight); + changed += this.setSpacing(object.horizontalSpacing, object.verticalSpacing, block); - if (this._itemHeight === lastHeight) { - return false; + if (this.setTextPadding(object.textPadding, block)) { + changed++; } - if (!blockRefreshAll) { - this.refreshAll(); + if (this.setItems(object.items, block)) { + changed++; } - return true; -}; - -/** - * Changes the font of the item - * Returns true if the change occurred - * - * @param {Function | Object} [itemFont] - Font of the item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupItemFont - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Boolean} Change occured - */ -DKTools.Sprite.Selectable.prototype.setItemFont = function(itemFont, blockRefreshAll) { - if (this._itemFont === itemFont) { - return false; + if (this.setDrawItemHandler(object.drawItemHandler, block)) { + changed++; } - const lastFont = this._itemFont; - this.setupItemFont(itemFont); + if (this.setItemWidth(object.itemWidth, block)) { + changed++; + } - if (this._itemFont === lastFont) { - return false; + if (this.setItemHeight(object.itemHeight, block)) { + changed++; } - if (!blockRefreshAll) { - this.refreshAll(); + if (this.setItemRect(object.itemRect, block)) { + changed++; } - return true; -}; + if (this.setItemFont(object.itemFont, block)) { + changed++; + } -/** - * Changes the text color of the item - * Returns true if the change occurred - * - * @param {Function | String} [itemTextColor] - Text color of the item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.setupItemTextColor - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Boolean} Change occured - */ -DKTools.Sprite.Selectable.prototype.setItemTextColor = function(itemTextColor, blockRefreshAll) { - if (this._itemTextColor === itemTextColor) { - return false; + if (this.setItemTextColor(object.itemTextColor, block)) { + changed++; } - const lastTextColor = this._itemTextColor; - this.setupItemTextColor(itemTextColor); + if (this.setItemPaintOpacity(object.itemPaintOpacity, block)) { + changed++; + } - if (this._itemTextColor === lastTextColor) { - return false; + if (this.setItemAlign(object.itemAlign, block)) { + changed++; } - if (!blockRefreshAll) { - this.refreshAll(); + if (changed) { + if (!blockStart) { + this.start(); + } + + if (activate) { + this.activate(); + } } - return true; + return changed; }; /** - * Changes the item paint opacity + * Changes the index * Returns true if the change occurred * - * @param {Function | Number} [itemPaintOpacity] - Paint opacity of the item + * @param {Number} [index] - Index * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.setupItemPaintOpacity + * @see DKTools.Sprite.Selectable.prototype.setupIndex * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Boolean} Change occured + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.setItemPaintOpacity = function(itemPaintOpacity, blockRefreshAll) { - if (this._itemPaintOpacity === itemPaintOpacity) { +DKTools.Sprite.Selectable.prototype.setIndex = function(index, blockRefreshAll) { + if (this._index === index) { return false; } - const lastPaintOpacity = this._itemPaintOpacity; - this.setupItemPaintOpacity(itemPaintOpacity); + const lastIndex = this._index; + this.setupIndex(index); - if (this._itemPaintOpacity === lastPaintOpacity) { + if (this._index === lastIndex) { return false; } @@ -19598,26 +19763,26 @@ DKTools.Sprite.Selectable.prototype.setItemPaintOpacity = function(itemPaintOpac }; /** - * Changes the align of the item + * Changes the number of the columns * Returns true if the change occurred * - * @param {Function | String} [itemAlign] - Align of the item + * @param {Number} [cols] - Number of the columns * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.setupItemAlign + * @see DKTools.Sprite.Selectable.prototype.setupMaxCols * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Boolean} Change occured + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.setItemAlign = function(itemAlign, blockRefreshAll) { - if (this._itemAlign === itemAlign) { +DKTools.Sprite.Selectable.prototype.setMaxCols = function(cols, blockRefreshAll) { + if (this._maxCols === cols) { return false; } - const lastAlign = this._itemAlign; - this.setupItemAlign(itemAlign); + const lastCols = this._maxCols; + this.setupMaxCols(cols); - if (this._itemAlign === lastAlign) { + if (this._maxCols === lastCols) { return false; } @@ -19629,4133 +19794,4103 @@ DKTools.Sprite.Selectable.prototype.setItemAlign = function(itemAlign, blockRefr }; /** - * Changes the top row + * Changes the fixed horizontal position + * Returns true if the change occurred * - * @param {Number} row - Row - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {Boolean} [fixedHorizontal] + * @param {Boolean} [blockRefreshAll=false] Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.getMaxTopRow + * @see DKTools.Sprite.Selectable.prototype.setupFixedHorizontal * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.setTopRow = function(row, blockRefreshAll) { - const topRow = _.clamp(row, 0, this.getMaxTopRow()); +DKTools.Sprite.Selectable.prototype.setFixedHorizontal = function(fixedHorizontal, blockRefreshAll) { + if (this._fixedHorizontal === fixedHorizontal) { + return false; + } - if (this._topRow !== topRow) { - this._topRow = topRow; + const lastFixed = this._fixedHorizontal; + this.setupFixedHorizontal(fixedHorizontal); - if (!blockRefreshAll) { - this.refreshAll(); - } + if (this._fixedHorizontal === lastFixed) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); } + + return true; }; /** - * Changes the top column + * Changes the fixed cursor + * Returns true if the change occurred * - * @param {Number} col - Column - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {Boolean} [cursorFixed] - Fixed cursor + * @param {Boolean} [blockRefreshAll=false] Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.getMaxTopCol + * @see DKTools.Sprite.Selectable.prototype.setupCursorFixed * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.setTopCol = function(col, blockRefreshAll) { - const topCol = _.clamp(col, 0, this.getMaxTopCol()); +DKTools.Sprite.Selectable.prototype.setCursorFixed = function(cursorFixed, blockRefreshAll) { + if (this._cursorFixed === cursorFixed) { + return false; + } - if (this._topCol !== topCol) { - this._topCol = topCol; + const lastFixed = this._cursorFixed; + this.setupCursorFixed(cursorFixed); - if (!blockRefreshAll) { - this.refreshAll(); - } + if (this._cursorFixed === lastFixed) { + return false; } -}; - -/** - * Chagnes the bottom row - * - * @param {Number} row - Row - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows - * @see DKTools.Sprite.Selectable.prototype.setTopRow - */ -DKTools.Sprite.Selectable.prototype.setBottomRow = function(row, blockRefreshAll) { - this.setTopRow(row - (this.getMaxPageRows() - 1), blockRefreshAll); -}; -/** - * Chagnes the bottom column - * - * @param {Number} col - Column - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols - * @see DKTools.Sprite.Selectable.prototype.setTopCol - */ -DKTools.Sprite.Selectable.prototype.setBottomCol = function(col, blockRefreshAll) { - this.setTopCol(col - (this.getMaxPageCols() - 1), blockRefreshAll); -}; + if (!blockRefreshAll) { + this.refreshAll(); + } -/** - * Changes the handler of the symbol - * - * @param {String} symbol - Symbol - * @param {Function} [handler] - Handler - */ -DKTools.Sprite.Selectable.prototype.setHandler = function(symbol, handler) { - this._handlers[symbol] = handler; + return true; }; /** - * Changes the cursor rect + * Changes the cursor all * Returns true if the change occurred * - * @param {PIXI.Rectangle | Rectangle | Object | Number} object - The X coordinate or Rectangle - * @param {Number} [y] - The Y coordinate - * @param {Number} [width] - Width of the rect - * @param {Number} [height] - Height of the rect - * - * @param {Number} object.x - The X coordinate - * @param {Number} object.y - The Y coordinate - * @param {Number} object.width - Width of the rect - * @param {Number} object.height - Height of the rect + * @param {Boolean} [cursorAll] - Cursor all + * @param {Boolean} [blockRefreshAll=false] Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Cursor.prototype.setCursorRect - * - * @returns {Boolean} Change occured + * @see DKTools.Sprite.Selectable.prototype.setupCursorAll + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.setCursorRect = function(object, y, width, height) { - return this._cursorSprite.setCursorRect(object, y, width, height); -}; +DKTools.Sprite.Selectable.prototype.setCursorAll = function(cursorAll, blockRefreshAll) { + if (this._cursorAll === cursorAll) { + return false; + } -// get methods + const lastAll = this._cursorAll; + this.setupCursorAll(cursorAll); -/** - * Returns the rectangle of the item by index - * - * @param {Number} index - Index - * @returns {Rectangle} Rectangle of the item by index - */ -DKTools.Sprite.Selectable.prototype.getItemRectByIndex = function(index) { - return this._itemRect(index); -}; + if (this._cursorAll === lastAll) { + return false; + } -/** - * Returns the rectangle of the item - * - * @param {Object} item - Item - * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex - * - * @returns {Rectangle} Rectangle of the item - */ -DKTools.Sprite.Selectable.prototype.getItemRect = function(item) { - return this.getItemRectByIndex(this.getItemIndex(item)); -}; + if (!blockRefreshAll) { + this.refreshAll(); + } -/** - * Returns the rectangle of the current item (selected item) - * - * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex - * - * @returns {Rectangle} Rectangle of the current item (selected item) - */ -DKTools.Sprite.Selectable.prototype.getCurrentItemRect = function() { - return this.getItemRectByIndex(this._index); + return true; }; /** - * Returns the rectangle of text of the item by index + * Changes the horizontal spacing + * Returns true if the change occurred * - * @param {Number} index - Index + * @param {Number} [spacing] - Horizontal spacing + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex + * @see DKTools.Sprite.Selectable.prototype.setupHorizontalSpacing + * @see DKTools.Sprite.Selectable.prototype.refreshAll * - * @returns {Rectangle} Rectangle of text of the item by index + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.getItemRectForTextByIndex = function(index) { - const rect = this.getItemRectByIndex(index); - rect.x += this._textPadding; - rect.width -= this._textPadding * 2; - return rect; -}; +DKTools.Sprite.Selectable.prototype.setHorizontalSpacing = function(spacing, blockRefreshAll) { + if (this._horizontalSpacing === spacing) { + return false; + } -/** - * Returns the rectangle of text of the item - * - * @param {Object} item - Item - * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getItemRectForTextByIndex - * - * @returns {Rectangle} Rectangle of text of the item - */ -DKTools.Sprite.Selectable.prototype.getItemRectForText = function(item) { - return this.getItemRectForTextByIndex(this.getItemIndex(item)); -}; + const lastSpacing = this._horizontalSpacing; + this.setupHorizontalSpacing(spacing); -/** - * Returns the width of the item - * - * @returns {Number} Width of the item - */ -DKTools.Sprite.Selectable.prototype.getItemWidth = function() { - if (DKTools.Utils.isFunction(this._itemWidth)) { - return this._itemWidth(); + if (this._horizontalSpacing === lastSpacing) { + return false; } - return this._itemWidth; -}; - -/** - * Returns the height of the item - * - * @returns {Number} Height of the item - */ -DKTools.Sprite.Selectable.prototype.getItemHeight = function() { - if (DKTools.Utils.isFunction(this._itemHeight)) { - return this._itemHeight(); - } else if (DKTools.Utils.isString(this._itemHeight)) { - return Number(this._itemHeight) * this.getLineHeight(); + if (!blockRefreshAll) { + this.refreshAll(); } - return this._itemHeight; + return true; }; /** - * Returns the item by index + * Changes the vertical spacing + * Returns true if the change occurred * - * @param {Number} index - Index - * @returns {Object | null} Item or null - */ -DKTools.Sprite.Selectable.prototype.getItem = function(index) { - return this._items[index] || null; -}; - -/** - * Returns the font of the item by index + * @param {Number} [spacing] - Vertical spacing + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @param {Number} index - Index - * @returns {Object} Font of the item by index + * @see DKTools.Sprite.Selectable.prototype.setupVerticalSpacing + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.getItemFontByIndex = function(index) { - const item = this.getItem(index); - const itemFont = item.font || this._itemFont; +DKTools.Sprite.Selectable.prototype.setVerticalSpacing = function(spacing, blockRefreshAll) { + if (this._verticalSpacing === spacing) { + return false; + } + + const lastSpacing = this._verticalSpacing; + this.setupVerticalSpacing(spacing); - if (DKTools.Utils.isFunction(itemFont)) { - return itemFont(index); + if (this._verticalSpacing === lastSpacing) { + return false; } - return itemFont; + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Returns the font of the item - * - * @param {Object} item - Item + * Changes the horizontal and vertical spacings + * Returns the number of changed parameters * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getItemFontByIndex + * @param {Number} [horizontalSpacing] - Horizontal spacing + * @param {Number} [verticalSpacing] - Vertical spacing + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @returns {Object} Font of the item + * @see DKTools.Sprite.Selectable.prototype.setHorizontalSpacing + * @see DKTools.Sprite.Selectable.prototype.setVerticalSpacing + * + * @returns {Number} Number of changed parameters */ -DKTools.Sprite.Selectable.prototype.getItemFont = function(item) { - return this.getItemFontByIndex(this.getItemIndex(item)); -}; +DKTools.Sprite.Selectable.prototype.setSpacing = function(horizontalSpacing, verticalSpacing, blockRefreshAll) { + const block = true; + let changed = 0; -/** - * Returns the text color of the item by index - * - * @param {Number} index - Index - * @returns {String} Text color of the item by index - */ -DKTools.Sprite.Selectable.prototype.getItemTextColorByIndex = function(index) { - const item = this.getItem(index); - const itemTextColor = item.textColor || this._itemTextColor; + if (this.setHorizontalSpacing(horizontalSpacing, block)) { + changed++; + } - if (DKTools.Utils.isFunction(itemTextColor)) { - return itemTextColor(index); + if (this.setVerticalSpacing(verticalSpacing, block)) { + changed++; } - return itemTextColor; + if (changed && !blockRefreshAll) { + this.refreshAll(); + } + + return changed; }; /** - * Returns the text color of the item + * Changes the text padding + * Returns true if the change occurred * - * @param {Object} item - Item + * @param {Number} [textPadding] - Text padding + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getItemTextColorByIndex + * @see DKTools.Sprite.Selectable.prototype.setupTextPadding + * @see DKTools.Sprite.Selectable.prototype.refreshAll * - * @returns {String} Text color of the item + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.getItemTextColor = function(item) { - return this.getItemTextColorByIndex(this.getItemIndex(item)); -}; +DKTools.Sprite.Selectable.prototype.setTextPadding = function(textPadding, blockRefreshAll) { + if (this._textPadding === textPadding) { + return false; + } -/** - * Returns the paint opacity of the item by index - * - * @param {Number} index - Index - * @returns {Number} Paint opacity of the item by index - */ -DKTools.Sprite.Selectable.prototype.getItemPaintOpacityByIndex = function(index) { - const item = this.getItem(index); - const itemPaintOpacity = Number.isFinite(item.paintOpacity) ? item.paintOpacity : this._itemPaintOpacity; + const lastPadding = this._textPadding; + this.setupTextPadding(textPadding); - if (DKTools.Utils.isFunction(itemPaintOpacity)) { - return itemPaintOpacity(index); + if (this._textPadding === lastPadding) { + return false; } - return itemPaintOpacity; + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Returns the paint opacity of the item + * Changes the items + * Returns true if the change occurred * - * @param {Object} item - Item + * @param {Object[]} [items] - List of the items + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getItemPaintOpacityByIndex + * @see DKTools.Sprite.Selectable.prototype.setupItems + * @see DKTools.Sprite.Selectable.prototype.refreshAll * - * @returns {Number} Paint opacity of the item + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.getItemPaintOpacity = function(item) { - return this.getItemPaintOpacityByIndex(this.getItemIndex(item)); -}; +DKTools.Sprite.Selectable.prototype.setItems = function(items, blockRefreshAll) { + if (this._items == items) { + return false; + } -/** - * Returns the align of the item by index - * - * @param {Number} index - Index - * @returns {String} Align of the item by index - */ -DKTools.Sprite.Selectable.prototype.getItemAlignByIndex = function(index) { - const item = this.getItem(index); - const itemAlign = item.align || this._itemAlign; + this.setupItems(items); - if (DKTools.Utils.isFunction(itemAlign)) { - return itemAlign(index); + if (!blockRefreshAll) { + this.refreshAll(); } - return itemAlign; + return true; }; /** - * Returns the align of the item - * - * @param {Object} item - Item + * Changes the handler of draw of the item + * Returns true if the change occurred * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getItemAlignByIndex + * @param {Function} [handler] - Handler of draw of the item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @returns {String} Align of the item by index - */ -DKTools.Sprite.Selectable.prototype.getItemAlign = function(item) { - return this.getItemAlignByIndex(this.getItemIndex(item)); -}; - -/** - * Returns the previous index + * @see DKTools.Sprite.Selectable.prototype.setupDrawItemHandler + * @see DKTools.Sprite.Selectable.prototype.refreshAll * - * @param {Boolean} [wrap=false] - Cyclic selection - * @returns {Number} Previous index + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.getPrevIndex = function(wrap) { - if (this._index > 0) { - return this._index - 1; - } else if (wrap) { - return this.getMaxItems() - 1; +DKTools.Sprite.Selectable.prototype.setDrawItemHandler = function(handler, blockRefreshAll) { + if (this._drawItemHandler === handler) { + return false; } - return -1; -}; + const lastHandler = this._drawItemHandler; + this.setupDrawItemHandler(handler); -/** - * Returns the next index - * - * @param {Boolean} [wrap=false] - Cyclic selection - * @returns {Number} Next index - */ -DKTools.Sprite.Selectable.prototype.getNextIndex = function(wrap) { - if (this._index < this.getMaxItems() - 1) { - return this._index + 1; - } else if (wrap) { - return 0; + if (this._drawItemHandler === lastHandler) { + return false; } - return -1; + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Returns the previous item + * Changes the width of the item + * Returns true if the change occurred * - * @param {Boolean} [wrap=false] - Cyclic selection + * @param {Function | Number} [itemWidth] - Width of the item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.getPrevIndex - * @see DKTools.Sprite.Selectable.prototype.getItem + * @see DKTools.Sprite.Selectable.prototype.setupItemWidth + * @see DKTools.Sprite.Selectable.prototype.refreshAll * - * @returns {Object | null} Previous item or null + * @returns {Boolean} Change occurred */ -DKTools.Sprite.Selectable.prototype.getPrevItem = function(wrap) { - return this.getItem(this.getPrevIndex(wrap)); +DKTools.Sprite.Selectable.prototype.setItemWidth = function(itemWidth, blockRefreshAll) { + if (this._itemWidth === itemWidth) { + return false; + } + + const lastWidth = this._itemWidth; + this.setupItemWidth(itemWidth); + + if (this._itemWidth === lastWidth) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Returns the next item + * Changes the height of the item + * Returns true if the change occurred * - * @param {Boolean} [wrap=false] - Cyclic selection + * @param {Function | Number} [itemHeight] - Height of the item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.getNextIndex - * @see DKTools.Sprite.Selectable.prototype.getItem + * @see DKTools.Sprite.Selectable.prototype.setupItemHeight + * @see DKTools.Sprite.Selectable.prototype.refreshAll * - * @returns {Object | null} Next item or null + * @returns {Boolean} Change occured */ -DKTools.Sprite.Selectable.prototype.getNextItem = function(wrap) { - return this.getItem(this.getNextIndex(wrap)); -}; +DKTools.Sprite.Selectable.prototype.setItemHeight = function(itemHeight, blockRefreshAll) { + if (this._itemHeight === itemHeight) { + return false; + } -/** - * Returns the current item (selected item) - * - * @see DKTools.Sprite.Selectable.prototype.getItem - * - * @returns {Object | null} Current item (selected item) or null - */ -DKTools.Sprite.Selectable.prototype.getCurrentItem = function() { - return this.getItem(this._index); -}; + const lastHeight = this._itemHeight; + this.setupItemHeight(itemHeight); -/** - * Returns the index of the item - * - * @param {Object} item - item - * @returns {Number} Index of the item - */ -DKTools.Sprite.Selectable.prototype.getItemIndex = function(item) { - return _.indexOf(this._items, item); + if (this._itemHeight === lastHeight) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Returns the visible items + * Changes the font of the item + * Returns true if the change occurred * - * @returns {Object[]} Visible items + * @param {Function | Object} [itemFont] - Font of the item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.setupItemFont + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occured */ -DKTools.Sprite.Selectable.prototype.getVisibleItems = function() { - const maxPageItems = this.getMaxPageItems(); - const maxItems = this.getMaxItems(); - let index = this.getTopIndex(); - let items = []; +DKTools.Sprite.Selectable.prototype.setItemFont = function(itemFont, blockRefreshAll) { + if (this._itemFont === itemFont) { + return false; + } - for(let i = 0; i < maxPageItems && index < maxItems; i++, index++) { - items.push(this.getItem(index)); + const lastFont = this._itemFont; + this.setupItemFont(itemFont); + + if (this._itemFont === lastFont) { + return false; } - return items; + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Returns the name of the item by index + * Changes the text color of the item + * Returns true if the change occurred + * + * @param {Function | String} [itemTextColor] - Text color of the item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @param {Number} index - Index - * @returns {String | null} Name of the item by index or null + * @see DKTools.Sprite.Selectable.prototype.setupItemTextColor + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Boolean} Change occured */ -DKTools.Sprite.Selectable.prototype.getItemName = function(index) { - const item = this.getItem(index); +DKTools.Sprite.Selectable.prototype.setItemTextColor = function(itemTextColor, blockRefreshAll) { + if (this._itemTextColor === itemTextColor) { + return false; + } - if (item) { - const name = item.name; - if (DKTools.Utils.isFunction(name)) { - return name(index); - } - return name; + const lastTextColor = this._itemTextColor; + this.setupItemTextColor(itemTextColor); + + if (this._itemTextColor === lastTextColor) { + return false; } - return null; -}; + if (!blockRefreshAll) { + this.refreshAll(); + } -/** - * Returns the symbol of the item by index - * - * @param {Number} index - Index - * @returns {String | null} Symbol of the item by index or null - */ -DKTools.Sprite.Selectable.prototype.getItemSymbol = function(index) { - const item = this.getItem(index); - return item ? item.symbol : null; + return true; }; /** - * Returns the ext of the item by index + * Changes the item paint opacity + * Returns true if the change occurred * - * @param {Number} index - Index - * @returns {* | null} Ext of the item by index or null - */ -DKTools.Sprite.Selectable.prototype.getItemExt = function(index) { - var item = this.getItem(index); - return item ? item.ext : null; -}; - -/** - * Returns the name of the current item (selected item) + * @param {Function | Number} [itemPaintOpacity] - Paint opacity of the item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.getItemName + * @see DKTools.Sprite.Selectable.prototype.setupItemPaintOpacity + * @see DKTools.Sprite.Selectable.prototype.refreshAll * - * @returns {String | null} Name of the current item (selected item) or null + * @returns {Boolean} Change occured */ -DKTools.Sprite.Selectable.prototype.getCurrentItemName = function() { - return this.getItemName(this._index); -}; +DKTools.Sprite.Selectable.prototype.setItemPaintOpacity = function(itemPaintOpacity, blockRefreshAll) { + if (this._itemPaintOpacity === itemPaintOpacity) { + return false; + } -/** - * Returns the symbol of the current item (selected item) - * - * @see DKTools.Sprite.Selectable.prototype.getItemSymbol - * - * @returns {String | null} Symbol of the current item (selected item) or null - */ -DKTools.Sprite.Selectable.prototype.getCurrentItemSymbol = function() { - return this.getItemSymbol(this._index); + const lastPaintOpacity = this._itemPaintOpacity; + this.setupItemPaintOpacity(itemPaintOpacity); + + if (this._itemPaintOpacity === lastPaintOpacity) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Returns the ext of the current item (selected item) + * Changes the align of the item + * Returns true if the change occurred * - * @see DKTools.Sprite.Selectable.prototype.getItemExt + * @param {Function | String} [itemAlign] - Align of the item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @returns {* | null} Ext of the current item (selected item) or null - */ -DKTools.Sprite.Selectable.prototype.getCurrentItemExt = function() { - return this.getItemExt(this._index); -}; - -/** - * Returns the number of the items + * @see DKTools.Sprite.Selectable.prototype.setupItemAlign + * @see DKTools.Sprite.Selectable.prototype.refreshAll * - * @returns {Number} Number of the items + * @returns {Boolean} Change occured */ -DKTools.Sprite.Selectable.prototype.getMaxItems = function() { - return this._items.length; -}; +DKTools.Sprite.Selectable.prototype.setItemAlign = function(itemAlign, blockRefreshAll) { + if (this._itemAlign === itemAlign) { + return false; + } -/** - * Returns the maximum number of the rows - * - * @returns {Number} Maximum number of the rows - */ -DKTools.Sprite.Selectable.prototype.getMaxRows = function() { - if (this.isFixedHorizontal()) { - return 1; + const lastAlign = this._itemAlign; + this.setupItemAlign(itemAlign); + + if (this._itemAlign === lastAlign) { + return false; } - return Math.max(1, Math.ceil(this.getMaxItems() / this.getMaxCols())); + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Returns the maximum number of the columns - * - * @returns {Number} Maximum number of the columns + * Changes the top row + * + * @param {Number} row - Row + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.getMaxTopRow + * @see DKTools.Sprite.Selectable.prototype.refreshAll */ -DKTools.Sprite.Selectable.prototype.getMaxCols = function() { - return this._maxCols; +DKTools.Sprite.Selectable.prototype.setTopRow = function(row, blockRefreshAll) { + const topRow = _.clamp(row, 0, this.getMaxTopRow()); + + if (this._topRow !== topRow) { + this._topRow = topRow; + + if (!blockRefreshAll) { + this.refreshAll(); + } + } }; /** - * Returns the maximum top row + * Changes the top column * - * @see DKTools.Sprite.Selectable.prototype.getMaxRows - * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows + * @param {Number} col - Column + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @returns {Number} Maximum top row + * @see DKTools.Sprite.Selectable.prototype.getMaxTopCol + * @see DKTools.Sprite.Selectable.prototype.refreshAll */ -DKTools.Sprite.Selectable.prototype.getMaxTopRow = function() { - return Math.max(0, this.getMaxRows() - this.getMaxPageRows()); +DKTools.Sprite.Selectable.prototype.setTopCol = function(col, blockRefreshAll) { + const topCol = _.clamp(col, 0, this.getMaxTopCol()); + + if (this._topCol !== topCol) { + this._topCol = topCol; + + if (!blockRefreshAll) { + this.refreshAll(); + } + } }; /** - * Returns the maximum top column + * Chagnes the bottom row * - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols + * @param {Number} row - Row + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @returns {Number} Maximum top column + * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows + * @see DKTools.Sprite.Selectable.prototype.setTopRow */ -DKTools.Sprite.Selectable.prototype.getMaxTopCol = function() { - return Math.max(0, this.getMaxItems() - this.getMaxPageCols()); +DKTools.Sprite.Selectable.prototype.setBottomRow = function(row, blockRefreshAll) { + this.setTopRow(row - (this.getMaxPageRows() - 1), blockRefreshAll); }; /** - * Returns the maximum page rows + * Chagnes the bottom column * - * @see DKTools.Sprite.Selectable.prototype.getItemHeight - * @see DKTools.Sprite.Selectable.prototype.getMaxRows + * @param {Number} col - Column + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @returns {Number} Maximum page rows + * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols + * @see DKTools.Sprite.Selectable.prototype.setTopCol */ -DKTools.Sprite.Selectable.prototype.getMaxPageRows = function() { - const spacing = this._verticalSpacing; - const realHeight = this.realHeight; - const itemHeight = this.getItemHeight(); - const maxRows = this.getMaxRows(); - let rows = 0, height = 0; - - for(; rows < maxRows && height + itemHeight + spacing <= realHeight && height + itemHeight <= realHeight; rows++) { - height += itemHeight + spacing; - } +DKTools.Sprite.Selectable.prototype.setBottomCol = function(col, blockRefreshAll) { + this.setTopCol(col - (this.getMaxPageCols() - 1), blockRefreshAll); +}; - return rows; +/** + * Changes the handler of the symbol + * + * @param {String} symbol - Symbol + * @param {Function} [handler] - Handler + */ +DKTools.Sprite.Selectable.prototype.setHandler = function(symbol, handler) { + this._handlers[symbol] = handler; }; /** - * Returns the maximum page columns + * Changes the cursor rect + * Returns true if the change occurred * - * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * @param {PIXI.Rectangle | Rectangle | Object | Number} object - The X coordinate or Rectangle + * @param {Number} [y] - The Y coordinate + * @param {Number} [width] - Width of the rect + * @param {Number} [height] - Height of the rect + * + * @param {Number} object.x - The X coordinate + * @param {Number} object.y - The Y coordinate + * @param {Number} object.width - Width of the rect + * @param {Number} object.height - Height of the rect * - * @returns {Number} Maximum page columns + * @see DKTools.Sprite.Cursor.prototype.setCursorRect + * + * @returns {Boolean} Change occured */ -DKTools.Sprite.Selectable.prototype.getMaxPageCols = function() { - return this.getMaxCols(); +DKTools.Sprite.Selectable.prototype.setCursorRect = function(object, y, width, height) { + return this._cursorSprite.setCursorRect(object, y, width, height); }; +// get methods + /** - * Returns the maximum page items - * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols - * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows - * - * @returns {Number} Maximum page items + * Returns the rectangle of the item by index + * + * @param {Number} index - Index + * @returns {Rectangle} Rectangle of the item by index */ -DKTools.Sprite.Selectable.prototype.getMaxPageItems = function() { - if (this.isHorizontal()) { - return this.getMaxPageCols(); - } +DKTools.Sprite.Selectable.prototype.getItemRectByIndex = function(index) { + return this._itemRect(index); +}; - return this.getMaxPageRows() * this.getMaxPageCols(); +/** + * Returns the rectangle of the item + * + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex + * + * @returns {Rectangle} Rectangle of the item + */ +DKTools.Sprite.Selectable.prototype.getItemRect = function(item) { + return this.getItemRectByIndex(this.getItemIndex(item)); }; /** - * Returns the row by index + * Returns the rectangle of the current item (selected item) * - * @param {Number} index - Index - * - * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * - * @returns {Number} Row by index + * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex + * + * @returns {Rectangle} Rectangle of the current item (selected item) */ -DKTools.Sprite.Selectable.prototype.getRowByIndex = function(index) { - return Math.floor(index / this.getMaxCols()); +DKTools.Sprite.Selectable.prototype.getCurrentItemRect = function() { + return this.getItemRectByIndex(this._index); }; /** - * Returns the current row + * Returns the rectangle of text of the item by index * - * @see DKTools.Sprite.Selectable.prototype.getRowByIndex - * - * @returns {Number} Current row + * @param {Number} index - Index + * + * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex + * + * @returns {Rectangle} Rectangle of text of the item by index */ -DKTools.Sprite.Selectable.prototype.getCurrentRow = function() { - return this.getRowByIndex(this._index); +DKTools.Sprite.Selectable.prototype.getItemRectForTextByIndex = function(index) { + const rect = this.getItemRectByIndex(index); + rect.x += this._textPadding; + rect.width -= this._textPadding * 2; + return rect; }; /** - * Returns the row of the item + * Returns the rectangle of text of the item * * @param {Object} item - Item - * + * * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getRowByIndex - * - * @returns {Number} Row of the item + * @see DKTools.Sprite.Selectable.prototype.getItemRectForTextByIndex + * + * @returns {Rectangle} Rectangle of text of the item */ -DKTools.Sprite.Selectable.prototype.getItemRow = function(item) { - return this.getRowByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.getItemRectForText = function(item) { + return this.getItemRectForTextByIndex(this.getItemIndex(item)); }; /** - * Returns the list of the items by row + * Returns the width of the item * - * @param {Number} row - Row - * - * @see DKTools.Sprite.Selectable.prototype.getMaxRows - * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * @see DKTools.Sprite.Selectable.prototype.getRowByIndex - * @see DKTools.Sprite.Selectable.prototype.getItem - * - * @returns {Object[]} List of the items by row + * @returns {Number} Width of the item */ -DKTools.Sprite.Selectable.prototype.getRowItems = function(row) { - const items = []; +DKTools.Sprite.Selectable.prototype.getItemWidth = function() { + if (DKTools.Utils.isFunction(this._itemWidth)) { + return this._itemWidth(); + } - if (_.inRange(row, 0, this.getMaxRows())) { - const maxPageItems = this.getMaxPageItems(); - const maxItems = this.getMaxItems(); - let index = row * this.getMaxCols(); + return this._itemWidth; +}; - for(let i = 0; i < maxPageItems && index < maxItems && this.getRowByIndex(index) === row; i++, index++) { - items.push(this.getItem(index)); - } +/** + * Returns the height of the item + * + * @returns {Number} Height of the item + */ +DKTools.Sprite.Selectable.prototype.getItemHeight = function() { + if (DKTools.Utils.isFunction(this._itemHeight)) { + return this._itemHeight(); + } else if (DKTools.Utils.isString(this._itemHeight)) { + return Number(this._itemHeight) * this.getLineHeight(); } - return items; + return this._itemHeight; }; /** - * Returns the column by index + * Returns the item by index * * @param {Number} index - Index - * - * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * - * @returns {Number} Column by index + * @returns {Object | null} Item or null */ -DKTools.Sprite.Selectable.prototype.getColByIndex = function(index) { - return Math.floor(index % this.getMaxCols()); +DKTools.Sprite.Selectable.prototype.getItem = function(index) { + return this._items[index] || null; }; /** - * Returns the current column + * Returns the font of the item by index * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.getColByIndex - * - * @returns {Number} Current column + * @param {Number} index - Index + * @returns {Object} Font of the item by index */ -DKTools.Sprite.Selectable.prototype.getCurrentCol = function() { - if (this.isHorizontal()) { - return this._index; +DKTools.Sprite.Selectable.prototype.getItemFontByIndex = function(index) { + const item = this.getItem(index); + const itemFont = item.font || this._itemFont; + + if (DKTools.Utils.isFunction(itemFont)) { + return itemFont(index); } - return this.getColByIndex(this._index); + return itemFont; }; /** - * Returns the column of the item + * Returns the font of the item * * @param {Object} item - Item - * + * * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.getColByIndex - * - * @returns {Number} Column of the item + * @see DKTools.Sprite.Selectable.prototype.getItemFontByIndex + * + * @returns {Object} Font of the item */ -DKTools.Sprite.Selectable.prototype.getItemCol = function(item) { - return this.getColByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.getItemFont = function(item) { + return this.getItemFontByIndex(this.getItemIndex(item)); }; /** - * Returns the list of the items by column + * Returns the text color of the item by index * - * @param {Number} col - Column - * - * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.getColByIndex - * @see DKTools.Sprite.Selectable.prototype.getItem - * - * @returns {Object[]} List of the items by column + * @param {Number} index - Index + * @returns {String} Text color of the item by index */ -DKTools.Sprite.Selectable.prototype.getColItems = function(col) { - const items = []; - - if (_.inRange(col, 0, this.getMaxCols())) { - const maxItems = this.getMaxItems(); +DKTools.Sprite.Selectable.prototype.getItemTextColorByIndex = function(index) { + const item = this.getItem(index); + const itemTextColor = item.textColor || this._itemTextColor; - for(let index = 0; index < maxItems; index++) { - if (this.getColByIndex(index) === col) { - items.push(this.getItem(index)); - } - } + if (DKTools.Utils.isFunction(itemTextColor)) { + return itemTextColor(index); } - return items; + return itemTextColor; }; /** - * Returns the top index - * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.getTopRow - * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * - * @returns {Number} Top index + * Returns the text color of the item + * + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.getItemTextColorByIndex + * + * @returns {String} Text color of the item */ -DKTools.Sprite.Selectable.prototype.getTopIndex = function() { - if (this.isHorizontal()) { - return this.getTopCol(); - } - - return this.getTopRow() * this.getMaxCols(); +DKTools.Sprite.Selectable.prototype.getItemTextColor = function(item) { + return this.getItemTextColorByIndex(this.getItemIndex(item)); }; /** - * Returns the top row - * - * @returns {Number} Top row + * Returns the paint opacity of the item by index + * + * @param {Number} index - Index + * @returns {Number} Paint opacity of the item by index */ -DKTools.Sprite.Selectable.prototype.getTopRow = function() { - return this._topRow; +DKTools.Sprite.Selectable.prototype.getItemPaintOpacityByIndex = function(index) { + const item = this.getItem(index); + const itemPaintOpacity = Number.isFinite(item.paintOpacity) ? item.paintOpacity : this._itemPaintOpacity; + + if (DKTools.Utils.isFunction(itemPaintOpacity)) { + return itemPaintOpacity(index); + } + + return itemPaintOpacity; }; /** - * Returns the top column - * - * @returns {Number} Top column + * Returns the paint opacity of the item + * + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.getItemPaintOpacityByIndex + * + * @returns {Number} Paint opacity of the item */ -DKTools.Sprite.Selectable.prototype.getTopCol = function() { - return this._topCol; +DKTools.Sprite.Selectable.prototype.getItemPaintOpacity = function(item) { + return this.getItemPaintOpacityByIndex(this.getItemIndex(item)); }; /** - * Returns the bottom row - * - * @see DKTools.Sprite.Selectable.prototype.getTopRow - * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows - * - * @returns {Number} Bottom row + * Returns the align of the item by index + * + * @param {Number} index - Index + * @returns {String} Align of the item by index */ -DKTools.Sprite.Selectable.prototype.getBottomRow = function() { - return Math.max(0, this.getTopRow() + this.getMaxPageRows() - 1); +DKTools.Sprite.Selectable.prototype.getItemAlignByIndex = function(index) { + const item = this.getItem(index); + const itemAlign = item.align || this._itemAlign; + + if (DKTools.Utils.isFunction(itemAlign)) { + return itemAlign(index); + } + + return itemAlign; }; /** - * Returns the bottom column - * - * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols - * - * @returns {Number} Bottom column + * Returns the align of the item + * + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.getItemAlignByIndex + * + * @returns {String} Align of the item by index */ -DKTools.Sprite.Selectable.prototype.getBottomCol = function() { - return Math.max(0, this.getTopCol() + this.getMaxPageCols() - 1); +DKTools.Sprite.Selectable.prototype.getItemAlign = function(item) { + return this.getItemAlignByIndex(this.getItemIndex(item)); }; /** - * Returns the bottom index - * - * @see DKTools.Sprite.Selectable.prototype.getTopIndex - * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * - * @returns {Number} Bottom index + * Returns the previous index + * + * @param {Boolean} [wrap=false] - Cyclic selection + * @returns {Number} Previous index */ -DKTools.Sprite.Selectable.prototype.getBottomIndex = function() { - return Math.min(this.getTopIndex() + this.getMaxPageItems(), this.getMaxItems()) - 1; -}; - -// is methods +DKTools.Sprite.Selectable.prototype.getPrevIndex = function(wrap) { + if (this._index > 0) { + return this._index - 1; + } else if (wrap) { + return this.getMaxItems() - 1; + } + return -1; +}; /** - * Returns true if the cursor is fixed + * Returns the next index * - * @returns {Boolean} Cursor is fixed + * @param {Boolean} [wrap=false] - Cyclic selection + * @returns {Number} Next index */ -DKTools.Sprite.Selectable.prototype.isCursorFixed = function() { - return this._cursorFixed; +DKTools.Sprite.Selectable.prototype.getNextIndex = function(wrap) { + if (this._index < this.getMaxItems() - 1) { + return this._index + 1; + } else if (wrap) { + return 0; + } + + return -1; }; /** - * Returns true if the cursor all + * Returns the previous item * - * @returns {Boolean} Cursor all + * @param {Boolean} [wrap=false] - Cyclic selection + * + * @see DKTools.Sprite.Selectable.prototype.getPrevIndex + * @see DKTools.Sprite.Selectable.prototype.getItem + * + * @returns {Object | null} Previous item or null */ -DKTools.Sprite.Selectable.prototype.isCursorAll = function() { - return this._cursorAll; +DKTools.Sprite.Selectable.prototype.getPrevItem = function(wrap) { + return this.getItem(this.getPrevIndex(wrap)); }; /** - * Returns true if the fixed horizontal position of the items + * Returns the next item * - * @returns {Boolean} Fixed horizontal position of the items + * @param {Boolean} [wrap=false] - Cyclic selection + * + * @see DKTools.Sprite.Selectable.prototype.getNextIndex + * @see DKTools.Sprite.Selectable.prototype.getItem + * + * @returns {Object | null} Next item or null */ -DKTools.Sprite.Selectable.prototype.isFixedHorizontal = function() { - return this._fixedHorizontal; +DKTools.Sprite.Selectable.prototype.getNextItem = function(wrap) { + return this.getItem(this.getNextIndex(wrap)); }; /** - * Returns true if the position of the items is horizontal + * Returns the current item (selected item) * - * @see DKTools.Sprite.Selectable.prototype.isFixedHorizontal - * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows - * - * @returns {Boolean} Position of the items is horizontal + * @see DKTools.Sprite.Selectable.prototype.getItem + * + * @returns {Object | null} Current item (selected item) or null */ -DKTools.Sprite.Selectable.prototype.isHorizontal = function() { - return this.isFixedHorizontal() || this.getMaxPageRows() === 1; +DKTools.Sprite.Selectable.prototype.getCurrentItem = function() { + return this.getItem(this._index); }; /** - * Returns true if the position of the items is vertical + * Returns the index of the item * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * - * @returns {Boolean} Position of the items is vertical + * @param {Object} item - item + * @returns {Number} Index of the item */ -DKTools.Sprite.Selectable.prototype.isVertical = function() { - return !this.isHorizontal(); +DKTools.Sprite.Selectable.prototype.getItemIndex = function(item) { + return _.indexOf(this._items, item); }; /** - * Returns true if the cursor can move + * Returns the visible items * - * @see DKTools.Sprite.Selectable.prototype.isVisibleAndActive - * @see DKTools.Sprite.Selectable.prototype.isCursorFixed - * @see DKTools.Sprite.Selectable.prototype.isCursorAll - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * - * @returns {Boolean} Cursor can move + * @returns {Object[]} Visible items */ -DKTools.Sprite.Selectable.prototype.isCursorMovable = function() { - return this.isVisibleAndActive() && !this.isCursorFixed() && !this.isCursorAll() && this.getMaxItems() > 0; +DKTools.Sprite.Selectable.prototype.getVisibleItems = function() { + const maxPageItems = this.getMaxPageItems(); + const maxItems = this.getMaxItems(); + let index = this.getTopIndex(); + let items = []; + + for(let i = 0; i < maxPageItems && index < maxItems; i++, index++) { + items.push(this.getItem(index)); + } + + return items; }; /** - * Returns true if the Ok is enabled - * - * @returns {Boolean} Ok is enabled + * Returns the name of the item by index + * + * @param {Number} index - Index + * @returns {String | null} Name of the item by index or null */ -DKTools.Sprite.Selectable.prototype.isOkEnabled = function() { - return true; +DKTools.Sprite.Selectable.prototype.getItemName = function(index) { + const item = this.getItem(index); + + if (item) { + const name = item.name; + if (DKTools.Utils.isFunction(name)) { + return name(index); + } + return name; + } + + return null; }; /** - * Returns true if the cancel is enabled - * - * @see DKTools.Sprite.Selectable.prototype.isHandled - * - * @returns {Boolean} Cancel is enabled + * Returns the symbol of the item by index + * + * @param {Number} index - Index + * @returns {String | null} Symbol of the item by index or null */ -DKTools.Sprite.Selectable.prototype.isCancelEnabled = function() { - return this.isHandled('cancel'); +DKTools.Sprite.Selectable.prototype.getItemSymbol = function(index) { + const item = this.getItem(index); + return item ? item.symbol : null; }; /** - * Returns true if the Ok is triggered - * - * @returns {Boolean} Ok is triggered + * Returns the ext of the item by index + * + * @param {Number} index - Index + * @returns {* | null} Ext of the item by index or null */ -DKTools.Sprite.Selectable.prototype.isOkTriggered = function() { - return Input.isRepeated('ok'); +DKTools.Sprite.Selectable.prototype.getItemExt = function(index) { + var item = this.getItem(index); + return item ? item.ext : null; }; /** - * Returns true if the cancel is triggered - * - * @returns {Boolean} Cancel is triggered + * Returns the name of the current item (selected item) + * + * @see DKTools.Sprite.Selectable.prototype.getItemName + * + * @returns {String | null} Name of the current item (selected item) or null */ -DKTools.Sprite.Selectable.prototype.isCancelTriggered = function() { - return Input.isRepeated('cancel') || TouchInput.isCancelled(); +DKTools.Sprite.Selectable.prototype.getCurrentItemName = function() { + return this.getItemName(this._index); }; /** - * Returns true if the cursor is visible + * Returns the symbol of the current item (selected item) * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.getBottomCol - * @see DKTools.Sprite.Selectable.prototype.getCurrentRow - * @see DKTools.Sprite.Selectable.prototype.getTopRow - * @see DKTools.Sprite.Selectable.prototype.getBottomRow - * - * @returns {Boolean} Cursor is visible + * @see DKTools.Sprite.Selectable.prototype.getItemSymbol + * + * @returns {String | null} Symbol of the current item (selected item) or null */ -DKTools.Sprite.Selectable.prototype.isCursorVisible = function() { - if (!this._cursorSprite.isVisible()) { - return false; - } - - if (this.isHorizontal()) { - const col = this.getCurrentCol(); - - return col >= this.getTopCol() && col <= this.getBottomCol(); - } - - const row = this.getCurrentRow(); - - return row >= this.getTopRow() && row <= this.getBottomRow(); +DKTools.Sprite.Selectable.prototype.getCurrentItemSymbol = function() { + return this.getItemSymbol(this._index); }; /** - * Returns true if the item by index is enabled + * Returns the ext of the current item (selected item) * - * @param {Number} index - Index - * - * @see DKTools.Sprite.Selectable.prototype.getItem - * - * @returns {Boolean} Item by index is enabled + * @see DKTools.Sprite.Selectable.prototype.getItemExt + * + * @returns {* | null} Ext of the current item (selected item) or null */ -DKTools.Sprite.Selectable.prototype.isItemEnabled = function(index) { - const item = this.getItem(index); - - if (item) { - const enabled = item.enabled; - - if (DKTools.Utils.isFunction(enabled)) { - return enabled(index); - } - - return enabled; - } - - return false; +DKTools.Sprite.Selectable.prototype.getCurrentItemExt = function() { + return this.getItemExt(this._index); }; /** - * Returns true if the current item (selected item) is enabled - * - * @see DKTools.Sprite.Selectable.prototype.isItemEnabled + * Returns the number of the items * - * @returns {Boolean} Current item (selected item) is enabled + * @returns {Number} Number of the items */ -DKTools.Sprite.Selectable.prototype.isCurrentItemEnabled = function() { - return this.isItemEnabled(this._index); +DKTools.Sprite.Selectable.prototype.getMaxItems = function() { + return this._items.length; }; /** - * Returns true if the symbol is handling + * Returns the maximum number of the rows * - * @param {String} symbol - Symbol - * @returns {Boolean} Symbol is handling + * @returns {Number} Maximum number of the rows */ -DKTools.Sprite.Selectable.prototype.isHandled = function(symbol) { - return !!this._handlers[symbol]; +DKTools.Sprite.Selectable.prototype.getMaxRows = function() { + if (this.isFixedHorizontal()) { + return 1; + } + + return Math.max(1, Math.ceil(this.getMaxItems() / this.getMaxCols())); }; /** - * Returns true if the item by index is visible + * Returns the maximum number of the columns * - * @param {Number} index - Index + * @returns {Number} Maximum number of the columns + */ +DKTools.Sprite.Selectable.prototype.getMaxCols = function() { + return this._maxCols; +}; + +/** + * Returns the maximum top row * - * @see DKTools.Sprite.Selectable.prototype.getTopIndex - * @see DKTools.Sprite.Selectable.prototype.getBottomIndex + * @see DKTools.Sprite.Selectable.prototype.getMaxRows + * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows * - * @returns {Boolean} Item by index is visible + * @returns {Number} Maximum top row */ -DKTools.Sprite.Selectable.prototype.isItemVisibleByIndex = function(index) { - return _.inRange(index, this.getTopIndex(), this.getBottomIndex() + 1); +DKTools.Sprite.Selectable.prototype.getMaxTopRow = function() { + return Math.max(0, this.getMaxRows() - this.getMaxPageRows()); }; /** - * Returns true if the item is visible - * - * @param {Object} item - Item - * - * @see DKTools.Sprite.Selectable.prototype.isItemVisibleByIndex - * - * @returns {Boolean} Item is visible + * Returns the maximum top column + * + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols + * + * @returns {Number} Maximum top column */ -DKTools.Sprite.Selectable.prototype.isItemVisible = function(item) { - return this.isItemVisibleByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.getMaxTopCol = function() { + return Math.max(0, this.getMaxItems() - this.getMaxPageCols()); }; -// has methods - /** - * Returns true if the item by index exists - * - * @param {Number} index - Index - * - * @see DKTools.Sprite.Selectable.prototype.getItem - * - * @returns {Boolean} Item by index exists + * Returns the maximum page rows + * + * @see DKTools.Sprite.Selectable.prototype.getItemHeight + * @see DKTools.Sprite.Selectable.prototype.getMaxRows + * + * @returns {Number} Maximum page rows */ -DKTools.Sprite.Selectable.prototype.hasItemByIndex = function(index) { - return !!this.getItem(index); +DKTools.Sprite.Selectable.prototype.getMaxPageRows = function() { + const spacing = this._verticalSpacing; + const realHeight = this.realHeight; + const itemHeight = this.getItemHeight(); + const maxRows = this.getMaxRows(); + let rows = 0, height = 0; + + for(; rows < maxRows && height + itemHeight + spacing <= realHeight && height + itemHeight <= realHeight; rows++) { + height += itemHeight + spacing; + } + + return rows; }; /** - * Returns true if the item exists - * - * @param {Object} item - item - * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.hasItemByIndex - * - * @returns {Boolean} Item exists + * Returns the maximum page columns + * + * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * + * @returns {Number} Maximum page columns */ -DKTools.Sprite.Selectable.prototype.hasItem = function(item) { - return this.hasItemByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.getMaxPageCols = function() { + return this.getMaxCols(); }; /** - * Returns true if the items exists - * - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * - * @returns {Boolean} Items exists + * Returns the maximum page items + * + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols + * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows + * + * @returns {Number} Maximum page items */ -DKTools.Sprite.Selectable.prototype.hasItems = function() { - return this.getMaxItems() > 0; +DKTools.Sprite.Selectable.prototype.getMaxPageItems = function() { + if (this.isHorizontal()) { + return this.getMaxPageCols(); + } + + return this.getMaxPageRows() * this.getMaxPageCols(); }; /** - * Returns true if the handler of draw of the item exists + * Returns the row by index * - * @returns {Boolean} Handler of draw of the item exists + * @param {Number} index - Index + * + * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * + * @returns {Number} Row by index */ -DKTools.Sprite.Selectable.prototype.hasDrawItemHandler = function() { - return !!this._drawItemHandler; +DKTools.Sprite.Selectable.prototype.getRowByIndex = function(index) { + return Math.floor(index / this.getMaxCols()); }; -// active methods - /** - * Activates the object + * Returns the current row * - * @override + * @see DKTools.Sprite.Selectable.prototype.getRowByIndex + * + * @returns {Number} Current row */ -DKTools.Sprite.Selectable.prototype.activate = function() { - DKTools.Sprite.Button.prototype.activate.call(this); - this.reselect(); +DKTools.Sprite.Selectable.prototype.getCurrentRow = function() { + return this.getRowByIndex(this._index); }; /** - * Deactivates the object - * - * @override - * @param {Boolean} [deselect=false] - Deselects the current item (selected item) + * Returns the row of the item * - * @see DKTools.Sprite.Selectable.prototype.deselect + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.getRowByIndex + * + * @returns {Number} Row of the item */ -DKTools.Sprite.Selectable.prototype.deactivate = function(deselect) { - DKTools.Sprite.Button.prototype.deactivate.call(this); - - if (deselect) { - this.deselect(); - } +DKTools.Sprite.Selectable.prototype.getItemRow = function(item) { + return this.getRowByIndex(this.getItemIndex(item)); }; -// cursor methods - /** - * Moves the cursor to down + * Returns the list of the items by row * - * @param {Boolean} [wrap=false] - Cyclic selection + * @param {Number} row - Row * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getMaxRows + * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems * @see DKTools.Sprite.Selectable.prototype.getMaxItems * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * @see DKTools.Sprite.Selectable.prototype.getMaxRows - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.Selectable.prototype.getRowByIndex + * @see DKTools.Sprite.Selectable.prototype.getItem + * + * @returns {Object[]} List of the items by row */ -DKTools.Sprite.Selectable.prototype.cursorDown = function(wrap) { - if (this.isHorizontal()) { - return; - } +DKTools.Sprite.Selectable.prototype.getRowItems = function(row) { + const items = []; - const index = this._index; - const maxItems = this.getMaxItems(); - const maxCols = this.getMaxCols(); + if (_.inRange(row, 0, this.getMaxRows())) { + const maxPageItems = this.getMaxPageItems(); + const maxItems = this.getMaxItems(); + let index = row * this.getMaxCols(); - if (index < maxItems - maxCols || (wrap && maxItems === this.getMaxRows() * maxCols)) { - this.selectItemByIndex((index + maxCols) % maxItems); + for(let i = 0; i < maxPageItems && index < maxItems && this.getRowByIndex(index) === row; i++, index++) { + items.push(this.getItem(index)); + } } + + return items; }; /** - * Moves the cursor to up + * Returns the column by index * - * @param {Boolean} [wrap=false] - Cyclic selection + * @param {Number} index - Index * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.getMaxItems * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * @see DKTools.Sprite.Selectable.prototype.getMaxRows - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * + * @returns {Number} Column by index + */ +DKTools.Sprite.Selectable.prototype.getColByIndex = function(index) { + return Math.floor(index % this.getMaxCols()); +}; + +/** + * Returns the current column + * + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getColByIndex + * + * @returns {Number} Current column */ -DKTools.Sprite.Selectable.prototype.cursorUp = function(wrap) { +DKTools.Sprite.Selectable.prototype.getCurrentCol = function() { if (this.isHorizontal()) { - return; + return this._index; } - const index = this._index; - const maxItems = this.getMaxItems(); - const maxCols = this.getMaxCols(); - - if (index >= maxCols || (wrap && maxItems === this.getMaxRows() * maxCols)) { - this.selectItemByIndex((index - maxCols + maxItems) % maxItems); - } + return this.getColByIndex(this._index); }; /** - * Moves the cursor to right + * Returns the column of the item * - * @param {Boolean} [wrap=false] - Cyclic selection + * @param {Object} item - Item * - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.selectNext - * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.getColByIndex + * + * @returns {Number} Column of the item */ -DKTools.Sprite.Selectable.prototype.cursorRight = function(wrap) { - const maxItems = this.getMaxItems(); - - if (maxItems < 2) { - return; - } - - if (this.isVertical()) { - const index = this._index; - const maxCols = this.getMaxCols(); - - if (maxCols >= 2 && (index < maxItems - 1 || wrap)) { - this.selectItemByIndex((index + 1) % maxItems); - } - } else { - this.selectNext(wrap); - } +DKTools.Sprite.Selectable.prototype.getItemCol = function(item) { + return this.getColByIndex(this.getItemIndex(item)); }; /** - * Moves the cursor to left + * Returns the list of the items by column * - * @param {Boolean} [wrap=false] - Cyclic selection + * @param {Number} col - Column * - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.selectPrev * @see DKTools.Sprite.Selectable.prototype.getMaxCols - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.getColByIndex + * @see DKTools.Sprite.Selectable.prototype.getItem + * + * @returns {Object[]} List of the items by column */ -DKTools.Sprite.Selectable.prototype.cursorLeft = function(wrap) { - const maxItems = this.getMaxItems(); - - if (maxItems < 2) { - return; - } +DKTools.Sprite.Selectable.prototype.getColItems = function(col) { + const items = []; - if (this.isVertical()) { - const index = this._index; - const maxCols = this.getMaxCols(); + if (_.inRange(col, 0, this.getMaxCols())) { + const maxItems = this.getMaxItems(); - if (maxCols >= 2 && (index > 0 || wrap)) { - this.selectItemByIndex((index - 1 + maxItems) % maxItems); + for(let index = 0; index < maxItems; index++) { + if (this.getColByIndex(index) === col) { + items.push(this.getItem(index)); + } } - } else { - this.selectPrev(wrap); } + + return items; }; /** - * Moves the cursor to lower page + * Returns the top index * * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.getTopRow * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows - * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols - * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.getMaxRows - * @see DKTools.Sprite.Selectable.prototype.setTopRow - * @see DKTools.Sprite.Selectable.prototype.setTopCol - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.Selectable.prototype.getTopRow + * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * + * @returns {Number} Top index */ -DKTools.Sprite.Selectable.prototype.cursorPagedown = function() { +DKTools.Sprite.Selectable.prototype.getTopIndex = function() { if (this.isHorizontal()) { - const topCol = this.getTopCol(); - const maxPageCols = this.getMaxPageCols(); - const maxItems = this.getMaxItems(); - - if (topCol + maxPageCols < maxItems) { - this.setTopCol(topCol + maxPageCols); - this.selectItemByIndex(Math.min(this._index + this.getMaxPageItems(), maxItems - 1)); - } - } else { - const topRow = this.getTopRow(); - const maxPageRows = this.getMaxPageRows(); - - if (topRow + maxPageRows < this.getMaxRows()) { - this.setTopRow(topRow + maxPageRows); - this.selectItemByIndex(Math.min(this._index + this.getMaxPageItems(), this.getMaxItems() - 1)); - } + return this.getTopCol(); } + + return this.getTopRow() * this.getMaxCols(); }; /** - * Moves the cursor to upper page + * Returns the top row * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.getTopRow - * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows - * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols - * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems - * @see DKTools.Sprite.Selectable.prototype.setTopRow - * @see DKTools.Sprite.Selectable.prototype.setTopCol - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @returns {Number} Top row */ -DKTools.Sprite.Selectable.prototype.cursorPageup = function() { - if (this.isHorizontal()) { - const topCol = this.getTopCol(); - - if (topCol > 0) { - this.setTopCol(topCol - this.getMaxPageCols()); - this.selectItemByIndex(Math.max(0, this._index - this.getMaxPageItems())); - } - } else { - const topRow = this.getTopRow(); - - if (topRow > 0) { - this.setTopRow(topRow - this.getMaxPageRows()); - this.selectItemByIndex(Math.max(0, this._index - this.getMaxPageItems())); - } - } +DKTools.Sprite.Selectable.prototype.getTopRow = function() { + return this._topRow; }; /** - * Shows the cursor + * Returns the top column + * + * @returns {Number} Top column */ -DKTools.Sprite.Selectable.prototype.showCursor = function() { - this._cursorSprite.show(true); +DKTools.Sprite.Selectable.prototype.getTopCol = function() { + return this._topCol; }; /** - * Hides the cursor + * Returns the bottom row + * + * @see DKTools.Sprite.Selectable.prototype.getTopRow + * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows + * + * @returns {Number} Bottom row */ -DKTools.Sprite.Selectable.prototype.hideCursor = function() { - this._cursorSprite.hide(); +DKTools.Sprite.Selectable.prototype.getBottomRow = function() { + return Math.max(0, this.getTopRow() + this.getMaxPageRows() - 1); }; -// touch methods - /** - * @private - * @param {Boolean} triggered + * Returns the bottom column * - * @see DKTools.Sprite.Selectable.prototype.hitTest - * @see DKTools.Sprite.Selectable.prototype.isOkEnabled - * @see DKTools.Sprite.Selectable.prototype.isCursorMovable - * @see DKTools.Sprite.Selectable.prototype.processOk - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex - * @see DKTools.Sprite.Selectable.prototype.playCursorSound + * @see DKTools.Sprite.Selectable.prototype.getTopCol + * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols + * + * @returns {Number} Bottom column */ -DKTools.Sprite.Selectable.prototype._onTouch = function(triggered) { - const lastIndex = this._index; - const x = TouchInput.x; - const y = TouchInput.y; - const hitIndex = this.hitTest(x, y); - - if (hitIndex >= 0) { - if (this._index === hitIndex) { - if (triggered && this.isOkEnabled()) { - this.processOk(); - } - } else if (this.isCursorMovable()) { - this.selectItemByIndex(hitIndex); - } - } - - if (this._index !== lastIndex) { - this.playCursorSound(); - } +DKTools.Sprite.Selectable.prototype.getBottomCol = function() { + return Math.max(0, this.getTopCol() + this.getMaxPageCols() - 1); }; /** - * @param {Number} x - The X coordinate - * @param {Number} y - The Y coordinate + * Returns the bottom index * - * @see DKTools.Sprite.Selectable.prototype.isOutside - * @see DKTools.Sprite.Selectable.prototype.canvasToLocalX - * @see DKTools.Sprite.Selectable.prototype.canvasToLocalY + * @see DKTools.Sprite.Selectable.prototype.getTopIndex * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.getTopIndex - * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex * - * @returns {Number} + * @returns {Number} Bottom index */ -DKTools.Sprite.Selectable.prototype.hitTest = function(x, y) { - if (this.isOutside(x, y)) { - return -1; - } +DKTools.Sprite.Selectable.prototype.getBottomIndex = function() { + return Math.min(this.getTopIndex() + this.getMaxPageItems(), this.getMaxItems()) - 1; +}; - const scale = this.scale; - const localX = this.canvasToLocalX(x); - const localY = this.canvasToLocalY(y); - const maxPageItems = this.getMaxPageItems(); - const maxItems = this.getMaxItems(); - let index = this.getTopIndex(); +// is methods - for (let i = 0; i < maxPageItems && index < maxItems; i++ , index++) { - const rect = this.getItemRectByIndex(index); - rect.x *= scale.x; - rect.y *= scale.y; - rect.width *= scale.x; - rect.height *= scale.y; +/** + * Returns true if the cursor is fixed + * + * @returns {Boolean} Cursor is fixed + */ +DKTools.Sprite.Selectable.prototype.isCursorFixed = function() { + return this._cursorFixed; +}; - if (rect.contains(localX, localY)) { - return index; - } - } +/** + * Returns true if the cursor all + * + * @returns {Boolean} Cursor all + */ +DKTools.Sprite.Selectable.prototype.isCursorAll = function() { + return this._cursorAll; +}; - return -1; +/** + * Returns true if the fixed horizontal position of the items + * + * @returns {Boolean} Fixed horizontal position of the items + */ +DKTools.Sprite.Selectable.prototype.isFixedHorizontal = function() { + return this._fixedHorizontal; }; -// draw methods - /** - * Draws all + * Returns true if the position of the items is horizontal * - * @override + * @see DKTools.Sprite.Selectable.prototype.isFixedHorizontal + * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows + * + * @returns {Boolean} Position of the items is horizontal */ -DKTools.Sprite.Selectable.prototype.drawAll = function() { - DKTools.Sprite.Button.prototype.drawAll.call(this); - this.drawAllItems(); +DKTools.Sprite.Selectable.prototype.isHorizontal = function() { + return this.isFixedHorizontal() || this.getMaxPageRows() === 1; }; /** - * Draws all items + * Returns true if the position of the items is vertical + * + * @see DKTools.Sprite.Selectable.prototype.isHorizontal * - * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.getTopIndex - * @see DKTools.Sprite.Selectable.prototype.drawItemByIndex + * @returns {Boolean} Position of the items is vertical */ -DKTools.Sprite.Selectable.prototype.drawAllItems = function() { - const maxPageItems = this.getMaxPageItems(); - const maxItems = this.getMaxItems(); - let index = this.getTopIndex(); - - for(let i = 0; i < maxPageItems && index < maxItems; i++, index++) { - this.drawItemByIndex(index); - } +DKTools.Sprite.Selectable.prototype.isVertical = function() { + return !this.isHorizontal(); }; /** - * Draws the item by index + * Returns true if the cursor can move * - * @param {Number} index - Index + * @see DKTools.Sprite.Selectable.prototype.isVisibleAndActive + * @see DKTools.Sprite.Selectable.prototype.isCursorFixed + * @see DKTools.Sprite.Selectable.prototype.isCursorAll + * @see DKTools.Sprite.Selectable.prototype.getMaxItems * - * @see DKTools.Sprite.Selectable.prototype.hasDrawItemHandler + * @returns {Boolean} Cursor can move */ -DKTools.Sprite.Selectable.prototype.drawItemByIndex = function(index) { - if (this.hasDrawItemHandler()) { - this._drawItemHandler(index); - } +DKTools.Sprite.Selectable.prototype.isCursorMovable = function() { + return this.isVisibleAndActive() && !this.isCursorFixed() && !this.isCursorAll() && this.getMaxItems() > 0; }; /** - * Draws the item - * - * @param {Object} item - Item + * Returns true if the Ok is enabled * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.drawItemByIndex + * @returns {Boolean} Ok is enabled */ -DKTools.Sprite.Selectable.prototype.drawItem = function(item) { - this.drawItemByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.isOkEnabled = function() { + return true; }; /** - * Clears the item by index - * - * @param {Number} index - Index - * - * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex - * @see DKTools.Sprite.Selectable.prototype.clearRect + * Returns true if the cancel is enabled + * + * @see DKTools.Sprite.Selectable.prototype.isHandled + * + * @returns {Boolean} Cancel is enabled */ -DKTools.Sprite.Selectable.prototype.clearItemByIndex = function(index) { - this.clearRect(this.getItemRectByIndex(index)); +DKTools.Sprite.Selectable.prototype.isCancelEnabled = function() { + return this.isHandled('cancel'); }; /** - * Clears the item - * - * @param {Object} item - Item - * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.clearItemByIndex + * Returns true if the Ok is triggered + * + * @returns {Boolean} Ok is triggered */ -DKTools.Sprite.Selectable.prototype.clearItem = function(item) { - this.clearItemByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.isOkTriggered = function() { + return Input.isRepeated('ok'); }; /** - * Redraws the item by index - * - * @param {Number} index - Index - * - * @see DKTools.Sprite.Selectable.prototype.isItemVisibleByIndex - * @see DKTools.Sprite.Selectable.prototype.clearItemByIndex - * @see DKTools.Sprite.Selectable.prototype.drawItemByIndex + * Returns true if the cancel is triggered + * + * @returns {Boolean} Cancel is triggered */ -DKTools.Sprite.Selectable.prototype.redrawItemByIndex = function(index) { - if (index >= 0 && this.isItemVisibleByIndex(index)) { - this.clearItemByIndex(index); - this.drawItemByIndex(index); - } +DKTools.Sprite.Selectable.prototype.isCancelTriggered = function() { + return Input.isRepeated('cancel') || TouchInput.isCancelled(); }; /** - * Redraws the item - * - * @param {Object} item - Item + * Returns true if the cursor is visible * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.redrawItemByIndex + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getTopCol + * @see DKTools.Sprite.Selectable.prototype.getBottomCol + * @see DKTools.Sprite.Selectable.prototype.getCurrentRow + * @see DKTools.Sprite.Selectable.prototype.getTopRow + * @see DKTools.Sprite.Selectable.prototype.getBottomRow + * + * @returns {Boolean} Cursor is visible */ -DKTools.Sprite.Selectable.prototype.redrawItem = function(item) { - this.redrawItemByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.isCursorVisible = function() { + if (!this._cursorSprite.isVisible()) { + return false; + } + + if (this.isHorizontal()) { + const col = this.getCurrentCol(); + + return col >= this.getTopCol() && col <= this.getBottomCol(); + } + + const row = this.getCurrentRow(); + + return row >= this.getTopRow() && row <= this.getBottomRow(); }; /** - * Redraws the current item (selected item) + * Returns true if the item by index is enabled * - * @see DKTools.Sprite.Selectable.prototype.redrawItemByIndex + * @param {Number} index - Index + * + * @see DKTools.Sprite.Selectable.prototype.getItem + * + * @returns {Boolean} Item by index is enabled */ -DKTools.Sprite.Selectable.prototype.redrawCurrentItem = function() { - this.redrawItemByIndex(this._index); -}; +DKTools.Sprite.Selectable.prototype.isItemEnabled = function(index) { + const item = this.getItem(index); -// sound methods + if (item) { + const enabled = item.enabled; + + if (DKTools.Utils.isFunction(enabled)) { + return enabled(index); + } + + return enabled; + } + + return false; +}; /** - * Plays "ok" sound + * Returns true if the current item (selected item) is enabled * - * @see SoundManager.playOk + * @see DKTools.Sprite.Selectable.prototype.isItemEnabled + * + * @returns {Boolean} Current item (selected item) is enabled */ -DKTools.Sprite.Selectable.prototype.playOkSound = function() { - SoundManager.playOk(); +DKTools.Sprite.Selectable.prototype.isCurrentItemEnabled = function() { + return this.isItemEnabled(this._index); }; /** - * Plays "cancel" sound + * Returns true if the symbol is handling * - * @see SoundManager.playCancel + * @param {String} symbol - Symbol + * @returns {Boolean} Symbol is handling */ -DKTools.Sprite.Selectable.prototype.playCancelSound = function() { - SoundManager.playCancel(); +DKTools.Sprite.Selectable.prototype.isHandled = function(symbol) { + return !!this._handlers[symbol]; }; /** - * Plays "cursor" sound + * Returns true if the item by index is visible * - * @see SoundManager.playCursor + * @param {Number} index - Index + * + * @see DKTools.Sprite.Selectable.prototype.getTopIndex + * @see DKTools.Sprite.Selectable.prototype.getBottomIndex + * + * @returns {Boolean} Item by index is visible */ -DKTools.Sprite.Selectable.prototype.playCursorSound = function() { - SoundManager.playCursor(); +DKTools.Sprite.Selectable.prototype.isItemVisibleByIndex = function(index) { + return _.inRange(index, this.getTopIndex(), this.getBottomIndex() + 1); }; /** - * Plays "buzzer" sound + * Returns true if the item is visible * - * @see SoundManager.playBuzzer + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.isItemVisibleByIndex + * + * @returns {Boolean} Item is visible */ -DKTools.Sprite.Selectable.prototype.playBuzzerSound = function() { - SoundManager.playBuzzer(); +DKTools.Sprite.Selectable.prototype.isItemVisible = function(item) { + return this.isItemVisibleByIndex(this.getItemIndex(item)); }; -// call methods +// has methods /** - * Calls the handler of the symbol + * Returns true if the item by index exists * - * @param {String} symbol - Symbol - * - * @see DKTools.Sprite.Selectable.prototype.isHandled + * @param {Number} index - Index + * + * @see DKTools.Sprite.Selectable.prototype.getItem + * + * @returns {Boolean} Item by index exists */ -DKTools.Sprite.Selectable.prototype.callHandler = function(symbol) { - if (this.isHandled(symbol)) { - this._handlers[symbol](this._index); - } +DKTools.Sprite.Selectable.prototype.hasItemByIndex = function(index) { + return !!this.getItem(index); }; /** - * Calls the handler of the Ok - * - * @see DKTools.Sprite.Selectable.prototype.getCurrentItemSymbol - * @see DKTools.Sprite.Selectable.prototype.isHandled - * @see DKTools.Sprite.Selectable.prototype.callHandler - * @see DKTools.Sprite.Selectable.prototype.activate + * Returns true if the item exists + * + * @param {Object} item - item + * + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.hasItemByIndex + * + * @returns {Boolean} Item exists */ -DKTools.Sprite.Selectable.prototype.callOkHandler = function() { - const symbol = this.getCurrentItemSymbol(); - - if (this.isHandled(symbol)) { - this.callHandler(symbol); - } else if (this.isHandled('ok')) { - this.callHandler('ok'); - } else { - this.activate(); - } +DKTools.Sprite.Selectable.prototype.hasItem = function(item) { + return this.hasItemByIndex(this.getItemIndex(item)); }; /** - * Calls the handler of the cancel - * - * @see DKTools.Sprite.Selectable.prototype.callHandler + * Returns true if the items exists + * + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * + * @returns {Boolean} Items exists */ -DKTools.Sprite.Selectable.prototype.callCancelHandler = function() { - this.callHandler('cancel'); +DKTools.Sprite.Selectable.prototype.hasItems = function() { + return this.getMaxItems() > 0; }; -// event methods - /** - * Updates the events with type: select - * - * @see DKTools.Sprite.Selectable.prototype.updateEventsContainer + * Returns true if the handler of draw of the item exists + * + * @returns {Boolean} Handler of draw of the item exists */ -DKTools.Sprite.Selectable.prototype.updateSelectEvents = function() { - this.updateEventsContainer('select'); +DKTools.Sprite.Selectable.prototype.hasDrawItemHandler = function() { + return !!this._drawItemHandler; }; -// select methods +// active methods /** - * Selects the item by index - * - * @param {Number} index - Index + * Activates the object * - * @see DKTools.Sprite.Selectable.prototype.setupIndex - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * @see DKTools.Sprite.Selectable.prototype.updateSelectEvents + * @override */ -DKTools.Sprite.Selectable.prototype.selectItemByIndex = function(index) { - this.setupIndex(index); - this.refreshAll(); - this.updateSelectEvents(); +DKTools.Sprite.Selectable.prototype.activate = function() { + DKTools.Sprite.Button.prototype.activate.call(this); + this.reselect(); }; /** - * Selects the item + * Deactivates the object * - * @param {Object} item - Item + * @override + * @param {Boolean} [deselect=false] - Deselects the current item (selected item) * - * @see DKTools.Sprite.Selectable.prototype.getItemIndex - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.Selectable.prototype.deselect */ -DKTools.Sprite.Selectable.prototype.selectItem = function(item) { - this.selectItemByIndex(this.getItemIndex(item)); +DKTools.Sprite.Selectable.prototype.deactivate = function(deselect) { + DKTools.Sprite.Button.prototype.deactivate.call(this); + + if (deselect) { + this.deselect(); + } }; +// cursor methods + /** - * Selects the item by symbol - * - * @param {String} symbol - Symbol + * Moves the cursor to down * - * @see DKTools.Sprite.Selectable.prototype.findSymbol + * @param {Boolean} [wrap=false] - Cyclic selection + * + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * @see DKTools.Sprite.Selectable.prototype.getMaxRows * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.selectSymbol = function(symbol) { - const index = Math.max(0, this.findSymbol(symbol)); - this.selectItemByIndex(index); +DKTools.Sprite.Selectable.prototype.cursorDown = function(wrap) { + if (this.isHorizontal()) { + return; + } + + const index = this._index; + const maxItems = this.getMaxItems(); + const maxCols = this.getMaxCols(); + + if (index < maxItems - maxCols || (wrap && maxItems === this.getMaxRows() * maxCols)) { + this.selectItemByIndex((index + maxCols) % maxItems); + } }; /** - * Selects the item by ext - * - * @param {*} ext - Ext of the item + * Moves the cursor to up * - * @see DKTools.Sprite.Selectable.prototype.findExt + * @param {Boolean} [wrap=false] - Cyclic selection + * + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.getMaxCols + * @see DKTools.Sprite.Selectable.prototype.getMaxRows * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.selectExt = function(ext) { - const index = Math.max(0, this.findExt(ext)); - this.selectItemByIndex(index); +DKTools.Sprite.Selectable.prototype.cursorUp = function(wrap) { + if (this.isHorizontal()) { + return; + } + + const index = this._index; + const maxItems = this.getMaxItems(); + const maxCols = this.getMaxCols(); + + if (index >= maxCols || (wrap && maxItems === this.getMaxRows() * maxCols)) { + this.selectItemByIndex((index - maxCols + maxItems) % maxItems); + } }; /** - * Deselects the current item (selected item) + * Moves the cursor to right + * + * @param {Boolean} [wrap=false] - Cyclic selection * + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.selectNext + * @see DKTools.Sprite.Selectable.prototype.getMaxCols * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.deselect = function() { - this.selectItemByIndex(-1); +DKTools.Sprite.Selectable.prototype.cursorRight = function(wrap) { + const maxItems = this.getMaxItems(); + + if (maxItems < 2) { + return; + } + + if (this.isVertical()) { + const index = this._index; + const maxCols = this.getMaxCols(); + + if (maxCols >= 2 && (index < maxItems - 1 || wrap)) { + this.selectItemByIndex((index + 1) % maxItems); + } + } else { + this.selectNext(wrap); + } }; /** - * Reselects the current item (selected item) + * Moves the cursor to left + * + * @param {Boolean} [wrap=false] - Cyclic selection * + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.selectPrev + * @see DKTools.Sprite.Selectable.prototype.getMaxCols * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.reselect = function() { - this.selectItemByIndex(this._index); +DKTools.Sprite.Selectable.prototype.cursorLeft = function(wrap) { + const maxItems = this.getMaxItems(); + + if (maxItems < 2) { + return; + } + + if (this.isVertical()) { + const index = this._index; + const maxCols = this.getMaxCols(); + + if (maxCols >= 2 && (index > 0 || wrap)) { + this.selectItemByIndex((index - 1 + maxItems) % maxItems); + } + } else { + this.selectPrev(wrap); + } }; /** - * Selects the previous item - * - * @param {Boolean} [wrap=false] - Cyclic selection - * - * @see DKTools.Sprite.Selectable.prototype.getPrevIndex + * Moves the cursor to lower page + * + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getTopRow + * @see DKTools.Sprite.Selectable.prototype.getTopCol + * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows + * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols + * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.getMaxRows + * @see DKTools.Sprite.Selectable.prototype.setTopRow + * @see DKTools.Sprite.Selectable.prototype.setTopCol * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.selectPrev = function(wrap) { - const index = this.getPrevIndex(wrap); +DKTools.Sprite.Selectable.prototype.cursorPagedown = function() { + if (this.isHorizontal()) { + const topCol = this.getTopCol(); + const maxPageCols = this.getMaxPageCols(); + const maxItems = this.getMaxItems(); - if (index >= 0) { - this.selectItemByIndex(index); + if (topCol + maxPageCols < maxItems) { + this.setTopCol(topCol + maxPageCols); + this.selectItemByIndex(Math.min(this._index + this.getMaxPageItems(), maxItems - 1)); + } + } else { + const topRow = this.getTopRow(); + const maxPageRows = this.getMaxPageRows(); + + if (topRow + maxPageRows < this.getMaxRows()) { + this.setTopRow(topRow + maxPageRows); + this.selectItemByIndex(Math.min(this._index + this.getMaxPageItems(), this.getMaxItems() - 1)); + } } }; /** - * Selects the next item - * - * @param {Boolean} [wrap=false] - Cyclic selection - * - * @see DKTools.Sprite.Selectable.prototype.getNextIndex + * Moves the cursor to upper page + * + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.getTopRow + * @see DKTools.Sprite.Selectable.prototype.getTopCol + * @see DKTools.Sprite.Selectable.prototype.getMaxPageRows + * @see DKTools.Sprite.Selectable.prototype.getMaxPageCols + * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems + * @see DKTools.Sprite.Selectable.prototype.setTopRow + * @see DKTools.Sprite.Selectable.prototype.setTopCol * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.selectNext = function(wrap) { - const index = this.getNextIndex(wrap); +DKTools.Sprite.Selectable.prototype.cursorPageup = function() { + if (this.isHorizontal()) { + const topCol = this.getTopCol(); - if (index >= 0) { - this.selectItemByIndex(index); + if (topCol > 0) { + this.setTopCol(topCol - this.getMaxPageCols()); + this.selectItemByIndex(Math.max(0, this._index - this.getMaxPageItems())); + } + } else { + const topRow = this.getTopRow(); + + if (topRow > 0) { + this.setTopRow(topRow - this.getMaxPageRows()); + this.selectItemByIndex(Math.max(0, this._index - this.getMaxPageItems())); + } } }; -// remove methods +/** + * Shows the cursor + */ +DKTools.Sprite.Selectable.prototype.showCursor = function() { + this._cursorSprite.show(true); +}; /** - * Removes the handler of the symbol - * - * @param {String} symbol - Symbol + * Hides the cursor */ -DKTools.Sprite.Selectable.prototype.removeHandler = function(symbol) { - delete this._handlers[symbol]; +DKTools.Sprite.Selectable.prototype.hideCursor = function() { + this._cursorSprite.hide(); }; -// item methods +// touch methods /** - * Checks the item - * Returns the item - * * @private + * @param {Boolean} triggered * - * @param {Object} item - Item - * - * @see DKTools.Sprite.Selectable.prototype.setHandler - * - * @returns {Object} Item + * @see DKTools.Sprite.Selectable.prototype.hitTest + * @see DKTools.Sprite.Selectable.prototype.isOkEnabled + * @see DKTools.Sprite.Selectable.prototype.isCursorMovable + * @see DKTools.Sprite.Selectable.prototype.processOk + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.Selectable.prototype.playCursorSound */ -DKTools.Sprite.Selectable.prototype._checkItem = function(item) { - if (item.enabled === undefined) { - item.enabled = true; - } +DKTools.Sprite.Selectable.prototype._onTouch = function(triggered) { + const lastIndex = this._index; + const x = TouchInput.x; + const y = TouchInput.y; + const hitIndex = this.hitTest(x, y); - if (item.ext === undefined) { - item.ext = null; + if (hitIndex >= 0) { + if (this._index === hitIndex) { + if (triggered && this.isOkEnabled()) { + this.processOk(); + } + } else if (this.isCursorMovable()) { + this.selectItemByIndex(hitIndex); + } } - if (item.symbol && item.handler) { - this.setHandler(item.symbol, item.handler); + if (this._index !== lastIndex) { + this.playCursorSound(); } - - return item; }; /** - * Removes the item - * - * @param {Object} item - Item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.hasItem - * @see DKTools.Utils.Array.remove - * @see DKTools.Sprite.Selectable.prototype.refreshAll - * - * @returns {Object | null} Removed item or null + * @param {Number} x - The X coordinate + * @param {Number} y - The Y coordinate + * + * @see DKTools.Sprite.Selectable.prototype.isOutside + * @see DKTools.Sprite.Selectable.prototype.canvasToLocalX + * @see DKTools.Sprite.Selectable.prototype.canvasToLocalY + * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.getTopIndex + * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex + * + * @returns {Number} */ -DKTools.Sprite.Selectable.prototype.removeItem = function(item, blockRefreshAll) { - if (!this.hasItem(item)) { - return null; +DKTools.Sprite.Selectable.prototype.hitTest = function(x, y) { + if (this.isOutside(x, y)) { + return -1; } - DKTools.Utils.Array.remove(this._items, item); + const scale = this.scale; + const localX = this.canvasToLocalX(x); + const localY = this.canvasToLocalY(y); + const maxPageItems = this.getMaxPageItems(); + const maxItems = this.getMaxItems(); + let index = this.getTopIndex(); - if (!blockRefreshAll) { - this.refreshAll(); + for (let i = 0; i < maxPageItems && index < maxItems; i++ , index++) { + const rect = this.getItemRectByIndex(index); + + rect.x *= scale.x; + rect.y *= scale.y; + rect.width *= scale.x; + rect.height *= scale.y; + + if (rect.contains(localX, localY)) { + return index; + } } - return item; + return -1; }; -/** - * Removes the item by index - * - * @param {Number} index - Index - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.getItem - * @see DKTools.Sprite.Selectable.prototype.removeItem - * - * @returns {Object | null} Removed item or null - */ -DKTools.Sprite.Selectable.prototype.removeItemByIndex = function(index, blockRefreshAll) { - return this.removeItem(this.getItem(index), blockRefreshAll); -}; +// draw methods /** - * Removes the items - * - * @param {Object[]} items - Items - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.removeItem - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * Draws all * - * @returns {Object[]} Removed items + * @override */ -DKTools.Sprite.Selectable.prototype.removeItems = function(items, blockRefreshAll) { - const removed = []; - - _.forEach(items, function(item) { - const removedItem = this.removeItem(item, true); - - if (removedItem) { - removed.push(removedItem); - } - }.bind(this)); - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return removed; +DKTools.Sprite.Selectable.prototype.drawAll = function() { + DKTools.Sprite.Button.prototype.drawAll.call(this); + this.drawAllItems(); }; /** - * Inserts the item - * - * @param {Object} item - Item - * @param {Number} [index=0] - Index to insert - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Utils.Array.insert - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * Draws all items + * + * @see DKTools.Sprite.Selectable.prototype.getMaxPageItems + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.getTopIndex + * @see DKTools.Sprite.Selectable.prototype.drawItemByIndex */ -DKTools.Sprite.Selectable.prototype.insertItem = function(item, index, blockRefreshAll) { - DKTools.Utils.Array.insert(this._items, this._checkItem(item), index); +DKTools.Sprite.Selectable.prototype.drawAllItems = function() { + const maxPageItems = this.getMaxPageItems(); + const maxItems = this.getMaxItems(); + let index = this.getTopIndex(); - if (!blockRefreshAll) { - this.refreshAll(); + for(let i = 0; i < maxPageItems && index < maxItems; i++, index++) { + this.drawItemByIndex(index); } }; /** - * Inserts the items - * - * @param {Object[]} items - Items - * @param {Number} [index=0] - Index to insert - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * Draws the item by index * - * @see DKTools.Sprite.Selectable.prototype.insertItem - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @param {Number} index - Index + * + * @see DKTools.Sprite.Selectable.prototype.hasDrawItemHandler */ -DKTools.Sprite.Selectable.prototype.insertItems = function(items, index, blockRefreshAll) { - items = _.reverse(items); - _.forEach(items, function(item) { - this.insertItem(item, index, true); - }.bind(this)); - - if (!blockRefreshAll) { - this.refreshAll(); +DKTools.Sprite.Selectable.prototype.drawItemByIndex = function(index) { + if (this.hasDrawItemHandler()) { + this._drawItemHandler(index); } }; /** - * Adds the item + * Draws the item * * @param {Object} item - Item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.Selectable.prototype.insertItem - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.drawItemByIndex */ -DKTools.Sprite.Selectable.prototype.addItem = function(item, blockRefreshAll) { - this.insertItem(item, this.getMaxItems() - 1, true); - - if (!blockRefreshAll) { - this.refreshAll(); - } +DKTools.Sprite.Selectable.prototype.drawItem = function(item) { + this.drawItemByIndex(this.getItemIndex(item)); }; /** - * Adds the items + * Clears the item by index * - * @param {Object[]} items - Items - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {Number} index - Index * - * @see DKTools.Sprite.Selectable.prototype.addItem - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex + * @see DKTools.Sprite.Selectable.prototype.clearRect */ -DKTools.Sprite.Selectable.prototype.addItems = function(items, blockRefreshAll) { - _.forEach(items, function(item) { - this.addItem(item, true); - }.bind(this)); - - if (!blockRefreshAll) { - this.refreshAll(); - } +DKTools.Sprite.Selectable.prototype.clearItemByIndex = function(index) { + this.clearRect(this.getItemRectByIndex(index)); }; /** - * Replaces the item + * Clears the item * * @param {Object} item - Item - * @param {Number} [index=0] - Index - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.clearItemByIndex */ -DKTools.Sprite.Selectable.prototype.replaceItem = function(item, index, blockRefreshAll) { - this._items[index || 0] = this._checkItem(item); - - if (!blockRefreshAll) { - this.refreshAll(); - } +DKTools.Sprite.Selectable.prototype.clearItem = function(item) { + this.clearItemByIndex(this.getItemIndex(item)); }; /** - * Enables the item + * Redraws the item by index * - * @param {Object} item - Item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {Number} index - Index * - * @see DKTools.Sprite.Selectable.prototype.hasItem - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @see DKTools.Sprite.Selectable.prototype.isItemVisibleByIndex + * @see DKTools.Sprite.Selectable.prototype.clearItemByIndex + * @see DKTools.Sprite.Selectable.prototype.drawItemByIndex */ -DKTools.Sprite.Selectable.prototype.enableItem = function(item, blockRefreshAll) { - if (!this.hasItem(item)) { - return; - } - - item.enabled = true; - - if (!blockRefreshAll) { - this.refreshAll(); +DKTools.Sprite.Selectable.prototype.redrawItemByIndex = function(index) { + if (index >= 0 && this.isItemVisibleByIndex(index)) { + this.clearItemByIndex(index); + this.drawItemByIndex(index); } }; /** - * Enables the item by index + * Redraws the item * - * @param {Number} index - Index - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @param {Object} item - Item * - * @see DKTools.Sprite.Selectable.prototype.getItem - * @see DKTools.Sprite.Selectable.prototype.enableItem + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.redrawItemByIndex */ -DKTools.Sprite.Selectable.prototype.enableItemByIndex = function(index, blockRefreshAll) { - this.enableItem(this.getItem(index), blockRefreshAll); +DKTools.Sprite.Selectable.prototype.redrawItem = function(item) { + this.redrawItemByIndex(this.getItemIndex(item)); }; /** - * Disables the item - * - * @param {Object} item - Item - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * Redraws the current item (selected item) * - * @see DKTools.Sprite.Selectable.prototype.hasItem - * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @see DKTools.Sprite.Selectable.prototype.redrawItemByIndex */ -DKTools.Sprite.Selectable.prototype.disableItem = function(item, blockRefreshAll) { - if (!this.hasItem(item)) { - return; - } +DKTools.Sprite.Selectable.prototype.redrawCurrentItem = function() { + this.redrawItemByIndex(this._index); +}; - item.enabled = false; +// sound methods - if (!blockRefreshAll) { - this.refreshAll(); - } +/** + * Plays "ok" sound + * + * @see SoundManager.playOk + */ +DKTools.Sprite.Selectable.prototype.playOkSound = function() { + SoundManager.playOk(); }; /** - * Disables the item by index - * - * @param {Number} index - Index - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * Plays "cancel" sound * - * @see DKTools.Sprite.Selectable.prototype.getItem - * @see DKTools.Sprite.Selectable.prototype.disableItem + * @see SoundManager.playCancel */ -DKTools.Sprite.Selectable.prototype.disableItemByIndex = function(index, blockRefreshAll) { - this.disableItem(this.getItem(index), blockRefreshAll); +DKTools.Sprite.Selectable.prototype.playCancelSound = function() { + SoundManager.playCancel(); }; -// find methods - /** - * Returns the index of the item by symbol + * Plays "cursor" sound * - * @param {Symbol} symbol - Symbol - * @returns {Number} Index of the item by symbol + * @see SoundManager.playCursor */ -DKTools.Sprite.Selectable.prototype.findSymbol = function(symbol) { - return _.findIndex(this._items, { symbol }); +DKTools.Sprite.Selectable.prototype.playCursorSound = function() { + SoundManager.playCursor(); }; /** - * Returns the index of the item by ext + * Plays "buzzer" sound * - * @param {*} ext - Ext of the item - * @returns {Number} Index of the item by ext + * @see SoundManager.playBuzzer */ -DKTools.Sprite.Selectable.prototype.findExt = function(ext) { - return _.findIndex(this._items, { ext }); +DKTools.Sprite.Selectable.prototype.playBuzzerSound = function() { + SoundManager.playBuzzer(); }; -// scroll methods +// call methods /** - * Resets the scroll + * Calls the handler of the symbol + * + * @param {String} symbol - Symbol * - * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.Selectable.prototype.isHandled */ -DKTools.Sprite.Selectable.prototype.resetScroll = function() { - if (this._index !== 0) { - this.selectItemByIndex(0); +DKTools.Sprite.Selectable.prototype.callHandler = function(symbol) { + if (this.isHandled(symbol)) { + this._handlers[symbol](this._index); } }; /** - * Scrolls down + * Calls the handler of the Ok * - * @see DKTools.Sprite.Selectable.prototype.getTopRow - * @see DKTools.Sprite.Selectable.prototype.getMaxRows - * @see DKTools.Sprite.Selectable.prototype.cursorDown + * @see DKTools.Sprite.Selectable.prototype.getCurrentItemSymbol + * @see DKTools.Sprite.Selectable.prototype.isHandled + * @see DKTools.Sprite.Selectable.prototype.callHandler + * @see DKTools.Sprite.Selectable.prototype.activate */ -DKTools.Sprite.Selectable.prototype.scrollDown = function() { - if (this.getTopRow() + 1 < this.getMaxRows()) { - this.cursorDown(); +DKTools.Sprite.Selectable.prototype.callOkHandler = function() { + const symbol = this.getCurrentItemSymbol(); + + if (this.isHandled(symbol)) { + this.callHandler(symbol); + } else if (this.isHandled('ok')) { + this.callHandler('ok'); + } else { + this.activate(); } }; /** - * Scrolls up - * - * @version 3.0.0 - * - * @see DKTools.Sprite.Selectable.prototype.getTopRow - * @see DKTools.Sprite.Selectable.prototype.cursorUp + * Calls the handler of the cancel + * + * @see DKTools.Sprite.Selectable.prototype.callHandler */ -DKTools.Sprite.Selectable.prototype.scrollUp = function() { - if (this.getCurrentRow() > 0) { - this.cursorUp(); - } +DKTools.Sprite.Selectable.prototype.callCancelHandler = function() { + this.callHandler('cancel'); }; +// event methods + /** - * Scrolls right + * Updates the events with type: select * - * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.getMaxItems - * @see DKTools.Sprite.Selectable.prototype.cursorRight + * @see DKTools.Sprite.Selectable.prototype.updateEventsContainer */ -DKTools.Sprite.Selectable.prototype.scrollRight = function() { - if (this.getTopCol() + 1 < this.getMaxItems()) { - this.cursorRight(); - } +DKTools.Sprite.Selectable.prototype.updateSelectEvents = function() { + this.updateEventsContainer('select'); }; +// select methods + /** - * Scrolls left + * Selects the item by index * - * @version 3.0.0 + * @param {Number} index - Index * - * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.cursorLeft + * @see DKTools.Sprite.Selectable.prototype.setupIndex + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * @see DKTools.Sprite.Selectable.prototype.updateSelectEvents */ -DKTools.Sprite.Selectable.prototype.scrollLeft = function() { - if (this.getCurrentCol() > 0) { - this.cursorLeft(); - } +DKTools.Sprite.Selectable.prototype.selectItemByIndex = function(index) { + this.setupIndex(index); + this.refreshAll(); + this.updateSelectEvents(); }; -// process methods - /** - * Processes all + * Selects the item * - * @override - * - * @see DKTools.Sprite.Selectable.prototype.processCursorMove - * @see DKTools.Sprite.Selectable.prototype.processHandling + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.getItemIndex + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.processAll = function() { - DKTools.Sprite.Button.prototype.processAll.call(this); - this.processCursorMove(); - this.processHandling(); +DKTools.Sprite.Selectable.prototype.selectItem = function(item) { + this.selectItemByIndex(this.getItemIndex(item)); }; /** - * Processes the move of the cursor - * - * @see DKTools.Sprite.Selectable.prototype.isCursorMovable - * @see DKTools.Sprite.Selectable.prototype.isHandled - * @see DKTools.Sprite.Selectable.prototype.cursorDown - * @see DKTools.Sprite.Selectable.prototype.cursorUp - * @see DKTools.Sprite.Selectable.prototype.cursorRight - * @see DKTools.Sprite.Selectable.prototype.cursorLeft - * @see DKTools.Sprite.Selectable.prototype.cursorPagedown - * @see DKTools.Sprite.Selectable.prototype.cursorPageup - * @see DKTools.Sprite.Selectable.prototype.playCursorSound + * Selects the item by symbol + * + * @param {String} symbol - Symbol + * + * @see DKTools.Sprite.Selectable.prototype.findSymbol + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.processCursorMove = function() { - if (!this.isCursorMovable()) { - return; - } - - const lastIndex = this._index; - - if (Input.isRepeated('down')) { - this.cursorDown(Input.isTriggered('down')); - } - - if (Input.isRepeated('up')) { - this.cursorUp(Input.isTriggered('up')); - } - - if (Input.isRepeated('right')) { - this.cursorRight(Input.isTriggered('right')); - } - - if (Input.isRepeated('left')) { - this.cursorLeft(Input.isTriggered('left')); - } - - if (!this.isHandled('pagedown') && Input.isTriggered('pagedown')) { - this.cursorPagedown(); - } - - if (!this.isHandled('pageup') && Input.isTriggered('pageup')) { - this.cursorPageup(); - } +DKTools.Sprite.Selectable.prototype.selectSymbol = function(symbol) { + const index = Math.max(0, this.findSymbol(symbol)); + this.selectItemByIndex(index); +}; - if (this._index !== lastIndex) { - this.playCursorSound(); - } +/** + * Selects the item by ext + * + * @param {*} ext - Ext of the item + * + * @see DKTools.Sprite.Selectable.prototype.findExt + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + */ +DKTools.Sprite.Selectable.prototype.selectExt = function(ext) { + const index = Math.max(0, this.findExt(ext)); + this.selectItemByIndex(index); }; /** - * Processes the handling + * Deselects the current item (selected item) * - * @see DKTools.Sprite.Selectable.prototype.isVisibleAndActive - * @see DKTools.Sprite.Selectable.prototype.isOkEnabled - * @see DKTools.Sprite.Selectable.prototype.isOkTriggered - * @see DKTools.Sprite.Selectable.prototype.isCancelEnabled - * @see DKTools.Sprite.Selectable.prototype.isCancelTriggered - * @see DKTools.Sprite.Selectable.prototype.isHandled - * @see DKTools.Sprite.Selectable.prototype.processOk - * @see DKTools.Sprite.Selectable.prototype.processCancel - * @see DKTools.Sprite.Selectable.prototype.processPagedown - * @see DKTools.Sprite.Selectable.prototype.processPageup + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.processHandling = function() { - if (!this.isVisibleAndActive()) { - return; - } - - if (this.isOkEnabled() && this.isOkTriggered()) { - this.processOk(); - } else if (this.isCancelEnabled() && this.isCancelTriggered()) { - this.processCancel(); - } else if (this.isHandled('pagedown') && Input.isTriggered('pagedown')) { - this.processPagedown(); - } else if (this.isHandled('pageup') && Input.isTriggered('pageup')) { - this.processPageup(); - } +DKTools.Sprite.Selectable.prototype.deselect = function() { + this.selectItemByIndex(-1); }; /** - * Processes the hover of the mouse + * Reselects the current item (selected item) * - * @see DKTools.Sprite.Selectable.prototype.isOptionEnabled - * @see DKTools.Sprite.Selectable.prototype.isCursorMovable - * @see DKTools.Sprite.Selectable.prototype.hitTest * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex - * @see DKTools.Sprite.Selectable.prototype.playCursorSound */ -DKTools.Sprite.Selectable.prototype.processMouseHover = function() { - if (this.isOptionEnabled('process-mouse-hover') && this.isCursorMovable()) { - const lastIndex = this._index; - const x = TouchInput.mouseX; - const y = TouchInput.mouseY; - const hitIndex = this.hitTest(x, y); - - if (hitIndex >= 0 && hitIndex !== lastIndex) { - this.selectItemByIndex(hitIndex); - this.playCursorSound(); - } - } +DKTools.Sprite.Selectable.prototype.reselect = function() { + this.selectItemByIndex(this._index); }; /** - * Processes the scroll of the mouse wheel - * - * @see DKTools.Sprite.Selectable.prototype.isOptionEnabled - * @see DKTools.Sprite.Selectable.prototype.isVisibleAndActive - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.scrollRight - * @see DKTools.Sprite.Selectable.prototype.scrollDown - * @see DKTools.Sprite.Selectable.prototype.scrollLeft - * @see DKTools.Sprite.Selectable.prototype.scrollUp + * Selects the previous item + * + * @param {Boolean} [wrap=false] - Cyclic selection + * + * @see DKTools.Sprite.Selectable.prototype.getPrevIndex + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.processWheelScroll = function() { - if (this.isOptionEnabled('process-wheel-scroll') && this.isVisibleAndActive()) { - const wheelY = this._wheelY; +DKTools.Sprite.Selectable.prototype.selectPrev = function(wrap) { + const index = this.getPrevIndex(wrap); - if (wheelY > 0) { - if (this.isHorizontal()) { - this.scrollRight(); - } else { - this.scrollDown(); - } - } else { - if (this.isHorizontal()) { - this.scrollLeft(); - } else { - this.scrollUp(); - } - } + if (index >= 0) { + this.selectItemByIndex(index); } }; /** - * Processes ok - * - * @see DKTools.Sprite.Selectable.prototype.isCurrentItemEnabled - * @see DKTools.Sprite.Selectable.prototype.updateInputData - * @see DKTools.Sprite.Selectable.prototype.deactivate - * @see DKTools.Sprite.Selectable.prototype.callOkHandler - * @see DKTools.Sprite.Selectable.prototype.playOkSound - * @see DKTools.Sprite.Selectable.prototype.playBuzzerSound + * Selects the next item + * + * @param {Boolean} [wrap=false] - Cyclic selection + * + * @see DKTools.Sprite.Selectable.prototype.getNextIndex + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.Selectable.prototype.processOk = function() { - if (this.isCurrentItemEnabled()) { - this.playOkSound(); - this.updateInputData(); - this.deactivate(); - this.callOkHandler(); - } else { - this.playBuzzerSound(); +DKTools.Sprite.Selectable.prototype.selectNext = function(wrap) { + const index = this.getNextIndex(wrap); + + if (index >= 0) { + this.selectItemByIndex(index); } }; +// remove methods + /** - * Processes cancel - * - * @see DKTools.Sprite.Selectable.prototype.playCancelSound - * @see DKTools.Sprite.Selectable.prototype.updateInputData - * @see DKTools.Sprite.Selectable.prototype.deactivate - * @see DKTools.Sprite.Selectable.prototype.callCancelHandler + * Removes the handler of the symbol + * + * @param {String} symbol - Symbol */ -DKTools.Sprite.Selectable.prototype.processCancel = function() { - this.playCancelSound(); - this.updateInputData(); - this.deactivate(); - this.callCancelHandler(); +DKTools.Sprite.Selectable.prototype.removeHandler = function(symbol) { + delete this._handlers[symbol]; }; +// item methods + /** - * Processes pageup + * Checks the item + * Returns the item * - * @see DKTools.Sprite.Selectable.prototype.playCursorSound - * @see DKTools.Sprite.Selectable.prototype.updateInputData - * @see DKTools.Sprite.Selectable.prototype.deactivate - * @see DKTools.Sprite.Selectable.prototype.callHandler + * @private + * + * @param {Object} item - Item + * + * @see DKTools.Sprite.Selectable.prototype.setHandler + * + * @returns {Object} Item */ -DKTools.Sprite.Selectable.prototype.processPageup = function() { - this.playCursorSound(); - this.updateInputData(); - this.deactivate(); - this.callHandler('pageup'); +DKTools.Sprite.Selectable.prototype._checkItem = function(item) { + if (item.enabled === undefined) { + item.enabled = true; + } + + if (item.ext === undefined) { + item.ext = null; + } + + if (item.symbol && item.handler) { + this.setHandler(item.symbol, item.handler); + } + + return item; }; /** - * Processes pagedown - * - * @see DKTools.Sprite.Selectable.prototype.playCursorSound - * @see DKTools.Sprite.Selectable.prototype.updateInputData - * @see DKTools.Sprite.Selectable.prototype.deactivate - * @see DKTools.Sprite.Selectable.prototype.callHandler + * Removes the item + * + * @param {Object} item - Item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.hasItem + * @see DKTools.Utils.Array.remove + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Object | null} Removed item or null */ -DKTools.Sprite.Selectable.prototype.processPagedown = function() { - this.playCursorSound(); - this.updateInputData(); - this.deactivate(); - this.callHandler('pagedown'); -}; +DKTools.Sprite.Selectable.prototype.removeItem = function(item, blockRefreshAll) { + if (!this.hasItem(item)) { + return null; + } -// update methods + DKTools.Utils.Array.remove(this._items, item); + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return item; +}; /** - * Updates all + * Removes the item by index * - * @override - * - * @see DKTools.Sprite.Selectable.prototype.updateCursor + * @param {Number} index - Index + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.getItem + * @see DKTools.Sprite.Selectable.prototype.removeItem + * + * @returns {Object | null} Removed item or null */ -DKTools.Sprite.Selectable.prototype.updateAll = function() { - DKTools.Sprite.Button.prototype.updateAll.call(this); - this.updateCursor(); +DKTools.Sprite.Selectable.prototype.removeItemByIndex = function(index, blockRefreshAll) { + return this.removeItem(this.getItem(index), blockRefreshAll); }; /** - * Updates the cursor - * - * @see DKTools.Sprite.Selectable.prototype.isHorizontal - * @see DKTools.Sprite.Selectable.prototype.isCursorAll - * @see DKTools.Sprite.Selectable.prototype.isCursorVisible - * @see DKTools.Sprite.Selectable.prototype.getCurrentCol - * @see DKTools.Sprite.Selectable.prototype.getTopCol - * @see DKTools.Sprite.Selectable.prototype.getBottomCol - * @see DKTools.Sprite.Selectable.prototype.getMaxRows - * @see DKTools.Sprite.Selectable.prototype.getItemHeight - * @see DKTools.Sprite.Selectable.prototype.setTopCol - * @see DKTools.Sprite.Selectable.prototype.setBottomCol - * @see DKTools.Sprite.Selectable.prototype.setCursorRect - * @see DKTools.Sprite.Selectable.prototype.resetScroll - * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex - * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex + * Removes the items + * + * @param {Object[]} items - Items + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.removeItem + * @see DKTools.Sprite.Selectable.prototype.refreshAll + * + * @returns {Object[]} Removed items */ -DKTools.Sprite.Selectable.prototype.updateCursor = function() { - if (this.isHorizontal()) { - const col = this.getCurrentCol(); +DKTools.Sprite.Selectable.prototype.removeItems = function(items, blockRefreshAll) { + const removed = []; - if (col < this.getTopCol()) { - this.setTopCol(col); - } else if (col > this.getBottomCol()) { - this.setBottomCol(col); - } - } else { - const row = this.getCurrentRow(); + _.forEach(items, function(item) { + const removedItem = this.removeItem(item, true); - if (row < this.getTopRow()) { - this.setTopRow(row); - } else if (row > this.getBottomRow()) { - this.setBottomRow(row); + if (removedItem) { + removed.push(removedItem); } + }.bind(this)); + + if (!blockRefreshAll) { + this.refreshAll(); } - if (this.isCursorAll()) { - const allRowsHeight = this.getMaxRows() * this.getItemHeight(); - this.setCursorRect(0, 0, this.realWidth, allRowsHeight); - this.resetScroll(); - } else if (this.isCursorVisible() || !this._cursorSprite.hasBitmap()) { - const rect = this.getItemRectByIndex(this._index); - this.setCursorRect(rect); - } else { - this.setCursorRect(Rectangle.emptyRectangle); + return removed; +}; + +/** + * Inserts the item + * + * @param {Object} item - Item + * @param {Number} [index=0] - Index to insert + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Utils.Array.insert + * @see DKTools.Sprite.Selectable.prototype.refreshAll + */ +DKTools.Sprite.Selectable.prototype.insertItem = function(item, index, blockRefreshAll) { + DKTools.Utils.Array.insert(this._items, this._checkItem(item), index); + + if (!blockRefreshAll) { + this.refreshAll(); } }; +/** + * Inserts the items + * + * @param {Object[]} items - Items + * @param {Number} [index=0] - Index to insert + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.insertItem + * @see DKTools.Sprite.Selectable.prototype.refreshAll + */ +DKTools.Sprite.Selectable.prototype.insertItems = function(items, index, blockRefreshAll) { + items = _.reverse(items); + _.forEach(items, function(item) { + this.insertItem(item, index, true); + }.bind(this)); + if (!blockRefreshAll) { + this.refreshAll(); + } +}; +/** + * Adds the item + * + * @param {Object} item - Item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.insertItem + * @see DKTools.Sprite.Selectable.prototype.refreshAll + */ +DKTools.Sprite.Selectable.prototype.addItem = function(item, blockRefreshAll) { + this.insertItem(item, this.getMaxItems() - 1, true); + if (!blockRefreshAll) { + this.refreshAll(); + } +}; -//=========================================================================== -// DKTools.Sprite.ProgressBar -//=========================================================================== - -DKTools.Sprite.ProgressBar.prototype = Object.create(DKTools.Sprite.prototype); -DKTools.Sprite.ProgressBar.prototype.constructor = DKTools.Sprite.ProgressBar; - -// properties +/** + * Adds the items + * + * @param {Object[]} items - Items + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.addItem + * @see DKTools.Sprite.Selectable.prototype.refreshAll + */ +DKTools.Sprite.Selectable.prototype.addItems = function(items, blockRefreshAll) { + _.forEach(items, function(item) { + this.addItem(item, true); + }.bind(this)); -Object.defineProperties(DKTools.Sprite.ProgressBar.prototype, { + if (!blockRefreshAll) { + this.refreshAll(); + } +}; - /** - * Value step - * - * @readonly - * @type {Number} - * @memberof DKTools.Sprite.ProgressBar.prototype - */ - valueStep: { - get: function() { - return this._valueStep; - }, - configurable: true - }, +/** + * Replaces the item + * + * @param {Object} item - Item + * @param {Number} [index=0] - Index + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.refreshAll + */ +DKTools.Sprite.Selectable.prototype.replaceItem = function(item, index, blockRefreshAll) { + this._items[index || 0] = this._checkItem(item); - /** - * Maximum value - * - * @readonly - * @type {Number} - * @memberof DKTools.Sprite.ProgressBar.prototype - */ - maxValue: { - get: function() { - return this._maxValue; - }, - configurable: true - }, + if (!blockRefreshAll) { + this.refreshAll(); + } +}; - /** - * Value - * - * @readonly - * @type {Number} - * @memberof DKTools.Sprite.ProgressBar.prototype - */ - value: { - get: function() { - return this._value; - }, - configurable: true - }, +/** + * Enables the item + * + * @param {Object} item - Item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.hasItem + * @see DKTools.Sprite.Selectable.prototype.refreshAll + */ +DKTools.Sprite.Selectable.prototype.enableItem = function(item, blockRefreshAll) { + if (!this.hasItem(item)) { + return; + } - /** - * Background color - * - * @readonly - * @type {String} - * @memberof DKTools.Sprite.ProgressBar.prototype - */ - backgroundColor: { - get: function() { - return this._backgroundColor; - }, - configurable: true - }, + item.enabled = true; - /** - * Progress color - * - * @readonly - * @type {String} - * @memberof DKTools.Sprite.ProgressBar.prototype - */ - progressColor: { - get: function() { - return this._progressColor; - }, - configurable: true - }, + if (!blockRefreshAll) { + this.refreshAll(); + } +}; - /** - * Handler of draw of the graphic - * - * @readonly - * @type {Function} - * @memberof DKTools.Sprite.ProgressBar.prototype - */ - drawGraphicHandler: { - get: function() { - return this._drawGraphicHandler; - }, - configurable: true - }, +/** + * Enables the item by index + * + * @param {Number} index - Index + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.getItem + * @see DKTools.Sprite.Selectable.prototype.enableItem + */ +DKTools.Sprite.Selectable.prototype.enableItemByIndex = function(index, blockRefreshAll) { + this.enableItem(this.getItem(index), blockRefreshAll); +}; - /** - * Handler of draw of the text - * - * @readonly - * @type {Function} - * @memberof DKTools.Sprite.ProgressBar.prototype - */ - drawTextHandler: { - get: function() { - return this._drawTextHandler; - }, - configurable: true +/** + * Disables the item + * + * @param {Object} item - Item + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.hasItem + * @see DKTools.Sprite.Selectable.prototype.refreshAll + */ +DKTools.Sprite.Selectable.prototype.disableItem = function(item, blockRefreshAll) { + if (!this.hasItem(item)) { + return; } -}); + item.enabled = false; -// standard methods + if (!blockRefreshAll) { + this.refreshAll(); + } +}; /** - * Returns the standard activity of the progress bar + * Disables the item by index * - * @override - * @returns {Boolean} Standard activity of the progress bar + * @param {Number} index - Index + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.Selectable.prototype.getItem + * @see DKTools.Sprite.Selectable.prototype.disableItem */ -DKTools.Sprite.ProgressBar.prototype.standardActive = function() { - return false; +DKTools.Sprite.Selectable.prototype.disableItemByIndex = function(index, blockRefreshAll) { + this.disableItem(this.getItem(index), blockRefreshAll); }; +// find methods + /** - * Returns the standard value step + * Returns the index of the item by symbol * - * @returns {Number} Standard value step + * @param {Symbol} symbol - Symbol + * @returns {Number} Index of the item by symbol */ -DKTools.Sprite.ProgressBar.prototype.standardValueStep = function() { - return 1; +DKTools.Sprite.Selectable.prototype.findSymbol = function(symbol) { + return _.findIndex(this._items, { symbol }); }; /** - * Returns the standard maximum value + * Returns the index of the item by ext * - * @returns {Number} Standard maximum value + * @param {*} ext - Ext of the item + * @returns {Number} Index of the item by ext */ -DKTools.Sprite.ProgressBar.prototype.standardMaxValue = function() { - return 100; +DKTools.Sprite.Selectable.prototype.findExt = function(ext) { + return _.findIndex(this._items, { ext }); }; +// scroll methods + /** - * Returns the standard value - * - * @returns {Number} Standard value + * Resets the scroll + * + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex */ -DKTools.Sprite.ProgressBar.prototype.standardValue = function() { - return 0; +DKTools.Sprite.Selectable.prototype.resetScroll = function() { + if (this._index !== 0) { + this.selectItemByIndex(0); + } }; /** - * Returns the standard background color - * - * @returns {String} Standard background color + * Scrolls down + * + * @see DKTools.Sprite.Selectable.prototype.getTopRow + * @see DKTools.Sprite.Selectable.prototype.getMaxRows + * @see DKTools.Sprite.Selectable.prototype.cursorDown */ -DKTools.Sprite.ProgressBar.prototype.standardBackgroundColor = function() { - return 'grey'; +DKTools.Sprite.Selectable.prototype.scrollDown = function() { + if (this.getTopRow() + 1 < this.getMaxRows()) { + this.cursorDown(); + } }; /** - * Returns the standard progress color + * Scrolls up * - * @returns {String} Standard progress color + * @version 3.0.0 + * + * @see DKTools.Sprite.Selectable.prototype.getTopRow + * @see DKTools.Sprite.Selectable.prototype.cursorUp */ -DKTools.Sprite.ProgressBar.prototype.standardProgressColor = function() { - return '#33ccff'; +DKTools.Sprite.Selectable.prototype.scrollUp = function() { + if (this.getCurrentRow() > 0) { + this.cursorUp(); + } }; /** - * Returns the standard handler of draw of the graphic - * - * @returns {null} Standard handler of draw of the graphic + * Scrolls right + * + * @see DKTools.Sprite.Selectable.prototype.getTopCol + * @see DKTools.Sprite.Selectable.prototype.getMaxItems + * @see DKTools.Sprite.Selectable.prototype.cursorRight */ -DKTools.Sprite.ProgressBar.prototype.standardDrawGraphicHandler = function() { - return null; +DKTools.Sprite.Selectable.prototype.scrollRight = function() { + if (this.getTopCol() + 1 < this.getMaxItems()) { + this.cursorRight(); + } }; /** - * Returns the standard handler of draw of the text + * Scrolls left * - * @returns {null} Standard handler of draw of the text + * @version 3.0.0 + * + * @see DKTools.Sprite.Selectable.prototype.getTopCol + * @see DKTools.Sprite.Selectable.prototype.cursorLeft */ -DKTools.Sprite.ProgressBar.prototype.standardDrawTextHandler = function() { - return null; +DKTools.Sprite.Selectable.prototype.scrollLeft = function() { + if (this.getCurrentCol() > 0) { + this.cursorLeft(); + } }; -// setup methods +// process methods /** - * Sets all parameters + * Processes all * * @override - * - * @param {Object | null} [object={}] - Parameters - * - * @param {Number} [object.valueStep] - Value step - * @param {Number} [object.maxValue] - Maximum value - * @param {Number} [object.value] - Value - * @param {String} [object.backgroundColor] - Background color - * @param {String} [object.progressColor] - Progress color - * @param {Function} [object.drawGraphicHandler] - Handler of draw of the graphic - * @param {Function} [object.drawTextHandler] - Handler of draw of the text - * - * @see DKTools.Sprite.prototype.setupAll - * @see DKTools.Sprite.ProgressBar.setupValueStep - * @see DKTools.Sprite.ProgressBar.setupMaxValue - * @see DKTools.Sprite.ProgressBar.setupValue - * @see DKTools.Sprite.ProgressBar.setupBackgroundColor - * @see DKTools.Sprite.ProgressBar.setupProgressColor - * @see DKTools.Sprite.ProgressBar.setupDrawGraphicHandler - * @see DKTools.Sprite.ProgressBar.setupDrawTextHandler + * + * @see DKTools.Sprite.Selectable.prototype.processCursorMove + * @see DKTools.Sprite.Selectable.prototype.processHandling */ -DKTools.Sprite.ProgressBar.prototype.setupAll = function(object) { - object = object || {}; - DKTools.Sprite.prototype.setupAll.call(this, object); - this.setupValueStep(object.valueStep); - this.setupMaxValue(object.maxValue); - this.setupValue(object.value); - this.setupBackgroundColor(object.progressColor); - this.setupProgressColor(object.progressColor); - this.setupDrawGraphicHandler(object.drawGraphicHandler); - this.setupDrawTextHandler(object.drawTextHandler); +DKTools.Sprite.Selectable.prototype.processAll = function() { + DKTools.Sprite.Button.prototype.processAll.call(this); + this.processCursorMove(); + this.processHandling(); }; /** - * Sets the value step - * - * @param {Number} [step=this.standardValueStep()] - Value step - * - * @see DKTools.Sprite.ProgressBar.prototype.standardValueStep + * Processes the move of the cursor + * + * @see DKTools.Sprite.Selectable.prototype.isCursorMovable + * @see DKTools.Sprite.Selectable.prototype.isHandled + * @see DKTools.Sprite.Selectable.prototype.cursorDown + * @see DKTools.Sprite.Selectable.prototype.cursorUp + * @see DKTools.Sprite.Selectable.prototype.cursorRight + * @see DKTools.Sprite.Selectable.prototype.cursorLeft + * @see DKTools.Sprite.Selectable.prototype.cursorPagedown + * @see DKTools.Sprite.Selectable.prototype.cursorPageup + * @see DKTools.Sprite.Selectable.prototype.playCursorSound */ -DKTools.Sprite.ProgressBar.prototype.setupValueStep = function(step) { - /** - * @private - * @readonly - * @type {Number} - */ - this._valueStep = step || this.standardValueStep(); +DKTools.Sprite.Selectable.prototype.processCursorMove = function() { + if (!this.isCursorMovable()) { + return; + } + + const lastIndex = this._index; + + if (Input.isRepeated('down')) { + this.cursorDown(Input.isTriggered('down')); + } + + if (Input.isRepeated('up')) { + this.cursorUp(Input.isTriggered('up')); + } + + if (Input.isRepeated('right')) { + this.cursorRight(Input.isTriggered('right')); + } + + if (Input.isRepeated('left')) { + this.cursorLeft(Input.isTriggered('left')); + } + + if (!this.isHandled('pagedown') && Input.isTriggered('pagedown')) { + this.cursorPagedown(); + } + + if (!this.isHandled('pageup') && Input.isTriggered('pageup')) { + this.cursorPageup(); + } + + if (this._index !== lastIndex) { + this.playCursorSound(); + } }; /** - * Sets the maximum value - * - * @param {Number} [max=this.standardMaxValue()] - Maximum value - * - * @see DKTools.Sprite.ProgressBar.prototype.setupMaxValue + * Processes the handling + * + * @see DKTools.Sprite.Selectable.prototype.isVisibleAndActive + * @see DKTools.Sprite.Selectable.prototype.isOkEnabled + * @see DKTools.Sprite.Selectable.prototype.isOkTriggered + * @see DKTools.Sprite.Selectable.prototype.isCancelEnabled + * @see DKTools.Sprite.Selectable.prototype.isCancelTriggered + * @see DKTools.Sprite.Selectable.prototype.isHandled + * @see DKTools.Sprite.Selectable.prototype.processOk + * @see DKTools.Sprite.Selectable.prototype.processCancel + * @see DKTools.Sprite.Selectable.prototype.processPagedown + * @see DKTools.Sprite.Selectable.prototype.processPageup */ -DKTools.Sprite.ProgressBar.prototype.setupMaxValue = function(max) { - /** - * @private - * @readonly - * @type {Number} - */ - this._maxValue = max || this.standardMaxValue(); +DKTools.Sprite.Selectable.prototype.processHandling = function() { + if (!this.isVisibleAndActive()) { + return; + } + + if (this.isOkEnabled() && this.isOkTriggered()) { + this.processOk(); + } else if (this.isCancelEnabled() && this.isCancelTriggered()) { + this.processCancel(); + } else if (this.isHandled('pagedown') && Input.isTriggered('pagedown')) { + this.processPagedown(); + } else if (this.isHandled('pageup') && Input.isTriggered('pageup')) { + this.processPageup(); + } }; /** - * Sets the value - * - * @param {Number} [value=this.standardValue()] - Value - * - * @see DKTools.Sprite.ProgressBar.prototype.standardValue + * Processes the hover of the mouse + * + * @see DKTools.Sprite.Selectable.prototype.isOptionEnabled + * @see DKTools.Sprite.Selectable.prototype.isCursorMovable + * @see DKTools.Sprite.Selectable.prototype.hitTest + * @see DKTools.Sprite.Selectable.prototype.selectItemByIndex + * @see DKTools.Sprite.Selectable.prototype.playCursorSound */ -DKTools.Sprite.ProgressBar.prototype.setupValue = function(value) { - const max = this._maxValue; - const newValue = Math.max(0, Math.min(value, max)); +DKTools.Sprite.Selectable.prototype.processMouseHover = function() { + if (this.isOptionEnabled('process-mouse-hover') && this.isCursorMovable()) { + const lastIndex = this._index; + const x = TouchInput.mouseX; + const y = TouchInput.mouseY; + const hitIndex = this.hitTest(x, y); - /** - * @private - * @readonly - * @type {Number} - */ - this._value = Number.isNaN(newValue) ? this.standardValue() : newValue; + if (hitIndex >= 0 && hitIndex !== lastIndex) { + this.selectItemByIndex(hitIndex); + this.playCursorSound(); + } + } +}; + +/** + * Processes the scroll of the mouse wheel + * + * @see DKTools.Sprite.Selectable.prototype.isOptionEnabled + * @see DKTools.Sprite.Selectable.prototype.isVisibleAndActive + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.scrollRight + * @see DKTools.Sprite.Selectable.prototype.scrollDown + * @see DKTools.Sprite.Selectable.prototype.scrollLeft + * @see DKTools.Sprite.Selectable.prototype.scrollUp + */ +DKTools.Sprite.Selectable.prototype.processWheelScroll = function() { + if (this.isOptionEnabled('process-wheel-scroll') && this.isVisibleAndActive()) { + const wheelY = this._wheelY; + + if (wheelY > 0) { + if (this.isHorizontal()) { + this.scrollRight(); + } else { + this.scrollDown(); + } + } else { + if (this.isHorizontal()) { + this.scrollLeft(); + } else { + this.scrollUp(); + } + } + } }; /** - * Sets the background color - * - * @param {String} [color=this.standardBackgroundColor()] - Background color - * - * @see DKTools.Sprite.ProgressBar.prototype.setupBackgroundColor + * Processes ok + * + * @see DKTools.Sprite.Selectable.prototype.isCurrentItemEnabled + * @see DKTools.Sprite.Selectable.prototype.updateInputData + * @see DKTools.Sprite.Selectable.prototype.deactivate + * @see DKTools.Sprite.Selectable.prototype.callOkHandler + * @see DKTools.Sprite.Selectable.prototype.playOkSound + * @see DKTools.Sprite.Selectable.prototype.playBuzzerSound */ -DKTools.Sprite.ProgressBar.prototype.setupBackgroundColor = function(color) { - /** - * @private - * @readonly - * @type {String} - */ - this._backgroundColor = color || this.standardBackgroundColor(); +DKTools.Sprite.Selectable.prototype.processOk = function() { + if (this.isCurrentItemEnabled()) { + this.playOkSound(); + this.updateInputData(); + this.deactivate(); + this.callOkHandler(); + } else { + this.playBuzzerSound(); + } }; /** - * Sets the progress color - * - * @param {String} [color=this.standardProgressColor()] - Progress color - * - * @see DKTools.Sprite.ProgressBar.prototype.standardProgressColor + * Processes cancel + * + * @see DKTools.Sprite.Selectable.prototype.playCancelSound + * @see DKTools.Sprite.Selectable.prototype.updateInputData + * @see DKTools.Sprite.Selectable.prototype.deactivate + * @see DKTools.Sprite.Selectable.prototype.callCancelHandler */ -DKTools.Sprite.ProgressBar.prototype.setupProgressColor = function(color) { - /** - * @private - * @readonly - * @type {String} - */ - this._progressColor = color || this.standardProgressColor(); +DKTools.Sprite.Selectable.prototype.processCancel = function() { + this.playCancelSound(); + this.updateInputData(); + this.deactivate(); + this.callCancelHandler(); }; /** - * Sets the handler of draw of the graphic - * - * @param {Function} [handler=this.standardDrawGraphicHandler()] - Handler of draw of the graphic - * - * @see DKTools.Sprite.ProgressBar.prototype.standardDrawGraphicHandler + * Processes pageup + * + * @see DKTools.Sprite.Selectable.prototype.playCursorSound + * @see DKTools.Sprite.Selectable.prototype.updateInputData + * @see DKTools.Sprite.Selectable.prototype.deactivate + * @see DKTools.Sprite.Selectable.prototype.callHandler */ -DKTools.Sprite.ProgressBar.prototype.setupDrawGraphicHandler = function(handler) { - /** - * @private - * @readonly - * @type {Function} - */ - this._drawGraphicHandler = handler || this.standardDrawGraphicHandler(); +DKTools.Sprite.Selectable.prototype.processPageup = function() { + this.playCursorSound(); + this.updateInputData(); + this.deactivate(); + this.callHandler('pageup'); }; /** - * Sets the handler of draw of the text - * - * @param {Function} [handler=this.standardDrawTextHandler()] - Handler of draw of the text - * - * @see DKTools.Sprite.ProgressBar.prototype.standardDrawTextHandler + * Processes pagedown + * + * @see DKTools.Sprite.Selectable.prototype.playCursorSound + * @see DKTools.Sprite.Selectable.prototype.updateInputData + * @see DKTools.Sprite.Selectable.prototype.deactivate + * @see DKTools.Sprite.Selectable.prototype.callHandler */ -DKTools.Sprite.ProgressBar.prototype.setupDrawTextHandler = function(handler) { - /** - * @private - * @readonly - * @type {Function} - */ - this._drawTextHandler = handler || this.standardDrawTextHandler(); +DKTools.Sprite.Selectable.prototype.processPagedown = function() { + this.playCursorSound(); + this.updateInputData(); + this.deactivate(); + this.callHandler('pagedown'); }; -// set methods +// update methods /** - * Changes all parameters - * Returns the number of changed parameters + * Updates all * * @override - * - * @param {Object} [object={}] - Parameters - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the progress bar - * - * @param {Number} [object.valueStep] - Value step - * @param {Number} [object.maxValue] - Maximum value - * @param {Number} [object.value] - Value - * @param {String} [object.backgroundColor] - Background color - * @param {String} [object.progressColor] - Progress color - * @param {Function} [object.drawGraphicHandler] - Handler of draw of the graphic - * @param {Function} [object.drawTextHandler] - Handler of draw of the text - * - * @see DKTools.Sprite.prototype.setAll - * @see DKTools.Sprite.ProgressBar.prototype.setValueStep - * @see DKTools.Sprite.ProgressBar.prototype.setMaxValue - * @see DKTools.Sprite.ProgressBar.prototype.setValue - * @see DKTools.Sprite.ProgressBar.prototype.setBackgroundColor - * @see DKTools.Sprite.ProgressBar.prototype.setProgressColor - * @see DKTools.Sprite.ProgressBar.prototype.setDrawGraphicHandler - * @see DKTools.Sprite.ProgressBar.prototype.setDrawTextHandler - * @see DKTools.Sprite.ProgressBar.prototype.start - * @see DKTools.Sprite.ProgressBar.prototype.activate - * - * @returns {Number} Number of changed parameters + * + * @see DKTools.Sprite.Selectable.prototype.updateCursor */ -DKTools.Sprite.ProgressBar.prototype.setAll = function(object, blockStart, activate) { - object = object || {}; - const block = true; +DKTools.Sprite.Selectable.prototype.updateAll = function() { + DKTools.Sprite.Button.prototype.updateAll.call(this); + this.updateCursor(); +}; - let changed = DKTools.Sprite.prototype.setAll.call(this, object, block); +/** + * Updates the cursor + * + * @see DKTools.Sprite.Selectable.prototype.isHorizontal + * @see DKTools.Sprite.Selectable.prototype.isCursorAll + * @see DKTools.Sprite.Selectable.prototype.isCursorVisible + * @see DKTools.Sprite.Selectable.prototype.getCurrentCol + * @see DKTools.Sprite.Selectable.prototype.getTopCol + * @see DKTools.Sprite.Selectable.prototype.getBottomCol + * @see DKTools.Sprite.Selectable.prototype.getMaxRows + * @see DKTools.Sprite.Selectable.prototype.getItemHeight + * @see DKTools.Sprite.Selectable.prototype.setTopCol + * @see DKTools.Sprite.Selectable.prototype.setBottomCol + * @see DKTools.Sprite.Selectable.prototype.setCursorRect + * @see DKTools.Sprite.Selectable.prototype.resetScroll + * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex + * @see DKTools.Sprite.Selectable.prototype.getItemRectByIndex + */ +DKTools.Sprite.Selectable.prototype.updateCursor = function() { + if (this.isHorizontal()) { + const col = this.getCurrentCol(); - if (this.setValueStep(object.valueStep, block)) { - changed++; - } + if (col < this.getTopCol()) { + this.setTopCol(col); + } else if (col > this.getBottomCol()) { + this.setBottomCol(col); + } + } else { + const row = this.getCurrentRow(); - if (this.setMaxValue(object.maxValue, block)) { - changed++; + if (row < this.getTopRow()) { + this.setTopRow(row); + } else if (row > this.getBottomRow()) { + this.setBottomRow(row); + } } - if (this.setValue(object.value, block)) { - changed++; + if (this.isCursorAll()) { + const allRowsHeight = this.getMaxRows() * this.getItemHeight(); + this.setCursorRect(0, 0, this.realWidth, allRowsHeight); + this.resetScroll(); + } else if (this.isCursorVisible() || !this._cursorSprite.hasBitmap()) { + const rect = this.getItemRectByIndex(this._index); + this.setCursorRect(rect); + } else { + this.setCursorRect(Rectangle.emptyRectangle); } +}; - if (this.setBackgroundColor(object.backgroundColor, block)) { - changed++; - } - if (this.setProgressColor(object.progressColor, block)) { - changed++; - } - if (this.setDrawGraphicHandler(object.drawGraphicHandler, block)) { - changed++; - } - if (this.setDrawTextHandler(object.drawTextHandler, block)) { - changed++; - } - if (changed) { - if (!blockStart) { - this.start(); - } +//=========================================================================== +// DKTools.Sprite.ProgressBar +//=========================================================================== - if (activate) { - this.activate(); - } - } +DKTools.Sprite.ProgressBar.prototype = Object.create(DKTools.Sprite.prototype); +DKTools.Sprite.ProgressBar.prototype.constructor = DKTools.Sprite.ProgressBar; - return changed; -}; +// properties -/** - * Changes the value step - * Returns true if the change occurred - * - * @param {Number} [step] - Шаг значения - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.ProgressBar.prototype.setupValueStep - * @see DKTools.Sprite.ProgressBar.prototype.refreshAll - * - * @returns {Boolean} Change occurred - */ -DKTools.Sprite.ProgressBar.prototype.setValueStep = function(step, blockRefreshAll) { - if (this._valueStep === step) { - return false; - } +Object.defineProperties(DKTools.Sprite.ProgressBar.prototype, { - const lastStep = this._valueStep; - this.setupValueStep(step); + /** + * Value step + * + * @readonly + * @type {Number} + * @memberof DKTools.Sprite.ProgressBar.prototype + */ + valueStep: { + get: function() { + return this._valueStep; + }, + configurable: true + }, - if (this._valueStep === lastStep) { - return false; - } + /** + * Maximum value + * + * @readonly + * @type {Number} + * @memberof DKTools.Sprite.ProgressBar.prototype + */ + maxValue: { + get: function() { + return this._maxValue; + }, + configurable: true + }, - if (!blockRefreshAll) { - this.refreshAll(); - } + /** + * Value + * + * @readonly + * @type {Number} + * @memberof DKTools.Sprite.ProgressBar.prototype + */ + value: { + get: function() { + return this._value; + }, + configurable: true + }, - return true; -}; + /** + * Background color + * + * @readonly + * @type {String} + * @memberof DKTools.Sprite.ProgressBar.prototype + */ + backgroundColor: { + get: function() { + return this._backgroundColor; + }, + configurable: true + }, -/** - * Changes the maximum value - * Returns true if the change occurred - * - * @param {Number} [max] - Maximum value - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.ProgressBar.prototype.setupMaxValue - * @see DKTools.Sprite.ProgressBar.prototype.refreshAll - * - * @returns {Boolean} Change occurred - */ -DKTools.Sprite.ProgressBar.prototype.setMaxValue = function(max, blockRefreshAll) { - if (this._maxValue === max) { - return false; - } + /** + * Progress color + * + * @readonly + * @type {String} + * @memberof DKTools.Sprite.ProgressBar.prototype + */ + progressColor: { + get: function() { + return this._progressColor; + }, + configurable: true + }, - const lastMax = this._maxValue; - this.setupMaxValue(max); + /** + * Handler of draw of the graphic + * + * @readonly + * @type {Function} + * @memberof DKTools.Sprite.ProgressBar.prototype + */ + drawGraphicHandler: { + get: function() { + return this._drawGraphicHandler; + }, + configurable: true + }, - if (this._maxValue === lastMax) { - return false; + /** + * Handler of draw of the text + * + * @readonly + * @type {Function} + * @memberof DKTools.Sprite.ProgressBar.prototype + */ + drawTextHandler: { + get: function() { + return this._drawTextHandler; + }, + configurable: true } - if (!blockRefreshAll) { - this.refreshAll(); - } +}); - return true; -}; +// standard methods /** - * Changes the value - * Returns true if the change occurred - * - * @param {Number} [value] - Value - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.ProgressBar.prototype.setupValue - * @see DKTools.Sprite.ProgressBar.prototype.refreshAll - * @see DKTools.Sprite.ProgressBar.prototype.updateValueEvents + * Returns the standard activity of the progress bar * - * @returns {Boolean} Change occurred + * @override + * @returns {Boolean} Standard activity of the progress bar */ -DKTools.Sprite.ProgressBar.prototype.setValue = function(value, blockRefreshAll) { - if (this._value === value) { - return false; - } - - const lastValue = this._value; - this.setupValue(value); - - if (this._value === lastValue) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - this.updateValueEvents(); - - return true; +DKTools.Sprite.ProgressBar.prototype.standardActive = function() { + return false; }; /** - * Changes the background color - * Returns true if the change occurred - * - * @param {String} [color] - Background color - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.ProgressBar.prototype.setupBackgroundColor - * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * Returns the standard value step * - * @returns {Boolean} Change occurred + * @returns {Number} Standard value step */ -DKTools.Sprite.ProgressBar.prototype.setBackgroundColor = function(color, blockRefreshAll) { - if (this._backgroundColor === color) { - return false; - } - - const lastColor = this._backgroundColor; - this.setupBackgroundColor(color); - - if (this._backgroundColor === lastColor) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return true; +DKTools.Sprite.ProgressBar.prototype.standardValueStep = function() { + return 1; }; /** - * Changes the progress color - * Returns true if the change occurred - * - * @param {String} [color] - Progress color - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.ProgressBar.prototype.setupProgressColor - * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * Returns the standard maximum value * - * @returns {Boolean} Change occurred + * @returns {Number} Standard maximum value */ -DKTools.Sprite.ProgressBar.prototype.setProgressColor = function(color, blockRefreshAll) { - if (this._progressColor === color) { - return false; - } - - const lastColor = this._progressColor; - this.setupProgressColor(color); - - if (this._progressColor === lastColor) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return true; +DKTools.Sprite.ProgressBar.prototype.standardMaxValue = function() { + return 100; }; /** - * Changes the handler of draw of the graphic - * Returns true if the change occurred - * - * @param {Function} [handler] - Handler of draw of the graphic - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.ProgressBar.prototype.setupDrawGraphicHandler - * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * Returns the standard value * - * @returns {Boolean} Change occurred + * @returns {Number} Standard value */ -DKTools.Sprite.ProgressBar.prototype.setDrawGraphicHandler = function(handler, blockRefreshAll) { - if (this._drawGraphicHandler === handler) { - return false; - } - - this.setupDrawGraphicHandler(handler); - - if (!blockRefreshAll) { - this.refreshAll(); - } - - return true; +DKTools.Sprite.ProgressBar.prototype.standardValue = function() { + return 0; }; /** - * Changes the handler of draw of the text - * Returns true if the change occurred - * - * @param {Function} [handler] - Handler of draw of the text - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.ProgressBar.prototype.setupDrawTextHandler - * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * Returns the standard background color * - * @returns {Boolean} Change occurred + * @returns {String} Standard background color */ -DKTools.Sprite.ProgressBar.prototype.setDrawTextHandler = function(handler, blockRefreshAll) { - if (this._drawTextHandler === handler) { - return false; - } - - this.setupDrawTextHandler(handler); - - if (!blockRefreshAll) { - this.refreshAll(); - } +DKTools.Sprite.ProgressBar.prototype.standardBackgroundColor = function() { + return 'grey'; +}; - return true; +/** + * Returns the standard progress color + * + * @returns {String} Standard progress color + */ +DKTools.Sprite.ProgressBar.prototype.standardProgressColor = function() { + return '#33ccff'; }; -// can methods +/** + * Returns the standard handler of draw of the graphic + * + * @returns {null} Standard handler of draw of the graphic + */ +DKTools.Sprite.ProgressBar.prototype.standardDrawGraphicHandler = function() { + return null; +}; /** - * Returns true if the progress bar can clone the fixed bitmap + * Returns the standard handler of draw of the text * - * @override - * @returns {Boolean} Progress bar can clone the fixed bitmap + * @returns {null} Standard handler of draw of the text */ -DKTools.Sprite.ProgressBar.prototype.canCloneFixedBitmap = function() { - return false; +DKTools.Sprite.ProgressBar.prototype.standardDrawTextHandler = function() { + return null; }; -// is methods +// setup methods /** - * Returns true if the progress bar is horizontal + * Sets all parameters * - * @returns {Boolean} Progress bar is horizontal + * @override + * + * @param {Object | null} [object={}] - Parameters + * + * @param {Number} [object.valueStep] - Value step + * @param {Number} [object.maxValue] - Maximum value + * @param {Number} [object.value] - Value + * @param {String} [object.backgroundColor] - Background color + * @param {String} [object.progressColor] - Progress color + * @param {Function} [object.drawGraphicHandler] - Handler of draw of the graphic + * @param {Function} [object.drawTextHandler] - Handler of draw of the text + * + * @see DKTools.Sprite.prototype.setupAll + * @see DKTools.Sprite.ProgressBar.setupValueStep + * @see DKTools.Sprite.ProgressBar.setupMaxValue + * @see DKTools.Sprite.ProgressBar.setupValue + * @see DKTools.Sprite.ProgressBar.setupBackgroundColor + * @see DKTools.Sprite.ProgressBar.setupProgressColor + * @see DKTools.Sprite.ProgressBar.setupDrawGraphicHandler + * @see DKTools.Sprite.ProgressBar.setupDrawTextHandler */ -DKTools.Sprite.ProgressBar.prototype.isHorizontal = function() { - return this.width > this.height; +DKTools.Sprite.ProgressBar.prototype.setupAll = function(object) { + object = object || {}; + DKTools.Sprite.prototype.setupAll.call(this, object); + this.setupValueStep(object.valueStep); + this.setupMaxValue(object.maxValue); + this.setupValue(object.value); + this.setupBackgroundColor(object.progressColor); + this.setupProgressColor(object.progressColor); + this.setupDrawGraphicHandler(object.drawGraphicHandler); + this.setupDrawTextHandler(object.drawTextHandler); }; /** - * Returns true if the progress bar is vertical + * Sets the value step * - * @see DKTools.Sprite.ProgressBar.prototype.isHorizontal + * @param {Number} [step=this.standardValueStep()] - Value step * - * @returns {Boolean} Progress bar is vertical + * @see DKTools.Sprite.ProgressBar.prototype.standardValueStep */ -DKTools.Sprite.ProgressBar.prototype.isVertical = function() { - return !this.isHorizontal(); +DKTools.Sprite.ProgressBar.prototype.setupValueStep = function(step) { + /** + * @private + * @readonly + * @type {Number} + */ + this._valueStep = step || this.standardValueStep(); }; /** - * Returns true if the progress bar is empty + * Sets the maximum value * - * @returns {Boolean} Progress bar is empty + * @param {Number} [max=this.standardMaxValue()] - Maximum value + * + * @see DKTools.Sprite.ProgressBar.prototype.setupMaxValue */ -DKTools.Sprite.ProgressBar.prototype.isEmpty = function() { - return this._value === 0; +DKTools.Sprite.ProgressBar.prototype.setupMaxValue = function(max) { + /** + * @private + * @readonly + * @type {Number} + */ + this._maxValue = max || this.standardMaxValue(); }; /** - * Returns true if the progress bar is full + * Sets the value * - * @returns {Boolean} Progress bar is full + * @param {Number} [value=this.standardValue()] - Value + * + * @see DKTools.Sprite.ProgressBar.prototype.standardValue */ -DKTools.Sprite.ProgressBar.prototype.isFull = function() { - return this._value === this._maxValue; -}; +DKTools.Sprite.ProgressBar.prototype.setupValue = function(value) { + const max = this._maxValue; + const newValue = Math.max(0, Math.min(value, max)); -// events methods + /** + * @private + * @readonly + * @type {Number} + */ + this._value = Number.isNaN(newValue) ? this.standardValue() : newValue; +}; /** - * Updates the events + * Sets the background color * - * @override + * @param {String} [color=this.standardBackgroundColor()] - Background color * - * @see DKTools.Sprite.prototype.updateEvents - * @see DKTools.Sprite.ProgressBar.prototype.updateEmptyEvents - * @see DKTools.Sprite.ProgressBar.prototype.updateFullEvents + * @see DKTools.Sprite.ProgressBar.prototype.setupBackgroundColor */ -DKTools.Sprite.ProgressBar.prototype.updateEvents = function() { - DKTools.Sprite.prototype.updateEvents.call(this); - this.updateEmptyEvents(); - this.updateFullEvents(); +DKTools.Sprite.ProgressBar.prototype.setupBackgroundColor = function(color) { + /** + * @private + * @readonly + * @type {String} + */ + this._backgroundColor = color || this.standardBackgroundColor(); }; /** - * Updates the events with type: value + * Sets the progress color * - * @see DKTools.Sprite.ProgressBar.prototype.updateEventsContainer + * @param {String} [color=this.standardProgressColor()] - Progress color + * + * @see DKTools.Sprite.ProgressBar.prototype.standardProgressColor */ -DKTools.Sprite.ProgressBar.prototype.updateValueEvents = function() { - this.updateEventsContainer('value'); +DKTools.Sprite.ProgressBar.prototype.setupProgressColor = function(color) { + /** + * @private + * @readonly + * @type {String} + */ + this._progressColor = color || this.standardProgressColor(); }; /** - * Updates the events with type: empty + * Sets the handler of draw of the graphic * - * @see DKTools.Sprite.ProgressBar.prototype.isEmpty - * @see DKTools.Sprite.ProgressBar.prototype.updateEventsContainer + * @param {Function} [handler=this.standardDrawGraphicHandler()] - Handler of draw of the graphic + * + * @see DKTools.Sprite.ProgressBar.prototype.standardDrawGraphicHandler */ -DKTools.Sprite.ProgressBar.prototype.updateEmptyEvents = function() { - if (this.isEmpty()) { - this.updateEventsContainer('empty'); - } +DKTools.Sprite.ProgressBar.prototype.setupDrawGraphicHandler = function(handler) { + /** + * @private + * @readonly + * @type {Function} + */ + this._drawGraphicHandler = handler || this.standardDrawGraphicHandler(); }; /** - * Updates the events with type: full + * Sets the handler of draw of the text * - * @see DKTools.Sprite.ProgressBar.prototype.isFull - * @see DKTools.Sprite.ProgressBar.prototype.updateEventsContainer + * @param {Function} [handler=this.standardDrawTextHandler()] - Handler of draw of the text + * + * @see DKTools.Sprite.ProgressBar.prototype.standardDrawTextHandler */ -DKTools.Sprite.ProgressBar.prototype.updateFullEvents = function() { - if (this.isFull()) { - this.updateEventsContainer('full'); - } +DKTools.Sprite.ProgressBar.prototype.setupDrawTextHandler = function(handler) { + /** + * @private + * @readonly + * @type {Function} + */ + this._drawTextHandler = handler || this.standardDrawTextHandler(); }; +// set methods + /** - * Handler of update of animate the value + * Changes all parameters + * Returns the number of changed parameters * - * @private + * @override * - * @param {Number} value - Value - * @param {DKTools.Event} event - Event + * @param {Object} [object={}] - Parameters + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the progress bar + * + * @param {Number} [object.valueStep] - Value step + * @param {Number} [object.maxValue] - Maximum value + * @param {Number} [object.value] - Value + * @param {String} [object.backgroundColor] - Background color + * @param {String} [object.progressColor] - Progress color + * @param {Function} [object.drawGraphicHandler] - Handler of draw of the graphic + * @param {Function} [object.drawTextHandler] - Handler of draw of the text * + * @see DKTools.Sprite.prototype.setAll + * @see DKTools.Sprite.ProgressBar.prototype.setValueStep + * @see DKTools.Sprite.ProgressBar.prototype.setMaxValue * @see DKTools.Sprite.ProgressBar.prototype.setValue + * @see DKTools.Sprite.ProgressBar.prototype.setBackgroundColor + * @see DKTools.Sprite.ProgressBar.prototype.setProgressColor + * @see DKTools.Sprite.ProgressBar.prototype.setDrawGraphicHandler + * @see DKTools.Sprite.ProgressBar.prototype.setDrawTextHandler + * @see DKTools.Sprite.ProgressBar.prototype.start + * @see DKTools.Sprite.ProgressBar.prototype.activate + * + * @returns {Number} Number of changed parameters */ -DKTools.Sprite.ProgressBar.prototype._updateAnimateValue = function(value, event) { - const remainingTime = event.remainingTime; - const newValue = (this._value * (remainingTime - 1) + value) / remainingTime; +DKTools.Sprite.ProgressBar.prototype.setAll = function(object, blockStart, activate) { + object = object || {}; + const block = true; + + let changed = DKTools.Sprite.prototype.setAll.call(this, object, block); + + if (this.setValueStep(object.valueStep, block)) { + changed++; + } + + if (this.setMaxValue(object.maxValue, block)) { + changed++; + } + + if (this.setValue(object.value, block)) { + changed++; + } + + if (this.setBackgroundColor(object.backgroundColor, block)) { + changed++; + } + + if (this.setProgressColor(object.progressColor, block)) { + changed++; + } + + if (this.setDrawGraphicHandler(object.drawGraphicHandler, block)) { + changed++; + } + + if (this.setDrawTextHandler(object.drawTextHandler, block)) { + changed++; + } + + if (changed) { + if (!blockStart) { + this.start(); + } - this.setValue(newValue); -}; + if (activate) { + this.activate(); + } + } -/** - * Animates the value - * Returns the update event - * - * @param {Number} value - Value - * @param {Number} duration - Duration of animation - * - * @see DKTools.Sprite.ProgressBar.prototype.addEvent - * @see DKTools.Sprite.ProgressBar.prototype._updateAnimateValue - * - * @returns {DKTools.Event} Update event - */ -DKTools.Sprite.ProgressBar.prototype.animateValue = function(value, duration) { - return this.addEvent({ - type: 'update', - repeatTime: duration, - repeats: 0, - onUpdate: this._updateAnimateValue.bind(this, value) - }); + return changed; }; /** - * Animates the empty value - * Returns the update event + * Changes the value step + * Returns true if the change occurred * - * @param {Number} duration - Duration of animation + * @param {Number} [step] - Шаг значения + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.ProgressBar.prototype.animateValue + * @see DKTools.Sprite.ProgressBar.prototype.setupValueStep + * @see DKTools.Sprite.ProgressBar.prototype.refreshAll * - * @returns {DKTools.Event} Update event + * @returns {Boolean} Change occurred */ -DKTools.Sprite.ProgressBar.prototype.animateEmpty = function(duration) { - return this.animateValue(0, duration); +DKTools.Sprite.ProgressBar.prototype.setValueStep = function(step, blockRefreshAll) { + if (this._valueStep === step) { + return false; + } + + const lastStep = this._valueStep; + this.setupValueStep(step); + + if (this._valueStep === lastStep) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Animates the full value - * Returns the update event + * Changes the maximum value + * Returns true if the change occurred * - * @param {Number} duration - Duration of animation + * @param {Number} [max] - Maximum value + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.ProgressBar.prototype.animateValue + * @see DKTools.Sprite.ProgressBar.prototype.setupMaxValue + * @see DKTools.Sprite.ProgressBar.prototype.refreshAll * - * @returns {DKTools.Event} Update event + * @returns {Boolean} Change occurred */ -DKTools.Sprite.ProgressBar.prototype.aimateFull = function(duration) { - return this.animateValue(this._maxValue, duration); -}; +DKTools.Sprite.ProgressBar.prototype.setMaxValue = function(max, blockRefreshAll) { + if (this._maxValue === max) { + return false; + } -// _draw methods + const lastMax = this._maxValue; + this.setupMaxValue(max); -/** - * Draws the graphic of progress - * - * @private - * - * @see DKTools.Sprite.ProgressBar.prototype.hasDrawGraphicHandler - */ -DKTools.Sprite.ProgressBar.prototype._drawProgressGraphic = function() { - if (this.hasDrawGraphicHandler()) { - this._drawGraphicHandler(this); + if (this._maxValue === lastMax) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); } + + return true; }; /** - * Draws the text of progress + * Changes the value + * Returns true if the change occurred * - * @private + * @param {Number} [value] - Value + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.ProgressBar.prototype.hasDrawTextHandler + * @see DKTools.Sprite.ProgressBar.prototype.setupValue + * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * @see DKTools.Sprite.ProgressBar.prototype.updateValueEvents + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.ProgressBar.prototype._drawProgressText = function() { - if (this.hasDrawTextHandler()) { - this._drawTextHandler(this); +DKTools.Sprite.ProgressBar.prototype.setValue = function(value, blockRefreshAll) { + if (this._value === value) { + return false; } -}; -// draw methods + const lastValue = this._value; + this.setupValue(value); -/** - * Draws all - * - * @override - */ -DKTools.Sprite.ProgressBar.prototype.drawAll = function() { - DKTools.Sprite.prototype.drawAll.call(this); - this.drawProgress(); -}; + if (this._value === lastValue) { + return false; + } -/** - * Draws the progress - * - * @see DKTools.Sprite.ProgressBar.prototype._drawProgressGraphic - * @see DKTools.Sprite.ProgressBar.prototype._drawProgressText - */ -DKTools.Sprite.ProgressBar.prototype.drawProgress = function() { - this._drawProgressGraphic(); - this._drawProgressText(); -}; + if (!blockRefreshAll) { + this.refreshAll(); + } -// has methods + this.updateValueEvents(); -/** - * Returns true if the progress bar has the handler of draw of the graphic - * - * @returns {Boolean} Progress bar has the handler of draw of the graphic - */ -DKTools.Sprite.ProgressBar.prototype.hasDrawGraphicHandler = function() { - return !!this._drawGraphicHandler; + return true; }; /** - * Returns true if the progress bar has the handler of draw of the text + * Changes the background color + * Returns true if the change occurred * - * @returns {Boolean} Progress bar has the handler of draw of the text + * @param {String} [color] - Background color + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.ProgressBar.prototype.setupBackgroundColor + * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.ProgressBar.prototype.hasDrawTextHandler = function() { - return !!this._drawTextHandler; -}; +DKTools.Sprite.ProgressBar.prototype.setBackgroundColor = function(color, blockRefreshAll) { + if (this._backgroundColor === color) { + return false; + } -// get methods + const lastColor = this._backgroundColor; + this.setupBackgroundColor(color); -/** - * Returns the current value in percent - * - * @returns {Number} Current value in percent - */ -DKTools.Sprite.ProgressBar.prototype.getPercents = function() { - return Math.ceil(this._value / this._maxValue * 100); -}; + if (this._backgroundColor === lastColor) { + return false; + } -/** - * Returns the previous value - * - * @returns {Number} Previous value - */ -DKTools.Sprite.ProgressBar.prototype.getPrevValue = function() { - return Math.max(0, this._value - this._valueStep); -}; + if (!blockRefreshAll) { + this.refreshAll(); + } -/** - * Returns the next value - * - * @returns {Number} Next value - */ -DKTools.Sprite.ProgressBar.prototype.getNextValue = function() { - return Math.min(this._value + this._valueStep, this._maxValue); + return true; }; -// value methods - /** - * Adds the value + * Changes the progress color + * Returns true if the change occurred * - * @param {Number} value - Value + * @param {String} [color] - Progress color + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.ProgressBar.prototype.setValue + * @see DKTools.Sprite.ProgressBar.prototype.setupProgressColor + * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.ProgressBar.prototype.addValue = function(value) { - if (value) { - this.setValue(this._value + value); +DKTools.Sprite.ProgressBar.prototype.setProgressColor = function(color, blockRefreshAll) { + if (this._progressColor === color) { + return false; } + + const lastColor = this._progressColor; + this.setupProgressColor(color); + + if (this._progressColor === lastColor) { + return false; + } + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Subtracts the value + * Changes the handler of draw of the graphic + * Returns true if the change occurred * - * @param {Number} value - Value + * @param {Function} [handler] - Handler of draw of the graphic + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @see DKTools.Sprite.ProgressBar.prototype.addValue + * @see DKTools.Sprite.ProgressBar.prototype.setupDrawGraphicHandler + * @see DKTools.Sprite.ProgressBar.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.ProgressBar.prototype.subValue = function(value) { - this.addValue(-value); +DKTools.Sprite.ProgressBar.prototype.setDrawGraphicHandler = function(handler, blockRefreshAll) { + if (this._drawGraphicHandler === handler) { + return false; + } + + this.setupDrawGraphicHandler(handler); + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; /** - * Sets the previous value + * Changes the handler of draw of the text * Returns true if the change occurred * - * @see DKTools.Sprite.ProgressBar.prototype.getPrevValue - * @see DKTools.Sprite.ProgressBar.prototype.setValue + * @param {Function} [handler] - Handler of draw of the text + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.ProgressBar.prototype.setupDrawTextHandler + * @see DKTools.Sprite.ProgressBar.prototype.refreshAll * * @returns {Boolean} Change occurred */ -DKTools.Sprite.ProgressBar.prototype.prevValue = function() { - return this.setValue(this.getPrevValue()); +DKTools.Sprite.ProgressBar.prototype.setDrawTextHandler = function(handler, blockRefreshAll) { + if (this._drawTextHandler === handler) { + return false; + } + + this.setupDrawTextHandler(handler); + + if (!blockRefreshAll) { + this.refreshAll(); + } + + return true; }; +// can methods + /** - * Sets the next value - * Returns true if the change occurred - * - * @see DKTools.Sprite.ProgressBar.prototype.getNextValue - * @see DKTools.Sprite.ProgressBar.prototype.setValue + * Returns true if the progress bar can clone the fixed bitmap * - * @returns {Boolean} Change occurred + * @override + * @returns {Boolean} Progress bar can clone the fixed bitmap */ -DKTools.Sprite.ProgressBar.prototype.nextValue = function() { - return this.setValue(this.getNextValue()); +DKTools.Sprite.ProgressBar.prototype.canCloneFixedBitmap = function() { + return false; }; +// is methods + /** - * Makes the progress bar empty + * Returns true if the progress bar is horizontal * - * @see DKTools.Sprite.ProgressBar.prototype.setValue + * @returns {Boolean} Progress bar is horizontal */ -DKTools.Sprite.ProgressBar.prototype.makeEmpty = function() { - this.setValue(0); +DKTools.Sprite.ProgressBar.prototype.isHorizontal = function() { + return this.width > this.height; }; /** - * Makes the progress bar full + * Returns true if the progress bar is vertical * - * @see DKTools.Sprite.ProgressBar.prototype.setValue + * @see DKTools.Sprite.ProgressBar.prototype.isHorizontal + * + * @returns {Boolean} Progress bar is vertical */ -DKTools.Sprite.ProgressBar.prototype.makeFull = function() { - this.setValue(this._maxValue); +DKTools.Sprite.ProgressBar.prototype.isVertical = function() { + return !this.isHorizontal(); }; - - - - -//=========================================================================== -// DKTools.Sprite.ProgressBar.Rectangle -//=========================================================================== - -DKTools.Sprite.ProgressBar.Rectangle.prototype = Object.create(DKTools.Sprite.ProgressBar.prototype); -DKTools.Sprite.ProgressBar.Rectangle.prototype.constructor = DKTools.Sprite.ProgressBar.Rectangle; - -// standard methods - /** - * Returns the standard handler of draw of the graphic for horizontal progress bar + * Returns true if the progress bar is empty * - * @returns {Function} Standard handler of draw of the graphic for horizontal progress bar + * @returns {Boolean} Progress bar is empty */ -DKTools.Sprite.ProgressBar.Rectangle.prototype.standardHorizontalDrawGraphicHandler = function() { - return function() { - this.fillAll(this._backgroundColor); - - if (!this.isEmpty()) { - this.fillRect({ - color: this._progressColor, - width: this._value * this.realWidth / this._maxValue - }); - } - }.bind(this); +DKTools.Sprite.ProgressBar.prototype.isEmpty = function() { + return this._value === 0; }; /** - * Returns the standard handler of draw of the graphic for vertical progress bar + * Returns true if the progress bar is full * - * @returns {Function} Standard handler of draw of the graphic for vertical progress bar + * @returns {Boolean} Progress bar is full */ -DKTools.Sprite.ProgressBar.Rectangle.prototype.standardVerticalDrawGraphicHandler = function() { - return function() { - this.fillAll(this._backgroundColor); - - if (!this.isEmpty()) { - const realHeight = this.realHeight; - const height = this._value * realHeight / this._maxValue; - - this.fillRect({ - color: this._progressColor, - y: realHeight - height, - width: this.realWidth, - height - }); - } - }.bind(this); +DKTools.Sprite.ProgressBar.prototype.isFull = function() { + return this._value === this._maxValue; }; +// events methods + /** - * Returns the standard handler of draw of the graphic + * Updates the events * * @override * - * @see DKTools.Sprite.ProgressBar.Rectangle.prototype.isHorizontal - * @see DKTools.Sprite.ProgressBar.Rectangle.prototype.standardHorizontalDrawGraphicHandler - * @see DKTools.Sprite.ProgressBar.Rectangle.prototype.standardVerticalDrawGraphicHandler - * - * @returns {Function} Standard handler of draw of the graphic + * @see DKTools.Sprite.prototype.updateEvents + * @see DKTools.Sprite.ProgressBar.prototype.updateEmptyEvents + * @see DKTools.Sprite.ProgressBar.prototype.updateFullEvents */ -DKTools.Sprite.ProgressBar.Rectangle.prototype.standardDrawGraphicHandler = function() { - return function(progressBar) { - let handler; - - if (this.isHorizontal()) { - handler = this.standardHorizontalDrawGraphicHandler(); - } else { - handler = this.standardVerticalDrawGraphicHandler(); - } - - if (handler) { - handler(progressBar); - } - }.bind(this); +DKTools.Sprite.ProgressBar.prototype.updateEvents = function() { + DKTools.Sprite.prototype.updateEvents.call(this); + this.updateEmptyEvents(); + this.updateFullEvents(); }; /** - * Returns the standard handler of draw of the text + * Updates the events with type: value * - * @override - * @returns {Function} Standard handler of draw of the text + * @see DKTools.Sprite.ProgressBar.prototype.updateEventsContainer */ -DKTools.Sprite.ProgressBar.Rectangle.prototype.standardDrawTextHandler = function() { - return function() { - const percents = this.getPercents(); - const text = `${percents}%`; - - this.drawText(text, { - height: this.realHeight - }); - }.bind(this); +DKTools.Sprite.ProgressBar.prototype.updateValueEvents = function() { + this.updateEventsContainer('value'); }; - - - - -//=========================================================================== -// DKTools.Sprite.ProgressBar.Circle -//=========================================================================== - -DKTools.Sprite.ProgressBar.Circle.prototype = Object.create(DKTools.Sprite.ProgressBar.prototype); -DKTools.Sprite.ProgressBar.Circle.prototype.constructor = DKTools.Sprite.ProgressBar.Circle; - -// properties - -Object.defineProperties(DKTools.Sprite.ProgressBar.Circle.prototype, { - - /** - * Line width - * - * @readonly - * @type {Number} - * @memberof DKTools.Sprite.ProgressBar.Circle.prototype - */ - lineWidth: { - get: function() { - return this._lineWidth; - }, - configurable: true +/** + * Updates the events with type: empty + * + * @see DKTools.Sprite.ProgressBar.prototype.isEmpty + * @see DKTools.Sprite.ProgressBar.prototype.updateEventsContainer + */ +DKTools.Sprite.ProgressBar.prototype.updateEmptyEvents = function() { + if (this.isEmpty()) { + this.updateEventsContainer('empty'); } - -}); - -// standard methods +}; /** - * Returns the standard handler of draw of the graphic + * Updates the events with type: full * - * @override - * @returns {Function} Standard handler of draw of the graphic + * @see DKTools.Sprite.ProgressBar.prototype.isFull + * @see DKTools.Sprite.ProgressBar.prototype.updateEventsContainer */ -DKTools.Sprite.ProgressBar.Circle.prototype.standardDrawGraphicHandler = function() { - return function() { - const lineWidth = this._lineWidth; - const realWidth = this.realWidth; - const radius = (realWidth - lineWidth) / 2; - const x = radius + lineWidth / 2; - const y = x; - - this.strokeArc({ - x, - y, - radius, - color: this._backgroundColor, - lineWidth - }); - - this.strokeArc({ - x, - y, - radius, - startAngle: -Math.PI / 2, - endAngle: -Math.PI / 2 + Math.PI * 2 * this._value / this._maxValue, - color: this._progressColor, - lineWidth - }); - }.bind(this); +DKTools.Sprite.ProgressBar.prototype.updateFullEvents = function() { + if (this.isFull()) { + this.updateEventsContainer('full'); + } }; /** - * Returns the standard handler of draw of the text + * Handler of update of animate the value * - * @override - * @returns {Function} Standard handler of draw of the text + * @private + * + * @param {Number} value - Value + * @param {DKTools.Event} event - Event + * + * @see DKTools.Sprite.ProgressBar.prototype.setValue */ -DKTools.Sprite.ProgressBar.Circle.prototype.standardDrawTextHandler = function() { - return function() { - const percents = this.getPercents(); - const text = `${percents}%`; - this.drawText(text, { height: this.realHeight }); - }.bind(this); +DKTools.Sprite.ProgressBar.prototype._updateAnimateValue = function(value, event) { + const remainingTime = event.remainingTime; + const newValue = (this._value * (remainingTime - 1) + value) / remainingTime; + + this.setValue(newValue); }; /** - * Returns the standard line width + * Animates the value + * Returns the update event * - * @returns {Number} Standard line width + * @param {Number} value - Value + * @param {Number} duration - Duration of animation + * + * @see DKTools.Sprite.ProgressBar.prototype.addEvent + * @see DKTools.Sprite.ProgressBar.prototype._updateAnimateValue + * + * @returns {DKTools.Event} Update event */ -DKTools.Sprite.ProgressBar.Circle.prototype.standardLineWidth = function() { - return 10; +DKTools.Sprite.ProgressBar.prototype.animateValue = function(value, duration) { + return this.addEvent({ + type: 'update', + repeatTime: duration, + repeats: 0, + onUpdate: this._updateAnimateValue.bind(this, value) + }); }; -// setup methods - /** - * Sets all parameters - * - * @override + * Animates the empty value + * Returns the update event * - * @param {Object} [object={}] - Parameters + * @param {Number} duration - Duration of animation * - * @param {Number} [object.lineWidth] - Line width + * @see DKTools.Sprite.ProgressBar.prototype.animateValue * - * @see DKTools.Sprite.ProgressBar.prototype.setupAll - * @see DKTools.Sprite.ProgressBar.Circle.prototype.setupLineWidth + * @returns {DKTools.Event} Update event */ -DKTools.Sprite.ProgressBar.Circle.prototype.setupAll = function(object) { - object = object || {}; - DKTools.Sprite.ProgressBar.prototype.setupAll.call(this, object); - this.setupLineWidth(object.lineWidth); +DKTools.Sprite.ProgressBar.prototype.animateEmpty = function(duration) { + return this.animateValue(0, duration); }; /** - * Sets the line width + * Animates the full value + * Returns the update event * - * @param {Number} [width=this.standardLineWidth()] - Line width + * @param {Number} duration - Duration of animation * - * @see DKTools.Sprite.ProgressBar.Circle.prototype.standardLineWidth + * @see DKTools.Sprite.ProgressBar.prototype.animateValue + * + * @returns {DKTools.Event} Update event */ -DKTools.Sprite.ProgressBar.Circle.prototype.setupLineWidth = function(width) { - /** - * @private - * @readonly - * @type {Number} - */ - this._lineWidth = width || this.standardLineWidth(); +DKTools.Sprite.ProgressBar.prototype.aimateFull = function(duration) { + return this.animateValue(this._maxValue, duration); }; -// set methods +// _draw methods /** - * Changes all parameters - * Returns the number of changed parameters - * - * @override - * - * @param {Object} [object={}] - Parameters - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the progress bar - * - * @param {Number} [object.lineWidth] - Line width + * Draws the graphic of progress * - * @see DKTools.Sprite.ProgressBar.prototype.setAll - * @see DKTools.Sprite.ProgressBar.Circle.prototype.setLineWidth - * @see DKTools.Sprite.ProgressBar.Circle.prototype.start - * @see DKTools.Sprite.ProgressBar.Circle.prototype.activate + * @private * - * @returns {Number} Number of changed parameters + * @see DKTools.Sprite.ProgressBar.prototype.hasDrawGraphicHandler */ -DKTools.Sprite.ProgressBar.Circle.prototype.setAll = function(object, blockStart, activate) { - object = object || {}; - const block = true; - let changed = DKTools.Sprite.ProgressBar.prototype.setAll.call(this, object, block); - - if (this.setLineWidth(object.lineWidth, block)) { - changed++; - } - - if (changed) { - if (!blockStart) { - this.start(); - } - - if (activate) { - this.activate(); - } +DKTools.Sprite.ProgressBar.prototype._drawProgressGraphic = function() { + if (this.hasDrawGraphicHandler()) { + this._drawGraphicHandler(this); } - - return changed; }; /** - * Changes the line width - * Returns true if the change occurred - * - * @param {Number} [width] - Line width - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * Draws the text of progress * - * @see DKTools.Sprite.ProgressBar.Circle.prototype.setupLineWidth - * @see DKTools.Sprite.ProgressBar.Circle.prototype.refreshAll + * @private * - * @returns {Boolean} Change occurred + * @see DKTools.Sprite.ProgressBar.prototype.hasDrawTextHandler */ -DKTools.Sprite.ProgressBar.Circle.prototype.setLineWidth = function(width, blockRefreshAll) { - if (this._lineWidth === width) { - return false; - } - - const lastWidth = this._lineWidth; - this.setupLineWidth(width); - - if (this._lineWidth === lastWidth) { - return false; - } - - if (!blockRefreshAll) { - this.refreshAll(); +DKTools.Sprite.ProgressBar.prototype._drawProgressText = function() { + if (this.hasDrawTextHandler()) { + this._drawTextHandler(this); } - - return true; }; - - - - -//=========================================================================== -// DKTools.Sprite.ProgressBar.SemiCircle -//=========================================================================== - -DKTools.Sprite.ProgressBar.SemiCircle.prototype = Object.create(DKTools.Sprite.ProgressBar.Circle.prototype); -DKTools.Sprite.ProgressBar.SemiCircle.prototype.constructor = DKTools.Sprite.ProgressBar.SemiCircle; +// draw methods /** - * Returns the standard handler of draw of the graphic + * Draws all * * @override - * @returns {Function} Standard handler of draw of the graphic */ -DKTools.Sprite.ProgressBar.SemiCircle.prototype.standardDrawGraphicHandler = function() { - return function() { - const lineWidth = this._lineWidth; - const realWidth = this.realWidth; - const radius = (realWidth - lineWidth) / 2; - const x = radius + lineWidth / 2; - const y = this.realHeight; - - this.strokeArc({ - x, - y, - radius, - startAngle: Math.PI, - color: this._backgroundColor, - lineWidth - }); - - this.strokeArc({ - x, - y, - radius, - startAngle: Math.PI, - endAngle: -Math.PI + Math.PI * this._value / this._maxValue, - color: this._progressColor, - lineWidth - }); - }.bind(this); +DKTools.Sprite.ProgressBar.prototype.drawAll = function() { + DKTools.Sprite.prototype.drawAll.call(this); + this.drawProgress(); }; +/** + * Draws the progress + * + * @see DKTools.Sprite.ProgressBar.prototype._drawProgressGraphic + * @see DKTools.Sprite.ProgressBar.prototype._drawProgressText + */ +DKTools.Sprite.ProgressBar.prototype.drawProgress = function() { + this._drawProgressGraphic(); + this._drawProgressText(); +}; +// has methods +/** + * Returns true if the progress bar has the handler of draw of the graphic + * + * @returns {Boolean} Progress bar has the handler of draw of the graphic + */ +DKTools.Sprite.ProgressBar.prototype.hasDrawGraphicHandler = function() { + return !!this._drawGraphicHandler; +}; +/** + * Returns true if the progress bar has the handler of draw of the text + * + * @returns {Boolean} Progress bar has the handler of draw of the text + */ +DKTools.Sprite.ProgressBar.prototype.hasDrawTextHandler = function() { + return !!this._drawTextHandler; +}; -//=========================================================================== -// DKTools.Sprite.CheckBox -//=========================================================================== - -DKTools.Sprite.CheckBox.prototype = Object.create(DKTools.Sprite.Button.prototype); -DKTools.Sprite.CheckBox.prototype.constructor = DKTools.Sprite.CheckBox; - -// properties - -Object.defineProperties(DKTools.Sprite.CheckBox.prototype, { - - /** - * Checked - * - * @readonly - * @type {Boolean} - * @memberof DKTools.Sprite.CheckBox.prototype - */ - checked: { - get: function() { - return this._checked; - }, - configurable: true - }, - - /** - * Checked graphic - * - * @readonly - * @type {Bitmap | String | Object} - * @memberof DKTools.Sprite.CheckBox.prototype - */ - checkedGraphic: { - get: function() { - return this._checkedGraphic; - }, - configurable: true - }, - - /** - * Unchecked graphic - * - * @readonly - * @type {Bitmap | String | Object} - * @memberof DKTools.Sprite.CheckBox.prototype - */ - uncheckedGraphic: { - get: function() { - return this._uncheckedGraphic; - }, - configurable: true - }, - -}); - -// standard methods +// get methods /** - * Returns the stadnard checked + * Returns the current value in percent * - * @returns {Boolean} Checked + * @returns {Number} Current value in percent */ -DKTools.Sprite.CheckBox.prototype.standardChecked = function() { - return false; +DKTools.Sprite.ProgressBar.prototype.getPercents = function() { + return Math.ceil(this._value / this._maxValue * 100); }; /** - * Returns the stadnard checked graphic + * Returns the previous value * - * @returns {null} Checked graphic + * @returns {Number} Previous value */ -DKTools.Sprite.CheckBox.prototype.standardCheckedGraphic = function() { - return null; +DKTools.Sprite.ProgressBar.prototype.getPrevValue = function() { + return Math.max(0, this._value - this._valueStep); }; /** - * Returns the stadnard unchecked graphic + * Returns the next value * - * @returns {null} Unchecked graphic + * @returns {Number} Next value */ -DKTools.Sprite.CheckBox.prototype.standardUncheckedGraphic = function() { - return null; +DKTools.Sprite.ProgressBar.prototype.getNextValue = function() { + return Math.min(this._value + this._valueStep, this._maxValue); }; -// setup methods +// value methods /** - * Sets all parameters - * - * @override - * - * @param {Object} [object={}] - Parameters + * Adds the value * - * @param {Boolean} [object.checked] - Checked - * @param {Bitmap | String | Object} [object.checkedGraphic] - Checked graphic - * @param {Bitmap | String | Object} [object.uncheckedGraphic] - Unchecked graphic + * @param {Number} value - Value * - * @see DKTools.Sprite.Button.prototype.setupAll - * @see DKTools.Sprite.CheckBox.prototype.setupChecked - * @see DKTools.Sprite.CheckBox.prototype.setupCheckedGraphic - * @see DKTools.Sprite.CheckBox.prototype.setupUncheckedGraphic + * @see DKTools.Sprite.ProgressBar.prototype.setValue */ -DKTools.Sprite.CheckBox.prototype.setupAll = function(object) { - DKTools.Sprite.Button.prototype.setupAll.call(this, object); - this.setupChecked(object.checked); - this.setupCheckedGraphic(object.checkedGraphic); - this.setupUncheckedGraphic(object.uncheckedGraphic); +DKTools.Sprite.ProgressBar.prototype.addValue = function(value) { + if (value) { + this.setValue(this._value + value); + } }; /** - * Sets the checked + * Subtracts the value * - * @param {Boolean} [checked=this.standardChecked()] - Checked + * @param {Number} value - Value * - * @see DKTools.Sprite.CheckBox.prototype.standardChecked + * @see DKTools.Sprite.ProgressBar.prototype.addValue */ -DKTools.Sprite.CheckBox.prototype.setupChecked = function(checked) { - /** - * @private - * @readonly - * @type {Boolean} - */ - this._checked = checked == null ? this.standardChecked() : checked; +DKTools.Sprite.ProgressBar.prototype.subValue = function(value) { + this.addValue(-value); }; /** - * Sets the checked graphic + * Sets the previous value + * Returns true if the change occurred * - * @param {Bitmap | String | Object} [graphic=this.standardCheckedGraphic()] - Checked graphic + * @see DKTools.Sprite.ProgressBar.prototype.getPrevValue + * @see DKTools.Sprite.ProgressBar.prototype.setValue * - * @see DKTools.Sprite.CheckBox.prototype.standardCheckedGraphic + * @returns {Boolean} Change occurred */ -DKTools.Sprite.CheckBox.prototype.setupCheckedGraphic = function(graphic) { - /** - * @private - * @readonly - * @type {Bitmap | String | Object} - */ - this._checkedGraphic = graphic || this.standardCheckedGraphic(); +DKTools.Sprite.ProgressBar.prototype.prevValue = function() { + return this.setValue(this.getPrevValue()); }; /** - * Sets the unchecked graphic + * Sets the next value + * Returns true if the change occurred * - * @param {Bitmap | String | Object} [graphic=this.standardUncheckedGraphic()] - Unchecked graphic + * @see DKTools.Sprite.ProgressBar.prototype.getNextValue + * @see DKTools.Sprite.ProgressBar.prototype.setValue * - * @see DKTools.Sprite.CheckBox.prototype.standardUncheckedGraphic + * @returns {Boolean} Change occurred */ -DKTools.Sprite.CheckBox.prototype.setupUncheckedGraphic = function(graphic) { - /** - * @private - * @readonly - * @type {Bitmap | String | Object} - */ - this._uncheckedGraphic = graphic || this.standardUncheckedGraphic(); +DKTools.Sprite.ProgressBar.prototype.nextValue = function() { + return this.setValue(this.getNextValue()); }; -// set methods - /** - * Changes all parameters - * Returns the number of changed parameters - * - * @override - * - * @param {Object} [object={}] - Parameters - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the check box - * - * @param {Boolean} [object.checked] - Checked - * @param {Bitmap | String | Object} [object.checkedGraphic] - Checked graphic - * @param {Bitmap | String | Object} [object.uncheckedGraphic] - Unchecked graphic + * Makes the progress bar empty * - * @see DKTools.Sprite.Button.prototype.setAll - * @see DKTools.Sprite.CheckBox.prototype.setChecked - * @see DKTools.Sprite.CheckBox.prototype.setCheckedGraphic - * @see DKTools.Sprite.CheckBox.prototype.setUncheckedGraphic - * @see DKTools.Sprite.CheckBox.prototype.start - * @see DKTools.Sprite.CheckBox.prototype.activate + * @see DKTools.Sprite.ProgressBar.prototype.setValue + */ +DKTools.Sprite.ProgressBar.prototype.makeEmpty = function() { + this.setValue(0); +}; + +/** + * Makes the progress bar full * - * @returns {Number} Number of changed parameters + * @see DKTools.Sprite.ProgressBar.prototype.setValue */ -DKTools.Sprite.CheckBox.prototype.setAll = function(object, blockStart, activate) { - object = object || {}; - const block = true; - let changed = DKTools.Sprite.Button.prototype.setAll.call(this, object, block); +DKTools.Sprite.ProgressBar.prototype.makeFull = function() { + this.setValue(this._maxValue); +}; - if (this.setChecked(object.checked, block)) { - changed++; - } - if (this.setCheckedGraphic(object.checkedGraphic, block)) { - changed++; - } - if (this.setUncheckedGraphic(object.uncheckedGraphic, block)) { - changed++; - } - if (changed) { - if (!blockStart) { - this.start(); - } - if (activate) { - this.activate(); - } - } +//=========================================================================== +// DKTools.Sprite.ProgressBar.Rectangle +//=========================================================================== - return changed; -}; +DKTools.Sprite.ProgressBar.Rectangle.prototype = Object.create(DKTools.Sprite.ProgressBar.prototype); +DKTools.Sprite.ProgressBar.Rectangle.prototype.constructor = DKTools.Sprite.ProgressBar.Rectangle; + +// standard methods /** - * Changes the checked - * Returns true if the change occurred - * - * @param {Boolean} [checked] - - * @param {Boolean} [blockRefreshAll=false] - - * - * @see DKTools.Sprite.CheckBox.prototype.setupChecked - * @see DKTools.Sprite.CheckBox.prototype.refreshAll + * Returns the standard handler of draw of the graphic for horizontal progress bar * - * @returns {Boolean} Change occurred + * @returns {Function} Standard handler of draw of the graphic for horizontal progress bar */ -DKTools.Sprite.CheckBox.prototype.setChecked = function(checked, blockRefreshAll) { - if (this._checked === checked) { - return false; - } +DKTools.Sprite.ProgressBar.Rectangle.prototype.standardHorizontalDrawGraphicHandler = function() { + return function() { + this.fillAll(this._backgroundColor); - const lastChecked = this._checked; - this.setupChecked(checked); + if (!this.isEmpty()) { + this.fillRect({ + color: this._progressColor, + width: this._value * this.realWidth / this._maxValue + }); + } + }.bind(this); +}; - if (this._checked === lastChecked) { - return false; - } +/** + * Returns the standard handler of draw of the graphic for vertical progress bar + * + * @returns {Function} Standard handler of draw of the graphic for vertical progress bar + */ +DKTools.Sprite.ProgressBar.Rectangle.prototype.standardVerticalDrawGraphicHandler = function() { + return function() { + this.fillAll(this._backgroundColor); - if (!blockRefreshAll) { - this.refreshAll(); - } + if (!this.isEmpty()) { + const realHeight = this.realHeight; + const height = this._value * realHeight / this._maxValue; - return true; + this.fillRect({ + color: this._progressColor, + y: realHeight - height, + width: this.realWidth, + height + }); + } + }.bind(this); }; /** - * Changes the checked graphic - * Returns true if the change occurred + * Returns the standard handler of draw of the graphic * - * @param {Bitmap | String | Object} [graphic] - Checked graphic - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * @override * - * @see DKTools.Sprite.CheckBox.prototype.setupCheckedGraphic - * @see DKTools.Sprite.CheckBox.prototype.refreshAll + * @see DKTools.Sprite.ProgressBar.Rectangle.prototype.isHorizontal + * @see DKTools.Sprite.ProgressBar.Rectangle.prototype.standardHorizontalDrawGraphicHandler + * @see DKTools.Sprite.ProgressBar.Rectangle.prototype.standardVerticalDrawGraphicHandler * - * @returns {Boolean} Change occurred + * @returns {Function} Standard handler of draw of the graphic */ -DKTools.Sprite.CheckBox.prototype.setCheckedGraphic = function(graphic, blockRefreshAll) { - const checkedGraphic = this._checkedGraphic; - - if (checkedGraphic == graphic) { - return false; - } - - if (checkedGraphic instanceof Bitmap) { - this.setupCheckedGraphic(graphic); - } else if (DKTools.Utils.isString(checkedGraphic) || checkedGraphic instanceof Object) { - const lastGraphic = checkedGraphic; - this.setupCheckedGraphic(graphic); - - if (_.isEqual(this._checkedGraphic, lastGraphic)) { - return false; - } - } else { - return false; - } +DKTools.Sprite.ProgressBar.Rectangle.prototype.standardDrawGraphicHandler = function() { + return function(progressBar) { + let handler; - if (!blockRefreshAll) { - this.refreshAll(); - } + if (this.isHorizontal()) { + handler = this.standardHorizontalDrawGraphicHandler(); + } else { + handler = this.standardVerticalDrawGraphicHandler(); + } - return true; + if (handler) { + handler(progressBar); + } + }.bind(this); }; /** - * Changes the unchecked graphic - * Returns true if the change occurred - * - * @param {Bitmap | String | Object} [graphic] - Unchecked graphic - * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function - * - * @see DKTools.Sprite.CheckBox.prototype.setupUncheckedGraphic - * @see DKTools.Sprite.CheckBox.prototype.refreshAll + * Returns the standard handler of draw of the text * - * @returns {Boolean} Change occurred + * @override + * @returns {Function} Standard handler of draw of the text */ -DKTools.Sprite.CheckBox.prototype.setUncheckedGraphic = function(graphic, blockRefreshAll) { - const uncheckedGraphic = this._uncheckedGraphic; +DKTools.Sprite.ProgressBar.Rectangle.prototype.standardDrawTextHandler = function() { + return function() { + const percents = this.getPercents(); + const text = `${percents}%`; - if (uncheckedGraphic == graphic) { - return false; - } + this.drawText(text, { + height: this.realHeight + }); + }.bind(this); +}; - if (uncheckedGraphic instanceof Bitmap) { - this.setupUncheckedGraphic(graphic); - } else if (DKTools.Utils.isString(uncheckedGraphic) || uncheckedGraphic instanceof Object) { - const lastGraphic = uncheckedGraphic; - this.setupUncheckedGraphic(graphic); - if (_.isEqual(this._uncheckedGraphic, lastGraphic)) { - return false; - } - } else { - return false; - } - if (!blockRefreshAll) { - this.refreshAll(); + + +//=========================================================================== +// DKTools.Sprite.ProgressBar.Circle +//=========================================================================== + +DKTools.Sprite.ProgressBar.Circle.prototype = Object.create(DKTools.Sprite.ProgressBar.prototype); +DKTools.Sprite.ProgressBar.Circle.prototype.constructor = DKTools.Sprite.ProgressBar.Circle; + +// properties + +Object.defineProperties(DKTools.Sprite.ProgressBar.Circle.prototype, { + + /** + * Line width + * + * @readonly + * @type {Number} + * @memberof DKTools.Sprite.ProgressBar.Circle.prototype + */ + lineWidth: { + get: function() { + return this._lineWidth; + }, + configurable: true } - return true; -}; +}); -// _refresh methods +// standard methods /** - * Refreshes the checked graphic - * - * @private - * - * @see DKTools.Sprite.CheckBox.prototype.loadBitmap + * Returns the standard handler of draw of the graphic + * + * @override + * @returns {Function} Standard handler of draw of the graphic */ -DKTools.Sprite.CheckBox.prototype._refreshCheckedGraphic = function() { - let bitmapObject = null; +DKTools.Sprite.ProgressBar.Circle.prototype.standardDrawGraphicHandler = function() { + return function() { + const lineWidth = this._lineWidth; + const realWidth = this.realWidth; + const radius = (realWidth - lineWidth) / 2; + const x = radius + lineWidth / 2; + const y = x; - if (DKTools.Utils.isString(this._checkedGraphic)) { - bitmapObject = { - folder: this._graphicFolder, - filename: this._checkedGraphic - }; - } else if (this._checkedGraphic instanceof Object) { - bitmapObject = this._checkedGraphic; - } + this.strokeArc({ + x, + y, + radius, + color: this._backgroundColor, + lineWidth + }); - if (bitmapObject) { - this.loadBitmap(bitmapObject); - } + this.strokeArc({ + x, + y, + radius, + startAngle: -Math.PI / 2, + endAngle: -Math.PI / 2 + Math.PI * 2 * this._value / this._maxValue, + color: this._progressColor, + lineWidth + }); + }.bind(this); }; /** - * Refreshes the unchecked graphic - * - * @private - * - * @see DKTools.Sprite.CheckBox.prototype.loadBitmap + * Returns the standard handler of draw of the text + * + * @override + * @returns {Function} Standard handler of draw of the text */ -DKTools.Sprite.CheckBox.prototype._refreshUncheckedGraphic = function() { - let bitmapObject = null; - - if (DKTools.Utils.isString(this._uncheckedGraphic)) { - bitmapObject = { - folder: this._graphicFolder, - filename: this._uncheckedGraphic - }; - } else if (this._uncheckedGraphic instanceof Object) { - bitmapObject = this._uncheckedGraphic; - } - - if (bitmapObject) { - this.loadBitmap(bitmapObject); - } +DKTools.Sprite.ProgressBar.Circle.prototype.standardDrawTextHandler = function() { + return function() { + const percents = this.getPercents(); + const text = `${percents}%`; + this.drawText(text, { height: this.realHeight }); + }.bind(this); }; /** - * Refreshes graphic - * - * @private - * - * @see DKTools.Sprite.CheckBox.prototype.isChecked - * @see DKTools.Sprite.CheckBox.prototype._refreshCheckedGraphic - * @see DKTools.Sprite.CheckBox.prototype._refreshUncheckedGraphic + * Returns the standard line width + * + * @returns {Number} Standard line width */ -DKTools.Sprite.CheckBox.prototype._refreshGraphic = function() { - if (this.isChecked()) { - this._refreshCheckedGraphic(); - } else { - this._refreshUncheckedGraphic(); - } +DKTools.Sprite.ProgressBar.Circle.prototype.standardLineWidth = function() { + return 10; }; -// refresh methods +// setup methods /** - * Updates and redraws all + * Sets all parameters * * @override - * - * @see DKTools.Sprite.CheckBox.prototype._refreshGraphic - * @see DKTools.Sprite.Button.prototype.refreshAll + * + * @param {Object} [object={}] - Parameters + * + * @param {Number} [object.lineWidth] - Line width + * + * @see DKTools.Sprite.ProgressBar.prototype.setupAll + * @see DKTools.Sprite.ProgressBar.Circle.prototype.setupLineWidth */ -DKTools.Sprite.CheckBox.prototype.refreshAll = function() { - this._refreshGraphic(); - DKTools.Sprite.Button.prototype.refreshAll.call(this); +DKTools.Sprite.ProgressBar.Circle.prototype.setupAll = function(object) { + object = object || {}; + DKTools.Sprite.ProgressBar.prototype.setupAll.call(this, object); + this.setupLineWidth(object.lineWidth); }; -// is methods - /** - * Returns true if the checkbox is checked - * - * @returns {Boolean} Checkbox is checked + * Sets the line width + * + * @param {Number} [width=this.standardLineWidth()] - Line width + * + * @see DKTools.Sprite.ProgressBar.Circle.prototype.standardLineWidth */ -DKTools.Sprite.CheckBox.prototype.isChecked = function() { - return this._checked; +DKTools.Sprite.ProgressBar.Circle.prototype.setupLineWidth = function(width) { + /** + * @private + * @readonly + * @type {Number} + */ + this._lineWidth = width || this.standardLineWidth(); }; -// event methods +// set methods /** - * Updates the events with type: mouse-click-button + * Changes all parameters + * Returns the number of changed parameters * - * @param {String} button - Mouse button + * @override * - * @see DKTools.Sprite.CheckBox.prototype.switch - * @see DKTools.Sprite.Button.prototype.updateMouseClickEvents + * @param {Object} [object={}] - Parameters + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the progress bar + * + * @param {Number} [object.lineWidth] - Line width + * + * @see DKTools.Sprite.ProgressBar.prototype.setAll + * @see DKTools.Sprite.ProgressBar.Circle.prototype.setLineWidth + * @see DKTools.Sprite.ProgressBar.Circle.prototype.start + * @see DKTools.Sprite.ProgressBar.Circle.prototype.activate + * + * @returns {Number} Number of changed parameters */ -DKTools.Sprite.CheckBox.prototype.updateMouseClickEvents = function(button) { - this.switch(); - DKTools.Sprite.Button.prototype.updateMouseClickEvents.call(this, button); -}; +DKTools.Sprite.ProgressBar.Circle.prototype.setAll = function(object, blockStart, activate) { + object = object || {}; + const block = true; + let changed = DKTools.Sprite.ProgressBar.prototype.setAll.call(this, object, block); + + if (this.setLineWidth(object.lineWidth, block)) { + changed++; + } + + if (changed) { + if (!blockStart) { + this.start(); + } -/** - * Updates the events with type: checked - * - * @see DKTools.Sprite.CheckBox.prototype.updateEventsContainer - */ -DKTools.Sprite.CheckBox.prototype.updateCheckedEvents = function() { - this.updateEventsContainer('checked'); + if (activate) { + this.activate(); + } + } + + return changed; }; /** - * Updates the events with type: unchecked + * Changes the line width + * Returns true if the change occurred * - * @see DKTools.Sprite.CheckBox.prototype.updateEventsContainer + * @param {Number} [width] - Line width + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function + * + * @see DKTools.Sprite.ProgressBar.Circle.prototype.setupLineWidth + * @see DKTools.Sprite.ProgressBar.Circle.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Sprite.CheckBox.prototype.updateUncheckedEvents = function() { - this.updateEventsContainer('unchecked'); -}; +DKTools.Sprite.ProgressBar.Circle.prototype.setLineWidth = function(width, blockRefreshAll) { + if (this._lineWidth === width) { + return false; + } -// other methods + const lastWidth = this._lineWidth; + this.setupLineWidth(width); -/** - * Switches the checkbox - * - * @see DKTools.Sprite.CheckBox.prototype.isChecked - * @see DKTools.Sprite.CheckBox.prototype.setChecked - */ -DKTools.Sprite.CheckBox.prototype.switch = function() { - this.setChecked(!this.isChecked()); -}; + if (this._lineWidth === lastWidth) { + return false; + } -/** - * Checks the checkbox - * - * @see DKTools.Sprite.CheckBox.prototype.isChecked - * @see DKTools.Sprite.CheckBox.prototype.switch - * @see DKTools.Sprite.CheckBox.prototype.updateCheckedEvents - */ -DKTools.Sprite.CheckBox.prototype.check = function() { - if (!this.isChecked()) { - this.switch(); - this.updateCheckedEvents(); + if (!blockRefreshAll) { + this.refreshAll(); } + + return true; }; + + + + +//=========================================================================== +// DKTools.Sprite.ProgressBar.SemiCircle +//=========================================================================== + +DKTools.Sprite.ProgressBar.SemiCircle.prototype = Object.create(DKTools.Sprite.ProgressBar.Circle.prototype); +DKTools.Sprite.ProgressBar.SemiCircle.prototype.constructor = DKTools.Sprite.ProgressBar.SemiCircle; + /** - * Unchecks the checkbox + * Returns the standard handler of draw of the graphic * - * @see DKTools.Sprite.CheckBox.prototype.isChecked - * @see DKTools.Sprite.CheckBox.prototype.switch - * @see DKTools.Sprite.CheckBox.prototype.updateUncheckedEvents + * @override + * @returns {Function} Standard handler of draw of the graphic */ -DKTools.Sprite.CheckBox.prototype.uncheck = function() { - if (this.isChecked()) { - this.switch(); - this.updateUncheckedEvents(); - } +DKTools.Sprite.ProgressBar.SemiCircle.prototype.standardDrawGraphicHandler = function() { + return function() { + const lineWidth = this._lineWidth; + const realWidth = this.realWidth; + const radius = (realWidth - lineWidth) / 2; + const x = radius + lineWidth / 2; + const y = this.realHeight; + + this.strokeArc({ + x, + y, + radius, + startAngle: Math.PI, + color: this._backgroundColor, + lineWidth + }); + + this.strokeArc({ + x, + y, + radius, + startAngle: Math.PI, + endAngle: -Math.PI + Math.PI * this._value / this._maxValue, + color: this._progressColor, + lineWidth + }); + }.bind(this); }; @@ -23763,41 +23898,87 @@ DKTools.Sprite.CheckBox.prototype.uncheck = function() { //=========================================================================== -// DKTools.Viewport +// DKTools.Sprite.CheckBox //=========================================================================== -DKTools.Viewport.prototype = Object.create(DKTools.Sprite.prototype); -DKTools.Viewport.prototype.constructor = DKTools.Viewport; +DKTools.Sprite.CheckBox.prototype = Object.create(DKTools.Sprite.Button.prototype); +DKTools.Sprite.CheckBox.prototype.constructor = DKTools.Sprite.CheckBox; // properties -Object.defineProperties(DKTools.Viewport.prototype, { +Object.defineProperties(DKTools.Sprite.CheckBox.prototype, { /** - * Shape of the mask - * + * Checked + * * @readonly - * @type {PIXI.Graphics} - * @memberof DKTools.Viewport.prototype + * @type {Boolean} + * @memberof DKTools.Sprite.CheckBox.prototype */ - maskShape: { + checked: { get: function() { - return this._maskShape; + return this._checked; }, configurable: true - } + }, + + /** + * Checked graphic + * + * @readonly + * @type {Bitmap | String | Object} + * @memberof DKTools.Sprite.CheckBox.prototype + */ + checkedGraphic: { + get: function() { + return this._checkedGraphic; + }, + configurable: true + }, + + /** + * Unchecked graphic + * + * @readonly + * @type {Bitmap | String | Object} + * @memberof DKTools.Sprite.CheckBox.prototype + */ + uncheckedGraphic: { + get: function() { + return this._uncheckedGraphic; + }, + configurable: true + }, }); // standard methods /** - * Returns the standard mask shape + * Returns the stadnard checked * - * @returns {String} Standard mask shape + * @returns {Boolean} Checked */ -DKTools.Viewport.prototype.standardMaskShape = function() { - return 'rect'; +DKTools.Sprite.CheckBox.prototype.standardChecked = function() { + return false; +}; + +/** + * Returns the stadnard checked graphic + * + * @returns {null} Checked graphic + */ +DKTools.Sprite.CheckBox.prototype.standardCheckedGraphic = function() { + return null; +}; + +/** + * Returns the stadnard unchecked graphic + * + * @returns {null} Unchecked graphic + */ +DKTools.Sprite.CheckBox.prototype.standardUncheckedGraphic = function() { + return null; }; // setup methods @@ -23809,31 +23990,68 @@ DKTools.Viewport.prototype.standardMaskShape = function() { * * @param {Object} [object={}] - Parameters * - * @param {String} [object.maskShape] - Shape of the mask + * @param {Boolean} [object.checked] - Checked + * @param {Bitmap | String | Object} [object.checkedGraphic] - Checked graphic + * @param {Bitmap | String | Object} [object.uncheckedGraphic] - Unchecked graphic * - * @see DKTools.Sprite.prototype.setupAll - * @see DKTools.Viewport.prototype.setupMaskShape + * @see DKTools.Sprite.Button.prototype.setupAll + * @see DKTools.Sprite.CheckBox.prototype.setupChecked + * @see DKTools.Sprite.CheckBox.prototype.setupCheckedGraphic + * @see DKTools.Sprite.CheckBox.prototype.setupUncheckedGraphic */ -DKTools.Viewport.prototype.setupAll = function(object) { - object = object || {}; - DKTools.Sprite.prototype.setupAll.call(this, object); - this.setupMaskShape(object.maskShape); +DKTools.Sprite.CheckBox.prototype.setupAll = function(object) { + DKTools.Sprite.Button.prototype.setupAll.call(this, object); + this.setupChecked(object.checked); + this.setupCheckedGraphic(object.checkedGraphic); + this.setupUncheckedGraphic(object.uncheckedGraphic); }; /** - * Sets the shape of the mask + * Sets the checked * - * @param {String} [shape] - Shape of the mask - * - * @see DKTools.Viewport.prototype.standardMaskShape + * @param {Boolean} [checked=this.standardChecked()] - Checked + * + * @see DKTools.Sprite.CheckBox.prototype.standardChecked */ -DKTools.Viewport.prototype.setupMaskShape = function(shape) { +DKTools.Sprite.CheckBox.prototype.setupChecked = function(checked) { /** * @private * @readonly - * @type {String} + * @type {Boolean} */ - this._maskShape = shape || this.standardMaskShape(); + this._checked = checked == null ? this.standardChecked() : checked; +}; + +/** + * Sets the checked graphic + * + * @param {Bitmap | String | Object} [graphic=this.standardCheckedGraphic()] - Checked graphic + * + * @see DKTools.Sprite.CheckBox.prototype.standardCheckedGraphic + */ +DKTools.Sprite.CheckBox.prototype.setupCheckedGraphic = function(graphic) { + /** + * @private + * @readonly + * @type {Bitmap | String | Object} + */ + this._checkedGraphic = graphic || this.standardCheckedGraphic(); +}; + +/** + * Sets the unchecked graphic + * + * @param {Bitmap | String | Object} [graphic=this.standardUncheckedGraphic()] - Unchecked graphic + * + * @see DKTools.Sprite.CheckBox.prototype.standardUncheckedGraphic + */ +DKTools.Sprite.CheckBox.prototype.setupUncheckedGraphic = function(graphic) { + /** + * @private + * @readonly + * @type {Bitmap | String | Object} + */ + this._uncheckedGraphic = graphic || this.standardUncheckedGraphic(); }; // set methods @@ -23846,24 +24064,35 @@ DKTools.Viewport.prototype.setupMaskShape = function(shape) { * * @param {Object} [object={}] - Parameters * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the object + * @param {Boolean} [activate=false] - Activates the check box * - * @param {String} [object.maskShape] - Shape of the mask + * @param {Boolean} [object.checked] - Checked + * @param {Bitmap | String | Object} [object.checkedGraphic] - Checked graphic + * @param {Bitmap | String | Object} [object.uncheckedGraphic] - Unchecked graphic * - * @see DKTools.Sprite.prototype.setAll - * @see DKTools.Viewport.prototype.setMaskShape - * @see DKTools.Viewport.prototype.start - * @see DKTools.Viewport.prototype.activate + * @see DKTools.Sprite.Button.prototype.setAll + * @see DKTools.Sprite.CheckBox.prototype.setChecked + * @see DKTools.Sprite.CheckBox.prototype.setCheckedGraphic + * @see DKTools.Sprite.CheckBox.prototype.setUncheckedGraphic + * @see DKTools.Sprite.CheckBox.prototype.start + * @see DKTools.Sprite.CheckBox.prototype.activate * * @returns {Number} Number of changed parameters */ -DKTools.Viewport.prototype.setAll = function(object, blockStart, activate) { +DKTools.Sprite.CheckBox.prototype.setAll = function(object, blockStart, activate) { object = object || {}; const block = true; + let changed = DKTools.Sprite.Button.prototype.setAll.call(this, object, block); - let changed = DKTools.Sprite.prototype.setAll.call(this, object, block); + if (this.setChecked(object.checked, block)) { + changed++; + } - if (this.setMaskShape(object.maskShape, block)) { + if (this.setCheckedGraphic(object.checkedGraphic, block)) { + changed++; + } + + if (this.setUncheckedGraphic(object.uncheckedGraphic, block)) { changed++; } @@ -23881,696 +24110,422 @@ DKTools.Viewport.prototype.setAll = function(object, blockStart, activate) { }; /** - * Changes the shape of the mask + * Changes the checked * Returns true if the change occurred * - * @param {String} [shape] - Shape of the mask - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [checked] - + * @param {Boolean} [blockRefreshAll=false] - + * + * @see DKTools.Sprite.CheckBox.prototype.setupChecked + * @see DKTools.Sprite.CheckBox.prototype.refreshAll * * @returns {Boolean} Change occurred */ -DKTools.Viewport.prototype.setMaskShape = function(shape, blockStart) { - if (this._maskShape === shape) { +DKTools.Sprite.CheckBox.prototype.setChecked = function(checked, blockRefreshAll) { + if (this._checked === checked) { return false; } - const lastShape = this._maskShape; - this.setupShape(shape); + const lastChecked = this._checked; + this.setupChecked(checked); - if (this._maskShape === lastShape) { + if (this._checked === lastChecked) { return false; } - if (!blockStart) { - this.start(); + if (!blockRefreshAll) { + this.refreshAll(); } return true; }; -// create methods - /** - * Creates all objects + * Changes the checked graphic + * Returns true if the change occurred * - * @override - * - * @see DKTools.Sprite.prototype.createAll - * @see DKTools.Viewport.prototype.createMask - */ -DKTools.Viewport.prototype.createAll = function() { - DKTools.Sprite.prototype.createAll.call(this); - this.createMask(); -}; - -/** - * Creates a mask - * - * @version 2.0.0 - * @override - * - * @see DKTools.Sprite.prototype.createMask - */ -DKTools.Viewport.prototype.createMask = function() { - DKTools.Sprite.prototype.createMask.call(this, this._maskShape); -}; - -// can methods - -/** - * Returns true if the viewport can clone the fixed bitmap + * @param {Bitmap | String | Object} [graphic] - Checked graphic + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @override - * @returns {Boolean} Viewport can clone the fixed bitmap + * @see DKTools.Sprite.CheckBox.prototype.setupCheckedGraphic + * @see DKTools.Sprite.CheckBox.prototype.refreshAll + * + * @returns {Boolean} Change occurred */ -DKTools.Viewport.prototype.canCloneFixedBitmap = function() { - return false; -}; - - - - - -//=========================================================================== -// DKTools.Layout -//=========================================================================== - -DKTools.Layout.prototype = Object.create(DKTools.Sprite.prototype); -DKTools.Layout.prototype.constructor = DKTools.Layout; - -// properties - -Object.defineProperties(DKTools.Layout.prototype, { - - /** - * Number of the columns - * - * @readonly - * @type {Number} - * @memberof DKTools.Layout.prototype - */ - maxCols: { - get: function() { - return this._maxCols; - }, - configurable: true - }, - - /** - * Items - * - * @readonly - * @type {DKTools.Sprite[] | *} - * @memberof DKTools.Layout.prototype - */ - items: { - get: function() { - return this._items; - }, - configurable: true - }, - - /** - * Height of the row - * - * @readonly - * @type {Function | Number} - * @memberof DKTools.Layout.prototype - */ - rowHeight: { - get: function() { - return this._rowHeight; - }, - configurable: true - }, - - /** - * Width of the column - * - * @readonly - * @type {Function | Number} - * @memberof DKTools.Layout.prototype - */ - colWidth: { - get: function() { - return this._colWidth; - }, - configurable: true - }, +DKTools.Sprite.CheckBox.prototype.setCheckedGraphic = function(graphic, blockRefreshAll) { + const checkedGraphic = this._checkedGraphic; - /** - * Horizontal spacing - * - * @readonly - * @type {Number} - * @memberof DKTools.Layout.prototype - */ - horizontalSpacing: { - get: function() { - return this._horizontalSpacing; - }, - configurable: true - }, + if (checkedGraphic == graphic) { + return false; + } - /** - * Vertical spacing - * - * @readonly - * @type {Number} - * @memberof DKTools.Layout.prototype - */ - verticalSpacing: { - get: function() { - return this._verticalSpacing; - }, - configurable: true - }, + if (checkedGraphic instanceof Bitmap) { + this.setupCheckedGraphic(graphic); + } else if (DKTools.Utils.isString(checkedGraphic) || checkedGraphic instanceof Object) { + const lastGraphic = checkedGraphic; + this.setupCheckedGraphic(graphic); - /** - * Value of the invert - * - * @readonly - * @type {Boolean} - * @memberof DKTools.Layout.prototype - */ - inverted: { - get: function() { - return this._inverted; - }, - configurable: true + if (_.isEqual(this._checkedGraphic, lastGraphic)) { + return false; + } + } else { + return false; } -}); - -// _clear methods + if (!blockRefreshAll) { + this.refreshAll(); + } -/** - * Clears all data - * - * @private - * @override - * - * @see DKTools.Sprite.prototype._clearAll - * @see DKTools.Layout.prototype._clearItems - */ -DKTools.Layout.prototype._clearAll = function() { - DKTools.Sprite.prototype._clearAll.call(this); - this._clearItems(); + return true; }; /** - * Clears items + * Changes the unchecked graphic + * Returns true if the change occurred * - * @private - */ -DKTools.Layout.prototype._clearItems = function() { - /** - * @private - * @readonly - * @type {Array} - */ - this._items = []; -}; - -// clear methods - -/** - * Clears items + * @param {Bitmap | String | Object} [graphic] - Unchecked graphic + * @param {Boolean} [blockRefreshAll=false] - Blocking the call of the "refreshAll" function * - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @see DKTools.Sprite.CheckBox.prototype.setupUncheckedGraphic + * @see DKTools.Sprite.CheckBox.prototype.refreshAll * - * @see DKTools.Layout.prototype.removeAllItems - * @see DKTools.Layout.prototype._clearItems - * @see DKTools.Layout.prototype.start + * @returns {Boolean} Change occurred */ -DKTools.Layout.prototype.clearItems = function(blockStart) { - this.removeAllItems(); - this._clearItems(); +DKTools.Sprite.CheckBox.prototype.setUncheckedGraphic = function(graphic, blockRefreshAll) { + const uncheckedGraphic = this._uncheckedGraphic; - if (!blockStart) { - this.start(); + if (uncheckedGraphic == graphic) { + return false; } -}; -// standard methods + if (uncheckedGraphic instanceof Bitmap) { + this.setupUncheckedGraphic(graphic); + } else if (DKTools.Utils.isString(uncheckedGraphic) || uncheckedGraphic instanceof Object) { + const lastGraphic = uncheckedGraphic; + this.setupUncheckedGraphic(graphic); -/** - * Returns the standard activity of the layout - * - * @override - * @returns {Boolean} Standard activity of the layout - */ -DKTools.Layout.prototype.standardActive = function() { - return false; -}; + if (_.isEqual(this._uncheckedGraphic, lastGraphic)) { + return false; + } + } else { + return false; + } -/** - * Returns the standard number of the columns - * - * @returns {Number} Standard number of columns - */ -DKTools.Layout.prototype.standardMaxCols = function() { - return 1; -}; + if (!blockRefreshAll) { + this.refreshAll(); + } -/** - * Returns the standard horizontal spacing - * - * @returns {Number} Standard horizontal spacing - */ -DKTools.Layout.prototype.standardHorizontalSpacing = function() { - return 12; + return true; }; -/** - * Returns the standard vertical spacing - * - * @returns {Number} Standard vertical spacing - */ -DKTools.Layout.prototype.standardVerticalSpacing = function() { - return this.getLineHeight() / 2; -}; +// _refresh methods /** - * Returns the standard list of the items - * - * @returns {Array} Standard list of the items + * Refreshes the checked graphic + * + * @private + * + * @see DKTools.Sprite.CheckBox.prototype.loadBitmap */ -DKTools.Layout.prototype.standardItems = function() { - return []; -}; +DKTools.Sprite.CheckBox.prototype._refreshCheckedGraphic = function() { + let bitmapObject = null; -/** - * Returns the standard height of the row - * - * @returns {Function} Standard height of the row - */ -DKTools.Layout.prototype.standardRowHeight = function() { - return function(row) { - const items = this.getItemsInRow(row); - return _.max(_.map(items, 'height')); - }.bind(this); + if (DKTools.Utils.isString(this._checkedGraphic)) { + bitmapObject = { + folder: this._graphicFolder, + filename: this._checkedGraphic + }; + } else if (this._checkedGraphic instanceof Object) { + bitmapObject = this._checkedGraphic; + } + + if (bitmapObject) { + this.loadBitmap(bitmapObject); + } }; /** - * Returns the standard width of the column - * - * @returns {Function} Standard width of the column + * Refreshes the unchecked graphic + * + * @private + * + * @see DKTools.Sprite.CheckBox.prototype.loadBitmap */ -DKTools.Layout.prototype.standardColWidth = function() { - return function(col) { - const items = this.getItemsInCol(col); - return _.max(_.map(items, 'width')); - }.bind(this); +DKTools.Sprite.CheckBox.prototype._refreshUncheckedGraphic = function() { + let bitmapObject = null; + + if (DKTools.Utils.isString(this._uncheckedGraphic)) { + bitmapObject = { + folder: this._graphicFolder, + filename: this._uncheckedGraphic + }; + } else if (this._uncheckedGraphic instanceof Object) { + bitmapObject = this._uncheckedGraphic; + } + + if (bitmapObject) { + this.loadBitmap(bitmapObject); + } }; /** - * Returns the standard value of the invert - * - * @returns {Boolean} Standard value of the invert + * Refreshes graphic + * + * @private + * + * @see DKTools.Sprite.CheckBox.prototype.isChecked + * @see DKTools.Sprite.CheckBox.prototype._refreshCheckedGraphic + * @see DKTools.Sprite.CheckBox.prototype._refreshUncheckedGraphic */ -DKTools.Layout.prototype.standardInverted = function() { - return false; +DKTools.Sprite.CheckBox.prototype._refreshGraphic = function() { + if (this.isChecked()) { + this._refreshCheckedGraphic(); + } else { + this._refreshUncheckedGraphic(); + } }; -// setup methods +// refresh methods /** - * Sets all parameters + * Updates and redraws all * * @override - * - * @param {Object} [object={}] - Parameters - * - * @param {Number} [object.maxCols] - Columns - * @param {Number} [object.horizontalSpacing] - Horizontal spacing - * @param {Number} [object.verticalSpacing] - Vertical spacing - * @param {Array} [object.items] - Items - * @param {Function | Number} [object.rowHeight] - Height of the row - * @param {Function | Number} [object.colWidth] - Width of the column - * @param {Boolean} [object.inverted] - Value of the invert - * - * @see DKTools.Sprite.prototype.setupAll - * @see DKTools.Layout.prototype.setupMaxCols - * @see DKTools.Layout.prototype.setupSpacing - * @see DKTools.Layout.prototype.setupItems - * @see DKTools.Layout.prototype.setupRowHeight - * @see DKTools.Layout.prototype.setupColWidth - * @see DKTools.Layout.prototype.setupInverted + * + * @see DKTools.Sprite.CheckBox.prototype._refreshGraphic + * @see DKTools.Sprite.Button.prototype.refreshAll */ -DKTools.Layout.prototype.setupAll = function(object) { - object = object || {}; - DKTools.Sprite.prototype.setupAll.call(this, object); - this.setupMaxCols(object.maxCols); - this.setupSpacing(object.horizontalSpacing, object.verticalSpacing); - this.setupItems(object.items); - this.setupRowHeight(object.rowHeight); - this.setupColWidth(object.colWidth); - this.setupInverted(object.inverted); +DKTools.Sprite.CheckBox.prototype.refreshAll = function() { + this._refreshGraphic(); + DKTools.Sprite.Button.prototype.refreshAll.call(this); }; -/** - * Sets the number of the columns - * - * @param {Number} [cols=this.standardMaxCols()] - Columns - * - * @see DKTools.Layout.prototype.standardMaxCols - */ -DKTools.Layout.prototype.setupMaxCols = function(cols) { - /** - * @private - * @readonly - * @type {Number} - */ - this._maxCols = (cols == null ? this.standardMaxCols() : cols); -}; +// is methods /** - * Sets the horizontal spacing - * - * @param {Number} [spacing=this.standardHorizontalSpacing()] - Horizontal spacing - * - * @see DKTools.Layout.prototype.standardHorizontalSpacing + * Returns true if the checkbox is checked + * + * @returns {Boolean} Checkbox is checked */ -DKTools.Layout.prototype.setupHorizontalSpacing = function(spacing) { - /** - * @private - * @readonly - * @type {Number} - */ - this._horizontalSpacing = (spacing == null ? this.standardHorizontalSpacing() : spacing); +DKTools.Sprite.CheckBox.prototype.isChecked = function() { + return this._checked; }; -/** - * Sets the vertical spacing - * - * @param {Number} [spacing=this.standardVerticalSpacing()] - Vertical spacing - * - * @see DKTools.Layout.prototype.standardVerticalSpacing - */ -DKTools.Layout.prototype.setupVerticalSpacing = function(spacing) { - /** - * @private - * @readonly - * @type {Number} - */ - this._verticalSpacing = (spacing == null ? this.standardVerticalSpacing() : spacing); -}; +// event methods /** - * Sets the horizontal and vertical spacing + * Updates the events with type: mouse-click-button * - * @param {Number} [horizontalSpacing] - Horizontal spacing - * @param {Number} [verticalSpacing] - Vertical spacing + * @param {String} button - Mouse button * - * @see DKTools.Layout.prototype.setupHorizontalSpacing - * @see DKTools.Layout.prototype.setupVerticalSpacing + * @see DKTools.Sprite.CheckBox.prototype.switch + * @see DKTools.Sprite.Button.prototype.updateMouseClickEvents */ -DKTools.Layout.prototype.setupSpacing = function(horizontalSpacing, verticalSpacing) { - this.setupHorizontalSpacing(horizontalSpacing); - this.setupVerticalSpacing(verticalSpacing); +DKTools.Sprite.CheckBox.prototype.updateMouseClickEvents = function(button) { + this.switch(); + DKTools.Sprite.Button.prototype.updateMouseClickEvents.call(this, button); }; /** - * Sets the items - * - * @param {DKTools.Sprite[] | *} [items=this.standardItems()] - Items + * Updates the events with type: checked * - * @see DKTools.Layout.prototype.standardItems + * @see DKTools.Sprite.CheckBox.prototype.updateEventsContainer */ -DKTools.Layout.prototype.setupItems = function(items) { - items = items || this.standardItems(); - _.forEach(items, function(item) { - this._items.push(item); - }.bind(this)); +DKTools.Sprite.CheckBox.prototype.updateCheckedEvents = function() { + this.updateEventsContainer('checked'); }; /** - * Sets the height of the row - * - * @param {Function | Number} [rowHeight=this.standardRowHeight()] - Height of the row + * Updates the events with type: unchecked * - * @see DKTools.Layout.prototype.standardRowHeight + * @see DKTools.Sprite.CheckBox.prototype.updateEventsContainer */ -DKTools.Layout.prototype.setupRowHeight = function(rowHeight) { - /** - * @private - * @readonly - * @type {Function | Number} - */ - this._rowHeight = rowHeight || this.standardRowHeight(); +DKTools.Sprite.CheckBox.prototype.updateUncheckedEvents = function() { + this.updateEventsContainer('unchecked'); }; +// other methods + /** - * Sets the width of the column - * - * @param {Function | Number} [colWidth=this.standardColWidth()] - Width of the column + * Switches the checkbox * - * @see DKTools.Layout.prototype.standardColWidth + * @see DKTools.Sprite.CheckBox.prototype.isChecked + * @see DKTools.Sprite.CheckBox.prototype.setChecked */ -DKTools.Layout.prototype.setupColWidth = function(colWidth) { - /** - * @private - * @readonly - * @type {Function | Number} - */ - this._colWidth = colWidth || this.standardColWidth(); +DKTools.Sprite.CheckBox.prototype.switch = function() { + this.setChecked(!this.isChecked()); }; /** - * Sets the value of the invert - * - * @param {Boolean} [inverted=this.standardInverted()] - Value of the ivnert + * Checks the checkbox * - * @see DKTools.Layout.prototype.standardInverted + * @see DKTools.Sprite.CheckBox.prototype.isChecked + * @see DKTools.Sprite.CheckBox.prototype.switch + * @see DKTools.Sprite.CheckBox.prototype.updateCheckedEvents */ -DKTools.Layout.prototype.setupInverted = function(inverted) { - /** - * @private - * @readonly - * @type {Boolean} - */ - this._inverted = (inverted == null ? this.standardInverted() : inverted); +DKTools.Sprite.CheckBox.prototype.check = function() { + if (!this.isChecked()) { + this.switch(); + this.updateCheckedEvents(); + } }; -// set methods - /** - * Changes all parameters - * Returns the number of changed parameters - * - * @override - * - * @param {Object} [object={}] - Parameters - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the layout - * - * @param {Number} [object.maxCols] - Columns - * @param {Number} [object.horizontalSpacing] - Horizontal spacing - * @param {Number} [object.verticalSpacing] - Vertical spacing - * @param {Array} [object.items] - Items - * @param {Function | Number} [object.rowHeight] - Height of the row - * @param {Function | Number} [object.colWidth] - Width of the column - * @param {Boolean} [object.inverted] - Value of the invert - * - * @see DKTools.Sprite.prototype.setupAll - * @see DKTools.Layout.prototype.setMaxCols - * @see DKTools.Layout.prototype.setSpacing - * @see DKTools.Layout.prototype.setItems - * @see DKTools.Layout.prototype.setRowHeight - * @see DKTools.Layout.prototype.setColWidth - * @see DKTools.Layout.prototype.setInverted - * @see DKTools.Layout.prototype.start - * @see DKTools.Layout.prototype.activate + * Unchecks the checkbox * - * @returns {Number} Number of changed parameters + * @see DKTools.Sprite.CheckBox.prototype.isChecked + * @see DKTools.Sprite.CheckBox.prototype.switch + * @see DKTools.Sprite.CheckBox.prototype.updateUncheckedEvents */ -DKTools.Layout.prototype.setAll = function(object, blockStart, activate) { - object = object || {}; - const block = true; - let changed = DKTools.Sprite.prototype.setAll.call(this, object, block); - - if (this.setMaxCols(object.maxCols, block)) { - changed++; +DKTools.Sprite.CheckBox.prototype.uncheck = function() { + if (this.isChecked()) { + this.switch(); + this.updateUncheckedEvents(); } +}; - changed += this.setSpacing(object.horizontalSpacing, object.verticalSpacing, block); - if (this.setItems(object.items, block)) { - changed++; - } - if (this.setRowHeight(object.rowHeight, block)) { - changed++; - } - if (this.setColWidth(object.colWidth, block)) { - changed++; - } - if (this.setInverted(object.reversed, block)) { - changed++; - } +//=========================================================================== +// DKTools.Viewport +//=========================================================================== - if (changed) { - if (!blockStart) { - this.start(); - } +DKTools.Viewport.prototype = Object.create(DKTools.Sprite.prototype); +DKTools.Viewport.prototype.constructor = DKTools.Viewport; - if (activate) { - this.activate(); - } - } +// properties - return changed; -}; +Object.defineProperties(DKTools.Viewport.prototype, { -/** - * Changes the number of the columns - * Returns true if the change occurred - * - * @param {Number} [cols] - Columns - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @see DKTools.Layout.prototype.setupMaxCols - * @see DKTools.Layout.prototype.start - * - * @returns {Boolean} Change occurred - */ -DKTools.Layout.prototype.setMaxCols = function(cols, blockStart) { - if (this._maxCols === cols) { - return false; + /** + * Shape of the mask + * + * @readonly + * @type {PIXI.Graphics} + * @memberof DKTools.Viewport.prototype + */ + maskShape: { + get: function() { + return this._maskShape; + }, + configurable: true } - const lastCols = this._maxCols; - this.setupMaxCols(cols); - - if (this._maxCols === lastCols) { - return false; - } +}); - if (!blockStart) { - this.start(); - } +// standard methods - return true; +/** + * Returns the standard mask shape + * + * @returns {String} Standard mask shape + */ +DKTools.Viewport.prototype.standardMaskShape = function() { + return 'rect'; }; +// setup methods + /** - * Changes the horizontal spacing - * Returns true if the change occurred + * Sets all parameters * - * @param {Number} [scacing] - Horizontal spacing - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @override * - * @see DKTools.Layout.prototype.setupHorizontalSpacing - * @see DKTools.Layout.prototype.start + * @param {Object} [object={}] - Parameters * - * @returns {Boolean} Change occurred + * @param {String} [object.maskShape] - Shape of the mask + * + * @see DKTools.Sprite.prototype.setupAll + * @see DKTools.Viewport.prototype.setupMaskShape */ -DKTools.Layout.prototype.setHorizontalSpacing = function(scacing, blockStart) { - if (this._horizontalSpacing === scacing) { - return false; - } - - const lastSpacing = this._horizontalSpacing; - this.setupHorizontalSpacing(scacing); - - if (this._horizontalSpacing === lastSpacing) { - return false; - } - - if (!blockStart) { - this.start(); - } - - return true; +DKTools.Viewport.prototype.setupAll = function(object) { + object = object || {}; + DKTools.Sprite.prototype.setupAll.call(this, object); + this.setupMaskShape(object.maskShape); }; /** - * Changes the vertical spacing - * Returns true if the change occurred - * - * @param {Number} [scacing] - Vertical spacing - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @see DKTools.Layout.prototype.setupVerticalSpacing - * @see DKTools.Layout.prototype.start + * Sets the shape of the mask * - * @returns {Boolean} Change occurred + * @param {String} [shape] - Shape of the mask + * + * @see DKTools.Viewport.prototype.standardMaskShape */ -DKTools.Layout.prototype.setVerticalSpacing = function(scacing, blockStart) { - if (this._verticalSpacing === scacing) { - return false; - } - - const lastSpacing = this._verticalSpacing; - this.setupVerticalSpacing(scacing); - - if (this._verticalSpacing === lastSpacing) { - return false; - } - - if (!blockStart) { - this.start(); - } - - return true; +DKTools.Viewport.prototype.setupMaskShape = function(shape) { + /** + * @private + * @readonly + * @type {String} + */ + this._maskShape = shape || this.standardMaskShape(); }; +// set methods + /** - * Changes the horizontal and vertical spacing + * Changes all parameters * Returns the number of changed parameters * - * @param {Number} [horizontalSpacing] - Horizontal spacing - * @param {Number} [verticalSpacing] - Vertical spacing + * @override + * + * @param {Object} [object={}] - Parameters * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the object * - * @see DKTools.Layout.prototype.setHorizontalSpacing - * @see DKTools.Layout.prototype.setVerticalSpacing - * @see DKTools.Layout.prototype.start + * @param {String} [object.maskShape] - Shape of the mask + * + * @see DKTools.Sprite.prototype.setAll + * @see DKTools.Viewport.prototype.setMaskShape + * @see DKTools.Viewport.prototype.start + * @see DKTools.Viewport.prototype.activate * * @returns {Number} Number of changed parameters */ -DKTools.Layout.prototype.setSpacing = function(horizontalSpacing, verticalSpacing, blockStart) { +DKTools.Viewport.prototype.setAll = function(object, blockStart, activate) { + object = object || {}; const block = true; - let changed = 0; - if (this.setHorizontalSpacing(horizontalSpacing, block)) { - changed++; - } + let changed = DKTools.Sprite.prototype.setAll.call(this, object, block); - if (this.setVerticalSpacing(verticalSpacing, block)) { + if (this.setMaskShape(object.maskShape, block)) { changed++; } - if (changed && !blockStart) { - this.start(); + if (changed) { + if (!blockStart) { + this.start(); + } + + if (activate) { + this.activate(); + } } return changed; }; /** - * Changes the items + * Changes the shape of the mask * Returns true if the change occurred * - * @param {DKTools.Sprite[] | *} [items] - Items + * @param {String} [shape] - Shape of the mask * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Layout.prototype.removeAllItems - * @see DKTools.Layout.prototype.setupItems - * @see DKTools.Layout.prototype.start - * * @returns {Boolean} Change occurred */ -DKTools.Layout.prototype.setItems = function(items, blockStart) { - if (this._items == items) { +DKTools.Viewport.prototype.setMaskShape = function(shape, blockStart) { + if (this._maskShape === shape) { return false; } - this.removeAllItems(); - this.setupItems(items); + const lastShape = this._maskShape; + this.setupShape(shape); + + if (this._maskShape === lastShape) { + return false; + } if (!blockStart) { this.start(); @@ -24579,3845 +24534,3867 @@ DKTools.Layout.prototype.setItems = function(items, blockStart) { return true; }; +// create methods + /** - * Changes the height of the row - * Returns true if the change occurred - * - * @param @param {Function | Number} [rowHeight] - Height of the row - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @see DKTools.Layout.prototype.setupRowHeight - * @see DKTools.Layout.prototype.start + * Creates all objects * - * @returns {Boolean} Change occurred + * @override + * + * @see DKTools.Sprite.prototype.createAll + * @see DKTools.Viewport.prototype.createMask */ -DKTools.Layout.prototype.setRowHeight = function(rowHeight, blockStart) { - if (this._rowHeight === rowHeight) { - return false; - } - - const lastHeight = this._rowHeight; - this.setupRowHeight(rowHeight); - - if (this._rowHeight === lastHeight) { - return false; - } - - if (!blockStart) { - this.start(); - } +DKTools.Viewport.prototype.createAll = function() { + DKTools.Sprite.prototype.createAll.call(this); + this.createMask(); +}; - return true; +/** + * Creates a mask + * + * @version 2.0.0 + * @override + * + * @see DKTools.Sprite.prototype.createMask + */ +DKTools.Viewport.prototype.createMask = function() { + DKTools.Sprite.prototype.createMask.call(this, this._maskShape); }; +// can methods + /** - * Changes the width of the column - * Returns true if the change occurred - * - * @param {Function | Number} [colWidth] - Width of the column - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @see DKTools.Layout.prototype.setupColWidth - * @see DKTools.Layout.prototype.start + * Returns true if the viewport can clone the fixed bitmap * - * @returns {Boolean} Change occurred + * @override + * @returns {Boolean} Viewport can clone the fixed bitmap */ -DKTools.Layout.prototype.setColWidth = function(colWidth, blockStart) { - if (this._colWidth === colWidth) { - return false; - } +DKTools.Viewport.prototype.canCloneFixedBitmap = function() { + return false; +}; - const lastWidth = this._colWidth; - this.setupColWidth(colWidth); - if (this._colWidth === lastWidth) { - return false; - } - if (!blockStart) { - this.start(); - } - return true; -}; -/** - * Changes the value of the invert - * Returns true if the change occurred - * - * @param {Boolean} [inverted] - Value of the invert - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @see DKTools.Layout.prototype.setupInverted - * @see DKTools.Layout.prototype.start - * - * @returns {Boolean} Change occurred - */ -DKTools.Layout.prototype.setInverted = function(inverted, blockStart) { - if (this._inverted === inverted) { - return false; - } +//=========================================================================== +// DKTools.Layout +//=========================================================================== - const lastReversed = this._inverted; - this.setupInverted(inverted); +DKTools.Layout.prototype = Object.create(DKTools.Sprite.prototype); +DKTools.Layout.prototype.constructor = DKTools.Layout; - if (this._inverted === lastReversed) { - return false; - } +// properties - if (!blockStart) { - this.start(); - } +Object.defineProperties(DKTools.Layout.prototype, { - return true; -}; + /** + * Number of the columns + * + * @readonly + * @type {Number} + * @memberof DKTools.Layout.prototype + */ + maxCols: { + get: function() { + return this._maxCols; + }, + configurable: true + }, -// start methods + /** + * Items + * + * @readonly + * @type {DKTools.Sprite[] | *} + * @memberof DKTools.Layout.prototype + */ + items: { + get: function() { + return this._items; + }, + configurable: true + }, -/** - * Starts the layout - * - * @override - * - * @see DKTools.Sprite.prototype.start - * @see DKTools.Layout.prototype.isReady - * @see DKTools.Layout.prototype.addOneTimeEvent - */ -DKTools.Layout.prototype.start = function() { - this._started = true; + /** + * Height of the row + * + * @readonly + * @type {Function | Number} + * @memberof DKTools.Layout.prototype + */ + rowHeight: { + get: function() { + return this._rowHeight; + }, + configurable: true + }, - if (this.isReady()) { - DKTools.Sprite.prototype.start.call(this); - } else { - this.addOneTimeEvent({ - type: 'ready', - onSuccess: this.start.bind(this) - }); + /** + * Width of the column + * + * @readonly + * @type {Function | Number} + * @memberof DKTools.Layout.prototype + */ + colWidth: { + get: function() { + return this._colWidth; + }, + configurable: true + }, + + /** + * Horizontal spacing + * + * @readonly + * @type {Number} + * @memberof DKTools.Layout.prototype + */ + horizontalSpacing: { + get: function() { + return this._horizontalSpacing; + }, + configurable: true + }, + + /** + * Vertical spacing + * + * @readonly + * @type {Number} + * @memberof DKTools.Layout.prototype + */ + verticalSpacing: { + get: function() { + return this._verticalSpacing; + }, + configurable: true + }, + + /** + * Value of the invert + * + * @readonly + * @type {Boolean} + * @memberof DKTools.Layout.prototype + */ + inverted: { + get: function() { + return this._inverted; + }, + configurable: true } -}; -// remove methods +}); + +// _clear methods /** - * Removes children objects from processing + * Clears all data * + * @private * @override * - * @see DKTools.Sprite.prototype.removeAllChildren - * @see DKTools.Layout.prototype.removeAllItems + * @see DKTools.Sprite.prototype._clearAll + * @see DKTools.Layout.prototype._clearItems */ -DKTools.Layout.prototype.removeAllChildren = function() { - DKTools.Sprite.prototype.removeAllChildren.call(this); - this.removeAllItems(); +DKTools.Layout.prototype._clearAll = function() { + DKTools.Sprite.prototype._clearAll.call(this); + this._clearItems(); }; /** - * Removes items from processing + * Clears items * - * @see DKTools.Layout.prototype.removeChild + * @private */ -DKTools.Layout.prototype.removeAllItems = function() { - this.removeChild.apply(this, this._items); +DKTools.Layout.prototype._clearItems = function() { + /** + * @private + * @readonly + * @type {Array} + */ + this._items = []; }; -/** - * Removes the item - * - * @param {DKTools.Sprite | *} item - Item - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @see DKTools.Layout.prototype.hasItem - * @see DKTools.Layout.prototype.removeChild - * @see DKTools.Layout.prototype.start - * @see DKTools.Utils.Array.remove - */ -DKTools.Layout.prototype.removeItem = function(item, blockStart) { - if (!this.hasItem(item)) { - return; - } - - this.removeChild(item); - - DKTools.Utils.Array.remove(this._items, item); - - if (!blockStart) { - this.start(); - } -}; +// clear methods /** - * Removes the items + * Clears items * - * @param {Array} items - Items * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Layout.prototype.removeItem + * @see DKTools.Layout.prototype.removeAllItems + * @see DKTools.Layout.prototype._clearItems * @see DKTools.Layout.prototype.start */ -DKTools.Layout.prototype.removeItems = function(items, blockStart) { - _.forEach(items, function(item) { - this.removeItem(item, true); - }.bind(this)); +DKTools.Layout.prototype.clearItems = function(blockStart) { + this.removeAllItems(); + this._clearItems(); if (!blockStart) { this.start(); } }; -/** - * Removes the item by index - * - * @param {Number} index - Index - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @see DKTools.Layout.prototype.getItem - * @see DKTools.Layout.prototype.removeItem - */ -DKTools.Layout.prototype.removeItemByIndex = function(index, blockStart) { - this.removeItem(this.getItem(index), blockStart); -}; - -/** - * Removes the columns - * - * @param {Number} cols - Columns - * - * @see DKTools.Layout.prototype.getMaxCols - * @see DKTools.Layout.prototype.addCols - */ -DKTools.Layout.prototype.removeCols = function(cols) { - if (this.getMaxCols() - cols >= 1) { - this.addCols(-cols); - } -}; +// standard methods /** - * Removes the column + * Returns the standard activity of the layout * - * @see DKTools.Layout.prototype.removeCols + * @override + * @returns {Boolean} Standard activity of the layout */ -DKTools.Layout.prototype.removeCol = function() { - this.removeCols(1); +DKTools.Layout.prototype.standardActive = function() { + return false; }; -// add methods - /** - * Adds children objects to processing + * Returns the standard number of the columns * - * @override - * - * @see DKTools.Sprite.prototype.addAllChildren - * @see DKTools.Layout.prototype.addAllItems + * @returns {Number} Standard number of columns */ -DKTools.Layout.prototype.addAllChildren = function() { - DKTools.Sprite.prototype.addAllChildren.call(this); - this.addAllItems(); +DKTools.Layout.prototype.standardMaxCols = function() { + return 1; }; /** - * Adds the itemns to processing + * Returns the standard horizontal spacing * - * @see DKTools.Layout.prototype.addChild + * @returns {Number} Standard horizontal spacing */ -DKTools.Layout.prototype.addAllItems = function() { - this.addChild.apply(this, this._items); +DKTools.Layout.prototype.standardHorizontalSpacing = function() { + return 12; }; /** - * Adds the item - * - * @param {DKTools.Sprite | *} item - Item - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * Returns the standard vertical spacing * - * @see DKTools.Layout.prototype.start + * @returns {Number} Standard vertical spacing */ -DKTools.Layout.prototype.addItem = function(item, blockStart) { - if (!(item instanceof DKTools.Sprite)) { - return; - } - - this._items.push(item); - - if (!blockStart) { - this.start(); - } +DKTools.Layout.prototype.standardVerticalSpacing = function() { + return this.getLineHeight() / 2; }; /** - * Adds the items - * - * @param {DKTools.Sprite[] | *} items - Items - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * Returns the standard list of the items * - * @see DKTools.Layout.prototype.addItem - * @see DKTools.Layout.prototype.start + * @returns {Array} Standard list of the items */ -DKTools.Layout.prototype.addItems = function(items, blockStart) { - _.forEach(items, function(item) { - this.addItem(item, true); - }.bind(this)); - - if (!blockStart) { - this.start(); - } +DKTools.Layout.prototype.standardItems = function() { + return []; }; /** - * Adds the columns - * - * @param {Number} cols - Columns + * Returns the standard height of the row * - * @see DKTools.Layout.prototype.getMaxCols - * @see DKTools.Layout.prototype.setMaxCols + * @returns {Function} Standard height of the row */ -DKTools.Layout.prototype.addCols = function(cols) { - this.setMaxCols(this.getMaxCols() + cols); +DKTools.Layout.prototype.standardRowHeight = function() { + return function(row) { + const items = this.getItemsInRow(row); + return _.max(_.map(items, 'height')); + }.bind(this); }; /** - * Adds the column + * Returns the standard width of the column * - * @see DKTools.Layout.prototype.addCols + * @returns {Function} Standard width of the column */ -DKTools.Layout.prototype.addCol = function() { - this.addCols(1); +DKTools.Layout.prototype.standardColWidth = function() { + return function(col) { + const items = this.getItemsInCol(col); + return _.max(_.map(items, 'width')); + }.bind(this); }; -// can methods - /** - * Returns true if the layout can clone the fixed bitmap + * Returns the standard value of the invert * - * @override - * @returns {Boolean} Layout can clone the fixed bitmap + * @returns {Boolean} Standard value of the invert */ -DKTools.Layout.prototype.canCloneFixedBitmap = function() { +DKTools.Layout.prototype.standardInverted = function() { return false; }; -// _get methods +// setup methods /** - * Returns the width of the bitmap - * - * @since 2.0.0 - * @private + * Sets all parameters + * * @override - * - * @see DKTools.Layout.prototype.getMaxCols - * @see DKTools.Layout.prototype.getColWidth - * - * @returns {Number} Width of the bitmap + * + * @param {Object} [object={}] - Parameters + * + * @param {Number} [object.maxCols] - Columns + * @param {Number} [object.horizontalSpacing] - Horizontal spacing + * @param {Number} [object.verticalSpacing] - Vertical spacing + * @param {Array} [object.items] - Items + * @param {Function | Number} [object.rowHeight] - Height of the row + * @param {Function | Number} [object.colWidth] - Width of the column + * @param {Boolean} [object.inverted] - Value of the invert + * + * @see DKTools.Sprite.prototype.setupAll + * @see DKTools.Layout.prototype.setupMaxCols + * @see DKTools.Layout.prototype.setupSpacing + * @see DKTools.Layout.prototype.setupItems + * @see DKTools.Layout.prototype.setupRowHeight + * @see DKTools.Layout.prototype.setupColWidth + * @see DKTools.Layout.prototype.setupInverted */ -DKTools.Layout.prototype._getBitmapWidth = function() { - let width = 0; - const maxCols = this.getMaxCols(); - - for (let i = 1; i <= maxCols; i++) { - width += this.getColWidth(i) + this._horizontalSpacing; - } - - return width - this._horizontalSpacing; +DKTools.Layout.prototype.setupAll = function(object) { + object = object || {}; + DKTools.Sprite.prototype.setupAll.call(this, object); + this.setupMaxCols(object.maxCols); + this.setupSpacing(object.horizontalSpacing, object.verticalSpacing); + this.setupItems(object.items); + this.setupRowHeight(object.rowHeight); + this.setupColWidth(object.colWidth); + this.setupInverted(object.inverted); }; /** - * Returns the height of the bitmap - * - * @since 2.0.0 - * @private - * @override - * - * @see DKTools.Layout.prototype.getMaxRows - * @see DKTools.Layout.prototype.getRowHeight - * - * @returns {Number} Height of the bitmap + * Sets the number of the columns + * + * @param {Number} [cols=this.standardMaxCols()] - Columns + * + * @see DKTools.Layout.prototype.standardMaxCols */ -DKTools.Layout.prototype._getBitmapHeight = function() { - let height = 0; - const maxRows = this.getMaxRows(); - - for (let i = 1; i <= maxRows; i++) { - height += this.getRowHeight(i) + this._verticalSpacing; - } - - return height - this._verticalSpacing; +DKTools.Layout.prototype.setupMaxCols = function(cols) { + /** + * @private + * @readonly + * @type {Number} + */ + this._maxCols = (cols == null ? this.standardMaxCols() : cols); }; -// get methods - /** - * Returns the maximum number of rows + * Sets the horizontal spacing * - * @see DKTools.Layout.prototype.getMaxItems - * @see DKTools.Layout.prototype.getMaxCols + * @param {Number} [spacing=this.standardHorizontalSpacing()] - Horizontal spacing * - * @returns {Number} Maximum number of rows + * @see DKTools.Layout.prototype.standardHorizontalSpacing */ -DKTools.Layout.prototype.getMaxRows = function() { - return Math.max(1, Math.ceil(this.getMaxItems() / this.getMaxCols())); +DKTools.Layout.prototype.setupHorizontalSpacing = function(spacing) { + /** + * @private + * @readonly + * @type {Number} + */ + this._horizontalSpacing = (spacing == null ? this.standardHorizontalSpacing() : spacing); }; /** - * Returns the maximum number of columns + * Sets the vertical spacing * - * @returns {Number} Maximum number of columns + * @param {Number} [spacing=this.standardVerticalSpacing()] - Vertical spacing + * + * @see DKTools.Layout.prototype.standardVerticalSpacing */ -DKTools.Layout.prototype.getMaxCols = function() { - return this._maxCols; +DKTools.Layout.prototype.setupVerticalSpacing = function(spacing) { + /** + * @private + * @readonly + * @type {Number} + */ + this._verticalSpacing = (spacing == null ? this.standardVerticalSpacing() : spacing); }; /** - * Returns the items + * Sets the horizontal and vertical spacing * - * @see DKTools.Layout.prototype.isInverted + * @param {Number} [horizontalSpacing] - Horizontal spacing + * @param {Number} [verticalSpacing] - Vertical spacing * - * @returns {DKTools.Sprite[] | *} Items + * @see DKTools.Layout.prototype.setupHorizontalSpacing + * @see DKTools.Layout.prototype.setupVerticalSpacing */ -DKTools.Layout.prototype.getItems = function() { - if (this.isInverted()) { - return _.reverse(_.clone(this._items)); - } - - return this._items; +DKTools.Layout.prototype.setupSpacing = function(horizontalSpacing, verticalSpacing) { + this.setupHorizontalSpacing(horizontalSpacing); + this.setupVerticalSpacing(verticalSpacing); }; /** - * Returns the number of the items + * Sets the items * - * @return {Number} Number of the items + * @param {DKTools.Sprite[] | *} [items=this.standardItems()] - Items + * + * @see DKTools.Layout.prototype.standardItems */ -DKTools.Layout.prototype.getMaxItems = function() { - return this._items.length; +DKTools.Layout.prototype.setupItems = function(items) { + items = items || this.standardItems(); + _.forEach(items, function(item) { + this._items.push(item); + }.bind(this)); }; /** - * Returns the index of the item - * - * @param {DKTools.Sprite | *} item - Item + * Sets the height of the row * - * @see DKTools.Layout.prototype.getItems + * @param {Function | Number} [rowHeight=this.standardRowHeight()] - Height of the row * - * @returns {Number} Index of the item + * @see DKTools.Layout.prototype.standardRowHeight */ -DKTools.Layout.prototype.getItemIndex = function(item) { - return _.indexOf(this.getItems(), item); +DKTools.Layout.prototype.setupRowHeight = function(rowHeight) { + /** + * @private + * @readonly + * @type {Function | Number} + */ + this._rowHeight = rowHeight || this.standardRowHeight(); }; /** - * Returns the item by index - * - * @param {Number} index - Index + * Sets the width of the column * - * @see DKTools.Layout.prototype.getItems + * @param {Function | Number} [colWidth=this.standardColWidth()] - Width of the column * - * @returns {DKTools.Sprite | * | undefined} Item by index or undefined + * @see DKTools.Layout.prototype.standardColWidth */ -DKTools.Layout.prototype.getItem = function(index) { - return this.getItems()[index]; +DKTools.Layout.prototype.setupColWidth = function(colWidth) { + /** + * @private + * @readonly + * @type {Function | Number} + */ + this._colWidth = colWidth || this.standardColWidth(); }; /** - * Returns the items in the row - * - * @param {Number} row - Row + * Sets the value of the invert * - * @see DKTools.Layout.prototype.getMaxCols - * @see DKTools.Layout.prototype.getMaxRows - * @see DKTools.Layout.prototype.getItem + * @param {Boolean} [inverted=this.standardInverted()] - Value of the ivnert * - * @returns {DKTools.Sprite[] | *} Items in the row + * @see DKTools.Layout.prototype.standardInverted */ -DKTools.Layout.prototype.getItemsInRow = function(row) { - const items = []; - const maxCols = this.getMaxCols(); - - if (row < 1 || row > this.getMaxRows()) { - return items; - } - - const startIndex = maxCols * (row - 1); - - for(let i = 0; i < maxCols; i++) { - items.push(this.getItem(startIndex + i)); - } - - return items; +DKTools.Layout.prototype.setupInverted = function(inverted) { + /** + * @private + * @readonly + * @type {Boolean} + */ + this._inverted = (inverted == null ? this.standardInverted() : inverted); }; +// set methods + /** - * Returns the items in the column + * Changes all parameters + * Returns the number of changed parameters * - * @param {Number} col - Column + * @override * - * @see DKTools.Layout.prototype.getMaxRows - * @see DKTools.Layout.prototype.getMaxCols - * @see DKTools.Layout.prototype.getItem + * @param {Object} [object={}] - Parameters + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the layout * - * @returns {DKTools.Sprite[] | *} Items in the column + * @param {Number} [object.maxCols] - Columns + * @param {Number} [object.horizontalSpacing] - Horizontal spacing + * @param {Number} [object.verticalSpacing] - Vertical spacing + * @param {Array} [object.items] - Items + * @param {Function | Number} [object.rowHeight] - Height of the row + * @param {Function | Number} [object.colWidth] - Width of the column + * @param {Boolean} [object.inverted] - Value of the invert + * + * @see DKTools.Sprite.prototype.setupAll + * @see DKTools.Layout.prototype.setMaxCols + * @see DKTools.Layout.prototype.setSpacing + * @see DKTools.Layout.prototype.setItems + * @see DKTools.Layout.prototype.setRowHeight + * @see DKTools.Layout.prototype.setColWidth + * @see DKTools.Layout.prototype.setInverted + * @see DKTools.Layout.prototype.start + * @see DKTools.Layout.prototype.activate + * + * @returns {Number} Number of changed parameters */ -DKTools.Layout.prototype.getItemsInCol = function(col) { - const items = []; - const maxRows = this.getMaxRows(); - const maxCols = this.getMaxCols(); - - if (col < 1 || col > maxCols) { - return items; +DKTools.Layout.prototype.setAll = function(object, blockStart, activate) { + object = object || {}; + const block = true; + let changed = DKTools.Sprite.prototype.setAll.call(this, object, block); + + if (this.setMaxCols(object.maxCols, block)) { + changed++; } - const startIndex = col - 1; + changed += this.setSpacing(object.horizontalSpacing, object.verticalSpacing, block); - for(let i = 0; i < maxRows; i++) { - items.push(this.getItem(startIndex + maxCols * i)); + if (this.setItems(object.items, block)) { + changed++; } - return items; -}; + if (this.setRowHeight(object.rowHeight, block)) { + changed++; + } -/** - * Returns the height of the row - * - * @param {Number} row - Row - * @returns {Number} Height of the row - */ -DKTools.Layout.prototype.getRowHeight = function(row) { - if (DKTools.Utils.isFunction(this._rowHeight)) { - return this._rowHeight(row); + if (this.setColWidth(object.colWidth, block)) { + changed++; } - return this._rowHeight; -}; + if (this.setInverted(object.reversed, block)) { + changed++; + } -/** - * Returns the width of the column - * - * @param {Number} col - Column - * @returns {Number} Width of the column - */ -DKTools.Layout.prototype.getColWidth = function(col) { - if (DKTools.Utils.isFunction(this._colWidth)) { - return this._colWidth(col); + if (changed) { + if (!blockStart) { + this.start(); + } + + if (activate) { + this.activate(); + } } - return this._colWidth; + return changed; }; /** - * Returns the Y coordinate of the row + * Changes the number of the columns + * Returns true if the change occurred * - * @param {Number} row - Row + * @param {Number} [cols] - Columns + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Layout.prototype.getRowHeight + * @see DKTools.Layout.prototype.setupMaxCols + * @see DKTools.Layout.prototype.start * - * @returns {Number} The Y coordinate of the row + * @returns {Boolean} Change occurred */ -DKTools.Layout.prototype.getRowY = function(row) { - let y = 0; +DKTools.Layout.prototype.setMaxCols = function(cols, blockStart) { + if (this._maxCols === cols) { + return false; + } - for(let i = 1; i < row; i++) { - y += this.getRowHeight(i) + this._verticalSpacing; + const lastCols = this._maxCols; + this.setupMaxCols(cols); + + if (this._maxCols === lastCols) { + return false; } - return y; + if (!blockStart) { + this.start(); + } + + return true; }; /** - * Returns the X coordinate of the column + * Changes the horizontal spacing + * Returns true if the change occurred * - * @param {Number} col - Column + * @param {Number} [scacing] - Horizontal spacing + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Layout.prototype.getColWidth + * @see DKTools.Layout.prototype.setupHorizontalSpacing + * @see DKTools.Layout.prototype.start * - * @returns {Number} The X coordinate of the column + * @returns {Boolean} Change occurred */ -DKTools.Layout.prototype.getColX = function(col) { - let x = 0; +DKTools.Layout.prototype.setHorizontalSpacing = function(scacing, blockStart) { + if (this._horizontalSpacing === scacing) { + return false; + } - for(let i = 1; i < col; i++) { - x += this.getColWidth(i) + this._horizontalSpacing; + const lastSpacing = this._horizontalSpacing; + this.setupHorizontalSpacing(scacing); + + if (this._horizontalSpacing === lastSpacing) { + return false; } - return x; + if (!blockStart) { + this.start(); + } + + return true; }; /** - * Returns the row of the item + * Changes the vertical spacing + * Returns true if the change occurred * - * @param {DKTools.Sprite | *} item - Item + * @param {Number} [scacing] - Vertical spacing + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Layout.prototype.getItemIndex - * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Layout.prototype.setupVerticalSpacing + * @see DKTools.Layout.prototype.start * - * @returns {Number} Row of the item or -1 + * @returns {Boolean} Change occurred */ -DKTools.Layout.prototype.getItemRow = function(item) { - const index = this.getItemIndex(item); +DKTools.Layout.prototype.setVerticalSpacing = function(scacing, blockStart) { + if (this._verticalSpacing === scacing) { + return false; + } - if (index >= 0) { - return Math.floor(index / this.getMaxCols()) + 1; + const lastSpacing = this._verticalSpacing; + this.setupVerticalSpacing(scacing); + + if (this._verticalSpacing === lastSpacing) { + return false; } - return -1; + if (!blockStart) { + this.start(); + } + + return true; }; /** - * Returns the column of the item + * Changes the horizontal and vertical spacing + * Returns the number of changed parameters * - * @param {DKTools.Sprite | *} item - Item + * @param {Number} [horizontalSpacing] - Horizontal spacing + * @param {Number} [verticalSpacing] - Vertical spacing + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Layout.prototype.getItemIndex - * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Layout.prototype.setHorizontalSpacing + * @see DKTools.Layout.prototype.setVerticalSpacing + * @see DKTools.Layout.prototype.start * - * @returns {Number} Column of the item or -1 + * @returns {Number} Number of changed parameters */ -DKTools.Layout.prototype.getItemCol = function(item) { - const index = this.getItemIndex(item); +DKTools.Layout.prototype.setSpacing = function(horizontalSpacing, verticalSpacing, blockStart) { + const block = true; + let changed = 0; - if (index >= 0) { - return (index % this.getMaxCols()) + 1; + if (this.setHorizontalSpacing(horizontalSpacing, block)) { + changed++; } - return -1; + if (this.setVerticalSpacing(verticalSpacing, block)) { + changed++; + } + + if (changed && !blockStart) { + this.start(); + } + + return changed; }; /** - * Returns the cell by row and column + * Changes the items + * Returns true if the change occurred * - * @param {Number} row - Row - * @param {Number} col - Col + * @param {DKTools.Sprite[] | *} [items] - Items + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Layout.prototype.getMaxCols - * @see DKTools.Layout.prototype.getColX - * @see DKTools.Layout.prototype.getRowY - * @see DKTools.Layout.prototype.getColWidth - * @see DKTools.Layout.prototype.getRowHeight + * @see DKTools.Layout.prototype.removeAllItems + * @see DKTools.Layout.prototype.setupItems + * @see DKTools.Layout.prototype.start * - * @returns {{ item: (DKTools.Sprite | * | undefined), x: Number, y: Number, width: Number, height: Number }} + * @returns {Boolean} Change occurred */ -DKTools.Layout.prototype.getCell = function(row, col) { - const index = this.getMaxCols() * (row - 1) + (col - 1); +DKTools.Layout.prototype.setItems = function(items, blockStart) { + if (this._items == items) { + return false; + } - return { - item: this.getItem(index), - x: this.getColX(col), - y: this.getRowY(row), - width: this.getColWidth(col), - height: this.getRowHeight(row) - }; -}; + this.removeAllItems(); + this.setupItems(items); -// move methods + if (!blockStart) { + this.start(); + } + + return true; +}; /** - * Moves the item + * Changes the height of the row + * Returns true if the change occurred * - * @param {Number} index - Index - * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - The X coordinate or Point or object with parameters - * @param {Number} [y] - The Y coordinate (if object is Number) + * @param {Function | Number} [rowHeight] - Height of the row + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @param {Number} [object.x] - The X coordinate - * @param {Number} [object.y] - The Y coordinate + * @see DKTools.Layout.prototype.setupRowHeight + * @see DKTools.Layout.prototype.start * - * @see DKTools.Layout.prototype.getItem + * @returns {Boolean} Change occurred */ -DKTools.Layout.prototype.moveItem = function(index, object, y) { - const item = this.getItem(index); - - if (item) { - item.move(object, y); +DKTools.Layout.prototype.setRowHeight = function(rowHeight, blockStart) { + if (this._rowHeight === rowHeight) { + return false; } -}; -// invert methods + const lastHeight = this._rowHeight; + this.setupRowHeight(rowHeight); -/** - * Inverts the layout - * - * @see DKTools.Layout.prototype.isInverted - * @see DKTools.Layout.prototype.setInverted - */ -DKTools.Layout.prototype.invert = function() { - this.setInverted(!this.isInverted()); -}; + if (this._rowHeight === lastHeight) { + return false; + } -// is methods + if (!blockStart) { + this.start(); + } -/** - * Returns true if the layout is empty - * - * @see DKTools.Layout.prototype.getMaxItems - * - * @returns {Boolean} Layout is empty - */ -DKTools.Layout.prototype.isEmpty = function() { - return this.getMaxItems() === 0; + return true; }; /** - * Returns true if the layout is ready + * Changes the width of the column + * Returns true if the change occurred * - * @override + * @param {Function | Number} [colWidth] - Width of the column + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Layout.prototype.isEmpty + * @see DKTools.Layout.prototype.setupColWidth + * @see DKTools.Layout.prototype.start * - * @returns {Boolean} Layout is ready + * @returns {Boolean} Change occurred */ -DKTools.Layout.prototype.isReady = function() { - return this.isEmpty() || _.every(this._items, function(item) { - return item.isReady(); - }); -}; +DKTools.Layout.prototype.setColWidth = function(colWidth, blockStart) { + if (this._colWidth === colWidth) { + return false; + } -/** - * Returns true if the layout is inverted - * - * @returns {Boolean} Layout is inverted - */ -DKTools.Layout.prototype.isInverted = function() { - return this._inverted; + const lastWidth = this._colWidth; + this.setupColWidth(colWidth); + + if (this._colWidth === lastWidth) { + return false; + } + + if (!blockStart) { + this.start(); + } + + return true; }; /** - * Returns true if the layout is horizontal + * Changes the value of the invert + * Returns true if the change occurred * - * @see DKTools.Layout.prototype.getMaxRows + * @param {Boolean} [inverted] - Value of the invert + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @returns {boolean} Layout is horizontal + * @see DKTools.Layout.prototype.setupInverted + * @see DKTools.Layout.prototype.start + * + * @returns {Boolean} Change occurred */ -DKTools.Layout.prototype.isHorizontal = function() { - return this.getMaxRows() === 1; +DKTools.Layout.prototype.setInverted = function(inverted, blockStart) { + if (this._inverted === inverted) { + return false; + } + + const lastReversed = this._inverted; + this.setupInverted(inverted); + + if (this._inverted === lastReversed) { + return false; + } + + if (!blockStart) { + this.start(); + } + + return true; }; +// start methods + /** - * Returns true if the layout is vertical - * - * @see DKTools.Layout.prototype.getMaxCols + * Starts the layout * - * @returns {boolean} Layout is vertical + * @override + * + * @see DKTools.Sprite.prototype.start + * @see DKTools.Layout.prototype.isReady + * @see DKTools.Layout.prototype.addOneTimeEvent */ -DKTools.Layout.prototype.isVertical = function() { - return this.getMaxCols() === 1; +DKTools.Layout.prototype.start = function() { + this._started = true; + + if (this.isReady()) { + DKTools.Sprite.prototype.start.call(this); + } else { + this.addOneTimeEvent({ + type: 'ready', + onSuccess: this.start.bind(this) + }); + } }; -// has methods +// remove methods /** - * Returns true if the layout has the items + * Removes children objects from processing * - * @see DKTools.Layout.prototype.isEmpty + * @override * - * @returns {Boolean} Layout has the items + * @see DKTools.Sprite.prototype.removeAllChildren + * @see DKTools.Layout.prototype.removeAllItems */ -DKTools.Layout.prototype.hasItems = function() { - return !this.isEmpty(); +DKTools.Layout.prototype.removeAllChildren = function() { + DKTools.Sprite.prototype.removeAllChildren.call(this); + this.removeAllItems(); }; /** - * Returns true if the layout has the item - * - * @param {DKTools.Sprite | *} item - Item - * - * @see DKTools.Layout.prototype.getItemIndex + * Removes items from processing * - * @returns {Boolean} Layout has the item + * @see DKTools.Layout.prototype.removeChild */ -DKTools.Layout.prototype.hasItem = function(item) { - return this.getItemIndex(item) >= 0; +DKTools.Layout.prototype.removeAllItems = function() { + this.removeChild.apply(this, this._items); }; -// items methods - /** - * Calls the callback function for the items + * Removes the item * - * @param {Function} callback - Function for the items - * @param {Boolean} [start=false] - Call of the "start" function + * @param {DKTools.Sprite | *} item - Item + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Layout.prototype.getItems + * @see DKTools.Layout.prototype.hasItem + * @see DKTools.Layout.prototype.removeChild * @see DKTools.Layout.prototype.start + * @see DKTools.Utils.Array.remove */ -DKTools.Layout.prototype.iterateItems = function(callback, start) { - _.forEach(this.getItems(), callback); +DKTools.Layout.prototype.removeItem = function(item, blockStart) { + if (!this.hasItem(item)) { + return; + } - if (start) { + this.removeChild(item); + + DKTools.Utils.Array.remove(this._items, item); + + if (!blockStart) { this.start(); } }; /** - * Starts the items - * - * @param {Boolean} [activate=false] - Activates the item - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * - * @see DKTools.Layout.prototype.iterateItems - */ -DKTools.Layout.prototype.startItems = function(activate, blockStart) { - const callback = function(item) { - item.start(activate); - }; - this.iterateItems(callback, !blockStart); -}; - -/** - * Resizes the item + * Removes the items * - * @param {DKTools.Sprite | *} item - Item - * @param {Number} [width] - Width of the item - * @param {Number} [height] - Height of the item + * @param {Array} items - Items * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Layout.prototype.hasItem + * @see DKTools.Layout.prototype.removeItem * @see DKTools.Layout.prototype.start */ -DKTools.Layout.prototype.resizeItem = function(item, width, height, blockStart) { - if (this.hasItem(item) && item.resize(width, height)) { - if (!blockStart) { - this.start(); - } +DKTools.Layout.prototype.removeItems = function(items, blockStart) { + _.forEach(items, function(item) { + this.removeItem(item, true); + }.bind(this)); + + if (!blockStart) { + this.start(); } }; /** - * Resizes the item by index + * Removes the item by index * * @param {Number} index - Index - * @param {Number} [width] - Width of the item - * @param {Number} [height] - Height of the item * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * * @see DKTools.Layout.prototype.getItem - * @see DKTools.Layout.prototype.resizeItem + * @see DKTools.Layout.prototype.removeItem */ -DKTools.Layout.prototype.resizeItemByIndex = function(index, width, height, blockStart) { - this.resizeItem(this.getItem(index), width, height, blockStart); +DKTools.Layout.prototype.removeItemByIndex = function(index, blockStart) { + this.removeItem(this.getItem(index), blockStart); }; /** - * Resizes the items + * Removes the columns * - * @param {Number} [width] - Width of the item - * @param {Number} [height] - Height of the item - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Number} cols - Columns * - * @see DKTools.Layout.prototype.resizeItem - * @see DKTools.Layout.prototype.iterateItems + * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Layout.prototype.addCols */ -DKTools.Layout.prototype.resizeItems = function(width, height, blockStart) { - const callback = function(item) { - this.resizeItem(item, width, height, true); - }.bind(this); - this.iterateItems(callback, !blockStart); +DKTools.Layout.prototype.removeCols = function(cols) { + if (this.getMaxCols() - cols >= 1) { + this.addCols(-cols); + } }; /** - * Activates the items - * - * @param {Boolean} [start=false] - Call of the "start" function + * Removes the column * - * @see DKTools.Layout.prototype.iterateItems + * @see DKTools.Layout.prototype.removeCols */ -DKTools.Layout.prototype.activateItems = function(start) { - const callback = function(item) { - item.activate(); - }; - this.iterateItems(callback, start); +DKTools.Layout.prototype.removeCol = function() { + this.removeCols(1); }; -/** - * Deactivates the items - * - * @param {Boolean} [start=false] - Call of the "start" function - * - * @see DKTools.Layout.prototype.iterateItems - */ -DKTools.Layout.prototype.deactivateItems = function(start) { - const callback = function(item) { - item.deactivate(); - }; - this.iterateItems(callback, start); -}; +// add methods /** - * Shows the items - * - * @param {Boolean} [activate=false] - Activates the items - * @param {Boolean} [start=false] - Call of the "start" function + * Adds children objects to processing * - * @see DKTools.Layout.prototype.iterateItems + * @override + * + * @see DKTools.Sprite.prototype.addAllChildren + * @see DKTools.Layout.prototype.addAllItems */ -DKTools.Layout.prototype.showItems = function(activate, start) { - const callback = function(item) { - item.show(activate); - }; - this.iterateItems(callback, start); +DKTools.Layout.prototype.addAllChildren = function() { + DKTools.Sprite.prototype.addAllChildren.call(this); + this.addAllItems(); }; /** - * Hides the items - * - * @param {Boolean} [blockDeactivate=false] - Block deactivation of the items - * @param {Boolean} [start=false] - Call of the "start" function + * Adds the itemns to processing * - * @see DKTools.Layout.prototype.iterateItems + * @see DKTools.Layout.prototype.addChild */ -DKTools.Layout.prototype.hideItems = function(blockDeactivate, start) { - const callback = function(item) { - item.hide(blockDeactivate); - }; - this.iterateItems(callback, start); +DKTools.Layout.prototype.addAllItems = function() { + this.addChild.apply(this, this._items); }; -// align methods - /** - * Aligns the item - * - * @param {DKTools.Sprite | * | Number} item - Item or index - * - * @see DKTools.Layout.prototype.isReady - * @see DKTools.Layout.prototype.getItemRow - * @see DKTools.Layout.prototype.getItemCol - * @see DKTools.Layout.prototype.getRowHeight - * @see DKTools.Layout.prototype.getColWidth - * @see DKTools.Layout.prototype.getColX - * @see DKTools.Layout.prototype.getRowY - * @see DKTools.Layout.prototype.addOneTimeEvent - */ -DKTools.Layout.prototype.alignItem = function(item) { - if (this.isReady()) { - const itemRow = this.getItemRow(item); - const itemCol = this.getItemCol(item); - const rowHeight = this.getRowHeight(itemRow); - const colWidth = this.getColWidth(itemCol); - const x = this.getColX(itemCol) + (colWidth - item.width) / 2; - const y = this.getRowY(itemRow) + (rowHeight - item.height) / 2; + * Adds the item + * + * @param {DKTools.Sprite | *} item - Item + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.start + */ +DKTools.Layout.prototype.addItem = function(item, blockStart) { + if (!(item instanceof DKTools.Sprite)) { + return; + } - item.move(x, y); - } else { - this.addOneTimeEvent({ - type: 'ready', - onSuccess: this.alignItem.bind(this, item) - }); + this._items.push(item); + + if (!blockStart) { + this.start(); } }; /** - * Aligns the row + * Adds the items * - * @param {Number} row - Row + * @param {DKTools.Sprite[] | *} items - Items + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Layout.prototype.getItemsInRow - * @see DKTools.Layout.prototype.alignItem + * @see DKTools.Layout.prototype.addItem + * @see DKTools.Layout.prototype.start */ -DKTools.Layout.prototype.alignRow = function(row) { - _.forEach(this.getItemsInRow(row), this.alignItem.bind(this)); +DKTools.Layout.prototype.addItems = function(items, blockStart) { + _.forEach(items, function(item) { + this.addItem(item, true); + }.bind(this)); + + if (!blockStart) { + this.start(); + } }; /** - * Aligns the column + * Adds the columns * - * @param {Number} col - Column + * @param {Number} cols - Columns * - * @see DKTools.Layout.prototype.getItemsInCol - * @see DKTools.Layout.prototype.alignItem + * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Layout.prototype.setMaxCols */ -DKTools.Layout.prototype.alignCol = function(col) { - _.forEach(this.getItemsInCol(col), this.alignItem.bind(this)); +DKTools.Layout.prototype.addCols = function(cols) { + this.setMaxCols(this.getMaxCols() + cols); }; /** - * Aligns the items + * Adds the column * - * @see DKTools.Layout.prototype.addOneTimeEvent - * @see DKTools.Layout.prototype.iterateItems - * @see DKTools.Layout.prototype.alignItem + * @see DKTools.Layout.prototype.addCols */ -DKTools.Layout.prototype.alignItems = function() { - this.addOneTimeEvent({ - type: 'ready', - onSuccess: function() { - this.iterateItems(this.alignItem.bind(this)) - }.bind(this) - }); +DKTools.Layout.prototype.addCol = function() { + this.addCols(1); }; -// update methods +// can methods /** - * Updates all + * Returns true if the layout can clone the fixed bitmap * * @override - * - * @see DKTools.Sprite.prototype.updateAll - * @see DKTools.Layout.prototype.updateLayout + * @returns {Boolean} Layout can clone the fixed bitmap */ -DKTools.Layout.prototype.updateAll = function() { - DKTools.Sprite.prototype.updateAll.call(this); - this.updateLayout(); +DKTools.Layout.prototype.canCloneFixedBitmap = function() { + return false; }; +// _get methods + /** - * Updates the layout - * - * @see DKTools.Layout.prototype.getMaxItems - * @see DKTools.Layout.prototype.getMaxRows + * Returns the width of the bitmap + * + * @since 2.0.0 + * @private + * @override + * * @see DKTools.Layout.prototype.getMaxCols - * @see DKTools.Layout.prototype.getColX - * @see DKTools.Layout.prototype.getRowY - * @see DKTools.Layout.prototype.moveItem + * @see DKTools.Layout.prototype.getColWidth + * + * @returns {Number} Width of the bitmap */ -DKTools.Layout.prototype.updateLayout = function() { - const maxItems = this.getMaxItems(); - const maxRows = this.getMaxRows(); +DKTools.Layout.prototype._getBitmapWidth = function() { + let width = 0; const maxCols = this.getMaxCols(); - let index = 0; - - for(let i = 1; i <= maxRows && index < maxItems; i++) { - for(let j = 1; j <= maxCols && index < maxItems; j++) { - const x = this.getColX(j); - const y = this.getRowY(i); - this.moveItem(index++, x, y); - } + for (let i = 1; i <= maxCols; i++) { + width += this.getColWidth(i) + this._horizontalSpacing; } -}; - - - - - -//=========================================================================== -// DKTools.Window -//=========================================================================== -DKTools.Window.prototype = Object.create(Window_Base.prototype); -DKTools.Utils.mixin(DKTools.Window.prototype, DKTools.Base.prototype); -DKTools.Window.prototype.constructor = DKTools.Window; + return width - this._horizontalSpacing; +}; /** - * Counter of created windows - * + * Returns the height of the bitmap + * + * @since 2.0.0 * @private - * @readonly - * @type {Number} - * @memberof DKTools.Window - */ -DKTools.Window._counter = 0; - -// properties - -Object.defineProperties(DKTools.Window.prototype, { - - /** - * Real width of the window (not including scaling) - * - * @readonly - * @type {Number} - * @memberof DKTools.Window.prototype - */ - realWidth: { - get: function() { - return this._width; - }, - set: function(value) { - this._width = value; - this._refreshAllParts(); - }, - configurable: true - }, - - /** - * Real height of the window (not including scaling) - * - * @readonly - * @type {Number} - * @memberof DKTools.Window.prototype - */ - realHeight: { - get: function() { - return this._height; - }, - set: function(value) { - this._height = value; - this._refreshAllParts(); - }, - configurable: true - }, - - /** - * Width of the window (taking into account scaling) - * - * @type {Number} - * @memberof DKTools.Window.prototype - */ - width: { - get: function() { - return this.realWidth * this.scale.x; - }, - set: function(value) { - this._width = Math.floor(value / this.scale.x); - this._refreshAllParts(); - }, - configurable: true - }, - - /** - * Height of the window (taking into account scaling) - * - * @type {Number} - * @memberof DKTools.Window.prototype - */ - height: { - get: function() { - return this.realHeight * this.scale.y; - }, - set: function(value) { - this._height = Math.floor(value / this.scale.y); - this._refreshAllParts(); - }, - configurable: true - }, - - /** - * Origin - * - * @readonly - * @type {Point} - * @memberof DKTools.Window.prototype - */ - origin: { - get: function() { - return this._origin; - }, - configurable: true - }, - - /** - * Opacity of the window - * - * @type {Number} - * @memberof DKTools.Window.prototype - */ - windowOpacity: { - get: function() { - return this._windowSpriteContainer.alpha * 255; - }, - set: function(value) { - this._windowSpriteContainer.alpha = _.clamp(value, 0, 255) / 255; - }, - configurable: true - }, - - /** - * Opacity of the frame - * - * @type {Number} - * @memberof DKTools.Window.prototype - */ - frameOpacity: { - get: function() { - return this._windowFrameSprite.alpha * 255; - }, - set: function(value) { - this._windowFrameSprite.alpha = _.clamp(value, 0, 255) / 255; - }, - configurable: true - }, + * @override + * + * @see DKTools.Layout.prototype.getMaxRows + * @see DKTools.Layout.prototype.getRowHeight + * + * @returns {Number} Height of the bitmap + */ +DKTools.Layout.prototype._getBitmapHeight = function() { + let height = 0; + const maxRows = this.getMaxRows(); - /** - * Opacity of the window - * - * @readonly - * @type {Object} - * @memberof DKTools.Window.prototype - */ - opacity: { - get: function() { - return this._opacity; - }, - configurable: true - }, + for (let i = 1; i <= maxRows; i++) { + height += this.getRowHeight(i) + this._verticalSpacing; + } - /** - * Tone of the window - * - * @readonly - * @type {Number[]} - * @memberof DKTools.Window.prototype - */ - tone: { - get: function() { - return this._tone; - }, - configurable: true - }, + return height - this._verticalSpacing; +}; - /** - * Sprite of the contents - * - * @readonly - * @type {DKTools.Sprite} - * @memberof DKTools.Window.prototype - */ - contentsSprite: { - get: function() { - return this._windowContentsSprite; - }, - configurable: true - }, +// get methods - /** - * Sprite of the frame - * - * @readonly - * @type {Sprite} - * @memberof DKTools.Window.prototype - */ - frameSprite: { - get: function() { - return this._windowFrameSprite; - }, - configurable: true - }, +/** + * Returns the maximum number of rows + * + * @see DKTools.Layout.prototype.getMaxItems + * @see DKTools.Layout.prototype.getMaxCols + * + * @returns {Number} Maximum number of rows + */ +DKTools.Layout.prototype.getMaxRows = function() { + return Math.max(1, Math.ceil(this.getMaxItems() / this.getMaxCols())); +}; - /** - * Sprite of the background - * - * @readonly - * @type {Sprite} - * @memberof DKTools.Window.prototype - */ - backSprite: { - get: function() { - return this._windowBackSprite; - }, - configurable: true - }, +/** + * Returns the maximum number of columns + * + * @returns {Number} Maximum number of columns + */ +DKTools.Layout.prototype.getMaxCols = function() { + return this._maxCols; +}; - /** - * Bitmap of sprite of the contents - * To support functions from DKTools.Base - * - * @type {Bitmap} - * @memberof DKTools.Window.prototype - */ - bitmap: { - get: function() { - return this.contents; - }, - set: function(value) { - this.contents = value; - }, - configurable: true +/** + * Returns the items + * + * @see DKTools.Layout.prototype.isInverted + * + * @returns {DKTools.Sprite[] | *} Items + */ +DKTools.Layout.prototype.getItems = function() { + if (this.isInverted()) { + return _.reverse(_.clone(this._items)); } -}); + return this._items; +}; -// initialize methods +/** + * Returns the number of the items + * + * @return {Number} Number of the items + */ +DKTools.Layout.prototype.getMaxItems = function() { + return this._items.length; +}; /** - * Initializes a class object + * Returns the index of the item * - * @override + * @param {DKTools.Sprite | *} item - Item * - * @param {Number | Object} [object] - The X coordinate - * @param {Number} [y] - The Y coordinate - * @param {Number} [width] - Width of the window - * @param {Number} [height] - Height of the window + * @see DKTools.Layout.prototype.getItems * - * @see PIXI.Container - * @see DKTools.Base.prototype.initialize + * @returns {Number} Index of the item */ -DKTools.Window.prototype.initialize = function(object, y, width, height) { - PIXI.Container.call(this); - DKTools.Base.prototype.initialize.call(this, object, y, width, height); - DKTools.Window._counter++; +DKTools.Layout.prototype.getItemIndex = function(item) { + return _.indexOf(this.getItems(), item); }; -// _clear methods +/** + * Returns the item by index + * + * @param {Number} index - Index + * + * @see DKTools.Layout.prototype.getItems + * + * @returns {DKTools.Sprite | * | undefined} Item by index or undefined + */ +DKTools.Layout.prototype.getItem = function(index) { + return this.getItems()[index]; +}; /** - * Clears all data + * Returns the items in the row * - * @private - * @override - * - * @see DKTools.Base.prototype._clearAll - * @see DKTools.Window.prototype._clearIsWindow - * @see DKTools.Window.prototype._clearOpenness - * @see DKTools.Window.prototype._clearPadding - * @see DKTools.Window.prototype._clearMargin - * @see DKTools.Window.prototype._clearColorTone - * @see DKTools.Window.prototype._clearOrigin - * @see DKTools.Window.prototype._clearArrows + * @param {Number} row - Row + * + * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Layout.prototype.getMaxRows + * @see DKTools.Layout.prototype.getItem + * + * @returns {DKTools.Sprite[] | *} Items in the row */ -DKTools.Window.prototype._clearAll = function() { - DKTools.Base.prototype._clearAll.call(this); - this._clearIsWindow(); - this._clearOpenness(); - this._clearPadding(); - this._clearMargin(); - this._clearColorTone(); - this._clearOrigin(); - this._clearArrows(); +DKTools.Layout.prototype.getItemsInRow = function(row) { + const items = []; + const maxCols = this.getMaxCols(); + + if (row < 1 || row > this.getMaxRows()) { + return items; + } + + const startIndex = maxCols * (row - 1); + + for(let i = 0; i < maxCols; i++) { + items.push(this.getItem(startIndex + i)); + } + + return items; +}; + +/** + * Returns the items in the column + * + * @param {Number} col - Column + * + * @see DKTools.Layout.prototype.getMaxRows + * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Layout.prototype.getItem + * + * @returns {DKTools.Sprite[] | *} Items in the column + */ +DKTools.Layout.prototype.getItemsInCol = function(col) { + const items = []; + const maxRows = this.getMaxRows(); + const maxCols = this.getMaxCols(); + + if (col < 1 || col > maxCols) { + return items; + } + + const startIndex = col - 1; + + for(let i = 0; i < maxRows; i++) { + items.push(this.getItem(startIndex + maxCols * i)); + } + + return items; +}; + +/** + * Returns the height of the row + * + * @param {Number} row - Row + * @returns {Number} Height of the row + */ +DKTools.Layout.prototype.getRowHeight = function(row) { + if (DKTools.Utils.isFunction(this._rowHeight)) { + return this._rowHeight(row); + } + + return this._rowHeight; +}; + +/** + * Returns the width of the column + * + * @param {Number} col - Column + * @returns {Number} Width of the column + */ +DKTools.Layout.prototype.getColWidth = function(col) { + if (DKTools.Utils.isFunction(this._colWidth)) { + return this._colWidth(col); + } + + return this._colWidth; }; /** - * Clears the "isWindow" + * Returns the Y coordinate of the row * - * @private + * @param {Number} row - Row + * + * @see DKTools.Layout.prototype.getRowHeight + * + * @returns {Number} The Y coordinate of the row */ -DKTools.Window.prototype._clearIsWindow = function() { - /** - * @private - * @readonly - * @type {Boolean} - */ - this._isWindow = true; +DKTools.Layout.prototype.getRowY = function(row) { + let y = 0; + + for(let i = 1; i < row; i++) { + y += this.getRowHeight(i) + this._verticalSpacing; + } + + return y; }; /** - * Clears the openness + * Returns the X coordinate of the column * - * @private - * - * @see DKTools.Window.prototype.standardOpenness + * @param {Number} col - Column + * + * @see DKTools.Layout.prototype.getColWidth + * + * @returns {Number} The X coordinate of the column */ -DKTools.Window.prototype._clearOpenness = function() { - /** - * @private - * @readonly - * @type {Number} - */ - this._openness = this.standardOpenness(); +DKTools.Layout.prototype.getColX = function(col) { + let x = 0; + + for(let i = 1; i < col; i++) { + x += this.getColWidth(i) + this._horizontalSpacing; + } + + return x; }; /** - * Clears the padding + * Returns the row of the item * - * @private - * - * @see DKTools.Window.prototype.standardPadding + * @param {DKTools.Sprite | *} item - Item + * + * @see DKTools.Layout.prototype.getItemIndex + * @see DKTools.Layout.prototype.getMaxCols + * + * @returns {Number} Row of the item or -1 */ -DKTools.Window.prototype._clearPadding = function() { - /** - * @private - * @readonly - * @type {Number} - */ - this._padding = this.standardPadding(); +DKTools.Layout.prototype.getItemRow = function(item) { + const index = this.getItemIndex(item); + + if (index >= 0) { + return Math.floor(index / this.getMaxCols()) + 1; + } + + return -1; }; /** - * Clears the margin + * Returns the column of the item * - * @private - * - * @see DKTools.Window.prototype.standardMargin + * @param {DKTools.Sprite | *} item - Item + * + * @see DKTools.Layout.prototype.getItemIndex + * @see DKTools.Layout.prototype.getMaxCols + * + * @returns {Number} Column of the item or -1 */ -DKTools.Window.prototype._clearMargin = function() { - /** - * @private - * @readonly - * @type {Number} - */ - this._margin = this.standardMargin(); +DKTools.Layout.prototype.getItemCol = function(item) { + const index = this.getItemIndex(item); + + if (index >= 0) { + return (index % this.getMaxCols()) + 1; + } + + return -1; }; /** - * Clears the color tone + * Returns the cell by row and column * - * @private - * - * @see DKTools.Window.prototype.standardTone + * @param {Number} row - Row + * @param {Number} col - Col + * + * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Layout.prototype.getColX + * @see DKTools.Layout.prototype.getRowY + * @see DKTools.Layout.prototype.getColWidth + * @see DKTools.Layout.prototype.getRowHeight + * + * @returns {{ item: (DKTools.Sprite | * | undefined), x: Number, y: Number, width: Number, height: Number }} */ -DKTools.Window.prototype._clearColorTone = function() { - /** - * @private - * @readonly - * @type {Number[]} - */ - this._colorTone = this.standardTone(); +DKTools.Layout.prototype.getCell = function(row, col) { + const index = this.getMaxCols() * (row - 1) + (col - 1); + + return { + item: this.getItem(index), + x: this.getColX(col), + y: this.getRowY(row), + width: this.getColWidth(col), + height: this.getRowHeight(row) + }; }; +// move methods + /** - * Clears the origin + * Moves the item * - * @private - * - * @see DKTools.Window.prototype.standardOrigin + * @param {Number} index - Index + * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - The X coordinate or Point or object with parameters + * @param {Number} [y] - The Y coordinate (if object is Number) + * + * @param {Number} [object.x] - The X coordinate + * @param {Number} [object.y] - The Y coordinate + * + * @see DKTools.Layout.prototype.getItem */ -DKTools.Window.prototype._clearOrigin = function() { - /** - * @private - * @readonly - * @type {Point} - */ - this._origin = this.standardOrigin(); +DKTools.Layout.prototype.moveItem = function(index, object, y) { + const item = this.getItem(index); + + if (item) { + item.move(object, y); + } }; +// invert methods + /** - * Clears the arrows + * Inverts the layout * - * @private + * @see DKTools.Layout.prototype.isInverted + * @see DKTools.Layout.prototype.setInverted */ -DKTools.Window.prototype._clearArrows = function() { - /** - * @private - * @readonly - * @type {DKTools.Sprite.Arrow[]} - */ - this._arrows = []; +DKTools.Layout.prototype.invert = function() { + this.setInverted(!this.isInverted()); }; -// _create methods +// is methods /** - * Creates all + * Returns true if the layout is empty * - * @private - * @override + * @see DKTools.Layout.prototype.getMaxItems * - * @see DKTools.Base.prototype._createAll - * @see DKTools.Window.prototype._createAllParts - * @see DKTools.Window.prototype._createWindowskin + * @returns {Boolean} Layout is empty */ -DKTools.Window.prototype._createAll = function() { - DKTools.Base.prototype._createAll.call(this); - this._createAllParts(); - this._createWindowskin(); +DKTools.Layout.prototype.isEmpty = function() { + return this.getMaxItems() === 0; }; /** - * Creates all parts of the window + * Returns true if the layout is ready * - * @private * @override * - * @see DKTools.Window.prototype._createSpriteContainer - * @see DKTools.Window.prototype._createBackSprite - * @see DKTools.Window.prototype._createFrameSprite - * @see DKTools.Window.prototype._createPauseSignSprite - */ -DKTools.Window.prototype._createAllParts = function() { - this._createSpriteContainer(); - this._createBackSprite(); - this._createFrameSprite(); - this._createPauseSignSprite(); -}; - -/** - * Creates the container of the sprites + * @see DKTools.Layout.prototype.isEmpty * - * @private - * - * @see PIXI.Container + * @returns {Boolean} Layout is ready */ -DKTools.Window.prototype._createSpriteContainer = function() { - /** - * @private - * @readonly - * @type {PIXI.Container} - */ - this._windowSpriteContainer = new PIXI.Container(); +DKTools.Layout.prototype.isReady = function() { + return this.isEmpty() || _.every(this._items, function(item) { + return item.isReady(); + }); }; /** - * Creates the sprite of the background + * Returns true if the layout is inverted * - * @private - * - * @see DKTools.Window.prototype.needsCreateBackSprite - * @see DKTools.Window.prototype.standardBackOpacity - * @see DKTools.Window.prototype.standardBackVisible + * @returns {Boolean} Layout is inverted */ -DKTools.Window.prototype._createBackSprite = function() { - if (this.needsCreateBackSprite()) { - /** - * @private - * @readonly - * @type {Sprite} - */ - this._windowBackSprite = new Sprite(); - this._windowBackSprite.opacity = this.standardBackOpacity(); - this._windowBackSprite.visible = this.standardBackVisible(); - } +DKTools.Layout.prototype.isInverted = function() { + return this._inverted; }; /** - * Creates the sprtie of the frame + * Returns true if the layout is horizontal * - * @private - * - * @see DKTools.Window.prototype.needsCreateFrameSprite - * @see DKTools.Window.prototype.standardFrameVisible + * @see DKTools.Layout.prototype.getMaxRows + * + * @returns {boolean} Layout is horizontal */ -DKTools.Window.prototype._createFrameSprite = function() { - if (this.needsCreateFrameSprite()) { - /** - * @private - * @readonly - * @type {Sprite} - */ - this._windowFrameSprite = new Sprite(); - this._windowFrameSprite.visible = this.standardFrameVisible(); - } +DKTools.Layout.prototype.isHorizontal = function() { + return this.getMaxRows() === 1; }; /** - * Creates the sprite of the pause sign + * Returns true if the layout is vertical * - * @private - * - * @see DKTools.Window.prototype.needsCreatePauseSignSprite + * @see DKTools.Layout.prototype.getMaxCols + * + * @returns {boolean} Layout is vertical */ -DKTools.Window.prototype._createPauseSignSprite = function() { - if (this.needsCreatePauseSignSprite()) { - /** - * @private - * @readonly - * @type {Sprite} - */ - this._windowPauseSignSprite = new Sprite(); - } +DKTools.Layout.prototype.isVertical = function() { + return this.getMaxCols() === 1; }; +// has methods + /** - * Creates the window skin + * Returns true if the layout has the items * - * @private + * @see DKTools.Layout.prototype.isEmpty * - * @see DKTools.Window.prototype.loadWindowskin + * @returns {Boolean} Layout has the items */ -DKTools.Window.prototype._createWindowskin = function() { - this.windowskin = this.loadWindowskin(); +DKTools.Layout.prototype.hasItems = function() { + return !this.isEmpty(); }; -// _setup methods +/** + * Returns true if the layout has the item + * + * @param {DKTools.Sprite | *} item - Item + * + * @see DKTools.Layout.prototype.getItemIndex + * + * @returns {Boolean} Layout has the item + */ +DKTools.Layout.prototype.hasItem = function(item) { + return this.getItemIndex(item) >= 0; +}; + +// items methods /** - * Sets the events + * Calls the callback function for the items * - * @private - * @override + * @param {Function} callback - Function for the items + * @param {Boolean} [start=false] - Call of the "start" function * - * @see DKTools.Base.prototype._setupEvents - * @see DKTools.Base.prototype.needsCreateArrowsSprites - * @see DKTools.Base.prototype._setupCreateArrowsEvent + * @see DKTools.Layout.prototype.getItems + * @see DKTools.Layout.prototype.start */ -DKTools.Window.prototype._setupEvents = function() { - DKTools.Base.prototype._setupEvents.call(this); +DKTools.Layout.prototype.iterateItems = function(callback, start) { + _.forEach(this.getItems(), callback); - if (this.needsCreateArrowsSprites()) { - this._setupCreateArrowsEvent(); + if (start) { + this.start(); } }; /** - * Sets the create arrows event - * - * @private - * - * @see DKTools.Window.prototype.addOneTimeEvent + * Starts the items + * + * @param {Boolean} [activate=false] - Activates the item + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.iterateItems */ -DKTools.Window.prototype._setupCreateArrowsEvent = function() { - this.addOneTimeEvent({ - type: 'create-all', - onSuccess: this.createArrows.bind(this) - }); +DKTools.Layout.prototype.startItems = function(activate, blockStart) { + const callback = function(item) { + item.start(activate); + }; + this.iterateItems(callback, !blockStart); }; -// _add methods - /** - * Adds children objects to processing + * Resizes the item * - * @private - * @override + * @param {DKTools.Sprite | *} item - Item + * @param {Number} [width] - Width of the item + * @param {Number} [height] - Height of the item + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Base.prototype._addAllChildren - * @see DKTools.Window.prototype._addAllParts + * @see DKTools.Layout.prototype.hasItem + * @see DKTools.Layout.prototype.start */ -DKTools.Window.prototype._addAllChildren = function() { - DKTools.Base.prototype._addAllChildren.call(this); - this._addAllParts(); +DKTools.Layout.prototype.resizeItem = function(item, width, height, blockStart) { + if (this.hasItem(item) && item.resize(width, height)) { + if (!blockStart) { + this.start(); + } + } }; /** - * Adds all parts of the window to processing + * Resizes the item by index * - * @private + * @param {Number} index - Index + * @param {Number} [width] - Width of the item + * @param {Number} [height] - Height of the item + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function * - * @see DKTools.Window.prototype._addSpriteContainer - * @see DKTools.Window.prototype._addPauseSignSprite + * @see DKTools.Layout.prototype.getItem + * @see DKTools.Layout.prototype.resizeItem */ -DKTools.Window.prototype._addAllParts = function() { - this._addSpriteContainer(); - this._addPauseSignSprite(); +DKTools.Layout.prototype.resizeItemByIndex = function(index, width, height, blockStart) { + this.resizeItem(this.getItem(index), width, height, blockStart); }; /** - * Adds the container of the sprites to processing + * Resizes the items * - * @private - * - * @see DKTools.Window.prototype.hasSpriteContainer - * @see DKTools.Window.prototype.hasBackSprite - * @see DKTools.Window.prototype.hasFrameSprite + * @param {Number} [width] - Width of the item + * @param {Number} [height] - Height of the item + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * + * @see DKTools.Layout.prototype.resizeItem + * @see DKTools.Layout.prototype.iterateItems */ -DKTools.Window.prototype._addSpriteContainer = function() { - if (this.hasSpriteContainer()) { - if (this.hasBackSprite()) { - this._windowSpriteContainer.addChild(this._windowBackSprite); - } - - if (this.hasFrameSprite()) { - this._windowSpriteContainer.addChild(this._windowFrameSprite); - } - - this.addChild(this._windowSpriteContainer); - } +DKTools.Layout.prototype.resizeItems = function(width, height, blockStart) { + const callback = function(item) { + this.resizeItem(item, width, height, true); + }.bind(this); + this.iterateItems(callback, !blockStart); }; /** - * Adds the sprite of the contents to processing + * Activates the items * - * @private - * - * @see DKTools.Window.prototype.hasContentsSprite + * @param {Boolean} [start=false] - Call of the "start" function + * + * @see DKTools.Layout.prototype.iterateItems */ -DKTools.Window.prototype._addContentsSprite = function() { - if (this.hasContentsSprite()) { - this.addChild(this._windowContentsSprite); - } +DKTools.Layout.prototype.activateItems = function(start) { + const callback = function(item) { + item.activate(); + }; + this.iterateItems(callback, start); }; /** - * Adds the sprite of the pause sign to processing + * Deactivates the items * - * @private - * - * @see DKTools.Window.prototype.hasPauseSignSprite + * @param {Boolean} [start=false] - Call of the "start" function + * + * @see DKTools.Layout.prototype.iterateItems */ -DKTools.Window.prototype._addPauseSignSprite = function() { - if (this.hasPauseSignSprite()) { - this.addChild(this._windowPauseSignSprite); - } +DKTools.Layout.prototype.deactivateItems = function(start) { + const callback = function(item) { + item.deactivate(); + }; + this.iterateItems(callback, start); }; -// standard methods - /** - * Returns the standard openness of the window + * Shows the items * - * @returns {Number} Standard openness of the window + * @param {Boolean} [activate=false] - Activates the items + * @param {Boolean} [start=false] - Call of the "start" function + * + * @see DKTools.Layout.prototype.iterateItems */ -DKTools.Window.prototype.standardOpenness = function() { - return 255; +DKTools.Layout.prototype.showItems = function(activate, start) { + const callback = function(item) { + item.show(activate); + }; + this.iterateItems(callback, start); }; /** - * Returns the standard openness speed of the window + * Hides the items * - * @returns {Number} Standard openness speed of the window + * @param {Boolean} [blockDeactivate=false] - Block deactivation of the items + * @param {Boolean} [start=false] - Call of the "start" function + * + * @see DKTools.Layout.prototype.iterateItems */ -DKTools.Window.prototype.standardOpennessSpeed = function() { - return 16; +DKTools.Layout.prototype.hideItems = function(blockDeactivate, start) { + const callback = function(item) { + item.hide(blockDeactivate); + }; + this.iterateItems(callback, start); }; +// align methods + /** - * Returns the standard margin of the window + * Aligns the item * - * @returns {Number} Standard margin of the window + * @param {DKTools.Sprite | * | Number} item - Item or index + * + * @see DKTools.Layout.prototype.isReady + * @see DKTools.Layout.prototype.getItemRow + * @see DKTools.Layout.prototype.getItemCol + * @see DKTools.Layout.prototype.getRowHeight + * @see DKTools.Layout.prototype.getColWidth + * @see DKTools.Layout.prototype.getColX + * @see DKTools.Layout.prototype.getRowY + * @see DKTools.Layout.prototype.addOneTimeEvent */ -DKTools.Window.prototype.standardMargin = function() { - return 4; +DKTools.Layout.prototype.alignItem = function(item) { + if (this.isReady()) { + const itemRow = this.getItemRow(item); + const itemCol = this.getItemCol(item); + const rowHeight = this.getRowHeight(itemRow); + const colWidth = this.getColWidth(itemCol); + const x = this.getColX(itemCol) + (colWidth - item.width) / 2; + const y = this.getRowY(itemRow) + (rowHeight - item.height) / 2; + + item.move(x, y); + } else { + this.addOneTimeEvent({ + type: 'ready', + onSuccess: this.alignItem.bind(this, item) + }); + } }; /** - * Returns the standard origin of the window + * Aligns the row * - * @returns {Point} Standard origin of the window + * @param {Number} row - Row + * + * @see DKTools.Layout.prototype.getItemsInRow + * @see DKTools.Layout.prototype.alignItem */ -DKTools.Window.prototype.standardOrigin = function() { - return new Point(0, 0); +DKTools.Layout.prototype.alignRow = function(row) { + _.forEach(this.getItemsInRow(row), this.alignItem.bind(this)); }; /** - * Returns the standard normal state of the arrow + * Aligns the column * - * @returns {Function} Standard normal state of the arrow + * @param {Number} col - Column + * + * @see DKTools.Layout.prototype.getItemsInCol + * @see DKTools.Layout.prototype.alignItem */ -DKTools.Window.prototype.standardArrowStateNormal = function() { - return function(event) { - const arrow = event.target; - arrow.setScale(1, 1); - arrow.setOpacity(255); - }; +DKTools.Layout.prototype.alignCol = function(col) { + _.forEach(this.getItemsInCol(col), this.alignItem.bind(this)); }; /** - * Returns the standard pressed state of the arrow + * Aligns the items * - * @returns {Function} Standard pressed state of the arrow + * @see DKTools.Layout.prototype.addOneTimeEvent + * @see DKTools.Layout.prototype.iterateItems + * @see DKTools.Layout.prototype.alignItem */ -DKTools.Window.prototype.standardArrowStatePressed = function() { - return function(event) { - const arrow = event.target; - arrow.setScale(0.9, 0.9); - arrow.setOpacity(160); - }; +DKTools.Layout.prototype.alignItems = function() { + this.addOneTimeEvent({ + type: 'ready', + onSuccess: function() { + this.iterateItems(this.alignItem.bind(this)) + }.bind(this) + }); }; +// update methods + /** - * Returns the standard sprite of the contents + * Updates all * - * @returns {DKTools.Sprite} Standard sprite of the contents + * @override + * + * @see DKTools.Sprite.prototype.updateAll + * @see DKTools.Layout.prototype.updateLayout */ -DKTools.Window.prototype.standardContentsSprite = function() { - return new DKTools.Sprite(); +DKTools.Layout.prototype.updateAll = function() { + DKTools.Sprite.prototype.updateAll.call(this); + this.updateLayout(); }; /** - * Returns the standard X coordinate of the child + * Updates the layout * - * @returns {Number} Standard X coordinate of the child + * @see DKTools.Layout.prototype.getMaxItems + * @see DKTools.Layout.prototype.getMaxRows + * @see DKTools.Layout.prototype.getMaxCols + * @see DKTools.Layout.prototype.getColX + * @see DKTools.Layout.prototype.getRowY + * @see DKTools.Layout.prototype.moveItem */ -DKTools.Window.prototype.standardChildX = function() { - return this.standardPadding(); +DKTools.Layout.prototype.updateLayout = function() { + const maxItems = this.getMaxItems(); + const maxRows = this.getMaxRows(); + const maxCols = this.getMaxCols(); + let index = 0; + + for(let i = 1; i <= maxRows && index < maxItems; i++) { + for(let j = 1; j <= maxCols && index < maxItems; j++) { + const x = this.getColX(j); + const y = this.getRowY(i); + + this.moveItem(index++, x, y); + } + } }; -/** - * Returns the standard Y coordinate of the child - * - * @returns {Number} Standard Y coordinate of the child - */ -DKTools.Window.prototype.standardChildY = function() { - return this.standardPadding(); -}; -/** - * Returns the standard position of the child - * - * @returns {Point} Standard position of the child - */ -DKTools.Window.prototype.standardChildPosition = function() { - return new Point(this.standardChildX(), this.standardChildY()); -}; -/** - * Returns the standard position of the contents - * - * @returns {Point} Standard position of the contents - */ -DKTools.Window.prototype.standardContentsPosition = function() { - return this.standardChildPosition(); -}; -/** - * Returns the standard visibility of the background - * - * @returns {Boolean} Standard visibility of the background - */ -DKTools.Window.prototype.standardBackVisible = function() { - return true; -}; -/** - * Returns the standard visibility of the frame - * - * @returns {Boolean} Standard visibility of the frame - */ -DKTools.Window.prototype.standardFrameVisible = function() { - return true; -}; +//=========================================================================== +// DKTools.Window +//=========================================================================== + +DKTools.Window.prototype = Object.create(Window_Base.prototype); +DKTools.Utils.mixin(DKTools.Window.prototype, DKTools.Base.prototype); +DKTools.Window.prototype.constructor = DKTools.Window; + +// properties + +Object.defineProperties(DKTools.Window.prototype, { + + /** + * Real width of the window (not including scaling) + * + * @readonly + * @type {Number} + * @memberof DKTools.Window.prototype + */ + realWidth: { + get: function() { + return this._width; + }, + set: function(value) { + this._width = value; + this._refreshAllParts(); + }, + configurable: true + }, + + /** + * Real height of the window (not including scaling) + * + * @readonly + * @type {Number} + * @memberof DKTools.Window.prototype + */ + realHeight: { + get: function() { + return this._height; + }, + set: function(value) { + this._height = value; + this._refreshAllParts(); + }, + configurable: true + }, + + /** + * Width of the window (taking into account scaling) + * + * @type {Number} + * @memberof DKTools.Window.prototype + */ + width: { + get: function() { + return this.realWidth * this.scale.x; + }, + set: function(value) { + this._width = Math.floor(value / this.scale.x); + this._refreshAllParts(); + }, + configurable: true + }, + + /** + * Height of the window (taking into account scaling) + * + * @type {Number} + * @memberof DKTools.Window.prototype + */ + height: { + get: function() { + return this.realHeight * this.scale.y; + }, + set: function(value) { + this._height = Math.floor(value / this.scale.y); + this._refreshAllParts(); + }, + configurable: true + }, + + /** + * Origin + * + * @readonly + * @type {Point} + * @memberof DKTools.Window.prototype + */ + origin: { + get: function() { + return this._origin; + }, + configurable: true + }, + + /** + * Opacity of the window + * + * @type {Number} + * @memberof DKTools.Window.prototype + */ + windowOpacity: { + get: function() { + return this._windowSpriteContainer.alpha * 255; + }, + set: function(value) { + this._windowSpriteContainer.alpha = _.clamp(value, 0, 255) / 255; + }, + configurable: true + }, + + /** + * Opacity of the frame + * + * @type {Number} + * @memberof DKTools.Window.prototype + */ + frameOpacity: { + get: function() { + return this._windowFrameSprite.alpha * 255; + }, + set: function(value) { + this._windowFrameSprite.alpha = _.clamp(value, 0, 255) / 255; + }, + configurable: true + }, + + /** + * Opacity of the window + * + * @readonly + * @type {Object} + * @memberof DKTools.Window.prototype + */ + opacity: { + get: function() { + return this._opacity; + }, + configurable: true + }, + + /** + * Tone of the window + * + * @readonly + * @type {Number[]} + * @memberof DKTools.Window.prototype + */ + tone: { + get: function() { + return this._tone; + }, + configurable: true + }, + + /** + * Sprite of the contents + * + * @readonly + * @type {DKTools.Sprite} + * @memberof DKTools.Window.prototype + */ + contentsSprite: { + get: function() { + return this._windowContentsSprite; + }, + configurable: true + }, + + /** + * Sprite of the frame + * + * @readonly + * @type {Sprite} + * @memberof DKTools.Window.prototype + */ + frameSprite: { + get: function() { + return this._windowFrameSprite; + }, + configurable: true + }, + + /** + * Sprite of the background + * + * @readonly + * @type {Sprite} + * @memberof DKTools.Window.prototype + */ + backSprite: { + get: function() { + return this._windowBackSprite; + }, + configurable: true + }, + + /** + * Bitmap of sprite of the contents + * To support functions from DKTools.Base + * + * @type {Bitmap} + * @memberof DKTools.Window.prototype + */ + bitmap: { + get: function() { + return this.contents; + }, + set: function(value) { + this.contents = value; + }, + configurable: true + } + +}); + +// initialize methods /** - * Returns the standard width of the contents + * Initializes a class object * - * @returns {Function} Standard width of the contents - */ -DKTools.Window.prototype.standardContentsWidth = function() { - return function() { - return this._width - this.standardPadding() * 2; - }.bind(this); -}; - -/** - * Returns the standard height of the contents + * @override * - * @returns {Function} Standard height of the contents - */ -DKTools.Window.prototype.standardContentsHeight = function() { - return function() { - return this._height - this.standardPadding() * 2; - }.bind(this); -}; - -/** - * Returns the standard opacity of the window + * @param {Number | Object} [object] - The X coordinate + * @param {Number} [y] - The Y coordinate + * @param {Number} [width] - Width of the window + * @param {Number} [height] - Height of the window * - * @returns {Number} Standard opacity of the window + * @see PIXI.Container + * @see DKTools.Base.prototype.initialize */ -DKTools.Window.prototype.standardWindowOpacity = function() { - return 255; +DKTools.Window.prototype.initialize = function(object, y, width, height) { + PIXI.Container.call(this); + DKTools.Base.prototype.initialize.call(this, object, y, width, height); }; +// _clear methods + /** - * Returns the standard opacity of the contents + * Clears all data * - * @returns {Number} Standard opacity of the contents + * @private + * @override + * + * @see DKTools.Base.prototype._clearAll + * @see DKTools.Window.prototype._clearIsWindow + * @see DKTools.Window.prototype._clearOpenness + * @see DKTools.Window.prototype._clearPadding + * @see DKTools.Window.prototype._clearMargin + * @see DKTools.Window.prototype._clearColorTone + * @see DKTools.Window.prototype._clearOrigin + * @see DKTools.Window.prototype._clearArrows */ -DKTools.Window.prototype.standardContentsOpacity = function() { - return 255; +DKTools.Window.prototype._clearAll = function() { + DKTools.Base.prototype._clearAll.call(this); + this._clearIsWindow(); + this._clearOpenness(); + this._clearPadding(); + this._clearMargin(); + this._clearColorTone(); + this._clearOrigin(); + this._clearArrows(); }; /** - * Returns the standard opacity of the frame + * Clears the "isWindow" * - * @returns {Number} Standard opacity of the frame + * @private */ -DKTools.Window.prototype.standardFrameOpacity = function() { - return 255; +DKTools.Window.prototype._clearIsWindow = function() { + /** + * @private + * @readonly + * @type {Boolean} + */ + this._isWindow = true; }; /** - * Returns the standard opacity - * - * @see DKTools.Window.prototype.standardWindowOpacity - * @see DKTools.Window.prototype.standardContentsOpacity - * @see DKTools.Window.prototype.standardFrameOpacity - * @see DKTools.Window.prototype.standardBackOpacity + * Clears the openness * - * @returns {Object} Standard opacity + * @private + * + * @see DKTools.Window.prototype.standardOpenness */ -DKTools.Window.prototype.standardOpacity = function() { - return { - windowOpacity: this.standardWindowOpacity(), - contentsOpacity: this.standardContentsOpacity(), - frameOpacity: this.standardFrameOpacity(), - backOpacity: this.standardBackOpacity() - }; +DKTools.Window.prototype._clearOpenness = function() { + /** + * @private + * @readonly + * @type {Number} + */ + this._openness = this.standardOpenness(); }; /** - * Returns the standard tone of the window + * Clears the padding * - * @returns {Number[]} Standard tone of the window + * @private + * + * @see DKTools.Window.prototype.standardPadding */ -DKTools.Window.prototype.standardTone = function() { - try { - return $gameSystem.windowTone(); - } catch(e) { - } - - return [0, 0, 0]; +DKTools.Window.prototype._clearPadding = function() { + /** + * @private + * @readonly + * @type {Number} + */ + this._padding = this.standardPadding(); }; -// setup methods - /** - * Sets all parameters - * - * @override - * - * @param {Object} [object={}] - Parameters - * - * @param {Function | Number} [object.contentsWidth] - Width of thw window - * @param {Function | Number} [object.contentsHeight] - Height of thw window - * @param {Object} [object.opacity] - Opacity of the window - * @param {Number[]} [object.tone] - Tone of the window - * - * @param {Number} [opacity.windowOpacity] - Opacity of the window - * @param {Number} [opacity.contentsOpacity] - Opacity of the contents - * @param {Number} [opacity.frameOpacity] - Opacity of the frame - * @param {Number} [opacity.backOpacity] - Opacity of the background + * Clears the margin * - * @see DKTools.Base.prototype.setupAll - * @see DKTools.Window.prototype.setupContentsWidth - * @see DKTools.Window.prototype.setupContentsHeight - * @see DKTools.Window.prototype.setupContentsSprite - * @see DKTools.Window.prototype.setupContentsPosition - * @see DKTools.Window.prototype.setupOpacity - * @see DKTools.Window.prototype.setupTone + * @private + * + * @see DKTools.Window.prototype.standardMargin */ -DKTools.Window.prototype.setupAll = function(object) { - object = object || {}; - DKTools.Base.prototype.setupAll.call(this, object); - let contentsSprite = object.contentsSprite; - - if (object instanceof DKTools.Window && contentsSprite instanceof DKTools.Sprite) { - contentsSprite = contentsSprite.clone({ blockStart: true }); - } - - this.setupContentsWidth(object.contentsWidth); - this.setupContentsHeight(object.contentsHeight); - this.setupContentsSprite(contentsSprite); - this.setupContentsPosition(object.contentsPosition); - this.setupOpacity(object.opacity); - this.setupTone(object.tone); +DKTools.Window.prototype._clearMargin = function() { + /** + * @private + * @readonly + * @type {Number} + */ + this._margin = this.standardMargin(); }; /** - * Sets the width of the window + * Clears the color tone * - * @param {Number} [width] - Width of the window + * @private * - * @see DKTools.Window.prototype._checkWidth + * @see DKTools.Window.prototype.standardTone */ -DKTools.Window.prototype.setupWidth = function(width) { - this.realWidth = this._checkWidth(width); +DKTools.Window.prototype._clearColorTone = function() { + /** + * @private + * @readonly + * @type {Number[]} + */ + this._colorTone = this.standardTone(); }; /** - * Sets the height of the window + * Clears the origin * - * @param {Number | String} [height] - Height of the window of number of lines (String) + * @private * - * @see DKTools.Window.prototype._checkHeight + * @see DKTools.Window.prototype.standardOrigin */ -DKTools.Window.prototype.setupHeight = function(height) { - if (DKTools.Utils.isString(height)) { - height = this.getLineHeight() * Number(height); - } - - this.realHeight = this._checkHeight(height); +DKTools.Window.prototype._clearOrigin = function() { + /** + * @private + * @readonly + * @type {Point} + */ + this._origin = this.standardOrigin(); }; /** - * Sets the size of the window - * - * @param {Number | Object} [object] - Width of the window or object with parameters - * @param {Number | String} [height] - Height of the window or number of lines (String) (if object is Number) - * - * @param {Number} [object.width] - Width of the window - * @param {Number | String} [object.height] - Height of the window or number of lines (String) + * Clears the arrows * - * @see DKTools.Window.prototype.getLineHeight - * @see DKTools.Window.prototype._checkWidth - * @see DKTools.Window.prototype._checkHeight - * @see Window.prototype.move + * @private */ -DKTools.Window.prototype.setupSize = function(object, height) { - if (object instanceof Object) { - return this.setupSize(object.width, object.height); - } - - if (DKTools.Utils.isString(height)) { - height = this.getLineHeight() * Number(height); - } - - // object - Number - object = this._checkWidth(object); - height = this._checkHeight(height); - - Window.prototype.move.call(this, this.x, this.y, object, height); +DKTools.Window.prototype._clearArrows = function() { + /** + * @private + * @readonly + * @type {DKTools.Sprite.Arrow[]} + */ + this._arrows = []; }; +// _create methods + /** - * Sets the width of the contents + * Creates all * - * @param {Function | Number} [contentsWidth=this.standardContentsWidth()] - Width of the contents + * @private + * @override * - * @see DKTools.Window.prototype.standardContentsWidth + * @see DKTools.Base.prototype._createAll + * @see DKTools.Window.prototype._createAllParts + * @see DKTools.Window.prototype._createWindowskin */ -DKTools.Window.prototype.setupContentsWidth = function(contentsWidth) { - this._contentsWidth = contentsWidth || this.standardContentsWidth(); +DKTools.Window.prototype._createAll = function() { + DKTools.Base.prototype._createAll.call(this); + this._createAllParts(); + this._createWindowskin(); }; /** - * Sets the height of the contents + * Creates all parts of the window * - * @param {Function | Number} [contentsHeight=this.standardContentsHeight()] - Height of the contents + * @version 3.1.0 + * @private + * @override * - * @see DKTools.Window.prototype.standardContentsHeight + * @see DKTools.Window.prototype._createSpriteContainer + * @see DKTools.Window.prototype._createBackSprite + * @see DKTools.Window.prototype._createFrameSprite + * @see DKTools.Window.prototype._createPauseSignSprite */ -DKTools.Window.prototype.setupContentsHeight = function(contentsHeight) { - this._contentsHeight = contentsHeight || this.standardContentsHeight(); +DKTools.Window.prototype._createAllParts = function() { + this._createSpriteContainer(); + this._createBackSprite(); + this._createFrameSprite(); + this._createPauseSignSprite(); + this._createArrows(); }; /** - * Sets the sprite of the contents - * - * @param {DKTools.Sprite | *} [contentsSprite=this.standardContentsSprite()] - Sprite of the contents + * Creates the container of the sprites * - * @see DKTools.Window.prototype.standardContentsSprite + * @private + * + * @see PIXI.Container */ -DKTools.Window.prototype.setupContentsSprite = function(contentsSprite) { +DKTools.Window.prototype._createSpriteContainer = function() { /** * @private * @readonly - * @type {DKTools.Sprite | *} + * @type {PIXI.Container} */ - this._windowContentsSprite = contentsSprite || this.standardContentsSprite(); + this._windowSpriteContainer = new PIXI.Container(); }; /** - * Sets the position of the contents - * - * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object=this.standardContentsPosition()] - The X coordinate or Point or object with parameters - * @param {Number} [y=undefined] - The Y coordinate (if object is Number) - * - * @param {Number} [object.x] - The X coordinate - * @param {Number} [object.y] - The Y coordinate + * Creates the sprite of the background * - * @see DKTools.Utils.Point.toPoint - * @see DKTools.Utils.Point.standardContentsPosition + * @private + * + * @see DKTools.Window.prototype.needsCreateBackSprite + * @see DKTools.Window.prototype.standardBackOpacity + * @see DKTools.Window.prototype.standardBackVisible */ -DKTools.Window.prototype.setupContentsPosition = function(object, y) { - const position = DKTools.Utils.Point.toPoint(object, y); - const newPosition = Object.assign(this.standardContentsPosition(), position); +DKTools.Window.prototype._createBackSprite = function() { + if (this.needsCreateBackSprite()) { + /** + * @private + * @readonly + * @type {Sprite} + */ + this._windowBackSprite = new Sprite(); + this._windowBackSprite.opacity = this.standardBackOpacity(); + this._windowBackSprite.visible = this.standardBackVisible(); + } +}; - /** - * @private - * @readonly - * @type {Point} - */ - this._contentsPosition = new Point(newPosition.x, newPosition.y); +/** + * Creates the sprtie of the frame + * + * @private + * + * @see DKTools.Window.prototype.needsCreateFrameSprite + * @see DKTools.Window.prototype.standardFrameVisible + */ +DKTools.Window.prototype._createFrameSprite = function() { + if (this.needsCreateFrameSprite()) { + /** + * @private + * @readonly + * @type {Sprite} + */ + this._windowFrameSprite = new Sprite(); + this._windowFrameSprite.visible = this.standardFrameVisible(); + } }; /** - * Sets the opacity of the window + * Creates the sprite of the pause sign * - * @param {Object} [opacity=this.standardOpacity()] - Opacity of the window + * @private + * + * @see DKTools.Window.prototype.needsCreatePauseSignSprite + */ +DKTools.Window.prototype._createPauseSignSprite = function() { + if (this.needsCreatePauseSignSprite()) { + /** + * @private + * @readonly + * @type {Sprite} + */ + this._windowPauseSignSprite = new Sprite(); + } +}; + +/** + * Creates the arrows * - * @param {Number} [opacity.windowOpacity] - Opacity of the window - * @param {Number} [opacity.contentsOpacity] - Opacity of the contents - * @param {Number} [opacity.frameOpacity] - Opacity of the frame - * @param {Number} [opacity.backOpacity] - Opacity of the background + * @since 3.1.0 + * @static * - * @see DKTools.Window.prototype.standardOpacity + * @see DKTools.Window.prototype.needsCreateDownArrowSprite + * @see DKTools.Window.prototype.needsCreateUpArrowSprite + * @see DKTools.Window.prototype.needsCreateRightArrowSprite + * @see DKTools.Window.prototype.needsCreateLeftArrowSprite + * @see DKTools.Window.prototype.createArrow + * @see DKTools.Window.prototype.onDownArrowUpdate + * @see DKTools.Window.prototype.onDownArrowMouseClick + * @see DKTools.Window.prototype.onDownArrowMouseLongPress + * @see DKTools.Window.prototype.onUpArrowUpdate + * @see DKTools.Window.prototype.onUpArrowMouseClick + * @see DKTools.Window.prototype.onUpArrowMouseLongPress + * @see DKTools.Window.prototype.onRightArrowUpdate + * @see DKTools.Window.prototype.onRightArrowMouseClick + * @see DKTools.Window.prototype.onRightArrowMouseLongPress + * @see DKTools.Window.prototype.onLeftArrowUpdate + * @see DKTools.Window.prototype.onLeftArrowMouseClick + * @see DKTools.Window.prototype.onLeftArrowMouseLongPress + * @see DKTools.Window.prototype.standardArrowStateNormal + * @see DKTools.Window.prototype.standardArrowStatePressed */ -DKTools.Window.prototype.setupOpacity = function(opacity) { - /** - * @private - * @type {Object} - */ - this._opacity = Object.assign(this.standardOpacity(), opacity); +DKTools.Window.prototype._createArrows = function() { + if (this.needsCreateUpArrowSprite()) { + this.createArrow('up', 'up', { + onUpdate: this.onUpArrowUpdate.bind(this), + onMouseClick: this.onUpArrowMouseClick.bind(this), + onMouseLongPress: this.onUpArrowMouseLongPress.bind(this), + onStateNormal: this.standardArrowStateNormal(), + onStatePressed: this.standardArrowStatePressed() + }); + } + + if (this.needsCreateDownArrowSprite()) { + this.createArrow('down', 'down', { + onUpdate: this.onDownArrowUpdate.bind(this), + onMouseClick: this.onDownArrowMouseClick.bind(this), + onMouseLongPress: this.onDownArrowMouseLongPress.bind(this), + onStateNormal: this.standardArrowStateNormal(), + onStatePressed: this.standardArrowStatePressed() + }); + } + + if (this.needsCreateLeftArrowSprite()) { + this.createArrow('left', 'left', { + onUpdate: this.onLeftArrowUpdate.bind(this), + onMouseClick: this.onLeftArrowMouseClick.bind(this), + onMouseLongPress: this.onLeftArrowMouseLongPress.bind(this), + onStateNormal: this.standardArrowStateNormal(), + onStatePressed: this.standardArrowStatePressed() + }); + } + + if (this.needsCreateRightArrowSprite()) { + this.createArrow('right', 'right', { + onUpdate: this.onRightArrowUpdate.bind(this), + onMouseClick: this.onRightArrowMouseClick.bind(this), + onMouseLongPress: this.onRightArrowMouseLongPress.bind(this), + onStateNormal: this.standardArrowStateNormal(), + onStatePressed: this.standardArrowStatePressed() + }); + } }; /** - * Sets the tone of the window + * Creates the window skin * - * @param {Number[]} [tone=this.standardTone()] - Tone of the window + * @private * - * @see DKTools.Window.prototype.standardTone + * @see DKTools.Window.prototype.loadWindowskin */ -DKTools.Window.prototype.setupTone = function(tone) { - const standardTone = _.clone(this.standardTone()); - - /** - * @private - * @type {Number[]} - */ - this._tone = Object.assign(standardTone, tone); +DKTools.Window.prototype._createWindowskin = function() { + this.windowskin = this.loadWindowskin(); }; -// set methods +// _add methods /** - * Changes all parameters - * Returns the number of changed parameters + * Adds children objects to processing * + * @private * @override * - * @param {Object} [object] - Parameters - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the window - * - * @param {Object} [object.opacity] - Opacity of the window - * @param {Number[]} [object.tone] - Tone of the window - * - * @param {Number} [object.opacity.windowOpacity] - Opacity of the window - * @param {Number} [object.opacity.contentsOpacity] - Opacity of the contents - * @param {Number} [object.opacity.frameOpacity] - Opacity of the frame - * @param {Number} [object.opacity.backOpacity] - Opacity of the background + * @see DKTools.Base.prototype._addAllChildren + * @see DKTools.Window.prototype._addAllParts + */ +DKTools.Window.prototype._addAllChildren = function() { + DKTools.Base.prototype._addAllChildren.call(this); + this._addAllParts(); +}; + +/** + * Adds all parts of the window to processing * - * @see DKTools.Base.prototype.setAll - * @see DKTools.Window.prototype.setOpacity - * @see DKTools.Window.prototype.setTone - * @see DKTools.Window.prototype.start - * @see DKTools.Window.prototype.activate + * @version 3.1.0 + * @private * - * @returns {Number} Number of changed parameters + * @see DKTools.Window.prototype._addSpriteContainer + * @see DKTools.Window.prototype._addPauseSignSprite */ -DKTools.Window.prototype.setAll = function(object, blockStart, activate) { - object = object || {}; - const block = true; - let changed = DKTools.Base.prototype.setAll.call(this, object, block); - - if (this.setOpacity(object.opacity, block)) { - changed++; - } - - if (this.setTone(object.tone, block)) { - changed++; - } +DKTools.Window.prototype._addAllParts = function() { + this._addSpriteContainer(); + this._addPauseSignSprite(); + this._addArrows(); +}; - if (changed) { - if (!blockStart) { - this.start(); +/** + * Adds the container of the sprites to processing + * + * @private + * + * @see DKTools.Window.prototype.hasSpriteContainer + * @see DKTools.Window.prototype.hasBackSprite + * @see DKTools.Window.prototype.hasFrameSprite + */ +DKTools.Window.prototype._addSpriteContainer = function() { + if (this.hasSpriteContainer()) { + if (this.hasBackSprite()) { + this._windowSpriteContainer.addChild(this._windowBackSprite); } - if (activate) { - this.activate(); + if (this.hasFrameSprite()) { + this._windowSpriteContainer.addChild(this._windowFrameSprite); } - } - return changed; + this.addChild(this._windowSpriteContainer); + } }; /** - * Changes the width of the window - * Returns true if the change occurred - * - * @param {Number} [width] - Width of the window - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the window - * - * @see DKTools.Window.prototype.resize + * Adds the sprite of the contents to processing * - * @returns {Boolean} Change occurred + * @private + * + * @see DKTools.Window.prototype.hasContentsSprite */ -DKTools.Window.prototype.setWidth = function(width, blockStart, activate) { - return this.resize(width, this._height, blockStart, activate); +DKTools.Window.prototype._addContentsSprite = function() { + if (this.hasContentsSprite()) { + this.addChild(this._windowContentsSprite); + } }; /** - * Changes the height of the window - * Returns true if the change occurred - * - * @param {Number} [height] - Height of the window - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the window - * - * @see DKTools.Window.prototype.resize + * Adds the sprite of the pause sign to processing * - * @returns {Boolean} Change occurred + * @private + * + * @see DKTools.Window.prototype.hasPauseSignSprite */ -DKTools.Window.prototype.setHeight = function(height, blockStart, activate) { - return this.resize(this._width, height, blockStart, activate); +DKTools.Window.prototype._addPauseSignSprite = function() { + if (this.hasPauseSignSprite()) { + this.addChild(this._windowPauseSignSprite); + } }; /** - * Changes the sprite of the contents - * Returns true if the change occurred - * - * @param {DKTools.Sprite | *} [contentsSprite] - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the window - * - * @see DKTools.Window.prototype.removeContentsSprite - * @see DKTools.Window.prototype.setupContentsSprite - * @see DKTools.Window.prototype.addContentsSprite - * @see DKTools.Window.prototype.activate + * Adds the arrows to processing * - * @returns {Boolean} Change occurred + * @since 3.1.0 + * @private */ -DKTools.Window.prototype.setContentsSprite = function(contentsSprite, blockStart, activate) { - if (this._windowContentsSprite == contentsSprite) { - return false; - } - - // TODO: проверить - this.removeContentsSprite(); - this.setupContentsSprite(contentsSprite); - this.addContentsSprite(); +DKTools.Window.prototype._addArrows = function() { + _.forEach(['up', 'down', 'left', 'right'], function(arrowType) { + const arrow = this.getArrow(arrowType); - if (!blockStart) { - this.start(); - } + if (arrow) { + this.addChild(arrow); + } + }.bind(this)); +}; - if (activate) { - this.activate(); - } +// standard methods - return true; +/** + * Returns the standard openness of the window + * + * @returns {Number} Standard openness of the window + */ +DKTools.Window.prototype.standardOpenness = function() { + return 255; }; /** - * Changes the position of the contents - * Returns true if the change occurred - * - * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - The X coordinate or Point or object with parameters - * @param {Number} [y=undefined] - The Y coordinate (if object is Number) - * - * @param {Number} [object.x] - The X coordinate - * @param {Number} [object.y] - The Y coordinate - * - * @see DKTools.Utils.Point.toPoint - * @see DKTools.Utils.Point.equals - * @see DKTools.Utils.Point.clone - * @see DKTools.Window.prototype.setupContentsPosition - * @see DKTools.Window.prototype._refreshContents + * Returns the standard openness speed of the window * - * @returns {Boolean} Change occurred + * @returns {Number} Standard openness speed of the window */ -DKTools.Window.prototype.setContentsPosition = function(object, y) { - if (object instanceof Object) { - return this.setContentsPosition(object, y); - } - - // object - Number - const newPos = DKTools.Utils.Point.toPoint(object, y); - - if (DKTools.Utils.Point.equals(this._contentsPosition, newPos)) { - return false; - } - - const lastPos = DKTools.Utils.Point.clone(this._contentsPosition); - this.setupContentsPosition(newPos); - - if (!DKTools.Utils.Point.equals(this._contentsPosition, lastPos)) { - this._refreshContents(); - return true; - } - - return false; +DKTools.Window.prototype.standardOpennessSpeed = function() { + return 16; }; /** - * Changes the opacity of the window - * Returns true if the change occurred - * - * @param {Object} [opacity] - Opacity of the window - * {Boolean} [blockUpdateOpacity=false] - Blocking the call of the "updateOpacity" function - * - * @param {Number} [opacity.windowOpacity] - Opacity of the window - * @param {Number} [opacity.contentsOpacity] - Opacity of the contents - * @param {Number} [opacity.frameOpacity] - Opacity of the frame - * @param {Number} [opacity.backOpacity] - Opacity of the background - * - * @see DKTools.Window.prototype.setupOpacity - * @see DKTools.Window.prototype.updateOpacity + * Returns the standard margin of the window * - * @returns {Boolean} Change occurred + * @returns {Number} Standard margin of the window */ -DKTools.Window.prototype.setOpacity = function(opacity, blockUpdateOpacity) { - if (_.isEqual(this._opacity, Object.assign(this.standardOpacity(), opacity))) { - return false; - } +DKTools.Window.prototype.standardMargin = function() { + return 4; +}; - this.setupOpacity(opacity); +/** + * Returns the standard origin of the window + * + * @returns {Point} Standard origin of the window + */ +DKTools.Window.prototype.standardOrigin = function() { + return new Point(0, 0); +}; - if (!blockUpdateOpacity) { - this.updateOpacity(); - } +/** + * Returns the standard position of the arrow of up + * + * @since 3.1.0 + * @returns {Point} Standard position of the arrow of up + */ +DKTools.Window.prototype.standardUpArrowPosition = function() { + return new Point(this._width / 2, 12); +}; - return true; +/** + * Returns the standard position of the arrow of down + * + * @since 3.1.0 + * @returns {Point} Standard position of the arrow of down + */ +DKTools.Window.prototype.standardDownArrowPosition = function() { + return new Point(this._width / 2, this._height - 12); }; /** - * Changes the tone of the window - * Returns true if the change occurred - * - * @override - * - * @param {Number[]} [tone] - Tone of the window - * @param {Boolean} [blockUpdateTone=false] - Blocking the call of the "updateTone" function + * Returns the standard position of the arrow of left * - * @see DKTools.Window.prototype.setupTone - * @see DKTools.Window.prototype.updateTone - * - * @returns {Boolean} Change occurred + * @since 3.1.0 + * @returns {Point} Standard position of the arrow of left */ -DKTools.Window.prototype.setTone = function(tone, blockUpdateTone) { - const standardTone = _.clone(this.standardTone()); - - if (_.isEqual(this._tone, Object.assign(standardTone, tone))) { - return false; - } - - this.setupTone(tone); - - if (!blockUpdateTone) { - this.updateTone(); - } - - return true; +DKTools.Window.prototype.standardLeftArrowPosition = function() { + return new Point(12, this._height / 2); }; -// get methods - /** - * Returns the minimum width of the window - * - * @override - * - * @see DKTools.Window.prototype.standardPadding - * @see DKTools.Base.prototype.getMinWidth + * Returns the standard position of the arrow of right * - * @returns {Number} Minimum width of the window + * @since 3.1.0 + * @returns {Point} Standard position of the arrow of right */ -DKTools.Window.prototype.getMinWidth = function() { - return this.standardPadding() * 2 + DKTools.Base.prototype.getMinWidth.call(this); +DKTools.Window.prototype.standardRightArrowPosition = function() { + return new Point(this._width - 12, this._height / 2); }; /** - * Returns the minimum height of the window + * Returns the standard normal state of the arrow * - * @override + * @returns {Function} Standard normal state of the arrow + */ +DKTools.Window.prototype.standardArrowStateNormal = function() { + return function(event) { + const arrow = event.target; + arrow.setScale(1, 1); + arrow.setOpacity(255); + }; +}; + +/** + * Returns the standard pressed state of the arrow * - * @see DKTools.Window.prototype.standardPadding - * @see DKTools.Base.prototype.getMinHeight + * @returns {Function} Standard pressed state of the arrow + */ +DKTools.Window.prototype.standardArrowStatePressed = function() { + return function(event) { + const arrow = event.target; + arrow.setScale(0.9, 0.9); + arrow.setOpacity(160); + }; +}; + +/** + * Returns the standard sprite of the contents * - * @returns {Number} Minimum height of the window + * @returns {DKTools.Sprite} Standard sprite of the contents */ -DKTools.Window.prototype.getMinHeight = function() { - return this.standardPadding() * 2 + DKTools.Base.prototype.getMinHeight.call(this); +DKTools.Window.prototype.standardContentsSprite = function() { + return new DKTools.Sprite(); }; /** - * Returns the width of the contents + * Returns the standard X coordinate of the child * - * @returns {Number} Width of the contents + * @returns {Number} Standard X coordinate of the child */ -DKTools.Window.prototype.getContentsWidth = function() { - if (DKTools.Utils.isFunction(this._contentsWidth)) { - return this._contentsWidth(); - } +DKTools.Window.prototype.standardChildX = function() { + return this.standardPadding(); +}; - return this._contentsWidth; +/** + * Returns the standard Y coordinate of the child + * + * @returns {Number} Standard Y coordinate of the child + */ +DKTools.Window.prototype.standardChildY = function() { + return this.standardPadding(); }; /** - * Returns the height of the contents + * Returns the standard position of the child * - * @returns {Number} Height of the contents + * @returns {Point} Standard position of the child */ -DKTools.Window.prototype.getContentsHeight = function() { - if (DKTools.Utils.isFunction(this._contentsHeight)) { - return this._contentsHeight(); - } +DKTools.Window.prototype.standardChildPosition = function() { + return new Point(this.standardChildX(), this.standardChildY()); +}; - return this._contentsHeight; +/** + * Returns the standard position of the contents + * + * @returns {Point} Standard position of the contents + */ +DKTools.Window.prototype.standardContentsPosition = function() { + return this.standardChildPosition(); }; /** - * Returns the size of the contents + * Returns the standard visibility of the background * - * @see DKTools.Window.prototype.getContentsWidth - * @see DKTools.Window.prototype.getContentsHeight + * @returns {Boolean} Standard visibility of the background + */ +DKTools.Window.prototype.standardBackVisible = function() { + return true; +}; + +/** + * Returns the standard visibility of the frame * - * @returns {Object} Size of the contents + * @returns {Boolean} Standard visibility of the frame */ -DKTools.Window.prototype.getContentsSize = function() { - return { width: this.getContentsWidth(), height: this.getContentsHeight() }; +DKTools.Window.prototype.standardFrameVisible = function() { + return true; }; /** - * Returns the arrow by ID + * Returns the standard width of the contents * - * @param {Number | String} id - ID of the arrow - * @returns {DKTools.Sprite.Arrow | undefined} Sprite of the arrow or undefined + * @returns {Function} Standard width of the contents */ -DKTools.Window.prototype.getArrow = function(id) { - return _.find(this._arrows, { id }); +DKTools.Window.prototype.standardContentsWidth = function() { + return function() { + return this._width - this.standardPadding() * 2; + }.bind(this); }; /** - * Returns the current opacity of the window + * Returns the standard height of the contents * - * @returns {Number} Current opacity of the window + * @returns {Function} Standard height of the contents */ -DKTools.Window.prototype.getCurrentOpacity = function() { - return this.windowOpacity; +DKTools.Window.prototype.standardContentsHeight = function() { + return function() { + return this._height - this.standardPadding() * 2; + }.bind(this); }; -// needs create methods +/** + * Returns the standard opacity of the window + * + * @returns {Number} Standard opacity of the window + */ +DKTools.Window.prototype.standardWindowOpacity = function() { + return 255; +}; /** - * Returns true if needs to create the sprite of the background + * Returns the standard opacity of the contents * - * @returns {Boolean} Needs to create the sprite of the background + * @returns {Number} Standard opacity of the contents */ -DKTools.Window.prototype.needsCreateBackSprite = function() { - return true; +DKTools.Window.prototype.standardContentsOpacity = function() { + return 255; }; /** - * Returns true if needs to create the sprite of the frame + * Returns the standard opacity of the frame * - * @returns {Boolean} Needs to create the sprite of the frame + * @returns {Number} Standard opacity of the frame */ -DKTools.Window.prototype.needsCreateFrameSprite = function() { - return true; +DKTools.Window.prototype.standardFrameOpacity = function() { + return 255; }; /** - * Returns true if needs to create the sprites of the arrows + * Returns the standard opacity * - * @returns {Boolean} Needs to create the sprites of the arrows + * @see DKTools.Window.prototype.standardWindowOpacity + * @see DKTools.Window.prototype.standardContentsOpacity + * @see DKTools.Window.prototype.standardFrameOpacity + * @see DKTools.Window.prototype.standardBackOpacity + * + * @returns {Object} Standard opacity */ -DKTools.Window.prototype.needsCreateArrowsSprites = function() { - return false; +DKTools.Window.prototype.standardOpacity = function() { + return { + windowOpacity: this.standardWindowOpacity(), + contentsOpacity: this.standardContentsOpacity(), + frameOpacity: this.standardFrameOpacity(), + backOpacity: this.standardBackOpacity() + }; }; /** - * Returns true if needs to create the sprite of the down arrow + * Returns the standard tone of the window * - * @returns {Boolean} Needs to create the sprite of the down arrow + * @returns {Number[]} Standard tone of the window */ -DKTools.Window.prototype.needsCreateDownArrowSprite = function() { - return true; +DKTools.Window.prototype.standardTone = function() { + try { + return $gameSystem.windowTone(); + } catch(e) { + } + + return [0, 0, 0]; }; +// setup methods + /** - * Returns true if needs to create the sprite of the up arrow + * Sets all parameters * - * @returns {Boolean} Needs to create the sprite of the up arrow + * @override + * + * @param {Object} [object={}] - Parameters + * + * @param {Function | Number} [object.contentsWidth] - Width of thw window + * @param {Function | Number} [object.contentsHeight] - Height of thw window + * @param {Object} [object.opacity] - Opacity of the window + * @param {Number[]} [object.tone] - Tone of the window + * + * @param {Number} [object.opacity.windowOpacity] - Opacity of the window + * @param {Number} [object.opacity.contentsOpacity] - Opacity of the contents + * @param {Number} [object.opacity.frameOpacity] - Opacity of the frame + * @param {Number} [object.opacity.backOpacity] - Opacity of the background + * + * @see DKTools.Base.prototype.setupAll + * @see DKTools.Window.prototype.setupContentsWidth + * @see DKTools.Window.prototype.setupContentsHeight + * @see DKTools.Window.prototype.setupContentsSprite + * @see DKTools.Window.prototype.setupContentsPosition + * @see DKTools.Window.prototype.setupOpacity + * @see DKTools.Window.prototype.setupTone */ -DKTools.Window.prototype.needsCreateUpArrowSprite = function() { - return true; +DKTools.Window.prototype.setupAll = function(object) { + object = object || {}; + + DKTools.Base.prototype.setupAll.call(this, object); + + let contentsSprite = object.contentsSprite; + + if (object instanceof DKTools.Window && contentsSprite instanceof DKTools.Sprite) { + contentsSprite = contentsSprite.clone({ blockStart: true }); + } + + this.setupContentsWidth(object.contentsWidth); + this.setupContentsHeight(object.contentsHeight); + this.setupContentsSprite(contentsSprite); + this.setupContentsPosition(object.contentsPosition); + this.setupOpacity(object.opacity); + this.setupTone(object.tone); }; /** - * Returns true if needs to create the sprite of the left arrow + * Sets the width of the window * - * @returns {Boolean} Needs to create the sprite of the left arrow + * @param {Number} [width] - Width of the window + * + * @see DKTools.Window.prototype._checkWidth */ -DKTools.Window.prototype.needsCreateLeftArrowSprite = function() { - return true; +DKTools.Window.prototype.setupWidth = function(width) { + this.realWidth = this._checkWidth(width); }; /** - * Returns true if needs to create the sprite of the right arrow + * Sets the height of the window * - * @returns {Boolean} Needs to create the sprite of the right arrow + * @param {Number | String} [height] - Height of the window of number of lines (String) + * + * @see DKTools.Window.prototype._checkHeight */ -DKTools.Window.prototype.needsCreateRightArrowSprite = function() { - return true; +DKTools.Window.prototype.setupHeight = function(height) { + if (DKTools.Utils.isString(height)) { + height = this.getLineHeight() * Number(height); + } + + this.realHeight = this._checkHeight(height); }; /** - * Returns true if needs to create the sprite of the pause sign + * Sets the size of the window * - * @returns {Boolean} Needs to create the sprite of the pause sign + * @param {Number | Object} [object] - Width of the window or object with parameters + * @param {Number | String} [height] - Height of the window or number of lines (String) (if object is Number) + * + * @param {Number} [object.width] - Width of the window + * @param {Number | String} [object.height] - Height of the window or number of lines (String) + * + * @see DKTools.Window.prototype.getLineHeight + * @see DKTools.Window.prototype._checkWidth + * @see DKTools.Window.prototype._checkHeight + * @see Window.prototype.move */ -DKTools.Window.prototype.needsCreatePauseSignSprite = function() { - return true; -}; +DKTools.Window.prototype.setupSize = function(object, height) { + if (object instanceof Object) { + return this.setupSize(object.width, object.height); + } -// _refresh methods + if (DKTools.Utils.isString(height)) { + height = this.getLineHeight() * Number(height); + } + + // object - Number + object = this._checkWidth(object); + height = this._checkHeight(height); + + Window.prototype.move.call(this, this.x, this.y, object, height); +}; /** - * Updates all parts of the window + * Sets the width of the contents * - * @private - * @override + * @param {Function | Number} [contentsWidth=this.standardContentsWidth()] - Width of the contents * - * @see DKTools.Window.prototype._refreshBack - * @see DKTools.Window.prototype._refreshFrame - * @see DKTools.Window.prototype._refreshContents - * @see DKTools.Window.prototype._refreshPauseSign + * @see DKTools.Window.prototype.standardContentsWidth */ -DKTools.Window.prototype._refreshAllParts = function() { - this._refreshBack(); - this._refreshFrame(); - this._refreshContents(); - this._refreshPauseSign(); +DKTools.Window.prototype.setupContentsWidth = function(contentsWidth) { + this._contentsWidth = contentsWidth || this.standardContentsWidth(); }; /** - * Updates the background of the window + * Sets the height of the contents * - * @private - * @override + * @param {Function | Number} [contentsHeight=this.standardContentsHeight()] - Height of the contents * - * @see Window.prototype._refreshBack + * @see DKTools.Window.prototype.standardContentsHeight */ -DKTools.Window.prototype._refreshBack = function() { - if (this.hasBackSprite()) { - Window.prototype._refreshBack.call(this); - } +DKTools.Window.prototype.setupContentsHeight = function(contentsHeight) { + this._contentsHeight = contentsHeight || this.standardContentsHeight(); }; /** - * Updates the frame of the window + * Sets the sprite of the contents * - * @private - * @override + * @param {DKTools.Sprite | *} [contentsSprite=this.standardContentsSprite()] - Sprite of the contents * - * @see Window.prototype._refreshFrame + * @see DKTools.Window.prototype.standardContentsSprite */ -DKTools.Window.prototype._refreshFrame = function() { - if (this.hasFrameSprite()) { - Window.prototype._refreshFrame.call(this); - } +DKTools.Window.prototype.setupContentsSprite = function(contentsSprite) { + /** + * @private + * @readonly + * @type {DKTools.Sprite | *} + */ + this._windowContentsSprite = contentsSprite || this.standardContentsSprite(); }; /** - * Updates the contents + * Sets the position of the contents * - * @private - * @override + * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object=this.standardContentsPosition()] - The X coordinate or Point or object with parameters + * @param {Number} [y] - The Y coordinate (if object is Number) + * + * @param {Number} [object.x] - The X coordinate + * @param {Number} [object.y] - The Y coordinate + * + * @see DKTools.Utils.Point.toPoint + * @see DKTools.Utils.Point.standardContentsPosition */ -DKTools.Window.prototype._refreshContents = function() { - if (this.hasContentsSprite()) { - this._windowContentsSprite.move(this._contentsPosition); - } +DKTools.Window.prototype.setupContentsPosition = function(object, y) { + const position = DKTools.Utils.Point.toPoint(object, y); + const newPosition = Object.assign(this.standardContentsPosition(), position); + + /** + * @private + * @readonly + * @type {Point} + */ + this._contentsPosition = new Point(newPosition.x, newPosition.y); }; /** - * Updates the sprite of the pause sign + * Sets the opacity of the window * - * @private - * @override + * @param {Object} [opacity=this.standardOpacity()] - Opacity of the window * - * @see Window.prototype._refreshPauseSign + * @param {Number} [opacity.windowOpacity] - Opacity of the window + * @param {Number} [opacity.contentsOpacity] - Opacity of the contents + * @param {Number} [opacity.frameOpacity] - Opacity of the frame + * @param {Number} [opacity.backOpacity] - Opacity of the background + * + * @see DKTools.Window.prototype.standardOpacity */ -DKTools.Window.prototype._refreshPauseSign = function() { - if (this.hasPauseSignSprite()) { - Window.prototype._refreshPauseSign.call(this); - } +DKTools.Window.prototype.setupOpacity = function(opacity) { + /** + * @private + * @type {Object} + */ + this._opacity = Object.assign(this.standardOpacity(), opacity); }; -// start methods - /** - * Starts the window + * Sets the tone of the window * - * @param {Boolean} [activate=false] - Activates the window + * @param {Number[]} [tone=this.standardTone()] - Tone of the window * - * @see DKTools.Base.prototype.start + * @see DKTools.Window.prototype.standardTone */ -DKTools.Window.prototype.start = function(activate) { - if (this.hasContentsSprite()) { - const contentsSprite = this._windowContentsSprite; - contentsSprite.resize(this.getContentsWidth(), this.getContentsHeight(), true); - contentsSprite.start(activate); - } +DKTools.Window.prototype.setupTone = function(tone) { + const standardTone = _.clone(this.standardTone()); - DKTools.Base.prototype.start.call(this, activate); + /** + * @private + * @type {Number[]} + */ + this._tone = Object.assign(standardTone, tone); }; -// remove methods +// set methods /** - * Removes children objects from processing + * Changes all parameters + * Returns the number of changed parameters * * @override + * + * @param {Object} [object] - Parameters + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the window + * + * @param {Object} [object.opacity] - Opacity of the window + * @param {Number[]} [object.tone] - Tone of the window + * + * @param {Number} [object.opacity.windowOpacity] - Opacity of the window + * @param {Number} [object.opacity.contentsOpacity] - Opacity of the contents + * @param {Number} [object.opacity.frameOpacity] - Opacity of the frame + * @param {Number} [object.opacity.backOpacity] - Opacity of the background + * + * @see DKTools.Base.prototype.setAll + * @see DKTools.Window.prototype.setOpacity + * @see DKTools.Window.prototype.setTone + * @see DKTools.Window.prototype.start + * @see DKTools.Window.prototype.activate + * + * @returns {Number} Number of changed parameters */ -DKTools.Window.prototype.removeAllChildren = function() { - DKTools.Base.prototype.removeAllChildren.call(this); - this.removeContentsSprite(); +DKTools.Window.prototype.setAll = function(object, blockStart, activate) { + object = object || {}; + const block = true; + let changed = DKTools.Base.prototype.setAll.call(this, object, block); + + if (this.setOpacity(object.opacity, block)) { + changed++; + } + + if (this.setTone(object.tone, block)) { + changed++; + } + + if (changed) { + if (!blockStart) { + this.start(); + } + + if (activate) { + this.activate(); + } + } + + return changed; }; /** - * Removes the sprite of the contents from processing + * Changes the width of the window + * Returns true if the change occurred + * + * @param {Number} [width] - Width of the window + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the window + * + * @see DKTools.Window.prototype.resize + * + * @returns {Boolean} Change occurred */ -DKTools.Window.prototype.removeContentsSprite = function() { - if (this.hasContentsSprite()) { - this.removeChild(this._windowContentsSprite); - } +DKTools.Window.prototype.setWidth = function(width, blockStart, activate) { + return this.resize(width, this._height, blockStart, activate); }; /** - * Removes the arrow by ID + * Changes the height of the window + * Returns true if the change occurred * - * @param {Number | String} id - ID of the arrow + * @param {Number} [height] - Height of the window + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the window * - * @see DKTools.Window.prototype.getArrow - * @see DKTools.Utils.Array.remove - * @see DKTools.Window.prototype.removeChild + * @see DKTools.Window.prototype.resize + * + * @returns {Boolean} Change occurred */ -DKTools.Window.prototype.removeArrow = function(id) { - const arrow = this.getArrow(id); - - if (arrow) { - DKTools.Utils.Array.remove(this._arrows, arrow); - this.removeChild(arrow); - } +DKTools.Window.prototype.setHeight = function(height, blockStart, activate) { + return this.resize(this._width, height, blockStart, activate); }; -// check methods - /** - * Checks size of the window - * Returns the number of changed parameters + * Changes the sprite of the contents + * Returns true if the change occurred * - * @override + * @param {DKTools.Sprite | *} [contentsSprite] + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the window * - * @see DKTools.Window.prototype.getMinWidth - * @see DKTools.Window.prototype.getMinHeight + * @see DKTools.Window.prototype.removeContentsSprite + * @see DKTools.Window.prototype.setupContentsSprite + * @see DKTools.Window.prototype.addContentsSprite + * @see DKTools.Window.prototype.activate * - * @returns {Number} Number of changed parameters + * @returns {Boolean} Change occurred */ -DKTools.Window.prototype.checkSize = function() { - const minWidth = this.getMinWidth(); - const minHeight = this.getMinHeight(); - let changed = 0; +DKTools.Window.prototype.setContentsSprite = function(contentsSprite, blockStart, activate) { + if (this._windowContentsSprite == contentsSprite) { + return false; + } - if (this._width < minWidth) { - this.setupWidth(minWidth); - changed++; + // TODO: проверить + this.removeContentsSprite(); + this.setupContentsSprite(contentsSprite); + this.addContentsSprite(); + + if (!blockStart) { + this.start(); } - if (this._height < minHeight) { - this.setupHeight(minHeight); - changed++; + if (activate) { + this.activate(); } - return changed; + return true; }; -// create methods - /** - * Creates the arrow + * Changes the position of the contents + * Returns true if the change occurred * - * @version 3.0.0 - * - * @param {String} arrowType - Type - * @param {Number | String | *} id - ID - * @param {Object} options - Options + * @param {Number | PIXI.Point | PIXI.ObservablePoint | Point | Object} [object] - The X coordinate or Point or object with parameters + * @param {Number} [y] - The Y coordinate (if object is Number) * - * @param {Number} [options.x] - The X coordinate - * @param {Number | String} [options.y] - The Y coordinate or line number (String) - * @param {Function} [options.onMouseDown] - - * @param {Function} [options.onMouseUp] - - * @param {Function} [options.onMouseClick] - - * @param {Function} [options.onMouseLongPress] - - * @param {Function} [options.onMouseLongPressStarted] - - * @param {Function} [options.onMouseLongPressFinished] - - * @param {Function} [options.onStateNormal] - - * @param {Function} [options.onStatePressed] - + * @param {Number} [object.x] - The X coordinate + * @param {Number} [object.y] - The Y coordinate * - * @see DKTools.Sprite.Arrow - * @see DKTools.Event.prototype.onUpdate + * @see DKTools.Utils.Point.toPoint + * @see DKTools.Utils.Point.equals + * @see DKTools.Utils.Point.clone + * @see DKTools.Window.prototype.setupContentsPosition + * @see DKTools.Window.prototype._refreshContents * - * @returns {DKTools.Sprite.Arrow} Created arrow + * @returns {Boolean} Change occurred */ -DKTools.Window.prototype.createArrow = function(arrowType, id, options) { - const arrow = new DKTools.Sprite.Arrow({ - x: options.x, - y: options.y, - id, - arrowType - }); - - arrow.start(); - - arrow.addEvent({ - type: 'update', - onUpdate: function(event) { - if (this.isOpenAndVisible()) { - arrow.show(); - } else { - arrow.hide(); - } - - if (DKTools.Utils.isFunction(options.onUpdate)) { - options.onUpdate(event); - } - }.bind(this) - }); - - if (DKTools.Utils.isFunction(options.onMouseDown)) { - arrow.addEvent({ - type: 'mouse-down-left', - onUpdate: options.onMouseDown - }); - } - - if (DKTools.Utils.isFunction(options.onMouseUp)) { - arrow.addEvent({ - type: 'mouse-up-left', - onUpdate: options.onMouseUp - }); - } - - if (DKTools.Utils.isFunction(options.onMouseClick)) { - arrow.addEvent({ - type: 'mouse-click-left', - onUpdate: options.onMouseClick - }); - } - - if (DKTools.Utils.isFunction(options.onMouseLongPress)) { - arrow.addEvent({ - type: 'mouse-long-press-left', - onUpdate: options.onMouseLongPress - }); +DKTools.Window.prototype.setContentsPosition = function(object, y) { + if (object instanceof Object) { + return this.setContentsPosition(object, y); } - if (DKTools.Utils.isFunction(options.onMouseLongPressStarted)) { - arrow.addEvent({ - type: 'mouse-long-press-left-started', - onUpdate: options.onMouseLongPressStarted - }); - } + // object - Number + const newPos = DKTools.Utils.Point.toPoint(object, y); - if (DKTools.Utils.isFunction(options.onMouseLongPressFinished)) { - arrow.addEvent({ - type: 'mouse-long-press-left-finished', - onUpdate: options.onMouseLongPressFinished - }); + if (DKTools.Utils.Point.equals(this._contentsPosition, newPos)) { + return false; } - if (DKTools.Utils.isFunction(options.onStateNormal)) { - arrow.addEvent({ - type: 'state-normal', - onUpdate: options.onStateNormal - }); - } + const lastPos = DKTools.Utils.Point.clone(this._contentsPosition); + this.setupContentsPosition(newPos); - if (DKTools.Utils.isFunction(options.onStatePressed)) { - arrow.addEvent({ - type: 'state-pressed', - onUpdate: options.onStatePressed - }); + if (!DKTools.Utils.Point.equals(this._contentsPosition, lastPos)) { + this._refreshContents(); + return true; } - this._arrows.push(arrow); - - this.addChild(arrow); - - return arrow; + return false; }; /** - * Creates the arrows + * Changes the opacity of the window + * Returns true if the change occurred * - * @version 3.0.0 + * @param {Object} [opacity] - Opacity of the window + * @param {Boolean} [blockUpdateOpacity=false] - Blocking the call of the "updateOpacity" function * - * @see DKTools.Window.prototype.needsCreateDownArrowSprite - * @see DKTools.Window.prototype.needsCreateUpArrowSprite - * @see DKTools.Window.prototype.needsCreateRightArrowSprite - * @see DKTools.Window.prototype.needsCreateLeftArrowSprite - * @see DKTools.Window.prototype.createArrow - * @see DKTools.Window.prototype.onDownArrowUpdate - * @see DKTools.Window.prototype.onDownArrowMouseClick - * @see DKTools.Window.prototype.onDownArrowMouseLongPress - * @see DKTools.Window.prototype.onUpArrowUpdate - * @see DKTools.Window.prototype.onUpArrowMouseClick - * @see DKTools.Window.prototype.onUpArrowMouseLongPress - * @see DKTools.Window.prototype.onRightArrowUpdate - * @see DKTools.Window.prototype.onRightArrowMouseClick - * @see DKTools.Window.prototype.onRightArrowMouseLongPress - * @see DKTools.Window.prototype.onLeftArrowUpdate - * @see DKTools.Window.prototype.onLeftArrowMouseClick - * @see DKTools.Window.prototype.onLeftArrowMouseLongPress - * @see DKTools.Window.prototype.standardArrowStateNormal - * @see DKTools.Window.prototype.standardArrowStatePressed + * @param {Number} [opacity.windowOpacity] - Opacity of the window + * @param {Number} [opacity.contentsOpacity] - Opacity of the contents + * @param {Number} [opacity.frameOpacity] - Opacity of the frame + * @param {Number} [opacity.backOpacity] - Opacity of the background + * + * @see DKTools.Window.prototype.setupOpacity + * @see DKTools.Window.prototype.updateOpacity + * + * @returns {Boolean} Change occurred */ -DKTools.Window.prototype.createArrows = function() { - const w = this._width; - const h = this._height; - const q = 12; - - if (this.needsCreateDownArrowSprite()) { - this.createArrow('down', 'down', { - x: w / 2, - y: h - q, - onUpdate: this.onDownArrowUpdate.bind(this), - onMouseClick: this.onDownArrowMouseClick.bind(this), - onMouseLongPress: this.onDownArrowMouseLongPress.bind(this), - onStateNormal: this.standardArrowStateNormal(), - onStatePressed: this.standardArrowStatePressed() - }); - } - - if (this.needsCreateUpArrowSprite()) { - this.createArrow('up', 'up', { - x: w / 2, - y: q, - onUpdate: this.onUpArrowUpdate.bind(this), - onMouseClick: this.onUpArrowMouseClick.bind(this), - onMouseLongPress: this.onUpArrowMouseLongPress.bind(this), - onStateNormal: this.standardArrowStateNormal(), - onStatePressed: this.standardArrowStatePressed() - }); - } - - if (this.needsCreateRightArrowSprite()) { - this.createArrow('right', 'right', { - x: w - q, - y: h / 2, - onUpdate: this.onRightArrowUpdate.bind(this), - onMouseClick: this.onRightArrowMouseClick.bind(this), - onMouseLongPress: this.onRightArrowMouseLongPress.bind(this), - onStateNormal: this.standardArrowStateNormal(), - onStatePressed: this.standardArrowStatePressed() - }); - } - - if (this.needsCreateLeftArrowSprite()) { - this.createArrow('left', 'left', { - x: q, - y: h / 2, - onUpdate: this.onLeftArrowUpdate.bind(this), - onMouseClick: this.onLeftArrowMouseClick.bind(this), - onMouseLongPress: this.onLeftArrowMouseLongPress.bind(this), - onStateNormal: this.standardArrowStateNormal(), - onStatePressed: this.standardArrowStatePressed() - }); +DKTools.Window.prototype.setOpacity = function(opacity, blockUpdateOpacity) { + if (_.isEqual(this._opacity, Object.assign(this.standardOpacity(), opacity))) { + return false; } -}; -// add methods + this.setupOpacity(opacity); -/** - * Adds children objects to processing - * - * @override - */ -DKTools.Window.prototype.addAllChildren = function() { - DKTools.Base.prototype.addAllChildren.call(this); - this.addContentsSprite(); -}; + if (!blockUpdateOpacity) { + this.updateOpacity(); + } -/** - * Adds the sprite of the contents to processing - */ -DKTools.Window.prototype.addContentsSprite = function() { - this._addContentsSprite(); - this._refreshContents(); + return true; }; -// refresh methods - /** - * Refreshes the arrows + * Changes the tone of the window + * Returns true if the change occurred * - * @since 2.0.0 + * @override + * + * @param {Number[]} [tone] - Tone of the window + * @param {Boolean} [blockUpdateTone=false] - Blocking the call of the "updateTone" function + * + * @see DKTools.Window.prototype.setupTone + * @see DKTools.Window.prototype.updateTone + * + * @returns {Boolean} Change occurred */ -DKTools.Window.prototype.refreshArrows = function() { - _.forEach(this._arrows, function(arrow) { - arrow.refreshAll(); - }); -}; +DKTools.Window.prototype.setTone = function(tone, blockUpdateTone) { + const standardTone = _.clone(this.standardTone()); -// redraw methods + if (_.isEqual(this._tone, Object.assign(standardTone, tone))) { + return false; + } -/** - * Redraws all - * - * @version 1.1.0 - */ -DKTools.Window.prototype.redrawAll = function() { - if (this.hasContentsSprite()) { - this._windowContentsSprite.redrawAll(); + this.setupTone(tone); + + if (!blockUpdateTone) { + this.updateTone(); } + + return true; }; -// can methods +// get methods /** - * Returns true if the window can be updated and redrawn + * Returns the minimum width of the window * - * @since 1.1.0 * @override - * @returns {Boolean} Window can be updated and redrawn + * + * @see DKTools.Window.prototype.standardPadding + * @see DKTools.Base.prototype.getMinWidth + * + * @returns {Number} Minimum width of the window */ -DKTools.Window.prototype.canRedrawAll = function() { - return this.hasContentsSprite() && DKTools.Base.prototype.canRedrawAll.call(this); +DKTools.Window.prototype.getMinWidth = function() { + return this.standardPadding() * 2 + DKTools.Base.prototype.getMinWidth.call(this); }; -// draw methods - /** - * Draws the text + * Returns the minimum height of the window * * @override * - * @param {String} text - Text - * @param {Object} [options={}] - Options for drawing + * @see DKTools.Window.prototype.standardPadding + * @see DKTools.Base.prototype.getMinHeight * - * @see DKTools.Window.prototype.hasContentsSprite - * @see DKTools.Sprite.prototype.drawText + * @returns {Number} Minimum height of the window */ -DKTools.Window.prototype.drawText = function(text, options) { - if (this.hasContentsSprite()) { - this._windowContentsSprite.drawText(text, options); - } +DKTools.Window.prototype.getMinHeight = function() { + return this.standardPadding() * 2 + DKTools.Base.prototype.getMinHeight.call(this); }; -// frame methods - /** - * Shows the frame + * Returns the width of the contents + * + * @returns {Number} Width of the contents */ -DKTools.Window.prototype.showFrame = function() { - if (this.hasFrameSprite()) { - this._windowFrameSprite.visible = true; +DKTools.Window.prototype.getContentsWidth = function() { + if (DKTools.Utils.isFunction(this._contentsWidth)) { + return this._contentsWidth(this); } -}; -/** - * Hides the frame - */ -DKTools.Window.prototype.hideFrame = function() { - if (this.hasFrameSprite()) { - this._windowFrameSprite.visible = false; - } + return this._contentsWidth; }; -// back methods - /** - * Shows the background + * Returns the height of the contents * - * @see DKTools.Window.prototype.hasBackSprite + * @returns {Number} Height of the contents */ -DKTools.Window.prototype.showBack = function() { - if (this.hasBackSprite()) { - this._windowBackSprite.visible = true; +DKTools.Window.prototype.getContentsHeight = function() { + if (DKTools.Utils.isFunction(this._contentsHeight)) { + return this._contentsHeight(this); } + + return this._contentsHeight; }; /** - * Hides the background + * Returns the size of the contents * - * @see DKTools.Window.prototype.hasBackSprite + * @see DKTools.Window.prototype.getContentsWidth + * @see DKTools.Window.prototype.getContentsHeight + * + * @returns {Object} Size of the contents */ -DKTools.Window.prototype.hideBack = function() { - if (this.hasBackSprite()) { - this._windowBackSprite.visible = false; - } +DKTools.Window.prototype.getContentsSize = function() { + return { width: this.getContentsWidth(), height: this.getContentsHeight() }; }; -// contents methods - /** - * Shows the contents - * - * @param {Boolean} [activate=false] - Activates the contents + * Returns the arrow by ID * - * @see DKTools.Window.prototype.hasContentsSprite + * @param {Number | String} id - ID of the arrow + * @returns {DKTools.Sprite.Arrow | undefined} Sprite of the arrow or undefined */ -DKTools.Window.prototype.showContents = function(activate) { - if (this.hasContentsSprite()) { - this._windowContentsSprite.show(activate); - } +DKTools.Window.prototype.getArrow = function(id) { + return _.find(this._arrows, { id }); }; /** - * Hides the contents + * Returns the current opacity of the window + * + * @returns {Number} Current opacity of the window */ -DKTools.Window.prototype.hideContents = function() { - if (this.hasContentsSprite()) { - this._windowContentsSprite.hide(); - } +DKTools.Window.prototype.getCurrentOpacity = function() { + return this.windowOpacity; }; -// is method +// needs create methods /** - * Returns true if the window is open and visible + * Returns true if needs to create the sprite of the background * - * @returns {Boolean} Window is open and visible + * @returns {Boolean} Needs to create the sprite of the background */ -DKTools.Window.prototype.isOpenAndVisible = function() { - return this.isOpen() && this.isVisible(); +DKTools.Window.prototype.needsCreateBackSprite = function() { + return true; }; /** - * Returns true if the window is open and active + * Returns true if needs to create the sprite of the frame * - * @returns {Boolean} Window is open and active + * @returns {Boolean} Needs to create the sprite of the frame */ -DKTools.Window.prototype.isOpenAndActive = function() { - return this.isOpen() && this.isActive(); +DKTools.Window.prototype.needsCreateFrameSprite = function() { + return true; }; /** - * Returns true if the coordinates is inside the window - * - * @override - * - * @param {Number} x - The X coordinate - * @param {Number} y - The Y coordinate + * Returns true if needs to create the sprites of the arrows * - * @returns {Boolean} Coordinates is inside the window + * @returns {Boolean} Needs to create the sprites of the arrows */ -DKTools.Window.prototype.isInside = function(x, y) { - const localX = this.canvasToLocalX(x); - const localY = this.canvasToLocalY(y); - const frame = new Rectangle(0, 0, this.width, this.height); - - return frame.contains(localX, localY); +DKTools.Window.prototype.needsCreateArrowsSprites = function() { + return false; }; -// has methods - /** - * Returns true if the window has the container of the sprites + * Returns true if needs to create the sprite of the down arrow * - * @returns {Boolean} Window has the container of the sprites + * @returns {Boolean} Needs to create the sprite of the down arrow */ -DKTools.Window.prototype.hasSpriteContainer = function() { - return !!this._windowSpriteContainer; +DKTools.Window.prototype.needsCreateDownArrowSprite = function() { + return true; }; /** - * Returns true if the window has the sprite of the background + * Returns true if needs to create the sprite of the up arrow * - * @returns {Boolean} Window has the sprite of the background + * @returns {Boolean} Needs to create the sprite of the up arrow */ -DKTools.Window.prototype.hasBackSprite = function() { - return !!this._windowBackSprite; +DKTools.Window.prototype.needsCreateUpArrowSprite = function() { + return true; }; /** - * Returns true if the window has the sprite of the frame + * Returns true if needs to create the sprite of the left arrow * - * @returns {Boolean} Window has the sprite of the frame + * @returns {Boolean} Needs to create the sprite of the left arrow */ -DKTools.Window.prototype.hasFrameSprite = function() { - return !!this._windowFrameSprite; +DKTools.Window.prototype.needsCreateLeftArrowSprite = function() { + return true; }; /** - * Returns true if the window has the sprite of the contents + * Returns true if needs to create the sprite of the right arrow * - * @returns {Boolean} Window has the sprite of the contents + * @returns {Boolean} Needs to create the sprite of the right arrow */ -DKTools.Window.prototype.hasContentsSprite = function() { - return !!this._windowContentsSprite; +DKTools.Window.prototype.needsCreateRightArrowSprite = function() { + return true; }; /** - * Returns true if the window has the arrow by ID - * - * @param {Number | String | *} id - ID of the arrow - * - * @see DKTools.Window.prototype.getArrow + * Returns true if needs to create the sprite of the pause sign * - * @returns {Boolean} Window has the arrow by ID + * @returns {Boolean} Needs to create the sprite of the pause sign */ -DKTools.Window.prototype.hasArrow = function(id) { - return !!this.getArrow(id); +DKTools.Window.prototype.needsCreatePauseSignSprite = function() { + return true; }; +// _refresh methods + /** - * Returns true if the window has the sprites of the arrows + * Updates all parts of the window * - * @returns {Boolean} Window has the sprites of the arrows + * @version 3.1.0 + * @private + * @override + * + * @see DKTools.Window.prototype._refreshBack + * @see DKTools.Window.prototype._refreshFrame + * @see DKTools.Window.prototype._refreshContents + * @see DKTools.Window.prototype._refreshPauseSign + * @see DKTools.Window.prototype._refreshArrows */ -DKTools.Window.prototype.hasArrowSprites = function() { - return this.hasUpArrowSprite() && this.hasDownArrowSprite() && - this.hasLeftArrowSprite() && this.hasRightArrowSprite(); +DKTools.Window.prototype._refreshAllParts = function() { + this._refreshBack(); + this._refreshFrame(); + this._refreshContents(); + this._refreshPauseSign(); + this._refreshArrows(); }; /** - * Returns true if the window has the sprite of the arrow of up + * Updates the background of the window * - * @see DKTools.Window.prototype.hasArrow + * @private + * @override * - * @returns {Boolean} Window has the sprite of the arrow of up + * @see Window.prototype._refreshBack */ -DKTools.Window.prototype.hasUpArrowSprite = function() { - return this.hasArrow('up'); +DKTools.Window.prototype._refreshBack = function() { + if (this.hasBackSprite()) { + Window.prototype._refreshBack.call(this); + } }; /** - * Returns true if the window has the sprite of the arrow of down + * Updates the frame of the window * - * @see DKTools.Window.prototype.hasArrow + * @private + * @override * - * @returns {Boolean} Window has the sprite of the arrow of down + * @see Window.prototype._refreshFrame */ -DKTools.Window.prototype.hasDownArrowSprite = function() { - return this.hasArrow('down'); +DKTools.Window.prototype._refreshFrame = function() { + if (this.hasFrameSprite()) { + Window.prototype._refreshFrame.call(this); + } }; /** - * Returns true if the window has the sprite of the arrow of left - * - * @see DKTools.Window.prototype.hasArrow + * Updates the contents * - * @returns {Boolean} Window has the sprite of the arrow of left + * @private + * @override */ -DKTools.Window.prototype.hasLeftArrowSprite = function() { - return this.hasArrow('left'); +DKTools.Window.prototype._refreshContents = function() { + if (this.hasContentsSprite()) { + this._windowContentsSprite.move(this._contentsPosition); + } }; /** - * Returns true if the window has the sprite of the arrow of right + * Updates the sprite of the pause sign * - * @see DKTools.Window.prototype.hasArrow + * @private + * @override * - * @returns {Boolean} Window has the sprite of the arrow of right + * @see Window.prototype._refreshPauseSign */ -DKTools.Window.prototype.hasRightArrowSprite = function() { - return this.hasArrow('right'); +DKTools.Window.prototype._refreshPauseSign = function() { + if (this.hasPauseSignSprite()) { + Window.prototype._refreshPauseSign.call(this); + } }; /** - * Returns true if the window has the sprite of the pause sign + * Updates the arrows * - * @returns {Boolean} Window has the sprite of the pause sign + * @since 3.1.0 + * @private + * @override */ -DKTools.Window.prototype.hasPauseSignSprite = function() { - return !!this._windowPauseSignSprite; +DKTools.Window.prototype._refreshArrows = function() { + const arrows = { + up: this.standardUpArrowPosition(), + down: this.standardDownArrowPosition(), + left: this.standardLeftArrowPosition(), + right: this.standardRightArrowPosition() + }; + + _.forEach(arrows, function(position, arrowType) { + const arrow = this.getArrow(arrowType); + + if (arrow) { + arrow.move(position); + } + }.bind(this)); }; +// start methods + /** - * Returns true if the window has the sprite of the background dimmer + * Starts the window * - * @returns {Boolean} Window has the sprite of the background dimmer + * @param {Boolean} [activate=false] - Activates the window + * + * @see DKTools.Base.prototype.start */ -DKTools.Window.prototype.hasBackgroundDimmer = function() { - return !!this._dimmerSprite; +DKTools.Window.prototype.start = function(activate) { + if (this.hasContentsSprite()) { + const contentsSprite = this._windowContentsSprite; + contentsSprite.resize(this.getContentsWidth(), this.getContentsHeight(), true); + contentsSprite.start(activate); + } + + DKTools.Base.prototype.start.call(this, activate); }; -// active methods +// remove methods /** - * Activates the window + * Removes children objects from processing * * @override */ -DKTools.Window.prototype.activate = function() { - DKTools.Base.prototype.activate.call(this); +DKTools.Window.prototype.removeAllChildren = function() { + DKTools.Base.prototype.removeAllChildren.call(this); + this.removeContentsSprite(); +}; +/** + * Removes the sprite of the contents from processing + */ +DKTools.Window.prototype.removeContentsSprite = function() { if (this.hasContentsSprite()) { - this._windowContentsSprite.activate(); + this.removeChild(this._windowContentsSprite); } }; /** - * Deactivates the window + * Removes the arrow by ID * - * @override + * @param {Number | String} id - ID of the arrow + * + * @see DKTools.Window.prototype.getArrow + * @see DKTools.Utils.Array.remove + * @see DKTools.Window.prototype.removeChild */ -DKTools.Window.prototype.deactivate = function() { - DKTools.Base.prototype.deactivate.call(this); +DKTools.Window.prototype.removeArrow = function(id) { + const arrow = this.getArrow(id); - if (this.hasContentsSprite()) { - this._windowContentsSprite.deactivate(); + if (arrow) { + DKTools.Utils.Array.remove(this._arrows, arrow); + this.removeChild(arrow); } }; -// size methods +// check methods /** - * Changes the size of the window if they are different from the current ones - * Returns true if the change occurred + * Checks size of the window + * Returns the number of changed parameters * * @override * - * @param {Number} [width] - Width of the window - * @param {Number} [height] - Height of the window - * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function - * @param {Boolean} [activate=false] - Activates the window - * * @see DKTools.Window.prototype.getMinWidth * @see DKTools.Window.prototype.getMinHeight - * @see DKTools.Window.prototype.setupSize - * @see DKTools.Window.prototype.start * - * @returns {Boolean} Change occurred + * @returns {Number} Number of changed parameters */ -DKTools.Window.prototype.resize = function(width, height, blockStart, activate) { - width = (width == null ? this.getMinWidth() : width); - height = (height == null ? this.getMinHeight() : height); +DKTools.Window.prototype.checkSize = function() { + const minWidth = this.getMinWidth(); + const minHeight = this.getMinHeight(); + let changed = 0; - if (DKTools.Utils.isString(height)) { - height = this.getLineHeight() * Number(height); + if (this._width < minWidth) { + this.setupWidth(minWidth); + changed++; } - if (this._width === width && this._height === height) { - return false; + if (this._height < minHeight) { + this.setupHeight(minHeight); + changed++; } - const lastWidth = this._width; - const lastHeight = this._height; - this.setupSize(width, height); + return changed; +}; - if (this._width === lastWidth && this._height === lastHeight) { - return false; +// create methods + +/** + * Creates the arrow + * + * @version 3.0.0 + * + * @param {String} arrowType - Type + * @param {Number | String | *} id - ID + * @param {Object} options - Options + * + * @param {Number} [options.x] - The X coordinate + * @param {Number | String} [options.y] - The Y coordinate or line number (String) + * @param {Function} [options.onMouseDown] - + * @param {Function} [options.onMouseUp] - + * @param {Function} [options.onMouseClick] - + * @param {Function} [options.onMouseLongPress] - + * @param {Function} [options.onMouseLongPressStarted] - + * @param {Function} [options.onMouseLongPressFinished] - + * @param {Function} [options.onStateNormal] - + * @param {Function} [options.onStatePressed] - + * + * @see DKTools.Sprite.Arrow + * @see DKTools.Event.prototype.onUpdate + * + * @returns {DKTools.Sprite.Arrow} Created arrow + */ +DKTools.Window.prototype.createArrow = function(arrowType, id, options) { + const arrow = new DKTools.Sprite.Arrow({ + x: options.x, + y: options.y, + id, + arrowType + }); + + arrow.start(); + + arrow.addEvent({ + type: 'update', + onUpdate: function(event) { + if (this.isOpenAndVisible()) { + arrow.show(); + } else { + arrow.hide(); + } + + if (DKTools.Utils.isFunction(options.onUpdate)) { + options.onUpdate(event); + } + }.bind(this) + }); + + if (DKTools.Utils.isFunction(options.onMouseDown)) { + arrow.addEvent({ + type: 'mouse-down-left', + onUpdate: options.onMouseDown + }); } - if (!blockStart) { - this.start(activate); + if (DKTools.Utils.isFunction(options.onMouseUp)) { + arrow.addEvent({ + type: 'mouse-up-left', + onUpdate: options.onMouseUp + }); + } + + if (DKTools.Utils.isFunction(options.onMouseClick)) { + arrow.addEvent({ + type: 'mouse-click-left', + onUpdate: options.onMouseClick + }); + } + + if (DKTools.Utils.isFunction(options.onMouseLongPress)) { + arrow.addEvent({ + type: 'mouse-long-press-left', + onUpdate: options.onMouseLongPress + }); + } + + if (DKTools.Utils.isFunction(options.onMouseLongPressStarted)) { + arrow.addEvent({ + type: 'mouse-long-press-left-started', + onUpdate: options.onMouseLongPressStarted + }); + } + + if (DKTools.Utils.isFunction(options.onMouseLongPressFinished)) { + arrow.addEvent({ + type: 'mouse-long-press-left-finished', + onUpdate: options.onMouseLongPressFinished + }); + } + + if (DKTools.Utils.isFunction(options.onStateNormal)) { + arrow.addEvent({ + type: 'state-normal', + onUpdate: options.onStateNormal + }); + } + + if (DKTools.Utils.isFunction(options.onStatePressed)) { + arrow.addEvent({ + type: 'state-pressed', + onUpdate: options.onStatePressed + }); } - return true; + this._arrows.push(arrow); + + this.addChild(arrow); + + return arrow; }; -// load methods +// add methods /** - * Loads and returns a bitmap from img/animations/ - * - * @method DKTools.Window.prototype.loadAnimation - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see DKTools.Window.prototype.loadBitmap + * Adds children objects to processing * - * @returns {Bitmap} Loaded bitmap + * @override */ +DKTools.Window.prototype.addAllChildren = function() { + DKTools.Base.prototype.addAllChildren.call(this); + this.addContentsSprite(); +}; /** - * Loads and returns a bitmap from img/battleback1/ - * - * @method DKTools.Window.prototype.loadBattleback1 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see DKTools.Window.prototype.loadBitmap - * - * @returns {Bitmap} Loaded bitmap + * Adds the sprite of the contents to processing */ +DKTools.Window.prototype.addContentsSprite = function() { + this._addContentsSprite(); + this._refreshContents(); +}; -/** - * Loads and returns a bitmap from img/battleback2/ - * - * @method DKTools.Window.prototype.loadBattleback2 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see DKTools.Window.prototype.loadBitmap - * - * @returns {Bitmap} Loaded bitmap - */ +// refresh methods /** - * Loads and returns a bitmap from img/enemies/ - * - * @method DKTools.Window.prototype.loadEnemy - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see DKTools.Window.prototype.loadBitmap + * Refreshes the arrows * - * @returns {Bitmap} Loaded bitmap + * @since 2.0.0 */ +DKTools.Window.prototype.refreshArrows = function() { + _.forEach(this._arrows, function(arrow) { + arrow.refreshAll(); + }); +}; -/** - * Loads and returns a bitmap from img/characters/ - * - * @method DKTools.Window.prototype.loadCharacter - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see DKTools.Window.prototype.loadBitmap - * - * @returns {Bitmap} Loaded bitmap - */ +// redraw methods /** - * Loads and returns a bitmap from img/faces/ - * - * @method DKTools.Window.prototype.loadFace - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see DKTools.Window.prototype.loadBitmap + * Redraws all * - * @returns {Bitmap} Loaded bitmap + * @version 1.1.0 */ +DKTools.Window.prototype.redrawAll = function() { + if (this.hasContentsSprite()) { + this._windowContentsSprite.redrawAll(); + } +}; -/** - * Loads and returns a bitmap from img/parallaxes/ - * - * @method DKTools.Window.prototype.loadParallax - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see DKTools.Window.prototype.loadBitmap - * - * @returns {Bitmap} Loaded bitmap - */ +// can methods /** - * Loads and returns a bitmap from img/pictures/ - * - * @method DKTools.Window.prototype.loadPicture - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see DKTools.Window.prototype.loadBitmap + * Returns true if the window can be updated and redrawn * - * @returns {Bitmap} Loaded bitmap + * @since 1.1.0 + * @override + * @returns {Boolean} Window can be updated and redrawn */ +DKTools.Window.prototype.canRedrawAll = function() { + return this.hasContentsSprite() && DKTools.Base.prototype.canRedrawAll.call(this); +}; -/** - * Loads and returns a bitmap from img/sv_actors/ - * - * @method DKTools.Window.prototype.loadSvActor - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see DKTools.Window.prototype.loadBitmap - * - * @returns {Bitmap} Loaded bitmap - */ +// draw methods /** - * Loads and returns a bitmap from img/sv_enemies/ - * - * @method DKTools.Window.prototype.loadSvEnemy - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) + * Draws the text * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap + * @override * - * @see DKTools.Window.prototype.loadBitmap + * @param {String} text - Text + * @param {Object} [options={}] - Options for drawing * - * @returns {Bitmap} Loaded bitmap + * @see DKTools.Window.prototype.hasContentsSprite + * @see DKTools.Sprite.prototype.drawText */ +DKTools.Window.prototype.drawText = function(text, options) { + if (this.hasContentsSprite()) { + this._windowContentsSprite.drawText(text, options); + } +}; -/** - * Loads and returns a bitmap from img/system/ - * - * @method DKTools.Window.prototype.loadSystem - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see DKTools.Window.prototype.loadBitmap - * - * @returns {Bitmap} Loaded bitmap - */ +// frame methods /** - * Loads and returns a bitmap from img/tilesets/ - * - * @method DKTools.Window.prototype.loadTileset - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see DKTools.Window.prototype.loadBitmap - * - * @returns {Bitmap} Loaded bitmap + * Shows the frame */ +DKTools.Window.prototype.showFrame = function() { + if (this.hasFrameSprite()) { + this._windowFrameSprite.visible = true; + } +}; /** - * Loads and returns a bitmap from img/titles1/ - * - * @method DKTools.Window.prototype.loadTitle1 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see DKTools.Window.prototype.loadBitmap - * - * @returns {Bitmap} Loaded bitmap + * Hides the frame */ +DKTools.Window.prototype.hideFrame = function() { + if (this.hasFrameSprite()) { + this._windowFrameSprite.visible = false; + } +}; + +// back methods /** - * Loads and returns a bitmap from img/titles2/ - * - * @method DKTools.Window.prototype.loadTitle2 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see DKTools.Window.prototype.loadBitmap + * Shows the background * - * @returns {Bitmap} Loaded bitmap + * @see DKTools.Window.prototype.hasBackSprite */ +DKTools.Window.prototype.showBack = function() { + if (this.hasBackSprite()) { + this._windowBackSprite.visible = true; + } +}; /** - * Loads and returns a bitmap from img/system/ - * - * @method DKTools.Window.prototype.loadWindowskin - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * - * @see DKTools.Window.prototype.loadSystem + * Hides the background * - * @returns {Bitmap} Loaded bitmap + * @see DKTools.Window.prototype.hasBackSprite */ +DKTools.Window.prototype.hideBack = function() { + if (this.hasBackSprite()) { + this._windowBackSprite.visible = false; + } +}; + +// contents methods /** - * Loads and returns a bitmap - * - * @param {String | Object} object - Path to file or object with parameters - * @param {String} filename - Name of file (if object is String) - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * - * @param {String} object.folder - Path to file - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap + * Shows the contents * - * @see DKTools.Utils.Bitmap.load + * @param {Boolean} [activate=false] - Activates the contents * - * @returns {Bitmap} Loaded bitmap + * @see DKTools.Window.prototype.hasContentsSprite */ -DKTools.Window.prototype.loadBitmap = function(object, filename, listener, hue, smooth) { - return DKTools.Utils.Bitmap.load(object, filename, listener, hue, smooth); +DKTools.Window.prototype.showContents = function(activate) { + if (this.hasContentsSprite()) { + this._windowContentsSprite.show(activate); + } }; -// reserve methods +/** + * Hides the contents + */ +DKTools.Window.prototype.hideContents = function() { + if (this.hasContentsSprite()) { + this._windowContentsSprite.hide(); + } +}; + +// is method /** - * Loads, reserves and returns a bitmap from img/animations/ - * - * @method DKTools.Window.prototype.reserveAnimation - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID - * - * @see DKTools.Window.prototype.reserveBitmap + * Returns true if the window is open and visible * - * @returns {Bitmap} Loaded bitmap + * @returns {Boolean} Window is open and visible */ +DKTools.Window.prototype.isOpenAndVisible = function() { + return this.isOpen() && this.isVisible(); +}; /** - * Loads, reserves and returns a bitmap from img/battleback1/ - * - * @method DKTools.Window.prototype.reserveBattleback1 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID - * - * @see DKTools.Window.prototype.reserveBitmap + * Returns true if the window is open and active * - * @returns {Bitmap} Loaded bitmap + * @returns {Boolean} Window is open and active */ +DKTools.Window.prototype.isOpenAndActive = function() { + return this.isOpen() && this.isActive(); +}; /** - * Loads, reserves and returns a bitmap from img/battleback2/ - * - * @method DKTools.Window.prototype.reserveBattleback2 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) + * Returns true if the coordinates is inside the window * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * @override * - * @see DKTools.Window.prototype.reserveBitmap + * @param {Number} x - The X coordinate + * @param {Number} y - The Y coordinate * - * @returns {Bitmap} Loaded bitmap + * @returns {Boolean} Coordinates is inside the window */ +DKTools.Window.prototype.isInside = function(x, y) { + const localX = this.canvasToLocalX(x); + const localY = this.canvasToLocalY(y); + const frame = new Rectangle(0, 0, this.width, this.height); + + return frame.contains(localX, localY); +}; + +// has methods /** - * Loads, reserves and returns a bitmap from img/enemies/ - * - * @method DKTools.Window.prototype.reserveEnemy - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID - * - * @see DKTools.Window.prototype.reserveBitmap + * Returns true if the window has the container of the sprites * - * @returns {Bitmap} Loaded bitmap + * @returns {Boolean} Window has the container of the sprites */ +DKTools.Window.prototype.hasSpriteContainer = function() { + return !!this._windowSpriteContainer; +}; /** - * Loads, reserves and returns a bitmap from img/characters/ - * - * @method DKTools.Window.prototype.reserveCharacter - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID - * - * @see DKTools.Window.prototype.reserveBitmap + * Returns true if the window has the sprite of the background * - * @returns {Bitmap} Loaded bitmap + * @returns {Boolean} Window has the sprite of the background */ +DKTools.Window.prototype.hasBackSprite = function() { + return !!this._windowBackSprite; +}; /** - * Loads, reserves and returns a bitmap from img/faces/ - * - * @method DKTools.Window.prototype.reserveFace - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID - * - * @see DKTools.Window.prototype.reserveBitmap + * Returns true if the window has the sprite of the frame * - * @returns {Bitmap} Loaded bitmap + * @returns {Boolean} Window has the sprite of the frame */ +DKTools.Window.prototype.hasFrameSprite = function() { + return !!this._windowFrameSprite; +}; /** - * Loads, reserves and returns a bitmap from img/parallaxes/ - * - * @method DKTools.Window.prototype.reserveParallax - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID - * - * @see DKTools.Window.prototype.reserveBitmap + * Returns true if the window has the sprite of the contents * - * @returns {Bitmap} Loaded bitmap + * @returns {Boolean} Window has the sprite of the contents */ +DKTools.Window.prototype.hasContentsSprite = function() { + return !!this._windowContentsSprite; +}; /** - * Loads, reserves and returns a bitmap from img/pictures/ - * - * @method DKTools.Window.prototype.reservePicture - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) + * Returns true if the window has the arrow by ID * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * @param {Number | String | *} id - ID of the arrow * - * @see DKTools.Window.prototype.reserveBitmap + * @see DKTools.Window.prototype.getArrow * - * @returns {Bitmap} Loaded bitmap + * @returns {Boolean} Window has the arrow by ID */ +DKTools.Window.prototype.hasArrow = function(id) { + return !!this.getArrow(id); +}; /** - * Loads, reserves and returns a bitmap from img/sv_actors/ - * - * @method DKTools.Window.prototype.reserveSvActor - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID - * - * @see DKTools.Window.prototype.reserveBitmap + * Returns true if the window has the sprites of the arrows * - * @returns {Bitmap} Loaded bitmap + * @returns {Boolean} Window has the sprites of the arrows */ +DKTools.Window.prototype.hasArrowSprites = function() { + return this.hasUpArrowSprite() && this.hasDownArrowSprite() && + this.hasLeftArrowSprite() && this.hasRightArrowSprite(); +}; /** - * Loads, reserves and returns a bitmap from img/sv_enemies/ - * - * @method DKTools.Window.prototype.reserveSvEnemy + * Returns true if the window has the sprite of the arrow of up * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) + * @see DKTools.Window.prototype.hasArrow * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * @returns {Boolean} Window has the sprite of the arrow of up + */ +DKTools.Window.prototype.hasUpArrowSprite = function() { + return this.hasArrow('up'); +}; + +/** + * Returns true if the window has the sprite of the arrow of down * - * @see DKTools.Window.prototype.reserveBitmap + * @see DKTools.Window.prototype.hasArrow * - * @returns {Bitmap} Loaded bitmap + * @returns {Boolean} Window has the sprite of the arrow of down */ +DKTools.Window.prototype.hasDownArrowSprite = function() { + return this.hasArrow('down'); +}; /** - * Loads, reserves and returns a bitmap from img/system/ - * - * @method DKTools.Window.prototype.reserveSystem - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * Returns true if the window has the sprite of the arrow of left * - * @see DKTools.Window.prototype.reserveBitmap + * @see DKTools.Window.prototype.hasArrow * - * @returns {Bitmap} Loaded bitmap + * @returns {Boolean} Window has the sprite of the arrow of left */ +DKTools.Window.prototype.hasLeftArrowSprite = function() { + return this.hasArrow('left'); +}; /** - * Loads, reserves and returns a bitmap from img/tilesets/ - * - * @method DKTools.Window.prototype.reserveTileset - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * Returns true if the window has the sprite of the arrow of right * - * @see DKTools.Window.prototype.reserveBitmap + * @see DKTools.Window.prototype.hasArrow * - * @returns {Bitmap} Loaded bitmap + * @returns {Boolean} Window has the sprite of the arrow of right */ +DKTools.Window.prototype.hasRightArrowSprite = function() { + return this.hasArrow('right'); +}; /** - * Loads, reserves and returns a bitmap from img/titles1/ - * - * @method DKTools.Window.prototype.loadTitle1 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID - * - * @see DKTools.Window.prototype.reserveBitmap + * Returns true if the window has the sprite of the pause sign * - * @returns {Bitmap} Loaded bitmap + * @returns {Boolean} Window has the sprite of the pause sign */ +DKTools.Window.prototype.hasPauseSignSprite = function() { + return !!this._windowPauseSignSprite; +}; /** - * Loads, reserves and returns a bitmap from img/titles2/ - * - * @method DKTools.Window.prototype.loadTitle2 - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID - * - * @see DKTools.Window.prototype.reserveBitmap + * Returns true if the window has the sprite of the background dimmer * - * @returns {Bitmap} Loaded bitmap + * @returns {Boolean} Window has the sprite of the background dimmer */ +DKTools.Window.prototype.hasBackgroundDimmer = function() { + return !!this._dimmerSprite; +}; + +// active methods /** - * Loads, reserves and returns a bitmap from img/system/ - * - * @method DKTools.Window.prototype.reserveWindowskin - * - * @param {String | Object} object - Name of file or object with parameters - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) - * - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * Activates the window * - * @see DKTools.Window.prototype.reserveSystem + * @override + */ +DKTools.Window.prototype.activate = function() { + DKTools.Base.prototype.activate.call(this); + + if (this.hasContentsSprite()) { + this._windowContentsSprite.activate(); + } +}; + +/** + * Deactivates the window * - * @returns {Bitmap} Loaded bitmap + * @override */ +DKTools.Window.prototype.deactivate = function() { + DKTools.Base.prototype.deactivate.call(this); + + if (this.hasContentsSprite()) { + this._windowContentsSprite.deactivate(); + } +}; + +// size methods /** - * Loads, reserves and returns a bitmap - * - * @param {String | Object} object - Path to file or object with parameters - * @param {String} filename - Name of file (if object is String) - * @param {Function} [listener] - Function of processing after loading a bitmap (if object is String) - * @param {Number} [hue] - Hue of bitmap (if object is String) - * @param {Boolean} [smooth] - Smooth of bitmap (if object is String) - * @param {Number} [reservationId] - Reservation ID (if object is String) + * Changes the size of the window if they are different from the current ones + * Returns true if the change occurred * - * @param {String} object.folder - Path to file - * @param {String} object.filename - Name of file - * @param {Function} [object.listener] - Function of processing after loading a bitmap - * @param {Number} [object.hue] - Hue of bitmap - * @param {Boolean} [object.smooth] - Smooth of bitmap - * @param {Number} [object.reservationId] - Reservation ID + * @override * - * @see DKTools.Utils.Bitmap.reserve - * - * @returns {Bitmap} Loaded bitmap + * @param {Number} [width] - Width of the window + * @param {Number} [height] - Height of the window + * @param {Boolean} [blockStart=false] - Blocking the call of the "start" function + * @param {Boolean} [activate=false] - Activates the window + * + * @see DKTools.Window.prototype.getMinWidth + * @see DKTools.Window.prototype.getMinHeight + * @see DKTools.Window.prototype.setupSize + * @see DKTools.Window.prototype.start + * + * @returns {Boolean} Change occurred */ -DKTools.Window.prototype.reserveBitmap = function(object, filename, listener, hue, smooth, reservationId) { - return DKTools.Utils.Bitmap.reserve(object, filename, listener, hue, smooth, reservationId); +DKTools.Window.prototype.resize = function(width, height, blockStart, activate) { + width = (width == null ? this.getMinWidth() : width); + height = (height == null ? this.getMinHeight() : height); + + if (DKTools.Utils.isString(height)) { + height = this.getLineHeight() * Number(height); + } + + if (this._width === width && this._height === height) { + return false; + } + + const lastWidth = this._width; + const lastHeight = this._height; + this.setupSize(width, height); + + if (this._width === lastWidth && this._height === lastHeight) { + return false; + } + + if (!blockStart) { + this.start(activate); + } + + return true; }; // events methods @@ -28439,7 +28416,7 @@ DKTools.Window.prototype.updateCloseEvents = function() { // arrow methods /** - * Callback function that will be processing update of the up arrow + * Callback function that will be processing update of the arrow of up * * @param {DKTools.Event} event - Event * @@ -28450,7 +28427,7 @@ DKTools.Window.prototype.onUpArrowUpdate = function(event) { }; /** - * Callback function that will be processing update of the down arrow + * Callback function that will be processing update of the arrow of down * * @param {DKTools.Event} event - Event * @@ -28461,7 +28438,7 @@ DKTools.Window.prototype.onDownArrowUpdate = function(event) { }; /** - * Callback function that will be processing update of the left arrow + * Callback function that will be processing update of the arrow of left * * @param {DKTools.Event} event - Event * @@ -28472,7 +28449,7 @@ DKTools.Window.prototype.onLeftArrowUpdate = function(event) { }; /** - * Callback function that will be processing update of the right arrow + * Callback function that will be processing update of the arrow of right * * @param {DKTools.Event} event - Event * @@ -28483,7 +28460,7 @@ DKTools.Window.prototype.onRightArrowUpdate = function(event) { }; /** - * Callback function that will be processing click of the up arrow + * Callback function that will be processing click of the arrow of up * * @param {DKTools.Event} event - Event * @@ -28494,7 +28471,7 @@ DKTools.Window.prototype.onUpArrowMouseClick = function(event) { }; /** - * Callback function that will be processing click of the down arrow + * Callback function that will be processing click of the arrow of down * * @param {DKTools.Event} event - Event * @@ -28505,7 +28482,7 @@ DKTools.Window.prototype.onDownArrowMouseClick = function(event) { }; /** - * Callback function that will be processing click of the left arrow + * Callback function that will be processing click of the arrow of left * * @param {DKTools.Event} event - Event * @@ -28516,7 +28493,7 @@ DKTools.Window.prototype.onLeftArrowMouseClick = function(event) { }; /** - * Callback function that will be processing click of the right arrow + * Callback function that will be processing click of the arrow of right * * @param {DKTools.Event} event - Event * @@ -28527,7 +28504,7 @@ DKTools.Window.prototype.onRightArrowMouseClick = function(event) { }; /** - * Callback function that will be processing long press of the up arrow + * Callback function that will be processing long press of the arrow of up * * @param {DKTools.Event} event - Event * @@ -28538,7 +28515,7 @@ DKTools.Window.prototype.onUpArrowMouseLongPress = function(event) { }; /** - * Callback function that will be processing long press of the down arrow + * Callback function that will be processing long press of the arrow of down * * @param {DKTools.Event} event - Event * @@ -28549,7 +28526,7 @@ DKTools.Window.prototype.onDownArrowMouseLongPress = function(event) { }; /** - * Callback function that will be processing long press of the left arrow + * Callback function that will be processing long press of the arrow of left * * @param {DKTools.Event} event - Event * @@ -28560,7 +28537,7 @@ DKTools.Window.prototype.onLeftArrowMouseLongPress = function(event) { }; /** - * Callback function that will be processing long press of the right arrow + * Callback function that will be processing long press of the arrow of right * * @param {DKTools.Event} event - Event * @@ -28775,7 +28752,7 @@ DKTools.Window.Selectable.prototype.needsCreateArrowsSprites = function() { // arrow methods /** - * Callback function that will be processing update of the up arrow + * Callback function that will be processing update of the arrow of up * * @param {DKTools.Event} event - Event * @@ -28800,7 +28777,7 @@ DKTools.Window.Selectable.prototype.onUpArrowUpdate = function(event) { }; /** - * Callback function that will be processing update of the down arrow + * Callback function that will be processing update of the arrow of down * * @param {DKTools.Event} event - Event * @@ -28828,7 +28805,7 @@ DKTools.Window.Selectable.prototype.onDownArrowUpdate = function(event) { }; /** - * Callback function that will be processing update of the left arrow + * Callback function that will be processing update of the arrow of left * * @param {DKTools.Event} event - Event * @@ -28853,7 +28830,7 @@ DKTools.Window.Selectable.prototype.onLeftArrowUpdate = function(event) { }; /** - * Callback function that will be processing update of the right arrow + * Callback function that will be processing update of the arrow of right * * @param {DKTools.Event} event - Event * @@ -28881,7 +28858,7 @@ DKTools.Window.Selectable.prototype.onRightArrowUpdate = function(event) { }; /** - * Callback function that will be processing click of the up arrow + * Callback function that will be processing click of the arrow of up * * @param {DKTools.Event} event - Event * @@ -28896,7 +28873,7 @@ DKTools.Window.Selectable.prototype.onUpArrowMouseClick = function(event) { }; /** - * Callback function that will be processing click of the down arrow + * Callback function that will be processing click of the arrow of down * * @param {DKTools.Event} event - Event * @@ -28911,7 +28888,7 @@ DKTools.Window.Selectable.prototype.onDownArrowMouseClick = function(event) { }; /** - * Callback function that will be processing click of the left arrow + * Callback function that will be processing click of the arrow of left * * @param {DKTools.Event} event - Event * @@ -28926,7 +28903,7 @@ DKTools.Window.Selectable.prototype.onLeftArrowMouseClick = function(event) { }; /** - * Callback function that will be processing click of the right arrow + * Callback function that will be processing click of the arrow of right * * @param {DKTools.Event} event - Event * @@ -28941,7 +28918,7 @@ DKTools.Window.Selectable.prototype.onRightArrowMouseClick = function(event) { }; /** - * Callback function that will be processing long press of the up arrow + * Callback function that will be processing long press of the arrow of up * * @param {DKTools.Event} event - Event * @@ -28952,7 +28929,7 @@ DKTools.Window.Selectable.prototype.onUpArrowMouseLongPress = function(event) { }; /** - * Callback function that will be processing long press of the down arrow + * Callback function that will be processing long press of the arrow of down * * @param {DKTools.Event} event - Event * @@ -28963,7 +28940,7 @@ DKTools.Window.Selectable.prototype.onDownArrowMouseLongPress = function(event) }; /** - * Callback function that will be processing long press of the left arrow + * Callback function that will be processing long press of the arrow of left * * @param {DKTools.Event} event - Event * @@ -28974,7 +28951,7 @@ DKTools.Window.Selectable.prototype.onLeftArrowMouseLongPress = function(event) }; /** - * Callback function that will be processing long press of the right arrow + * Callback function that will be processing long press of the arrow of right * * @param {DKTools.Event} event - Event * @@ -29973,15 +29950,6 @@ DKTools.Scene.prototype.updateChildren = function() { this.iterateChildren(this.updateChild); }; -/** - * Updates the events - * - * @since 2.0.0 - */ -DKTools.Scene.prototype.updateEvents = function() { - this._eventManager.update(); -}; - @@ -30001,6 +29969,23 @@ const DKToolsParam = new DKTools.ParameterManager('DKTools'); +//=========================================================================== +// initialize plugin commands +//=========================================================================== + +DKTools.PluginCommandManager.set('DKPluginsCheckUpdates', function() { + DKTools.Utils._checkUpdates(); + DKTools.Utils._openConsole(); +}); + +DKTools.PluginCommandManager.set('OpenDebugConsole', function() { + DKTools.Utils._openConsole(); +}); + + + + + //=========================================================================== // window //=========================================================================== @@ -30039,7 +30024,7 @@ const DKTools_Graphics_initialize = Graphics.initialize; Graphics.initialize = function(width, height, type) { DKTools_Graphics_initialize.call(this, width, height, type); - if (Utils.isOptionValid('test') && DKToolsParam.get('Show FPS')) { + if (DKTools.Utils.isTest() && DKToolsParam.get('Show FPS')) { this.showFps(); } }; @@ -30047,7 +30032,7 @@ Graphics.initialize = function(width, height, type) { const DKTools_Graphics_printLoadingError = Graphics.printLoadingError; Graphics.printLoadingError = function(url) { DKTools_Graphics_printLoadingError.call(this, url); - SceneManager._logError(`Failed to load: ${url}`); + DKTools.Utils.logError(`Failed to load: ${url}`); }; @@ -30361,6 +30346,26 @@ Object.defineProperties(TouchInput, { +//=========================================================================== +// Tilemap +//=========================================================================== + +const DKTools__Tilemap_initialize = Tilemap.prototype.initialize; +Tilemap.prototype.initialize = function() { + DKTools__Tilemap_initialize.call(this); + + const param = DKToolsParam.get('Tile Size'); + + if (param.Enabled) { + this._tileWidth = param.Size; + this._tileHeight = param.Size; + } +}; + + + + + //=========================================================================== // SceneManager //=========================================================================== @@ -30368,10 +30373,10 @@ Object.defineProperties(TouchInput, { const DKTools_SceneManager_initGraphics = SceneManager.initGraphics; SceneManager.initGraphics = function() { const param = DKToolsParam.get('Screen Resolution'); - const width = param['Screen Width']; - const height = param['Screen Height']; + const width = param.Width; + const height = param.Height; - if (param['Enabled']) { + if (param.Enabled) { this._boxWidth = width; this._screenWidth = width; this._boxHeight = height; @@ -30397,69 +30402,6 @@ SceneManager.updateResolution = function() { } }; -SceneManager._logError = function(e) { - if (!e || !DKTools.IO.isLocalMode()) { - return; - } - - const param = DKToolsParam.get('Errors Log'); - const enabled = param['Enabled']; - - if (enabled === 'None' || - enabled === 'Only Game' && Utils.isOptionValid('test') || - enabled === 'Only Test' && !Utils.isOptionValid('test')) { - return; - } - - const fs = DKTools.IO.fs; - const os = require('os'); - - if (!fs || !os) { - return; - } - - const fileSize = param['File Size'] * 1024 * 1024; - const filename = param['Filename']; - const file = new DKTools.IO.File(filename); - const stats = file.getStats({ sync: true }).data; - let fileDescription = fs.openSync(filename, 'a'); - - if (stats && stats.size > fileSize) { - fs.closeSync(fileDescription); - file.remove({ sync: true }); - fileDescription = fs.openSync(filename, 'a'); - } - - if (e instanceof Object) { - let data = `Date: ${new Date().toString()}` + os.EOL + - `Name: ${e.name}` + os.EOL + - `Message: ${e.message}` + os.EOL; - - if (e.filename != undefined) { - data += `Filename: ${e.filename}` + os.EOL; - } - - if (e.lineNumber !== undefined) { - data += `Line: ${e.lineNumber}` + os.EOL; - } - - if (e.columnNumber !== undefined) { - data += `Column: ${e.columnNumber}` + os.EOL; - } - - data += `Stack: ${e.stack}` + os.EOL + os.EOL; - - fs.writeSync(fileDescription, data); - } else { - const data = `Date: ${new Date().toString()}` + os.EOL + - `Error: ${e}` + os.EOL + os.EOL; - - fs.writeSync(fileDescription, data); - } - - fs.closeSync(fileDescription); -}; - const DKTools_SceneManager_onKeyDown = SceneManager.onKeyDown; SceneManager.onKeyDown = function(event) { DKTools_SceneManager_onKeyDown.call(this, event); @@ -30473,7 +30415,7 @@ SceneManager.onKeyDown = function(event) { const keyCode = event.keyCode; if (keyCode === quickLoadKeyCode && - Utils.isOptionValid('test') && + DKTools.Utils.isTest() && DKToolsParam.get('Quick Load', 'Enabled')) { const savefileId = DKToolsParam.get('Quick Load', 'Savefile ID'); const scene = SceneManager._scene; @@ -30504,13 +30446,21 @@ SceneManager.onKeyDown = function(event) { const DKTools_SceneManager_catchException = SceneManager.catchException; SceneManager.catchException = function(e) { DKTools_SceneManager_catchException.call(this, e); - this._logError(e); + DKTools.Utils.logError(e); + + if (DKTools.Utils.isTest() && DKToolsParam.get('Debug Console', 'Open On Error')) { + DKTools.Utils._openConsole(); + } }; const DKTools_SceneManager_onError = SceneManager.onError; SceneManager.onError = function(e) { DKTools_SceneManager_onError.call(this, e); - this._logError(e); + DKTools.Utils.logError(e); + + if (DKTools.Utils.isTest() && DKToolsParam.get('Debug Console', 'Open On Error')) { + DKTools.Utils._openConsole(); + } }; @@ -30525,7 +30475,7 @@ const DKTools_Scene_Boot_start = Scene_Boot.prototype.start; Scene_Boot.prototype.start = function() { const quickStart = DKToolsParam.get('Quick Start'); - if (quickStart['Enabled']) { + if (quickStart.Enabled) { DKTools_Scene_Boot_start.call(this); if (!DataManager.isBattleTest() && !DataManager.isEventTest() && @@ -30546,6 +30496,36 @@ Scene_Boot.prototype.start = function() { +//=========================================================================== +// Game_Map +//=========================================================================== + +const DKTools_Game_Map_tileWidth = Game_Map.prototype.tileWidth; +Game_Map.prototype.tileWidth = function() { + const param = DKToolsParam.get('Tile Size'); + + if (param.Enabled) { + return param.Size; + } + + return DKTools_Game_Map_tileWidth.call(this); +}; + +const DKTools_Game_Map_tileHeight = Game_Map.prototype.tileHeight; +Game_Map.prototype.tileHeight = function() { + const param = DKToolsParam.get('Tile Size'); + + if (param.Enabled) { + return param.Size; + } + + return DKTools_Game_Map_tileHeight.call(this); +}; + + + + + //=========================================================================== // Game_Interpreter //=========================================================================== diff --git a/README.md b/README.md index e3e8803..b1602ab 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,12 @@ **Author**: DK -**Version**: Public 3.0.0 +**Version**: Public 3.1.0 **Description**: Library for RPG Maker MV. Contains many tools for developing. **Documentation**: https://dk-plugins.ru/documentation/DKTools/index.html **Dependencies**: RPG Maker MV 1.5+ - -## **Installation**: -1. Copy DKTools.js to the js/plugins/ of your project -2. Enable DKTools in the plugin manager -3. Add at least one game language in the parameters of the DKTools ## **4 steps to use DKTools** 1. Create element @@ -119,9 +114,4 @@ DKTools.Window DKTools.Window.Selectable -DKTools.Scene - -## **3 main reasons for use DKTools:** -1. Not need to waste time for creating a special sprites or windows -2. Large number of element parameters and all parameters have default values -3. Many different functions in each element +DKTools.Scene \ No newline at end of file