左撇子模式;选项框宽度;fillText支持\r

This commit is contained in:
ckcz123 2020-10-27 18:51:10 +08:00
parent dc4a77afcd
commit 90d4488ffb
4 changed files with 65 additions and 8 deletions

View File

@ -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) {

View File

@ -1176,6 +1176,7 @@ control.prototype._updateDamage_extraDamage = function (floorId, onMap) {
for (var x=startX;x<endX;x++) {
for (var y=startY;y<endY;y++) {
if (core.noPass(x, y, floorId)) continue;
var damage = core.status.checkBlock.damage[x+","+y]||0;
if (damage>0) { // 该点伤害
damage = core.formatBigNumber(damage, true);

View File

@ -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);

View File

@ -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);