From a9d3a94f0ee4e5566bff7ae8c7eb1ca2eb01c49d Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Tue, 22 Oct 2019 19:34:40 +0800 Subject: [PATCH] optimize 264 --- _server/MotaAction.g4 | 16 ++++++++-------- libs/ui.js | 18 +++++------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/_server/MotaAction.g4 b/_server/MotaAction.g4 index f5de3a74..9cf927f7 100644 --- a/_server/MotaAction.g4 +++ b/_server/MotaAction.g4 @@ -2388,28 +2388,28 @@ return code; */; drawSelector_s - : '绘制闪烁光标' EvalString '起点像素' 'x' PosString 'y' PosString '宽' PosString '高' PosString '清空已有光标' Bool Newline + : '绘制闪烁光标' EvalString '编号' Int '起点像素' 'x' PosString 'y' PosString '宽' PosString '高' PosString Newline /* drawSelector_s tooltip : drawSelector:绘制闪烁光标 helpUrl : https://h5mota.com/games/template/_docs/#/event?id=drawSelector%ef%bc%9a%e7%bb%98%e5%88%b6%e9%97%aa%e7%83%81%e5%85%89%e6%a0%87 -default : ["winskin.png","0","0","100","100", false] +default : ["winskin.png","1","0","0","100","100"] colour : this.subColor -Bool_0 = Bool_0 ? (',"clear": true') : ''; -var code = '{"type": "drawSelector", "image": "'+EvalString_0+'", "x": '+PosString_0+', "y": '+PosString_1+', "width": '+PosString_2+', "height": '+PosString_3+Bool_0+'},\n'; +var code = '{"type": "drawSelector", "image": "'+EvalString_0+'", "code": '+Int_0+', "x": '+PosString_0+', "y": '+PosString_1+', "width": '+PosString_2+', "height": '+PosString_3+'},\n'; return code; */; drawSelector_1_s - : '清除闪烁光标' Newline + : '清除闪烁光标' '编号' Int Newline /* drawSelector_1_s tooltip : drawSelector:清除闪烁光标 helpUrl : https://h5mota.com/games/template/_docs/#/event?id=showImage%ef%bc%9a%e6%98%be%e7%a4%ba%e5%9b%be%e7%89%87 +default : ["1"] colour : this.subColor -var code = '{"type": "drawSelector"},\n'; +var code = '{"type": "drawSelector", "code": '+Int_0+'},\n'; return code; */; @@ -3541,11 +3541,11 @@ ActionParser.prototype.parseAction = function() { case "drawSelector": // 绘制光标 if (data.image) { this.next = MotaActionBlocks['drawSelector_s'].xmlText([ - data.image, data.x, data.y, data.width, data.height, data.clear || false, this.next + data.image, data.code, data.x, data.y, data.width, data.height, this.next ]); } else { - this.next = MotaActionBlocks['drawSelector_1_s'].xmlText([this.next]); + this.next = MotaActionBlocks['drawSelector_1_s'].xmlText([data.code, this.next]); } case "animateImage": // 兼容 animateImage break; diff --git a/libs/ui.js b/libs/ui.js index b259c760..302e902f 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -644,15 +644,9 @@ ui.prototype.drawWindowSelector = function(background, x, y, w, h) { this._drawSelector(ctx, background, w, h); } -ui.prototype._deleteAllSelectors = function () { - for (var i = 0; core.dymCanvas['_uievent_selector_' + i]; i++) { - core.deleteCanvas('_uievent_selector_' + i); - } -} - ui.prototype._uievent_drawSelector = function (data) { - if (data.image == null) return this._deleteAllSelectors(); - if (data.clear) this,this._deleteAllSelectors(); + var canvasName = '_uievent_selector_' + (data.code || 0); + if (data.image == null) return core.deleteCanvas(canvasName); var background = data.image || core.status.textAttribute.background; if (typeof background != 'string') return; @@ -664,10 +658,8 @@ ui.prototype._uievent_drawSelector = function (data) { } var z = 136; if (core.dymCanvas.uievent) z = (parseInt(core.dymCanvas.uievent.canvas.style.zIndex) || 135) + 1; - var i = 0; - while (core.dymCanvas['_uievent_selector_' + i]) i++; - var ctx = core.createCanvas('_uievent_selector_' + i, x, y, w, h, z); - ctx.canvas.classlist.add('_uievent_selector'); + var ctx = core.createCanvas(canvasName, x, y, w, h, z); + ctx.canvas.classList.add('_uievent_selector'); this._drawSelector(ctx, background, w, h); } @@ -1721,7 +1713,7 @@ ui.prototype._drawBook_drawName = function (index, enemy, top, left, width) { } else { core.fillText('ui', enemy.name, left + width / 2, - top + 28, '#DDDDDD', this._buildFont(17, true)); + top + 28, '#DDDDDD', this._buildFont(17, true), width); core.fillText('ui', enemy.specialText, left + width / 2, top + 50, '#FF6A6A', this._buildFont(15, true), width); }