From 9771247b79bc180a9a181252c416112b647f479e Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sat, 19 Nov 2022 11:30:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E7=95=8C=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 2 +- index.html | 2 +- package.json | 1 + pnpm-lock.yaml | 7 + public/libs/actions.js | 2240 ++++++++++++------- public/libs/ui.js | 3910 +++++++++++++++++++++++---------- public/project/enemys.js | 2 +- public/project/plugins.js | 5 + src/components/boxAnimate.vue | 3 +- src/components/enemyOne.vue | 43 +- src/components/scroll.vue | 89 +- src/panel/enemyCritical.vue | 193 ++ src/panel/enemySpecial.vue | 94 + src/plugin/book.tsx | 121 + src/plugin/uiController.ts | 18 +- src/plugin/use.ts | 103 +- src/plugin/utils.ts | 17 + src/styles.less | 3 + src/types/enemy.d.ts | 4 +- src/types/plugin.d.ts | 29 +- src/types/util.d.ts | 8 +- src/ui/book.vue | 58 +- src/ui/bookDetail.vue | 174 +- vite.config.ts | 2 +- 24 files changed, 5022 insertions(+), 2106 deletions(-) create mode 100644 src/panel/enemyCritical.vue create mode 100644 src/panel/enemySpecial.vue create mode 100644 src/plugin/book.tsx diff --git a/components.d.ts b/components.d.ts index b7d04c5..aeed6a3 100644 --- a/components.d.ts +++ b/components.d.ts @@ -8,7 +8,7 @@ export {} declare module '@vue/runtime-core' { export interface GlobalComponents { ADivider: typeof import('ant-design-vue/es')['Divider'] - BookOne: typeof import('./src/components/bookOne.vue')['default'] + ASlider: typeof import('ant-design-vue/es')['Slider'] BoxAnimate: typeof import('./src/components/boxAnimate.vue')['default'] EnemyOne: typeof import('./src/components/enemyOne.vue')['default'] Scroll: typeof import('./src/components/scroll.vue')['default'] diff --git a/index.html b/index.html index 0a088c0..ef76494 100644 --- a/index.html +++ b/index.html @@ -15,7 +15,7 @@ - +
diff --git a/package.json b/package.json index 0a1ff9e..b2c7953 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@ant-design/icons-vue": "^6.1.0", "ant-design-vue": "^3.2.13", "axios": "^1.1.3", + "chart.js": "^4.0.1", "lodash": "^4.17.21", "lz-string": "^1.4.4", "mutate-animate": "^0.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2a4e3d0..23e4b81 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,6 +12,7 @@ specifiers: '@vitejs/plugin-vue-jsx': ^2.1.1 ant-design-vue: ^3.2.13 axios: ^1.1.3 + chart.js: ^4.0.1 compressing: ^1.6.2 fontmin: ^0.9.9 form-data: ^4.0.0 @@ -32,6 +33,7 @@ dependencies: '@ant-design/icons-vue': 6.1.0_vue@3.2.45 ant-design-vue: 3.2.15_vue@3.2.45 axios: 1.1.3 + chart.js: 4.0.1 lodash: 4.17.21 lz-string: 1.4.4 mutate-animate: 0.1.0 @@ -1069,6 +1071,11 @@ packages: supports-color: 5.5.0 dev: true + /chart.js/4.0.1: + resolution: {integrity: sha512-5/8/9eBivwBZK81mKvmIwTb2Pmw4D/5h1RK9fBWZLLZ8mCJ+kfYNmV9rMrGoa5Hgy2/wVDBMLSUDudul2/9ihA==} + engines: {pnpm: ^7.0.0} + dev: false + /chokidar/3.5.3: resolution: {integrity: sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==} engines: {node: '>= 8.10.0'} diff --git a/public/libs/actions.js b/public/libs/actions.js index 6891d5a..c21b3d5 100644 --- a/public/libs/actions.js +++ b/public/libs/actions.js @@ -1,16 +1,17 @@ - /* actions.js:用户交互的事件的处理 键盘、鼠标、触摸屏事件相关 */ -"use strict"; +'use strict'; -function actions () { +function actions() { this._init(); this._HX_ = core._HALF_WIDTH_; this._HY_ = core._HALF_HEIGHT_; - this._out = function (x) { return x < this._HX_ - 2 || this._HX_ + 2 < x; }; + this._out = function (x) { + return x < this._HX_ - 2 || this._HX_ + 2 < x; + }; this.LAST = core._WIDTH_ - 1; } @@ -18,44 +19,118 @@ actions.prototype._init = function () { this.actionsdata = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.actions; this.actions = {}; // --- onkeyDown注册 - this.registerAction('onkeyDown', '_sys_checkReplay', this._sys_checkReplay, 100); + this.registerAction( + 'onkeyDown', + '_sys_checkReplay', + this._sys_checkReplay, + 100 + ); this.registerAction('onkeyDown', '_sys_onkeyDown', this._sys_onkeyDown, 0); // --- onkeyUp注册 - this.registerAction('onkeyUp', '_sys_onkeyUp_replay', this._sys_onkeyUp_replay, 100); + this.registerAction( + 'onkeyUp', + '_sys_onkeyUp_replay', + this._sys_onkeyUp_replay, + 100 + ); this.registerAction('onkeyUp', '_sys_onkeyUp', this._sys_onkeyUp, 0); // --- pressKey注册 - this.registerAction('pressKey', '_sys_checkReplay', this._sys_checkReplay, 100); + this.registerAction( + 'pressKey', + '_sys_checkReplay', + this._sys_checkReplay, + 100 + ); this.registerAction('pressKey', '_sys_pressKey', this._sys_pressKey, 0); // --- keyDown注册 - this.registerAction('keyDown', '_sys_checkReplay', this._sys_checkReplay, 100); - this.registerAction('keyDown', '_sys_keyDown_lockControl', this._sys_keyDown_lockControl, 50); + this.registerAction( + 'keyDown', + '_sys_checkReplay', + this._sys_checkReplay, + 100 + ); + this.registerAction( + 'keyDown', + '_sys_keyDown_lockControl', + this._sys_keyDown_lockControl, + 50 + ); this.registerAction('keyDown', '_sys_keyDown', this._sys_keyDown, 0); // --- keyUp注册 - this.registerAction('keyUp', '_sys_keyUp_replay', this._sys_keyUp_replay, 100); - this.registerAction('keyUp', '_sys_keyUp_lockControl', this._sys_keyUp_lockControl, 50); + this.registerAction( + 'keyUp', + '_sys_keyUp_replay', + this._sys_keyUp_replay, + 100 + ); + this.registerAction( + 'keyUp', + '_sys_keyUp_lockControl', + this._sys_keyUp_lockControl, + 50 + ); this.registerAction('keyUp', '_sys_keyUp', this._sys_keyUp, 0); // --- ondown注册 - this.registerAction('ondown', '_sys_checkReplay', this._sys_checkReplay, 100); - this.registerAction('ondown', '_sys_ondown_lockControl', this._sys_ondown_lockControl, 30); + this.registerAction( + 'ondown', + '_sys_checkReplay', + this._sys_checkReplay, + 100 + ); + this.registerAction( + 'ondown', + '_sys_ondown_lockControl', + this._sys_ondown_lockControl, + 30 + ); this.registerAction('ondown', '_sys_ondown', this._sys_ondown, 0); // --- onmove注册 - this.registerAction('onmove', '_sys_checkReplay', this._sys_checkReplay, 100); - this.registerAction('onmove', '_sys_onmove_choices', this._sys_onmove_choices, 30); + this.registerAction( + 'onmove', + '_sys_checkReplay', + this._sys_checkReplay, + 100 + ); + this.registerAction( + 'onmove', + '_sys_onmove_choices', + this._sys_onmove_choices, + 30 + ); this.registerAction('onmove', '_sys_onmove', this._sys_onmove, 0); // --- onup注册 this.registerAction('onup', '_sys_checkReplay', this._sys_checkReplay, 100); this.registerAction('onup', '_sys_onup', this._sys_onup, 0); // --- onclick已废弃,将视为ondown // --- onmousewheel注册 - this.registerAction('onmousewheel', '_sys_onmousewheel', this._sys_onmousewheel, 0); + this.registerAction( + 'onmousewheel', + '_sys_onmousewheel', + this._sys_onmousewheel, + 0 + ); // --- keyDownCtrl注册 - this.registerAction('keyDownCtrl', '_sys_keyDownCtrl', this._sys_keyDownCtrl, 0); + this.registerAction( + 'keyDownCtrl', + '_sys_keyDownCtrl', + this._sys_keyDownCtrl, + 0 + ); // --- longClick注册 - this.registerAction('longClick', '_sys_longClick_lockControl', this._sys_longClick_lockControl, 50); + this.registerAction( + 'longClick', + '_sys_longClick_lockControl', + this._sys_longClick_lockControl, + 50 + ); // --- onStatusBarClick注册 - this.registerAction('onStatusBarClick', '_sys_onStatusBarClick', this._sys_onStatusBarClick, 0); - -} + this.registerAction( + 'onStatusBarClick', + '_sys_onStatusBarClick', + this._sys_onStatusBarClick, + 0 + ); +}; ////// 注册一个用户交互行为 ////// /* @@ -67,8 +142,7 @@ actions.prototype._init = function () { * 返回:如果func返回true,则不会再继续执行其他的交互函数;否则会继续执行其他的交互函数。 */ actions.prototype.registerAction = function (action, name, func, priority) { - if (!name || !func) - return; + if (!name || !func) return; // 将onclick视为ondown处理 if (action == 'onclick') action = 'ondown'; priority = priority || 0; @@ -76,13 +150,16 @@ actions.prototype.registerAction = function (action, name, func, priority) { this.actions[action] = []; } this.unregisterAction(action, name); - this.actions[action].push( - { "action": action, "name": name, "func": func, "priority": priority } - ); + this.actions[action].push({ + action: action, + name: name, + func: func, + priority: priority + }); this.actions[action] = this.actions[action].sort(function (a, b) { return b.priority - a.priority; }); -} +}; ////// 注销一个用户交互行为 ////// actions.prototype.unregisterAction = function (action, name) { @@ -92,7 +169,7 @@ actions.prototype.unregisterAction = function (action, name) { this.actions[action] = this.actions[action].filter(function (x) { return x.name != name; }); -} +}; ////// 执行一个用户交互行为 ////// actions.prototype.doRegisteredAction = function (action) { @@ -100,65 +177,83 @@ actions.prototype.doRegisteredAction = function (action) { if (!actions) return false; for (var i = 0; i < actions.length; ++i) { try { - if (core.doFunc.apply(core, [actions[i].func, this].concat(Array.prototype.slice.call(arguments, 1)))) + if ( + core.doFunc.apply( + core, + [actions[i].func, this].concat( + Array.prototype.slice.call(arguments, 1) + ) + ) + ) return true; - } - catch (e) { + } catch (e) { console.error(e); - console.error("ERROR in actions[" + actions[i].name + "]."); + console.error('ERROR in actions[' + actions[i].name + '].'); } } return false; -} +}; actions.prototype._checkReplaying = function () { - if (core.isReplaying() && - ['save', 'book', 'book-detail', 'viewMaps', 'toolbox', 'equipbox', 'text'].indexOf(core.status.event.id) < 0) + if ( + core.isReplaying() && + [ + 'save', + 'book', + 'book-detail', + 'viewMaps', + 'toolbox', + 'equipbox', + 'text' + ].indexOf(core.status.event.id) < 0 + ) return true; return false; -} +}; ////// 检查是否在录像播放中,如果是,则停止交互 actions.prototype._sys_checkReplay = function () { if (this._checkReplaying()) return true; -} +}; ////// 检查左手模式 actions.prototype.__checkLeftHandPrefer = function (e) { if (!core.flags.leftHandPrefer) return e; var map = { - 87: 38, // W -> up + 87: 38, // W -> up 83: 40, // S -> down 65: 37, // A -> left 68: 39, // D -> right 73: 87, // I -> W 74: 65, // J -> A 75: 83, // K -> S - 76: 68, // L -> D - } + 76: 68 // L -> D + }; var newEvent = {}; for (var one in e) { if (!(e[one] instanceof Function)) { newEvent[one] = e[one]; } - }; - ["stopPropagation", "stopImmediatePropagation", "preventDefault"].forEach(function (one) { - newEvent[one] = function () { - return e[one](); + } + ['stopPropagation', 'stopImmediatePropagation', 'preventDefault'].forEach( + function (one) { + newEvent[one] = function () { + return e[one](); + }; } - }); + ); newEvent.keyCode = map[e.keyCode] || e.keyCode; return newEvent; -} +}; ////// 按下某个键时 ////// actions.prototype.onkeyDown = function (e) { this.doRegisteredAction('onkeyDown', this.__checkLeftHandPrefer(e)); -} +}; actions.prototype._sys_onkeyDown = function (e) { - core.status.holdingKeys = core.status.holdingKeys || [] - var isArrow = { 37: true, 38: true, 39: true, 40: true }[e.keyCode] + core.status.holdingKeys = core.status.holdingKeys || []; + var isArrow = { 37: true, 38: true, 39: true, 40: true }[e.keyCode]; if (isArrow && !core.status.lockControl) { for (var ii = 0; ii < core.status.holdingKeys.length; ii++) { if (core.status.holdingKeys[ii] === e.keyCode) { @@ -172,58 +267,80 @@ actions.prototype._sys_onkeyDown = function (e) { if (e.keyCode == 17) core.status.ctrlDown = true; this.keyDown(e.keyCode); } -} +}; ////// 放开某个键时 ////// actions.prototype.onkeyUp = function (e) { this.doRegisteredAction('onkeyUp', this.__checkLeftHandPrefer(e)); -} +}; actions.prototype._sys_onkeyUp_replay = function (e) { if (this._checkReplaying()) { - if (e.keyCode == 27) // ESCAPE + if (e.keyCode == 27) + // ESCAPE core.stopReplay(); - else if (e.keyCode == 90) // Z + else if (e.keyCode == 90) + // Z core.speedDownReplay(); - else if (e.keyCode == 67) // C + else if (e.keyCode == 67) + // C core.speedUpReplay(); - else if (e.keyCode == 32) // SPACE + else if (e.keyCode == 32) + // SPACE core.triggerReplay(); - else if (e.keyCode == 65) // A + else if (e.keyCode == 65) + // A core.rewindReplay(); - else if (e.keyCode == 83) // S + else if (e.keyCode == 83) + // S core.control._replay_SL(); - else if (e.keyCode == 88) // X + else if (e.keyCode == 88) + // X core.control._replay_book(); - else if (e.keyCode == 33 || e.keyCode == 34) // PgUp/PgDn + else if (e.keyCode == 33 || e.keyCode == 34) + // PgUp/PgDn core.control._replay_viewMap(); - else if (e.keyCode == 78) // N + else if (e.keyCode == 78) + // N core.stepReplay(); - else if (e.keyCode == 84) // T + else if (e.keyCode == 84) + // T core.control._replay_toolbox(); - else if (e.keyCode == 81) // Q + else if (e.keyCode == 81) + // Q core.control._replay_equipbox(); - else if (e.keyCode == 66) // B + else if (e.keyCode == 66) + // B core.ui._drawStatistics(); - else if (e.keyCode >= 49 && e.keyCode <= 51) // 1-3 + else if (e.keyCode >= 49 && e.keyCode <= 51) + // 1-3 core.setReplaySpeed(e.keyCode - 48); - else if (e.keyCode == 52) // 4 + else if (e.keyCode == 52) + // 4 core.setReplaySpeed(6); - else if (e.keyCode == 53) // 5 + else if (e.keyCode == 53) + // 5 core.setReplaySpeed(12); - else if (e.keyCode == 54) // 6 + else if (e.keyCode == 54) + // 6 core.setReplaySpeed(24); return true; } -} +}; actions.prototype._sys_onkeyUp = function (e) { - var isArrow = { 37: true, 38: true, 39: true, 40: true }[e.keyCode] + var isArrow = { 37: true, 38: true, 39: true, 40: true }[e.keyCode]; if (isArrow && !core.status.lockControl) { for (var ii = 0; ii < core.status.holdingKeys.length; ii++) { if (core.status.holdingKeys[ii] === e.keyCode) { - core.status.holdingKeys = core.status.holdingKeys.slice(0, ii).concat(core.status.holdingKeys.slice(ii + 1)); - if (ii === core.status.holdingKeys.length && core.status.holdingKeys.length !== 0) core.pressKey(core.status.holdingKeys.slice(-1)[0]); + core.status.holdingKeys = core.status.holdingKeys + .slice(0, ii) + .concat(core.status.holdingKeys.slice(ii + 1)); + if ( + ii === core.status.holdingKeys.length && + core.status.holdingKeys.length !== 0 + ) + core.pressKey(core.status.holdingKeys.slice(-1)[0]); break; } } @@ -233,12 +350,12 @@ actions.prototype._sys_onkeyUp = function (e) { if (e.keyCode == 17) core.status.ctrlDown = false; this.keyUp(e.keyCode, e.altKey); } -} +}; ////// 按住某个键时 ////// actions.prototype.pressKey = function (keyCode) { this.doRegisteredAction('pressKey', keyCode); -} +}; actions.prototype._sys_pressKey = function (keyCode) { if (keyCode === core.status.holdingKeys.slice(-1)[0]) { @@ -247,12 +364,12 @@ actions.prototype._sys_pressKey = function (keyCode) { core.pressKey(keyCode); }, 30); } -} +}; ////// 根据按下键的code来执行一系列操作 ////// actions.prototype.keyDown = function (keyCode) { this.doRegisteredAction('keyDown', keyCode); -} +}; actions.prototype._sys_keyDown_lockControl = function (keyCode) { if (!core.status.lockControl) return false; @@ -265,9 +382,6 @@ actions.prototype._sys_keyDown_lockControl = function (keyCode) { case 'action': this._keyDownAction(keyCode); break; - case 'book': - this._keyDownBook(keyCode); - break; case 'fly': this._keyDownFly(keyCode); break; @@ -307,11 +421,10 @@ actions.prototype._sys_keyDown_lockControl = function (keyCode) { break; } return true; -} +}; actions.prototype._sys_keyDown = function (keyCode) { - if (!core.status.played) - return true; + if (!core.status.played) return true; switch (keyCode) { case 37: core.moveHero('left'); @@ -327,23 +440,29 @@ actions.prototype._sys_keyDown = function (keyCode) { break; } return true; -} +}; ////// 根据放开键的code来执行一系列操作 ////// actions.prototype.keyUp = function (keyCode, altKey, fromReplay) { this.doRegisteredAction('keyUp', keyCode, altKey, fromReplay); -} +}; actions.prototype._sys_keyUp_replay = function (keyCode, altKey, fromReplay) { if (!fromReplay && this._checkReplaying()) return true; -} +}; actions.prototype._sys_keyUp_lockControl = function (keyCode, altKey) { if (!core.status.lockControl) return false; var ok = function () { - return keyCode == 27 || keyCode == 88 || keyCode == 13 || keyCode == 32 || keyCode == 67; - } + return ( + keyCode == 27 || + keyCode == 88 || + keyCode == 13 || + keyCode == 32 || + keyCode == 67 + ); + }; core.status.holdingKeys = []; switch (core.status.event.id) { @@ -362,12 +481,6 @@ actions.prototype._sys_keyUp_lockControl = function (keyCode, altKey) { case 'help': ok() && core.closePanel(); break; - case 'book': - this._keyUpBook(keyCode); - break; - case 'book-detail': - ok() && this._clickBookDetail(); - break; case 'fly': this._keyUpFly(keyCode); break; @@ -437,25 +550,26 @@ actions.prototype._sys_keyUp_lockControl = function (keyCode, altKey) { break; } return true; -} +}; actions.prototype._sys_keyUp = function (keyCode, altKey) { - if (!core.status.played) - return true; + if (!core.status.played) return true; this.actionsdata.onKeyUp(keyCode, altKey); if (core.status.automaticRoute && core.status.automaticRoute.autoHeroMove) { core.stopAutomaticRoute(); } core.status.heroStop = true; return true; -} +}; ////// 点击(触摸)事件按下时 ////// actions.prototype.ondown = function (loc) { - var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); - var px = parseInt(loc.x / core.domStyle.scale), py = parseInt(loc.y / core.domStyle.scale); + var x = parseInt(loc.x / loc.size), + y = parseInt(loc.y / loc.size); + var px = parseInt(loc.x / core.domStyle.scale), + py = parseInt(loc.y / core.domStyle.scale); this.doRegisteredAction('ondown', x, y, px, py); -} +}; actions.prototype._sys_ondown_lockControl = function (x, y, px, py) { if (core.status.played && !core.status.lockControl) return false; @@ -464,12 +578,6 @@ actions.prototype._sys_ondown_lockControl = function (x, y, px, py) { case 'centerFly': this._clickCenterFly(x, y, px, py); break; - case 'book': - this._clickBook(x, y, px, py); - break; - case 'book-detail': - this._clickBookDetail(x, y, px, py); - break; case 'fly': this._clickFly(x, y, px, py); break; @@ -558,26 +666,40 @@ actions.prototype._sys_ondown_lockControl = function (x, y, px, py) { clearInterval(core.interval.onDownInterval); core.interval.onDownInterval = null; } - }, 40) + }, 40); } }, 500); } return true; -} +}; actions.prototype._sys_ondown = function (x, y, px, py) { if (core.status.lockControl) return false; core.status.downTime = new Date(); core.deleteCanvas('route'); - var pos = { 'x': parseInt((px + core.bigmap.offsetX) / 32), 'y': parseInt((py + core.bigmap.offsetY) / 32) }; + var pos = { + x: parseInt((px + core.bigmap.offsetX) / 32), + y: parseInt((py + core.bigmap.offsetY) / 32) + }; core.status.stepPostfix = []; core.status.stepPostfix.push(pos); - core.fillRect('ui', pos.x * 32 + 12 - core.bigmap.offsetX, pos.y * 32 + 12 - core.bigmap.offsetY, 8, 8, '#bfbfbf'); + core.fillRect( + 'ui', + pos.x * 32 + 12 - core.bigmap.offsetX, + pos.y * 32 + 12 - core.bigmap.offsetY, + 8, + 8, + '#bfbfbf' + ); clearTimeout(core.timeout.onDownTimeout); core.timeout.onDownTimeout = null; core.status.preview.prepareDragging = false; - if (!core.hasFlag('__lockViewport__') && (core.status.thisMap.width > core._WIDTH_ || core.status.thisMap.height > core._HEIGHT_)) { + if ( + !core.hasFlag('__lockViewport__') && + (core.status.thisMap.width > core._WIDTH_ || + core.status.thisMap.height > core._HEIGHT_) + ) { core.status.preview.prepareDragging = true; core.status.preview.px = px; core.status.preview.py = py; @@ -590,14 +712,16 @@ actions.prototype._sys_ondown = function (x, y, px, py) { core.status.stepPostfix = []; }, 500); } -} +}; ////// 当在触摸屏上滑动时 ////// actions.prototype.onmove = function (loc) { - var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); - var px = parseInt(loc.x / core.domStyle.scale), py = parseInt(loc.y / core.domStyle.scale); + var x = parseInt(loc.x / loc.size), + y = parseInt(loc.y / loc.size); + var px = parseInt(loc.x / core.domStyle.scale), + py = parseInt(loc.y / core.domStyle.scale); this.doRegisteredAction('onmove', x, y, px, py); -} +}; actions.prototype._sys_onmove_choices = function (x, y, px, py) { if (!core.status.lockControl) return false; @@ -635,19 +759,25 @@ actions.prototype._sys_onmove_choices = function (x, y, px, py) { break; } return false; -} +}; actions.prototype._sys_onmove = function (x, y, px, py) { if (core.status.lockControl) return false; if (core.status.preview.dragging) { - core.setViewport(core.bigmap.offsetX - px + core.status.preview.px, core.bigmap.offsetY - py + core.status.preview.py); + core.setViewport( + core.bigmap.offsetX - px + core.status.preview.px, + core.bigmap.offsetY - py + core.status.preview.py + ); core.status.preview.px = px; core.status.preview.py = py; return true; } if (core.status.preview.prepareDragging) { - if (Math.abs(px - core.status.preview.px) <= 20 && Math.abs(py - core.status.preview.py) <= 20) + if ( + Math.abs(px - core.status.preview.px) <= 20 && + Math.abs(py - core.status.preview.py) <= 20 + ) return true; else core.status.preview.prepareDragging = false; } @@ -656,33 +786,57 @@ actions.prototype._sys_onmove = function (x, y, px, py) { core.timeout.onDownTimeout = null; if ((core.status.stepPostfix || []).length > 0) { - var pos = { 'x': parseInt((px + core.bigmap.offsetX) / 32), 'y': parseInt((py + core.bigmap.offsetY) / 32) }; + var pos = { + x: parseInt((px + core.bigmap.offsetX) / 32), + y: parseInt((py + core.bigmap.offsetY) / 32) + }; var pos0 = core.status.stepPostfix[core.status.stepPostfix.length - 1]; - var directionDistance = [pos.y - pos0.y, pos0.x - pos.x, pos0.y - pos.y, pos.x - pos0.x]; - var max = 0, index = 4; + var directionDistance = [ + pos.y - pos0.y, + pos0.x - pos.x, + pos0.y - pos.y, + pos.x - pos0.x + ]; + var max = 0, + index = 4; for (var ii = 0; ii < 4; ii++) { if (directionDistance[ii] > max) { index = ii; max = directionDistance[ii]; } } - pos = [{ 'x': 0, 'y': 1 }, { 'x': -1, 'y': 0 }, { 'x': 0, 'y': -1 }, { 'x': 1, 'y': 0 }, false][index] + pos = [ + { x: 0, y: 1 }, + { x: -1, y: 0 }, + { x: 0, y: -1 }, + { x: 1, y: 0 }, + false + ][index]; if (pos) { pos.x += pos0.x; pos.y += pos0.y; core.status.stepPostfix.push(pos); - core.fillRect('ui', pos.x * 32 + 12 - core.bigmap.offsetX, pos.y * 32 + 12 - core.bigmap.offsetY, 8, 8, '#bfbfbf'); + core.fillRect( + 'ui', + pos.x * 32 + 12 - core.bigmap.offsetX, + pos.y * 32 + 12 - core.bigmap.offsetY, + 8, + 8, + '#bfbfbf' + ); } } return true; -} +}; ////// 当点击(触摸)事件放开时 ////// actions.prototype.onup = function (loc) { - var x = parseInt(loc.x / loc.size), y = parseInt(loc.y / loc.size); - var px = parseInt(loc.x / core.domStyle.scale), py = parseInt(loc.y / core.domStyle.scale); + var x = parseInt(loc.x / loc.size), + y = parseInt(loc.y / loc.size); + var px = parseInt(loc.x / core.domStyle.scale), + py = parseInt(loc.y / core.domStyle.scale); this.doRegisteredAction('onup', x, y, px, py); -} +}; actions.prototype._sys_onup = function (x, y, px, py) { clearTimeout(core.timeout.onDownTimeout); @@ -701,14 +855,18 @@ actions.prototype._sys_onup = function (x, y, px, py) { if ((core.status.stepPostfix || []).length == 0) return false; var stepPostfix = []; - var direction = { '0': { '1': 'down', '-1': 'up' }, '-1': { '0': 'left' }, '1': { '0': 'right' } }; + var direction = { + 0: { 1: 'down', '-1': 'up' }, + '-1': { 0: 'left' }, + 1: { 0: 'right' } + }; for (var ii = 1; ii < core.status.stepPostfix.length; ii++) { var pos0 = core.status.stepPostfix[ii - 1]; var pos = core.status.stepPostfix[ii]; stepPostfix.push({ - 'direction': direction[pos.x - pos0.x][pos.y - pos0.y], - 'x': pos.x, - 'y': pos.y + direction: direction[pos.x - pos0.x][pos.y - pos0.y], + x: pos.x, + y: pos.y }); } var posx = core.status.stepPostfix[0].x; @@ -719,44 +877,45 @@ actions.prototype._sys_onup = function (x, y, px, py) { } // 长按 - if (!core.status.lockControl && stepPostfix.length == 0 && core.status.downTime != null && new Date() - core.status.downTime >= 1000) { + if ( + !core.status.lockControl && + stepPostfix.length == 0 && + core.status.downTime != null && + new Date() - core.status.downTime >= 1000 + ) { core.actions.longClick(x, y, px, py); - } - else { + } else { //posx,posy是寻路的目标点,stepPostfix是后续的移动 core.setAutomaticRoute(posx, posy, stepPostfix); } core.status.downTime = null; return true; -} +}; ////// 获得点击事件相对左上角的坐标 ////// actions.prototype._getClickLoc = function (x, y) { - - var statusBar = { 'x': 0, 'y': 0 }; + var statusBar = { x: 0, y: 0 }; var size = 32; size = size * core.domStyle.scale; if (core.domStyle.isVertical) { statusBar.x = 3; statusBar.y = core.dom.statusBar.offsetHeight + 3; - } - else { + } else { statusBar.x = core.dom.statusBar.offsetWidth + 3; statusBar.y = 3; } var left = core.dom.gameGroup.offsetLeft + statusBar.x; var top = core.dom.gameGroup.offsetTop + statusBar.y; - var loc = { 'x': Math.max(x - left), 'y': Math.max(y - top, 0), 'size': size }; + var loc = { x: Math.max(x - left), y: Math.max(y - top, 0), size: size }; return loc; -} - +}; ////// 滑动鼠标滚轮时的操作 ////// actions.prototype.onmousewheel = function (direct) { this.doRegisteredAction('onmousewheel', direct); -} +}; actions.prototype._sys_onmousewheel = function (direct) { // 向下滚动是 -1 ,向上是 1 @@ -775,17 +934,13 @@ actions.prototype._sys_onmousewheel = function (direct) { return; } - // 怪物手册 - if (core.status.lockControl && core.status.event.id == 'book') { - var pageinfo = core.ui._drawBook_pageinfo(); - if (direct == 1) core.ui.drawBook(core.status.event.data - pageinfo.per_page); - if (direct == -1) core.ui.drawBook(core.status.event.data + pageinfo.per_page); - return; - } - // 存读档 - if (core.status.lockControl && (core.status.event.id == 'save' || core.status.event.id == 'load')) { - var index = core.status.event.data.page * 10 + core.status.event.data.offset; + if ( + core.status.lockControl && + (core.status.event.id == 'save' || core.status.event.id == 'load') + ) { + var index = + core.status.event.data.page * 10 + core.status.event.data.offset; if (direct == 1) core.ui._drawSLPanel(index - 10); if (direct == -1) core.ui._drawSLPanel(index + 10); return; @@ -793,46 +948,70 @@ actions.prototype._sys_onmousewheel = function (direct) { // 浏览地图 if (core.status.lockControl && core.status.event.id == 'viewMaps') { - if (direct == 1) this._clickViewMaps(this._HX_, this._HY_ - 3, core._PX_ / 2, core._PY_ / 5 * 1.5); - if (direct == -1) this._clickViewMaps(this._HX_, this._HY_ + 3, core._PX_ / 2, core._PY_ / 5 * 3.5); + if (direct == 1) + this._clickViewMaps( + this._HX_, + this._HY_ - 3, + core._PX_ / 2, + (core._PY_ / 5) * 1.5 + ); + if (direct == -1) + this._clickViewMaps( + this._HX_, + this._HY_ + 3, + core._PX_ / 2, + (core._PY_ / 5) * 3.5 + ); return; } // wait事件 - if (core.status.lockControl && core.status.event.id == 'action' && core.status.event.data.type == 'wait') { - var timeout = Math.max(0, core.status.event.timeout - new Date().getTime()) || 0; + if ( + core.status.lockControl && + core.status.event.id == 'action' && + core.status.event.data.type == 'wait' + ) { + var timeout = + Math.max(0, core.status.event.timeout - new Date().getTime()) || 0; core.setFlag('type', 0); var keycode = direct == 1 ? 33 : 34; core.setFlag('keycode', keycode); core.setFlag('timeout', timeout); - var executed = core.events.__action_wait_afterGet(core.status.event.data.current); + var executed = core.events.__action_wait_afterGet( + core.status.event.data.current + ); if (executed || !core.status.event.data.current.forceChild) { - core.status.route.push("input:" + (1e8 * timeout + keycode)); + core.status.route.push('input:' + (1e8 * timeout + keycode)); clearTimeout(core.status.event.interval); delete core.status.event.timeout; core.doAction(); } return; } - -} +}; ////// 长按Ctrl键时 ////// actions.prototype.keyDownCtrl = function () { this.doRegisteredAction('keyDownCtrl'); -} +}; actions.prototype._sys_keyDownCtrl = function () { if (core.status.event.id == 'text') { core.drawText(); return true; } - if (core.status.event.id == 'action' && core.status.event.data.type == 'text') { + if ( + core.status.event.id == 'action' && + core.status.event.data.type == 'text' + ) { core.doAction(); return true; } - if (core.status.event.id == 'action' && core.status.event.data.type == 'sleep' - && !core.status.event.data.current.noSkip) { + if ( + core.status.event.id == 'action' && + core.status.event.data.type == 'sleep' && + !core.status.event.data.current.noSkip + ) { if (core.timeout.sleepTimeout && !core.hasAsync()) { clearTimeout(core.timeout.sleepTimeout); core.timeout.sleepTimeout = null; @@ -840,13 +1019,13 @@ actions.prototype._sys_keyDownCtrl = function () { } return true; } -} +}; ////// 长按 ////// actions.prototype.longClick = function (x, y, px, py) { if (!core.isPlaying()) return false; return this.doRegisteredAction('longClick', x, y, px, py); -} +}; actions.prototype._sys_longClick_lockControl = function (x, y, px, py) { if (!core.status.lockControl) return false; @@ -854,27 +1033,48 @@ actions.prototype._sys_longClick_lockControl = function (x, y, px, py) { core.drawText(); return true; } - if (core.status.event.id == 'action' && core.status.event.data.type == 'text') { + if ( + core.status.event.id == 'action' && + core.status.event.data.type == 'text' + ) { core.doAction(); return true; } // 长按楼传器的箭头可以快速翻页 if (core.status.event.id == 'fly') { - if ((x == core._WIDTH_ - 2 || x == core._WIDTH_ - 3) && (y == this._HY_ - 1 || y == this._HY_ + 3)) { + if ( + (x == core._WIDTH_ - 2 || x == core._WIDTH_ - 3) && + (y == this._HY_ - 1 || y == this._HY_ + 3) + ) { this._clickFly(x, y); return true; } } // 长按SL上下页快速翻页 - if (["save", "load", "replayLoad", "replayRemain", "replaySince"].indexOf(core.status.event.id) >= 0) { - if ([this._HX_ - 2, this._HX_ - 3, this._HX_ + 2, this._HX_ + 3].indexOf(x) >= 0 && y===core._HEIGHT_-1) { + if ( + ['save', 'load', 'replayLoad', 'replayRemain', 'replaySince'].indexOf( + core.status.event.id + ) >= 0 + ) { + if ( + [ + this._HX_ - 2, + this._HX_ - 3, + this._HX_ + 2, + this._HX_ + 3 + ].indexOf(x) >= 0 && + y === core._HEIGHT_ - 1 + ) { this._clickSL(x, y); return true; } } // 长按可以跳过等待事件 - if (core.status.event.id == 'action' && core.status.event.data.type == 'sleep' - && !core.status.event.data.current.noSkip) { + if ( + core.status.event.id == 'action' && + core.status.event.data.type == 'sleep' && + !core.status.event.data.current.noSkip + ) { if (core.timeout.sleepTimeout && !core.hasAsync()) { clearTimeout(core.timeout.sleepTimeout); core.timeout.sleepTimeout = null; @@ -883,32 +1083,44 @@ actions.prototype._sys_longClick_lockControl = function (x, y, px, py) { } } return false; -} +}; actions.prototype.onStatusBarClick = function (e) { if (!core.isPlaying()) return false; var left = core.dom.gameGroup.offsetLeft + 3; var top = core.dom.gameGroup.offsetTop + 3; - var px = parseInt((e.clientX - left) / core.domStyle.scale), py = parseInt((e.clientY - top) / core.domStyle.scale); - return this.doRegisteredAction('onStatusBarClick', Math.max(px, 0), Math.max(py, 0)); -} + var px = parseInt((e.clientX - left) / core.domStyle.scale), + py = parseInt((e.clientY - top) / core.domStyle.scale); + return this.doRegisteredAction( + 'onStatusBarClick', + Math.max(px, 0), + Math.max(py, 0) + ); +}; actions.prototype._sys_onStatusBarClick = function (px, py, vertical) { if (this.actionsdata.onStatusBarClick) return this.actionsdata.onStatusBarClick(px, py, vertical); -} +}; /////////////////// 在某个界面时的按键点击效果 /////////////////// actions.prototype._getChoicesTopIndex = function (length) { - return this._HY_ - parseInt((length - 1) / 2) + (core.status.event.ui.offset || 0); -} + return ( + this._HY_ - + parseInt((length - 1) / 2) + + (core.status.event.ui.offset || 0) + ); +}; // 数字键快速选择选项 actions.prototype._selectChoices = function (length, keycode, callback) { var topIndex = this._getChoicesTopIndex(length); if (keycode == 13 || keycode == 32 || keycode == 67) { - callback.apply(this, [this._HX_, topIndex + core.status.event.selection]); + callback.apply(this, [ + this._HX_, + topIndex + core.status.event.selection + ]); } if (keycode >= 49 && keycode <= 57) { @@ -917,21 +1129,29 @@ actions.prototype._selectChoices = function (length, keycode, callback) { callback.apply(this, [this._HX_, topIndex + index]); } } -} +}; // 上下键调整选项 actions.prototype._keyDownChoices = function (keycode) { if (keycode == 38) { core.status.event.selection--; core.playSound('光标移动'); - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices, core.status.event.ui.width); + core.ui.drawChoices( + core.status.event.ui.text, + core.status.event.ui.choices, + core.status.event.ui.width + ); } if (keycode == 40) { core.status.event.selection++; core.playSound('光标移动'); - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices, core.status.event.ui.width); + core.ui.drawChoices( + core.status.event.ui.text, + core.status.event.ui.choices, + core.status.event.ui.width + ); } -} +}; // 移动光标 actions.prototype._onMoveChoices = function (x, y) { @@ -943,54 +1163,77 @@ actions.prototype._onMoveChoices = function (x, y) { if (selection == core.status.event.selection) return; core.status.event.selection = selection; core.playSound('光标移动'); - core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices, core.status.event.ui.width); + core.ui.drawChoices( + core.status.event.ui.text, + core.status.event.ui.choices, + core.status.event.ui.width + ); } -} +}; ////// 点击中心对称飞行器时 actions.prototype._clickCenterFly = function (x, y) { - var posX = core.status.event.data.posX, posY = core.status.event.data.posY; + var posX = core.status.event.data.posX, + posY = core.status.event.data.posY; core.ui.closePanel(); if (x == posX && y == posY) { if (core.canUseItem('centerFly')) { core.useItem('centerFly'); - } - else { + } else { core.playSound('操作失败'); - core.drawTip('当前不能使用' + core.material.items['centerFly'].name, 'centerFly'); + core.drawTip( + '当前不能使用' + core.material.items['centerFly'].name, + 'centerFly' + ); } } -} +}; actions.prototype._keyUpCenterFly = function (keycode) { core.ui.closePanel(); if (keycode == 51 || keycode == 13 || keycode == 32 || keycode == 67) { if (core.canUseItem('centerFly')) { core.useItem('centerFly'); - } - else { + } else { core.playSound('操作失败'); - core.drawTip('当前不能使用' + core.material.items['centerFly'].name, 'centerFly'); + core.drawTip( + '当前不能使用' + core.material.items['centerFly'].name, + 'centerFly' + ); } } -} +}; ////// 点击确认框时 ////// actions.prototype._clickConfirmBox = function (x, y, px, py) { - if (px >= core._PX_ / 2 - 70 && px <= core._PX_ / 2 - 10 - && py >= core._PY_ / 2 && py <= core._PY_ / 2 + 64 && core.status.event.data.yes) + if ( + px >= core._PX_ / 2 - 70 && + px <= core._PX_ / 2 - 10 && + py >= core._PY_ / 2 && + py <= core._PY_ / 2 + 64 && + core.status.event.data.yes + ) core.status.event.data.yes(); - if (px >= core._PX_ / 2 + 10 && px <= core._PX_ / 2 + 70 - && py >= core._PY_ / 2 && py <= core._PY_ / 2 + 64 && core.status.event.data.no) + if ( + px >= core._PX_ / 2 + 10 && + px <= core._PX_ / 2 + 70 && + py >= core._PY_ / 2 && + py <= core._PY_ / 2 + 64 && + core.status.event.data.no + ) core.status.event.data.no(); -} +}; ////// 键盘操作确认框时 ////// actions.prototype._keyUpConfirmBox = function (keycode) { if (keycode == 37 || keycode == 39) { core.status.event.selection = 1 - core.status.event.selection; core.playSound('光标移动'); - core.ui.drawConfirmBox(core.status.event.ui, core.status.event.data.yes, core.status.event.data.no); + core.ui.drawConfirmBox( + core.status.event.ui, + core.status.event.data.yes, + core.status.event.data.no + ); return; } if (keycode == 13 || keycode == 32 || keycode == 67) { @@ -1007,7 +1250,7 @@ actions.prototype._keyUpConfirmBox = function (keycode) { return; } } -} +}; ////// 鼠标在确认框上移动时 ////// actions.prototype._onMoveConfirmBox = function (x, y, px, py) { @@ -1019,7 +1262,11 @@ actions.prototype._onMoveConfirmBox = function (x, y, px, py) { if (core.status.event.id == 'action') { core.ui.drawConfirmBox(core.status.event.ui.text); } else { - core.ui.drawConfirmBox(core.status.event.ui, core.status.event.data.yes, core.status.event.data.no); + core.ui.drawConfirmBox( + core.status.event.ui, + core.status.event.data.yes, + core.status.event.data.no + ); } } return; @@ -1031,20 +1278,24 @@ actions.prototype._onMoveConfirmBox = function (x, y, px, py) { if (core.status.event.id == 'action') { core.ui.drawConfirmBox(core.status.event.ui.text); } else { - core.ui.drawConfirmBox(core.status.event.ui, core.status.event.data.yes, core.status.event.data.no); + core.ui.drawConfirmBox( + core.status.event.ui, + core.status.event.data.yes, + core.status.event.data.no + ); } } return; } } -} +}; actions.prototype._clickAction_text = function () { // 正在淡入淡出的话不执行 if (core.status.event.animateUI) return; var data = core.clone(core.status.event.data.current); - if (typeof data == 'string') data = { "type": "text", "text": data }; + if (typeof data == 'string') data = { type: 'text', text: data }; // 打字机效果显示全部文字 if (core.status.event.interval != null) { @@ -1060,7 +1311,7 @@ actions.prototype._clickAction_text = function () { // 不清除对话框 core.doAction(); } -} +}; ////// 自定义事件时的点击操作 ////// actions.prototype._clickAction = function (x, y, px, py) { @@ -1069,16 +1320,21 @@ actions.prototype._clickAction = function (x, y, px, py) { } if (core.status.event.data.type == 'wait') { - var timeout = Math.max(0, core.status.event.timeout - new Date().getTime()) || 0; + var timeout = + Math.max(0, core.status.event.timeout - new Date().getTime()) || 0; core.setFlag('type', 1); core.setFlag('x', x); core.setFlag('y', y); core.setFlag('px', px); core.setFlag('py', py); core.setFlag('timeout', timeout); - var executed = core.events.__action_wait_afterGet(core.status.event.data.current); + var executed = core.events.__action_wait_afterGet( + core.status.event.data.current + ); if (executed || !core.status.event.data.current.forceChild) { - core.status.route.push("input:" + (1e8 * timeout + 1000000 + 1000 * px + py)); + core.status.route.push( + 'input:' + (1e8 * timeout + 1000000 + 1000 * px + py) + ); clearTimeout(core.status.event.interval); delete core.status.event.timeout; core.doAction(); @@ -1092,52 +1348,64 @@ actions.prototype._clickAction = function (x, y, px, py) { var choices = data.choices; if (choices.length == 0) return; if (this._out(x)) return; - var topIndex = this._getChoicesTopIndex(choices.length); - if (y >= topIndex && y < topIndex + choices.length) { - var choice = choices[y - topIndex]; - if (choice.need != null && choice.need != '' && !core.calValue(choice.need)) { - core.playSound('操作失败'); - core.drawTip("无法选择此项"); - return; - } - clearTimeout(core.status.event.interval); - var timeout = Math.max(0, core.status.event.timeout - new Date().getTime()) || 0; - delete core.status.event.timeout; - core.setFlag('timeout', timeout); - // 对全局商店特殊处理 - var index = y - topIndex; - if (index == choices.length - 1 && core.hasFlag('@temp@shop')) { - index = -1; - } - core.status.route.push("choices:" + (100 * timeout + index)); - core.insertAction(choice.action); - core.doAction(); + var topIndex = this._getChoicesTopIndex(choices.length); + if (y >= topIndex && y < topIndex + choices.length) { + var choice = choices[y - topIndex]; + if ( + choice.need != null && + choice.need != '' && + !core.calValue(choice.need) + ) { + core.playSound('操作失败'); + core.drawTip('无法选择此项'); + return; } + clearTimeout(core.status.event.interval); + var timeout = + Math.max(0, core.status.event.timeout - new Date().getTime()) || + 0; + delete core.status.event.timeout; + core.setFlag('timeout', timeout); + // 对全局商店特殊处理 + var index = y - topIndex; + if (index == choices.length - 1 && core.hasFlag('@temp@shop')) { + index = -1; + } + core.status.route.push('choices:' + (100 * timeout + index)); + core.insertAction(choice.action); + core.doAction(); + } return; } if (core.status.event.data.type == 'confirm') { if ((x == this._HX_ - 2 || x == this._HX_ - 1) && y == this._HY_ + 1) { clearTimeout(core.status.event.interval); - var timeout = Math.max(0, core.status.event.timeout - new Date().getTime()) || 0; + var timeout = + Math.max(0, core.status.event.timeout - new Date().getTime()) || + 0; delete core.status.event.timeout; core.setFlag('timeout', timeout); - core.status.route.push("choices:" + 100 * timeout); + core.status.route.push('choices:' + 100 * timeout); core.insertAction(core.status.event.ui.yes); core.doAction(); - } - else if ((x == this._HX_ + 2 || x == this._HX_ + 1) && y == this._HY_ + 1) { + } else if ( + (x == this._HX_ + 2 || x == this._HX_ + 1) && + y == this._HY_ + 1 + ) { clearTimeout(core.status.event.interval); - var timeout = Math.max(0, core.status.event.timeout - new Date().getTime()) || 0; + var timeout = + Math.max(0, core.status.event.timeout - new Date().getTime()) || + 0; delete core.status.event.timeout; core.setFlag('timeout', timeout); - core.status.route.push("choices:" + (100 * timeout + 1)); + core.status.route.push('choices:' + (100 * timeout + 1)); core.insertAction(core.status.event.ui.no); core.doAction(); } return; } -} +}; ////// 自定义事件时,按下某个键的操作 ////// actions.prototype._keyDownAction = function (keycode) { @@ -1145,27 +1413,36 @@ actions.prototype._keyDownAction = function (keycode) { this._keyDownChoices(keycode); return; } - if (core.status.event.data.type == 'confirm' && (keycode == 37 || keycode == 39)) { + if ( + core.status.event.data.type == 'confirm' && + (keycode == 37 || keycode == 39) + ) { core.status.event.selection = 1 - core.status.event.selection; core.playSound('光标移动'); core.drawConfirmBox(core.status.event.ui.text); return; } -} +}; ////// 自定义事件时,放开某个键的操作 ////// actions.prototype._keyUpAction = function (keycode) { - if (core.status.event.data.type == 'text' && (keycode == 13 || keycode == 32 || keycode == 67)) { + if ( + core.status.event.data.type == 'text' && + (keycode == 13 || keycode == 32 || keycode == 67) + ) { return this._clickAction_text(); } if (core.status.event.data.type == 'wait') { - var timeout = Math.max(0, core.status.event.timeout - new Date().getTime()) || 0; + var timeout = + Math.max(0, core.status.event.timeout - new Date().getTime()) || 0; core.setFlag('type', 0); core.setFlag('keycode', keycode); core.setFlag('timeout', timeout); - var executed = core.events.__action_wait_afterGet(core.status.event.data.current); + var executed = core.events.__action_wait_afterGet( + core.status.event.data.current + ); if (executed || !core.status.event.data.current.forceChild) { - core.status.route.push("input:" + (1e8 * timeout + keycode)); + core.status.route.push('input:' + (1e8 * timeout + keycode)); clearTimeout(core.status.event.interval); delete core.status.event.timeout; core.doAction(); @@ -1180,127 +1457,81 @@ actions.prototype._keyUpAction = function (keycode) { } return; } - if (core.status.event.data.type == 'confirm' && (keycode == 13 || keycode == 32 || keycode == 67)) { - var timeout = Math.max(0, core.status.event.timeout - new Date().getTime()) || 0; + if ( + core.status.event.data.type == 'confirm' && + (keycode == 13 || keycode == 32 || keycode == 67) + ) { + var timeout = + Math.max(0, core.status.event.timeout - new Date().getTime()) || 0; delete core.status.event.timeout; core.setFlag('timeout', timeout); - core.status.route.push("choices:" + (100 * timeout + core.status.event.selection)); + core.status.route.push( + 'choices:' + (100 * timeout + core.status.event.selection) + ); if (core.status.event.selection == 0) core.insertAction(core.status.event.ui.yes); else core.insertAction(core.status.event.ui.no); core.doAction(); return; } -} - -////// 怪物手册界面的点击操作 ////// -actions.prototype._clickBook = function (x, y) { - var pageinfo = core.ui._drawBook_pageinfo(); - // 上一页 - if ((x == this._HX_ - 2 || x == this._HX_ - 3) && y===core._HEIGHT_-1) { - core.playSound('光标移动'); - core.ui.drawBook(core.status.event.data - pageinfo.per_page); - return; - } - // 下一页 - if ((x == this._HX_ + 2 || x == this._HX_ + 3) && y===core._HEIGHT_-1) { - core.playSound('光标移动'); - core.ui.drawBook(core.status.event.data + pageinfo.per_page); - return; - } - // 返回 - if (x >= this.LAST - 2 && y===core._HEIGHT_-1) { - core.playSound('取消'); - if (core.events.recoverEvents(core.status.event.interval)) { - return; - } - else if (core.status.event.ui != null) { - core.status.boxAnimateObjs = []; - core.ui._drawViewMaps(core.status.event.ui); - } - else core.ui.closePanel(); - return; - } - // 怪物信息 - var data = core.status.event.data; - if (data != null && y < core._HEIGHT_-1) { - var per_page = pageinfo.per_page, page = parseInt(data / per_page); - var u = this.LAST / per_page; - for (var i = 0; i < per_page; ++i) { - if (y >= u * i && y < u * (i + 1)) { - var index = per_page * page + i; - core.ui.drawBook(index); - core.ui._drawBookDetail(index); - break; - } - } - return; - } - return; -} - -////// 怪物手册界面时,按下某个键的操作 ////// -actions.prototype._keyDownBook = function (keycode) { - var pageinfo = core.ui._drawBook_pageinfo(); - if (keycode == 37) { core.playSound('光标移动'); core.ui.drawBook(core.status.event.data - pageinfo.per_page); } - if (keycode == 38) { core.playSound('光标移动'); core.ui.drawBook(core.status.event.data - 1); } - if (keycode == 39) { core.playSound('光标移动'); core.ui.drawBook(core.status.event.data + pageinfo.per_page); } - if (keycode == 40) { core.playSound('光标移动'); core.ui.drawBook(core.status.event.data + 1); } - if (keycode == 33) { core.playSound('光标移动'); core.ui.drawBook(core.status.event.data - pageinfo.per_page); } - if (keycode == 34) { core.playSound('光标移动'); core.ui.drawBook(core.status.event.data + pageinfo.per_page); } - return; -} - -////// 怪物手册界面时,放开某个键的操作 ////// -actions.prototype._keyUpBook = function (keycode) { - if (keycode == 27 || keycode == 88) { - core.playSound('取消'); - if (core.events.recoverEvents(core.status.event.interval)) { - return; - } - else if (core.status.event.ui != null) { - core.status.boxAnimateObjs = []; - core.ui._drawViewMaps(core.status.event.ui); - } - else core.ui.closePanel(); - return; - } - if (keycode == 13 || keycode == 32 || keycode == 67) { - var data = core.status.event.data; - if (data != null) { - core.ui._drawBookDetail(data); - } - return; - } -} - -////// 怪物手册属性显示界面时的点击操作 ////// -actions.prototype._clickBookDetail = function () { - core.clearMap('data'); - core.playSound('取消'); - core.status.event.id = 'book'; -} +}; ////// 楼层传送器界面时的点击操作 ////// actions.prototype._clickFly = function (x, y) { - if ((x == core._WIDTH_ - 2 || x == core._WIDTH_ - 3) && y == this._HY_ + 3) { core.playSound('光标移动'); core.ui.drawFly(this._getNextFlyFloor(-1)); } - if ((x == core._WIDTH_ - 2 || x == core._WIDTH_ - 3) && y == this._HY_ - 1) { core.playSound('光标移动'); core.ui.drawFly(this._getNextFlyFloor(1)); } - if ((x == core._WIDTH_ - 2 || x == core._WIDTH_ - 3) && y == this._HY_ + 4) { core.playSound('光标移动'); core.ui.drawFly(this._getNextFlyFloor(-10)); } - if ((x == core._WIDTH_ - 2 || x == core._WIDTH_ - 3) && y == this._HY_ - 2) { core.playSound('光标移动'); core.ui.drawFly(this._getNextFlyFloor(10)); } - if (x >= this._HX_ - 1 && x <= this._HX_ + 1 && y===core._HEIGHT_-1) { core.playSound('取消'); core.ui.closePanel(); } - if (x >= 0 && x <= this._HX_ + 3 && y >= 3 && y <= core._HEIGHT_-1 - 1) + if ( + (x == core._WIDTH_ - 2 || x == core._WIDTH_ - 3) && + y == this._HY_ + 3 + ) { + core.playSound('光标移动'); + core.ui.drawFly(this._getNextFlyFloor(-1)); + } + if ( + (x == core._WIDTH_ - 2 || x == core._WIDTH_ - 3) && + y == this._HY_ - 1 + ) { + core.playSound('光标移动'); + core.ui.drawFly(this._getNextFlyFloor(1)); + } + if ( + (x == core._WIDTH_ - 2 || x == core._WIDTH_ - 3) && + y == this._HY_ + 4 + ) { + core.playSound('光标移动'); + core.ui.drawFly(this._getNextFlyFloor(-10)); + } + if ( + (x == core._WIDTH_ - 2 || x == core._WIDTH_ - 3) && + y == this._HY_ - 2 + ) { + core.playSound('光标移动'); + core.ui.drawFly(this._getNextFlyFloor(10)); + } + if (x >= this._HX_ - 1 && x <= this._HX_ + 1 && y === core._HEIGHT_ - 1) { + core.playSound('取消'); + core.ui.closePanel(); + } + if (x >= 0 && x <= this._HX_ + 3 && y >= 3 && y <= core._HEIGHT_ - 1 - 1) core.flyTo(core.floorIds[core.status.event.data]); return; -} +}; ////// 楼层传送器界面时,按下某个键的操作 ////// actions.prototype._keyDownFly = function (keycode) { - if (keycode == 37) { core.playSound('光标移动'); core.ui.drawFly(this._getNextFlyFloor(-10)); } - else if (keycode == 38) { core.playSound('光标移动'); core.ui.drawFly(this._getNextFlyFloor(1)); } - else if (keycode == 39) { core.playSound('光标移动'); core.ui.drawFly(this._getNextFlyFloor(10)); } - else if (keycode == 40) { core.playSound('光标移动'); core.ui.drawFly(this._getNextFlyFloor(-1)); } + if (keycode == 37) { + core.playSound('光标移动'); + core.ui.drawFly(this._getNextFlyFloor(-10)); + } else if (keycode == 38) { + core.playSound('光标移动'); + core.ui.drawFly(this._getNextFlyFloor(1)); + } else if (keycode == 39) { + core.playSound('光标移动'); + core.ui.drawFly(this._getNextFlyFloor(10)); + } else if (keycode == 40) { + core.playSound('光标移动'); + core.ui.drawFly(this._getNextFlyFloor(-1)); + } return; -} +}; actions.prototype._getNextFlyFloor = function (delta, index) { if (index == null) index = core.status.event.data; @@ -1312,14 +1543,17 @@ actions.prototype._getNextFlyFloor = function (delta, index) { index += sign; if (index < 0 || index >= core.floorIds.length) break; var floorId = core.floorIds[index]; - if (core.status.maps[floorId].canFlyTo && core.hasVisitedFloor(floorId)) { + if ( + core.status.maps[floorId].canFlyTo && + core.hasVisitedFloor(floorId) + ) { delta--; ans = index; } if (delta == 0) break; } return ans; -} +}; ////// 楼层传送器界面时,放开某个键的操作 ////// actions.prototype._keyUpFly = function (keycode) { @@ -1330,7 +1564,7 @@ actions.prototype._keyUpFly = function (keycode) { if (keycode == 13 || keycode == 32 || keycode == 67) this._clickFly(this._HX_ - 1, this._HY_ - 1); return; -} +}; ////// 查看地图界面时的点击操作 ////// actions.prototype._clickViewMaps = function (x, y, px, py) { @@ -1340,9 +1574,14 @@ actions.prototype._clickViewMaps = function (x, y, px, py) { } var now = core.floorIds.indexOf(core.status.floorId); var index = core.status.event.data.index; - var cx = core.status.event.data.x, cy = core.status.event.data.y; - var floorId = core.floorIds[index], mh = core.floors[floorId].height; - var perpx = core._PX_ / 5, cornerpx = perpx * 3 / 4, perpy = core._PY_ / 5, cornerpy = perpy * 3 / 4; + var cx = core.status.event.data.x, + cy = core.status.event.data.y; + var floorId = core.floorIds[index], + mh = core.floors[floorId].height; + var perpx = core._PX_ / 5, + cornerpx = (perpx * 3) / 4, + perpy = core._PY_ / 5, + cornerpy = (perpy * 3) / 4; if (px <= cornerpx && py <= cornerpy) { core.status.event.data.damage = !core.status.event.data.damage; @@ -1364,12 +1603,24 @@ actions.prototype._clickViewMaps = function (x, y, px, py) { return; } - if (px >= perpx && px <= core._PX_ - perpx && py <= perpy && (!core.status.event.data.all && mh > core._HEIGHT_)) { + if ( + px >= perpx && + px <= core._PX_ - perpx && + py <= perpy && + !core.status.event.data.all && + mh > core._HEIGHT_ + ) { core.playSound('光标移动'); core.ui._drawViewMaps(index, cx, cy - 1); return; } - if (px >= perpx && px <= core._PX_ - perpx && py >= core._PY_ - perpy && (!core.status.event.data.all && mh > core._HEIGHT_)) { + if ( + px >= perpx && + px <= core._PX_ - perpx && + py >= core._PY_ - perpy && + !core.status.event.data.all && + mh > core._HEIGHT_ + ) { core.playSound('光标移动'); core.ui._drawViewMaps(index, cx, cy + 1); return; @@ -1385,46 +1636,89 @@ actions.prototype._clickViewMaps = function (x, y, px, py) { return; } - if (py <= 2 * perpy && (mh == core._HEIGHT_ || (px >= perpx && px <= core._PX_ - perpx))) { + if ( + py <= 2 * perpy && + (mh == core._HEIGHT_ || (px >= perpx && px <= core._PX_ - perpx)) + ) { core.playSound('光标移动'); index++; - while (index < core.floorIds.length && index != now && core.status.maps[core.floorIds[index]].cannotViewMap) + while ( + index < core.floorIds.length && + index != now && + core.status.maps[core.floorIds[index]].cannotViewMap + ) index++; - if (index < core.floorIds.length) - core.ui._drawViewMaps(index); + if (index < core.floorIds.length) core.ui._drawViewMaps(index); return; } - if (py >= 3 * perpy && (mh == core._HEIGHT_ || (px >= perpx && px <= core._PX_ - perpx))) { + if ( + py >= 3 * perpy && + (mh == core._HEIGHT_ || (px >= perpx && px <= core._PX_ - perpx)) + ) { core.playSound('光标移动'); index--; - while (index >= 0 && index != now && core.status.maps[core.floorIds[index]].cannotViewMap) + while ( + index >= 0 && + index != now && + core.status.maps[core.floorIds[index]].cannotViewMap + ) index--; - if (index >= 0) - core.ui._drawViewMaps(index); + if (index >= 0) core.ui._drawViewMaps(index); return; } - if (px >= perpx && px <= core._PX_ - perpx && py >= perpy * 2 && py <= perpy * 3) { + if ( + px >= perpx && + px <= core._PX_ - perpx && + py >= perpy * 2 && + py <= perpy * 3 + ) { core.clearMap('data'); core.playSound('取消'); core.ui.closePanel(); return; } -} +}; ////// 查看地图界面时,按下某个键的操作 ////// actions.prototype._keyDownViewMaps = function (keycode) { if (core.status.event.data == null) return; - var floorId = core.floorIds[core.status.event.data.index], mh = core.floors[floorId].height; + var floorId = core.floorIds[core.status.event.data.index], + mh = core.floors[floorId].height; - if (keycode == 38 || keycode == 33) this._clickViewMaps(this._HX_ , this._HY_ - 3 , core._PX_ / 2, core._PY_ / 5 * 1.5); - if (keycode == 40 || keycode == 34) this._clickViewMaps(this._HX_ , this._HY_ + 3 , core._PX_ / 2, core._PY_ / 5 * 3.5); - if (keycode == 87 && mh > core._HEIGHT_) this._clickViewMaps(this._HX_ , 0 , core._PX_ / 2, 1 ); - if (keycode == 65) this._clickViewMaps(0 , this._HY_ , 1 , core._PY_ / 2 ); - if (keycode == 83 && mh > core._HEIGHT_) this._clickViewMaps(this._HX_ , core._HEIGHT_ - 1, core._PX_ / 2, core._PY_ - 1 ); - if (keycode == 68) this._clickViewMaps(core._WIDTH_ - 1, this._HY_ , core._PX_ , core._PY_ / 2 - 1 ); + if (keycode == 38 || keycode == 33) + this._clickViewMaps( + this._HX_, + this._HY_ - 3, + core._PX_ / 2, + (core._PY_ / 5) * 1.5 + ); + if (keycode == 40 || keycode == 34) + this._clickViewMaps( + this._HX_, + this._HY_ + 3, + core._PX_ / 2, + (core._PY_ / 5) * 3.5 + ); + if (keycode == 87 && mh > core._HEIGHT_) + this._clickViewMaps(this._HX_, 0, core._PX_ / 2, 1); + if (keycode == 65) this._clickViewMaps(0, this._HY_, 1, core._PY_ / 2); + if (keycode == 83 && mh > core._HEIGHT_) + this._clickViewMaps( + this._HX_, + core._HEIGHT_ - 1, + core._PX_ / 2, + core._PY_ - 1 + ); + if (keycode == 68) + this._clickViewMaps( + core._WIDTH_ - 1, + this._HY_, + core._PX_, + core._PY_ / 2 - 1 + ); return; -} +}; ////// 查看地图界面时,放开某个键的操作 ////// actions.prototype._keyUpViewMaps = function (keycode) { @@ -1434,7 +1728,12 @@ actions.prototype._keyUpViewMaps = function (keycode) { } var floorId = core.floorIds[core.status.event.data.index]; - if (keycode == 27 || keycode == 13 || keycode == 32 || (!core.isReplaying() && keycode == 67)) { + if ( + keycode == 27 || + keycode == 13 || + keycode == 32 || + (!core.isReplaying() && keycode == 67) + ) { core.clearMap('data'); core.playSound('取消'); core.ui.closePanel(); @@ -1472,35 +1771,38 @@ actions.prototype._keyUpViewMaps = function (keycode) { return; } return; -} +}; ////// 快捷商店界面时的点击操作 ////// actions.prototype._clickQuickShop = function (x, y) { var shopIds = core.listShopIds(); if (this._out(x)) return; - var topIndex = this._HY_ - parseInt(shopIds.length / 2) + (core.status.event.ui.offset || 0); - if (y >= topIndex && y < topIndex + shopIds.length) { - var shopId = shopIds[y - topIndex]; - if (!core.canOpenShop(shopId)) { - core.playSound('操作失败'); - core.drawTip('当前项尚未开启'); - return; - } - var message = core.canUseQuickShop(shopId); - if (message == null) { - // core.ui.closePanel(); - core.openShop(shopIds[y - topIndex], false); - } else { - core.playSound('操作失败'); - core.drawTip(message); - } + var topIndex = + this._HY_ - + parseInt(shopIds.length / 2) + + (core.status.event.ui.offset || 0); + if (y >= topIndex && y < topIndex + shopIds.length) { + var shopId = shopIds[y - topIndex]; + if (!core.canOpenShop(shopId)) { + core.playSound('操作失败'); + core.drawTip('当前项尚未开启'); + return; } - // 离开 - else if (y == topIndex + shopIds.length) { - core.playSound('取消'); - core.ui.closePanel(); + var message = core.canUseQuickShop(shopId); + if (message == null) { + // core.ui.closePanel(); + core.openShop(shopIds[y - topIndex], false); + } else { + core.playSound('操作失败'); + core.drawTip(message); } -} + } + // 离开 + else if (y == topIndex + shopIds.length) { + core.playSound('取消'); + core.ui.closePanel(); + } +}; ////// 快捷商店界面时,放开某个键的操作 ////// actions.prototype._keyUpQuickShop = function (keycode) { @@ -1509,9 +1811,13 @@ actions.prototype._keyUpQuickShop = function (keycode) { core.ui.closePanel(); return; } - this._selectChoices(core.listShopIds().length + 1, keycode, this._clickQuickShop); + this._selectChoices( + core.listShopIds().length + 1, + keycode, + this._clickQuickShop + ); return; -} +}; ////// 工具栏界面时的点击操作 ////// actions.prototype._clickToolbox = function (x, y) { @@ -1521,13 +1827,11 @@ actions.prototype._clickToolbox = function (x, y) { // 装备栏 if (x >= this.LAST - 2 && y == 0) { core.ui.closePanel(); - if (core.isReplaying()) - core.control._replay_equipbox(); - else - core.openEquipbox(); + if (core.isReplaying()) core.control._replay_equipbox(); + else core.openEquipbox(); return; } - if (x >= this.LAST - 2 && y===core._HEIGHT_-1) { + if (x >= this.LAST - 2 && y === core._HEIGHT_ - 1) { core.playSound('取消'); core.ui.closePanel(); var last = core.status.route[core.status.route.length - 1] || ''; @@ -1542,12 +1846,12 @@ actions.prototype._clickToolbox = function (x, y) { var constantsPage = core.status.event.data.constantsPage; // 上一页 if (x == this._HX_ - 2 || x == this._HX_ - 3) { - if (y===core._HEIGHT_-1 - 5 && toolsPage > 1) { + if (y === core._HEIGHT_ - 1 - 5 && toolsPage > 1) { core.status.event.data.toolsPage--; core.playSound('光标移动'); core.ui._drawToolbox(core.status.event.selection); } - if (y===core._HEIGHT_-1 && constantsPage > 1) { + if (y === core._HEIGHT_ - 1 && constantsPage > 1) { core.status.event.data.constantsPage--; core.playSound('光标移动'); core.ui._drawToolbox(core.status.event.selection); @@ -1555,12 +1859,18 @@ actions.prototype._clickToolbox = function (x, y) { } // 下一页 if (x == this._HX_ + 2 || x == this._HX_ + 3) { - if (y===core._HEIGHT_-1 - 5 && toolsPage < Math.ceil(tools.length / this.LAST)) { + if ( + y === core._HEIGHT_ - 1 - 5 && + toolsPage < Math.ceil(tools.length / this.LAST) + ) { core.status.event.data.toolsPage++; core.playSound('光标移动'); core.ui._drawToolbox(core.status.event.selection); } - if (y===core._HEIGHT_-1 && constantsPage < Math.ceil(constants.length / this.LAST)) { + if ( + y === core._HEIGHT_ - 1 && + constantsPage < Math.ceil(constants.length / this.LAST) + ) { core.status.event.data.constantsPage++; core.playSound('光标移动'); core.ui._drawToolbox(core.status.event.selection); @@ -1568,14 +1878,13 @@ actions.prototype._clickToolbox = function (x, y) { } var index = parseInt(x / 2); - if (y===core._HEIGHT_-1 - 8) index += 0; - else if (y===core._HEIGHT_-1 - 6) index += this._HX_; - else if (y===core._HEIGHT_-1 - 3) index += this.LAST; - else if (y===core._HEIGHT_-1 - 1) index += this.LAST + this._HX_; + if (y === core._HEIGHT_ - 1 - 8) index += 0; + else if (y === core._HEIGHT_ - 1 - 6) index += this._HX_; + else if (y === core._HEIGHT_ - 1 - 3) index += this.LAST; + else if (y === core._HEIGHT_ - 1 - 1) index += this.LAST + this._HX_; else index = -1; - if (index >= 0) - this._clickToolboxIndex(index); -} + if (index >= 0) this._clickToolboxIndex(index); +}; ////// 选择工具栏界面中某个Index后的操作 ////// actions.prototype._clickToolboxIndex = function (index) { @@ -1587,9 +1896,10 @@ actions.prototype._clickToolboxIndex = function (index) { if (index < this.LAST) { select = index + this.LAST * (core.status.event.data.toolsPage - 1); items = tools; - } - else { - select = index % this.LAST + this.LAST * (core.status.event.data.constantsPage - 1); + } else { + select = + (index % this.LAST) + + this.LAST * (core.status.event.data.constantsPage - 1); items = constants; } if (items == null) return; @@ -1598,12 +1908,11 @@ actions.prototype._clickToolboxIndex = function (index) { if (itemId == core.status.event.data.selectId) { if (core.isReplaying()) return; core.events.tryUseItem(itemId); - } - else { + } else { core.playSound('光标移动'); core.ui._drawToolbox(index); } -} +}; ////// 工具栏界面时,按下某个键的操作 ////// actions.prototype._keyDownToolbox = function (keycode) { @@ -1618,67 +1927,78 @@ actions.prototype._keyDownToolbox = function (keycode) { var constantsPage = core.status.event.data.constantsPage; var toolsTotalPage = Math.ceil(tools.length / this.LAST); var constantsTotalPage = Math.ceil(constants.length / this.LAST); - var toolsLastIndex = toolsPage < toolsTotalPage ? last_index : (tools.length + last_index) % this.LAST; - var constantsLastIndex = this.LAST + (constantsPage < constantsTotalPage ? last_index : (constants.length + last_index) % this.LAST); + var toolsLastIndex = + toolsPage < toolsTotalPage + ? last_index + : (tools.length + last_index) % this.LAST; + var constantsLastIndex = + this.LAST + + (constantsPage < constantsTotalPage + ? last_index + : (constants.length + last_index) % this.LAST); - if (keycode == 37) { // left - if (index == 0) { // 处理向前翻页 + if (keycode == 37) { + // left + if (index == 0) { + // 处理向前翻页 if (toolsPage > 1) { core.status.event.data.toolsPage--; index = last_index; - } - else return; // 第一页不向前翻 - } - else if (index == this.LAST) { + } else return; // 第一页不向前翻 + } else if (index == this.LAST) { if (constantsPage == 1) { if (toolsTotalPage == 0) return; core.status.event.data.toolsPage = toolsTotalPage; index = (tools.length + last_index) % this.LAST; - } - else { + } else { core.status.event.data.constantsPage--; index = 2 * this.LAST - 1; } - } - else index -= 1; + } else index -= 1; this._clickToolboxIndex(index); return; } - if (keycode == 38) { // up - if (index >= this.LAST && index < this.LAST + this._HX_) { // 进入tools + if (keycode == 38) { + // up + if (index >= this.LAST && index < this.LAST + this._HX_) { + // 进入tools if (toolsTotalPage == 0) return; - if (toolsLastIndex >= this._HX_) index = Math.min(toolsLastIndex, index - this._HX_); + if (toolsLastIndex >= this._HX_) + index = Math.min(toolsLastIndex, index - this._HX_); else index = Math.min(toolsLastIndex, index - this.LAST); - } - else if (index < this._HX_) return; // 第一行没有向上 + } else if (index < this._HX_) return; // 第一行没有向上 else index -= this._HX_; this._clickToolboxIndex(index); return; } - if (keycode == 39) { // right + if (keycode == 39) { + // right if (toolsPage < toolsTotalPage && index == last_index) { core.status.event.data.toolsPage++; index = 0; - } - else if (constantsPage < constantsTotalPage && index == 2 * this.LAST - 1) { + } else if ( + constantsPage < constantsTotalPage && + index == 2 * this.LAST - 1 + ) { core.status.event.data.constantsPage++; index = this.LAST; - } - else if (index == toolsLastIndex) { + } else if (index == toolsLastIndex) { if (constantsTotalPage == 0) return; core.status.event.data.constantsPage = 1; index = this.LAST; - } - else if (index == constantsLastIndex) // 一个物品无操作 + } else if (index == constantsLastIndex) + // 一个物品无操作 return; else index++; this._clickToolboxIndex(index); return; } - if (keycode == 40) { // down + if (keycode == 40) { + // down var nextIndex = null; if (index < this._HX_) { - if (toolsLastIndex >= this._HX_) nextIndex = Math.min(toolsLastIndex, index + this._HX_); + if (toolsLastIndex >= this._HX_) + nextIndex = Math.min(toolsLastIndex, index + this._HX_); else index += this._HX_; } if (nextIndex == null && index < this.LAST) { @@ -1694,17 +2014,15 @@ actions.prototype._keyDownToolbox = function (keycode) { } return; } -} +}; ////// 工具栏界面时,放开某个键的操作 ////// actions.prototype._keyUpToolbox = function (keycode) { if (keycode == 81) { core.playSound('确定'); core.ui.closePanel(); - if (core.isReplaying()) - core.control._replay_equipbox(); - else - core.openEquipbox(); + if (core.isReplaying()) core.control._replay_equipbox(); + else core.openEquipbox(); return; } if (keycode == 84 || keycode == 27 || keycode == 88) { @@ -1723,20 +2041,18 @@ actions.prototype._keyUpToolbox = function (keycode) { this._clickToolboxIndex(core.status.event.selection); return; } -} +}; ////// 装备栏界面时的点击操作 ////// actions.prototype._clickEquipbox = function (x, y, px, py) { if (x >= this.LAST - 2 && y == 0) { core.playSound('确定'); core.ui.closePanel(); - if (core.isReplaying()) - core.control._replay_toolbox(); - else - core.openToolbox(); + if (core.isReplaying()) core.control._replay_toolbox(); + else core.openToolbox(); return; } - if (x >= this.LAST - 2 && y===core._HEIGHT_-1) { + if (x >= this.LAST - 2 && y === core._HEIGHT_ - 1) { core.playSound('取消'); core.ui.closePanel(); var last = core.status.route[core.status.route.length - 1] || ''; @@ -1746,7 +2062,7 @@ actions.prototype._clickEquipbox = function (x, y, px, py) { core.checkAutoEvents(); return; } - if ((x == this._HX_ - 2 || x == this._HX_ - 3) && y===core._HEIGHT_-1) { + if ((x == this._HX_ - 2 || x == this._HX_ - 3) && y === core._HEIGHT_ - 1) { if (core.status.event.data.page > 1) { core.status.event.data.page--; core.playSound('光标移动'); @@ -1754,8 +2070,10 @@ actions.prototype._clickEquipbox = function (x, y, px, py) { } return; } - if ((x == this._HX_ + 2 || x == this._HX_ + 3) && y===core._HEIGHT_-1) { - var lastPage = Math.ceil(core.getToolboxItems('equips').length / this.LAST); + if ((x == this._HX_ + 2 || x == this._HX_ + 3) && y === core._HEIGHT_ - 1) { + var lastPage = Math.ceil( + core.getToolboxItems('equips').length / this.LAST + ); if (core.status.event.data.page < lastPage) { core.status.event.data.page++; core.playSound('光标移动'); @@ -1763,38 +2081,54 @@ actions.prototype._clickEquipbox = function (x, y, px, py) { } return; } - var per_page = this._HX_ - 3, v = core._WIDTH_ / per_page; + var per_page = this._HX_ - 3, + v = core._WIDTH_ / per_page; if (y === core._HEIGHT_ - 9) { - for (var i = 0; i < per_page; ++i) if (x >= i * v && x <= (i + 1) * v) return this._clickEquipboxIndex(i); + for (var i = 0; i < per_page; ++i) + if (x >= i * v && x <= (i + 1) * v) + return this._clickEquipboxIndex(i); } else if (y === core._HEIGHT_ - 7) { - for (var i = 0; i < per_page; ++i) if (x >= i * v && x <= (i + 1) * v) return this._clickEquipboxIndex(per_page + i); + for (var i = 0; i < per_page; ++i) + if (x >= i * v && x <= (i + 1) * v) + return this._clickEquipboxIndex(per_page + i); } else if (Math.abs(core._HEIGHT_ - 5 - py / 32) < 0.5) { - for (var i = 0; i < per_page; ++i) if (x >= i * v && x <= (i + 1) * v) return this._clickEquipboxIndex(2 * per_page + i); - } else if (y === core._HEIGHT_ - 4) this._clickEquipboxIndex(this.LAST + parseInt(x / 2)) - else if (y === core._HEIGHT_ - 2) this._clickEquipboxIndex(this.LAST + this._HX_ + parseInt(x / 2)); -} + for (var i = 0; i < per_page; ++i) + if (x >= i * v && x <= (i + 1) * v) + return this._clickEquipboxIndex(2 * per_page + i); + } else if (y === core._HEIGHT_ - 4) + this._clickEquipboxIndex(this.LAST + parseInt(x / 2)); + else if (y === core._HEIGHT_ - 2) + this._clickEquipboxIndex(this.LAST + this._HX_ + parseInt(x / 2)); +}; ////// 选择装备栏界面中某个Index后的操作 ////// actions.prototype._clickEquipboxIndex = function (index) { if (index < this.LAST) { if (index >= core.status.globalAttribute.equipName.length) return; - if (index == core.status.event.selection && core.status.hero.equipment[index]) { + if ( + index == core.status.event.selection && + core.status.hero.equipment[index] + ) { if (core.isReplaying()) return; core.unloadEquip(index); - core.status.route.push("unEquip:" + index); + core.status.route.push('unEquip:' + index); } else core.playSound('光标移动'); - } - else { + } else { var equips = core.getToolboxItems('equips'); if (index == core.status.event.selection) { if (core.isReplaying()) return; - var equipId = equips[index - this.LAST + (core.status.event.data.page - 1) * this.LAST]; + var equipId = + equips[ + index - + this.LAST + + (core.status.event.data.page - 1) * this.LAST + ]; core.loadEquip(equipId); - core.status.route.push("equip:" + equipId); + core.status.route.push('equip:' + equipId); } else core.playSound('光标移动'); } core.ui._drawEquipbox(index); -} +}; ////// 装备栏界面时,按下某个键的操作 ////// actions.prototype._keyDownEquipbox = function (keycode) { @@ -1807,71 +2141,75 @@ actions.prototype._keyDownEquipbox = function (keycode) { var index = core.status.event.selection; var page = core.status.event.data.page; var totalPage = Math.ceil(ownEquipment.length / this.LAST); - var totalLastIndex = this.LAST + (page < totalPage ? last_index : (ownEquipment.length + last_index) % this.LAST); + var totalLastIndex = + this.LAST + + (page < totalPage + ? last_index + : (ownEquipment.length + last_index) % this.LAST); - if (keycode == 37) { // left + if (keycode == 37) { + // left if (index == 0) return; if (index == this.LAST) { if (page > 1) { core.status.event.data.page--; core.playSound('光标移动'); index = this.LAST + last_index; - } - else if (page == 1) - index = equipCapacity - 1; + } else if (page == 1) index = equipCapacity - 1; else return; - } - else index -= 1; + } else index -= 1; this._clickEquipboxIndex(index); return; } - if (keycode == 38) { // up + if (keycode == 38) { + // up if (index < per_line) return; else if (index < 2 * per_line) index -= per_line; else if (index < this.LAST + this._HX_) { index = parseInt((index - this.LAST) / 2); - if (equipCapacity > per_line) index = Math.min(equipCapacity - 1, index + per_line); + if (equipCapacity > per_line) + index = Math.min(equipCapacity - 1, index + per_line); else index = Math.min(equipCapacity - 1, index); - } - else index -= this._HX_; + } else index -= this._HX_; this._clickEquipboxIndex(index); return; } - if (keycode == 39) { // right + if (keycode == 39) { + // right if (page < totalPage && index == this.LAST + last_index) { core.status.event.data.page++; core.playSound('光标移动'); index = this.LAST; - } - else if (index == equipCapacity - 1) { + } else if (index == equipCapacity - 1) { if (totalPage == 0) return; index = this.LAST; - } - else if (index == totalLastIndex) - return; + } else if (index == totalLastIndex) return; else index++; this._clickEquipboxIndex(index); return; } - if (keycode == 40) { // down + if (keycode == 40) { + // down if (index < per_line) { - if (equipCapacity > per_line) index = Math.min(index + per_line, equipCapacity - 1); + if (equipCapacity > per_line) + index = Math.min(index + per_line, equipCapacity - 1); else { if (totalPage == 0) return; index = Math.min(2 * index + 1 + this.LAST, totalLastIndex); } - } - else if (index < 2 * per_line) { + } else if (index < 2 * per_line) { if (totalPage == 0) return; - index = Math.min(2 * (index - per_line) + 1 + this.LAST, totalLastIndex); - } - else if (index < this.LAST + this._HX_) + index = Math.min( + 2 * (index - per_line) + 1 + this.LAST, + totalLastIndex + ); + } else if (index < this.LAST + this._HX_) index = Math.min(index + this._HX_, totalLastIndex); else return; this._clickEquipboxIndex(index); return; } -} +}; ////// 装备栏界面时,放开某个键的操作 ////// actions.prototype._keyUpEquipbox = function (keycode, altKey) { @@ -1882,10 +2220,8 @@ actions.prototype._keyUpEquipbox = function (keycode, altKey) { if (keycode == 84) { core.playSound('确定'); core.ui.closePanel(); - if (core.isReplaying()) - core.control._replay_toolbox(); - else - core.openToolbox(); + if (core.isReplaying()) core.control._replay_toolbox(); + else core.openToolbox(); return; } if (keycode == 81 || keycode == 27 || keycode == 88) { @@ -1904,44 +2240,44 @@ actions.prototype._keyUpEquipbox = function (keycode, altKey) { this._clickEquipboxIndex(core.status.event.selection); return; } -} +}; ////// 存读档界面时的点击操作 ////// actions.prototype._clickSL = function (x, y) { - var page = core.status.event.data.page, offset = core.status.event.data.offset; + var page = core.status.event.data.page, + offset = core.status.event.data.offset; var index = page * 10 + offset; // 上一页 - if ((x == this._HX_ - 2 || x == this._HX_ - 3) && y===core._HEIGHT_-1) { + if ((x == this._HX_ - 2 || x == this._HX_ - 3) && y === core._HEIGHT_ - 1) { core.playSound('光标移动'); core.ui._drawSLPanel(10 * (page - 1) + offset); return; } // 下一页 - if ((x == this._HX_ + 2 || x == this._HX_ + 3) && y===core._HEIGHT_-1) { + if ((x == this._HX_ + 2 || x == this._HX_ + 3) && y === core._HEIGHT_ - 1) { core.playSound('光标移动'); core.ui._drawSLPanel(10 * (page + 1) + offset); return; } // 返回 - if (x >= this.LAST - 2 && y===core._HEIGHT_-1) { + if (x >= this.LAST - 2 && y === core._HEIGHT_ - 1) { core.playSound('取消'); - if (core.events.recoverEvents(core.status.event.interval)) - return; + if (core.events.recoverEvents(core.status.event.interval)) return; core.ui.closePanel(); delete core.status.tempRoute; - if (!core.isPlaying()) - core.showStartAnimate(true); + if (!core.isPlaying()) core.showStartAnimate(true); return; } // 删除 - if (x >= 0 && x <= 2 && y===core._HEIGHT_-1) { + if (x >= 0 && x <= 2 && y === core._HEIGHT_ - 1) { if (core.status.event.id == 'save') { core.status.event.selection = !core.status.event.selection; core.ui._drawSLPanel(index); - } - else { // 显示收藏 - core.status.event.data.mode = core.status.event.data.mode == 'all' ? 'fav' : 'all'; + } else { + // 显示收藏 + core.status.event.data.mode = + core.status.event.data.mode == 'all' ? 'fav' : 'all'; if (core.status.event.data.mode == 'fav') core.ui._drawSLPanel(1, true); else { @@ -1953,8 +2289,10 @@ actions.prototype._clickSL = function (x, y) { return; } // 点存档名 - var xLeft = parseInt(core._WIDTH_ / 3), xRight = parseInt(core._WIDTH_ * 2 / 3); - var topY1 = 0, topY2 = this._HY_; + var xLeft = parseInt(core._WIDTH_ / 3), + xRight = parseInt((core._WIDTH_ * 2) / 3); + var topY1 = 0, + topY2 = this._HY_; if (y >= topY1 && y <= topY1 + 1) { if (x >= xLeft && x < xRight) return this._clickSL_favorite(page, 1); if (x >= xRight) return this._clickSL_favorite(page, 2); @@ -1967,7 +2305,7 @@ actions.prototype._clickSL = function (x, y) { var id = null; if (y >= topY1 + 2 && y < this._HY_ - 1) { - if (x < xLeft) id = "autoSave"; + if (x < xLeft) id = 'autoSave'; if (x >= xLeft && x < xRight) id = 5 * page + 1; if (x >= xRight) id = 5 * page + 2; } @@ -1980,117 +2318,131 @@ actions.prototype._clickSL = function (x, y) { if (core.status.event.selection) { if (id == 'autoSave') { core.playSound('操作失败'); - core.drawTip("无法删除自动存档!"); + core.drawTip('无法删除自动存档!'); } else { core.removeSave(id, function () { core.ui._drawSLPanel(index, true); }); } - } - else { + } else { if (core.status.event.data.mode == 'fav' && id != 'autoSave') id = core.saves.favorite[id - 1]; core.doSL(id, core.status.event.id); } } -} +}; actions.prototype._clickSL_favorite = function (page, offset) { if (offset == 0) return; var index = 5 * page + offset; - if (core.status.event.data.mode == 'fav') { // 收藏模式下点击的下标直接对应favorite + if (core.status.event.data.mode == 'fav') { + // 收藏模式下点击的下标直接对应favorite index = core.saves.favorite[index - 1]; - core.myprompt("请输入想要显示的存档名(长度不超过5字符)", null, function (value) { - if (value && value.length <= 5) { - core.saves.favoriteName[index] = value; - core.control._updateFavoriteSaves(); - core.ui._drawSLPanel(10 * page + offset); - } else if (value) { - alert("无效的输入!"); + core.myprompt( + '请输入想要显示的存档名(长度不超过5字符)', + null, + function (value) { + if (value && value.length <= 5) { + core.saves.favoriteName[index] = value; + core.control._updateFavoriteSaves(); + core.ui._drawSLPanel(10 * page + offset); + } else if (value) { + alert('无效的输入!'); + } } - }); + ); } else { var v = core.saves.favorite.indexOf(index); core.playSound('确定'); - if (v >= 0) { // 已经处于收藏状态:取消收藏 + if (v >= 0) { + // 已经处于收藏状态:取消收藏 core.saves.favorite.splice(v, 1); delete core.saves.favoriteName[index]; - } - else if (core.hasSave(index)) { // 存在存档则进行收藏 + } else if (core.hasSave(index)) { + // 存在存档则进行收藏 core.saves.favorite.push(index); - core.saves.favorite = core.saves.favorite.sort(function (a, b) { return a - b; }); // 保证有序 - core.drawTip("收藏成功!"); + core.saves.favorite = core.saves.favorite.sort(function (a, b) { + return a - b; + }); // 保证有序 + core.drawTip('收藏成功!'); } core.control._updateFavoriteSaves(); core.ui._drawSLPanel(10 * page + offset); } -} +}; ////// 存读档界面时,按下某个键的操作 ////// actions.prototype._keyDownSL = function (keycode) { - - var page = core.status.event.data.page, offset = core.status.event.data.offset; + var page = core.status.event.data.page, + offset = core.status.event.data.offset; var index = page * 10 + offset; - if (keycode == 37) { // left + if (keycode == 37) { + // left core.playSound('光标移动'); if (offset == 0) { core.ui._drawSLPanel(10 * (page - 1) + 5); - } - else { + } else { core.ui._drawSLPanel(index - 1); } return; } - if (keycode == 38) { // up + if (keycode == 38) { + // up core.playSound('光标移动'); if (offset < 3) { core.ui._drawSLPanel(10 * (page - 1) + offset + 3); - } - else { + } else { core.ui._drawSLPanel(index - 3); } return; } - if (keycode == 39) { // right + if (keycode == 39) { + // right core.playSound('光标移动'); if (offset == 5) { core.ui._drawSLPanel(10 * (page + 1) + 1); - } - else { + } else { core.ui._drawSLPanel(index + 1); } return; } - if (keycode == 40) { // down + if (keycode == 40) { + // down core.playSound('光标移动'); if (offset >= 3) { core.ui._drawSLPanel(10 * (page + 1) + offset - 3); - } - else { + } else { core.ui._drawSLPanel(index + 3); } return; } - if (keycode == 33) { // PAGEUP + if (keycode == 33) { + // PAGEUP core.playSound('光标移动'); core.ui._drawSLPanel(10 * (page - 1) + offset); return; } - if (keycode == 34) { // PAGEDOWN + if (keycode == 34) { + // PAGEDOWN core.playSound('光标移动'); core.ui._drawSLPanel(10 * (page + 1) + offset); return; } -} +}; ////// 存读档界面时,放开某个键的操作 ////// actions.prototype._keyUpSL = function (keycode) { - var page = core.status.event.data.page, offset = core.status.event.data.offset; + var page = core.status.event.data.page, + offset = core.status.event.data.offset; var index = page * 10 + offset; - if (keycode == 27 || keycode == 88 || (core.status.event.id == 'save' && keycode == 83) - || (core.status.event.id == 'load' && keycode == 68)) { + if ( + keycode == 27 || + keycode == 88 || + (core.status.event.id == 'save' && keycode == 83) || + (core.status.event.id == 'load' && keycode == 68) + ) { this._clickSL(core._WIDTH_ - 1, core._HEIGHT_ - 1); return; } @@ -2100,37 +2452,38 @@ actions.prototype._keyUpSL = function (keycode) { return; } if (keycode == 13 || keycode == 32 || keycode == 67) { - if (offset == 0) - core.doSL("autoSave", core.status.event.id); + if (offset == 0) core.doSL('autoSave', core.status.event.id); else { var id = 5 * page + offset; - if (core.status.event.data.mode == 'fav') id = core.saves.favorite[id - 1]; + if (core.status.event.data.mode == 'fav') + id = core.saves.favorite[id - 1]; core.doSL(id, core.status.event.id); } return; } - if (keycode == 69 && core.status.event.id != 'save') { // E 收藏切换 + if (keycode == 69 && core.status.event.id != 'save') { + // E 收藏切换 this._clickSL(0, core._HEIGHT_ - 1); return; } if (keycode == 46) { if (offset == 0) { core.playSound('操作失败'); - core.drawTip("无法删除自动存档!"); - } - else { + core.drawTip('无法删除自动存档!'); + } else { var id = 5 * page + offset; - if (core.status.event.data.mode == 'fav') id = core.saves.favorite[id - 1]; + if (core.status.event.data.mode == 'fav') + id = core.saves.favorite[id - 1]; core.removeSave(id, function () { core.ui._drawSLPanel(index, true); }); } } - if (keycode == 70 && core.status.event.data.mode == 'all') { // F + if (keycode == 70 && core.status.event.data.mode == 'all') { + // F this._clickSL_favorite(page, offset); } -} - +}; ////// 系统设置界面时的点击操作 ////// actions.prototype._clickSwitchs = function (x, y) { @@ -2159,7 +2512,7 @@ actions.prototype._clickSwitchs = function (x, y) { return core.ui._drawSettings(); } } -} +}; ////// 系统设置界面时,放开某个键的操作 ////// actions.prototype._keyUpSwitchs = function (keycode) { @@ -2169,8 +2522,12 @@ actions.prototype._keyUpSwitchs = function (keycode) { core.ui._drawSettings(); return; } - this._selectChoices(core.status.event.ui.choices.length, keycode, this._clickSwitchs); -} + this._selectChoices( + core.status.event.ui.choices.length, + keycode, + this._clickSwitchs + ); +}; actions.prototype._clickSwitchs_sounds = function (x, y) { var choices = core.status.event.ui.choices; @@ -2181,8 +2538,10 @@ actions.prototype._clickSwitchs_sounds = function (x, y) { } if (selection >= 0 && selection < choices.length) { var width = choices[selection].width; - var leftPos = (core._PX_ - width) / 2, rightPos = (core._PX_ + width) / 2; - var leftGrid = parseInt(leftPos / 32), rightGrid = parseInt(rightPos / 32) - 1; + var leftPos = (core._PX_ - width) / 2, + rightPos = (core._PX_ + width) / 2; + var leftGrid = parseInt(leftPos / 32), + rightGrid = parseInt(rightPos / 32) - 1; core.status.event.selection = selection; switch (selection) { case 0: @@ -2190,8 +2549,10 @@ actions.prototype._clickSwitchs_sounds = function (x, y) { case 1: return this._clickSwitchs_sounds_se(); case 2: - if (x == leftGrid || x == leftGrid + 1) return this._clickSwitchs_sounds_userVolume(-1); - if (x == rightGrid || x == rightGrid + 1) return this._clickSwitchs_sounds_userVolume(1); + if (x == leftGrid || x == leftGrid + 1) + return this._clickSwitchs_sounds_userVolume(-1); + if (x == rightGrid || x == rightGrid + 1) + return this._clickSwitchs_sounds_userVolume(1); return; case 3: core.status.event.selection = 0; @@ -2200,32 +2561,39 @@ actions.prototype._clickSwitchs_sounds = function (x, y) { return; } } -} +}; actions.prototype._clickSwitchs_sounds_bgm = function () { core.triggerBgm(); core.playSound('确定'); core.ui._drawSwitchs_sounds(); -} +}; actions.prototype._clickSwitchs_sounds_se = function () { core.musicStatus.soundStatus = !core.musicStatus.soundStatus; core.setLocalStorage('soundStatus', core.musicStatus.soundStatus); core.playSound('确定'); core.ui._drawSwitchs_sounds(); -} +}; actions.prototype._clickSwitchs_sounds_userVolume = function (delta) { var value = Math.round(Math.sqrt(100 * core.musicStatus.userVolume)); if (value == 0 && delta < 0) return; - core.musicStatus.userVolume = core.clamp(Math.pow(value + delta, 2) / 100, 0, 1); + core.musicStatus.userVolume = core.clamp( + Math.pow(value + delta, 2) / 100, + 0, + 1 + ); //audioContext 音效 不受designVolume 影响 - if (core.musicStatus.gainNode != null) core.musicStatus.gainNode.gain.value = core.musicStatus.userVolume; - if (core.musicStatus.playingBgm) core.material.bgms[core.musicStatus.playingBgm].volume = core.musicStatus.userVolume * core.musicStatus.designVolume; + if (core.musicStatus.gainNode != null) + core.musicStatus.gainNode.gain.value = core.musicStatus.userVolume; + if (core.musicStatus.playingBgm) + core.material.bgms[core.musicStatus.playingBgm].volume = + core.musicStatus.userVolume * core.musicStatus.designVolume; core.setLocalStorage('userVolume', core.musicStatus.userVolume); core.playSound('确定'); core.ui._drawSwitchs_sounds(); -} +}; actions.prototype._keyUpSwitchs_sounds = function (keycode) { if (keycode == 27 || keycode == 88) { @@ -2236,15 +2604,23 @@ actions.prototype._keyUpSwitchs_sounds = function (keycode) { } if (keycode == 37) { switch (core.status.event.selection) { - case 2: core.playSound('确定'); return this._clickSwitchs_sounds_userVolume(-1); + case 2: + core.playSound('确定'); + return this._clickSwitchs_sounds_userVolume(-1); } } else if (keycode == 39) { switch (core.status.event.selection) { - case 2: core.playSound('确定'); return this._clickSwitchs_sounds_userVolume(1); + case 2: + core.playSound('确定'); + return this._clickSwitchs_sounds_userVolume(1); } } - this._selectChoices(core.status.event.ui.choices.length, keycode, this._clickSwitchs_sounds); -} + this._selectChoices( + core.status.event.ui.choices.length, + keycode, + this._clickSwitchs_sounds + ); +}; actions.prototype._clickSwitchs_display = function (x, y) { var choices = core.status.event.ui.choices; @@ -2255,13 +2631,17 @@ actions.prototype._clickSwitchs_display = function (x, y) { } if (selection >= 0 && selection < choices.length) { var width = choices[selection].width; - var leftPos = (core._PX_ - width) / 2, rightPos = (core._PX_ + width) / 2; - var leftGrid = parseInt(leftPos / 32), rightGrid = parseInt(rightPos / 32) - 1; + var leftPos = (core._PX_ - width) / 2, + rightPos = (core._PX_ + width) / 2; + var leftGrid = parseInt(leftPos / 32), + rightGrid = parseInt(rightPos / 32) - 1; core.status.event.selection = selection; switch (selection) { case 0: - if (x == leftGrid || x == leftGrid + 1) return this._clickSwitchs_display_setSize(-1); - if (x == rightGrid || x == rightGrid + 1) return this._clickSwitchs_display_setSize(1); + if (x == leftGrid || x == leftGrid + 1) + return this._clickSwitchs_display_setSize(-1); + if (x == rightGrid || x == rightGrid + 1) + return this._clickSwitchs_display_setSize(1); return; case 1: core.playSound('确定'); @@ -2283,7 +2663,10 @@ actions.prototype._clickSwitchs_display = function (x, y) { return this._clickSwitchs_display_extraDamageType(); case 7: core.playSound('确定'); - core.setLocalStorage('autoScale', core.getLocalStorage('autoScale') ? false : true); + core.setLocalStorage( + 'autoScale', + core.getLocalStorage('autoScale') ? false : true + ); core.ui._drawSwitchs_display(); break; case 8: @@ -2293,57 +2676,60 @@ actions.prototype._clickSwitchs_display = function (x, y) { return; } } -} +}; actions.prototype._clickSwitchs_display_setSize = function (delta) { core.setDisplayScale(delta); - var currentRatio = Math.max(window.devicePixelRatio || 1, core.domStyle.scale); + var currentRatio = Math.max( + window.devicePixelRatio || 1, + core.domStyle.scale + ); if (currentRatio > core.domStyle.ratio) { - core.drawTip("需刷新页面以调整UI清晰度"); + core.drawTip('需刷新页面以调整UI清晰度'); } core.ui._drawSwitchs_display(); -} +}; actions.prototype._clickSwitchs_display_enableHDCanvas = function () { core.flags.enableHDCanvas = !core.flags.enableHDCanvas; core.setLocalStorage('enableHDCanvas', core.flags.enableHDCanvas); - core.drawTip("开关高清UI,需刷新页面方可生效"); + core.drawTip('开关高清UI,需刷新页面方可生效'); core.ui._drawSwitchs_display(); -} +}; actions.prototype._clickSwitchs_display_enableEnemyPoint = function () { core.flags.enableEnemyPoint = !core.flags.enableEnemyPoint; core.setLocalStorage('enableEnemyPoint', core.flags.enableEnemyPoint); core.ui._drawSwitchs_display(); -} +}; actions.prototype._clickSwitchs_display_enemyDamage = function () { core.flags.displayEnemyDamage = !core.flags.displayEnemyDamage; core.updateDamage(); core.setLocalStorage('enemyDamage', core.flags.displayEnemyDamage); core.ui._drawSwitchs_display(); -} +}; actions.prototype._clickSwitchs_display_critical = function () { core.flags.displayCritical = !core.flags.displayCritical; core.updateDamage(); core.setLocalStorage('critical', core.flags.displayCritical); core.ui._drawSwitchs_display(); -} +}; actions.prototype._clickSwitchs_display_extraDamage = function () { core.flags.displayExtraDamage = !core.flags.displayExtraDamage; core.updateDamage(); core.setLocalStorage('extraDamage', core.flags.displayExtraDamage); core.ui._drawSwitchs_display(); -} +}; actions.prototype._clickSwitchs_display_extraDamageType = function () { core.flags.extraDamageType = (core.flags.extraDamageType + 1) % 3; core.updateDamage(); core.setLocalStorage('extraDamageType', core.flags.extraDamageType); core.ui._drawSwitchs_display(); -} +}; actions.prototype._keyUpSwitchs_display = function (keycode) { if (keycode == 27 || keycode == 88) { @@ -2354,15 +2740,23 @@ actions.prototype._keyUpSwitchs_display = function (keycode) { } if (keycode == 37) { switch (core.status.event.selection) { - case 0: core.playSound('确定'); return this._clickSwitchs_display_setSize(-1); + case 0: + core.playSound('确定'); + return this._clickSwitchs_display_setSize(-1); } } else if (keycode == 39) { switch (core.status.event.selection) { - case 0: core.playSound('确定'); return this._clickSwitchs_display_setSize(1); + case 0: + core.playSound('确定'); + return this._clickSwitchs_display_setSize(1); } } - this._selectChoices(core.status.event.ui.choices.length, keycode, this._clickSwitchs_display); -} + this._selectChoices( + core.status.event.ui.choices.length, + keycode, + this._clickSwitchs_display + ); +}; actions.prototype._clickSwitchs_action = function (x, y) { var choices = core.status.event.ui.choices; @@ -2373,17 +2767,31 @@ actions.prototype._clickSwitchs_action = function (x, y) { } if (selection >= 0 && selection < choices.length) { var width = choices[selection].width; - var leftPos = (core._PX_ - width) / 2, rightPos = (core._PX_ + width) / 2; - var leftGrid = parseInt(leftPos / 32), rightGrid = parseInt(rightPos / 32) - 1; + var leftPos = (core._PX_ - width) / 2, + rightPos = (core._PX_ + width) / 2; + var leftGrid = parseInt(leftPos / 32), + rightGrid = parseInt(rightPos / 32) - 1; core.status.event.selection = selection; switch (selection) { case 0: - if (x == leftGrid || x == leftGrid + 1) { core.playSound('确定'); return this._clickSwitchs_action_moveSpeed(-10); } - if (x == rightGrid || x == rightGrid + 1) { core.playSound('确定'); return this._clickSwitchs_action_moveSpeed(10); } + if (x == leftGrid || x == leftGrid + 1) { + core.playSound('确定'); + return this._clickSwitchs_action_moveSpeed(-10); + } + if (x == rightGrid || x == rightGrid + 1) { + core.playSound('确定'); + return this._clickSwitchs_action_moveSpeed(10); + } return; case 1: - if (x == leftGrid || x == leftGrid + 1) { core.playSound('确定'); return this._clickSwitchs_action_floorChangeTime(-100); } - if (x == rightGrid || x == rightGrid + 1) { core.playSound('确定'); return this._clickSwitchs_action_floorChangeTime(100); } + if (x == leftGrid || x == leftGrid + 1) { + core.playSound('确定'); + return this._clickSwitchs_action_floorChangeTime(-100); + } + if (x == rightGrid || x == rightGrid + 1) { + core.playSound('确定'); + return this._clickSwitchs_action_floorChangeTime(100); + } case 2: core.playSound('确定'); return this._clickSwitchs_action_potionNoRouting(); @@ -2400,40 +2808,47 @@ actions.prototype._clickSwitchs_action = function (x, y) { return; } } -} +}; actions.prototype._clickSwitchs_action_moveSpeed = function (delta) { core.values.moveSpeed = core.clamp(core.values.moveSpeed + delta, 50, 200); - core.setLocalStorage("moveSpeed", core.values.moveSpeed); + core.setLocalStorage('moveSpeed', core.values.moveSpeed); core.ui._drawSwitchs_action(); -} +}; actions.prototype._clickSwitchs_action_floorChangeTime = function (delta) { - core.values.floorChangeTime = core.clamp(core.values.floorChangeTime + delta, 0, 2000); - core.setLocalStorage("floorChangeTime", core.values.floorChangeTime); + core.values.floorChangeTime = core.clamp( + core.values.floorChangeTime + delta, + 0, + 2000 + ); + core.setLocalStorage('floorChangeTime', core.values.floorChangeTime); core.ui._drawSwitchs_action(); -} +}; actions.prototype._clickSwitchs_action_potionNoRouting = function () { - if (core.hasFlag('__potionNoRouting__')) core.removeFlag('__potionNoRouting__'); + if (core.hasFlag('__potionNoRouting__')) + core.removeFlag('__potionNoRouting__'); else core.setFlag('__potionNoRouting__', true); core.ui._drawSwitchs_action(); -} +}; actions.prototype._clickSwitchs_action_clickMove = function () { if (core.hasFlag('__noClickMove__')) core.removeFlag('__noClickMove__'); else core.setFlag('__noClickMove__', true); core.ui._drawSwitchs_action(); -} +}; actions.prototype._clickSwitchs_action_leftHandPrefer = function () { core.flags.leftHandPrefer = !core.flags.leftHandPrefer; core.setLocalStorage('leftHandPrefer', core.flags.leftHandPrefer); if (core.flags.leftHandPrefer) { - core.myconfirm("左手模式已开启!\n此模式下WASD将用于移动勇士,IJKL对应于原始的WASD进行存读档等操作。") + core.myconfirm( + '左手模式已开启!\n此模式下WASD将用于移动勇士,IJKL对应于原始的WASD进行存读档等操作。' + ); } core.ui._drawSwitchs_action(); -} +}; actions.prototype._keyUpSwitchs_action = function (keycode) { if (keycode == 27 || keycode == 88) { @@ -2444,17 +2859,29 @@ actions.prototype._keyUpSwitchs_action = function (keycode) { } if (keycode == 37) { switch (core.status.event.selection) { - case 0: core.playSound('确定'); return this._clickSwitchs_action_moveSpeed(-10); - case 1: core.playSound('确定'); return this._clickSwitchs_action_floorChangeTime(-100); + case 0: + core.playSound('确定'); + return this._clickSwitchs_action_moveSpeed(-10); + case 1: + core.playSound('确定'); + return this._clickSwitchs_action_floorChangeTime(-100); } } else if (keycode == 39) { switch (core.status.event.selection) { - case 0: core.playSound('确定'); return this._clickSwitchs_action_moveSpeed(10); - case 1: core.playSound('确定'); return this._clickSwitchs_action_floorChangeTime(100); + case 0: + core.playSound('确定'); + return this._clickSwitchs_action_moveSpeed(10); + case 1: + core.playSound('确定'); + return this._clickSwitchs_action_floorChangeTime(100); } } - this._selectChoices(core.status.event.ui.choices.length, keycode, this._clickSwitchs_action); -} + this._selectChoices( + core.status.event.ui.choices.length, + keycode, + this._clickSwitchs_action + ); +}; ////// 系统菜单栏界面时的点击操作 ////// actions.prototype._clickSettings = function (x, y) { @@ -2503,7 +2930,7 @@ actions.prototype._clickSettings = function (x, y) { } } return; -} +}; ////// 系统菜单栏界面时,放开某个键的操作 ////// actions.prototype._keyUpSettings = function (keycode) { @@ -2512,8 +2939,12 @@ actions.prototype._keyUpSettings = function (keycode) { core.ui.closePanel(); return; } - this._selectChoices(core.status.event.ui.choices.length, keycode, this._clickSettings); -} + this._selectChoices( + core.status.event.ui.choices.length, + keycode, + this._clickSettings + ); +}; ////// 存档笔记页面时的点击操作 ////// actions.prototype._clickNotes = function (x, y) { @@ -2548,30 +2979,31 @@ actions.prototype._clickNotes = function (x, y) { break; } } -} +}; actions.prototype.__clickNotes_replaceText = function (data) { - data = (data || "").replace(/[\${}]/g, "_") - .replace(/(\t|\\t)\[.*?\]/g, "") - .replace("\b", "\\b") - .replace(/\\b\[.*?\]/g, "") - .replace(/\n|\\n/g, " "); - if (data.length > 45) data = data.substring(0, 43) + "..."; + data = (data || '') + .replace(/[\${}]/g, '_') + .replace(/(\t|\\t)\[.*?\]/g, '') + .replace('\b', '\\b') + .replace(/\\b\[.*?\]/g, '') + .replace(/\n|\\n/g, ' '); + if (data.length > 45) data = data.substring(0, 43) + '...'; return data; -} +}; actions.prototype._clickNotes_new = function () { core.status.hero.notes = core.status.hero.notes || []; - core.myprompt("请输入一段笔记,不超过45字", null, function (data) { + core.myprompt('请输入一段笔记,不超过45字', null, function (data) { data = core.actions.__clickNotes_replaceText(data); if (data) { core.status.hero.notes.push(data); - core.drawText("存档笔记新增成功!"); + core.drawText('存档笔记新增成功!'); } else { core.ui.closePanel(); } }); -} +}; actions.prototype._clickNotes_show = function () { core.playSound('确定'); @@ -2580,70 +3012,108 @@ actions.prototype._clickNotes_show = function () { for (var i = 0; i < core.status.hero.notes.length; i += 5) { var v = []; for (var j = i; j < i + 5 && j < core.status.hero.notes.length; ++j) { - v.push(j + 1 + ". " + this.__clickNotes_replaceText(core.status.hero.notes[j])); + v.push( + j + + 1 + + '. ' + + this.__clickNotes_replaceText(core.status.hero.notes[j]) + ); } - result.push("\t[存档笔记]" + v.join("\n")); + result.push('\t[存档笔记]' + v.join('\n')); } - if (result.length == 0) result.push("当前没有存档笔记,试着新增一个吧!\n(菜单栏 -> 存档笔记 -> 新增存档笔记)"); + if (result.length == 0) + result.push( + '当前没有存档笔记,试着新增一个吧!\n(菜单栏 -> 存档笔记 -> 新增存档笔记)' + ); core.drawText(result); -} +}; actions.prototype._clickNotes_edit = function () { core.status.hero.notes = core.status.hero.notes || []; if (core.status.hero.notes.length == 0) { - core.drawText("当前没有存档笔记,试着新增一个吧!"); + core.drawText('当前没有存档笔记,试着新增一个吧!'); } else { - core.myprompt("请输入要编辑的存档笔记编号(1 - " + core.status.hero.notes.length + ")", "1", function (data) { - if (!data) core.ui.closePanel(); - var value = parseInt(data) || 0; - if (!value || value <= 0 || value > core.status.hero.notes.length) { - core.drawText("不合法的输入!"); - } else { - core.myprompt("请输入新内容,不超过45字", core.status.hero.notes[value - 1], function (data) { - data = core.actions.__clickNotes_replaceText(data); - if (data) { - core.status.hero.notes[value - 1] = data; - core.drawText("存档笔记编辑成功!"); - } else { - core.ui.closePanel(); - } - }); + core.myprompt( + '请输入要编辑的存档笔记编号(1 - ' + + core.status.hero.notes.length + + ')', + '1', + function (data) { + if (!data) core.ui.closePanel(); + var value = parseInt(data) || 0; + if ( + !value || + value <= 0 || + value > core.status.hero.notes.length + ) { + core.drawText('不合法的输入!'); + } else { + core.myprompt( + '请输入新内容,不超过45字', + core.status.hero.notes[value - 1], + function (data) { + data = core.actions.__clickNotes_replaceText(data); + if (data) { + core.status.hero.notes[value - 1] = data; + core.drawText('存档笔记编辑成功!'); + } else { + core.ui.closePanel(); + } + } + ); + } } - }) + ); } -} +}; actions.prototype._clickNotes_delete = function () { core.status.hero.notes = core.status.hero.notes || []; if (core.status.hero.notes.length == 0) { core.stopSound(); core.playSound('操作失败'); - core.drawText("当前没有存档笔记,无法删除!"); + core.drawText('当前没有存档笔记,无法删除!'); } else { - core.myprompt("请输入要删除的所有存档笔记编号,以逗号分隔。不填则代表删除全部笔记。", null, function (data) { - if (data == null) { - core.ui.closePanel(); - return; - } - else if (!data) { - core.status.hero.notes = []; - core.drawText("所有存档笔记删除成功!"); - } else { - data = data.split(",").map(function (one) { return parseInt(one); }) - .filter(function (one) { return one && one > 0 && one <= core.status.hero.notes.length }); - if (data.length == 0) { - core.drawText("没有要删除的笔记!"); + core.myprompt( + '请输入要删除的所有存档笔记编号,以逗号分隔。不填则代表删除全部笔记。', + null, + function (data) { + if (data == null) { + core.ui.closePanel(); + return; + } else if (!data) { + core.status.hero.notes = []; + core.drawText('所有存档笔记删除成功!'); } else { - data.sort(function (a, b) { return b - a; }) - .forEach(function (index) { + data = data + .split(',') + .map(function (one) { + return parseInt(one); + }) + .filter(function (one) { + return ( + one && + one > 0 && + one <= core.status.hero.notes.length + ); + }); + if (data.length == 0) { + core.drawText('没有要删除的笔记!'); + } else { + data.sort(function (a, b) { + return b - a; + }).forEach(function (index) { core.status.hero.notes.splice(index - 1, 1); }); - core.drawText("已删除 " + data.sort().join(",") + " 号笔记"); + core.drawText( + '已删除 ' + data.sort().join(',') + ' 号笔记' + ); + } } } - }) + ); } -} +}; ////// 存档笔记页面时,放开某个键的操作 ////// actions.prototype._keyUpNotes = function (keycode) { @@ -2653,8 +3123,12 @@ actions.prototype._keyUpNotes = function (keycode) { core.ui._drawSettings(); return; } - this._selectChoices(core.status.event.ui.choices.length, keycode, this._clickNotes); -} + this._selectChoices( + core.status.event.ui.choices.length, + keycode, + this._clickNotes + ); +}; ////// 同步存档界面时的点击操作 ////// actions.prototype._clickSyncSave = function (x, y) { @@ -2695,24 +3169,29 @@ actions.prototype._clickSyncSave = function (x, y) { core.playSound('取消'); core.ui._drawSettings(); break; - } } return; -} +}; actions.prototype._clickSyncSave_readFile = function () { - core.readFile(function (obj) { - if (obj.name != core.firstData.name) return alert("存档和游戏不一致!"); - if (obj.version != core.firstData.version) return alert("游戏版本不一致!"); - if (!obj.data) return alert("无效的存档!"); - core.control._syncLoad_write(obj.data); - }, null, ".h5save"); -} + core.readFile( + function (obj) { + if (obj.name != core.firstData.name) + return alert('存档和游戏不一致!'); + if (obj.version != core.firstData.version) + return alert('游戏版本不一致!'); + if (!obj.data) return alert('无效的存档!'); + core.control._syncLoad_write(obj.data); + }, + null, + '.h5save' + ); +}; actions.prototype._clickSyncSave_replay = function () { core.ui._drawReplay(); -} +}; ////// 同步存档界面时,放开某个键的操作 ////// actions.prototype._keyUpSyncSave = function (keycode) { @@ -2722,8 +3201,12 @@ actions.prototype._keyUpSyncSave = function (keycode) { core.ui._drawSettings(); return; } - this._selectChoices(core.status.event.ui.choices.length, keycode, this._clickSyncSave); -} + this._selectChoices( + core.status.event.ui.choices.length, + keycode, + this._clickSyncSave + ); +}; ////// 同步存档选择界面时的点击操作 ////// actions.prototype._clickSyncSelect = function (x, y) { @@ -2737,9 +3220,12 @@ actions.prototype._clickSyncSelect = function (x, y) { switch (selection) { case 0: core.playSound('确定'); - core.myconfirm('你确定要同步全部存档么?\n这可能在存档较多的时候比较慢。', function () { - core.syncSave('all'); - }); + core.myconfirm( + '你确定要同步全部存档么?\n这可能在存档较多的时候比较慢。', + function () { + core.syncSave('all'); + } + ); break; case 1: core.playSound('确定'); @@ -2752,7 +3238,7 @@ actions.prototype._clickSyncSelect = function (x, y) { break; } } -} +}; ////// 同步存档选择界面时,放开某个键的操作 ////// actions.prototype._keyUpSyncSelect = function (keycode) { @@ -2762,8 +3248,12 @@ actions.prototype._keyUpSyncSelect = function (keycode) { core.ui._drawSyncSave(); return; } - this._selectChoices(core.status.event.ui.choices.length, keycode, this._clickSyncSelect); -} + this._selectChoices( + core.status.event.ui.choices.length, + keycode, + this._clickSyncSelect + ); +}; ////// 存档下载界面时的点击操作 ////// actions.prototype._clickLocalSaveSelect = function (x, y) { @@ -2779,12 +3269,17 @@ actions.prototype._clickLocalSaveSelect = function (x, y) { var callback = function (saves) { if (saves) { var content = { - "name": core.firstData.name, - "version": core.firstData.version, - "data": saves - } - core.download(core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5save", - LZString.compressToBase64(JSON.stringify(content))); + name: core.firstData.name, + version: core.firstData.version, + data: saves + }; + core.download( + core.firstData.name + + '_' + + core.formatDate2(new Date()) + + '.h5save', + LZString.compressToBase64(JSON.stringify(content)) + ); } }; if (selection == 0) core.getAllSaves(callback); @@ -2795,7 +3290,7 @@ actions.prototype._clickLocalSaveSelect = function (x, y) { core.playSound('取消'); core.ui._drawSyncSave(); } -} +}; ////// 存档下载界面时,放开某个键的操作 ////// actions.prototype._keyUpLocalSaveSelect = function (keycode) { @@ -2805,8 +3300,12 @@ actions.prototype._keyUpLocalSaveSelect = function (keycode) { core.ui._drawSyncSave(); return; } - this._selectChoices(core.status.event.ui.choices.length, keycode, this._clickLocalSaveSelect); -} + this._selectChoices( + core.status.event.ui.choices.length, + keycode, + this._clickLocalSaveSelect + ); +}; ////// 存档删除界面时的点击操作 ////// actions.prototype._clickStorageRemove = function (x, y) { @@ -2830,50 +3329,56 @@ actions.prototype._clickStorageRemove = function (x, y) { break; } } -} +}; actions.prototype._clickStorageRemove_all = function () { - core.myconfirm("你确定要清除【全部游戏】的所有本地存档?\n此行为不可逆!!!", function () { - core.ui.drawWaiting("正在清空,请稍候..."); - core.clearLocalForage(function () { - core.saves.ids = {}; - core.saves.autosave.data = null; - core.saves.autosave.updated = false; - core.saves.autosave.now = 0; - core.saves.cache = {}; - core.ui.closePanel(); - core.saves.saveIndex = 1; - core.saves.favorite = []; - core.saves.favoriteName = {}; - core.control._updateFavoriteSaves(); - core.removeLocalStorage('saveIndex'); - core.drawText("\t[操作成功]你的所有存档已被清空。"); - }); - }); -} + core.myconfirm( + '你确定要清除【全部游戏】的所有本地存档?\n此行为不可逆!!!', + function () { + core.ui.drawWaiting('正在清空,请稍候...'); + core.clearLocalForage(function () { + core.saves.ids = {}; + core.saves.autosave.data = null; + core.saves.autosave.updated = false; + core.saves.autosave.now = 0; + core.saves.cache = {}; + core.ui.closePanel(); + core.saves.saveIndex = 1; + core.saves.favorite = []; + core.saves.favoriteName = {}; + core.control._updateFavoriteSaves(); + core.removeLocalStorage('saveIndex'); + core.drawText('\t[操作成功]你的所有存档已被清空。'); + }); + } + ); +}; actions.prototype._clickStorageRemove_current = function () { - core.myconfirm("你确定要清除本游戏的所有本地存档?\n此行为不可逆!!!", function () { - var done = function () { - core.saves.ids = {}; - core.saves.autosave.data = null; - core.saves.autosave.updated = false; - core.saves.autosave.now = 0; - core.ui.closePanel(); - core.saves.saveIndex = 1; - core.saves.favorite = []; - core.saves.favoriteName = {}; - core.control._updateFavoriteSaves(); - core.removeLocalStorage('saveIndex'); - core.drawText("\t[操作成功]当前塔的存档已被清空。"); + core.myconfirm( + '你确定要清除本游戏的所有本地存档?\n此行为不可逆!!!', + function () { + var done = function () { + core.saves.ids = {}; + core.saves.autosave.data = null; + core.saves.autosave.updated = false; + core.saves.autosave.now = 0; + core.ui.closePanel(); + core.saves.saveIndex = 1; + core.saves.favorite = []; + core.saves.favoriteName = {}; + core.control._updateFavoriteSaves(); + core.removeLocalStorage('saveIndex'); + core.drawText('\t[操作成功]当前塔的存档已被清空。'); + }; + core.ui.drawWaiting('正在清空,请稍候...'); + Object.keys(core.saves.ids).forEach(function (v) { + core.removeLocalForage('save' + v); + }); + core.removeLocalForage('autoSave', done); } - core.ui.drawWaiting("正在清空,请稍候..."); - Object.keys(core.saves.ids).forEach(function (v) { - core.removeLocalForage("save" + v); - }); - core.removeLocalForage("autoSave", done); - }); -} + ); +}; ////// 存档删除界面时,放开某个键的操作 ////// actions.prototype._keyUpStorageRemove = function (keycode) { @@ -2883,8 +3388,12 @@ actions.prototype._keyUpStorageRemove = function (keycode) { core.ui._drawSyncSave(); return; } - this._selectChoices(core.status.event.ui.choices.length, keycode, this._clickStorageRemove); -} + this._selectChoices( + core.status.event.ui.choices.length, + keycode, + this._clickStorageRemove + ); +}; ////// 回放选择界面时的点击操作 ////// actions.prototype._clickReplay = function (x, y) { @@ -2897,75 +3406,105 @@ actions.prototype._clickReplay = function (x, y) { var selection = y - topIndex; core.status.event.selection = selection; switch (selection) { - case 0: core.playSound('确定'); return this._clickReplay_fromBeginning(); - case 1: core.playSound('确定'); return this._clickReplay_fromLoad(); - case 2: core.playSound('确定'); return this._clickReplay_replayRemain(); - case 3: core.playSound('确定'); return this._clickReplay_replaySince(); - case 4: core.playSound('确定'); return core.chooseReplayFile(); - case 5: core.playSound('确定'); return this._clickReplay_download(); - case 6: core.playSound('取消'); return core.ui.closePanel(); + case 0: + core.playSound('确定'); + return this._clickReplay_fromBeginning(); + case 1: + core.playSound('确定'); + return this._clickReplay_fromLoad(); + case 2: + core.playSound('确定'); + return this._clickReplay_replayRemain(); + case 3: + core.playSound('确定'); + return this._clickReplay_replaySince(); + case 4: + core.playSound('确定'); + return core.chooseReplayFile(); + case 5: + core.playSound('确定'); + return this._clickReplay_download(); + case 6: + core.playSound('取消'); + return core.ui.closePanel(); } } -} +}; actions.prototype._clickReplay_fromBeginning = function () { core.ui.closePanel(); - core.startGame(core.status.hard, core.getFlag('__seed__'), core.cloneArray(core.status.route)); -} + core.startGame( + core.status.hard, + core.getFlag('__seed__'), + core.cloneArray(core.status.route) + ); +}; actions.prototype._clickReplay_fromLoad = function () { core.status.event.id = 'replayLoad'; core.status.event.selection = null; core.clearUI(); var saveIndex = core.saves.saveIndex; - var page = parseInt((saveIndex - 1) / 5), offset = saveIndex - 5 * page; + var page = parseInt((saveIndex - 1) / 5), + offset = saveIndex - 5 * page; core.ui._drawSLPanel(10 * page + offset); -} +}; actions.prototype._clickReplay_replayRemain = function () { core.closePanel(); - core.drawText([ - "\t[接续播放录像]该功能允许你播放\r[yellow]两个存档之间的录像\r,常常用于\r[yellow]区域优化\r。\n" + - "例如,有若干个区,已经全部通关;之后重打一区并进行了优化,则可以对剩余区域直接播放录像而无需全部重打。\n\n" + - "详细使用方法参见露珠录制的视频教程:\n\r[yellow]https://bilibili.com/video/BV1az4y1C78x", - "\t[步骤1]请选择一个存档。\n\r[yellow]该存档的坐标必须和当前勇士坐标完全相同。\r\n将尝试从此处开始回放。", - ], function () { - core.status.event.id = 'replayRemain'; - core.lockControl(); - var saveIndex = core.saves.saveIndex; - var page = parseInt((saveIndex - 1) / 5), offset = saveIndex - 5 * page; - core.ui._drawSLPanel(10 * page + offset); - }); -} + core.drawText( + [ + '\t[接续播放录像]该功能允许你播放\r[yellow]两个存档之间的录像\r,常常用于\r[yellow]区域优化\r。\n' + + '例如,有若干个区,已经全部通关;之后重打一区并进行了优化,则可以对剩余区域直接播放录像而无需全部重打。\n\n' + + '详细使用方法参见露珠录制的视频教程:\n\r[yellow]https://bilibili.com/video/BV1az4y1C78x', + '\t[步骤1]请选择一个存档。\n\r[yellow]该存档的坐标必须和当前勇士坐标完全相同。\r\n将尝试从此处开始回放。' + ], + function () { + core.status.event.id = 'replayRemain'; + core.lockControl(); + var saveIndex = core.saves.saveIndex; + var page = parseInt((saveIndex - 1) / 5), + offset = saveIndex - 5 * page; + core.ui._drawSLPanel(10 * page + offset); + } + ); +}; actions.prototype._clickReplay_replaySince = function () { core.closePanel(); - core.drawText([ - "\t[播放存档剩余录像]该功能为【接续播放录像】的简化版本,允许你播放\r[yellow]一个存档中剩余的录像\r,常常用于\r[yellow]录像局部优化\r。\n" + - "在录像正常播放中,你随时可以暂停并按S键进行存档;此时\r[yellow]剩余录像\r也会被记在存档中(在读档界面用\r[yellow][R]\r标识。)\n" + - "之后,你可以选择在路线优化后直接播放该存档的\r[yellow]剩余录像\r,而无需再像接续播放一样选择录像起点和终点。\n\n" + - "详细使用方法参见露珠录制的视频教程:\n\r[yellow]https://bilibili.com/video/BV1az4y1C78x", - "请选择一个存档。\n\n\r[yellow]该存档需为录像播放中存的,且坐标必须和当前勇士坐标完全相同。\r\n将尝试播放此存档的剩余录像。", - ], function () { - core.status.event.id = 'replaySince'; - core.lockControl(); - var saveIndex = core.saves.saveIndex; - var page = parseInt((saveIndex - 1) / 5), offset = saveIndex - 5 * page; - core.ui._drawSLPanel(10 * page + offset); - }); -} + core.drawText( + [ + '\t[播放存档剩余录像]该功能为【接续播放录像】的简化版本,允许你播放\r[yellow]一个存档中剩余的录像\r,常常用于\r[yellow]录像局部优化\r。\n' + + '在录像正常播放中,你随时可以暂停并按S键进行存档;此时\r[yellow]剩余录像\r也会被记在存档中(在读档界面用\r[yellow][R]\r标识。)\n' + + '之后,你可以选择在路线优化后直接播放该存档的\r[yellow]剩余录像\r,而无需再像接续播放一样选择录像起点和终点。\n\n' + + '详细使用方法参见露珠录制的视频教程:\n\r[yellow]https://bilibili.com/video/BV1az4y1C78x', + '请选择一个存档。\n\n\r[yellow]该存档需为录像播放中存的,且坐标必须和当前勇士坐标完全相同。\r\n将尝试播放此存档的剩余录像。' + ], + function () { + core.status.event.id = 'replaySince'; + core.lockControl(); + var saveIndex = core.saves.saveIndex; + var page = parseInt((saveIndex - 1) / 5), + offset = saveIndex - 5 * page; + core.ui._drawSLPanel(10 * page + offset); + } + ); +}; actions.prototype._clickReplay_download = function () { // if (core.hasFlag('debug')) return core.drawText("\t[系统提示]调试模式下无法下载录像"); - core.download(core.firstData.name + "_" + core.formatDate2() + ".h5route", - LZString.compressToBase64(JSON.stringify({ - 'name': core.firstData.name, - 'hard': core.status.hard, - 'seed': core.getFlag('__seed__'), - 'route': core.encodeRoute(core.status.route) - }))); - -} + core.download( + core.firstData.name + '_' + core.formatDate2() + '.h5route', + LZString.compressToBase64( + JSON.stringify({ + name: core.firstData.name, + hard: core.status.hard, + seed: core.getFlag('__seed__'), + route: core.encodeRoute(core.status.route) + }) + ) + ); +}; ////// 回放选择界面时,放开某个键的操作 ////// actions.prototype._keyUpReplay = function (keycode) { @@ -2974,8 +3513,12 @@ actions.prototype._keyUpReplay = function (keycode) { core.ui.closePanel(); return; } - this._selectChoices(core.status.event.ui.choices.length, keycode, this._clickReplay); -} + this._selectChoices( + core.status.event.ui.choices.length, + keycode, + this._clickReplay + ); +}; ////// 游戏信息界面时的点击操作 ////// actions.prototype._clickGameInfo = function (x, y) { @@ -2988,12 +3531,18 @@ actions.prototype._clickGameInfo = function (x, y) { var selection = y - topIndex; core.status.event.selection = selection; switch (selection) { - case 0: return core.ui._drawStatistics(); - case 1: return this._clickGameInfo_openProject(); - case 2: return this._clickGameInfo_openComments(); - case 3: return core.ui._drawHelp(); - case 4: return core.ui._drawAbout(); - case 5: return this._clickGameInfo_download(); + case 0: + return core.ui._drawStatistics(); + case 1: + return this._clickGameInfo_openProject(); + case 2: + return this._clickGameInfo_openComments(); + case 3: + return core.ui._drawHelp(); + case 4: + return core.ui._drawAbout(); + case 5: + return this._clickGameInfo_download(); case 6: core.status.event.selection = 5; core.playSound('取消'); @@ -3001,35 +3550,31 @@ actions.prototype._clickGameInfo = function (x, y) { break; } } -} +}; actions.prototype._clickGameInfo_openProject = function () { - if (core.platform.isPC) - window.open("editor.html", "_blank"); + if (core.platform.isPC) window.open('editor.html', '_blank'); else { - core.myconfirm("即将离开本游戏,跳转至工程页面,确认?", function () { - window.location.href = "editor-mobile.html"; + core.myconfirm('即将离开本游戏,跳转至工程页面,确认?', function () { + window.location.href = 'editor-mobile.html'; }); } -} +}; actions.prototype._clickGameInfo_openComments = function () { if (core.platform.isPC) { - window.open("/score.php?name=" + core.firstData.name, "_blank"); - } - else { - core.myconfirm("即将离开本游戏,跳转至评论页面,确认?", function () { - window.location.href = "/score.php?name=" + core.firstData.name; + window.open('/score.php?name=' + core.firstData.name, '_blank'); + } else { + core.myconfirm('即将离开本游戏,跳转至评论页面,确认?', function () { + window.location.href = '/score.php?name=' + core.firstData.name; }); } -} +}; actions.prototype._clickGameInfo_download = function () { - if (core.platform.isPC) - window.open(core.firstData.name + ".zip"); - else - window.location.href = core.firstData.name + ".zip"; -} + if (core.platform.isPC) window.open(core.firstData.name + '.zip'); + else window.location.href = core.firstData.name + '.zip'; +}; ////// 游戏信息界面时,放开某个键的操作 ////// actions.prototype._keyUpGameInfo = function (keycode) { @@ -3038,8 +3583,12 @@ actions.prototype._keyUpGameInfo = function (keycode) { core.playSound('取消'); return core.ui._drawSettings(); } - this._selectChoices(core.status.event.ui.choices.length, keycode, this._clickGameInfo); -} + this._selectChoices( + core.status.event.ui.choices.length, + keycode, + this._clickGameInfo + ); +}; ////// “虚拟键盘”界面时的点击操作 ////// actions.prototype._clickKeyBoard = function (x, y) { @@ -3054,9 +3603,9 @@ actions.prototype._clickKeyBoard = function (x, y) { } // 字母 var lines = [ - ["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"], - ["A", "S", "D", "F", "G", "H", "J", "K", "L"], - ["Z", "X", "C", "V", "B", "N", "M"], + ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'], + ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'], + ['Z', 'X', 'C', 'V', 'B', 'N', 'M'] ]; if (y == this._HY_ - 1 && x >= m - 5 && x <= m + 4) { core.ui.closePanel(); @@ -3101,11 +3650,14 @@ actions.prototype._clickKeyBoard = function (x, y) { core.playSound('取消'); core.ui.closePanel(); } -} +}; ////// 光标界面时的点击操作 ////// actions.prototype._clickCursor = function (x, y, px, py) { - if (x == core.status.automaticRoute.cursorX && y == core.status.automaticRoute.cursorY) { + if ( + x == core.status.automaticRoute.cursorX && + y == core.status.automaticRoute.cursorY + ) { core.ui.closePanel(); // 视为按下再放起 this.doRegisteredAction('ondown', x, y, px, py); @@ -3115,35 +3667,39 @@ actions.prototype._clickCursor = function (x, y, px, py) { core.status.automaticRoute.cursorX = x; core.status.automaticRoute.cursorY = y; core.ui._drawCursor(); -} +}; ////// 光标界面时,按下某个键的操作 ////// actions.prototype._keyDownCursor = function (keycode) { - if (keycode == 37) { // left + if (keycode == 37) { + // left core.status.automaticRoute.cursorX--; core.playSound('光标移动'); core.ui._drawCursor(); return; } - if (keycode == 38) { // up + if (keycode == 38) { + // up core.status.automaticRoute.cursorY--; core.playSound('光标移动'); core.ui._drawCursor(); return; } - if (keycode == 39) { // right + if (keycode == 39) { + // right core.status.automaticRoute.cursorX++; core.playSound('光标移动'); core.ui._drawCursor(); return; } - if (keycode == 40) { // down + if (keycode == 40) { + // down core.status.automaticRoute.cursorY++; core.playSound('光标移动'); core.ui._drawCursor(); return; } -} +}; ////// 光标界面时,放开某个键的操作 ////// actions.prototype._keyUpCursor = function (keycode) { @@ -3162,4 +3718,4 @@ actions.prototype._keyUpCursor = function (keycode) { this.doRegisteredAction('onup', x, y, 32 * x + 16, 32 * y + 16); return; } -} +}; diff --git a/public/libs/ui.js b/public/libs/ui.js index 7b6885e..64afac4 100644 --- a/public/libs/ui.js +++ b/public/libs/ui.js @@ -1,20 +1,19 @@ - /** * ui.js:负责所有和UI界面相关的绘制 * 包括: * 自动寻路、怪物手册、楼传器、存读档、菜单栏、NPC对话事件、等等 */ -"use strict"; +'use strict'; -function ui () { +function ui() { this._init(); } // 初始化UI ui.prototype._init = function () { this.uidata = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.ui; -} +}; ////////////////// 地图设置 @@ -22,55 +21,76 @@ ui.prototype.getContextByName = function (name) { if (name instanceof HTMLCanvasElement) return name.getContext('2d'); var canvas = name; if (typeof name == 'string') { - if (core.canvas[name]) - canvas = core.canvas[name]; - else if (core.dymCanvas[name]) - canvas = core.dymCanvas[name]; + if (core.canvas[name]) canvas = core.canvas[name]; + else if (core.dymCanvas[name]) canvas = core.dymCanvas[name]; } if (canvas && canvas.canvas) { return canvas; } return null; -} +}; ui.prototype._createUIEvent = function () { if (main.mode == 'editor') return; if (!core.dymCanvas['uievent']) { core.createCanvas('uievent', 0, 0, core._PX_, core._PY_, 135); } -} +}; ////// 清除地图 ////// ui.prototype.clearMap = function (name, x, y, width, height) { if (name == 'all') { for (var m in core.canvas) { - core.canvas[m].clearRect(-32, -32, core.canvas[m].canvas.width + 32, core.canvas[m].canvas.height + 32); + core.canvas[m].clearRect( + -32, + -32, + core.canvas[m].canvas.width + 32, + core.canvas[m].canvas.height + 32 + ); } - core.dom.gif.innerHTML = ""; + core.dom.gif.innerHTML = ''; core.removeGlobalAnimate(); - core.deleteCanvas(function (one) { return one.startsWith('_bigImage_'); }); + core.deleteCanvas(function (one) { + return one.startsWith('_bigImage_'); + }); core.setWeather(null); - } - else { + } else { var ctx = this.getContextByName(name); if (ctx) { if (x != null && y != null && width != null && height != null) { ctx.clearRect(x, y, width, height); } else { - ctx.clearRect(-32, -32, ctx.canvas.width + 32, ctx.canvas.height + 32); + ctx.clearRect( + -32, + -32, + ctx.canvas.width + 32, + ctx.canvas.height + 32 + ); } } } -} +}; ui.prototype._uievent_clearMap = function (data) { - if (main.mode != 'editor' && (data.x == null || data.y == null || data.width == null || data.height == null)) { + if ( + main.mode != 'editor' && + (data.x == null || + data.y == null || + data.width == null || + data.height == null) + ) { this.deleteCanvas('uievent'); return; } this._createUIEvent(); - this.clearMap('uievent', core.calValue(data.x), core.calValue(data.y), core.calValue(data.width), core.calValue(data.height)); -} + this.clearMap( + 'uievent', + core.calValue(data.x), + core.calValue(data.y), + core.calValue(data.width), + core.calValue(data.height) + ); +}; ////// 在某个canvas上绘制一段文字 ////// ui.prototype.fillText = function (name, text, x, y, style, font, maxWidth) { @@ -78,8 +98,8 @@ ui.prototype.fillText = function (name, text, x, y, style, font, maxWidth) { if (font) core.setFont(name, font); var ctx = this.getContextByName(name); if (!ctx) return; - text = (text + "").replace(/\\r/g, '\r'); - var originText = text.replace(/\r(\[.*\])?/g, ""); + text = (text + '').replace(/\\r/g, '\r'); + var originText = text.replace(/\r(\[.*\])?/g, ''); var index = text.indexOf('\r'); if (maxWidth != null) { this.setFontForMaxWidth(ctx, index >= 0 ? originText : text, maxWidth); @@ -91,13 +111,14 @@ ui.prototype.fillText = function (name, text, x, y, style, font, maxWidth) { if (textAlign == 'center') x -= textWidth / 2; else if (textAlign == 'right') x -= textWidth; ctx.textAlign = 'left'; - text = text.replace(/\r(?!\[.*\])/g, "\r[" + currentStyle + "]"); + text = text.replace(/\r(?!\[.*\])/g, '\r[' + currentStyle + ']'); var colorArray = text.match(/\r\[.*?\]/g); var textArray = text.split(/\r\[.*?\]/); var width = 0; for (var i = 0; i < textArray.length; i++) { var subtext = textArray[i]; - if (colorArray[i - 1]) ctx.fillStyle = colorArray[i - 1].slice(2, -1); + if (colorArray[i - 1]) + ctx.fillStyle = colorArray[i - 1].slice(2, -1); ctx.fillText(subtext, x + width, y); width += core.calWidth(ctx, subtext, x, y); } @@ -106,27 +127,45 @@ ui.prototype.fillText = function (name, text, x, y, style, font, maxWidth) { } else { ctx.fillText(text, x, y); } -} +}; ui.prototype._uievent_fillText = function (data) { this._createUIEvent(); - this.fillText('uievent', core.replaceText(data.text), core.calValue(data.x), core.calValue(data.y), data.style, data.font, data.maxWidth); -} + this.fillText( + 'uievent', + core.replaceText(data.text), + core.calValue(data.x), + core.calValue(data.y), + data.style, + data.font, + data.maxWidth + ); +}; ////// 自适配字体大小 ui.prototype.setFontForMaxWidth = function (name, text, maxWidth, font) { var ctx = this.getContextByName(name); if (font) core.setFont(name, font); - var font = ctx.font, u = /(\d+)px/.exec(font); + var font = ctx.font, + u = /(\d+)px/.exec(font); if (u == null) return; for (var font_size = parseInt(u[1]); font_size >= 8; font_size--) { - ctx.font = font.replace(/(\d+)px/, font_size + "px"); + ctx.font = font.replace(/(\d+)px/, font_size + 'px'); if (ctx.measureText(text).width <= maxWidth) return; } -} +}; ////// 在某个canvas上绘制粗体 ////// -ui.prototype.fillBoldText = function (name, text, x, y, style, strokeStyle, font, maxWidth) { +ui.prototype.fillBoldText = function ( + name, + text, + x, + y, + style, + strokeStyle, + font, + maxWidth +) { var ctx = this.getContextByName(name); if (!ctx) return; if (font) ctx.font = font; @@ -142,12 +181,20 @@ ui.prototype.fillBoldText = function (name, text, x, y, style, strokeStyle, font ctx.strokeText(text, x, y); ctx.fillStyle = style; ctx.fillText(text, x, y); -} +}; ui.prototype._uievent_fillBoldText = function (data) { this._createUIEvent(); - this.fillBoldText('uievent', core.replaceText(data.text), core.calValue(data.x), core.calValue(data.y), data.style, data.strokeStyle, data.font); -} + this.fillBoldText( + 'uievent', + core.replaceText(data.text), + core.calValue(data.x), + core.calValue(data.y), + data.style, + data.strokeStyle, + data.font + ); +}; ////// 在某个canvas上绘制一个矩形 ////// ui.prototype.fillRect = function (name, x, y, width, height, style, angle) { @@ -165,21 +212,45 @@ ui.prototype.fillRect = function (name, x, y, width, height, style, angle) { ctx.restore(); } } -} +}; ui.prototype._uievent_fillRect = function (data) { this._createUIEvent(); if (data.radius) { - this.fillRoundRect('uievent', core.calValue(data.x), core.calValue(data.y), core.calValue(data.width), core.calValue(data.height), - core.calValue(data.radius), data.style, (core.calValue(data.angle) || 0) * Math.PI / 180); + this.fillRoundRect( + 'uievent', + core.calValue(data.x), + core.calValue(data.y), + core.calValue(data.width), + core.calValue(data.height), + core.calValue(data.radius), + data.style, + ((core.calValue(data.angle) || 0) * Math.PI) / 180 + ); } else { - this.fillRect('uievent', core.calValue(data.x), core.calValue(data.y), core.calValue(data.width), core.calValue(data.height), - data.style, (core.calValue(data.angle) || 0) * Math.PI / 180); + this.fillRect( + 'uievent', + core.calValue(data.x), + core.calValue(data.y), + core.calValue(data.width), + core.calValue(data.height), + data.style, + ((core.calValue(data.angle) || 0) * Math.PI) / 180 + ); } -} +}; ////// 在某个canvas上绘制一个矩形的边框 ////// -ui.prototype.strokeRect = function (name, x, y, width, height, style, lineWidth, angle) { +ui.prototype.strokeRect = function ( + name, + x, + y, + width, + height, + style, + lineWidth, + angle +) { if (style) core.setStrokeStyle(name, style); if (lineWidth) core.setLineWidth(name, lineWidth); var ctx = this.getContextByName(name); @@ -195,21 +266,47 @@ ui.prototype.strokeRect = function (name, x, y, width, height, style, lineWidth, ctx.restore(); } } -} +}; ui.prototype._uievent_strokeRect = function (data) { this._createUIEvent(); if (data.radius) { - this.strokeRoundRect('uievent', core.calValue(data.x), core.calValue(data.y), core.calValue(data.width), core.calValue(data.height), - core.calValue(data.radius), data.style, data.lineWidth, (core.calValue(data.angle) || 0) * Math.PI / 180); + this.strokeRoundRect( + 'uievent', + core.calValue(data.x), + core.calValue(data.y), + core.calValue(data.width), + core.calValue(data.height), + core.calValue(data.radius), + data.style, + data.lineWidth, + ((core.calValue(data.angle) || 0) * Math.PI) / 180 + ); } else { - this.strokeRect('uievent', core.calValue(data.x), core.calValue(data.y), core.calValue(data.width), core.calValue(data.height), - data.style, data.lineWidth, (core.calValue(data.angle) || 0) * Math.PI / 180); + this.strokeRect( + 'uievent', + core.calValue(data.x), + core.calValue(data.y), + core.calValue(data.width), + core.calValue(data.height), + data.style, + data.lineWidth, + ((core.calValue(data.angle) || 0) * Math.PI) / 180 + ); } -} +}; ////// 在某个canvas上绘制一个圆角矩形 ////// -ui.prototype.fillRoundRect = function (name, x, y, width, height, radius, style, angle) { +ui.prototype.fillRoundRect = function ( + name, + x, + y, + width, + height, + radius, + style, + angle +) { if (style) core.setFillStyle(name, style); var ctx = this.getContextByName(name); if (ctx) { @@ -225,10 +322,20 @@ ui.prototype.fillRoundRect = function (name, x, y, width, height, radius, style, ctx.restore(); } } -} +}; ////// 在某个canvas上绘制一个圆角矩形的边框 ////// -ui.prototype.strokeRoundRect = function (name, x, y, width, height, radius, style, lineWidth, angle) { +ui.prototype.strokeRoundRect = function ( + name, + x, + y, + width, + height, + radius, + style, + lineWidth, + angle +) { if (style) core.setStrokeStyle(name, style); if (lineWidth) core.setLineWidth(name, lineWidth); var ctx = this.getContextByName(name); @@ -245,9 +352,16 @@ ui.prototype.strokeRoundRect = function (name, x, y, width, height, radius, styl ctx.restore(); } } -} +}; -ui.prototype._roundRect_buildPath = function (ctx, x, y, width, height, radius) { +ui.prototype._roundRect_buildPath = function ( + ctx, + x, + y, + width, + height, + radius +) { ctx.beginPath(); ctx.moveTo(x + radius, y); ctx.lineTo(x + width - radius, y); @@ -259,7 +373,7 @@ ui.prototype._roundRect_buildPath = function (ctx, x, y, width, height, radius) ctx.lineTo(x, y + radius); ctx.quadraticCurveTo(x, y, x + radius, y); ctx.closePath(); -} +}; ////// 在某个canvas上绘制一个多边形 ////// ui.prototype.fillPolygon = function (name, nodes, style) { @@ -269,18 +383,19 @@ ui.prototype.fillPolygon = function (name, nodes, style) { if (!nodes || nodes.length < 3) return; ctx.beginPath(); for (var i = 0; i < nodes.length; ++i) { - var x = core.calValue(nodes[i][0]), y = core.calValue(nodes[i][1]); + var x = core.calValue(nodes[i][0]), + y = core.calValue(nodes[i][1]); if (i == 0) ctx.moveTo(x, y); else ctx.lineTo(x, y); } ctx.closePath(); ctx.fill(); -} +}; ui.prototype._uievent_fillPolygon = function (data) { this._createUIEvent(); this.fillPolygon('uievent', data.nodes, data.style); -} +}; ////// 在某个canvas上绘制一个多边形的边框 ////// ui.prototype.strokePolygon = function (name, nodes, style, lineWidth) { @@ -291,18 +406,19 @@ ui.prototype.strokePolygon = function (name, nodes, style, lineWidth) { if (!nodes || nodes.length < 3) return; ctx.beginPath(); for (var i = 0; i < nodes.length; ++i) { - var x = core.calValue(nodes[i][0]), y = core.calValue(nodes[i][1]); + var x = core.calValue(nodes[i][0]), + y = core.calValue(nodes[i][1]); if (i == 0) ctx.moveTo(x, y); else ctx.lineTo(x, y); } ctx.closePath(); ctx.stroke(); -} +}; ui.prototype._uievent_strokePolygon = function (data) { this._createUIEvent(); this.strokePolygon('uievent', data.nodes, data.style, data.lineWidth); -} +}; ////// 在某个canvas上绘制一个椭圆 ////// ui.prototype.fillEllipse = function (name, x, y, a, b, angle, style) { @@ -312,20 +428,36 @@ ui.prototype.fillEllipse = function (name, x, y, a, b, angle, style) { ctx.beginPath(); ctx.ellipse(x, y, a, b, angle, 0, 2 * Math.PI); ctx.fill(); -} +}; ui.prototype.fillCircle = function (name, x, y, r, style) { return this.fillEllipse(name, x, y, r, r, 0, style); -} +}; ui.prototype._uievent_fillEllipse = function (data) { this._createUIEvent(); - this.fillEllipse('uievent', core.calValue(data.x), core.calValue(data.y), core.calValue(data.a), - core.calValue(data.b), (core.calValue(data.angle) || 0) * Math.PI / 180, data.style); -} + this.fillEllipse( + 'uievent', + core.calValue(data.x), + core.calValue(data.y), + core.calValue(data.a), + core.calValue(data.b), + ((core.calValue(data.angle) || 0) * Math.PI) / 180, + data.style + ); +}; ////// 在某个canvas上绘制一个圆的边框 ////// -ui.prototype.strokeEllipse = function (name, x, y, a, b, angle, style, lineWidth) { +ui.prototype.strokeEllipse = function ( + name, + x, + y, + a, + b, + angle, + style, + lineWidth +) { if (style) core.setStrokeStyle(name, style); if (lineWidth) core.setLineWidth(name, lineWidth); var ctx = this.getContextByName(name); @@ -333,17 +465,25 @@ ui.prototype.strokeEllipse = function (name, x, y, a, b, angle, style, lineWidth ctx.beginPath(); ctx.ellipse(x, y, a, b, angle, 0, 2 * Math.PI); ctx.stroke(); -} +}; ui.prototype.strokeCircle = function (name, x, y, r, style, lineWidth) { return this.strokeEllipse(name, x, y, r, r, 0, style, lineWidth); -} +}; ui.prototype._uievent_strokeEllipse = function (data) { this._createUIEvent(); - this.strokeEllipse('uievent', core.calValue(data.x), core.calValue(data.y), core.calValue(data.a), - core.calValue(data.b), (core.calValue(data.angle) || 0) * Math.PI / 180, data.style, data.lineWidth); -} + this.strokeEllipse( + 'uievent', + core.calValue(data.x), + core.calValue(data.y), + core.calValue(data.a), + core.calValue(data.b), + ((core.calValue(data.angle) || 0) * Math.PI) / 180, + data.style, + data.lineWidth + ); +}; ui.prototype.fillArc = function (name, x, y, r, start, end, style) { if (style) core.setFillStyle(name, style); @@ -354,15 +494,31 @@ ui.prototype.fillArc = function (name, x, y, r, start, end, style) { ctx.arc(x, y, r, start, end); ctx.closePath(); ctx.fill(); -} +}; ui.prototype._uievent_fillArc = function (data) { this._createUIEvent(); - this.fillArc('uievent', core.calValue(data.x), core.calValue(data.y), core.calValue(data.r), - (core.calValue(data.start) || 0) * Math.PI / 180, (core.calValue(data.end) || 0) * Math.PI / 180, data.style); -} + this.fillArc( + 'uievent', + core.calValue(data.x), + core.calValue(data.y), + core.calValue(data.r), + ((core.calValue(data.start) || 0) * Math.PI) / 180, + ((core.calValue(data.end) || 0) * Math.PI) / 180, + data.style + ); +}; -ui.prototype.strokeArc = function (name, x, y, r, start, end, style, lineWidth) { +ui.prototype.strokeArc = function ( + name, + x, + y, + r, + start, + end, + style, + lineWidth +) { if (style) core.setStrokeStyle(name, style); if (lineWidth) core.setLineWidth(name, lineWidth); var ctx = this.getContextByName(name); @@ -370,13 +526,21 @@ ui.prototype.strokeArc = function (name, x, y, r, start, end, style, lineWidth) ctx.beginPath(); ctx.arc(x, y, r, start, end); ctx.stroke(); -} +}; ui.prototype._uievent_strokeArc = function (data) { this._createUIEvent(); - this.strokeArc('uievent', core.calValue(data.x), core.calValue(data.y), core.calValue(data.r), - (core.calValue(data.start) || 0) * Math.PI / 180, (core.calValue(data.end) || 0) * Math.PI / 180, data.style, data.lineWidth); -} + this.strokeArc( + 'uievent', + core.calValue(data.x), + core.calValue(data.y), + core.calValue(data.r), + ((core.calValue(data.start) || 0) * Math.PI) / 180, + ((core.calValue(data.end) || 0) * Math.PI) / 180, + data.style, + data.lineWidth + ); +}; ////// 在某个canvas上绘制一条线 ////// ui.prototype.drawLine = function (name, x1, y1, x2, y2, style, lineWidth) { @@ -388,12 +552,20 @@ ui.prototype.drawLine = function (name, x1, y1, x2, y2, style, lineWidth) { ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke(); -} +}; ui.prototype._uievent_drawLine = function (data) { this._createUIEvent(); - this.drawLine('uievent', core.calValue(data.x1), core.calValue(data.y1), core.calValue(data.x2), core.calValue(data.y2), data.style, data.lineWidth); -} + this.drawLine( + 'uievent', + core.calValue(data.x1), + core.calValue(data.y1), + core.calValue(data.x2), + core.calValue(data.y2), + data.style, + data.lineWidth + ); +}; ////// 在某个canvas上绘制一个箭头 ////// ui.prototype.drawArrow = function (name, x1, y1, x2, y2, style, lineWidth) { @@ -403,45 +575,60 @@ ui.prototype.drawArrow = function (name, x1, y1, x2, y2, style, lineWidth) { var ctx = this.getContextByName(name); if (!ctx) return; var head = 10; - var dx = x2 - x1, dy = y2 - y1; + var dx = x2 - x1, + dy = y2 - y1; var angle = Math.atan2(dy, dx); ctx.beginPath(); ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); - ctx.lineTo(x2 - head * Math.cos(angle - Math.PI / 6), y2 - head * Math.sin(angle - Math.PI / 6)); + ctx.lineTo( + x2 - head * Math.cos(angle - Math.PI / 6), + y2 - head * Math.sin(angle - Math.PI / 6) + ); ctx.moveTo(x2, y2); - ctx.lineTo(x2 - head * Math.cos(angle + Math.PI / 6), y2 - head * Math.sin(angle + Math.PI / 6)); + ctx.lineTo( + x2 - head * Math.cos(angle + Math.PI / 6), + y2 - head * Math.sin(angle + Math.PI / 6) + ); ctx.stroke(); -} +}; ui.prototype._uievent_drawArrow = function (data) { this._createUIEvent(); - this.drawArrow('uievent', core.calValue(data.x1), core.calValue(data.y1), core.calValue(data.x2), core.calValue(data.y2), data.style, data.lineWidth); -} + this.drawArrow( + 'uievent', + core.calValue(data.x1), + core.calValue(data.y1), + core.calValue(data.x2), + core.calValue(data.y2), + data.style, + data.lineWidth + ); +}; ////// 设置某个canvas的文字字体 ////// ui.prototype.setFont = function (name, font) { var ctx = this.getContextByName(name); if (ctx) ctx.font = font; -} +}; ////// 设置某个canvas的线宽度 ////// ui.prototype.setLineWidth = function (name, lineWidth) { var ctx = this.getContextByName(name); if (ctx) ctx.lineWidth = lineWidth; -} +}; ////// 保存某个canvas状态 ////// ui.prototype.saveCanvas = function (name) { var ctx = this.getContextByName(name); if (ctx) ctx.save(); -} +}; ////// 加载某个canvas状态 ////// ui.prototype.loadCanvas = function (name) { var ctx = this.getContextByName(name); if (ctx) ctx.restore(); -} +}; ////// 设置某个canvas的alpha值,并返回设置之前的alpha值 ////// ui.prototype.setAlpha = function (name, alpha) { @@ -450,13 +637,13 @@ ui.prototype.setAlpha = function (name, alpha) { var previousAlpha = ctx.globalAlpha; ctx.globalAlpha = alpha; return previousAlpha; -} +}; ////// 设置某个canvas的透明度;尽量不要使用本函数,而是全部换成setAlpha实现 ////// ui.prototype.setOpacity = function (name, opacity) { var ctx = this.getContextByName(name); if (ctx) ctx.canvas.style.opacity = opacity; -} +}; ////// 设置某个canvas的filter ////// ui.prototype.setFilter = function (name, filter) { @@ -470,35 +657,36 @@ ui.prototype.setFilter = function (name, filter) { if (filter.hue > 0) x.push('hue-rotate(' + filter.hue + 'deg)'); if (filter.grayscale > 0) x.push('grayscale(' + filter.grayscale + ')'); if (filter.invert) x.push('invert(1)'); - if (filter.shadow > 0) x.push('drop-shadow(0 0 ' + filter.shadow + 'px black)'); + if (filter.shadow > 0) + x.push('drop-shadow(0 0 ' + filter.shadow + 'px black)'); if (x.length == 0) ctx.filter = 'none'; else ctx.filter = x.join(' '); } -} +}; ////// 设置某个canvas的绘制属性(如颜色等) ////// ui.prototype.setFillStyle = function (name, style) { var ctx = this.getContextByName(name); if (ctx) ctx.fillStyle = core.arrayToRGBA(style); -} +}; ////// 设置某个canvas边框属性 ////// ui.prototype.setStrokeStyle = function (name, style) { var ctx = this.getContextByName(name); if (ctx) ctx.strokeStyle = core.arrayToRGBA(style); -} +}; ////// 设置某个canvas的对齐 ////// ui.prototype.setTextAlign = function (name, align) { var ctx = this.getContextByName(name); if (ctx) ctx.textAlign = align; -} +}; ////// 设置某个canvas的baseline ////// ui.prototype.setTextBaseline = function (name, baseline) { var ctx = this.getContextByName(name); if (ctx) ctx.textBaseline = baseline; -} +}; ui.prototype._uievent_setAttribute = function (data) { this._createUIEvent(); @@ -515,12 +703,12 @@ ui.prototype._uievent_setAttribute = function (data) { if (core.dymCanvas._uievent_selector) core.dymCanvas._uievent_selector.canvas.style.zIndex = z + 1; } -} +}; ui.prototype._uievent_setFilter = function (data) { this._createUIEvent(); this.setFilter('uievent', data); -} +}; ////// 计算某段文字的宽度 ////// ui.prototype.calWidth = function (name, text, font) { @@ -530,7 +718,7 @@ ui.prototype.calWidth = function (name, text, font) { return ctx.measureText(text).width; } return 0; -} +}; ////// 字符串自动换行的分割 ////// ui.prototype.splitLines = function (name, text, maxWidth, font) { @@ -544,12 +732,10 @@ ui.prototype.splitLines = function (name, text, maxWidth, font) { if (text.charAt(i) == '\n') { contents.push(text.substring(last, i)); last = i + 1; - } - else if (text.charAt(i) == '\\' && text.charAt(i + 1) == 'n') { + } else if (text.charAt(i) == '\\' && text.charAt(i + 1) == 'n') { contents.push(text.substring(last, i)); last = i + 2; - } - else { + } else { var toAdd = text.substring(last, i + 1); var width = core.calWidth(name, toAdd); if (maxWidth && width > maxWidth) { @@ -560,16 +746,33 @@ ui.prototype.splitLines = function (name, text, maxWidth, font) { } contents.push(text.substring(last)); return contents; -} +}; ////// 绘制一张图片 ////// -ui.prototype.drawImage = function (name, image, x, y, w, h, x1, y1, w1, h1, angle, reverse) { +ui.prototype.drawImage = function ( + name, + image, + x, + y, + w, + h, + x1, + y1, + w1, + h1, + angle, + reverse +) { // 检测文件名以 :x, :y, :o 结尾,表示左右翻转,上下翻转和中心翻转 var ctx = this.getContextByName(name); if (!ctx) return; // var reverse = null; if (typeof image == 'string') { - if (image.endsWith(':x') || image.endsWith(':y') || image.endsWith(':o')) { + if ( + image.endsWith(':x') || + image.endsWith(':y') || + image.endsWith(':o') + ) { reverse = image.charAt(image.length - 1); image = image.substring(0, image.length - 2); } @@ -579,9 +782,9 @@ ui.prototype.drawImage = function (name, image, x, y, w, h, x1, y1, w1, h1, angl } var scale = { - 'x': [-1, 1], - 'y': [1, -1], - 'o': [-1, -1] + x: [-1, 1], + y: [1, -1], + o: [-1, -1] }; // 只能接受2, 4, 8个参数 @@ -616,13 +819,24 @@ ui.prototype.drawImage = function (name, image, x, y, w, h, x1, y1, w1, h1, angl } return; } -} +}; ui.prototype._uievent_drawImage = function (data) { this._createUIEvent(); - this.drawImage('uievent', data.image + (data.reverse || ''), core.calValue(data.x), core.calValue(data.y), core.calValue(data.w), core.calValue(data.h), - core.calValue(data.x1), core.calValue(data.y1), core.calValue(data.w1), core.calValue(data.h1), (core.calValue(data.angle) || 0) * Math.PI / 180); -} + this.drawImage( + 'uievent', + data.image + (data.reverse || ''), + core.calValue(data.x), + core.calValue(data.y), + core.calValue(data.w), + core.calValue(data.h), + core.calValue(data.x1), + core.calValue(data.y1), + core.calValue(data.w1), + core.calValue(data.h1), + ((core.calValue(data.angle) || 0) * Math.PI) / 180 + ); +}; ui.prototype.drawIcon = function (name, id, x, y, w, h, frame) { frame = frame || 0; @@ -632,11 +846,27 @@ ui.prototype.drawIcon = function (name, id, x, y, w, h, frame) { if (!info) { // 检查状态栏图标 if (core.statusBar.icons[id] instanceof Image) - info = { image: core.statusBar.icons[id], posX: 0, posY: 0, height: 32 }; + info = { + image: core.statusBar.icons[id], + posX: 0, + posY: 0, + height: 32 + }; else return; } - core.drawImage(ctx, info.image, 32 * (info.posX + frame), info.height * info.posY, 32, info.height, x, y, w || 32, h || info.height); -} + core.drawImage( + ctx, + info.image, + 32 * (info.posX + frame), + info.height * info.posY, + 32, + info.height, + x, + y, + w || 32, + h || info.height + ); +}; ui.prototype._uievent_drawIcon = function (data) { this._createUIEvent(); @@ -644,9 +874,19 @@ ui.prototype._uievent_drawIcon = function (data) { try { id = core.calValue(data.id); if (typeof id !== 'string') id = data.id; - } catch (e) { id = data.id; } - this.drawIcon('uievent', id, core.calValue(data.x), core.calValue(data.y), core.calValue(data.width), core.calValue(data.height), data.frame || 0); -} + } catch (e) { + id = data.id; + } + this.drawIcon( + 'uievent', + id, + core.calValue(data.x), + core.calValue(data.y), + core.calValue(data.width), + core.calValue(data.height), + data.frame || 0 + ); +}; ///////////////// UI绘制 @@ -655,7 +895,7 @@ ui.prototype.closePanel = function () { if (core.status.hero && core.status.hero.flags) { // 清除全部临时变量 Object.keys(core.status.hero.flags).forEach(function (name) { - if (name.startsWith("@temp@") || /^arg\d+$/.test(name)) { + if (name.startsWith('@temp@') || /^arg\d+$/.test(name)) { delete core.status.hero.flags[name]; } }); @@ -672,27 +912,27 @@ ui.prototype.closePanel = function () { // 清除onDownInterval clearInterval(core.interval.onDownInterval); core.interval.onDownInterval = 'tmp'; -} +}; ui.prototype.clearUI = function () { core.status.boxAnimateObjs = []; - core.deleteCanvas("_selector"); + core.deleteCanvas('_selector'); main.dom.next.style.display = 'none'; main.dom.next.style.opacity = 1; core.clearMap('ui'); core.setAlpha('ui', 1); core.setOpacity('ui', 1); core.deleteCanvas('ui2'); -} +}; ////// 左上角绘制一段提示 ////// ui.prototype.drawTip = function (text, id, frame) { - text = core.replaceText(text) || ""; + text = core.replaceText(text) || ''; var realText = this._getRealContent(text); var one = { text: text, textX: 21, - width: 26 + core.calWidth('data', realText, "16px Arial"), + width: 26 + core.calWidth('data', realText, '16px Arial'), opacity: 0.1, stage: 1, frame: frame || 0, @@ -703,9 +943,13 @@ ui.prototype.drawTip = function (text, id, frame) { if (info == null || !info.image || info.bigImage) { // 检查状态栏图标 if (core.statusBar.icons[id] instanceof Image) { - info = { image: core.statusBar.icons[id], posX: 0, posY: 0, height: 32 }; - } - else info = null; + info = { + image: core.statusBar.icons[id], + posX: 0, + posY: 0, + height: 32 + }; + } else info = null; } if (info != null) { one.image = info.image; @@ -717,16 +961,27 @@ ui.prototype.drawTip = function (text, id, frame) { } } core.animateFrame.tip = one; -} +}; ui.prototype._drawTip_drawOne = function (tip) { core.setAlpha('data', tip.opacity); core.fillRect('data', 5, 5, tip.width, 42, '#000000'); if (tip.image) - core.drawImage('data', tip.image, (tip.posX + tip.frame) * 32, tip.posY * tip.height, 32, 32, 10, 10, 32, 32); + core.drawImage( + 'data', + tip.image, + (tip.posX + tip.frame) * 32, + tip.posY * tip.height, + 32, + 32, + 10, + 10, + 32, + 32 + ); core.fillText('data', tip.text, tip.textX, 33, '#FFFFFF'); core.setAlpha('data', 1); -} +}; ////// 地图中间绘制一段文字 ////// ui.prototype.drawText = function (contents, callback) { @@ -740,63 +995,73 @@ ui.prototype.drawText = function (contents, callback) { } var data = core.status.event.data.list.shift(); - if (typeof data == 'string') data = { "text": data }; + if (typeof data == 'string') data = { text: data }; core.ui.drawTextBox(data.text, data); -} +}; ui.prototype._drawText_setContent = function (contents, callback) { // 合并进 insertAction - if ((core.status.event && core.status.event.id == 'action') - || (!core.hasFlag('__replayText__') && core.isReplaying())) { + if ( + (core.status.event && core.status.event.id == 'action') || + (!core.hasFlag('__replayText__') && core.isReplaying()) + ) { core.insertAction(contents, null, null, callback); return; } if (!(contents instanceof Array)) contents = [contents]; - core.status.event = { 'id': 'text', 'data': { 'list': contents, 'callback': callback } }; + core.status.event = { + id: 'text', + data: { list: contents, callback: callback } + }; core.lockControl(); core.waitHeroToStop(core.drawText); return; -} +}; ////// 正则处理 \t[xx,yy] 问题 ui.prototype._getTitleAndIcon = function (content) { - var title = null, image = null, icon = null, height = 32, animate = 1; - var bigImage = null, face = null; - content = content.replace(/(\t|\\t)\[(([^\],]+),)?([^\],]+)\]/g, function (s0, s1, s2, s3, s4) { - if (s4) { - if (s4 == 'hero') { - title = core.status.hero.name; - image = core.material.images.hero; - icon = 0; - var w = core.material.icons.hero.width || 32; - height = 32 * core.material.icons.hero.height / w; - } - else if (s4.endsWith(".png")) { - s4 = core.getMappedName(s4); - image = core.material.images.images[s4]; - } - else { - var blockInfo = core.getBlockInfo(s4); - if (blockInfo != null) { - if (blockInfo.name) title = blockInfo.name; - bigImage = blockInfo.bigImage; - face = blockInfo.face; - image = blockInfo.image; - icon = blockInfo.posY; - height = bigImage == null ? blockInfo.height : 32; - animate = blockInfo.animate; + var title = null, + image = null, + icon = null, + height = 32, + animate = 1; + var bigImage = null, + face = null; + content = content.replace( + /(\t|\\t)\[(([^\],]+),)?([^\],]+)\]/g, + function (s0, s1, s2, s3, s4) { + if (s4) { + if (s4 == 'hero') { + title = core.status.hero.name; + image = core.material.images.hero; + icon = 0; + var w = core.material.icons.hero.width || 32; + height = (32 * core.material.icons.hero.height) / w; + } else if (s4.endsWith('.png')) { + s4 = core.getMappedName(s4); + image = core.material.images.images[s4]; + } else { + var blockInfo = core.getBlockInfo(s4); + if (blockInfo != null) { + if (blockInfo.name) title = blockInfo.name; + bigImage = blockInfo.bigImage; + face = blockInfo.face; + image = blockInfo.image; + icon = blockInfo.posY; + height = bigImage == null ? blockInfo.height : 32; + animate = blockInfo.animate; + } else title = s4; } - else title = s4; } + if (s3 != null) { + title = s3; + if (title == 'null') title = null; + } + return ''; } - if (s3 != null) { - title = s3; - if (title == 'null') title = null; - } - return ""; - }); + ); return { content: content, title: title, @@ -805,13 +1070,16 @@ ui.prototype._getTitleAndIcon = function (content) { height: height, animate: animate, bigImage: bigImage, - face: face, + face: face }; -} +}; ////// 正则处理 \b[up,xxx] 问题 ui.prototype._getPosition = function (content) { - var pos = null, px = null, py = null, noPeak = false; + var pos = null, + px = null, + py = null, + noPeak = false; if (core.status.event.id == 'action') { px = core.status.event.data.x; py = core.status.event.data.y; @@ -820,45 +1088,53 @@ ui.prototype._getPosition = function (content) { px = editor.pos.x; py = editor.pos.y; } - content = content.replace("\b", "\\b") - .replace(/\\b\[(up|center|down|hero|this)(,(hero|null|\d+,\d+|\d+))?]/g, function (s0, s1, s2, s3) { - pos = s1; - if (s3 == 'hero' || s1 == 'hero' && !s3) { - px = core.getHeroLoc('x'); - py = core.getHeroLoc('y'); - } - else if (s3 == 'null') { - px = py = null; - } - else if (s3) { - var str = s3.split(','); - px = py = null; - if (str.length == 1) { - var follower = core.status.hero.followers[parseInt(str[0]) - 1]; - if (follower) { - px = follower.x; - py = follower.y; + content = content + .replace('\b', '\\b') + .replace( + /\\b\[(up|center|down|hero|this)(,(hero|null|\d+,\d+|\d+))?]/g, + function (s0, s1, s2, s3) { + pos = s1; + if (s3 == 'hero' || (s1 == 'hero' && !s3)) { + px = core.getHeroLoc('x'); + py = core.getHeroLoc('y'); + } else if (s3 == 'null') { + px = py = null; + } else if (s3) { + var str = s3.split(','); + px = py = null; + if (str.length == 1) { + var follower = + core.status.hero.followers[parseInt(str[0]) - 1]; + if (follower) { + px = follower.x; + py = follower.y; + } + } else { + px = parseInt(str[0]); + py = parseInt(str[1]); + noPeak = core.getBlockId(px, py) == null; } - } else { - px = parseInt(str[0]); - py = parseInt(str[1]); - noPeak = core.getBlockId(px, py) == null; } + if (pos == 'hero' || pos == 'this') { + pos = + py == null + ? 'center' + : py > core._HALF_HEIGHT_ + ? 'up' + : 'down'; + } + return ''; } - if (pos == 'hero' || pos == 'this') { - pos = py == null ? 'center' : (py > core._HALF_HEIGHT_ ? 'up' : 'down'); - } - return ""; - }); + ); return { content: content, position: pos, px: px, py: py, noPeak: noPeak }; -} +}; ////// 绘制系统选择光标 ui.prototype._drawWindowSelector = function (background, x, y, w, h) { - w = Math.round(w), h = Math.round(h); - var ctx = core.ui.createCanvas("_selector", x, y, w, h, 165); + (w = Math.round(w)), (h = Math.round(h)); + var ctx = core.ui.createCanvas('_selector', x, y, w, h, 165); this._drawSelector(ctx, background, w, h); -} +}; ////// 自绘一个选择光标 ui.prototype.drawUIEventSelector = function (code, background, x, y, w, h, z) { @@ -869,49 +1145,119 @@ ui.prototype.drawUIEventSelector = function (code, background, x, y, w, h, z) { this._drawSelector('uievent', background, w, h, x, y); return; } - z = z || (core.dymCanvas.uievent ? (parseInt(core.dymCanvas.uievent.canvas.style.zIndex) || 135) + 1 : 136); + z = + z || + (core.dymCanvas.uievent + ? (parseInt(core.dymCanvas.uievent.canvas.style.zIndex) || 135) + 1 + : 136); var ctx = core.createCanvas(canvasName, x, y, w, h, z); ctx.canvas.classList.add('_uievent_selector'); this._drawSelector(ctx, background, w, h); -} +}; ui.prototype._uievent_drawSelector = function (data) { if (data.image == null) this.clearUIEventSelector(data.code || 0); - else this.drawUIEventSelector(data.code, data.image, core.calValue(data.x), core.calValue(data.y), core.calValue(data.width), core.calValue(data.height)); -} + else + this.drawUIEventSelector( + data.code, + data.image, + core.calValue(data.x), + core.calValue(data.y), + core.calValue(data.width), + core.calValue(data.height) + ); +}; ////// 清除自绘的选择光标 ui.prototype.clearUIEventSelector = function (codes) { if (codes == null) { - core.deleteCanvas(function (one) { return one.startsWith('_uievent_selector_'); }) + core.deleteCanvas(function (one) { + return one.startsWith('_uievent_selector_'); + }); return; } if (codes instanceof Array) { - codes.forEach(function (code) { core.ui.clearUIEventSelector(code); }); + codes.forEach(function (code) { + core.ui.clearUIEventSelector(code); + }); return; } core.deleteCanvas('_uievent_selector_' + (codes || 0)); -} +}; ui.prototype._drawSelector = function (ctx, background, w, h, left, top) { left = left || 0; top = top || 0; // back - core.drawImage(ctx, background, 130, 66, 28, 28, left + 2, top + 2, w - 4, h - 4); + core.drawImage( + ctx, + background, + 130, + 66, + 28, + 28, + left + 2, + top + 2, + w - 4, + h - 4 + ); // corner core.drawImage(ctx, background, 128, 64, 2, 2, left, top, 2, 2); core.drawImage(ctx, background, 158, 64, 2, 2, left + w - 2, top, 2, 2); core.drawImage(ctx, background, 128, 94, 2, 2, left, top + h - 2, 2, 2); - core.drawImage(ctx, background, 158, 94, 2, 2, left + w - 2, top + h - 2, 2, 2); + core.drawImage( + ctx, + background, + 158, + 94, + 2, + 2, + left + w - 2, + top + h - 2, + 2, + 2 + ); // border core.drawImage(ctx, background, 130, 64, 28, 2, left + 2, top, w - 4, 2); - core.drawImage(ctx, background, 130, 94, 28, 2, left + 2, top + h - 2, w - 4, 2); + core.drawImage( + ctx, + background, + 130, + 94, + 28, + 2, + left + 2, + top + h - 2, + w - 4, + 2 + ); core.drawImage(ctx, background, 128, 66, 2, 28, left, top + 2, 2, h - 4); - core.drawImage(ctx, background, 158, 66, 2, 28, left + w - 2, top + 2, 2, h - 4); -} + core.drawImage( + ctx, + background, + 158, + 66, + 2, + 28, + left + w - 2, + top + 2, + 2, + h - 4 + ); +}; ////// 绘制 WindowSkin -ui.prototype.drawWindowSkin = function (background, ctx, x, y, w, h, direction, px, py) { +ui.prototype.drawWindowSkin = function ( + background, + ctx, + x, + y, + w, + h, + direction, + px, + py +) { background = background || core.status.textAttribute.background; // 仿RM窗口皮肤 ↓ // 绘制背景 @@ -921,84 +1267,266 @@ ui.prototype.drawWindowSkin = function (background, ctx, x, y, w, h, direction, core.drawImage(ctx, background, 128, 0, 16, 16, x, y, 16, 16); for (var dx = 0; dx < w - 64; dx += 32) { core.drawImage(ctx, background, 144, 0, 32, 16, x + dx + 16, y, 32, 16); - core.drawImage(ctx, background, 144, 48, 32, 16, x + dx + 16, y + h - 16, 32, 16); + core.drawImage( + ctx, + background, + 144, + 48, + 32, + 16, + x + dx + 16, + y + h - 16, + 32, + 16 + ); } - core.drawImage(ctx, background, 144, 0, w - dx - 32, 16, x + dx + 16, y, w - dx - 32, 16); - core.drawImage(ctx, background, 144, 48, w - dx - 32, 16, x + dx + 16, y + h - 16, w - dx - 32, 16); + core.drawImage( + ctx, + background, + 144, + 0, + w - dx - 32, + 16, + x + dx + 16, + y, + w - dx - 32, + 16 + ); + core.drawImage( + ctx, + background, + 144, + 48, + w - dx - 32, + 16, + x + dx + 16, + y + h - 16, + w - dx - 32, + 16 + ); core.drawImage(ctx, background, 176, 0, 16, 16, x + w - 16, y, 16, 16); // 左右 for (var dy = 0; dy < h - 64; dy += 32) { - core.drawImage(ctx, background, 128, 16, 16, 32, x, y + dy + 16, 16, 32); - core.drawImage(ctx, background, 176, 16, 16, 32, x + w - 16, y + dy + 16, 16, 32); + core.drawImage( + ctx, + background, + 128, + 16, + 16, + 32, + x, + y + dy + 16, + 16, + 32 + ); + core.drawImage( + ctx, + background, + 176, + 16, + 16, + 32, + x + w - 16, + y + dy + 16, + 16, + 32 + ); } - core.drawImage(ctx, background, 128, 16, 16, h - dy - 32, x, y + dy + 16, 16, h - dy - 32); - core.drawImage(ctx, background, 176, 16, 16, h - dy - 32, x + w - 16, y + dy + 16, 16, h - dy - 32); + core.drawImage( + ctx, + background, + 128, + 16, + 16, + h - dy - 32, + x, + y + dy + 16, + 16, + h - dy - 32 + ); + core.drawImage( + ctx, + background, + 176, + 16, + 16, + h - dy - 32, + x + w - 16, + y + dy + 16, + 16, + h - dy - 32 + ); // 下方 core.drawImage(ctx, background, 128, 48, 16, 16, x, y + h - 16, 16, 16); - core.drawImage(ctx, background, 176, 48, 16, 16, x + w - 16, y + h - 16, 16, 16); + core.drawImage( + ctx, + background, + 176, + 48, + 16, + 16, + x + w - 16, + y + h - 16, + 16, + 16 + ); // arrow if (px != null && py != null) { if (direction == 'up') { - core.drawImage(ctx, background, 128, 96, 32, 32, px, y + h - 3, 32, 32); + core.drawImage( + ctx, + background, + 128, + 96, + 32, + 32, + px, + y + h - 3, + 32, + 32 + ); } else if (direction == 'down') { - core.drawImage(ctx, background, 160, 96, 32, 32, px, y - 29, 32, 32); + core.drawImage( + ctx, + background, + 160, + 96, + 32, + 32, + px, + y - 29, + 32, + 32 + ); } } // 仿RM窗口皮肤 ↑ -} +}; ////// 绘制一个背景图,可绘制 winskin 或纯色背景;支持小箭头绘制 ui.prototype.drawBackground = function (left, top, right, bottom, posInfo) { posInfo = posInfo || {}; - var px = posInfo.px == null || posInfo.noPeak ? null : posInfo.px * 32 - core.bigmap.offsetX; - var py = posInfo.py == null || posInfo.noPeak ? null : posInfo.py * 32 - core.bigmap.offsetY; - var xoffset = posInfo.xoffset || 0, yoffset = posInfo.yoffset || 0; + var px = + posInfo.px == null || posInfo.noPeak + ? null + : posInfo.px * 32 - core.bigmap.offsetX; + var py = + posInfo.py == null || posInfo.noPeak + ? null + : posInfo.py * 32 - core.bigmap.offsetY; + var xoffset = posInfo.xoffset || 0, + yoffset = posInfo.yoffset || 0; var background = core.status.textAttribute.background; - if (this._drawBackground_drawWindowSkin(background, left, top, right, bottom, posInfo.position, px, py, posInfo.ctx)) + if ( + this._drawBackground_drawWindowSkin( + background, + left, + top, + right, + bottom, + posInfo.position, + px, + py, + posInfo.ctx + ) + ) return true; - if (typeof background == 'string') background = core.initStatus.textAttribute.background; - this._drawBackground_drawColor(background, left, top, right, bottom, posInfo.position, px, py, xoffset, yoffset, posInfo.ctx); + if (typeof background == 'string') + background = core.initStatus.textAttribute.background; + this._drawBackground_drawColor( + background, + left, + top, + right, + bottom, + posInfo.position, + px, + py, + xoffset, + yoffset, + posInfo.ctx + ); return false; -} +}; ui.prototype._uievent_drawBackground = function (data) { this._createUIEvent(); var background = data.background || core.status.textAttribute.background; - var x = core.calValue(data.x), y = core.calValue(data.y), w = core.calValue(data.width), h = core.calValue(data.height); + var x = core.calValue(data.x), + y = core.calValue(data.y), + w = core.calValue(data.width), + h = core.calValue(data.height); if (typeof background == 'string') { this.drawWindowSkin(background, 'uievent', x, y, w, h); - } - else if (background instanceof Array) { + } else if (background instanceof Array) { this.fillRect('uievent', x, y, w, h, core.arrayToRGBA(background)); this.strokeRect('uievent', x, y, w, h); } -} +}; ui.prototype._drawWindowSkin_getOpacity = function () { - return core.getFlag("__winskin_opacity__", 0.85); -} + return core.getFlag('__winskin_opacity__', 0.85); +}; -ui.prototype._drawBackground_drawWindowSkin = function (background, left, top, right, bottom, position, px, py, ctx) { +ui.prototype._drawBackground_drawWindowSkin = function ( + background, + left, + top, + right, + bottom, + position, + px, + py, + ctx +) { ctx = ctx || 'ui'; - if (typeof background == 'string' && core.material.images.images[background]) { + if ( + typeof background == 'string' && + core.material.images.images[background] + ) { var image = core.material.images.images[background]; if (image.width == 192 && image.height == 128) { core.setAlpha(ctx, this._drawWindowSkin_getOpacity()); - this.drawWindowSkin(image, ctx, left, top, right - left, bottom - top, position, px, py); + this.drawWindowSkin( + image, + ctx, + left, + top, + right - left, + bottom - top, + position, + px, + py + ); core.setAlpha(ctx, 1); return true; } } return false; -} +}; -ui.prototype._drawBackground_drawColor = function (background, left, top, right, bottom, position, px, py, xoffset, yoffset, ctx) { +ui.prototype._drawBackground_drawColor = function ( + background, + left, + top, + right, + bottom, + position, + px, + py, + xoffset, + yoffset, + ctx +) { ctx = ctx || 'ui'; var alpha = background[3]; core.setAlpha(ctx, alpha); - core.setStrokeStyle(ctx, core.arrayToRGBA(core.status.globalAttribute.borderColor)); + core.setStrokeStyle( + ctx, + core.arrayToRGBA(core.status.globalAttribute.borderColor) + ); core.setFillStyle(ctx, core.arrayToRGB(background)); core.setLineWidth(ctx, 2); // 绘制 @@ -1024,27 +1552,39 @@ ui.prototype._drawBackground_drawColor = function (background, left, top, right, ctx.fill(); ctx.stroke(); core.setAlpha(ctx, 1); -} +}; ////// 计算有效文本框的宽度 -ui.prototype._calTextBoxWidth = function (ctx, content, min_width, max_width, font) { +ui.prototype._calTextBoxWidth = function ( + ctx, + content, + min_width, + max_width, + font +) { // 无限长度自动换行 var allLines = core.splitLines(ctx, content, null, font); // 如果不存在手动换行,尽量调成半行形式 if (allLines.length == 1) { var w = core.calWidth(ctx, allLines[0]) + 10; - if (w < min_width * 2.3) return core.clamp(w / 1.4, min_width, max_width); - if (w < max_width * 2.2) return core.clamp(w / 2.4, min_width, max_width); + if (w < min_width * 2.3) + return core.clamp(w / 1.4, min_width, max_width); + if (w < max_width * 2.2) + return core.clamp(w / 2.4, min_width, max_width); return core.clamp(w / 3.4, min_width, max_width); } // 存在手动换行:以最长的为准 else { - return core.clamp(allLines.reduce(function (pre, curr) { - return Math.max(pre, core.calWidth(ctx, curr) + 10); - }, 0), min_width, max_width); + return core.clamp( + allLines.reduce(function (pre, curr) { + return Math.max(pre, core.calWidth(ctx, curr) + 10); + }, 0), + min_width, + max_width + ); } -} +}; ////// 处理 \i[xxx] 的问题 ui.prototype._getDrawableIconInfo = function (id) { @@ -1052,8 +1592,17 @@ ui.prototype._getDrawableIconInfo = function (id) { id = core.getFlag(id.substring(5), id); } id = core.getIdOfThis(id); - var image = null, icon = null; - ["terrains", "animates", "items", "npcs", "enemys", 'enemy48', 'npc48'].forEach(function (v) { + var image = null, + icon = null; + [ + 'terrains', + 'animates', + 'items', + 'npcs', + 'enemys', + 'enemy48', + 'npc48' + ].forEach(function (v) { if (core.material.icons[v][id] != null) { image = core.material.images[v]; icon = core.material.icons[v][id]; @@ -1064,14 +1613,22 @@ ui.prototype._getDrawableIconInfo = function (id) { icon = 0; } return [image, icon]; -} +}; ui.prototype._buildFont = function (fontSize, bold, italic, font) { - var textAttribute = core.status.textAttribute || core.initStatus.textAttribute, - globalAttribute = core.status.globalAttribute || core.initStatus.globalAttribute; + var textAttribute = + core.status.textAttribute || core.initStatus.textAttribute, + globalAttribute = + core.status.globalAttribute || core.initStatus.globalAttribute; if (bold == null) bold = textAttribute.bold; - return (bold ? "bold " : "") + (italic ? "italic " : "") + (fontSize || textAttribute.textfont) + "px " + (font || globalAttribute.font); -} + return ( + (bold ? 'bold ' : '') + + (italic ? 'italic ' : '') + + (fontSize || textAttribute.textfont) + + 'px ' + + (font || globalAttribute.font) + ); +}; ////// 绘制一段文字到某个画布上面 // ctx:要绘制到的画布 @@ -1082,26 +1639,35 @@ ui.prototype._buildFont = function (fontSize, bold, italic, font) { ui.prototype.drawTextContent = function (ctx, content, config) { ctx = core.getContextByName(ctx); // 设置默认配置项 - var textAttribute = core.status.textAttribute || core.initStatus.textAttribute; - var globalAttribute = core.status.globalAttribute || core.initStatus.globalAttribute; + var textAttribute = + core.status.textAttribute || core.initStatus.textAttribute; + var globalAttribute = + core.status.globalAttribute || core.initStatus.globalAttribute; config = core.clone(config || {}); config.left = config.left || 0; - config.right = config.left + (config.maxWidth == null ? core._PX_ : config.maxWidth); + config.right = + config.left + (config.maxWidth == null ? core._PX_ : config.maxWidth); config.top = config.top || 0; config.color = core.arrayToRGBA(config.color || textAttribute.text); if (config.bold == null) config.bold = textAttribute.bold; config.italic = config.italic || false; - config.align = config.align || textAttribute.align || "left"; + config.align = config.align || textAttribute.align || 'left'; config.fontSize = config.fontSize || textAttribute.textfont; - config.lineHeight = config.lineHeight || (config.fontSize * 1.3); + config.lineHeight = config.lineHeight || config.fontSize * 1.3; config.defaultFont = config.font = config.font || globalAttribute.font; config.time = config.time || 0; - config.letterSpacing = config.letterSpacing == null ? (textAttribute.letterSpacing || 0) : config.letterSpacing; + config.letterSpacing = + config.letterSpacing == null + ? textAttribute.letterSpacing || 0 + : config.letterSpacing; config.index = 0; config.currcolor = config.color; config.currfont = config.fontSize; - config.lineMargin = Math.max(Math.round(config.fontSize / 4), config.lineHeight - config.fontSize); + config.lineMargin = Math.max( + Math.round(config.fontSize / 4), + config.lineHeight - config.fontSize + ); config.topMargin = parseInt(config.lineMargin / 2); config.lineMaxHeight = config.lineMargin + config.fontSize; config.offsetX = 0; @@ -1113,24 +1679,33 @@ ui.prototype.drawTextContent = function (ctx, content, config) { // 创建一个新的临时画布 var tempCtx = document.createElement('canvas').getContext('2d'); if (config.isHD) { - core.maps._setHDCanvasSize(tempCtx, ctx.canvas.width, ctx.canvas.height); + core.maps._setHDCanvasSize( + tempCtx, + ctx.canvas.width, + ctx.canvas.height + ); } else { tempCtx.canvas.width = ctx == null ? 1 : ctx.canvas.width; tempCtx.canvas.height = ctx == null ? 1 : ctx.canvas.height; } tempCtx.textBaseline = 'top'; - tempCtx.font = this._buildFont(config.fontSize, config.bold, config.italic, config.font); + tempCtx.font = this._buildFont( + config.fontSize, + config.bold, + config.italic, + config.font + ); tempCtx.fillStyle = config.color; config = this._drawTextContent_draw(ctx, tempCtx, content, config); return config; -} +}; ui.prototype._uievent_drawTextContent = function (data) { this._createUIEvent(); data.left = core.calValue(data.left); data.top = core.calValue(data.top); this.drawTextContent('uievent', core.replaceText(data.text), data); -} +}; // 绘制的基本逻辑: // 1. 一个个字符绘制到对应画布上(靠左对齐);这个过程中,记下来每个字对应的方块 [x, y, w, h] @@ -1149,16 +1724,24 @@ ui.prototype._drawTextContent_draw = function (ctx, tempCtx, content, config) { var block = config.blocks[config.index++]; if (block != null) { var ratio = config.isHD ? core.domStyle.ratio : 1; - core.drawImage(ctx, tempCtx.canvas, block.left * ratio, block.top * ratio, block.width * ratio, block.height * ratio, - config.left + block.left + block.marginLeft, config.top + block.top + block.marginTop, - block.width, block.height); + core.drawImage( + ctx, + tempCtx.canvas, + block.left * ratio, + block.top * ratio, + block.width * ratio, + block.height * ratio, + config.left + block.left + block.marginLeft, + config.top + block.top + block.marginTop, + block.width, + block.height + ); } return true; - } + }; if (config.time == 0) { while (_drawNext()); - } - else { + } else { clearInterval(core.status.event.interval); core.status.event.interval = setInterval(function () { if (!_drawNext()) { @@ -1169,7 +1752,7 @@ ui.prototype._drawTextContent_draw = function (ctx, tempCtx, content, config) { } return config; -} +}; ui.prototype._drawTextContent_next = function (tempCtx, content, config) { if (config.index >= content.length) { @@ -1179,19 +1762,26 @@ ui.prototype._drawTextContent_next = function (tempCtx, content, config) { // get next character var ch = content.charAt(config.index); var code = content.charCodeAt(config.index++); - while (code >= 0xD800 && code <= 0xDBFF) { + while (code >= 0xd800 && code <= 0xdbff) { ch += content.charAt(config.index); code = content.charCodeAt(config.index++); } return this._drawTextContent_drawChar(tempCtx, content, config, ch); -} +}; // 绘制下一个字符 -ui.prototype._drawTextContent_drawChar = function (tempCtx, content, config, ch) { +ui.prototype._drawTextContent_drawChar = function ( + tempCtx, + content, + config, + ch +) { // 标点禁则:不能在行首的标点 - var forbidStart = "))】》>﹞>)]»›〕〉}]」}〗』" + ",。?!:;·…,.?!:;、……~&@#~&@#"; + var forbidStart = + '))】》>﹞>)]»›〕〉}]」}〗』' + + ',。?!:;·…,.?!:;、……~&@#~&@#'; // 标点禁则:不能在行尾的标点 - var forbidEnd = "((【《<﹝<([«‹〔〈{[「{〖『"; + var forbidEnd = '((【《<﹝<([«‹〔〈{[「{〖『'; // \n, \\n if (ch == '\n' || (ch == '\\' && content.charAt(config.index) == 'n')) { @@ -1206,17 +1796,30 @@ ui.prototype._drawTextContent_drawChar = function (tempCtx, content, config, ch) } if (ch == '\\') { var c = content.charAt(config.index); - if (c == 'i') return this._drawTextContent_drawIcon(tempCtx, content, config); - if (c == 'c') return this._drawTextContent_changeFontSize(tempCtx, content, config); + if (c == 'i') + return this._drawTextContent_drawIcon(tempCtx, content, config); + if (c == 'c') + return this._drawTextContent_changeFontSize( + tempCtx, + content, + config + ); if (c == 'd' || c == 'e') { config.index++; if (c == 'd') config.bold = !config.bold; if (c == 'e') config.italic = !config.italic; - tempCtx.font = this._buildFont(config.currfont, config.bold, config.italic, config.font); + tempCtx.font = this._buildFont( + config.currfont, + config.bold, + config.italic, + config.font + ); return true; } - if (c == 'g') return this._drawTextContent_changeFont(tempCtx, content, config); - if (c == 'z') return this._drawTextContent_emptyChar(tempCtx, content, config); + if (c == 'g') + return this._drawTextContent_changeFont(tempCtx, content, config); + if (c == 'z') + return this._drawTextContent_emptyChar(tempCtx, content, config); } // 检查是不是自动换行 var charwidth = core.calWidth(tempCtx, ch) + config.letterSpacing; @@ -1230,14 +1833,24 @@ ui.prototype._drawTextContent_drawChar = function (tempCtx, content, config, ch) config.index -= ch.length; return this._drawTextContent_next(tempCtx, content, config); } - } else if (forbidEnd.indexOf(ch) >= 0 && config.index < content.length) { + } else if ( + forbidEnd.indexOf(ch) >= 0 && + config.index < content.length + ) { // --- 当前不应该换行;但是提前检查一下是否是行尾标点 var nextch = content.charAt(config.index); // 确认不是手动换行 - if (nextch != '\n' && !(nextch == '\\' && content.charAt(config.index + 1) == 'n')) { + if ( + nextch != '\n' && + !(nextch == '\\' && content.charAt(config.index + 1) == 'n') + ) { // 检查是否会换行 - var nextchwidth = core.calWidth(tempCtx, nextch) + config.letterSpacing; - if (config.offsetX + charwidth + nextchwidth > config.maxWidth) { + var nextchwidth = + core.calWidth(tempCtx, nextch) + config.letterSpacing; + if ( + config.offsetX + charwidth + nextchwidth > + config.maxWidth + ) { // 下一项会换行,因此在此处换行 this._drawTextContent_newLine(tempCtx, config); config.index -= ch.length; @@ -1248,25 +1861,28 @@ ui.prototype._drawTextContent_drawChar = function (tempCtx, content, config, ch) } // 输出 - var left = config.offsetX, top = config.offsetY + config.topMargin; + var left = config.offsetX, + top = config.offsetY + config.topMargin; core.fillText(tempCtx, ch, left, top); config.blocks.push({ - left: config.offsetX, top: config.offsetY, - width: charwidth, height: config.currfont + config.lineMargin, - line: config.line, marginLeft: 0 + left: config.offsetX, + top: config.offsetY, + width: charwidth, + height: config.currfont + config.lineMargin, + line: config.line, + marginLeft: 0 }); config.offsetX += charwidth; return true; -} +}; ui.prototype._drawTextContent_newLine = function (tempCtx, config) { // 计算偏移量 - var width = config.offsetX, totalWidth = config.right - config.left; + var width = config.offsetX, + totalWidth = config.right - config.left; var marginLeft = 0; - if (config.align == 'center') - marginLeft = (totalWidth - width) / 2; - else if (config.align == 'right') - marginLeft = totalWidth - width; + if (config.align == 'center') marginLeft = (totalWidth - width) / 2; + else if (config.align == 'right') marginLeft = totalWidth - width; config.blocks.forEach(function (b) { if (b == null) return; @@ -1283,56 +1899,91 @@ ui.prototype._drawTextContent_newLine = function (tempCtx, config) { config.lineMaxHeight = config.currfont + config.lineMargin; config.line++; config.forceChangeLine = false; -} +}; -ui.prototype._drawTextContent_changeColor = function (tempCtx, content, config) { +ui.prototype._drawTextContent_changeColor = function ( + tempCtx, + content, + config +) { // 检查是不是 [] - var index = config.index, index2; - if (content.charAt(index) == '[' && ((index2 = content.indexOf(']', index)) >= 0)) { + var index = config.index, + index2; + if ( + content.charAt(index) == '[' && + (index2 = content.indexOf(']', index)) >= 0 + ) { // 变色 var str = content.substring(index + 1, index2); - if (str == "") tempCtx.fillStyle = config.color; + if (str == '') tempCtx.fillStyle = config.color; else tempCtx.fillStyle = str; config.index = index2 + 1; - } - else tempCtx.fillStyle = config.color; + } else tempCtx.fillStyle = config.color; return this._drawTextContent_next(tempCtx, content, config); -} +}; -ui.prototype._drawTextContent_changeFontSize = function (tempCtx, content, config) { +ui.prototype._drawTextContent_changeFontSize = function ( + tempCtx, + content, + config +) { config.index++; // 检查是不是 [] - var index = config.index, index2; - if (content.charAt(index) == '[' && ((index2 = content.indexOf(']', index)) >= 0)) { + var index = config.index, + index2; + if ( + content.charAt(index) == '[' && + (index2 = content.indexOf(']', index)) >= 0 + ) { var str = content.substring(index + 1, index2); if (!/^\d+$/.test(str)) config.currfont = config.fontSize; else config.currfont = parseInt(str); config.index = index2 + 1; - } - else config.currfont = config.fontSize; - config.lineMaxHeight = Math.max(config.lineMaxHeight, config.currfont + config.lineMargin); - tempCtx.font = this._buildFont(config.currfont, config.bold, config.italic, config.font); + } else config.currfont = config.fontSize; + config.lineMaxHeight = Math.max( + config.lineMaxHeight, + config.currfont + config.lineMargin + ); + tempCtx.font = this._buildFont( + config.currfont, + config.bold, + config.italic, + config.font + ); return this._drawTextContent_next(tempCtx, content, config); -} +}; ui.prototype._drawTextContent_changeFont = function (tempCtx, content, config) { config.index++; // 检查是不是 [] - var index = config.index, index2; - if (content.charAt(index) == '[' && ((index2 = content.indexOf(']', index)) >= 0)) { + var index = config.index, + index2; + if ( + content.charAt(index) == '[' && + (index2 = content.indexOf(']', index)) >= 0 + ) { var str = content.substring(index + 1, index2); - if (str == "") config.font = config.defaultFont; + if (str == '') config.font = config.defaultFont; else config.font = str; config.index = index2 + 1; } else config.font = config.defaultFont; - tempCtx.font = this._buildFont(config.currfont, config.bold, config.italic, config.font); + tempCtx.font = this._buildFont( + config.currfont, + config.bold, + config.italic, + config.font + ); return this._drawTextContent_next(tempCtx, content, config); -} +}; ui.prototype._drawTextContent_emptyChar = function (tempCtx, content, config) { config.index++; - var index = config.index, index2; - if (content.charAt(index) == '[' && ((index2 = content.indexOf(']', index)) >= 0)) { + var index = config.index, + index2; + if ( + content.charAt(index) == '[' && + (index2 = content.indexOf(']', index)) >= 0 + ) { var str = content.substring(index + 1, index2); if (/^\d+$/.test(str)) { var value = parseInt(str); @@ -1341,22 +1992,30 @@ ui.prototype._drawTextContent_emptyChar = function (tempCtx, content, config) { } } else config.blocks.push(null); config.index = index2 + 1; - } - else config.blocks.push(null); + } else config.blocks.push(null); return this._drawTextContent_next(tempCtx, content, config); -} +}; ui.prototype._drawTextContent_drawIcon = function (tempCtx, content, config) { // 绘制一个 \i 效果 - var index = config.index, index2; - if (content.charAt(config.index + 1) == '[' && ((index2 = content.indexOf(']', index + 1)) >= 0)) { + var index = config.index, + index2; + if ( + content.charAt(config.index + 1) == '[' && + (index2 = content.indexOf(']', index + 1)) >= 0 + ) { var str = core.replaceText(content.substring(index + 2, index2)); // --- 获得图标 var cls = core.getClsFromId(str) || ''; - var iconInfo = core.ui._getDrawableIconInfo(str), image = iconInfo[0], icon = iconInfo[1]; - if (image == null) return this._drawTextContent_next(tempCtx, content, config); + var iconInfo = core.ui._getDrawableIconInfo(str), + image = iconInfo[0], + icon = iconInfo[1]; + if (image == null) + return this._drawTextContent_next(tempCtx, content, config); // 检查自动换行 - var width = config.currfont + 2, left = config.offsetX + 2, top = config.offsetY + config.topMargin - 1; + var width = config.currfont + 2, + left = config.offsetX + 2, + top = config.offsetY + config.topMargin - 1; if (config.maxWidth != null && left + width > config.maxWidth) { this._drawTextContent_newLine(tempCtx, config); config.index--; @@ -1365,12 +2024,26 @@ ui.prototype._drawTextContent_drawIcon = function (tempCtx, content, config) { // 绘制到画布上 var height = 32; if (cls.endsWith('48')) height = 48; - core.drawImage(tempCtx, image, 0, height * icon, 32, height, left, top, width, height === 48 ? width * 1.5 : width); + core.drawImage( + tempCtx, + image, + 0, + height * icon, + 32, + height, + left, + top, + width, + height === 48 ? width * 1.5 : width + ); config.blocks.push({ - left: left, top: config.offsetY, - width: width, height: width + config.lineMargin, - line: config.line, marginLeft: 0 + left: left, + top: config.offsetY, + width: width, + height: width + config.lineMargin, + line: config.line, + marginLeft: 0 }); config.offsetX += width + 6; @@ -1378,20 +2051,27 @@ ui.prototype._drawTextContent_drawIcon = function (tempCtx, content, config) { return true; } return this._drawTextContent_next(tempCtx, content, config); -} +}; ui.prototype.getTextContentHeight = function (content, config) { return this.drawTextContent(null, content, config).offsetY; -} +}; ui.prototype._getRealContent = function (content) { - return content.replace(/(\r|\\(r|c|d|e|g|z))(\[.*?])?/g, "").replace(/(\\i)(\[.*?])?/g, "占1"); -} + return content + .replace(/(\r|\\(r|c|d|e|g|z))(\[.*?])?/g, '') + .replace(/(\\i)(\[.*?])?/g, '占1'); +}; ui.prototype._animateUI = function (type, ctx, callback) { ctx = ctx || 'ui'; var time = core.status.textAttribute.animateTime || 0; - if (!core.status.event || !time || core.isReplaying() || (type != 'show' && type != 'hide')) { + if ( + !core.status.event || + !time || + core.isReplaying() || + (type != 'show' && type != 'hide') + ) { if (callback) callback(); return; } @@ -1415,7 +2095,7 @@ ui.prototype._animateUI = function (type, ctx, callback) { if (callback) callback(); } }, time / 20); -} +}; ////// 绘制一个对话框 ////// ui.prototype.drawTextBox = function (content, config) { @@ -1434,7 +2114,8 @@ ui.prototype.drawTextBox = function (content, config) { var textAttribute = core.status.textAttribute; var titleInfo = this._getTitleAndIcon(content); var posInfo = this._getPosition(titleInfo.content); - if (posInfo.position != 'up' && posInfo.position != 'down') posInfo.px = posInfo.py = null; + if (posInfo.position != 'up' && posInfo.position != 'down') + posInfo.px = posInfo.py = null; if (!posInfo.position) posInfo.position = textAttribute.position; content = this._drawTextBox_drawImages(posInfo.content, config.ctx); if (config.pos) { @@ -1445,8 +2126,17 @@ ui.prototype.drawTextBox = function (content, config) { posInfo.ctx = ctx; // Step 2: 计算对话框的矩形位置 - var hPos = this._drawTextBox_getHorizontalPosition(content, titleInfo, posInfo); - var vPos = this._drawTextBox_getVerticalPosition(content, titleInfo, posInfo, hPos.validWidth); + var hPos = this._drawTextBox_getHorizontalPosition( + content, + titleInfo, + posInfo + ); + var vPos = this._drawTextBox_getVerticalPosition( + content, + titleInfo, + posInfo, + hPos.validWidth + ); posInfo.xoffset = hPos.xoffset; posInfo.yoffset = vPos.yoffset - 4; @@ -1456,109 +2146,211 @@ ui.prototype.drawTextBox = function (content, config) { } // Step 3: 绘制背景图 - var isWindowSkin = this.drawBackground(hPos.left, vPos.top, hPos.right, vPos.bottom, posInfo); - var alpha = isWindowSkin ? this._drawWindowSkin_getOpacity() : textAttribute.background[3]; + var isWindowSkin = this.drawBackground( + hPos.left, + vPos.top, + hPos.right, + vPos.bottom, + posInfo + ); + var alpha = isWindowSkin + ? this._drawWindowSkin_getOpacity() + : textAttribute.background[3]; // Step 4: 绘制标题、头像、动画 - var content_top = this._drawTextBox_drawTitleAndIcon(titleInfo, hPos, vPos, alpha, config.ctx); + var content_top = this._drawTextBox_drawTitleAndIcon( + titleInfo, + hPos, + vPos, + alpha, + config.ctx + ); // Step 5: 绘制正文 var config = this.drawTextContent(config.ctx || 'ui', content, { - left: hPos.content_left, top: content_top, maxWidth: hPos.validWidth, - lineHeight: vPos.lineHeight, time: (config.showAll || config.async || textAttribute.time <= 0 || core.status.event.id != 'action') ? 0 : textAttribute.time + left: hPos.content_left, + top: content_top, + maxWidth: hPos.validWidth, + lineHeight: vPos.lineHeight, + time: + config.showAll || + config.async || + textAttribute.time <= 0 || + core.status.event.id != 'action' + ? 0 + : textAttribute.time }); // Step 6: 绘制光标 if (main.mode == 'play') { main.dom.next.style.display = 'block'; - main.dom.next.style.borderRightColor = main.dom.next.style.borderBottomColor = core.arrayToRGB(textAttribute.text); - main.dom.next.style.top = (vPos.bottom - 20) * core.domStyle.scale + "px"; + main.dom.next.style.borderRightColor = + main.dom.next.style.borderBottomColor = core.arrayToRGB( + textAttribute.text + ); + main.dom.next.style.top = + (vPos.bottom - 20) * core.domStyle.scale + 'px'; var left = (hPos.left + hPos.right) / 2; - if (posInfo.position == 'up' && !posInfo.noPeak && posInfo.px != null && Math.abs(posInfo.px * 32 + 16 - left) < 50) + if ( + posInfo.position == 'up' && + !posInfo.noPeak && + posInfo.px != null && + Math.abs(posInfo.px * 32 + 16 - left) < 50 + ) left = hPos.right - 64; - main.dom.next.style.left = left * core.domStyle.scale + "px"; + main.dom.next.style.left = left * core.domStyle.scale + 'px'; } return config; -} +}; ui.prototype._drawTextBox_drawImages = function (content, ctx) { ctx = ctx || 'ui'; return content.replace(/(\f|\\f)\[(.*?)]/g, function (text, sympol, str) { - var ss = str.split(","); + var ss = str.split(','); // 绘制 if (ss.length == 3) core.drawImage(ctx, ss[0], parseFloat(ss[1]), parseFloat(ss[2])); else if (ss.length == 5) - core.drawImage(ctx, ss[0], parseFloat(ss[1]), parseFloat(ss[2]), parseFloat(ss[3]), parseFloat(ss[4])); + core.drawImage( + ctx, + ss[0], + parseFloat(ss[1]), + parseFloat(ss[2]), + parseFloat(ss[3]), + parseFloat(ss[4]) + ); else if (ss.length >= 9) { if (ss.length >= 10) core.setAlpha(ctx, parseFloat(ss[9])); - var angle = (parseFloat(ss[10]) || 0) * Math.PI / 180; - core.drawImage(ctx, ss[0], parseFloat(ss[1]), parseFloat(ss[2]), parseFloat(ss[3]), parseFloat(ss[4]), - parseFloat(ss[5]), parseFloat(ss[6]), parseFloat(ss[7]), parseFloat(ss[8]), angle); + var angle = ((parseFloat(ss[10]) || 0) * Math.PI) / 180; + core.drawImage( + ctx, + ss[0], + parseFloat(ss[1]), + parseFloat(ss[2]), + parseFloat(ss[3]), + parseFloat(ss[4]), + parseFloat(ss[5]), + parseFloat(ss[6]), + parseFloat(ss[7]), + parseFloat(ss[8]), + angle + ); core.setAlpha(ctx, 1); } - return ""; + return ''; }); -} +}; -ui.prototype._drawTextBox_getHorizontalPosition = function (content, titleInfo, posInfo) { +ui.prototype._drawTextBox_getHorizontalPosition = function ( + content, + titleInfo, + posInfo +) { var ctx = posInfo.ctx || 'ui'; var realContent = this._getRealContent(content); - var paddingLeft = 25, paddingRight = 12; - if ((posInfo.px != null && posInfo.py != null) || posInfo.pos) paddingLeft = 20; + var paddingLeft = 25, + paddingRight = 12; + if ((posInfo.px != null && posInfo.py != null) || posInfo.pos) + paddingLeft = 20; if (titleInfo.icon != null) paddingLeft = 62; // 15 + 32 + 15 else if (titleInfo.image) paddingLeft = 90; // 10 + 70 + 10 - var left = 7 + 3 * (core._HALF_WIDTH_ - 6), right = core._PX_ - left, - width = right - left, validWidth = width - paddingLeft - paddingRight; + var left = 7 + 3 * (core._HALF_WIDTH_ - 6), + right = core._PX_ - left, + width = right - left, + validWidth = width - paddingLeft - paddingRight; // 对话框效果:改为动态计算 if ((posInfo.px != null && posInfo.py != null) || posInfo.pos) { - var min_width = 220 - paddingLeft, max_width = validWidth; + var min_width = 220 - paddingLeft, + max_width = validWidth; // 无行走图或头像,则可以适当缩小min_width if (titleInfo.image == null) min_width = 160; if (titleInfo.title) { - min_width = core.clamp(core.calWidth(ctx, titleInfo.title, this._buildFont(core.status.textAttribute.titlefont, true)), min_width, max_width); + min_width = core.clamp( + core.calWidth( + ctx, + titleInfo.title, + this._buildFont(core.status.textAttribute.titlefont, true) + ), + min_width, + max_width + ); } if (posInfo.pos) { left = core.calValue(posInfo.pos[0]) || 0; - max_width = Math.max(min_width, right - left - paddingLeft - paddingRight); + max_width = Math.max( + min_width, + right - left - paddingLeft - paddingRight + ); } else left = null; if (posInfo.pos && posInfo.pos[2] != null) { width = core.calValue(posInfo.pos[2]) || 0; min_width = validWidth = width - paddingLeft - paddingRight; } else validWidth = 0; if (validWidth < min_width) { - validWidth = this._calTextBoxWidth('ui', realContent, min_width, max_width, this._buildFont()); + validWidth = this._calTextBoxWidth( + 'ui', + realContent, + min_width, + max_width, + this._buildFont() + ); width = validWidth + paddingLeft + paddingRight; } - if (left == null) left = core.clamp(32 * posInfo.px + 16 - width / 2 - core.bigmap.offsetX, left, right - width); + if (left == null) + left = core.clamp( + 32 * posInfo.px + 16 - width / 2 - core.bigmap.offsetX, + left, + right - width + ); right = left + width; } - return { left: left, right: right, width: width, validWidth: validWidth, xoffset: 11, content_left: left + paddingLeft }; -} + return { + left: left, + right: right, + width: width, + validWidth: validWidth, + xoffset: 11, + content_left: left + paddingLeft + }; +}; -ui.prototype._drawTextBox_getVerticalPosition = function (content, titleInfo, posInfo, validWidth) { - var textAttribute = core.status.textAttribute || core.initStatus.textAttribute; - var lineHeight = textAttribute.lineHeight || (textAttribute.textfont + 6); - var height = 45 + this.getTextContentHeight(content, { - lineHeight: lineHeight, maxWidth: validWidth - }); +ui.prototype._drawTextBox_getVerticalPosition = function ( + content, + titleInfo, + posInfo, + validWidth +) { + var textAttribute = + core.status.textAttribute || core.initStatus.textAttribute; + var lineHeight = textAttribute.lineHeight || textAttribute.textfont + 6; + var height = + 45 + + this.getTextContentHeight(content, { + lineHeight: lineHeight, + maxWidth: validWidth + }); if (titleInfo.title) height += textAttribute.titlefont + 5; if (titleInfo.icon != null) { if (titleInfo.title) height = Math.max(height, titleInfo.height + 50); else height = Math.max(height, titleInfo.height + 30); - } - else if (titleInfo.image) - height = Math.max(height, 90); + } else if (titleInfo.image) height = Math.max(height, 90); var yoffset = 16; var top = parseInt((core._PY_ - height) / 2); switch (posInfo.position) { - case 'center': top = parseInt((core._PY_ - height) / 2); break; + case 'center': + top = parseInt((core._PY_ - height) / 2); + break; case 'up': if (posInfo.px == null || posInfo.py == null) top = 5 + textAttribute.offset; else - top = 32 * posInfo.py - height - (titleInfo.height - 32) - yoffset - core.bigmap.offsetY; + top = + 32 * posInfo.py - + height - + (titleInfo.height - 32) - + yoffset - + core.bigmap.offsetY; break; case 'down': if (posInfo.px == null || posInfo.py == null) @@ -1571,10 +2363,22 @@ ui.prototype._drawTextBox_getVerticalPosition = function (content, titleInfo, po top = core.calValue(posInfo.pos[1]) || 0; } - return { top: top, height: height, bottom: top + height, yoffset: yoffset, lineHeight: lineHeight }; -} + return { + top: top, + height: height, + bottom: top + height, + yoffset: yoffset, + lineHeight: lineHeight + }; +}; -ui.prototype._drawTextBox_drawTitleAndIcon = function (titleInfo, hPos, vPos, alpha, ctx) { +ui.prototype._drawTextBox_drawTitleAndIcon = function ( + titleInfo, + hPos, + vPos, + alpha, + ctx +) { ctx = ctx || 'ui'; core.setTextAlign(ctx, 'left'); var textAttribute = core.status.textAttribute; @@ -1588,18 +2392,35 @@ ui.prototype._drawTextBox_drawTitleAndIcon = function (titleInfo, hPos, vPos, al core.setStrokeStyle(ctx, core.arrayToRGB(textAttribute.title)); // --- title也要居中或者右对齐? - var title_width = core.calWidth(ctx, titleInfo.title, this._buildFont(titlefont, true)); + var title_width = core.calWidth( + ctx, + titleInfo.title, + this._buildFont(titlefont, true) + ); var title_left = hPos.content_left; if (textAttribute.align == 'center') title_left = hPos.left + (hPos.width - title_width) / 2; else if (textAttribute.align == 'right') title_left = hPos.right - title_width - 12; - core.fillText(ctx, titleInfo.title, title_left, vPos.top + 8 + titlefont); + core.fillText( + ctx, + titleInfo.title, + title_left, + vPos.top + 8 + titlefont + ); } if (titleInfo.icon != null) { core.setAlpha(ctx, alpha); - core.strokeRect(ctx, hPos.left + 15 - 1, image_top - 1, 34, titleInfo.height + 2, null, 2); + core.strokeRect( + ctx, + hPos.left + 15 - 1, + image_top - 1, + 34, + titleInfo.height + 2, + null, + 2 + ); core.setAlpha(ctx, 1); core.status.boxAnimateObjs = []; // --- 勇士 @@ -1608,69 +2429,131 @@ ui.prototype._drawTextBox_drawTitleAndIcon = function (titleInfo, hPos, vPos, al var direction = core.getHeroLoc('direction'); if (direction == 'up') direction = 'down'; core.status.boxAnimateObjs.push({ - 'bgx': hPos.left + 15, 'bgy': image_top, 'bgWidth': 32, 'bgHeight': titleInfo.height, - 'x': hPos.left + 15, 'y': image_top, 'height': titleInfo.height, 'animate': 4, - 'image': titleInfo.image, 'pos': core.material.icons.hero[direction].loc * titleInfo.height, ctx: ctx, - }) + bgx: hPos.left + 15, + bgy: image_top, + bgWidth: 32, + bgHeight: titleInfo.height, + x: hPos.left + 15, + y: image_top, + height: titleInfo.height, + animate: 4, + image: titleInfo.image, + pos: + core.material.icons.hero[direction].loc * + titleInfo.height, + ctx: ctx + }); } else { - core.clearMap(ctx, hPos.left + 15, image_top, 32, titleInfo.height); - core.fillRect(ctx, hPos.left + 15, image_top, 32, titleInfo.height, core.material.groundPattern); - core.drawImage(ctx, titleInfo.image, 0, 0, core.material.icons.hero.width || 32, core.material.icons.hero.height, - hPos.left + 15, image_top, 32, titleInfo.height); + core.clearMap( + ctx, + hPos.left + 15, + image_top, + 32, + titleInfo.height + ); + core.fillRect( + ctx, + hPos.left + 15, + image_top, + 32, + titleInfo.height, + core.material.groundPattern + ); + core.drawImage( + ctx, + titleInfo.image, + 0, + 0, + core.material.icons.hero.width || 32, + core.material.icons.hero.height, + hPos.left + 15, + image_top, + 32, + titleInfo.height + ); } - } - else { + } else { if (titleInfo.bigImage) { core.status.boxAnimateObjs.push({ - bigImage: titleInfo.bigImage, face: titleInfo.face, centerX: hPos.left + 15 + 16, - centerY: image_top + titleInfo.height / 2, max_width: 50, ctx: ctx + bigImage: titleInfo.bigImage, + face: titleInfo.face, + centerX: hPos.left + 15 + 16, + centerY: image_top + titleInfo.height / 2, + max_width: 50, + ctx: ctx }); } else { core.status.boxAnimateObjs.push({ - 'bgx': hPos.left + 15, 'bgy': image_top, 'bgWidth': 32, 'bgHeight': titleInfo.height, - 'x': hPos.left + 15, 'y': image_top, 'height': titleInfo.height, 'animate': titleInfo.animate, - 'image': titleInfo.image, 'pos': titleInfo.icon * titleInfo.height, ctx: ctx, + bgx: hPos.left + 15, + bgy: image_top, + bgWidth: 32, + bgHeight: titleInfo.height, + x: hPos.left + 15, + y: image_top, + height: titleInfo.height, + animate: titleInfo.animate, + image: titleInfo.image, + pos: titleInfo.icon * titleInfo.height, + ctx: ctx }); } } core.drawBoxAnimate(); } - if (titleInfo.image != null && titleInfo.icon == null) { // 头像图 - core.drawImage(ctx, titleInfo.image, 0, 0, titleInfo.image.width, titleInfo.image.height, - hPos.left + 10, vPos.top + 10, 70, 70); + if (titleInfo.image != null && titleInfo.icon == null) { + // 头像图 + core.drawImage( + ctx, + titleInfo.image, + 0, + 0, + titleInfo.image.width, + titleInfo.image.height, + hPos.left + 10, + vPos.top + 10, + 70, + 70 + ); } return content_top; -} +}; ui.prototype._createTextCanvas = function (content, lineHeight) { - var width = core._PX_, height = 30 + this.getTextContentHeight(content, { lineHeight: lineHeight }); + var width = core._PX_, + height = + 30 + this.getTextContentHeight(content, { lineHeight: lineHeight }); var ctx = document.createElement('canvas').getContext('2d'); ctx.canvas.width = width; ctx.canvas.height = height; ctx.clearRect(0, 0, width, height); return ctx; -} +}; ////// 绘制滚动字幕 ////// ui.prototype.drawScrollText = function (content, time, lineHeight, callback) { - content = core.replaceText(content || ""); + content = core.replaceText(content || ''); lineHeight = lineHeight || 1.4; time = time || 5000; this.clearUI(); var offset = core.status.textAttribute.offset || 15; lineHeight *= core.status.textAttribute.textfont; var ctx = this._createTextCanvas(content, lineHeight); - var obj = { align: core.status.textAttribute.align, lineHeight: lineHeight }; + var obj = { + align: core.status.textAttribute.align, + lineHeight: lineHeight + }; if (obj.align == 'right') obj.left = core._PX_ - offset; else if (obj.align != 'center') obj.left = offset; this.drawTextContent(ctx, content, obj); this._drawScrollText_animate(ctx, time, callback); -} +}; ui.prototype._drawScrollText_animate = function (ctx, time, callback) { // 开始绘制到UI上 - time /= Math.max(core.status.replay.speed, 1) - var per_pixel = 1, height = ctx.canvas.height, per_time = time * per_pixel / (core._PY_ + height); + time /= Math.max(core.status.replay.speed, 1); + var per_pixel = 1, + height = ctx.canvas.height, + per_time = (time * per_pixel) / (core._PY_ + height); var currH = core._PY_; core.drawImage('ui', ctx.canvas, 0, currH); var animate = setInterval(function () { @@ -1687,59 +2570,98 @@ ui.prototype._drawScrollText_animate = function (ctx, time, callback) { core.animateFrame.lastAsyncId = animate; core.animateFrame.asyncId[animate] = callback; -} +}; ////// 文本图片化 ////// ui.prototype.textImage = function (content, lineHeight) { - content = core.replaceText(content || ""); + content = core.replaceText(content || ''); lineHeight = lineHeight || 1.4; lineHeight *= core.status.textAttribute.textfont; var ctx = this._createTextCanvas(content, lineHeight); - this.drawTextContent(ctx, content, { align: core.status.textAttribute.align, lineHeight: lineHeight }); + this.drawTextContent(ctx, content, { + align: core.status.textAttribute.align, + lineHeight: lineHeight + }); return ctx.canvas; -} +}; ////// 绘制一个选项界面 ////// ui.prototype.drawChoices = function (content, choices, width, ctx) { choices = core.clone(choices || []); - core.status.event.ui = { "text": content, "choices": choices, "width": width }; + core.status.event.ui = { text: content, choices: choices, width: width }; this.clearUI(); - content = core.replaceText(content || ""); + content = core.replaceText(content || ''); var titleInfo = this._getTitleAndIcon(content); titleInfo.content = this._drawTextBox_drawImages(titleInfo.content, ctx); - var hPos = this._drawChoices_getHorizontalPosition(titleInfo, choices, width, ctx); + var hPos = this._drawChoices_getHorizontalPosition( + titleInfo, + choices, + width, + ctx + ); var vPos = this._drawChoices_getVerticalPosition(titleInfo, choices, hPos); core.status.event.ui.offset = vPos.offset; - var isWindowSkin = this.drawBackground(hPos.left, vPos.top, hPos.right, vPos.bottom, { ctx: ctx }); + var isWindowSkin = this.drawBackground( + hPos.left, + vPos.top, + hPos.right, + vPos.bottom, + { ctx: ctx } + ); this._drawChoices_drawTitle(titleInfo, hPos, vPos, ctx); this._drawChoices_drawChoices(choices, isWindowSkin, hPos, vPos, ctx); -} +}; -ui.prototype._drawChoices_getHorizontalPosition = function (titleInfo, choices, width, ctx) { +ui.prototype._drawChoices_getHorizontalPosition = function ( + titleInfo, + choices, + width, + ctx +) { ctx = ctx || 'ui'; // 宽度计算:考虑提示文字和选项的长度 core.setFont(ctx, this._buildFont(17, true)); - var width = this._calTextBoxWidth(ctx, titleInfo.content || "", width || 246, core._PX_ - 20); + var width = this._calTextBoxWidth( + ctx, + titleInfo.content || '', + width || 246, + core._PX_ - 20 + ); for (var i = 0; i < choices.length; i++) { - if (typeof choices[i] === 'string') - choices[i] = { "text": choices[i] }; + if (typeof choices[i] === 'string') choices[i] = { text: choices[i] }; choices[i].text = core.replaceText(choices[i].text); - choices[i].width = core.calWidth(ctx, core.replaceText(choices[i].text)); + choices[i].width = core.calWidth( + ctx, + core.replaceText(choices[i].text) + ); if (choices[i].icon != null) choices[i].width += 28; width = Math.max(width, choices[i].width + 30); } - var left = (core._PX_ - width) / 2, right = left + width; - var content_left = left + (titleInfo.icon == null ? 15 : 60), validWidth = right - content_left - 10; + var left = (core._PX_ - width) / 2, + right = left + width; + var content_left = left + (titleInfo.icon == null ? 15 : 60), + validWidth = right - content_left - 10; - return { left: left, right: right, width: width, content_left: content_left, validWidth: validWidth }; -} + return { + left: left, + right: right, + width: width, + content_left: content_left, + validWidth: validWidth + }; +}; -ui.prototype._drawChoices_getVerticalPosition = function (titleInfo, choices, hPos) { +ui.prototype._drawChoices_getVerticalPosition = function ( + titleInfo, + choices, + hPos +) { var length = choices.length; - var height = 32 * (length + 2), bottom = core._PY_ / 2 + height / 2; + var height = 32 * (length + 2), + bottom = core._PY_ / 2 + height / 2; if (length % 2 == 0) bottom += 16; var offset = 0; var choice_top = bottom - height + 56; @@ -1747,7 +2669,10 @@ ui.prototype._drawChoices_getVerticalPosition = function (titleInfo, choices, hP var headHeight = 0; if (titleInfo.title) headHeight += 25; headHeight += this.getTextContentHeight(titleInfo.content, { - lineHeight: 20, maxWidth: hPos.validWidth, fontSize: 15, bold: true + lineHeight: 20, + maxWidth: hPos.validWidth, + fontSize: 15, + bold: true }); height += headHeight; if (bottom - height <= 32) { @@ -1756,8 +2681,14 @@ ui.prototype._drawChoices_getVerticalPosition = function (titleInfo, choices, hP choice_top += 32 * offset; } } - return { top: bottom - height, height: height, bottom: bottom, choice_top: choice_top, offset: offset }; -} + return { + top: bottom - height, + height: height, + bottom: bottom, + choice_top: choice_top, + offset: offset + }; +}; ui.prototype._drawChoices_drawTitle = function (titleInfo, hPos, vPos, ctx) { if (!titleInfo.content) return; @@ -1772,81 +2703,163 @@ ui.prototype._drawChoices_drawTitle = function (titleInfo, hPos, vPos, ctx) { if (titleInfo.icon != null) { title_offset += 12; - core.strokeRect(ctx, hPos.left + 15 - 1, vPos.top + 30 - 1, 34, titleInfo.height + 2, '#DDDDDD', 2); + core.strokeRect( + ctx, + hPos.left + 15 - 1, + vPos.top + 30 - 1, + 34, + titleInfo.height + 2, + '#DDDDDD', + 2 + ); core.status.boxAnimateObjs = []; if (titleInfo.bigImage) { core.status.boxAnimateObjs.push({ - bigImage: titleInfo.bigImage, face: titleInfo.face, centerX: hPos.left + 15 + 16, - centerY: vPos.top + 30 + titleInfo.height / 2, max_width: 50, ctx: ctx + bigImage: titleInfo.bigImage, + face: titleInfo.face, + centerX: hPos.left + 15 + 16, + centerY: vPos.top + 30 + titleInfo.height / 2, + max_width: 50, + ctx: ctx }); } else { core.status.boxAnimateObjs.push({ - 'bgx': hPos.left + 15, 'bgy': vPos.top + 30, 'bgWidth': 32, 'bgHeight': titleInfo.height, - 'x': hPos.left + 15, 'y': vPos.top + 30, 'height': titleInfo.height, 'animate': titleInfo.animate, - 'image': titleInfo.image, 'pos': titleInfo.icon * titleInfo.height, ctx: ctx + bgx: hPos.left + 15, + bgy: vPos.top + 30, + bgWidth: 32, + bgHeight: titleInfo.height, + x: hPos.left + 15, + y: vPos.top + 30, + height: titleInfo.height, + animate: titleInfo.animate, + image: titleInfo.image, + pos: titleInfo.icon * titleInfo.height, + ctx: ctx }); } core.drawBoxAnimate(); - }; + } - core.fillText(ctx, titleInfo.title, title_offset, vPos.top + 27, - core.arrayToRGBA(core.status.textAttribute.title), this._buildFont(19, true)); + core.fillText( + ctx, + titleInfo.title, + title_offset, + vPos.top + 27, + core.arrayToRGBA(core.status.textAttribute.title), + this._buildFont(19, true) + ); } core.setTextAlign(ctx, 'left'); this.drawTextContent(ctx, titleInfo.content, { - left: hPos.content_left, top: content_top, maxWidth: hPos.validWidth, - fontSize: 15, lineHeight: 20, bold: true + left: hPos.content_left, + top: content_top, + maxWidth: hPos.validWidth, + fontSize: 15, + lineHeight: 20, + bold: true }); -} +}; -ui.prototype._drawChoices_drawChoices = function (choices, isWindowSkin, hPos, vPos, ctx) { +ui.prototype._drawChoices_drawChoices = function ( + choices, + isWindowSkin, + hPos, + vPos, + ctx +) { var hasCtx = ctx != null; ctx = ctx || 'ui'; // 选项 core.setTextAlign(ctx, 'center'); core.setFont(ctx, this._buildFont(17, true)); for (var i = 0; i < choices.length; i++) { - var color = core.arrayToRGBA(choices[i].color || core.status.textAttribute.text); - if (main.mode == 'play' && choices[i].need != null && choices[i].need != '' && !core.calValue(choices[i].need)) color = '#999999'; + var color = core.arrayToRGBA( + choices[i].color || core.status.textAttribute.text + ); + if ( + main.mode == 'play' && + choices[i].need != null && + choices[i].need != '' && + !core.calValue(choices[i].need) + ) + color = '#999999'; core.setFillStyle(ctx, color); var offset = core._PX_ / 2; if (choices[i].icon) { - var iconInfo = this._getDrawableIconInfo(choices[i].icon), image = iconInfo[0], icon = iconInfo[1]; + var iconInfo = this._getDrawableIconInfo(choices[i].icon), + image = iconInfo[0], + icon = iconInfo[1]; if (image != null) { - core.drawImage(ctx, image, 0, 32 * icon, 32, 32, - core._PX_ / 2 - choices[i].width / 2, vPos.choice_top + 32 * i - 17, 22, 22); + core.drawImage( + ctx, + image, + 0, + 32 * icon, + 32, + 32, + core._PX_ / 2 - choices[i].width / 2, + vPos.choice_top + 32 * i - 17, + 22, + 22 + ); offset += 14; } } - core.fillText(ctx, choices[i].text, offset, vPos.choice_top + 32 * i, color); + core.fillText( + ctx, + choices[i].text, + offset, + vPos.choice_top + 32 * i, + color + ); } if (choices.length > 0 && core.status.event.selection != 'none') { core.status.event.selection = core.status.event.selection || 0; - while (core.status.event.selection < 0) core.status.event.selection += choices.length; - while (core.status.event.selection >= choices.length) core.status.event.selection -= choices.length; + while (core.status.event.selection < 0) + core.status.event.selection += choices.length; + while (core.status.event.selection >= choices.length) + core.status.event.selection -= choices.length; var len = choices[core.status.event.selection].width; if (isWindowSkin) { if (hasCtx) { - this._drawSelector(ctx, core.status.textAttribute.background, - len + 10, 28, core._PX_ / 2 - len / 2 - 5, vPos.choice_top + 32 * core.status.event.selection - 20); + this._drawSelector( + ctx, + core.status.textAttribute.background, + len + 10, + 28, + core._PX_ / 2 - len / 2 - 5, + vPos.choice_top + 32 * core.status.event.selection - 20 + ); } else { - this._drawWindowSelector(core.status.textAttribute.background, - core._PX_ / 2 - len / 2 - 5, vPos.choice_top + 32 * core.status.event.selection - 20, len + 10, 28); + this._drawWindowSelector( + core.status.textAttribute.background, + core._PX_ / 2 - len / 2 - 5, + vPos.choice_top + 32 * core.status.event.selection - 20, + len + 10, + 28 + ); } - } - else - core.strokeRoundRect(ctx, core._PX_ / 2 - len / 2 - 5, vPos.choice_top + 32 * core.status.event.selection - 20, - len + 10, 28, 6, core.status.globalAttribute.selectColor, 2); + } else + core.strokeRoundRect( + ctx, + core._PX_ / 2 - len / 2 - 5, + vPos.choice_top + 32 * core.status.event.selection - 20, + len + 10, + 28, + 6, + core.status.globalAttribute.selectColor, + 2 + ); } -} +}; ////// 绘制一个确认/取消的警告页面 ////// ui.prototype.drawConfirmBox = function (text, yesCallback, noCallback, ctx) { var hasCtx = ctx != null; ctx = ctx || 'ui'; - text = core.replaceText(text || ""); + text = core.replaceText(text || ''); if (main.mode == 'play') { core.lockControl(); @@ -1855,196 +2868,301 @@ ui.prototype.drawConfirmBox = function (text, yesCallback, noCallback, ctx) { if (core.status.event.id != 'action') { core.status.event.id = 'confirmBox'; core.status.event.ui = text; - core.status.event.data = { 'yes': yesCallback, 'no': noCallback }; + core.status.event.data = { yes: yesCallback, no: noCallback }; } } - if (core.status.event.selection != 0 && core.status.event.selection != 'none') core.status.event.selection = 1; + if ( + core.status.event.selection != 0 && + core.status.event.selection != 'none' + ) + core.status.event.selection = 1; this.clearUI(); core.setFont(ctx, this._buildFont(19, true)); - var contents = text.split("\n"); + var contents = text.split('\n'); var rect = this._drawConfirmBox_getRect(contents, ctx); - var isWindowSkin = this.drawBackground(rect.left, rect.top, rect.right, rect.bottom, { ctx: ctx }); + var isWindowSkin = this.drawBackground( + rect.left, + rect.top, + rect.right, + rect.bottom, + { ctx: ctx } + ); core.setTextAlign(ctx, 'center'); - core.setFillStyle(ctx, core.arrayToRGBA(core.status.textAttribute.text)) + core.setFillStyle(ctx, core.arrayToRGBA(core.status.textAttribute.text)); for (var i in contents) { core.fillText(ctx, contents[i], core._PX_ / 2, rect.top + 50 + i * 30); } - core.fillText(ctx, "确定", core._PX_ / 2 - 38, rect.bottom - 35, null, this._buildFont(17, true)); - core.fillText(ctx, "取消", core._PX_ / 2 + 38, rect.bottom - 35); + core.fillText( + ctx, + '确定', + core._PX_ / 2 - 38, + rect.bottom - 35, + null, + this._buildFont(17, true) + ); + core.fillText(ctx, '取消', core._PX_ / 2 + 38, rect.bottom - 35); if (core.status.event.selection != 'none') { - var len = core.calWidth(ctx, "确定"); - var strokeLeft = core._PX_ / 2 + (76 * core.status.event.selection - 38) - parseInt(len / 2) - 5; + var len = core.calWidth(ctx, '确定'); + var strokeLeft = + core._PX_ / 2 + + (76 * core.status.event.selection - 38) - + parseInt(len / 2) - + 5; if (isWindowSkin) { if (hasCtx) { - this._drawSelector(ctx, core.status.textAttribute.background, - len + 10, 28, strokeLeft, rect.bottom - 35 - 20); + this._drawSelector( + ctx, + core.status.textAttribute.background, + len + 10, + 28, + strokeLeft, + rect.bottom - 35 - 20 + ); } else { - this._drawWindowSelector(core.status.textAttribute.background, strokeLeft, rect.bottom - 35 - 20, len + 10, 28); + this._drawWindowSelector( + core.status.textAttribute.background, + strokeLeft, + rect.bottom - 35 - 20, + len + 10, + 28 + ); } - } - else - core.strokeRoundRect(ctx, strokeLeft, rect.bottom - 35 - 20, len + 10, 28, 6, core.status.globalAttribute.selectColor, 2); + } else + core.strokeRoundRect( + ctx, + strokeLeft, + rect.bottom - 35 - 20, + len + 10, + 28, + 6, + core.status.globalAttribute.selectColor, + 2 + ); } -} +}; ui.prototype._drawConfirmBox_getRect = function (contents, ctx) { var max_width = contents.reduce(function (pre, curr) { return Math.max(pre, core.calWidth(ctx, curr)); }, 0); - var left = Math.min(core._PX_ / 2 - 40 - parseInt(max_width / 2), 100), right = core._PX_ - left; - var top = core._PY_ / 2 - 68 - (contents.length - 1) * 30, bottom = core._PY_ / 2 + 68; - return { top: top, left: left, bottom: bottom, right: right, width: right - left, height: bottom - top }; -} + var left = Math.min(core._PX_ / 2 - 40 - parseInt(max_width / 2), 100), + right = core._PX_ - left; + var top = core._PY_ / 2 - 68 - (contents.length - 1) * 30, + bottom = core._PY_ / 2 + 68; + return { + top: top, + left: left, + bottom: bottom, + right: right, + width: right - left, + height: bottom - top + }; +}; ////// 绘制等待界面 ////// ui.prototype.drawWaiting = function (text) { core.lockControl(); core.status.event.id = 'waiting'; core.clearUI(); - text = core.replaceText(text || ""); + text = core.replaceText(text || ''); var text_length = core.calWidth('ui', text, this._buildFont(19, true)); - var width = Math.max(text_length + 80, 220), left = core._PX_ / 2 - parseInt(width / 2), right = left + width; - var top = core._PY_ / 2 - 48, height = 96, bottom = top + height; + var width = Math.max(text_length + 80, 220), + left = core._PX_ / 2 - parseInt(width / 2), + right = left + width; + var top = core._PY_ / 2 - 48, + height = 96, + bottom = top + height; this.drawBackground(left, top, right, bottom); core.setTextAlign('ui', 'center'); - core.fillText('ui', text, core._PX_ / 2, top + 56, core.arrayToRGBA(core.status.textAttribute.text)); -} + core.fillText( + 'ui', + text, + core._PX_ / 2, + top + 56, + core.arrayToRGBA(core.status.textAttribute.text) + ); +}; ////// 绘制系统设置界面 ////// ui.prototype._drawSwitchs = function () { core.status.event.id = 'switchs'; - var choices = [ - "音效设置", - "显示设置", - "操作设置", - "返回主菜单" - ]; + var choices = ['音效设置', '显示设置', '操作设置', '返回主菜单']; this.drawChoices(null, choices); -} +}; ui.prototype._drawSwitchs_sounds = function () { core.status.event.id = 'switchs-sounds'; var choices = [ - "音乐: " + (core.musicStatus.bgmStatus ? "[ON]" : "[OFF]"), - "音效: " + (core.musicStatus.soundStatus ? "[ON]" : "[OFF]"), + '音乐: ' + (core.musicStatus.bgmStatus ? '[ON]' : '[OFF]'), + '音效: ' + (core.musicStatus.soundStatus ? '[ON]' : '[OFF]'), // 显示为 0~10 十挡 - " < 音量:" + Math.round(Math.sqrt(100 * core.musicStatus.userVolume)) + " > ", - "返回上一级" + ' < 音量:' + + Math.round(Math.sqrt(100 * core.musicStatus.userVolume)) + + ' > ', + '返回上一级' ]; this.drawChoices(null, choices); -} +}; ui.prototype._drawSwitchs_display = function () { core.status.event.id = 'switchs-display'; var choices = [ - " < 放缩:" + Math.max(core.domStyle.scale, 1) + "x > ", - "高清画面: " + (core.flags.enableHDCanvas ? "[ON]" : "[OFF]"), - "定点怪显: " + (core.flags.enableEnemyPoint ? "[ON]" : "[OFF]"), - "怪物显伤: " + (core.flags.displayEnemyDamage ? "[ON]" : "[OFF]"), - "临界显伤: " + (core.flags.displayCritical ? "[ON]" : "[OFF]"), - "领域显伤: " + (core.flags.displayExtraDamage ? "[ON]" : "[OFF]"), - "领域模式: " + (core.flags.extraDamageType == 2 ? "[最简]" : core.flags.extraDamageType == 1 ? "[半透明]" : "[完整]"), - "自动放缩: " + (core.getLocalStorage('autoScale') ? "[ON]" : "[OFF]"), - "返回上一级", + ' < 放缩:' + Math.max(core.domStyle.scale, 1) + 'x > ', + '高清画面: ' + (core.flags.enableHDCanvas ? '[ON]' : '[OFF]'), + '定点怪显: ' + (core.flags.enableEnemyPoint ? '[ON]' : '[OFF]'), + '怪物显伤: ' + (core.flags.displayEnemyDamage ? '[ON]' : '[OFF]'), + '临界显伤: ' + (core.flags.displayCritical ? '[ON]' : '[OFF]'), + '领域显伤: ' + (core.flags.displayExtraDamage ? '[ON]' : '[OFF]'), + '领域模式: ' + + (core.flags.extraDamageType == 2 + ? '[最简]' + : core.flags.extraDamageType == 1 + ? '[半透明]' + : '[完整]'), + '自动放缩: ' + (core.getLocalStorage('autoScale') ? '[ON]' : '[OFF]'), + '返回上一级' ]; this.drawChoices(null, choices); -} +}; ui.prototype._drawSwitchs_action = function () { core.status.event.id = 'switchs-action'; var choices = [ // 数值越大耗时越长 - " < 步时:" + core.values.moveSpeed + " > ", - " < 转场:" + core.values.floorChangeTime + " > ", - "血瓶绕路: " + (core.hasFlag('__potionNoRouting__') ? "[ON]" : "[OFF]"), - "单击瞬移: " + (!core.hasFlag("__noClickMove__") ? "[ON]" : "[OFF]"), - "左手模式: " + (core.flags.leftHandPrefer ? "[ON]" : "[OFF]"), - "返回上一级", + ' < 步时:' + core.values.moveSpeed + ' > ', + ' < 转场:' + core.values.floorChangeTime + ' > ', + '血瓶绕路: ' + + (core.hasFlag('__potionNoRouting__') ? '[ON]' : '[OFF]'), + '单击瞬移: ' + (!core.hasFlag('__noClickMove__') ? '[ON]' : '[OFF]'), + '左手模式: ' + (core.flags.leftHandPrefer ? '[ON]' : '[OFF]'), + '返回上一级' ]; this.drawChoices(null, choices); -} +}; ////// 绘制系统菜单栏 ////// ui.prototype._drawSettings = function () { core.status.event.id = 'settings'; this.drawChoices(null, [ - "系统设置", "虚拟键盘", "浏览地图", "存档笔记", "同步存档", "游戏信息", "返回标题", "返回游戏" + '系统设置', + '虚拟键盘', + '浏览地图', + '存档笔记', + '同步存档', + '游戏信息', + '返回标题', + '返回游戏' ]); -} +}; ////// 绘制存档笔记 ////// ui.prototype._drawNotes = function () { core.status.event.id = 'notes'; core.status.hero.notes = core.status.hero.notes || []; core.lockControl(); - this.drawChoices("存档笔记允许你写入和查看任何笔记(快捷键M),你可以用做任何标记,比如Boss前的属性、开门和路线选择等。", [ - "新增存档笔记", "查看存档笔记", "编辑存档笔记", "删除存档笔记", "返回上一页" - ]); -} + this.drawChoices( + '存档笔记允许你写入和查看任何笔记(快捷键M),你可以用做任何标记,比如Boss前的属性、开门和路线选择等。', + [ + '新增存档笔记', + '查看存档笔记', + '编辑存档笔记', + '删除存档笔记', + '返回上一页' + ] + ); +}; ////// 绘制快捷商店选择栏 ////// ui.prototype._drawQuickShop = function () { core.status.event.id = 'selectShop'; - var shopList = core.status.shops, keys = core.listShopIds(); + var shopList = core.status.shops, + keys = core.listShopIds(); var choices = keys.map(function (shopId) { - return { "text": shopList[shopId].textInList, "color": core.isShopVisited(shopId) ? null : "#999999" }; + return { + text: shopList[shopId].textInList, + color: core.isShopVisited(shopId) ? null : '#999999' + }; }); - choices.push("返回游戏"); + choices.push('返回游戏'); this.drawChoices(null, choices); -} +}; ////// 绘制存档同步界面 ////// ui.prototype._drawSyncSave = function () { core.status.event.id = 'syncSave'; this.drawChoices(null, [ - "同步存档到服务器", "从服务器加载存档", "存档至本地文件", "从本地文件读档", "回放和下载录像", "清空本地存档", "返回主菜单" + '同步存档到服务器', + '从服务器加载存档', + '存档至本地文件', + '从本地文件读档', + '回放和下载录像', + '清空本地存档', + '返回主菜单' ]); -} +}; ////// 绘制存档同步选择页面 ////// ui.prototype._drawSyncSelect = function () { core.status.event.id = 'syncSelect'; this.drawChoices(null, [ - "同步本地所有存档", "只同步当前单存档", "返回上级菜单" + '同步本地所有存档', + '只同步当前单存档', + '返回上级菜单' ]); -} +}; ////// 绘制单存档界面 ////// ui.prototype._drawLocalSaveSelect = function () { core.status.event.id = 'localSaveSelect'; this.drawChoices(null, [ - "下载所有存档", "只下载当前单存档", "返回上级菜单" + '下载所有存档', + '只下载当前单存档', + '返回上级菜单' ]); -} +}; ////// 绘制存档删除页面 ////// ui.prototype._drawStorageRemove = function () { core.status.event.id = 'storageRemove'; this.drawChoices(null, [ - "清空全部塔的存档", "只清空当前塔的存档", "返回上级菜单" + '清空全部塔的存档', + '只清空当前塔的存档', + '返回上级菜单' ]); -} +}; ui.prototype._drawReplay = function () { core.lockControl(); core.status.event.id = 'replay'; core.playSound('打开界面'); this.drawChoices(null, [ - "从头回放录像", "从存档开始回放", "接续播放剩余录像", "播放存档剩余录像", "选择录像文件", "下载当前录像", "返回游戏" + '从头回放录像', + '从存档开始回放', + '接续播放剩余录像', + '播放存档剩余录像', + '选择录像文件', + '下载当前录像', + '返回游戏' ]); -} +}; ui.prototype._drawGameInfo = function () { core.status.event.id = 'gameInfo'; this.drawChoices(null, [ - "数据统计", "查看工程", "游戏主页", "操作帮助", "关于游戏", "下载离线版本", "返回主菜单" + '数据统计', + '查看工程', + '游戏主页', + '操作帮助', + '关于游戏', + '下载离线版本', + '返回主菜单' ]); -} +}; ////// 绘制分页 ////// ui.prototype.drawPagination = function (page, totalPage, y) { @@ -2053,307 +3171,109 @@ ui.prototype.drawPagination = function (page, totalPage, y) { if (y == null) y = core._HEIGHT_ - 1; core.setFillStyle('ui', '#DDDDDD'); - var length = core.calWidth('ui', page + " / " + page, this._buildFont(15, true)); + var length = core.calWidth( + 'ui', + page + ' / ' + page, + this._buildFont(15, true) + ); core.setTextAlign('ui', 'left'); - core.fillText('ui', page + " / " + totalPage, parseInt((core._PX_ - length) / 2), y * 32 + 19); + core.fillText( + 'ui', + page + ' / ' + totalPage, + parseInt((core._PX_ - length) / 2), + y * 32 + 19 + ); core.setTextAlign('ui', 'center'); if (page > 1) core.fillText('ui', '上一页', core._PX_ / 2 - 80, y * 32 + 19); if (page < totalPage) core.fillText('ui', '下一页', core._PX_ / 2 + 80, y * 32 + 19); -} +}; ////// 绘制键盘光标 ////// ui.prototype._drawCursor = function () { var automaticRoute = core.status.automaticRoute; - automaticRoute.cursorX = core.clamp(automaticRoute.cursorX, 0, core._WIDTH_ - 1); - automaticRoute.cursorY = core.clamp(automaticRoute.cursorY, 0, core._HEIGHT_ - 1); + automaticRoute.cursorX = core.clamp( + automaticRoute.cursorX, + 0, + core._WIDTH_ - 1 + ); + automaticRoute.cursorY = core.clamp( + automaticRoute.cursorY, + 0, + core._HEIGHT_ - 1 + ); core.status.event.id = 'cursor'; core.lockControl(); core.clearUI(); var width = 4; - core.strokeRect('ui', 32 * automaticRoute.cursorX + width / 2, 32 * automaticRoute.cursorY + width / 2, - 32 - width, 32 - width, core.status.globalAttribute.selectColor, width); - -} + core.strokeRect( + 'ui', + 32 * automaticRoute.cursorX + width / 2, + 32 * automaticRoute.cursorY + width / 2, + 32 - width, + 32 - width, + core.status.globalAttribute.selectColor, + width + ); +}; ////// 绘制怪物手册 ////// -ui.prototype.drawBook = function (index) { - var floorId = core.floorIds[(core.status.event.ui || {}).index] || core.status.floorId; - // 清除浏览地图时的光环缓存 - if (floorId != core.status.floorId && core.status.checkBlock) { - core.status.checkBlock.cache = {}; - } - var enemys = core.enemys.getCurrentEnemys(floorId); - core.clearUI(); - core.clearMap('data'); - // 生成groundPattern - core.maps.generateGroundPattern(floorId); - this._drawBook_drawBackground(); - core.setAlpha('ui', 1); - - if (enemys.length == 0) { - return this._drawBook_drawEmpty(); - } - - index = core.clamp(index, 0, enemys.length - 1); - core.status.event.data = index; - var pageinfo = this._drawBook_pageinfo(); - var perpage = pageinfo.per_page, page = parseInt(index / perpage) + 1, totalPage = Math.ceil(enemys.length / perpage); - - var start = (page - 1) * perpage; - enemys = enemys.slice(start, page * perpage); - - for (var i = 0; i < enemys.length; i++) - this._drawBook_drawOne(floorId, i, enemys[i], pageinfo, index == start + i); - - core.drawBoxAnimate(); - this.drawPagination(page, totalPage); - core.setTextAlign('ui', 'center'); - core.fillText('ui', '返回游戏', core._PX_ - 46, core._PY_ - 13, '#DDDDDD', this._buildFont(15, true)); -} - -ui.prototype._drawBook_pageinfo = function () { - var per_page = core._HALF_HEIGHT_; - var padding_top = 12; // 距离顶端像素 - var per_height = (core._PY_ - 32 - padding_top) / per_page; - return { per_page: per_page, padding_top: padding_top, per_height: per_height }; -} - -ui.prototype._drawBook_drawBackground = function () { - core.setAlpha('ui', 1); - core.setFillStyle('ui', core.material.groundPattern); - core.fillRect('ui', 0, 0, core._PX_, core._PY_); - - core.setAlpha('ui', 0.6); - core.setFillStyle('ui', '#000000'); - core.fillRect('ui', 0, 0, core._PX_, core._PY_); -} - -ui.prototype._drawBook_drawEmpty = function () { - core.setTextAlign('ui', 'center'); - core.fillText('ui', "本层无怪物", core._PX_ / 2, core._PY_ / 2 + 14, '#999999', this._buildFont(50, true)); - core.fillText('ui', '返回游戏', core._PX_ - 46, core._PY_ - 13, '#DDDDDD', this._buildFont(15, true)); -} - -ui.prototype._drawBook_drawOne = function (floorId, index, enemy, pageinfo, selected) { - var top = pageinfo.per_height * index + pageinfo.padding_top; // 最上面margin默认是12px - enemy.floorId = floorId; - // 横向规划: - // 22 + 42 = 64 是头像框 - this._drawBook_drawBox(index, enemy, top, pageinfo); - var left = 64, total_width = core._PX_ - left; - var name_width = total_width * 10 / 35; - this._drawBook_drawName(index, enemy, top, left, name_width); - this._drawBook_drawContent(index, enemy, top, left + name_width); - if (selected) - core.strokeRoundRect('ui', 10, top + 1, core._PX_ - 10 * 2, pageinfo.per_height, 10, core.status.globalAttribute.selectColor); -} - -ui.prototype._drawBook_is32x32 = function (blockInfo) { - // 判定48的怪物上半部分是否是全透明 - var height = blockInfo.height - 32; - var canvas = document.createElement('canvas'); - canvas.width = 32; canvas.height = height; - var ctx = canvas.getContext("2d"); - core.drawImage(ctx, blockInfo.image, 0, blockInfo.posY * blockInfo.height, 32, height, 0, 0, 32, height); - var url = canvas.toDataURL(); - core.clearMap(ctx); - return url == canvas.toDataURL(); -} - -ui.prototype._drawBook_drawBox = function (index, enemy, top, pageinfo) { - // 横向:22+42;纵向:10 + 42 + 10(正好居中);内部图像 32x32 - var border_top = top + (pageinfo.per_height - 42) / 2, border_left = 22; - var img_top = border_top + 5, img_left = border_left + 5; - core.strokeRect('ui', 22, border_top, 42, 42, '#DDDDDD', 2); - var blockInfo = core.getBlockInfo(enemy.id); - - // 检查大怪物 - if (blockInfo.bigImage) { - core.status.boxAnimateObjs.push({ - bigImage: blockInfo.bigImage, face: blockInfo.face, centerX: border_left + 21, centerY: border_top + 21, - max_width: 60 - }); - } - else if (blockInfo.height >= 42) { - var originEnemy = core.material.enemys[enemy.id] || {}; - // 检查上半部分是不是纯透明的;取用原始值避免重复计算 - if (originEnemy.is32x32 == null) { - originEnemy.is32x32 = this._drawBook_is32x32(blockInfo); - } - if (originEnemy.is32x32) { - core.status.boxAnimateObjs.push({ - 'bgx': border_left, 'bgy': border_top, 'bgWidth': 42, 'bgHeight': 42, - 'x': img_left, 'y': img_top, 'height': 32, 'animate': blockInfo.animate, - 'image': blockInfo.image, 'pos': blockInfo.posY * blockInfo.height + blockInfo.height - 32 - }); - } else { - var drawWidth = 42 * 32 / blockInfo.height; - core.status.boxAnimateObjs.push({ - 'bgx': border_left, 'bgy': border_top, 'bgWidth': 42, 'bgHeight': 42, - 'x': img_left - 5 + (42 - drawWidth) / 2, 'y': img_top - 5, 'dw': drawWidth, 'dh': 42, - 'height': blockInfo.height, 'animate': blockInfo.animate, - 'image': blockInfo.image, 'pos': blockInfo.posY * blockInfo.height - }); - } - } else { - core.status.boxAnimateObjs.push({ - 'bgx': border_left, 'bgy': border_top, 'bgWidth': 42, 'bgHeight': 42, - 'x': img_left, 'y': img_top, 'height': 32, 'animate': blockInfo.animate, - 'image': blockInfo.image, 'pos': blockInfo.posY * blockInfo.height - }); - } -} - -ui.prototype._drawBook_drawName = function (index, enemy, top, left, width) { - // 绘制第零列(名称和特殊属性) - // 如果需要添加自己的比如怪物的称号等,也可以在这里绘制 - core.setTextAlign('ui', 'center'); - if (enemy.specialText.length == 0) { - core.fillText('ui', enemy.name, left + width / 2, - top + 35, '#DDDDDD', this._buildFont(17, true), width); - } - else { - core.fillText('ui', enemy.name, left + width / 2, - top + 28, '#DDDDDD', this._buildFont(17, true), width); - switch (enemy.specialText.length) { - case 1: - core.fillText('ui', enemy.specialText[0], left + width / 2, - top + 50, core.arrayToRGBA((enemy.specialColor || [])[0] || '#FF6A6A'), - this._buildFont(15, true), width); - break; - case 2: - // Step 1: 计算字体 - var text = enemy.specialText[0] + " " + enemy.specialText[1]; - core.setFontForMaxWidth('ui', text, width, this._buildFont(15, true)); - // Step 2: 计算总宽度 - var totalWidth = core.calWidth('ui', text); - var leftWidth = core.calWidth('ui', enemy.specialText[0]); - var rightWidth = core.calWidth('ui', enemy.specialText[1]); - // Step 3: 绘制 - core.fillText('ui', enemy.specialText[0], left + (width + leftWidth - totalWidth) / 2, - top + 50, core.arrayToRGBA((enemy.specialColor || [])[0] || '#FF6A6A')); - core.fillText('ui', enemy.specialText[1], left + (width + totalWidth - rightWidth) / 2, - top + 50, core.arrayToRGBA((enemy.specialColor || [])[1] || '#FF6A6A')); - break; - default: - core.fillText('ui', '多属性...', left + width / 2, - top + 50, '#FF6A6A', this._buildFont(15, true), width); - } - } -} - -ui.prototype._drawBook_drawContent = function (index, enemy, top, left) { - var width = core._PX_ - left; // 9 : 8 : 8 划分三列 - this._drawBook_drawRow1(index, enemy, top, left, width, top + 20); - this._drawBook_drawRow2(index, enemy, top, left, width, top + 38); - this._drawBook_drawRow3(index, enemy, top, left, width, top + 56); -} - -ui.prototype._drawBook_drawRow1 = function (index, enemy, top, left, width, position) { - // 绘制第一行 - core.setTextAlign('ui', 'left'); - var b13 = this._buildFont(13, true), f13 = this._buildFont(13, false); - var col1 = left, col2 = left + width * 9 / 25, col3 = left + width * 17 / 25; - core.fillText('ui', core.getStatusLabel('hp'), col1, position, '#DDDDDD', f13); - core.fillText('ui', core.formatBigNumber(enemy.hp || 0), col1 + 30, position, null, b13); - core.fillText('ui', core.getStatusLabel('atk'), col2, position, null, f13); - core.fillText('ui', core.formatBigNumber(enemy.atk || 0), col2 + 30, position, null, b13); - core.fillText('ui', core.getStatusLabel('def'), col3, position, null, f13); - core.fillText('ui', core.formatBigNumber(enemy.def || 0), col3 + 30, position, null, b13); -} - -ui.prototype._drawBook_drawRow2 = function (index, enemy, top, left, width, position) { - // 绘制第二行 - core.setTextAlign('ui', 'left'); - var b13 = this._buildFont(13, true), f13 = this._buildFont(13, false); - var col1 = left, col2 = left + width * 9 / 25, col3 = left + width * 17 / 25; - // 获得第二行绘制的内容 - var second_line = []; - if (core.flags.statusBarItems.indexOf('enableMoney') >= 0) second_line.push([core.getStatusLabel('money'), core.formatBigNumber(enemy.money || 0)]); - if (core.flags.enableAddPoint) second_line.push([core.getStatusLabel('point'), core.formatBigNumber(enemy.point || 0)]); - if (core.flags.statusBarItems.indexOf('enableExp') >= 0) second_line.push([core.getStatusLabel('exp'), core.formatBigNumber(enemy.exp || 0)]); - - var damage_offset = col1 + (core._PX_ - col1) / 2 - 12; - // 第一列 - if (second_line.length > 0) { - var one = second_line.shift(); - core.fillText('ui', one[0], col1, position, '#DDDDDD', f13); - core.fillText('ui', one[1], col1 + 30, position, null, b13); - damage_offset = col2 + (core._PX_ - col2) / 2 - 12; - } - // 第二列 - if (second_line.length > 0) { - var one = second_line.shift(); - core.fillText('ui', one[0], col2, position, '#DDDDDD', f13); - core.fillText('ui', one[1], col2 + 30, position, null, b13); - damage_offset = col3 + (core._PX_ - col3) / 2 - 12; - } - // 忽略第三列,直接绘制伤害 - this._drawBook_drawDamage(index, enemy, damage_offset, position); -} - -ui.prototype._drawBook_drawRow3 = function (index, enemy, top, left, width, position) { - // 绘制第三行 - core.setTextAlign('ui', 'left'); - var b13 = this._buildFont(13, true), f13 = this._buildFont(13, false); - var col1 = left, col2 = left + width * 9 / 25, col3 = left + width * 17 / 25; - core.fillText('ui', '临界', col1, position, '#DDDDDD', f13); - core.fillText('ui', core.formatBigNumber(enemy.critical || 0), col1 + 30, position, null, b13); - core.fillText('ui', '减伤', col2, position, null, f13); - core.fillText('ui', core.formatBigNumber(enemy.criticalDamage || 0), col2 + 30, position, null, b13); - core.fillText('ui', '加防', col3, position, null, f13); - core.fillText('ui', core.formatBigNumber(enemy.defDamage || 0), col3 + 30, position, null, b13); -} - -ui.prototype._drawBook_drawDamage = function (index, enemy, offset, position) { - core.setTextAlign('ui', 'center'); - var damage = enemy.damage, color = '#FFFF00'; - if (damage == null) { - damage = '无法战斗'; - color = '#FF2222'; - } - else { - if (damage >= core.status.hero.hp) color = '#FF2222'; - else if (damage >= core.status.hero.hp * 2 / 3) color = '#FF9933'; - else if (damage <= 0) color = '#11FF11'; - damage = core.formatBigNumber(damage); - if (core.enemys.hasSpecial(enemy, 19)) damage += "+"; - if (core.enemys.hasSpecial(enemy, 21)) damage += "-"; - if (core.enemys.hasSpecial(enemy, 11)) damage += "^"; - } - if (enemy.notBomb) damage += "[b]"; - core.fillText('ui', damage, offset, position, color, this._buildFont(13, true)); -} +ui.prototype.drawBook = function (index) {}; ////// 绘制怪物属性的详细信息 ////// ui.prototype._drawBookDetail = function (index) { - var info = this._drawBookDetail_getInfo(index), enemy = info[0]; + var info = this._drawBookDetail_getInfo(index), + enemy = info[0]; if (!enemy) return; - var content = info[1].join("\n"); + var content = info[1].join('\n'); core.status.event.id = 'book-detail'; core.animateFrame.tip = null; core.clearMap('data'); - var left = 10, width = core._PX_ - 2 * left, right = left + width; - var content_left = left + 25, validWidth = right - content_left - 13; - var height = Math.max(this.getTextContentHeight(content, { fontSize: 16, lineHeight: 24, maxWidth: validWidth }) + 58, 80), - top = (core._PY_ - height) / 2, bottom = top + height; + var left = 10, + width = core._PX_ - 2 * left, + right = left + width; + var content_left = left + 25, + validWidth = right - content_left - 13; + var height = Math.max( + this.getTextContentHeight(content, { + fontSize: 16, + lineHeight: 24, + maxWidth: validWidth + }) + 58, + 80 + ), + top = (core._PY_ - height) / 2, + bottom = top + height; core.setAlpha('data', 0.9); core.fillRect('data', left, top, width, height, '#000000'); core.setAlpha('data', 1); - core.strokeRect('data', left - 1, top - 1, width + 1, height + 1, - core.arrayToRGBA(core.status.globalAttribute.borderColor), 2); + core.strokeRect( + 'data', + left - 1, + top - 1, + width + 1, + height + 1, + core.arrayToRGBA(core.status.globalAttribute.borderColor), + 2 + ); core.playSound('确定'); - this._drawBookDetail_drawContent(enemy, content, { top: top, content_left: content_left, bottom: bottom, validWidth: validWidth }); -} + this._drawBookDetail_drawContent(enemy, content, { + top: top, + content_left: content_left, + bottom: bottom, + validWidth: validWidth + }); +}; ui.prototype._drawBookDetail_getInfo = function (index) { - var floorId = core.floorIds[(core.status.event.ui || {}).index] || core.status.floorId; + var floorId = + core.floorIds[(core.status.event.ui || {}).index] || + core.status.floorId; // 清除浏览地图时的光环缓存 if (floorId != core.status.floorId && core.status.checkBlock) { core.status.checkBlock.cache = {}; @@ -2361,14 +3281,15 @@ ui.prototype._drawBookDetail_getInfo = function (index) { var enemys = core.enemys.getCurrentEnemys(floorId); if (enemys.length == 0) return []; index = core.clamp(index, 0, enemys.length - 1); - var enemy = enemys[index], enemyId = enemy.id; + var enemy = enemys[index], + enemyId = enemy.id; var texts = core.enemys.getSpecialHint(enemyId); - if (texts.length == 0) texts.push("该怪物无特殊属性。"); - if (enemy.description) texts.push(enemy.description + "\r"); - texts.push(""); + if (texts.length == 0) texts.push('该怪物无特殊属性。'); + if (enemy.description) texts.push(enemy.description + '\r'); + texts.push(''); this._drawBookDetail_getTexts(enemy, floorId, texts); return [enemy, texts]; -} +}; ui.prototype._drawBookDetail_getTexts = function (enemy, floorId, texts) { // --- 原始数值 @@ -2381,25 +3302,27 @@ ui.prototype._drawBookDetail_getTexts = function (enemy, floorId, texts) { this._drawBookDetail_hatred(enemy, texts); // --- 战斗回合数,临界表 this._drawBookDetail_turnAndCriticals(enemy, floorId, texts); -} +}; ui.prototype._drawBookDetail_origin = function (enemy, texts) { // 怪物数值和原始值不一样时,在详细信息页显示原始数值 var originEnemy = core.enemys._getCurrentEnemys_getEnemy(enemy.id); var content = []; if (enemy.locs != null && enemy.locs.length >= 0) { - texts.push("\r[#FF6A6A]\\d怪物坐标:\\d\r[]" + JSON.stringify(enemy.locs)); + texts.push( + '\r[#FF6A6A]\\d怪物坐标:\\d\r[]' + JSON.stringify(enemy.locs) + ); } - ["hp", "atk", "def", "point", "money", "exp"].forEach(function (one) { + ['hp', 'atk', 'def', 'point', 'money', 'exp'].forEach(function (one) { if (enemy[one] == null || originEnemy[one] == null) return; if (enemy[one] != originEnemy[one]) { - content.push(core.getStatusLabel(one) + " " + originEnemy[one]); + content.push(core.getStatusLabel(one) + ' ' + originEnemy[one]); } }); if (content.length > 0) { - texts.push("\r[#FF6A6A]\\d原始数值:\\d\r[]" + content.join(";")); + texts.push('\r[#FF6A6A]\\d原始数值:\\d\r[]' + content.join(';')); } -} +}; ui.prototype._drawBookDetail_mofang = function (enemy, texts) { // 模仿临界计算器 @@ -2407,7 +3330,11 @@ ui.prototype._drawBookDetail_mofang = function (enemy, texts) { var hp = enemy.hp; var delta = core.status.hero.atk - core.status.hero.def; if (delta < hp && hp <= 10000 && hp > 0) { - texts.push("\r[#FF6A6A]\\d模仿临界计算器:\\d\r[](当前攻防差" + core.formatBigNumber(delta) + ")"); + texts.push( + '\r[#FF6A6A]\\d模仿临界计算器:\\d\r[](当前攻防差' + + core.formatBigNumber(delta) + + ')' + ); var u = []; this._drawBookDetail_mofang_getArray(hp).forEach(function (t) { if (u.length < 20) u.push(t); @@ -2416,83 +3343,121 @@ ui.prototype._drawBookDetail_mofang = function (enemy, texts) { u.push(t); } }); - texts.push(JSON.stringify(u.map(function (v) { - return core.formatBigNumber(v[0]) + ":" + v[1]; - }))); + texts.push( + JSON.stringify( + u.map(function (v) { + return core.formatBigNumber(v[0]) + ':' + v[1]; + }) + ) + ); } } -} +}; ui.prototype._drawBookDetail_mofang_getArray = function (hp) { var arr = []; - var last = 0, start = 0; + var last = 0, + start = 0; for (var i = 1; i < hp; i++) { var now = parseInt((hp - 1) / i); if (now != last) { if (last != 0) { - arr.push([start, last + "x"]); + arr.push([start, last + 'x']); } last = now; start = i; } } if (last != 0) { - arr.push([start, "1x"]); - arr.push([hp, "0"]); + arr.push([start, '1x']); + arr.push([hp, '0']); } return arr; -} +}; ui.prototype._drawBookDetail_vampire = function (enemy, floorId, texts) { if (core.enemys.hasSpecial(enemy.special, 11)) { var damage = core.getDamage(enemy.id); if (damage != null) { // 二分HP - var start = 1, end = 100 * damage; + var start = 1, + end = 100 * damage; var nowHp = core.status.hero.hp; while (start < end) { var mid = Math.floor((start + end) / 2); core.status.hero.hp = mid; - if (core.canBattle(enemy.id, enemy.x, enemy.y, floorId)) end = mid; + if (core.canBattle(enemy.id, enemy.x, enemy.y, floorId)) + end = mid; else start = mid + 1; } core.status.hero.hp = start; if (core.canBattle(enemy.id)) { - texts.push("\r[#FF6A6A]\\d打死该怪物最低需要生命值:\\d\r[]" + core.formatBigNumber(start)); + texts.push( + '\r[#FF6A6A]\\d打死该怪物最低需要生命值:\\d\r[]' + + core.formatBigNumber(start) + ); } core.status.hero.hp = nowHp; } } -} +}; ui.prototype._drawBookDetail_hatred = function (enemy, texts) { if (core.enemys.hasSpecial(enemy.special, 17)) { - texts.push("\r[#FF6A6A]\\d当前仇恨伤害值:\\d\r[]" + core.getFlag('hatred', 0)); + texts.push( + '\r[#FF6A6A]\\d当前仇恨伤害值:\\d\r[]' + core.getFlag('hatred', 0) + ); } -} +}; -ui.prototype._drawBookDetail_turnAndCriticals = function (enemy, floorId, texts) { - var damageInfo = core.getDamageInfo(enemy.id, null, enemy.x, enemy.y, floorId); - texts.push("\r[#FF6A6A]\\d战斗回合数:\\d\r[]" + ((damageInfo || {}).turn || 0)); +ui.prototype._drawBookDetail_turnAndCriticals = function ( + enemy, + floorId, + texts +) { + var damageInfo = core.getDamageInfo( + enemy.id, + null, + enemy.x, + enemy.y, + floorId + ); + texts.push( + '\r[#FF6A6A]\\d战斗回合数:\\d\r[]' + ((damageInfo || {}).turn || 0) + ); // 临界表 - var criticals = core.enemys.nextCriticals(enemy.id, 8, enemy.x, enemy.y, floorId).map(function (v) { - return core.formatBigNumber(v[0]) + ":" + core.formatBigNumber(v[1]); - }); + var criticals = core.enemys + .nextCriticals(enemy.id, 8, enemy.x, enemy.y, floorId) + .map(function (v) { + return ( + core.formatBigNumber(v[0]) + ':' + core.formatBigNumber(v[1]) + ); + }); while (criticals[0] == '0:0') criticals.shift(); - texts.push("\r[#FF6A6A]\\d临界表:\\d\r[]" + JSON.stringify(criticals)); -} + texts.push('\r[#FF6A6A]\\d临界表:\\d\r[]' + JSON.stringify(criticals)); +}; ui.prototype._drawBookDetail_drawContent = function (enemy, content, pos) { // 名称 core.setTextAlign('data', 'left'); - core.fillText('data', enemy.name, pos.content_left, pos.top + 30, core.status.globalAttribute.selectColor, this._buildFont(22, true)); + core.fillText( + 'data', + enemy.name, + pos.content_left, + pos.top + 30, + core.status.globalAttribute.selectColor, + this._buildFont(22, true) + ); var content_top = pos.top + 44; this.drawTextContent('data', content, { - left: pos.content_left, top: content_top, maxWidth: pos.validWidth, - fontSize: 16, lineHeight: 24 + left: pos.content_left, + top: content_top, + maxWidth: pos.validWidth, + fontSize: 16, + lineHeight: 24 }); -} +}; ////// 绘制楼层传送器 ////// ui.prototype.drawFly = function (page) { @@ -2504,11 +3469,39 @@ ui.prototype.drawFly = function (page) { core.fillRect('ui', 0, 0, core._PX_, core._PY_, '#000000'); core.setAlpha('ui', 1); core.setTextAlign('ui', 'center'); - core.fillText('ui', '楼层跳跃', core._PX_ / 2, 48, '#FFFFFF', this._buildFont(28, true)); - core.fillText('ui', '返回游戏', core._PX_ / 2, core._PY_ - 13, null, this._buildFont(15, true)) + core.fillText( + 'ui', + '楼层跳跃', + core._PX_ / 2, + 48, + '#FFFFFF', + this._buildFont(28, true) + ); + core.fillText( + 'ui', + '返回游戏', + core._PX_ / 2, + core._PY_ - 13, + null, + this._buildFont(15, true) + ); core.setTextAlign('ui', 'right'); - core.fillText('ui', '浏览地图时也', core._PX_ - 10, core._PY_ - 23, '#aaaaaa', this._buildFont(10, false)); - core.fillText('ui', '可楼层跳跃!', core._PX_ - 10, core._PY_ - 11, null, this._buildFont(10, false)); + core.fillText( + 'ui', + '浏览地图时也', + core._PX_ - 10, + core._PY_ - 23, + '#aaaaaa', + this._buildFont(10, false) + ); + core.fillText( + 'ui', + '可楼层跳跃!', + core._PX_ - 10, + core._PY_ - 11, + null, + this._buildFont(10, false) + ); core.setTextAlign('ui', 'center'); var middle = core._PY_ / 2 + 39; @@ -2521,19 +3514,48 @@ ui.prototype.drawFly = function (page) { start_y += 22; } if (core.actions._getNextFlyFloor(1) != page) { - core.fillText('ui', '▲', core._PX_ - 60, middle - 64, null, this._buildFont(17, false)); + core.fillText( + 'ui', + '▲', + core._PX_ - 60, + middle - 64, + null, + this._buildFont(17, false) + ); core.fillText('ui', '▲', core._PX_ - 60, middle - 96); core.fillText('ui', '▲', core._PX_ - 60, middle - 96 - 7); } if (core.actions._getNextFlyFloor(-1) != page) { - core.fillText('ui', '▼', core._PX_ - 60, middle + 64, null, this._buildFont(17, false)); + core.fillText( + 'ui', + '▼', + core._PX_ - 60, + middle + 64, + null, + this._buildFont(17, false) + ); core.fillText('ui', '▼', core._PX_ - 60, middle + 96); core.fillText('ui', '▼', core._PX_ - 60, middle + 96 + 7); } var size = 0.75; - core.strokeRect('ui', 16, 64, size * core._PX_, size * core._PY_, '#FFFFFF', 2); - core.drawThumbnail(floorId, null, { ctx: 'ui', x: 16, y: 64, size: size, damage: true, all: true }); -} + core.strokeRect( + 'ui', + 16, + 64, + size * core._PX_, + size * core._PY_, + '#FFFFFF', + 2 + ); + core.drawThumbnail(floorId, null, { + ctx: 'ui', + x: 16, + y: 64, + size: size, + damage: true, + all: true + }); +}; ////// 绘制中心对称飞行器 ui.prototype._drawCenterFly = function () { @@ -2541,18 +3563,48 @@ ui.prototype._drawCenterFly = function () { core.status.event.id = 'centerFly'; var fillstyle = 'rgba(255,0,0,0.5)'; if (core.canUseItem('centerFly')) fillstyle = 'rgba(0,255,0,0.5)'; - var toX = core.bigmap.width - 1 - core.getHeroLoc('x'), toY = core.bigmap.height - 1 - core.getHeroLoc('y'); + var toX = core.bigmap.width - 1 - core.getHeroLoc('x'), + toY = core.bigmap.height - 1 - core.getHeroLoc('y'); this.clearUI(); core.fillRect('ui', 0, 0, core._PX_, core._PY_, '#000000'); - core.drawThumbnail(null, null, { heroLoc: core.status.hero.loc, heroIcon: core.status.hero.image, ctx: 'ui', centerX: toX, centerY: toY }); - var offsetX = core.clamp(toX - core._HALF_WIDTH_, 0, core.bigmap.width - core._WIDTH_), - offsetY = core.clamp(toY - core._HALF_HEIGHT_, 0, core.bigmap.height - core._HEIGHT_); - core.fillRect('ui', (toX - offsetX) * 32, (toY - offsetY) * 32, 32, 32, fillstyle); - core.status.event.data = { "x": toX, "y": toY, "posX": toX - offsetX, "posY": toY - offsetY }; + core.drawThumbnail(null, null, { + heroLoc: core.status.hero.loc, + heroIcon: core.status.hero.image, + ctx: 'ui', + centerX: toX, + centerY: toY + }); + var offsetX = core.clamp( + toX - core._HALF_WIDTH_, + 0, + core.bigmap.width - core._WIDTH_ + ), + offsetY = core.clamp( + toY - core._HALF_HEIGHT_, + 0, + core.bigmap.height - core._HEIGHT_ + ); + core.fillRect( + 'ui', + (toX - offsetX) * 32, + (toY - offsetY) * 32, + 32, + 32, + fillstyle + ); + core.status.event.data = { + x: toX, + y: toY, + posX: toX - offsetX, + posY: toY - offsetY + }; core.playSound('打开界面'); - core.drawTip("请确认当前" + core.material.items['centerFly'].name + "的位置", 'centerFly'); + core.drawTip( + '请确认当前' + core.material.items['centerFly'].name + '的位置', + 'centerFly' + ); return; -} +}; ////// 绘制浏览地图界面 ////// ui.prototype._drawViewMaps = function (index, x, y) { @@ -2564,30 +3616,61 @@ ui.prototype._drawViewMaps = function (index, x, y) { core.status.checkBlock.cache = {}; var data = this._drawViewMaps_buildData(index, x, y); core.fillRect('ui', 0, 0, core._PX_, core._PY_, '#000000'); - core.drawThumbnail(data.floorId, null, { damage: data.damage, ctx: 'ui', centerX: data.x, centerY: data.y, all: data.all }); + core.drawThumbnail(data.floorId, null, { + damage: data.damage, + ctx: 'ui', + centerX: data.x, + centerY: data.y, + all: data.all + }); core.clearMap('data'); core.setTextAlign('data', 'left'); core.setFont('data', '16px Arial'); var text = core.status.maps[data.floorId].title; if (!data.all && (data.mw > core._WIDTH_ || data.mh > core._HEIGHT_)) - text += " [" + (data.x - core._HALF_WIDTH_) + "," + (data.y - core._HALF_HEIGHT_) + "]"; - if (core.markedFloorIds[data.floorId]) - text += " (已标记)"; - var textX = 16, textY = 18, width = textX + core.calWidth('data', text) + 16, height = 42; + text += + ' [' + + (data.x - core._HALF_WIDTH_) + + ',' + + (data.y - core._HALF_HEIGHT_) + + ']'; + if (core.markedFloorIds[data.floorId]) text += ' (已标记)'; + var textX = 16, + textY = 18, + width = textX + core.calWidth('data', text) + 16, + height = 42; core.fillRect('data', 5, 5, width, height, 'rgba(0,0,0,0.4)'); core.fillText('data', text, textX + 5, textY + 15, 'rgba(255,255,255,0.6)'); -} +}; ui.prototype._drawViewMaps_drawHint = function () { core.playSound('打开界面'); core.fillRect('ui', 0, 0, core._PX_, core._PY_, 'rgba(0,0,0,0.7)'); core.setTextAlign('ui', 'center'); var stroke = function (left, top, width, height, fillStyle, lineWidth) { - core.strokeRect('ui', left + 2, top + 2, width - 4, height - 4, fillStyle, lineWidth); - } + core.strokeRect( + 'ui', + left + 2, + top + 2, + width - 4, + height - 4, + fillStyle, + lineWidth + ); + }; - var perpx = core._PX_ / 5, cornerpx = perpx * 3 / 4, perpy = core._PY_ / 5, cornerpy = perpy * 3 / 4; - stroke(perpx, 0, 3 * perpx, perpy, core.status.globalAttribute.selectColor, 4); // up + var perpx = core._PX_ / 5, + cornerpx = (perpx * 3) / 4, + perpy = core._PY_ / 5, + cornerpy = (perpy * 3) / 4; + stroke( + perpx, + 0, + 3 * perpx, + perpy, + core.status.globalAttribute.selectColor, + 4 + ); // up stroke(0, perpy, perpx, 3 * perpy); // left stroke(perpx, 4 * perpy, 3 * perpx, perpy); // down stroke(4 * perpx, perpy, perpx, 3 * perpy); // right @@ -2598,49 +3681,85 @@ ui.prototype._drawViewMaps_drawHint = function () { stroke(0, core._PY_ - cornerpy, cornerpx, cornerpy); // left bottom; core.setTextBaseline('ui', 'middle'); - core.fillText('ui', "上移地图 [W]", core._PX_ / 2, perpy / 2, core.status.globalAttribute.selectColor, '20px Arial'); - core.fillText('ui', "下移地图 [S]", core._PX_ / 2, core._PY_ - perpy / 2); + core.fillText( + 'ui', + '上移地图 [W]', + core._PX_ / 2, + perpy / 2, + core.status.globalAttribute.selectColor, + '20px Arial' + ); + core.fillText('ui', '下移地图 [S]', core._PX_ / 2, core._PY_ - perpy / 2); core.fillText('ui', 'V', cornerpx / 2, cornerpy / 2); core.fillText('ui', 'Z', core._PX_ - cornerpx / 2, cornerpy / 2); core.fillText('ui', 'B', cornerpx / 2, core._PY_ - cornerpy / 2); - var top = core._PY_ / 2 - 66, left = perpx / 2, right = core._PX_ - left; - var lt = ["左", "移", "地", "图", "[A]"], rt = ["右", "移", "地", "图", "[D]"]; + var top = core._PY_ / 2 - 66, + left = perpx / 2, + right = core._PX_ - left; + var lt = ['左', '移', '地', '图', '[A]'], + rt = ['右', '移', '地', '图', '[D]']; for (var i = 0; i < 5; ++i) { - core.fillText("ui", lt[i], left, top + 32 * i); - core.fillText("ui", rt[i], right, top + 32 * i); + core.fillText('ui', lt[i], left, top + 32 * i); + core.fillText('ui', rt[i], right, top + 32 * i); } - core.fillText('ui', "前张地图 [▲ / PGUP]", core._PX_ / 2, perpy * 1.5); - core.fillText('ui', "后张地图 [▼ / PGDN]", core._PX_ / 2, core._PY_ - perpy * 1.5); + core.fillText('ui', '前张地图 [▲ / PGUP]', core._PX_ / 2, perpy * 1.5); + core.fillText( + 'ui', + '后张地图 [▼ / PGDN]', + core._PX_ / 2, + core._PY_ - perpy * 1.5 + ); - core.fillText('ui', "退出 [ESC / ENTER]", core._PX_ / 2, core._PY_ / 2); - core.fillText('ui', "[X] 可查看" + core.material.items['book'].name + - " [G] 可使用" + core.material.items['fly'].name, core._PX_, core._PY_ + 32, null, '12px Arial'); + core.fillText('ui', '退出 [ESC / ENTER]', core._PX_ / 2, core._PY_ / 2); + core.fillText( + 'ui', + '[X] 可查看' + + core.material.items['book'].name + + ' [G] 可使用' + + core.material.items['fly'].name, + core._PX_, + core._PY_ + 32, + null, + '12px Arial' + ); core.setTextBaseline('ui', 'alphabetic'); -} +}; ui.prototype._drawViewMaps_buildData = function (index, x, y) { var damage = (core.status.event.data || {}).damage; var all = (core.status.event.data || { all: true }).all; if (index.damage != null) damage = index.damage; if (index.all != null) all = index.all; - if (index.index != null) { x = index.x; y = index.y; index = index.index; } + if (index.index != null) { + x = index.x; + y = index.y; + index = index.index; + } index = core.clamp(index, 0, core.floorIds.length - 1); if (damage == null) damage = true; // 浏览地图默认开显伤好了 - var floorId = core.floorIds[index], mw = core.floors[floorId].width, mh = core.floors[floorId].height; + var floorId = core.floorIds[index], + mw = core.floors[floorId].width, + mh = core.floors[floorId].height; if (x == null) x = parseInt(mw / 2); if (y == null) y = parseInt(mh / 2); x = core.clamp(x, core._HALF_WIDTH_, mw - core._HALF_WIDTH_ - 1); y = core.clamp(y, core._HALF_HEIGHT_, mh - core._HALF_HEIGHT_ - 1); core.status.event.data = { - index: index, x: x, y: y, floorId: floorId, mw: mw, mh: mh, - damage: damage, all: all + index: index, + x: x, + y: y, + floorId: floorId, + mw: mw, + mh: mh, + damage: damage, + all: all }; return core.status.event.data; -} +}; ////// 绘制道具栏 ////// ui.prototype._drawToolbox = function (index) { @@ -2654,21 +3773,39 @@ ui.prototype._drawToolbox = function (index) { core.canvas.ui.strokeWidth = 2; core.setTextAlign('ui', 'right'); var line1 = core._PY_ - 306; - this._drawToolbox_drawLine(line1, "消耗道具"); + this._drawToolbox_drawLine(line1, '消耗道具'); var line2 = core._PY_ - 146; - this._drawToolbox_drawLine(line2, "永久道具"); + this._drawToolbox_drawLine(line2, '永久道具'); this._drawToolbox_drawDescription(info, line1); - this._drawToolbox_drawContent(info, line1, info.tools, info.toolsPage, true); + this._drawToolbox_drawContent( + info, + line1, + info.tools, + info.toolsPage, + true + ); this.drawPagination(info.toolsPage, info.toolsTotalPage, core._HEIGHT_ - 6); - this._drawToolbox_drawContent(info, line2, info.constants, info.constantsPage); + this._drawToolbox_drawContent( + info, + line2, + info.constants, + info.constantsPage + ); this.drawPagination(info.constantsPage, info.constantsTotalPage); core.setTextAlign('ui', 'center'); - core.fillText('ui', '[装备栏]', core._PX_ - 46, 25, '#DDDDDD', this._buildFont(15, true)); + core.fillText( + 'ui', + '[装备栏]', + core._PX_ - 46, + 25, + '#DDDDDD', + this._buildFont(15, true) + ); core.fillText('ui', '返回游戏', core._PX_ - 46, core._PY_ - 13); -} +}; ////// 获得所有应该在道具栏显示的某个类型道具 ////// ui.prototype.getToolboxItems = function (cls) { @@ -2676,14 +3813,20 @@ ui.prototype.getToolboxItems = function (cls) { return this.uidata.getToolboxItems(cls); } return Object.keys(core.status.hero.items[cls] || {}) - .filter(function (id) { return !core.material.items[id].hideInToolbox; }) + .filter(function (id) { + return !core.material.items[id].hideInToolbox; + }) .sort(); -} +}; ui.prototype._drawToolbox_getInfo = function (index) { // 设定eventdata if (!core.status.event.data || core.status.event.data.toolsPage == null) - core.status.event.data = { "toolsPage": 1, "constantsPage": 1, "selectId": null } + core.status.event.data = { + toolsPage: 1, + constantsPage: 1, + selectId: null + }; // 获取物品列表 var tools = core.getToolboxItems('tools'), constants = core.getToolboxItems('constants'); @@ -2703,26 +3846,32 @@ ui.prototype._drawToolbox_getInfo = function (index) { select = index + (toolsPage - 1) * n; if (select >= tools.length) select = Math.max(0, tools.length - 1); selectId = tools[select]; - } - else { - select = index % n + (constantsPage - 1) * n; - if (select >= constants.length) select = Math.max(0, constants.length - 1); + } else { + select = (index % n) + (constantsPage - 1) * n; + if (select >= constants.length) + select = Math.max(0, constants.length - 1); selectId = constants[select]; } if (!core.hasItem(selectId)) selectId = null; core.status.event.data.selectId = selectId; return { - index: index, tools: tools, constants: constants, toolsPage: toolsPage, constantsPage: constantsPage, - toolsTotalPage: toolsTotalPage, constantsTotalPage: constantsTotalPage, selectId: selectId + index: index, + tools: tools, + constants: constants, + toolsPage: toolsPage, + constantsPage: constantsPage, + toolsTotalPage: toolsTotalPage, + constantsTotalPage: constantsTotalPage, + selectId: selectId }; -} +}; ui.prototype._drawToolbox_drawBackground = function () { // 绘制 core.clearMap('ui'); core.setAlpha('ui', 0.85); core.fillRect('ui', 0, 0, core._PX_, core._PY_, '#000000'); -} +}; ui.prototype._drawToolbox_drawLine = function (yoffset, text) { core.setFillStyle('ui', '#DDDDDD'); @@ -2736,22 +3885,47 @@ ui.prototype._drawToolbox_drawLine = function (yoffset, text) { core.canvas.ui.lineTo(core._PX_ - 72, yoffset - 25); core.canvas.ui.lineTo(core._PX_ - 102, yoffset - 1); core.canvas.ui.fill(); - core.fillText('ui', text, core._PX_ - 5, yoffset - 6, '#333333', this._buildFont(16, true)); -} + core.fillText( + 'ui', + text, + core._PX_ - 5, + yoffset - 6, + '#333333', + this._buildFont(16, true) + ); +}; ui.prototype._drawToolbox_drawDescription = function (info, max_height) { core.setTextAlign('ui', 'left'); if (!info.selectId) return; var item = core.material.items[info.selectId]; - var name = item.name || "未知道具"; - try { name = core.replaceText(name); } catch (e) { } - core.fillText('ui', name, 10, 32, core.status.globalAttribute.selectColor, this._buildFont(20, true)) - var text = item.text || "该道具暂无描述。"; - try { text = core.replaceText(text); } catch (e) { } + var name = item.name || '未知道具'; + try { + name = core.replaceText(name); + } catch (e) {} + core.fillText( + 'ui', + name, + 10, + 32, + core.status.globalAttribute.selectColor, + this._buildFont(20, true) + ); + var text = item.text || '该道具暂无描述。'; + try { + text = core.replaceText(text); + } catch (e) {} var height = null; for (var fontSize = 17; fontSize >= 9; fontSize -= 2) { - var config = { left: 10, top: 46, fontSize: fontSize, maxWidth: core._PX_ - 15, bold: false, color: "white" }; + var config = { + left: 10, + top: 46, + fontSize: fontSize, + maxWidth: core._PX_ - 15, + bold: false, + color: 'white' + }; height = 42 + core.getTextContentHeight(text, config); if (height < max_height || fontSize == 9) { core.drawTextContent('ui', text, config); @@ -2759,25 +3933,65 @@ ui.prototype._drawToolbox_drawDescription = function (info, max_height) { } } if (height < max_height - 33) { - core.fillText('ui', '<继续点击该道具即可进行使用>', 10, max_height - 15, '#CCCCCC', this._buildFont(14, false)); + core.fillText( + 'ui', + '<继续点击该道具即可进行使用>', + 10, + max_height - 15, + '#CCCCCC', + this._buildFont(14, false) + ); } -} +}; -ui.prototype._drawToolbox_drawContent = function (info, line, items, page, drawCount) { +ui.prototype._drawToolbox_drawContent = function ( + info, + line, + items, + page, + drawCount +) { var n = core._HALF_WIDTH_; core.setTextAlign('ui', 'right'); for (var i = 0; i < core._WIDTH_ - 1; i++) { var item = items[(core._WIDTH_ - 1) * (page - 1) + i]; if (!item) continue; var yoffset = line + 54 * Math.floor(i / n) + 19; - var icon = core.material.icons.items[item], image = core.material.images.items; - core.drawImage('ui', image, 0, 32 * icon, 32, 32, 64 * (i % n) + 21, yoffset, 32, 32); + var icon = core.material.icons.items[item], + image = core.material.images.items; + core.drawImage( + 'ui', + image, + 0, + 32 * icon, + 32, + 32, + 64 * (i % n) + 21, + yoffset, + 32, + 32 + ); if (drawCount) - core.fillText('ui', core.itemCount(item), 64 * (i % n) + 56, yoffset + 33, '#FFFFFF', this._buildFont(14, true)); + core.fillText( + 'ui', + core.itemCount(item), + 64 * (i % n) + 56, + yoffset + 33, + '#FFFFFF', + this._buildFont(14, true) + ); if (info.selectId == item) - core.strokeRoundRect('ui', 64 * (i % n) + 17, yoffset - 4, 40, 40, 6, core.status.globalAttribute.selectColor); + core.strokeRoundRect( + 'ui', + 64 * (i % n) + 17, + yoffset - 4, + 40, + 40, + 6, + core.status.globalAttribute.selectColor + ); } -} +}; ////// 绘制装备界面 ////// ui.prototype._drawEquipbox = function (index) { @@ -2790,24 +4004,37 @@ ui.prototype._drawEquipbox = function (index) { core.canvas.ui.strokeWidth = 2; core.setTextAlign('ui', 'right'); var line1 = core._PY_ - 306; - this._drawToolbox_drawLine(line1, "当前装备"); + this._drawToolbox_drawLine(line1, '当前装备'); var line2 = core._PY_ - 146; - this._drawToolbox_drawLine(line2 + 9, "拥有装备"); + this._drawToolbox_drawLine(line2 + 9, '拥有装备'); this._drawEquipbox_description(info, line1); this._drawEquipbox_drawEquiped(info, line1); - this._drawToolbox_drawContent(info, line2, info.ownEquipment, info.page, true); + this._drawToolbox_drawContent( + info, + line2, + info.ownEquipment, + info.page, + true + ); this.drawPagination(info.page, info.totalPage); core.setTextAlign('ui', 'center'); - core.fillText('ui', '[道具栏]', core._PX_ - 46, 25, '#DDDDDD', this._buildFont(15, true)); + core.fillText( + 'ui', + '[道具栏]', + core._PX_ - 46, + 25, + '#DDDDDD', + this._buildFont(15, true) + ); core.fillText('ui', '返回游戏', core._PX_ - 46, core._PY_ - 13); -} +}; ui.prototype._drawEquipbox_getInfo = function (index) { if (!core.status.event.data || core.status.event.data.page == null) - core.status.event.data = { "page": 1, "selectId": null }; + core.status.event.data = { page: 1, selectId: null }; var allEquips = core.status.globalAttribute.equipName; var equipLength = allEquips.length; if (!core.status.hero.equipment) core.status.hero.equipment = []; @@ -2827,40 +4054,62 @@ ui.prototype._drawEquipbox_getInfo = function (index) { if (index < n) { if (index >= equipLength) index = Math.max(0, equipLength - 1); selectId = equipEquipment[index] || null; - } - else { - if (page == totalPage) index = Math.min(index, (ownEquipment.length + n - 1) % n + n); + } else { + if (page == totalPage) + index = Math.min(index, ((ownEquipment.length + n - 1) % n) + n); selectId = ownEquipment[index - n + (page - 1) * n]; if (!core.hasItem(selectId)) selectId = null; } core.status.event.selection = index; core.status.event.data.selectId = selectId; return { - index: index, selectId: selectId, page: page, totalPage: totalPage, allEquips: allEquips, - equipLength: equipLength, equipEquipment: equipEquipment, ownEquipment: ownEquipment + index: index, + selectId: selectId, + page: page, + totalPage: totalPage, + allEquips: allEquips, + equipLength: equipLength, + equipEquipment: equipEquipment, + ownEquipment: ownEquipment }; -} +}; ui.prototype._drawEquipbox_description = function (info, max_height) { core.setTextAlign('ui', 'left'); if (!info.selectId) return; var equip = core.material.items[info.selectId]; // --- 标题 - if (!equip.equip) equip.equip = { "type": 0 }; - var equipType = equip.equip.type, equipString; + if (!equip.equip) equip.equip = { type: 0 }; + var equipType = equip.equip.type, + equipString; if (typeof equipType === 'string') { - equipString = equipType || "未知部位"; + equipString = equipType || '未知部位'; equipType = core.items.getEquipTypeByName(equipType); - } - else equipString = info.allEquips[equipType] || "未知部位"; - core.fillText('ui', equip.name + "(" + equipString + ")", 10, 32, core.status.globalAttribute.selectColor, this._buildFont(20, true)) + } else equipString = info.allEquips[equipType] || '未知部位'; + core.fillText( + 'ui', + equip.name + '(' + equipString + ')', + 10, + 32, + core.status.globalAttribute.selectColor, + this._buildFont(20, true) + ); // --- 描述 - var text = equip.text || "该装备暂无描述。"; - try { text = core.replaceText(text); } catch (e) { } + var text = equip.text || '该装备暂无描述。'; + try { + text = core.replaceText(text); + } catch (e) {} var height = null; for (var fontSize = 17; fontSize >= 9; fontSize -= 2) { - var config = { left: 10, top: 46, fontSize: fontSize, maxWidth: core._PX_ - 15, bold: false, color: "white" }; + var config = { + left: 10, + top: 46, + fontSize: fontSize, + maxWidth: core._PX_ - 15, + bold: false, + color: 'white' + }; height = 42 + core.getTextContentHeight(text, config); if (height < max_height - 30 || fontSize == 9) { core.drawTextContent('ui', text, config); @@ -2868,25 +4117,52 @@ ui.prototype._drawEquipbox_description = function (info, max_height) { } } // --- 变化值 - this._drawEquipbox_drawStatusChanged(info, max_height - 15, equip, equipType); -} + this._drawEquipbox_drawStatusChanged( + info, + max_height - 15, + equip, + equipType + ); +}; -ui.prototype._drawEquipbox_getStatusChanged = function (info, equip, equipType, y) { +ui.prototype._drawEquipbox_getStatusChanged = function ( + info, + equip, + equipType, + y +) { if (info.index < core._WIDTH_ - 1) { // 光标在装备栏上:查询卸下装备属性 return core.compareEquipment(null, info.selectId); } if (equipType < 0) { // 没有空位 - core.fillText('ui', '<当前没有该装备的空位,请先卸下装备>', 10, y, '#CCCCCC', this._buildFont(14, false)); + core.fillText( + 'ui', + '<当前没有该装备的空位,请先卸下装备>', + 10, + y, + '#CCCCCC', + this._buildFont(14, false) + ); return null; } // 光标在装备上:查询装上后的属性变化 return core.compareEquipment(info.selectId, info.equipEquipment[equipType]); -} +}; -ui.prototype._drawEquipbox_drawStatusChanged = function (info, y, equip, equipType) { - var compare = this._drawEquipbox_getStatusChanged(info, equip, equipType, y); +ui.prototype._drawEquipbox_drawStatusChanged = function ( + info, + y, + equip, + equipType +) { + var compare = this._drawEquipbox_getStatusChanged( + info, + equip, + equipType, + y + ); if (compare == null) return; var obj = { drawOffset: 10, y: y }; @@ -2896,48 +4172,89 @@ ui.prototype._drawEquipbox_drawStatusChanged = function (info, y, equip, equipTy if (typeof core.status.hero[name] != 'number') continue; var nowValue = core.getRealStatus(name); // 查询新值 - var newValue = Math.floor((core.getStatus(name) + (compare.value[name] || 0)) - * (core.getBuff(name) * 100 + (compare.percentage[name] || 0)) / 100); + var newValue = Math.floor( + ((core.getStatus(name) + (compare.value[name] || 0)) * + (core.getBuff(name) * 100 + (compare.percentage[name] || 0))) / + 100 + ); if (nowValue == newValue) continue; var text = core.getStatusLabel(name); - this._drawEquipbox_drawStatusChanged_draw(text + " ", '#CCCCCC', obj); + this._drawEquipbox_drawStatusChanged_draw(text + ' ', '#CCCCCC', obj); var color = newValue > nowValue ? '#00FF00' : '#FF0000'; nowValue = core.formatBigNumber(nowValue); newValue = core.formatBigNumber(newValue); - this._drawEquipbox_drawStatusChanged_draw(nowValue + "->", '#CCCCCC', obj); + this._drawEquipbox_drawStatusChanged_draw( + nowValue + '->', + '#CCCCCC', + obj + ); this._drawEquipbox_drawStatusChanged_draw(newValue, color, obj); obj.drawOffset += 8; } -} +}; -ui.prototype._drawEquipbox_drawStatusChanged_draw = function (text, color, obj) { +ui.prototype._drawEquipbox_drawStatusChanged_draw = function ( + text, + color, + obj +) { var len = core.calWidth('ui', text); - if (obj.drawOffset + len >= core._PX_) { // 换行 + if (obj.drawOffset + len >= core._PX_) { + // 换行 obj.y += 19; obj.drawOffset = 10; } core.fillText('ui', text, obj.drawOffset, obj.y, color); obj.drawOffset += len; -} +}; ui.prototype._drawEquipbox_drawEquiped = function (info, line) { core.setTextAlign('ui', 'center'); - var per_line = core._HALF_WIDTH_ - 3, width = Math.floor(core._PX_ / (per_line + 0.25)); + var per_line = core._HALF_WIDTH_ - 3, + width = Math.floor(core._PX_ / (per_line + 0.25)); // 当前装备 for (var i = 0; i < info.equipLength; i++) { var equipId = info.equipEquipment[i] || null; // var offset_text = width * (i % per_line) + 56; - var offset_image = width * (i % per_line) + width * 2 / 3; + var offset_image = width * (i % per_line) + (width * 2) / 3; var offset_text = offset_image - (width - 32) / 2; var y = line + 54 * Math.floor(i / per_line) + 19; if (equipId) { var icon = core.material.icons.items[equipId]; - core.drawImage('ui', core.material.images.items, 0, 32 * icon, 32, 32, offset_image, y, 32, 32); + core.drawImage( + 'ui', + core.material.images.items, + 0, + 32 * icon, + 32, + 32, + offset_image, + y, + 32, + 32 + ); } - core.fillText('ui', info.allEquips[i] || "未知", offset_text, y + 27, '#FFFFFF', this._buildFont(16, true)) - core.strokeRoundRect('ui', offset_image - 4, y - 4, 40, 40, 6, info.index == i ? core.status.globalAttribute.selectColor : "#FFFFFF"); + core.fillText( + 'ui', + info.allEquips[i] || '未知', + offset_text, + y + 27, + '#FFFFFF', + this._buildFont(16, true) + ); + core.strokeRoundRect( + 'ui', + offset_image - 4, + y - 4, + 40, + 40, + 6, + info.index == i + ? core.status.globalAttribute.selectColor + : '#FFFFFF' + ); } -} +}; ////// 绘制存档/读档界面 ////// ui.prototype._drawSLPanel = function (index, refresh) { @@ -2945,14 +4262,22 @@ ui.prototype._drawSLPanel = function (index, refresh) { if (index == null) index = 1; if (index < 0) index = 0; - var page = parseInt(index / 10), offset = index % 10; + var page = parseInt(index / 10), + offset = index % 10; var max_page = main.savePages || 30; if (core.status.event.data && core.status.event.data.mode == 'fav') max_page = Math.ceil((core.saves.favorite || []).length / 5); if (page >= max_page) page = max_page - 1; if (offset > 5) offset = 5; - if (core.status.event.data && core.status.event.data.mode == 'fav' && page == max_page - 1) { - offset = Math.min(offset, (core.saves.favorite || []).length - 5 * page); + if ( + core.status.event.data && + core.status.event.data.mode == 'fav' && + page == max_page - 1 + ) { + offset = Math.min( + offset, + (core.saves.favorite || []).length - 5 * page + ); } var last_page = -1; @@ -2961,16 +4286,15 @@ ui.prototype._drawSLPanel = function (index, refresh) { last_page = core.status.event.data.page; mode = core.status.event.data.mode; } - core.status.event.data = { 'page': page, 'offset': offset, 'mode': mode }; + core.status.event.data = { page: page, offset: offset, mode: mode }; core.status.event.ui = core.status.event.ui || []; if (refresh || page != last_page) { core.status.event.ui = []; this._drawSLPanel_loadSave(page, function () { core.ui._drawSLPanel_draw(page, max_page); }); - } - else this._drawSLPanel_draw(page, max_page); -} + } else this._drawSLPanel_draw(page, max_page); +}; ui.prototype._drawSLPanel_draw = function (page, max_page) { // --- 绘制背景 @@ -2979,10 +4303,16 @@ ui.prototype._drawSLPanel_draw = function (page, max_page) { core.ui.drawPagination(page + 1, max_page); core.setTextAlign('ui', 'center'); var bottom = core._PY_ - 13; - core.fillText('ui', '返回游戏', core._PX_ - 48, bottom, '#DDDDDD', this._buildFont(15, true)); + core.fillText( + 'ui', + '返回游戏', + core._PX_ - 48, + bottom, + '#DDDDDD', + this._buildFont(15, true) + ); - if (core.status.event.selection) - core.setFillStyle('ui', '#FF6A6A'); + if (core.status.event.selection) core.setFillStyle('ui', '#FF6A6A'); if (core.status.event.id == 'save') core.fillText('ui', '删除模式', 48, bottom); else { @@ -2994,14 +4324,14 @@ ui.prototype._drawSLPanel_draw = function (page, max_page) { } // --- 绘制记录 this._drawSLPanel_drawRecords(); -} +}; ui.prototype._drawSLPanel_drawBackground = function () { core.clearMap('ui'); core.setAlpha('ui', 0.85); core.fillRect('ui', 0, 0, core._PX_, core._PY_, '#000000'); // 可改成背景图 core.setAlpha('ui', 1); -} +}; ui.prototype._drawSLPanel_loadSave = function (page, callback) { var ids = [0]; @@ -3012,88 +4342,207 @@ ui.prototype._drawSLPanel_loadSave = function (page, callback) { ids.push(id); } core.getSaves(ids, function (data) { - for (var i = 1; i < ids.length; ++i) - core.status.event.ui[i] = data[i]; - core.status.event.ui[0] = data[0] == null ? null : data[0][core.saves.autosave.now - 1]; + for (var i = 1; i < ids.length; ++i) core.status.event.ui[i] = data[i]; + core.status.event.ui[0] = + data[0] == null ? null : data[0][core.saves.autosave.now - 1]; callback(); }); -} +}; // 在以x为中心轴 y为顶坐标 的位置绘制一条宽为size的记录 cho表示是否被选中 选中会加粗 highlight表示高亮标题 ✐ -ui.prototype._drawSLPanel_drawRecord = function (title, data, x, y, size, cho, highLight) { - var globalAttribute = core.status.globalAttribute || core.initStatus.globalAttribute; +ui.prototype._drawSLPanel_drawRecord = function ( + title, + data, + x, + y, + size, + cho, + highLight +) { + var globalAttribute = + core.status.globalAttribute || core.initStatus.globalAttribute; var strokeColor = globalAttribute.selectColor; if (core.status.event.selection) strokeColor = '#FF6A6A'; if (!data || !data.floorId) highLight = false; if (data && data.__toReplay__) title = '[R]' + title; - var w = size * core._PX_, h = size * core._PY_; - core.fillText('ui', title, x, y, highLight ? globalAttribute.selectColor : '#FFFFFF', this._buildFont(17, true)); - core.strokeRect('ui', x - w / 2, y + 15, w, h, cho ? strokeColor : '#FFFFFF', cho ? 3 : 1); + var w = size * core._PX_, + h = size * core._PY_; + core.fillText( + 'ui', + title, + x, + y, + highLight ? globalAttribute.selectColor : '#FFFFFF', + this._buildFont(17, true) + ); + core.strokeRect( + 'ui', + x - w / 2, + y + 15, + w, + h, + cho ? strokeColor : '#FFFFFF', + cho ? 3 : 1 + ); if (data && data.floorId) { - core.setTextAlign('ui', "center"); + core.setTextAlign('ui', 'center'); var map = core.maps.loadMap(data.maps, data.floorId); core.extractBlocksForUI(map, data.hero.flags); core.drawThumbnail(data.floorId, map.blocks, { - heroLoc: data.hero.loc, heroIcon: data.hero.image, flags: data.hero.flags, - ctx: 'ui', x: x - w / 2, y: y + 15, size: size, centerX: data.hero.loc.x, centerY: data.hero.loc.y, noHD: true + heroLoc: data.hero.loc, + heroIcon: data.hero.image, + flags: data.hero.flags, + ctx: 'ui', + x: x - w / 2, + y: y + 15, + size: size, + centerX: data.hero.loc.x, + centerY: data.hero.loc.y, + noHD: true }); - if (core.isPlaying() && core.getFlag("hard") != data.hero.flags.hard) { + if (core.isPlaying() && core.getFlag('hard') != data.hero.flags.hard) { core.fillRect('ui', x - w / 2, y + 15, w, h, [0, 0, 0, 0.4]); - core.fillText('ui', data.hard, x, parseInt(y + 22 + h / 2), data.hero.flags.__hardColor__ || 'white', this._buildFont(30, true)); + core.fillText( + 'ui', + data.hard, + x, + parseInt(y + 22 + h / 2), + data.hero.flags.__hardColor__ || 'white', + this._buildFont(30, true) + ); } // 绘制存档笔记 if (data.hero.notes && data.hero.notes.length > 0) { core.setTextAlign('ui', 'left'); if (data.hero.notes.length >= 2) { core.fillRect('ui', x - w / 2, y + 15, w, 28, [0, 0, 0, 0.3]); - core.fillBoldText('ui', data.hero.notes.length - 1 + ". " + data.hero.notes[data.hero.notes.length - 2].substring(0, 10), - x - w / 2 + 2, y + 15 + 12, '#FFFFFF', null, this._buildFont(10, false)); - core.fillBoldText('ui', data.hero.notes.length + ". " + data.hero.notes[data.hero.notes.length - 1].substring(0, 10), - x - w / 2 + 2, y + 15 + 24); + core.fillBoldText( + 'ui', + data.hero.notes.length - + 1 + + '. ' + + data.hero.notes[data.hero.notes.length - 2].substring( + 0, + 10 + ), + x - w / 2 + 2, + y + 15 + 12, + '#FFFFFF', + null, + this._buildFont(10, false) + ); + core.fillBoldText( + 'ui', + data.hero.notes.length + + '. ' + + data.hero.notes[data.hero.notes.length - 1].substring( + 0, + 10 + ), + x - w / 2 + 2, + y + 15 + 24 + ); } else { core.fillRect('ui', x - w / 2, y + 15, w, 16, [0, 0, 0, 0.3]); - core.fillBoldText('ui', data.hero.notes.length + ". " + data.hero.notes[data.hero.notes.length - 1].substring(0, 10), - x - w / 2 + 2, y + 15 + 12, '#FFFFFF', null, this._buildFont(10, false)); + core.fillBoldText( + 'ui', + data.hero.notes.length + + '. ' + + data.hero.notes[data.hero.notes.length - 1].substring( + 0, + 10 + ), + x - w / 2 + 2, + y + 15 + 12, + '#FFFFFF', + null, + this._buildFont(10, false) + ); } } - core.setTextAlign('ui', "center"); - var v = core.formatBigNumber(data.hero.hp, true) + "/" + core.formatBigNumber(data.hero.atk, true) + "/" + core.formatBigNumber(data.hero.def, true); - var v2 = "/" + core.formatBigNumber(data.hero.mdef, true); - if (core.calWidth('ui', v + v2, this._buildFont(10, false)) <= w) v += v2; + core.setTextAlign('ui', 'center'); + var v = + core.formatBigNumber(data.hero.hp, true) + + '/' + + core.formatBigNumber(data.hero.atk, true) + + '/' + + core.formatBigNumber(data.hero.def, true); + var v2 = '/' + core.formatBigNumber(data.hero.mdef, true); + if (core.calWidth('ui', v + v2, this._buildFont(10, false)) <= w) + v += v2; core.fillText('ui', v, x, y + 30 + h, globalAttribute.selectColor); - core.fillText('ui', core.formatDate(new Date(data.time)), x, y + 43 + h, data.hero.flags.debug ? '#FF6A6A' : '#FFFFFF'); - } - else { + core.fillText( + 'ui', + core.formatDate(new Date(data.time)), + x, + y + 43 + h, + data.hero.flags.debug ? '#FF6A6A' : '#FFFFFF' + ); + } else { core.fillRect('ui', x - w / 2, y + 15, w, h, '#333333'); - core.fillText('ui', '空', x, parseInt(y + 22 + h / 2), '#FFFFFF', this._buildFont(30, true)); + core.fillText( + 'ui', + '空', + x, + parseInt(y + 22 + h / 2), + '#FFFFFF', + this._buildFont(30, true) + ); } -} +}; ui.prototype._drawSLPanel_drawRecords = function (n) { var page = core.status.event.data.page; var offset = core.status.event.data.offset; - var u = Math.floor(core._PX_ / 6), size = 0.3; - var name = core.status.event.id == 'save' ? "存档" : core.status.event.id == 'load' ? "读档" : "回放"; + var u = Math.floor(core._PX_ / 6), + size = 0.3; + var name = + core.status.event.id == 'save' + ? '存档' + : core.status.event.id == 'load' + ? '读档' + : '回放'; for (var i = 0; i < (n || 6); i++) { var data = core.status.event.ui[i]; var id = 5 * page + i; - var highLight = (i > 0 && core.saves.favorite.indexOf(id) >= 0) || core.status.event.data.mode == 'fav'; - var title = (highLight ? '★ ' : '☆ ') + (core.saves.favoriteName[id] || (name + id)); + var highLight = + (i > 0 && core.saves.favorite.indexOf(id) >= 0) || + core.status.event.data.mode == 'fav'; + var title = + (highLight ? '★ ' : '☆ ') + + (core.saves.favoriteName[id] || name + id); if (i != 0 && core.status.event.data.mode == 'fav') { if (!data) break; var real_id = core.saves.favorite[id - 1]; - title = (core.saves.favoriteName[real_id] || (name + real_id)) + ' ✐'; + title = (core.saves.favoriteName[real_id] || name + real_id) + ' ✐'; } var charSize = 32; // 字体占用像素范围 - var topSpan = parseInt((core._PY_ - charSize - 2 * (charSize * 2 + size * core._PY_)) / 3); // Margin + var topSpan = parseInt( + (core._PY_ - charSize - 2 * (charSize * 2 + size * core._PY_)) / 3 + ); // Margin var yTop1 = topSpan + parseInt(charSize / 2) + 8; // 文字的中心 var yTop2 = yTop1 + charSize * 2 + size * core._PY_ + topSpan; if (i < 3) { - this._drawSLPanel_drawRecord(i == 0 ? "自动存档" : title, data, (2 * i + 1) * u, yTop1, size, i == offset, highLight); - } - else { - this._drawSLPanel_drawRecord(title, data, (2 * i - 5) * u, yTop2, size, i == offset, highLight); + this._drawSLPanel_drawRecord( + i == 0 ? '自动存档' : title, + data, + (2 * i + 1) * u, + yTop1, + size, + i == offset, + highLight + ); + } else { + this._drawSLPanel_drawRecord( + title, + data, + (2 * i - 5) * u, + yTop2, + size, + i == offset, + highLight + ); } } }; @@ -3106,47 +4555,84 @@ ui.prototype._drawKeyBoard = function () { var offset = core._WIDTH_ % 2 == 0 ? 16 : 0; - var width = 384, height = 320; - var left = (core._PX_ - width) / 2 + offset, right = left + width; - var top = (core._PY_ - height) / 2 + (core._HEIGHT_ % 2 == 0 ? 16 : 0), bottom = top + height; + var width = 384, + height = 320; + var left = (core._PX_ - width) / 2 + offset, + right = left + width; + var top = (core._PY_ - height) / 2 + (core._HEIGHT_ % 2 == 0 ? 16 : 0), + bottom = top + height; var isWindowSkin = this.drawBackground(left, top, right, bottom); core.setTextAlign('ui', 'center'); core.setFillStyle('ui', core.arrayToRGBA(core.status.textAttribute.title)); - core.fillText('ui', '虚拟键盘', core._PX_ / 2 + offset, top + 35, null, this._buildFont(22, true)); + core.fillText( + 'ui', + '虚拟键盘', + core._PX_ / 2 + offset, + top + 35, + null, + this._buildFont(22, true) + ); core.setFont('ui', this._buildFont(17, false)); core.setFillStyle('ui', core.arrayToRGBA(core.status.textAttribute.text)); var now = core._PY_ / 2 - 89 + (core._HEIGHT_ % 2 == 0 ? 16 : 0); var lines = [ - ["F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "10", "11"], - ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"], - ["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"], - ["A", "S", "D", "F", "G", "H", "J", "K", "L"], - ["Z", "X", "C", "V", "B", "N", "M"], - ["-", "=", "[", "]", "\\", ";", "'", ",", ".", "/", "`"], - ["ES", "TA", "CA", "SH", "CT", "AL", "SP", "BS", "EN", "DE"] + ['F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', '10', '11'], + ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'], + ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'], + ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'], + ['Z', 'X', 'C', 'V', 'B', 'N', 'M'], + ['-', '=', '[', ']', '\\', ';', "'", ',', '.', '/', '`'], + ['ES', 'TA', 'CA', 'SH', 'CT', 'AL', 'SP', 'BS', 'EN', 'DE'] ]; lines.forEach(function (line) { for (var i = 0; i < line.length; i++) { - core.fillText('ui', line[i], core._PX_ / 2 + 32 * (i - 5) + offset, now); + core.fillText( + 'ui', + line[i], + core._PX_ / 2 + 32 * (i - 5) + offset, + now + ); } now += 32; }); - core.fillText("ui", "返回游戏", core._PX_ / 2 + 128 + offset, now - 3, '#FFFFFF', this._buildFont(15, true)); + core.fillText( + 'ui', + '返回游戏', + core._PX_ / 2 + 128 + offset, + now - 3, + '#FFFFFF', + this._buildFont(15, true) + ); if (isWindowSkin) - this._drawWindowSelector(core.status.textAttribute.background, core._PX_ / 2 + 92 + offset, now - 22, 72, 27); + this._drawWindowSelector( + core.status.textAttribute.background, + core._PX_ / 2 + 92 + offset, + now - 22, + 72, + 27 + ); else - core.strokeRoundRect('ui', core._PX_ / 2 + 92 + offset, now - 22, 72, 27, 6, core.status.globalAttribute.selectColor, 2); -} + core.strokeRoundRect( + 'ui', + core._PX_ / 2 + 92 + offset, + now - 22, + 72, + 27, + 6, + core.status.globalAttribute.selectColor, + 2 + ); +}; ////// 绘制状态栏 ///// ui.prototype.drawStatusBar = function () { this.uidata.drawStatusBar(); -} +}; ////// 绘制“数据统计”界面 ////// ui.prototype._drawStatistics = function (floorIds) { @@ -3157,27 +4643,60 @@ ui.prototype._drawStatistics = function (floorIds) { core.ui._drawStatistics_floorId(floorId, obj); }); var statistics = core.status.hero.statistics; - core.setFlag("__replayText__", true); + core.setFlag('__replayText__', true); core.drawText([ - this._drawStatistics_generateText(obj, "全塔", obj.total), - this._drawStatistics_generateText(obj, "当前", obj.current), - this._drawStatistics_generateText(obj, "标记(浏览地图时B键或左下角)", obj.marked), - "当前总步数:" + core.status.hero.steps + ",当前游戏时长:" + core.formatTime(statistics.currTime) - + ",总游戏时长" + core.formatTime(statistics.totalTime) - + "。\n瞬间移动次数:" + statistics.moveDirectly + ",共计少走" + statistics.ignoreSteps + "步。" - + "\n\n总计通过血瓶恢复生命值为" + core.formatBigNumber(statistics.hp) + "点。\n\n" - + "总计打死了" + statistics.battle + "个怪物,得到了" + core.formatBigNumber(statistics.money) + "金币," + core.formatBigNumber(statistics.exp) + "点经验。\n\n" - + "受到的总伤害为" + core.formatBigNumber(statistics.battleDamage + statistics.poisonDamage + statistics.extraDamage) - + ",其中战斗伤害" + core.formatBigNumber(statistics.battleDamage) + "点" - + (core.flags.statusBarItems.indexOf('enableDebuff') >= 0 ? (",中毒伤害" + core.formatBigNumber(statistics.poisonDamage) + "点") : "") - + ",领域/夹击/阻击/血网伤害" + core.formatBigNumber(statistics.extraDamage) + "点。", - "\t[说明]1. 地图数据统计的效果仅模拟当前立刻获得该道具的效果。\n2. 不会计算“不可被浏览地图”的隐藏层的数据。\n" + - "3. 不会计算任何通过事件得到的道具(显示事件、改变图块、或直接增加道具等)。\n" + - "4. 在自定义道具(例如其他宝石)后,需在脚本编辑的drawStatistics中注册,不然不会进行统计。\n" + - "5. 道具不会统计通过插入事件或useItemEvent实现的效果。\n6. 所有统计信息仅供参考,如有错误,概不负责。" - ]) - core.removeFlag("__replayText__"); -} + this._drawStatistics_generateText(obj, '全塔', obj.total), + this._drawStatistics_generateText(obj, '当前', obj.current), + this._drawStatistics_generateText( + obj, + '标记(浏览地图时B键或左下角)', + obj.marked + ), + '当前总步数:' + + core.status.hero.steps + + ',当前游戏时长:' + + core.formatTime(statistics.currTime) + + ',总游戏时长' + + core.formatTime(statistics.totalTime) + + '。\n瞬间移动次数:' + + statistics.moveDirectly + + ',共计少走' + + statistics.ignoreSteps + + '步。' + + '\n\n总计通过血瓶恢复生命值为' + + core.formatBigNumber(statistics.hp) + + '点。\n\n' + + '总计打死了' + + statistics.battle + + '个怪物,得到了' + + core.formatBigNumber(statistics.money) + + '金币,' + + core.formatBigNumber(statistics.exp) + + '点经验。\n\n' + + '受到的总伤害为' + + core.formatBigNumber( + statistics.battleDamage + + statistics.poisonDamage + + statistics.extraDamage + ) + + ',其中战斗伤害' + + core.formatBigNumber(statistics.battleDamage) + + '点' + + (core.flags.statusBarItems.indexOf('enableDebuff') >= 0 + ? ',中毒伤害' + + core.formatBigNumber(statistics.poisonDamage) + + '点' + : '') + + ',领域/夹击/阻击/血网伤害' + + core.formatBigNumber(statistics.extraDamage) + + '点。', + '\t[说明]1. 地图数据统计的效果仅模拟当前立刻获得该道具的效果。\n2. 不会计算“不可被浏览地图”的隐藏层的数据。\n' + + '3. 不会计算任何通过事件得到的道具(显示事件、改变图块、或直接增加道具等)。\n' + + '4. 在自定义道具(例如其他宝石)后,需在脚本编辑的drawStatistics中注册,不然不会进行统计。\n' + + '5. 道具不会统计通过插入事件或useItemEvent实现的效果。\n6. 所有统计信息仅供参考,如有错误,概不负责。' + ]); + core.removeFlag('__replayText__'); +}; ui.prototype._drawStatistics_buildObj = function () { // 数据统计要统计如下方面: @@ -3189,58 +4708,72 @@ ui.prototype._drawStatistics_buildObj = function () { // 6. 当前已恢复的生命值;当前总伤害、战斗伤害、阻激夹域血网伤害、中毒伤害。 var ori = this.uidata.drawStatistics(); var ids = ori.filter(function (e) { - return e.endsWith("Door") || core.material.items[e]; + return e.endsWith('Door') || core.material.items[e]; }); - var cnt = {}, cls = {}, ext = {}; + var cnt = {}, + cls = {}, + ext = {}; ids.forEach(function (e) { - if (e.endsWith("Door")) cls[e] = "doors"; + if (e.endsWith('Door')) cls[e] = 'doors'; else cls[e] = core.material.items[e].cls; cnt[e] = 0; - }) - var order = ["doors", "items", "tools", "constants", "equips"]; + }); + var order = ['doors', 'items', 'tools', 'constants', 'equips']; ids.sort(function (a, b) { - var c1 = order.indexOf(cls[a]), c2 = order.indexOf(cls[b]); + var c1 = order.indexOf(cls[a]), + c2 = order.indexOf(cls[b]); if (c1 == c2) return ori.indexOf(a) - ori.indexOf(b); return c1 - c2; }); var obj = { - 'monster': { - 'count': 0, 'money': 0, 'exp': 0, 'point': 0, + monster: { + count: 0, + money: 0, + exp: 0, + point: 0 }, - 'count': cnt, - 'add': { - 'hp': 0, 'atk': 0, 'def': 0, 'mdef': 0 + count: cnt, + add: { + hp: 0, + atk: 0, + def: 0, + mdef: 0 } }; - return { ids: ids, cls: cls, ext: ext, total: core.clone(obj), current: core.clone(obj), marked: core.clone(obj) }; -} + return { + ids: ids, + cls: cls, + ext: ext, + total: core.clone(obj), + current: core.clone(obj), + marked: core.clone(obj) + }; +}; ui.prototype._drawStatistics_add = function (floorId, obj, x1, x2, value) { obj.total[x1][x2] += value || 0; - if (floorId == core.status.floorId) - obj.current[x1][x2] += value || 0; - if (core.markedFloorIds[floorId]) - obj.marked[x1][x2] += value || 0; -} + if (floorId == core.status.floorId) obj.current[x1][x2] += value || 0; + if (core.markedFloorIds[floorId]) obj.marked[x1][x2] += value || 0; +}; ui.prototype._drawStatistics_floorId = function (floorId, obj) { core.extractBlocks(floorId); - var floor = core.status.maps[floorId], blocks = floor.blocks; + var floor = core.status.maps[floorId], + blocks = floor.blocks; // 隐藏层不给看 if (floor.cannotViewMap && floorId != core.status.floorId) return; blocks.forEach(function (block) { if (block.disable) return; var event = block.event; - if (event.cls.indexOf("enemy") == 0) { + if (event.cls.indexOf('enemy') == 0) { core.ui._drawStatistics_enemy(floorId, event.id, obj); - } - else { + } else { var id = event.id; if (obj.total.count[id] != null) core.ui._drawStatistics_items(floorId, floor, id, obj); } - }) -} + }); +}; ui.prototype._drawStatistics_enemy = function (floorId, id, obj) { var enemy = core.material.enemys[id]; @@ -3248,17 +4781,21 @@ ui.prototype._drawStatistics_enemy = function (floorId, id, obj) { this._drawStatistics_add(floorId, obj, 'monster', 'exp', enemy.exp); this._drawStatistics_add(floorId, obj, 'monster', 'point', enemy.point); this._drawStatistics_add(floorId, obj, 'monster', 'count', 1); -} +}; ui.prototype._drawStatistics_items = function (floorId, floor, id, obj) { - var hp = 0, atk = 0, def = 0, mdef = 0; + var hp = 0, + atk = 0, + def = 0, + mdef = 0; if (obj.cls[id] == 'items' && id != 'superPotion') { var temp = core.clone(core.status.hero); - core.setFlag("__statistics__", true); + core.setFlag('__statistics__', true); var ratio = core.status.thisMap.ratio; core.status.thisMap.ratio = core.clone(core.status.maps[floorId].ratio); - try { eval(core.material.items[id].itemEffect); } - catch (e) { } + try { + eval(core.material.items[id].itemEffect); + } catch (e) {} core.status.thisMap.ratio = ratio; hp = core.status.hero.hp - temp.hp; atk = core.status.hero.atk - temp.atk; @@ -3267,64 +4804,78 @@ ui.prototype._drawStatistics_items = function (floorId, floor, id, obj) { core.status.hero = temp; window.hero = core.status.hero; window.flags = core.status.hero.flags; - } - else if (obj.cls[id] == 'equips') { + } else if (obj.cls[id] == 'equips') { var values = core.material.items[id].equip || {}; atk = values.atk || 0; def = values.def || 0; mdef = values.mdef || 0; } - if (id.indexOf('sword') == 0 || id.indexOf('shield') == 0 || obj.cls[id] == 'equips') { - var t = ""; + if ( + id.indexOf('sword') == 0 || + id.indexOf('shield') == 0 || + obj.cls[id] == 'equips' + ) { + var t = ''; if (atk > 0) t += atk + core.getStatusLabel('atk'); if (def > 0) t += def + core.getStatusLabel('def'); if (mdef > 0) t += mdef + core.getStatusLabel('mdef'); - if (t != "") obj.ext[id] = t; + if (t != '') obj.ext[id] = t; } this._drawStatistics_add(floorId, obj, 'count', id, 1); this._drawStatistics_add(floorId, obj, 'add', 'hp', hp); this._drawStatistics_add(floorId, obj, 'add', 'atk', atk); this._drawStatistics_add(floorId, obj, 'add', 'def', def); this._drawStatistics_add(floorId, obj, 'add', 'mdef', mdef); -} +}; ui.prototype._drawStatistics_generateText = function (obj, type, data) { - var text = type + "地图中:\n"; - text += "共有怪物" + data.monster.count + "个"; - if (core.flags.statusBarItems.indexOf('enableMoney') >= 0) text += ",总金币数" + data.monster.money; - if (core.flags.statusBarItems.indexOf('enableExp') >= 0) text += ",总经验数" + data.monster.exp; - if (core.flags.enableAddPoint) text += ",总加点数" + data.monster.point; - text += "。\n"; + var text = type + '地图中:\n'; + text += '共有怪物' + data.monster.count + '个'; + if (core.flags.statusBarItems.indexOf('enableMoney') >= 0) + text += ',总金币数' + data.monster.money; + if (core.flags.statusBarItems.indexOf('enableExp') >= 0) + text += ',总经验数' + data.monster.exp; + if (core.flags.enableAddPoint) text += ',总加点数' + data.monster.point; + text += '。\n'; - var prev = ""; + var prev = ''; obj.ids.forEach(function (key) { var value = data.count[key]; if (value == 0) return; if (obj.cls[key] != prev) { - if (prev != "") text += "。"; - text += "\n"; - } - else text += ","; + if (prev != '') text += '。'; + text += '\n'; + } else text += ','; prev = obj.cls[key]; - var name = ((core.material.items[key] || (core.getBlockById(key) || {}).event) || {}).name || key; - text += name + value + "个"; - if (obj.ext[key]) - text += "(" + obj.ext[key] + ")"; - }) - if (prev != "") text += "。"; + var name = + ( + core.material.items[key] || + (core.getBlockById(key) || {}).event || + {} + ).name || key; + text += name + value + '个'; + if (obj.ext[key]) text += '(' + obj.ext[key] + ')'; + }); + if (prev != '') text += '。'; - text += "\n"; - text += "共加生命值" + core.formatBigNumber(data.add.hp) + "点,攻击" - + core.formatBigNumber(data.add.atk) + "点,防御" - + core.formatBigNumber(data.add.def) + "点,护盾" - + core.formatBigNumber(data.add.mdef) + "点。"; + text += '\n'; + text += + '共加生命值' + + core.formatBigNumber(data.add.hp) + + '点,攻击' + + core.formatBigNumber(data.add.atk) + + '点,防御' + + core.formatBigNumber(data.add.def) + + '点,护盾' + + core.formatBigNumber(data.add.mdef) + + '点。'; return text; -} +}; ////// 绘制“关于”界面 ////// ui.prototype._drawAbout = function () { return this.uidata.drawAbout(); -} +}; ////// 绘制帮助页面 ////// ui.prototype._drawHelp = function () { @@ -3336,34 +4887,37 @@ ui.prototype._drawHelp = function () { core.setAlpha('ui', 1); core.fillRect('ui', 0, 0, core._PX_, core._PY_, '#000000'); core.drawImage('ui', core.material.images.keyboard, 0, 0); - } - else { + } else { core.drawText([ - "\t[键盘快捷键列表]" + - "[CTRL] 跳过对话 [Z] 转向\n" + - "[X] " + core.material.items['book'].name + " [G] " + core.material.items['fly'].name + "\n" + - "[A] 读取自动存档 [W] 撤销读取自动存档\n" + - "[S/D] 存读档页面 [SPACE] 轻按\n" + - "[V] 快捷商店 [ESC] 系统菜单\n" + - "[T] 道具页面 [Q] 装备页面\n" + - "[B] 数据统计 [H] 帮助页面\n" + - "[R] 回放录像 [E] 显示光标\n" + - "[N] 返回标题页面 [P] 游戏主页\n" + - "[O] 查看工程 [F7] 打开debug穿墙模式\n" + - "[PgUp/PgDn] 浏览地图\n" + - "[1~4] 快捷使用破炸飞和其他道具\n" + - "[Alt+0~9] 快捷换装", - "\t[鼠标操作]" + - "点状态栏中图标: 进行对应的操作\n" + - "点任意块: 寻路并移动\n" + - "点任意块并拖动: 指定寻路路线\n" + - "双击空地: 瞬间移动\n" + - "单击勇士: 转向\n" + - "双击勇士: 轻按(仅在轻按开关打开时有效)\n" + - "长按任意位置:跳过剧情对话或打开虚拟键盘" + '\t[键盘快捷键列表]' + + '[CTRL] 跳过对话 [Z] 转向\n' + + '[X] ' + + core.material.items['book'].name + + ' [G] ' + + core.material.items['fly'].name + + '\n' + + '[A] 读取自动存档 [W] 撤销读取自动存档\n' + + '[S/D] 存读档页面 [SPACE] 轻按\n' + + '[V] 快捷商店 [ESC] 系统菜单\n' + + '[T] 道具页面 [Q] 装备页面\n' + + '[B] 数据统计 [H] 帮助页面\n' + + '[R] 回放录像 [E] 显示光标\n' + + '[N] 返回标题页面 [P] 游戏主页\n' + + '[O] 查看工程 [F7] 打开debug穿墙模式\n' + + '[PgUp/PgDn] 浏览地图\n' + + '[1~4] 快捷使用破炸飞和其他道具\n' + + '[Alt+0~9] 快捷换装', + '\t[鼠标操作]' + + '点状态栏中图标: 进行对应的操作\n' + + '点任意块: 寻路并移动\n' + + '点任意块并拖动: 指定寻路路线\n' + + '双击空地: 瞬间移动\n' + + '单击勇士: 转向\n' + + '双击勇士: 轻按(仅在轻按开关打开时有效)\n' + + '长按任意位置:跳过剧情对话或打开虚拟键盘' ]); } -} +}; ////// 动态canvas ////// @@ -3376,11 +4930,11 @@ ui.prototype.createCanvas = function (name, x, y, width, height, z) { core.dymCanvas[name].canvas.style.zIndex = z; return core.dymCanvas[name]; } - var newCanvas = document.createElement("canvas"); + var newCanvas = document.createElement('canvas'); newCanvas.id = name; newCanvas.style.display = 'block'; - newCanvas.setAttribute("_left", x); - newCanvas.setAttribute("_top", y); + newCanvas.setAttribute('_left', x); + newCanvas.setAttribute('_top', y); newCanvas.style.width = width * core.domStyle.scale + 'px'; newCanvas.style.height = height * core.domStyle.scale + 'px'; newCanvas.style.left = x * core.domStyle.scale + 'px'; @@ -3392,7 +4946,7 @@ ui.prototype.createCanvas = function (name, x, y, width, height, z) { core.maps._setHDCanvasSize(core.dymCanvas[name], width, height); core.dom.gameDraw.appendChild(newCanvas); return core.dymCanvas[name]; -} +}; ////// canvas重定位 ////// ui.prototype.relocateCanvas = function (name, x, y, useDelta) { @@ -3401,21 +4955,21 @@ ui.prototype.relocateCanvas = function (name, x, y, useDelta) { if (x != null) { // 增量模式 if (useDelta) { - x += parseFloat(ctx.canvas.getAttribute("_left")) || 0; + x += parseFloat(ctx.canvas.getAttribute('_left')) || 0; } ctx.canvas.style.left = x * core.domStyle.scale + 'px'; - ctx.canvas.setAttribute("_left", x); + ctx.canvas.setAttribute('_left', x); } if (y != null) { // 增量模式 if (useDelta) { - y += parseFloat(ctx.canvas.getAttribute("_top")) || 0; + y += parseFloat(ctx.canvas.getAttribute('_top')) || 0; } ctx.canvas.style.top = y * core.domStyle.scale + 'px'; - ctx.canvas.setAttribute("_top", y); + ctx.canvas.setAttribute('_top', y); } return ctx; -} +}; ////// canvas旋转 ////// ui.prototype.rotateCanvas = function (name, angle, centerX, centerY) { @@ -3426,9 +4980,13 @@ ui.prototype.rotateCanvas = function (name, angle, centerX, centerY) { if (centerX == null || centerY == null) { canvas.style.transformOrigin = ''; } else { - var left = parseFloat(canvas.getAttribute("_left")); - var top = parseFloat(canvas.getAttribute("_top")); - canvas.style.transformOrigin = (centerX - left) * core.domStyle.scale + 'px ' + (centerY - top) * core.domStyle.scale + 'px'; + var left = parseFloat(canvas.getAttribute('_left')); + var top = parseFloat(canvas.getAttribute('_top')); + canvas.style.transformOrigin = + (centerX - left) * core.domStyle.scale + + 'px ' + + (centerY - top) * core.domStyle.scale + + 'px'; } if (angle == 0) { canvas.style.transform = ''; @@ -3436,22 +4994,30 @@ ui.prototype.rotateCanvas = function (name, angle, centerX, centerY) { canvas.style.transform = 'rotate(' + angle + 'deg)'; } canvas.setAttribute('_angle', angle); -} +}; ////// canvas重置 ////// -ui.prototype.resizeCanvas = function (name, width, height, styleOnly, isTempCanvas) { +ui.prototype.resizeCanvas = function ( + name, + width, + height, + styleOnly, + isTempCanvas +) { var ctx = core.getContextByName(name); if (!ctx) return null; if (width != null) { - if (!styleOnly) core.maps._setHDCanvasSize(ctx, width, null, isTempCanvas); + if (!styleOnly) + core.maps._setHDCanvasSize(ctx, width, null, isTempCanvas); ctx.canvas.style.width = width * core.domStyle.scale + 'px'; } if (height != null) { - if (!styleOnly) core.maps._setHDCanvasSize(ctx, null, height, isTempCanvas); + if (!styleOnly) + core.maps._setHDCanvasSize(ctx, null, height, isTempCanvas); ctx.canvas.style.height = height * core.domStyle.scale + 'px'; } return ctx; -} +}; ////// canvas删除 ////// ui.prototype.deleteCanvas = function (name) { if (name instanceof Function) { @@ -3464,9 +5030,11 @@ ui.prototype.deleteCanvas = function (name) { if (!core.dymCanvas[name]) return null; core.dom.gameDraw.removeChild(core.dymCanvas[name].canvas); delete core.dymCanvas[name]; -} +}; ////// 删除所有动态canvas ////// ui.prototype.deleteAllCanvas = function () { - return this.deleteCanvas(function () { return true; }) -} + return this.deleteCanvas(function () { + return true; + }); +}; diff --git a/public/project/enemys.js b/public/project/enemys.js index 6d362dd..8f9d836 100644 --- a/public/project/enemys.js +++ b/public/project/enemys.js @@ -5,7 +5,7 @@ var enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80 = "blackSlime": {"name":"青头怪","hp":170,"atk":20,"def":8,"money":0,"exp":3,"point":0,"special":[]}, "slimelord": {"name":"粘液王","hp":200,"atk":58,"def":24,"money":0,"exp":8,"point":0,"special":[]}, "bat": {"name":"小蝙蝠","hp":60,"atk":15,"def":0,"money":0,"exp":2,"point":0,"special":[4]}, - "bigBat": {"name":"大蝙蝠","hp":150,"atk":17,"def":5,"money":0,"exp":4,"point":0,"special":[4]}, + "bigBat": {"name":"大蝙蝠","hp":150,"atk":17,"def":5,"money":0,"exp":4,"point":0,"special":[4,5,6],"crit":0,"charge":0,"courage":0,"together":0,"hungry":0,"value":100,"n":1000}, "redBat": {"name":"恐怖蝙蝠","hp":1200,"atk":260,"def":110,"money":1,"exp":32,"point":0,"special":[5]}, "vampire": {"name":"冥灵魔王","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[]}, "skeleton": {"name":"骷髅人","hp":300,"atk":80,"def":10,"money":0,"exp":9,"point":0,"special":[1],"crit":300}, diff --git a/public/project/plugins.js b/public/project/plugins.js index e47712b..53755ad 100644 --- a/public/project/plugins.js +++ b/public/project/plugins.js @@ -9311,5 +9311,10 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = { } return res; } + }, + "uiChange": function () { + ui.prototype.drawBook = function () { + return core.plugin.bookOpened.value = true; + } } }; diff --git a/src/components/boxAnimate.vue b/src/components/boxAnimate.vue index d682ff8..ae3c24a 100644 --- a/src/components/boxAnimate.vue +++ b/src/components/boxAnimate.vue @@ -33,12 +33,13 @@ onMounted(() => { c.height *= scale; ctx.scale(scale, scale); - const fn = (time: number) => { + const fn = () => { core.clearMap(ctx); const frame = core.status.globalAnimateStatus % frames; core.drawIcon(ctx, props.id, 0, 0, props.width, props.height, frame); }; + fn(); addAnimate(fn); onUnmounted(() => { diff --git a/src/components/enemyOne.vue b/src/components/enemyOne.vue index 765ee0a..d1da9b7 100644 --- a/src/components/enemyOne.vue +++ b/src/components/enemyOne.vue @@ -1,5 +1,5 @@ -