diff --git a/_server/editor.js b/_server/editor.js index 56487191..8704fea1 100644 --- a/_server/editor.js +++ b/_server/editor.js @@ -55,6 +55,7 @@ function editor() { editModeSelect :document.getElementById('editModeSelect'), mid2 : document.getElementById('mid2'), clearLastUsedBtn: document.getElementById('clearLastUsedBtn'), + lastUsedTitle: document.getElementById('lastUsedTitle'), lastUsedDiv: document.getElementById('lastUsedDiv'), lastUsed: document.getElementById('lastUsed'), lastUsedCtx: document.getElementById('lastUsed').getContext('2d'), @@ -105,6 +106,7 @@ function editor() { lockMode: false, // 最近使用的图块 + lastUsedType: null, lastUsed: [], }; @@ -406,16 +408,33 @@ editor.prototype.updateMap = function () { this.updateLastUsedMap(); } +editor.prototype.setLastUsedType = function (type) { + if (type == editor.uivalues.lastUsedType) return; + editor.uivalues.lastUsedType = type; + var _buildHtml = function (type, text) { + if (type == null) return "" + text + ""; + else return `${text}`; + } + editor.dom.lastUsedTitle.innerHTML + = type == 'frequent' ? (_buildHtml('recent', '最近使用') + " | " + _buildHtml(null, '最常使用')) + : (_buildHtml(null, '最近使用') + " | " + _buildHtml('frequent', '最常使用')); + this.updateLastUsedMap(); +} + editor.prototype.updateLastUsedMap = function () { + var lastUsed = editor.uivalues.lastUsed.sort(function (a, b) { + return (b[editor.uivalues.lastUsedType] || 0) - (a[editor.uivalues.lastUsedType] || 0); + }); + // 绘制最近使用事件 var ctx = editor.dom.lastUsedCtx; ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); ctx.strokeStyle = 'rgba(255,128,0,0.85)'; ctx.lineWidth = 4; - for (var i = 0; i < editor.uivalues.lastUsed.length; ++i) { + for (var i = 0; i < lastUsed.length; ++i) { try { var x = i % core.__SIZE__, y = parseInt(i / core.__SIZE__); - var info = editor.uivalues.lastUsed[i]; + var info = lastUsed[i]; if (!info || !info.images) continue; if (info.isTile && core.material.images.tilesets[info.images]) { ctx.drawImage(core.material.images.tilesets[info.images], 32 * info.x, 32 * info.y, 32, 32, x*32, y*32, 32, 32); @@ -458,6 +477,7 @@ editor.prototype.drawInitData = function (icons) { // editor.uivalues.folded = true; editor.uivalues.foldPerCol = editor.config.get('foldPerCol', 50); // var imgNames = Object.keys(images); //还是固定顺序吧; + editor.setLastUsedType(editor.config.get('lastUsedType', 'recent')); editor.uivalues.lastUsed = editor.config.get("lastUsed", []); var imgNames = ["terrains", "animates", "enemys", "enemy48", "items", "npcs", "npc48", "autotile"]; diff --git a/_server/editor_mappanel.js b/_server/editor_mappanel.js index fcfb0fd3..e84a600d 100644 --- a/_server/editor_mappanel.js +++ b/_server/editor_mappanel.js @@ -257,7 +257,17 @@ editor_mappanel_wrapper = function (editor) { } // console.log(editor.map); if (editor.info.y != null) { - editor.uivalues.lastUsed = [editor.info].concat(editor.uivalues.lastUsed.filter(function (e) { return e.id != editor.info.id})); + var found = false; + editor.uivalues.lastUsed.forEach(function (one) { + if (one.id == editor.info.id) { + found = true; + one.recent = new Date().getTime(); + one.frequent = (one.frequent || 0) + 1; + } + }) + if (!found) { + editor.uivalues.lastUsed.push(Object.assign({}, editor.info, {recent: new Date().getTime(), frequent: 1})); + } editor.config.set("lastUsed", editor.uivalues.lastUsed); } editor.updateMap(); @@ -781,7 +791,13 @@ editor_mappanel_wrapper = function (editor) { var x = parseInt(px / 32), y = parseInt(py / 32); var index = x + core.__SIZE__ * y; if (index >= editor.uivalues.lastUsed.length) return; - editor.setSelectBoxFromInfo(editor.uivalues.lastUsed[index]); + var lastUsed = editor.uivalues.lastUsed.sort(function (a, b) { + return (b[editor.uivalues.lastUsedType] || 0) - (a[editor.uivalues.lastUsedType] || 0); + }); + var one = Object.assign({}, lastUsed[index]); + delete one['recent']; + delete one['frequent']; + editor.setSelectBoxFromInfo(one); return; } diff --git a/editor-mobile.html b/editor-mobile.html index 2b9bf8b0..dabddf55 100644 --- a/editor-mobile.html +++ b/editor-mobile.html @@ -320,7 +320,7 @@
-

最近使用的图块列表(Ctrl+滚轮放缩)

+

(Ctrl+滚轮放缩)

diff --git a/v2.x-final更新.txt b/v2.x-final更新.txt index 7cbd5c2f..cc988fc5 100644 --- a/v2.x-final更新.txt +++ b/v2.x-final更新.txt @@ -51,11 +51,12 @@ 地图拉框选择复制剪切删除 (已完成!) 素材替换 大屏幕下放大游戏界面 -最近使用/最常使用的图块 +(已完成!) 最近使用/最常使用的图块 (已完成!) loader并行加载 合并items.js (已完成!) 增加fonts目录,全塔属性增加fonts引用 (已完成!) 右边框输入完后解析按钮高亮 +32x48的门 -------------