// SplendorDialogs.js — the counting house's pop-ups: a parchment card in a // walnut frame. Each opener returns { close() } and swallows clicks beneath. // // openPauseMenu resume · pace · hints · rivals' reach · undo · ambience · rules · new game · leave // confirmBox yes / no // openReturn choose the tokens to hand back over the 10-gem limit // openNobleChoice several patrons qualify — pick one import { GAME_WIDTH, GAME_HEIGHT } from '../../config.js'; import { Button } from '../../ui/Button.js'; import { GEMS, GOLD, GEM_NAME, HAND_LIMIT, nobleInfo } from './SplendorData.js'; import { tokenTotal } from './SplendorLogic.js'; import { SERIF, DISPLAY, INK, chipKey, nobleKey } from './SplendorArt.js'; export function frame(scene, x, y, w, h, depth) { const g = scene.add.graphics().setDepth(depth); g.fillStyle(0x000000, 0.5).fillRoundedRect(x + 4, y + 8, w, h, 14); g.fillStyle(0x4a2a14, 1).fillRoundedRect(x, y, w, h, 14); g.lineStyle(2, 0xd9b45a, 0.9).strokeRoundedRect(x + 4, y + 4, w - 8, h - 8, 11); g.fillStyle(0xf0e2c0, 1).fillRoundedRect(x + 10, y + 10, w - 20, h - 20, 8); g.lineStyle(1.5, 0x8a6420, 0.8).strokeRoundedRect(x + 16, y + 16, w - 32, h - 32, 6); return g; } export function blocker(scene, depth, alpha = 0) { return scene.add.rectangle(GAME_WIDTH / 2, GAME_HEIGHT / 2, GAME_WIDTH, GAME_HEIGHT, 0x000000, alpha) .setDepth(depth).setInteractive(); } export function title(scene, x, y, text, depth, size = 26) { return scene.add.text(x, y, text, { fontFamily: DISPLAY, fontSize: `${size}px`, color: '#4a2008', align: 'center' }) .setOrigin(0.5).setDepth(depth); } 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'); export const PACE_LABEL = { relaxed: 'Relaxed', normal: 'Normal', fast: 'Brisk' }; // ── pause / settings ────────────────────────────────────────────────────────────────── export function openPauseMenu(scene, { settings, depth, onChange, onRules, onNewGame, onLeave, onClose }) { const objs = [blocker(scene, depth - 1, 0.5)]; const w = 520, h = 660; const x = GAME_WIDTH / 2 - w / 2, y = GAME_HEIGHT / 2 - h / 2; objs.push(frame(scene, x, y, w, h, depth)); objs.push(title(scene, x + w / 2, y + 50, 'The Counting House', depth + 1, 28)); const cx = x + w / 2; let hRef = null; const rows = [ ['Resume', () => hRef.close(), 0x2a4a30], [() => `Pace: ${PACE_LABEL[settings.pace]}`, () => { const order = ['relaxed', 'normal', 'fast']; onChange('pace', order[(order.indexOf(settings.pace) + 1) % order.length]); }], [() => `Buying hints: ${onOff(settings.hints)}`, () => onChange('hints', !settings.hints)], [() => `Rivals' reach markers: ${onOff(settings.reach)}`, () => onChange('reach', !settings.reach)], [() => `Undo last move: ${onOff(settings.undo)}`, () => onChange('undo', !settings.undo)], [() => `Lamp & dust ambience: ${onOff(settings.ambient)}`, () => onChange('ambient', !settings.ambient)], ['How to Play', () => onRules()], ['New Game', () => { hRef.close(); onNewGame(); }, 0x6a4a1a], ['Leave Table', () => { hRef.close(); onLeave(); }, 0x7a2a1a], ]; rows.forEach(([label, fn, bg], i) => { const text = typeof label === 'function' ? label() : label; const btn = new Button(scene, cx, y + 110 + i * 54, text, () => { fn(); if (typeof label === 'function') btn.setLabel(label()); }, { width: 420, height: 44, fontSize: 17, bg: bg ?? 0x5a3820 }).setDepth(depth + 2); objs.push(btn); }); objs.push(scene.add.text(cx, y + h - 34, 'Pace: Relaxed plays every showcase in full; Normal shortens rivals\'; Brisk skips them.\nKeys: 1–5 gems · Enter take · Esc clear · Z undo · M menu', { fontFamily: SERIF, fontSize: '12px', fontStyle: 'italic', color: '#5a4428', align: 'center', wordWrap: { width: w - 60 }, }).setOrigin(0.5).setDepth(depth + 1)); hRef = handle(objs, onClose); return hRef; } // ── confirm ───────────────────────────────────────────────────────────────────────────── export function confirmBox(scene, { heading, text, yes = 'Yes', no = 'Cancel', depth, onYes, onNo }) { const objs = [blocker(scene, depth - 1, 0.5)]; const w = 520, h = 250; const x = GAME_WIDTH / 2 - w / 2, y = GAME_HEIGHT / 2 - h / 2; objs.push(frame(scene, x, y, w, h, depth)); objs.push(title(scene, x + w / 2, y + 48, heading, depth + 1, 24)); objs.push(scene.add.text(x + w / 2, y + 108, text, { fontFamily: SERIF, fontSize: '16px', color: INK, align: 'center', wordWrap: { width: w - 70 }, }).setOrigin(0.5).setDepth(depth + 1)); let hRef = null; objs.push(new Button(scene, x + w / 2 - 116, y + h - 52, yes, () => { hRef.close(); onYes?.(); }, { width: 200, height: 46, fontSize: 18, bg: 0x2a4a30 }).setDepth(depth + 2)); objs.push(new Button(scene, x + w / 2 + 116, y + h - 52, no, () => { hRef.close(); onNo?.(); }, { width: 200, height: 46, fontSize: 18, bg: 0x5a3820 }).setDepth(depth + 2)); objs[0].on('pointerdown', () => { hRef.close(); onNo?.(); }); hRef = handle(objs); return hRef; } // ── hand back tokens ───────────────────────────────────────────────────────────────────── // Starts from `suggested` (a colour → n map); click a chip in "Keep" to move it // to "Return" and back. Confirm once exactly the excess is chosen. export function openReturn(scene, { player, suggested = {}, depth, onDone }) { const objs = [blocker(scene, depth - 1, 0.55)]; const excess = tokenTotal(player) - HAND_LIMIT; const w = 760, h = 420; const x = GAME_WIDTH / 2 - w / 2, y = GAME_HEIGHT / 2 - h / 2; objs.push(frame(scene, x, y, w, h, depth)); objs.push(title(scene, x + w / 2, y + 46, 'Too Many Gems', depth + 1, 26)); const sub = scene.add.text(x + w / 2, y + 84, '', { fontFamily: SERIF, fontSize: '16px', color: INK, align: 'center' }).setOrigin(0.5).setDepth(depth + 1); objs.push(sub); const order = [...GEMS, GOLD]; const ret = {}; for (const c of order) ret[c] = Math.min(player.tokens[c] ?? 0, suggested[c] ?? 0); let dyn = []; let confirmBtn = null; const chosen = () => order.reduce((n, c) => n + ret[c], 0); const draw = () => { dyn.forEach((o) => o.destroy()); dyn = []; const left = excess - chosen(); sub.setText(left > 0 ? `You may hold ${HAND_LIMIT}. Choose ${left} more to return to the case.` : left < 0 ? `That is ${-left} too many — keep some back.` : 'Ready — these go back to the jewel case.'); order.forEach((c, i) => { const cx = x + 90 + i * 116; const keep = (player.tokens[c] ?? 0) - ret[c]; dyn.push(scene.add.text(cx, y + 124, GEM_NAME[c], { fontFamily: SERIF, fontSize: '13px', fontStyle: 'bold', color: '#4a2008' }).setOrigin(0.5).setDepth(depth + 1)); const mk = (yy, n, label, fn) => { const img = scene.add.image(cx, yy, chipKey(c)).setDisplaySize(58, 58).setDepth(depth + 1).setAlpha(n > 0 ? 1 : 0.2); dyn.push(img); dyn.push(scene.add.text(cx + 34, yy, `×${n}`, { fontFamily: SERIF, fontSize: '17px', fontStyle: 'bold', color: INK }).setOrigin(0, 0.5).setDepth(depth + 1)); if (n > 0) { img.setInteractive({ useHandCursor: true }); img.on('pointerdown', fn); } void label; }; mk(y + 172, keep, 'keep', () => { ret[c]++; draw(); }); mk(y + 270, ret[c], 'return', () => { ret[c]--; draw(); }); }); dyn.push(scene.add.text(x + 30, y + 172, 'Keep', { fontFamily: DISPLAY, fontSize: '15px', color: '#4a2008' }).setOrigin(0, 0.5).setAngle(-90).setDepth(depth + 1)); dyn.push(scene.add.text(x + 30, y + 270, 'Return', { fontFamily: DISPLAY, fontSize: '15px', color: '#8a1a10' }).setOrigin(0, 0.5).setAngle(-90).setDepth(depth + 1)); confirmBtn?.setEnabled?.(left === 0); confirmBtn?.setAlpha(left === 0 ? 1 : 0.5); }; const g = scene.add.graphics().setDepth(depth); g.lineStyle(1, 0x8a6420, 0.5).lineBetween(x + 50, y + 221, x + w - 50, y + 221); objs.push(g); let hRef = null; confirmBtn = new Button(scene, x + w / 2, y + h - 48, 'Return to the case', () => { if (chosen() !== excess) return; const map = {}; for (const c of order) if (ret[c]) map[c] = ret[c]; hRef.close(); onDone(map); }, { width: 260, height: 46, fontSize: 18, bg: 0x2a4a30 }).setDepth(depth + 2); objs.push(confirmBtn); draw(); hRef = handle(objs, () => dyn.forEach((o) => o.destroy())); return hRef; } // ── several patrons ────────────────────────────────────────────────────────────────────── export function openNobleChoice(scene, { nobles, depth, onPick }) { const objs = [blocker(scene, depth - 1, 0.55)]; const w = 200 + nobles.length * 190, h = 400; const x = GAME_WIDTH / 2 - w / 2, y = GAME_HEIGHT / 2 - h / 2; objs.push(frame(scene, x, y, w, h, depth)); objs.push(title(scene, x + w / 2, y + 46, 'Patrons Seek You Out', depth + 1, 26)); objs.push(scene.add.text(x + w / 2, y + 82, 'Only one may visit this turn. Choose your patron.', { fontFamily: SERIF, fontSize: '15px', fontStyle: 'italic', color: INK, }).setOrigin(0.5).setDepth(depth + 1)); let hRef = null; nobles.forEach((n, i) => { const cx = x + w / 2 + (i - (nobles.length - 1) / 2) * 190; const img = scene.add.image(cx, y + 210, nobleKey(n)).setDisplaySize(140, 175).setDepth(depth + 1).setInteractive({ useHandCursor: true }); img.on('pointerover', () => img.setDisplaySize(150, 187)); img.on('pointerout', () => img.setDisplaySize(140, 175)); img.on('pointerdown', () => { hRef.close(); onPick(n.id); }); objs.push(img); const info = nobleInfo(n); objs.push(scene.add.text(cx, y + 318, info.name, { fontFamily: DISPLAY, fontSize: '16px', color: '#4a2008' }).setOrigin(0.5).setDepth(depth + 1)); objs.push(scene.add.text(cx, y + 340, info.title, { fontFamily: SERIF, fontSize: '12px', fontStyle: 'italic', color: '#5a4428', align: 'center', wordWrap: { width: 170 } }).setOrigin(0.5, 0).setDepth(depth + 1)); }); hRef = handle(objs); return hRef; }