From 90d4488ffb116b215f0f9c5de4cc3efb2deb74c7 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Tue, 27 Oct 2020 18:51:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A6=E6=92=87=E5=AD=90=E6=A8=A1=E5=BC=8F;?= =?UTF-8?q?=E9=80=89=E9=A1=B9=E6=A1=86=E5=AE=BD=E5=BA=A6;fillText=E6=94=AF?= =?UTF-8?q?=E6=8C=81\r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/actions.js | 43 +++++++++++++++++++++++++++++++++++++++++-- libs/control.js | 1 + libs/core.js | 1 + libs/ui.js | 28 ++++++++++++++++++++++------ 4 files changed, 65 insertions(+), 8 deletions(-) diff --git a/libs/actions.js b/libs/actions.js index 5792a382..084a7392 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -125,9 +125,37 @@ 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 + 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 + } + 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](); + } + }); + newEvent.keyCode = map[e.keyCode] || e.keyCode; + return newEvent; +} + ////// 按下某个键时 ////// actions.prototype.onkeyDown = function (e) { - this.doRegisteredAction('onkeyDown', e); + this.doRegisteredAction('onkeyDown', this.__checkLeftHandPrefer(e)); } actions.prototype._sys_onkeyDown = function (e) { @@ -150,7 +178,7 @@ actions.prototype._sys_onkeyDown = function (e) { ////// 放开某个键时 ////// actions.prototype.onkeyUp = function (e) { - this.doRegisteredAction('onkeyUp', e); + this.doRegisteredAction('onkeyUp', this.__checkLeftHandPrefer(e)); } actions.prototype._sys_onkeyUp_replay = function (e) { @@ -1994,6 +2022,8 @@ actions.prototype._clickSwitchs = function (x, y) { case 8: return this._clickSwitchs_clickMove(); case 9: + return this._clickSwitchs_leftHandPrefer(); + case 10: core.status.event.selection = 0; core.ui._drawSettings(); break; @@ -2099,6 +2129,15 @@ actions.prototype._clickSwitchs_clickMove = function () { core.ui._drawSwitchs(); } +actions.prototype._clickSwitchs_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.ui._drawSwitchs(); +} + ////// 系统设置界面时,放开某个键的操作 ////// actions.prototype._keyUpSwitchs = function (keycode) { if (keycode == 27 || keycode == 88) { diff --git a/libs/control.js b/libs/control.js index 5903daca..223898ea 100644 --- a/libs/control.js +++ b/libs/control.js @@ -1176,6 +1176,7 @@ control.prototype._updateDamage_extraDamage = function (floorId, onMap) { for (var x=startX;x0) { // 该点伤害 damage = core.formatBigNumber(damage, true); diff --git a/libs/core.js b/libs/core.js index d469dffb..0f163532 100644 --- a/libs/core.js +++ b/libs/core.js @@ -318,6 +318,7 @@ core.prototype._init_sys_flags = function () { core.flags.displayEnemyDamage = core.getLocalStorage('enemyDamage', core.flags.displayEnemyDamage); core.flags.displayCritical = core.getLocalStorage('critical', core.flags.displayCritical); core.flags.displayExtraDamage = core.getLocalStorage('extraDamage', core.flags.displayExtraDamage); + core.flags.leftHandPrefer = core.getLocalStorage('leftHandPrefer', false); // 行走速度 core.values.moveSpeed = core.getLocalStorage('moveSpeed', 100); core.values.floorChangeTime = core.getLocalStorage('floorChangeTime', core.values.floorChangeTime); diff --git a/libs/ui.js b/libs/ui.js index cbedaa6d..d26eef1b 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -81,11 +81,26 @@ ui.prototype.fillText = function (name, text, x, y, style, font, maxWidth) { if (style) core.setFillStyle(name, style); if (font) core.setFont(name, font); var ctx = this.getContextByName(name); - if (ctx) { - // 如果存在最大宽度 - if (maxWidth != null) { - this.setFontForMaxWidth(ctx, text, maxWidth); + if (!ctx) return; + var currentStyle = ctx.fillStyle; + text = (text + "").replace(/\\r/g, '\r'); + var index = text.indexOf('\r'); + if (maxWidth != null) { + this.setFontForMaxWidth(ctx, index >= 0 ? text.replace(/\r(\[.*\])?/g, "") : text, maxWidth); + } + if (index >= 0) { + 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]; + width += core.calWidth(ctx, subtext, x, y); + ctx.fillText(subtext, x + width, y); } + ctx.fillStyle = currentStyle; + } else { ctx.fillText(text, x, y); } } @@ -1576,8 +1591,8 @@ ui.prototype.drawChoices = function(content, choices) { } ui.prototype._drawChoices_getHorizontalPosition = function (titleInfo, choices) { - // 宽度计算:考虑选项的长度 - var width = 246; + // 宽度计算:考虑提示文字和选项的长度 + var width = this._calTextBoxWidth('ui', titleInfo.content || "", 246, this.PIXEL - 20); core.setFont('ui', this._buildFont(17, true)); for (var i = 0; i < choices.length; i++) { if (typeof choices[i] === 'string') @@ -1759,6 +1774,7 @@ ui.prototype._drawSwitchs = function() { "临界/领域: "+(core.flags.displayCritical ? "[ON]" : "[OFF]")+" "+(core.flags.displayExtraDamage ? "[ON]" : "[OFF]"), "血瓶绕路: "+(core.hasFlag('__potionNoRouting__') ? "[ON]":"[OFF]"), "单击瞬移: "+(!core.hasFlag("__noClickMove__") ? "[ON]":"[OFF]"), + "左撇模式: "+(core.flags.leftHandPrefer ? "[ON]":"[OFF]"), "返回主菜单" ]; this.drawChoices(null, choices);