// ChineseCheckersDialogs.js — pavilion pop-ups on rice paper in a black // lacquer frame. Each opener returns { close() } and swallows clicks beneath. import { GAME_WIDTH, GAME_HEIGHT } from '../../config.js'; import { Button } from '../../ui/Button.js'; import { DISPLAY_FONT, SERIF } from './ChineseCheckersArt.js'; const INK = '#5a1a12'; export function frame(scene, x, y, w, h, depth) { const g = scene.add.graphics().setDepth(depth); g.fillStyle(0x000000, 0.5).fillRoundedRect(x + 6, y + 10, w, h, 16); g.fillStyle(0x120808, 1).fillRoundedRect(x, y, w, h, 16); g.lineStyle(3, 0xe8c46a, 1).strokeRoundedRect(x + 5, y + 5, w - 10, h - 10, 13); g.fillStyle(0xf4ecd8, 1).fillRoundedRect(x + 14, y + 14, w - 28, h - 28, 10); g.lineStyle(2, 0x8e1c16, 1).strokeRoundedRect(x + 22, y + 22, w - 44, h - 44, 8); // cloud-scroll corners g.lineStyle(2, 0x8e1c16, 0.8); for (const [cx, cy] of [[x + 40, y + 40], [x + w - 40, y + 40], [x + 40, y + h - 40], [x + w - 40, y + h - 40]]) { g.beginPath(); g.arc(cx, cy, 8, 0, Math.PI * 1.6); g.strokePath(); } return g; } export function blocker(scene, depth, alpha = 0) { return scene.add.rectangle(GAME_WIDTH / 2, GAME_HEIGHT / 2, GAME_WIDTH, GAME_HEIGHT, 0x05030a, alpha).setDepth(depth).setInteractive(); } export function handle(objs, onClose) { let closed = false; return { objs, close() { if (closed) return; closed = true; objs.forEach((o) => o?.destroy?.()); onClose?.(); } }; } const onOff = (v) => (v ? 'On' : 'Off'); const PACE = { relaxed: 'Relaxed', normal: 'Normal', fast: 'Fast' }; export function openPauseMenu(scene, { settings, depth, sixPlayers, onChange, onRules, onNewGame, onLeave, onClose }) { const objs = [blocker(scene, depth - 1, 0.55)]; const w = 600, h = 760; const x = GAME_WIDTH / 2 - w / 2, y = GAME_HEIGHT / 2 - h / 2; objs.push(frame(scene, x, y, w, h, depth)); objs.push(scene.add.text(x + w / 2, y + 62, 'The Pavilion', { fontFamily: DISPLAY_FONT, fontSize: '32px', color: INK }).setOrigin(0.5).setDepth(depth + 1)); const cx = x + w / 2; let hRef = null; const cycle = (k, order) => onChange(k, order[(order.indexOf(settings[k]) + 1) % order.length]); const rows = [ ['Resume', () => hRef.close(), 0x2a4a6a], [() => `Opponent speed: ${PACE[settings.pace]}`, () => cycle('pace', ['relaxed', 'normal', 'fast'])], [() => `Skip opponent animations: ${onOff(settings.skipAI)}`, () => onChange('skipAI', !settings.skipAI)], [() => `Path previews & row gains: ${onOff(settings.hints)}`, () => onChange('hints', !settings.hints)], [() => `Colour-blind symbols on marbles: ${onOff(settings.symbols)}`, () => onChange('symbols', !settings.symbols)], [() => `Wind chimes: ${onOff(settings.chimes)}`, () => onChange('chimes', !settings.chimes)], [() => `House rule — anti-blocking: ${onOff(settings.antiBlock)}`, () => onChange('antiBlock', !settings.antiBlock)], [() => `House rule — partner teams (6 players): ${onOff(settings.teams)}`, () => onChange('teams', !settings.teams)], ['How to Play', () => onRules()], ['New Game', () => { hRef.close(); onNewGame(); }, 0x6a4a1a], ['Leave Table', () => { hRef.close(); onLeave(); }, 0x7a1a14], ]; rows.forEach(([label, fn, bg], i) => { const text = typeof label === 'function' ? label() : label; const btn = new Button(scene, cx, y + 124 + i * 50, text, () => { fn(); if (typeof label === 'function') btn.setLabel(label()); }, { width: 520, height: 42, fontSize: 15, bg: bg ?? 0x3a1a14, }).setDepth(depth + 2); objs.push(btn); }); const note = sixPlayers ? 'House rules apply from the next game.' : 'House rules apply from the next game. Partner teams need all six seats.'; objs.push(scene.add.text(cx, y + h - 50, `${note}\nKeys: click or drag a marble · Z undo · H hint · Esc menu`, { fontFamily: SERIF, fontSize: '13px', fontStyle: 'italic', color: '#4a3a22', align: 'center', wordWrap: { width: w - 80 }, }).setOrigin(0.5).setDepth(depth + 1)); hRef = handle(objs, onClose); return hRef; } export function confirmBox(scene, { heading, text, yes = 'Yes', no = 'Cancel', depth, onYes, onNo }) { const objs = [blocker(scene, depth - 1, 0.55)]; const w = 540, h = 280; const x = GAME_WIDTH / 2 - w / 2, y = GAME_HEIGHT / 2 - h / 2; objs.push(frame(scene, x, y, w, h, depth)); objs.push(scene.add.text(x + w / 2, y + 66, heading, { fontFamily: DISPLAY_FONT, fontSize: '26px', color: INK }).setOrigin(0.5).setDepth(depth + 1)); objs.push(scene.add.text(x + w / 2, y + 134, text, { fontFamily: SERIF, fontSize: '18px', color: '#2a1a10', align: 'center', wordWrap: { width: w - 90 } }).setOrigin(0.5).setDepth(depth + 1)); let hRef = null; objs.push(new Button(scene, x + w / 2 - 118, y + h - 62, yes, () => { hRef.close(); onYes?.(); }, { width: 210, height: 46, fontSize: 18, bg: 0x7a1a14 }).setDepth(depth + 2)); objs.push(new Button(scene, x + w / 2 + 118, y + h - 62, no, () => { hRef.close(); onNo?.(); }, { width: 210, height: 46, fontSize: 18, bg: 0x2a4a6a }).setDepth(depth + 2)); hRef = handle(objs); return hRef; } export function toast(scene, text, { depth, x = GAME_WIDTH / 2, y = 1030, ms = 2200 } = {}) { const t = scene.add.text(x, y, text, { fontFamily: SERIF, fontSize: '20px', color: '#2a1a10', backgroundColor: '#f4ecd8', padding: { x: 18, y: 10 } }) .setOrigin(0.5).setDepth(depth).setAlpha(0); scene.tweens.add({ targets: t, alpha: 1, duration: 200 }); scene.tweens.add({ targets: t, alpha: 0, delay: ms, duration: 400, onComplete: () => t.destroy() }); return t; }