fea: 添加地图管理

This commit is contained in:
cancerai committed 2026-10-22 23:16:27 +08:00
1 parent cc2883458c
commit 22157d4baa
7 files changed
+201 -44

No files matched your search

+43 -3
View File
@@ -14,6 +14,7 @@ const TABS = [
export const UI = {
H: {}, // handlers
filter: 'all',
manage: false, // 自制页「管理」态:开启后每张自制地图显示删除按钮
cur: 'scr-title',
toastTimer: 0,
@@ -37,6 +38,7 @@ export const UI = {
b.textContent = label;
b.onclick = () => {
this.filter = k;
this.setManage(false); // 切换分类时退出管理模式
$$('#level-tabs .tab').forEach(t => t.classList.remove('on'));
b.classList.add('on');
this.renderLevels();
@@ -49,7 +51,7 @@ export const UI = {
SCREENS.forEach(s => $('#' + s).classList.toggle('hidden', s !== name));
this.cur = name;
$('#hud').classList.toggle('hidden', name !== null && name !== '');
if (name === 'scr-levels') this.renderLevels();
if (name === 'scr-levels') { this.setManage(false); this.renderLevels(); }
},
showGame() {
SCREENS.forEach(s => $('#' + s).classList.add('hidden'));
@@ -64,6 +66,9 @@ export const UI = {
const all = [...LEVELS, ...customs];
const list = all.filter(l => this.filter === 'all' ? true : l.type === this.filter);
// 「管理地图」按钮只在自制分类下显示
this.updateManageBtn();
if (!list.length) {
grid.innerHTML = '<div style="color:#666;padding:20px">这个分类下还没有关卡。去「自制关卡」造一个吧。</div>';
return;
@@ -71,7 +76,7 @@ export const UI = {
list.forEach(l => {
const rec = Save.get(l.id);
const card = document.createElement('div');
card.className = 'lv-card' + (rec ? ' cleared' : '');
card.className = 'lv-card' + (rec ? ' cleared' : '') + (this.manage && l.builtin === false ? ' manage' : '');
const stars = '★'.repeat(l.diff || 1) + '☆'.repeat(Math.max(0, 5 - (l.diff || 1)));
card.innerHTML = `
<div class="idx">${l.builtin === false ? 'U' + (l.no || '') : String(l.index + 1).padStart(2, '0')}</div>
@@ -83,11 +88,46 @@ export const UI = {
<div class="st">${rec ? `✔ 死亡 ${rec.deaths} · ${fmtTime(rec.time)}` : '未通关'}</div>
${rec ? '<div class="chk">✔</div>' : ''}
`;
card.onclick = () => this.H.play(l);
// 管理态下自制卡不再可进入,只保留删除按钮,避免误点开始
if (!(this.manage && l.builtin === false)) card.onclick = () => this.H.play(l);
// 管理态:自制地图显示删除按钮
if (l.builtin === false && this.manage) {
const del = document.createElement('button');
del.className = 'lv-del';
del.textContent = '✕';
del.title = '删除这张地图';
del.onclick = (e) => { e.stopPropagation(); this.delCustom(l); };
card.appendChild(del);
}
grid.appendChild(card);
});
},
/** 刷新「管理地图」按钮:仅在自制分类可见;管理态文案变「完成」并高亮 */
updateManageBtn() {
const mb = $('#manage-btn');
if (!mb) return;
mb.classList.toggle('hidden', this.filter !== 'custom');
mb.textContent = this.manage ? '完成' : '管理地图';
mb.classList.toggle('on', this.manage);
},
/** 切换自制页的管理态(显示/隐藏删除按钮) */
setManage(on) {
// 仅自制分类可进入管理态;非自制分类的开启请求按退出处理(按钮不可见,须自动复位)
if (on && this.filter !== 'custom') on = false;
this.manage = !!on;
this.updateManageBtn();
this.renderLevels();
},
/** 删除一张自制地图(从关卡选择界面管理) */
delCustom(l) {
if (typeof confirm === 'function' && !confirm('删除地图「' + (l.name || 'MY MAP') + '」?此操作不可恢复')) return;
Save.removeCustom(l.id);
this.renderLevels();
},
hud({ name, deaths, ms, apples, totalApples, hasGun, save, totalSaves }) {
$('#hud-level').textContent = name || '';
$('#hud-deaths').textContent = 'DEATH ' + deaths;