chore: adjust player tank's size
This commit is contained in:
+138
-13
@@ -49,32 +49,90 @@ const SettingsScene = {
|
||||
ctx.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
|
||||
const cx = SCREEN_WIDTH / 2;
|
||||
let y = 60;
|
||||
|
||||
// Reset button map each frame so layout changes don't keep stale rects.
|
||||
this._buttons = {};
|
||||
|
||||
// Title
|
||||
const titleY = Math.max(48, SCREEN_HEIGHT * 0.08);
|
||||
ctx.fillStyle = COLORS.MENU_TITLE;
|
||||
ctx.font = 'bold 28px Arial';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.fillText(t('settings.title'), cx, y);
|
||||
ctx.fillText(t('settings.title'), cx, titleY);
|
||||
|
||||
y += 70;
|
||||
// Back button (reserved at bottom so we can layout rows above it).
|
||||
const backH = 42;
|
||||
const backMarginBottom = 28;
|
||||
const backCenterY = SCREEN_HEIGHT - backMarginBottom - backH / 2;
|
||||
|
||||
// Toggle items
|
||||
const toggles = [
|
||||
{ key: 'soundEnabled', label: t('settings.sound'), icon: '🔊' },
|
||||
{ key: 'musicEnabled', label: t('settings.music'), icon: '🎵' },
|
||||
{ key: 'vibrationEnabled', label: t('settings.vibration'), icon: '📳' },
|
||||
// Rows: nickname + 3 toggles. Distribute evenly between title and back btn.
|
||||
const rows = [
|
||||
{ type: 'nickname' },
|
||||
{ type: 'toggle', key: 'soundEnabled', label: t('settings.sound'), icon: '🔊' },
|
||||
{ type: 'toggle', key: 'musicEnabled', label: t('settings.music'), icon: '🎵' },
|
||||
{ type: 'toggle', key: 'vibrationEnabled', label: t('settings.vibration'), icon: '📳' },
|
||||
];
|
||||
const rowH = 50;
|
||||
const topPad = titleY + 36;
|
||||
const bottomPad = backCenterY - backH / 2 - 20;
|
||||
const availH = Math.max(rowH * rows.length, bottomPad - topPad);
|
||||
const step = Math.max(rowH + 8, availH / rows.length);
|
||||
const firstCenterY = topPad + step / 2;
|
||||
|
||||
for (const toggle of toggles) {
|
||||
this._renderToggle(ctx, cx, y, toggle);
|
||||
y += 70;
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const row = rows[i];
|
||||
const cy = firstCenterY + i * step;
|
||||
if (row.type === 'nickname') {
|
||||
this._renderNicknameRow(ctx, cx, cy);
|
||||
} else {
|
||||
this._renderToggle(ctx, cx, cy, row);
|
||||
}
|
||||
}
|
||||
|
||||
// Back button
|
||||
y = SCREEN_HEIGHT - 80;
|
||||
this._renderBackButton(ctx, cx, y);
|
||||
this._renderBackButton(ctx, cx, backCenterY);
|
||||
},
|
||||
|
||||
_renderNicknameRow(ctx, cx, y) {
|
||||
const w = SCREEN_WIDTH * 0.7;
|
||||
const h = 50;
|
||||
const x = cx - w / 2;
|
||||
|
||||
this._buttons['nickname'] = { x, y: y - h / 2, w, h };
|
||||
|
||||
// Background
|
||||
ctx.fillStyle = '#1e1e3a';
|
||||
ctx.fillRect(x, y - h / 2, w, h);
|
||||
ctx.strokeStyle = '#333366';
|
||||
ctx.lineWidth = 1;
|
||||
ctx.strokeRect(x, y - h / 2, w, h);
|
||||
|
||||
// Icon + label (left)
|
||||
ctx.fillStyle = COLORS.HUD_TEXT;
|
||||
ctx.font = '16px Arial';
|
||||
ctx.textAlign = 'left';
|
||||
ctx.textBaseline = 'middle';
|
||||
const leftLabel = `👤 ${t('settings.nickname') || '显示名字'}`;
|
||||
ctx.fillText(leftLabel, x + 15, y);
|
||||
|
||||
// Current value + chevron (right)
|
||||
const profile = GameGlobal.playerProfile;
|
||||
let shown = '';
|
||||
if (profile) {
|
||||
if (profile.granted && profile.nickname) {
|
||||
shown = profile.truncate ? profile.truncate(profile.nickname, 5) : profile.nickname;
|
||||
} else if (typeof profile.getDisplayName === 'function') {
|
||||
const pid = (GameGlobal.networkManager && GameGlobal.networkManager.playerId) || '';
|
||||
shown = profile.getDisplayName(pid);
|
||||
}
|
||||
}
|
||||
if (!shown) shown = 'Tanker';
|
||||
|
||||
ctx.fillStyle = profile && profile.granted ? '#FFD700' : '#8899AA';
|
||||
ctx.font = '13px Arial';
|
||||
ctx.textAlign = 'right';
|
||||
ctx.fillText(`${shown} ›`, x + w - 15, y);
|
||||
},
|
||||
|
||||
_renderToggle(ctx, cx, y, toggle) {
|
||||
@@ -153,6 +211,10 @@ const SettingsScene = {
|
||||
if (tx >= rect.x && tx <= rect.x + rect.w && ty >= rect.y && ty <= rect.y + rect.h) {
|
||||
if (key === 'back') {
|
||||
GameGlobal.sceneManager.switchTo(SCENE.MENU);
|
||||
} else if (key === 'nickname') {
|
||||
// IMPORTANT: wx.getUserProfile must be called synchronously from a
|
||||
// user tap handler; invoking it here is fine (touchstart is a tap).
|
||||
this._requestNicknameAuth();
|
||||
} else if (this._settings.hasOwnProperty(key)) {
|
||||
this._settings[key] = !this._settings[key];
|
||||
// Notify audio system
|
||||
@@ -162,6 +224,69 @@ const SettingsScene = {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// ============================================================
|
||||
// Nickname acquisition (moved from MenuScene)
|
||||
// ============================================================
|
||||
_requestNicknameAuth() {
|
||||
const profile = GameGlobal.playerProfile;
|
||||
if (!profile) return;
|
||||
|
||||
const onDone = (ok) => {
|
||||
if (ok) {
|
||||
try {
|
||||
wx.showToast({
|
||||
title: `欢迎 ${profile.nickname}`,
|
||||
icon: 'none',
|
||||
duration: 1500,
|
||||
});
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof profile.requestUserProfile === 'function') {
|
||||
profile.requestUserProfile().then((ok) => {
|
||||
if (ok) {
|
||||
onDone(true);
|
||||
} else {
|
||||
this._promptManualNickname(onDone);
|
||||
}
|
||||
}).catch(() => this._promptManualNickname(onDone));
|
||||
} else {
|
||||
this._promptManualNickname(onDone);
|
||||
}
|
||||
},
|
||||
|
||||
_promptManualNickname(cb) {
|
||||
try {
|
||||
if (typeof wx === 'undefined' || typeof wx.showModal !== 'function') {
|
||||
cb && cb(false);
|
||||
return;
|
||||
}
|
||||
wx.showModal({
|
||||
title: '设置昵称',
|
||||
content: '输入在对战中显示的名字(最长16字)',
|
||||
editable: true,
|
||||
placeholderText: '例如:坏蹄子',
|
||||
confirmText: '确定',
|
||||
cancelText: '取消',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
const profile = GameGlobal.playerProfile;
|
||||
const ok = profile && typeof profile.setManualNickname === 'function'
|
||||
&& profile.setManualNickname(res.content || '');
|
||||
cb && cb(!!ok);
|
||||
} else {
|
||||
cb && cb(false);
|
||||
}
|
||||
},
|
||||
fail: () => cb && cb(false),
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn('[Settings] showModal failed:', e && e.message);
|
||||
cb && cb(false);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = SettingsScene;
|
||||
|
||||
Reference in New Issue
Block a user