置顶常用图块

This commit is contained in:
ckcz123 2020-05-17 19:27:37 +08:00
parent b2de5a8a62
commit 7d9653f6e6
4 changed files with 24 additions and 6 deletions

View File

@ -423,6 +423,7 @@ editor.prototype.setLastUsedType = function (type) {
editor.prototype.updateLastUsedMap = function () { editor.prototype.updateLastUsedMap = function () {
var lastUsed = editor.uivalues.lastUsed.sort(function (a, b) { var lastUsed = editor.uivalues.lastUsed.sort(function (a, b) {
if ((a.istop || 0) != (b.istop || 0)) return (b.istop || 0) - (a.istop || 0);
return (b[editor.uivalues.lastUsedType] || 0) - (a[editor.uivalues.lastUsedType] || 0); return (b[editor.uivalues.lastUsedType] || 0) - (a[editor.uivalues.lastUsedType] || 0);
}); });
@ -430,6 +431,7 @@ editor.prototype.updateLastUsedMap = function () {
var ctx = editor.dom.lastUsedCtx; var ctx = editor.dom.lastUsedCtx;
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
ctx.strokeStyle = 'rgba(255,128,0,0.85)'; ctx.strokeStyle = 'rgba(255,128,0,0.85)';
ctx.fillStyle = 'rgba(255,0,0,0.85)';
ctx.lineWidth = 4; ctx.lineWidth = 4;
for (var i = 0; i < lastUsed.length; ++i) { for (var i = 0; i < lastUsed.length; ++i) {
try { try {
@ -444,6 +446,9 @@ editor.prototype.updateLastUsedMap = function () {
var per_height = info.images.endsWith('48') ? 48 : 32; var per_height = info.images.endsWith('48') ? 48 : 32;
ctx.drawImage(core.material.images[info.images], 0, info.y * per_height, 32, per_height, x * 32, y * 32, 32, 32); ctx.drawImage(core.material.images[info.images], 0, info.y * per_height, 32, per_height, x * 32, y * 32, 32, 32);
} }
if (info.istop) {
ctx.fillRect(32 * x, 32 * y + 24, 8, 8);
}
if (selectBox.isSelected() && editor.info.id == info.id) { if (selectBox.isSelected() && editor.info.id == info.id) {
ctx.strokeRect(32 * x + 2, 32 * y + 2, 28, 28); ctx.strokeRect(32 * x + 2, 32 * y + 2, 28, 28);
} }

View File

@ -35,6 +35,7 @@ editor_listen_wrapper = function (editor) {
editor.dom.clearLoc.onmousedown = editor.uifunctions.clearLoc_click editor.dom.clearLoc.onmousedown = editor.uifunctions.clearLoc_click
editor.dom.lastUsed.onmousedown = editor.uifunctions.lastUsed_click; editor.dom.lastUsed.onmousedown = editor.uifunctions.lastUsed_click;
editor.dom.lastUsed.oncontextmenu = function (e) { e.preventDefault(); }
editor.dom.clearLastUsedBtn.onclick = editor.uifunctions.clearLastUsedBtn_click; editor.dom.clearLastUsedBtn.onclick = editor.uifunctions.clearLastUsedBtn_click;
editor.dom.lockMode.onchange = editor.uifunctions.lockMode_onchange; editor.dom.lockMode.onchange = editor.uifunctions.lockMode_onchange;

View File

@ -792,21 +792,33 @@ editor_mappanel_wrapper = function (editor) {
var index = x + core.__SIZE__ * y; var index = x + core.__SIZE__ * y;
if (index >= editor.uivalues.lastUsed.length) return; if (index >= editor.uivalues.lastUsed.length) return;
var lastUsed = editor.uivalues.lastUsed.sort(function (a, b) { var lastUsed = editor.uivalues.lastUsed.sort(function (a, b) {
if ((a.istop || 0) != (b.istop || 0)) return (b.istop || 0) - (a.istop || 0);
return (b[editor.uivalues.lastUsedType] || 0) - (a[editor.uivalues.lastUsedType] || 0); return (b[editor.uivalues.lastUsedType] || 0) - (a[editor.uivalues.lastUsedType] || 0);
}); });
if (e.button == 2) {
lastUsed[index].istop = lastUsed[index].istop ? 0 : 1;
printf("已"+(lastUsed[index].istop ? '置顶' : '取消置顶')+"该图块");
editor.config.set('lastUsed', editor.uivalues.lastUsed);
editor.updateLastUsedMap();
return false;
}
var one = Object.assign({}, lastUsed[index]); var one = Object.assign({}, lastUsed[index]);
delete one['recent']; delete one['recent'];
delete one['frequent']; delete one['frequent'];
delete one['istop'];
editor.setSelectBoxFromInfo(one); editor.setSelectBoxFromInfo(one);
return; return false;
} }
editor.uifunctions.clearLastUsedBtn_click = function () { editor.uifunctions.clearLastUsedBtn_click = function () {
if (editor.isMobile) return; if (editor.isMobile) return;
editor.uivalues.lastUsed = []; if (confirm("你确定要清理全部最近使用图块么?\n所有最近使用和最常使用图块含置顶图块都将被清除此过程不可逆")) {
editor.config.set('lastUsed', []); editor.uivalues.lastUsed = [];
editor.updateLastUsedMap(); editor.config.set('lastUsed', []);
editor.updateLastUsedMap();
}
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

View File

@ -366,7 +366,7 @@
</div> </div>
</div> </div>
<div id="mid2"> <div id="mid2">
<p style="margin: 10px"><span id='lastUsedTitle'></span>Ctrl+滚轮放缩) <button id='clearLastUsedBtn'>清除</button></p> <p style="margin: 10px"><span id='lastUsedTitle'></span><small>Ctrl+滚轮放缩,右键置顶</small> <button id='clearLastUsedBtn'>清除</button></p>
<div class="map" id="lastUsedDiv"> <div class="map" id="lastUsedDiv">
<canvas id='lastUsed' width='416' height='416' style="overflow: hidden"></canvas> <canvas id='lastUsed' width='416' height='416' style="overflow: hidden"></canvas>
</div> </div>