Name on statusBar

This commit is contained in:
oc 2018-10-11 21:51:41 +08:00
parent 806449381b
commit 3565b2256a
11 changed files with 98 additions and 27 deletions

View File

@ -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",

View File

@ -333,6 +333,10 @@
<img id="img-floor">
<p class='statusLabel' id='floor'></p>
</div>
<div class="status" id="nameCol">
<img id="img-name">
<p class='statusLabel' id='name'></p>
</div>
<div class="status" id="lvCol">
<img id="img-lv">
<p class='statusLabel' id='lv'></p>

View File

@ -319,6 +319,10 @@
<img id="img-floor">
<p class='statusLabel' id='floor'></p>
</div>
<div class="status" id="nameCol">
<img id="img-name">
<p class='statusLabel' id='name'></p>
</div>
<div class="status" id="lvCol">
<img id="img-lv">
<p class='statusLabel' id='lv'></p>

View File

@ -46,6 +46,10 @@
<img id="img-floor">
<p class='statusLabel' id='floor'></p>
</div>
<div class="status" id="nameCol">
<img id="img-name">
<p class='statusLabel' id='name'></p>
</div>
<div class="status" id="lvCol">
<img id="img-lv">
<p class='statusLabel' id='lv'></p>

View File

@ -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,6 +1203,7 @@ control.prototype.checkBlock = function () {
// 检查阻击事件
var snipe = [];
if (!core.hasFlag("no_snipe")) {
var scan = {
'up': {'x': 0, 'y': -1},
'left': {'x': -1, 'y': 0},
@ -1214,6 +1221,7 @@ control.prototype.checkBlock = function () {
}
}
}
}
if (core.status.checkBlock.betweenAttack[x+core.bigmap.width*y] && damage>0) {
core.drawTip('受到夹击,生命变成一半');
@ -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) {
Object.keys(core.statusBar).forEach(function (e) {
if (core.isset(core.statusBar[e].innerHTML))
core.statusBar[e].innerHTML = "&nbsp;";
});
})
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: {

View File

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

View File

@ -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.src = core.material.images.images[name].src;
core.material.images.hero.onload = function () {
core.material.icons.hero.height = core.material.images.images[name].height/4;
core.drawHero();
core.control.updateHeroIcon(name);
if (!noDraw) core.drawHero();
}
core.material.images.hero.src = core.material.images.images[name].src;
}
}

View File

@ -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'),

View File

@ -187,6 +187,7 @@ data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d =
},
"flags": {
"enableFloor": true,
"enableName": false,
"enableLv": false,
"enableHPMax": false,
"enableMDef": true,

View File

@ -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;
// 检测是不是纯数字;如果带中文等需要取消斜体(不然很难看的!)

View File

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