From ec60742c5d011d2baaf0199e8ce384b257a055e6 Mon Sep 17 00:00:00 2001 From: tocque Date: Fri, 15 May 2020 16:53:24 +0800 Subject: [PATCH] fix heroIcon & add fold for table gap --- _server/editor_table.js | 62 ++++++++++++++++++++++++- _server/table/data.comment.js | 14 +++++- libs/events.js | 7 ++- libs/maps.js | 2 +- libs/ui.js | 4 +- main.js | 2 +- project/data.js | 4 +- project/functions.js | 4 +- project/{materials => images}/hero.png | Bin 9 files changed, 86 insertions(+), 13 deletions(-) rename project/{materials => images}/hero.png (100%) diff --git a/_server/editor_table.js b/_server/editor_table.js index c9d0ce31..98e93689 100644 --- a/_server/editor_table.js +++ b/_server/editor_table.js @@ -57,11 +57,21 @@ editor_table_wrapper = function (editor) { } editor_table.prototype.gap = function (field) { - return /* html */`--------${field}----\n` + var tokenlist = field.slice(2, -2).split("']['"); + var rule = tokenlist.join("-"); + tokenlist.pop(); + var self = tokenlist.join("-"); + var status = tokenPool.check(rule); + return /* html */` + ---- + ---- + ${field} + + \n` } editor_table.prototype.tr = function (guid, field, shortField, commentHTMLescape, cobjstr, shortComment, tdstr, type) { - return /* html */` + return /* html */` ${shortField} ${shortComment || commentHTMLescape}
${tdstr}
@@ -349,6 +359,54 @@ editor_table_wrapper = function (editor) { } } + tokenPool = new class { + + constructor() { + this.pool = new Set(); + this.style = document.createElement("style"); + document.body.appendChild(this.style); + } + + add(token) { + this.pool.add(token); + this.render(); + } + + remove(token) { + this.pool.delete(token); + this.render(); + } + + render() { + var content = ""; + this.pool.forEach((k) => { + content += /* CSS */`[data-field|=${k}]{ display: none }`; + }) + this.style.innerHTML = content; + } + + check(token) { + return this.pool.has(token); + } + } + + /** + * 当"折叠"被按下时 + */ + editor_table.prototype.onFoldBtnClick = function (button) { + var tr = button.parentNode.parentNode; + if (button.dataset.fold == "true") { + tokenPool.remove(tr.dataset.gap); + button.dataset.fold = "false"; + button.innerText = "折叠"; + } else { + var style = document.createElement("style"); + tokenPool.add(tr.dataset.gap); + button.dataset.fold = "true"; + button.innerText = "展开"; + } + } + /** * 当"显示完整注释"被按下时 */ diff --git a/_server/table/data.comment.js b/_server/table/data.comment.js index d92b6349..394abeb8 100644 --- a/_server/table/data.comment.js +++ b/_server/table/data.comment.js @@ -134,8 +134,10 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { }, "startBgm": { "_leaf": true, - "_type": "textarea", - "_string": true, + "_type": "select", + "_select": { + "values": [null].concat(Object.keys(editor.core.material.bgms)) + }, "_docs": "标题音乐", "_data": "在标题界面应该播放的bgm内容" }, @@ -242,6 +244,14 @@ var data_comment_c456ea59_6018_45ef_8bcc_211a24c627dc = { "hero": { "_type": "object", "_data": { + "image": { + "_leaf": true, + "_type": "select", + "_select": { + "values": [null].concat(Object.keys(editor.core.material.images)) + }, + "_data": "勇士行走图" + }, "name": { "_leaf": true, "_type": "textarea", diff --git a/libs/events.js b/libs/events.js index ea1a1316..7d0e8235 100644 --- a/libs/events.js +++ b/libs/events.js @@ -2851,8 +2851,11 @@ events.prototype._jumpHero_finished = function (animate, ex, ey, callback) { events.prototype.setHeroIcon = function (name, noDraw) { name = core.getMappedName(name); var img = core.material.images.images[name]; - if (!img) return; - core.setFlag("heroIcon", name); + if (!img) { + console.error("找不到图片: "+img); + return; + } + core.status.hero.image = name; core.material.images.hero = img; core.material.icons.hero.width = img.width / 4; core.material.icons.hero.height = img.height / 4; diff --git a/libs/maps.js b/libs/maps.js index 72debb41..ae76cecb 100644 --- a/libs/maps.js +++ b/libs/maps.js @@ -1238,7 +1238,7 @@ maps.prototype._drawThumbnail_realDrawTempCanvas = function (floorId, blocks, op this.drawEvents(floorId, blocks, tempCanvas); // 缩略图:勇士 if (options.heroLoc) { - options.heroIcon = options.heroIcon || core.getFlag("heroIcon", "hero.png"); + options.heroIcon = options.heroIcon || core.status.hero.image; options.heroIcon = core.getMappedName(options.heroIcon); var icon = core.material.icons.hero[options.heroLoc.direction]; var height = core.material.images.images[options.heroIcon].height / 4; diff --git a/libs/ui.js b/libs/ui.js index 8050ec13..94a0a1e1 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -2057,7 +2057,7 @@ ui.prototype.drawCenterFly = function () { var fillstyle = 'rgba(255,0,0,0.5)'; if (core.canUseItem('centerFly')) fillstyle = 'rgba(0,255,0,0.5)'; var toX = core.bigmap.width - 1 - core.getHeroLoc('x'), toY = core.bigmap.height - 1 - core.getHeroLoc('y'); - core.drawThumbnail(null, null, {heroLoc: core.status.hero.loc, heroIcon: core.getFlag('heroIcon', "hero.png")}, + core.drawThumbnail(null, null, {heroLoc: core.status.hero.loc, heroIcon: core.status.hero.image}, {ctx: 'ui', centerX: toX, centerY: toY}); var offsetX = core.clamp(toX - core.__HALF_SIZE__, 0, core.bigmap.width - core.__SIZE__), offsetY = core.clamp(toY - core.__HALF_SIZE__, 0, core.bigmap.height - core.__SIZE__); @@ -2542,7 +2542,7 @@ ui.prototype._drawSLPanel_drawRecord = function(title, data, x, y, size, cho, hi core.strokeRect('ui', x-size/2, y+15, size, size, cho?strokeColor:'#FFFFFF', cho?6:2); if (data && data.floorId) { core.drawThumbnail(data.floorId, core.maps.loadMap(data.maps, data.floorId).blocks, { - heroLoc: data.hero.loc, heroIcon: data.hero.flags.heroIcon, flags: data.hero.flags + heroLoc: data.hero.loc, heroIcon: data.hero.image, flags: data.hero.flags }, { ctx: 'ui', x: x-size/2, y: y+15, size: size, centerX: data.hero.loc.x, centerY: data.hero.loc.y }); diff --git a/main.js b/main.js index e6206b82..89864d06 100644 --- a/main.js +++ b/main.js @@ -85,7 +85,7 @@ function main() { 'data', 'enemys', 'icons', 'maps', 'items', 'functions', 'events', 'plugins' ]; this.materials = [ - 'animates', 'enemys', 'hero', 'items', 'npcs', 'terrains', 'enemy48', 'npc48' + 'animates', 'enemys', 'items', 'npcs', 'terrains', 'enemy48', 'npc48' ]; this.statusBar = { diff --git a/project/data.js b/project/data.js index 2c6ff1de..3eb22a7b 100644 --- a/project/data.js +++ b/project/data.js @@ -10,7 +10,8 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = ], "images": [ "bg.jpg", - "winskin.png" + "winskin.png", + "hero.png" ], "tilesets": [ "magictower.png" @@ -81,6 +82,7 @@ var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = "version": "Ver 2.6.6", "floorId": "sample0", "hero": { + "image": "hero.png", "name": "阳光", "lv": 1, "hpmax": 9999, diff --git a/project/functions.js b/project/functions.js index cf38a8c7..42316aff 100644 --- a/project/functions.js +++ b/project/functions.js @@ -16,7 +16,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 初始化人物,图标,统计信息 core.status.hero = core.clone(hero); window.flags = core.status.hero.flags; - core.events.setHeroIcon(core.getFlag('heroIcon', 'hero.png'), true); + core.events.setHeroIcon(core.status.hero.image, true); core.control._initStatistics(core.animateFrame.totalTime); core.status.hero.statistics.totalTime = core.animateFrame.totalTime = Math.max(core.status.hero.statistics.totalTime, core.animateFrame.totalTime); @@ -945,7 +945,7 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = // 重置音量 core.events.setVolume(core.getFlag("__volume__", 1), 0); // 加载勇士图标 - var icon = core.getFlag("heroIcon", "hero.png"); + var icon = core.status.hero.image; icon = core.getMappedName(icon); if (core.material.images.images[icon]) { core.material.images.hero = core.material.images.images[icon]; diff --git a/project/materials/hero.png b/project/images/hero.png similarity index 100% rename from project/materials/hero.png rename to project/images/hero.png