From 3565b2256a9b5eecc1ed8523dc820c4ebde52204 Mon Sep 17 00:00:00 2001 From: oc Date: Thu, 11 Oct 2018 21:51:41 +0800 Subject: [PATCH] Name on statusBar --- _server/data.comment.js | 6 ++++ editor-mobile.html | 4 +++ editor.html | 4 +++ index.html | 4 +++ libs/control.js | 78 ++++++++++++++++++++++++++++++----------- libs/core.js | 6 ++-- libs/events.js | 9 +++-- main.js | 4 +++ project/data.js | 1 + project/functions.js | 5 ++- styles.css | 4 +++ 11 files changed, 98 insertions(+), 27 deletions(-) diff --git a/_server/data.comment.js b/_server/data.comment.js index 94a6fcbb..a149b17b 100644 --- a/_server/data.comment.js +++ b/_server/data.comment.js @@ -351,6 +351,12 @@ data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = "_bool": "bool", "_data": "是否在状态栏显示当前楼层" }, + "enableName": { + "_leaf": true, + "_type": "checkbox", + "_bool": "bool", + "_data": "是否在状态栏显示勇士名字" + }, "enableLv": { "_leaf": true, "_type": "checkbox", diff --git a/editor-mobile.html b/editor-mobile.html index 3f656e78..b04d75ae 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -333,6 +333,10 @@

+
+ +

+

diff --git a/editor.html b/editor.html index f3d9b16f..1a37ee1b 100644 --- a/editor.html +++ b/editor.html @@ -319,6 +319,10 @@

+
+ +

+

diff --git a/index.html b/index.html index 7710ce4e..f84ce4e1 100644 --- a/index.html +++ b/index.html @@ -46,6 +46,10 @@

+
+ +

+

diff --git a/libs/control.js b/libs/control.js index 80a4e03e..505ab2d4 100644 --- a/libs/control.js +++ b/libs/control.js @@ -250,6 +250,8 @@ control.prototype.clearStatus = function() { } core.status = {}; core.clearStatusBar(); + core.status.played = false; + core.events.setHeroIcon('hero.png', true); } ////// 重置游戏状态和初始数据 ////// @@ -266,7 +268,6 @@ control.prototype.resetStatus = function(hero, hard, floorId, route, maps, value // 初始化status core.status = core.clone(core.initStatus); - core.status.played = true; // 初始化maps core.status.floorId = floorId; core.status.maps = core.clone(maps); @@ -275,6 +276,8 @@ control.prototype.resetStatus = function(hero, hard, floorId, route, maps, value core.material.items = core.clone(core.items.getItems()); // 初始化人物属性 core.status.hero = core.clone(hero); + // 初始化人物图标 + core.events.setHeroIcon(core.getFlag('heroIcon', 'hero.png'), true); // 统计数据 if (!core.isset(core.status.hero.statistics)) core.status.hero.statistics = { @@ -302,6 +305,7 @@ control.prototype.resetStatus = function(hero, hard, floorId, route, maps, value else core.values = core.clone(core.data.values); core.events.initGame(); + core.status.played = true; } ////// 开始游戏 ////// @@ -1022,6 +1026,8 @@ control.prototype.updateViewport = function() { ////// 绘制勇士 ////// control.prototype.drawHero = function (direction, x, y, status, offset) { + if (!core.isPlaying()) return; + var scan = { 'up': {'x': 0, 'y': -1}, 'left': {'x': -1, 'y': 0}, @@ -1197,20 +1203,22 @@ control.prototype.checkBlock = function () { // 检查阻击事件 var snipe = []; - var scan = { - 'up': {'x': 0, 'y': -1}, - 'left': {'x': -1, 'y': 0}, - 'down': {'x': 0, 'y': 1}, - 'right': {'x': 1, 'y': 0} - } - for (var direction in scan) { - var nx = x+scan[direction].x, ny=y+scan[direction].y; - if (nx<0 || nx>=core.bigmap.width || ny<0 || ny>=core.bigmap.height) continue; - var id=core.status.checkBlock.map[nx+core.bigmap.width*ny]; - if (core.isset(id)) { - var enemy = core.material.enemys[id]; - if (core.isset(enemy) && core.enemys.hasSpecial(enemy.special, 18)) { - snipe.push({'direction': direction, 'x': nx, 'y': ny}); + if (!core.hasFlag("no_snipe")) { + var scan = { + 'up': {'x': 0, 'y': -1}, + 'left': {'x': -1, 'y': 0}, + 'down': {'x': 0, 'y': 1}, + 'right': {'x': 1, 'y': 0} + } + for (var direction in scan) { + var nx = x+scan[direction].x, ny=y+scan[direction].y; + if (nx<0 || nx>=core.bigmap.width || ny<0 || ny>=core.bigmap.height) continue; + var id=core.status.checkBlock.map[nx+core.bigmap.width*ny]; + if (core.isset(id)) { + var enemy = core.material.enemys[id]; + if (core.isset(enemy) && core.enemys.hasSpecial(enemy.special, 18)) { + snipe.push({'direction': direction, 'x': nx, 'y': ny}); + } } } } @@ -2585,11 +2593,11 @@ control.prototype.playSound = function (sound) { ////// 清空状态栏 ////// control.prototype.clearStatusBar = function() { - var statusList = ['floor', 'lv', 'hpmax', 'hp', 'atk', 'def', 'mdef', 'money', 'experience', - 'up', 'yellowKey', 'blueKey', 'redKey', 'poison', 'weak', 'curse', 'hard']; - statusList.forEach(function (e) { - core.statusBar[e].innerHTML = " "; - }); + + Object.keys(core.statusBar).forEach(function (e) { + if (core.isset(core.statusBar[e].innerHTML)) + core.statusBar[e].innerHTML = " "; + }) core.statusBar.image.book.style.opacity = 0.3; if (!core.flags.equipboxButton) { core.statusBar.image.fly.style.opacity = 0.3; @@ -2645,6 +2653,27 @@ control.prototype.updateStatusBar = function () { } } +control.prototype.updateHeroIcon = function (name) { + name = name || "hero.png"; + if (core.statusBar.icons.name == name) return; + core.statusBar.icons.name = name; + + var image = core.material.images.hero; + + var canvas = document.createElement("canvas"); + var context = canvas.getContext("2d"); + canvas.width = 32; + canvas.height = 32; + context.drawImage(image, 0, 0, 32, 32, 0, 0, 32, 32); + if (core.material.icons.hero.height>=48) { + context.lineWidth = 5; + context.strokeStyle = '#FFFFFF'; + context.strokeRect(0, 0, 32, 32); + } + core.statusBar.image.name.src = canvas.toDataURL("image/png"); + +} + ////// 屏幕分辨率改变后重新自适应 ////// control.prototype.resize = function(clientWidth, clientHeight) { if (main.mode=='editor')return; @@ -2685,8 +2714,9 @@ control.prototype.resize = function(clientWidth, clientHeight) { if (!core.flags.enableExperience) count--; if (!core.flags.enableLevelUp) count--; if (!core.flags.enableDebuff) count--; - if (core.isset(core.flags.enableKeys) && !core.flags.enableKeys) count--; + if (!core.flags.enableKeys) count--; if (!core.flags.enablePZF) count--; + if (!core.flags.enableName) count--; var statusLineHeight = BASE_LINEHEIGHT * 9 / count; var statusLineFontSize = DEFAULT_FONT_SIZE; @@ -2940,6 +2970,12 @@ control.prototype.resize = function(clientWidth, clientHeight) { display: core.flags.enableFloor ? 'block': 'none' } }, + { + id: 'nameCol', + rules: { + display: core.flags.enableName ? 'block': 'none' + } + }, { id: 'lvCol', rules: { diff --git a/libs/core.js b/libs/core.js index 9033a221..b155f6e5 100644 --- a/libs/core.js +++ b/libs/core.js @@ -292,8 +292,7 @@ core.prototype.init = function (coreData, callback) { 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.clickMoveDirectly = core.getLocalStorage('clickMoveDirectly', - !(core.isset(core.flags.clickMoveDirectly) && !core.flags.clickMoveDirectly)); + core.flags.clickMoveDirectly = core.getLocalStorage('clickMoveDirectly', core.flags.clickMoveDirectly); core.material.ground = new Image(); core.material.ground.src = "project/images/ground.png"; @@ -304,6 +303,9 @@ core.prototype.init = function (coreData, callback) { console.log(core.material); // 设置勇士高度 core.material.icons.hero.height = core.material.images.hero.height/4; + // 行走图 + core.control.updateHeroIcon(); + core.initStatus.maps = core.maps.initMaps(core.floorIds); core.setRequestAnimationFrame(); core.showStartAnimate(); diff --git a/libs/events.js b/libs/events.js index 7c043b97..39950751 100644 --- a/libs/events.js +++ b/libs/events.js @@ -1568,12 +1568,15 @@ events.prototype.canUseQuickShop = function(shopId) { } ////// 设置角色行走图 ////// -events.prototype.setHeroIcon = function (name) { +events.prototype.setHeroIcon = function (name, noDraw) { if (core.isset(core.material.images.images[name]) && core.material.images.images[name].width==128) { core.setFlag("heroIcon", name); + core.material.images.hero.onload = function () { + core.material.icons.hero.height = core.material.images.images[name].height/4; + core.control.updateHeroIcon(name); + if (!noDraw) core.drawHero(); + } core.material.images.hero.src = core.material.images.images[name].src; - core.material.icons.hero.height = core.material.images.images[name].height/4; - core.drawHero(); } } diff --git a/main.js b/main.js index f966596c..54442633 100644 --- a/main.js +++ b/main.js @@ -51,6 +51,7 @@ function main() { 'data': document.getElementById('data'), 'statusLabels': document.getElementsByClassName('statusLabel'), 'floorCol': document.getElementById('floorCol'), + 'nameCol': document.getElementById('nameCol'), 'lvCol': document.getElementById('lvCol'), 'hpmaxCol': document.getElementById('hpmaxCol'), 'mdefCol': document.getElementById('mdefCol'), @@ -76,6 +77,7 @@ function main() { this.statusBar = { 'image': { 'floor': document.getElementById('img-floor'), + 'name': document.getElementById('img-name'), 'lv': document.getElementById('img-lv'), 'hpmax': document.getElementById('img-hpmax'), 'hp': document.getElementById("img-hp"), @@ -95,6 +97,7 @@ function main() { }, 'icons': { 'floor': 0, + 'name': null, 'lv': 1, 'hpmax': 2, 'hp': 3, @@ -120,6 +123,7 @@ function main() { 'equipbox': 23, }, 'floor': document.getElementById('floor'), + 'name': document.getElementById('name'), 'lv': document.getElementById('lv'), 'hpmax': document.getElementById('hpmax'), 'hp': document.getElementById('hp'), diff --git a/project/data.js b/project/data.js index d708e48a..e035a504 100644 --- a/project/data.js +++ b/project/data.js @@ -187,6 +187,7 @@ data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = }, "flags": { "enableFloor": true, + "enableName": false, "enableLv": false, "enableHPMax": false, "enableMDef": true, diff --git a/project/functions.js b/project/functions.js index f128df95..8c35d32a 100644 --- a/project/functions.js +++ b/project/functions.js @@ -590,7 +590,10 @@ functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = core.setStatus('hp', Math.min(core.getStatus('hpmax'), core.getStatus('hp'))); } - // 设置等级奴名称 + // 设置勇士名字和图标 + core.statusBar.name.innerHTML = core.getStatus('name'); + + // 设置等级名称 var lvName = core.getLvName(); core.statusBar.lv.innerHTML = lvName; // 检测是不是纯数字;如果带中文等需要取消斜体(不然很难看的!) diff --git a/styles.css b/styles.css index 6b45773f..19d1048e 100644 --- a/styles.css +++ b/styles.css @@ -227,6 +227,10 @@ span#poison, span#weak, span#curse, span#pickaxe, span#bomb, span#fly { font-size: 1em; } +p#name { + font-style: normal; +} + .gameCanvas { position: absolute; box-sizing: border-box;