From f6ac9610cc91b9f7bf1c015ad4f02036b608cf3b Mon Sep 17 00:00:00 2001 From: oc Date: Sun, 28 Apr 2019 21:14:14 +0800 Subject: [PATCH] hero any width --- _docs/event.md | 2 +- libs/control.js | 15 +++++++++------ libs/events.js | 13 +++++++------ libs/ui.js | 22 ++++++++++++++++------ project/functions.js | 1 + project/icons.js | 1 + 6 files changed, 35 insertions(+), 19 deletions(-) diff --git a/_docs/event.md b/_docs/event.md index dd104f48..1df664c1 100644 --- a/_docs/event.md +++ b/_docs/event.md @@ -180,7 +180,7 @@ 我们可以给文字加上标题或图标,只要以`\t[...]`开头就可以。 -其一般写法是`\t[名字,ID]`,其中名字为你要显示的标题,ID为图块ID,只能为open`hero`,或者NPC/怪物的图块ID。 +其一般写法是`\t[名字,ID]`,其中名字为你要显示的标题,ID为图块ID,只能为`hero`,或者NPC/怪物的图块ID。 如果不需要可以不写ID,则只会显示标题。 diff --git a/libs/control.js b/libs/control.js index 36bdf40c..4145e01e 100644 --- a/libs/control.js +++ b/libs/control.js @@ -777,9 +777,9 @@ control.prototype.drawHero = function (status, offset) { core.clearMap('hero'); this._drawHero_getDrawObjs(direction, x, y, status, offset).forEach(function (block) { - core.drawImage('hero', block.img, block.heroIcon[block.status]*32, - block.heroIcon.loc * block.height, 32, block.height, - block.posx, block.posy+32-block.height, 32, block.height); + core.drawImage('hero', block.img, block.heroIcon[block.status]*block.width, + block.heroIcon.loc * block.height, block.width, block.height, + block.posx+(32-block.width)/2, block.posy+32-block.height, block.width, block.height); }); core.control.updateViewport(); @@ -789,6 +789,7 @@ control.prototype._drawHero_getDrawObjs = function (direction, x, y, status, off var heroIconArr = core.material.icons.hero, drawObjs = [], index = 0; drawObjs.push({ "img": core.material.images.hero, + "width": core.material.icons.hero.width || 32, "height": core.material.icons.hero.height, "heroIcon": heroIconArr[direction], "posx": x * 32 - core.bigmap.offsetX + core.utils.scan[direction].x * offset, @@ -799,6 +800,7 @@ control.prototype._drawHero_getDrawObjs = function (direction, x, y, status, off (core.status.hero.followers||[]).forEach(function (t) { drawObjs.push({ "img": core.material.images.images[t.name], + "width": core.material.images.images[t.name].width/4, "height": core.material.images.images[t.name].height/4, "heroIcon": heroIconArr[t.direction], "posx": 32*t.x - core.bigmap.offsetX + (t.stop?0:core.utils.scan[t.direction].x*offset), @@ -2345,14 +2347,15 @@ control.prototype.updateHeroIcon = function (name) { var image = core.material.images.hero; // 全身图 - var height = core.material.icons.hero.height; - var ratio = 32 / height, width = 32 * ratio, left = 16-width/2; + var w = core.material.icons.hero.width || 32; + var h = core.material.icons.hero.height || 48; + var ratio = Math.max(w / h, 1), width = 32 * ratio, left = 16 - width/2; var canvas = document.createElement("canvas"); var context = canvas.getContext("2d"); canvas.width = 32; canvas.height = 32; - context.drawImage(image, 0, 0, 32, height, left, 0, width, 32); + context.drawImage(image, 0, 0, w, h, left, 0, width, 32); core.statusBar.image.name.src = canvas.toDataURL("image/png"); } diff --git a/libs/events.js b/libs/events.js index cfa68e7d..64bb9cb3 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1758,8 +1758,7 @@ events.prototype.hasAsync = function () { events.prototype.follow = function (name) { core.status.hero.followers = core.status.hero.followers || []; name = core.getMappedName(name); - if (core.material.images.images[name] - && core.material.images.images[name].width == 128) { + if (core.material.images.images[name]) { core.status.hero.followers.push({"name": name}); core.gatherFollowers(); core.clearMap('hero'); @@ -2139,6 +2138,7 @@ events.prototype.jumpHero = function (ex, ey, time, callback) { core.playSound('jump.mp3'); var jumpInfo = core.maps.__generateJumpInfo(sx, sy, ex, ey, time || 500); jumpInfo.icon = core.material.icons.hero[core.getHeroLoc('direction')]; + jumpInfo.width = core.material.icons.hero.width || 32; jumpInfo.height = core.material.icons.hero.height; this._jumpHero_doJump(jumpInfo, callback); @@ -2158,12 +2158,12 @@ events.prototype._jumpHero_doJump = function (jumpInfo, callback) { events.prototype._jumpHero_jumping = function (jumpInfo) { core.clearMap('hero'); core.maps.__updateJumpInfo(jumpInfo); - var nowx = jumpInfo.px, nowy = jumpInfo.py, height = jumpInfo.height; + var nowx = jumpInfo.px, nowy = jumpInfo.py, width = jumpInfo.width || 32, height = jumpInfo.height; core.bigmap.offsetX = core.clamp(nowx - 32*core.__HALF_SIZE__, 0, 32*core.bigmap.width-core.__PIXELS__); core.bigmap.offsetY = core.clamp(nowy - 32*core.__HALF_SIZE__, 0, 32*core.bigmap.height-core.__PIXELS__); core.control.updateViewport(); - core.drawImage('hero', core.material.images.hero, jumpInfo.icon.stop, jumpInfo.icon.loc * height, 32, height, - nowx - core.bigmap.offsetX, nowy + 32-height - core.bigmap.offsetY, 32, height); + core.drawImage('hero', core.material.images.hero, jumpInfo.icon.stop, jumpInfo.icon.loc * height, width, height, + nowx + (32 - width) / 2 - core.bigmap.offsetX, nowy + 32-height - core.bigmap.offsetY, width, height); } events.prototype._jumpHero_finished = function (animate, ex, ey, callback) { @@ -2251,9 +2251,10 @@ events.prototype.canUseQuickShop = function (shopId) { events.prototype.setHeroIcon = function (name, noDraw) { name = core.getMappedName(name); var img = core.material.images.images[name]; - if (!img || img.width != 128) return; + if (!img) return; core.setFlag("heroIcon", name); core.material.images.hero.onload = function () { + core.material.icons.hero.width = img.width / 4; core.material.icons.hero.height = img.height / 4; core.control.updateHeroIcon(name); if (!noDraw) core.drawHero(); diff --git a/libs/ui.js b/libs/ui.js index 67e5ad85..aca20dd8 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -373,7 +373,8 @@ ui.prototype._getTitleAndIcon = function (content) { title = core.status.hero.name; image = core.material.images.hero; icon = 0; - height = core.material.icons.hero.height; + 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); @@ -928,11 +929,20 @@ ui.prototype._drawTextBox_drawTitleAndIcon = function (titleInfo, hPos, vPos, al core.strokeRect('ui', hPos.left + 15 - 1, image_top-1, 34, titleInfo.height + 2, null, 2); core.setAlpha('ui', 1); core.status.boxAnimateObjs = []; - 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 - }); + // --- 勇士 + if (titleInfo.image == core.material.images.hero) { + core.clearMap('ui', hPos.left + 15, image_top, 32, titleInfo.height); + core.fillRect('ui', hPos.left + 15, image_top, 32, titleInfo.height, core.material.groundPattern); + core.drawImage('ui', titleInfo.image, 0, 0, core.material.icons.hero.width || 32, core.material.icons.hero.height, + hPos.left + 15, image_top, 32, titleInfo.height); + } + 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 + }); + } core.drawBoxAnimate(); } if (titleInfo.image != null && titleInfo.icon == null) { // 头像图 diff --git a/project/functions.js b/project/functions.js index 5b007f7a..e2497c87 100644 --- a/project/functions.js +++ b/project/functions.js @@ -973,6 +973,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = icon = core.getMappedName(icon); if (core.material.images.images[icon]) { core.material.images.hero.src = core.material.images.images[icon].src; + core.material.icons.hero.width = core.material.images.images[icon].width / 4; core.material.icons.hero.height = core.material.images.images[icon].height / 4; } // 刷新怪物数据 diff --git a/project/icons.js b/project/icons.js index 0fe339c2..e9d0ae7c 100644 --- a/project/icons.js +++ b/project/icons.js @@ -25,6 +25,7 @@ var icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1 = "leftFoot": 1, "rightFoot": 3 }, + "width": 32, "height": 48 }, "terrains": {