最近使用/最常使用图块

This commit is contained in:
ckcz123 2020-05-17 17:53:52 +08:00
parent a62e0119fd
commit b2de5a8a62
5 changed files with 44 additions and 7 deletions

View File

@ -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 "<b>" + text + "</b>";
else return `<a href="javascript:editor.setLastUsedType('${type}')">${text}</a>`;
}
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"];

View File

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

View File

@ -320,7 +320,7 @@
</div>
<div id="mid2" style="display: none">
<p style="margin: 10px">最近使用的图块列表: <button id='clearLastUsedBtn'>清除</button></p>
<p style="margin: 10px"><span id='lastUsedTitle'></span> <button id='clearLastUsedBtn'>清除</button></p>
<div class="map" style="height: 160px; margin-top: 25px" id="lastUsedDiv">
<canvas class='gameCanvas' id='lastUsed' width='416' height='160'></canvas>
</div>

View File

@ -366,7 +366,7 @@
</div>
</div>
<div id="mid2">
<p style="margin: 10px">最近使用的图块列表Ctrl+滚轮放缩) <button id='clearLastUsedBtn'>清除</button></p>
<p style="margin: 10px"><span id='lastUsedTitle'></span>Ctrl+滚轮放缩) <button id='clearLastUsedBtn'>清除</button></p>
<div class="map" id="lastUsedDiv">
<canvas id='lastUsed' width='416' height='416' style="overflow: hidden"></canvas>
</div>

View File

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