142 lines
7.4 KiB
JavaScript
142 lines
7.4 KiB
JavaScript
// AzulDialogs.js — the workshop's pop-ups: a cream plaster card in a walnut
|
||
// frame with a cobalt hairline. Each opener returns { close() } and swallows
|
||
// clicks beneath it.
|
||
//
|
||
// openPauseMenu resume · opponent speed · helpers · wall variant · rules · new game · leave
|
||
// openLog the full order book (wheel scroll)
|
||
// confirmBox yes / no
|
||
|
||
import { GAME_WIDTH, GAME_HEIGHT } from '../../config.js';
|
||
import { Button } from '../../ui/Button.js';
|
||
import { SERIF, DISPLAY, COBALT, INK } from './AzulArt.js';
|
||
|
||
export function frame(scene, x, y, w, h, depth) {
|
||
const g = scene.add.graphics().setDepth(depth);
|
||
g.fillStyle(0x000000, 0.45).fillRoundedRect(x + 4, y + 8, w, h, 14);
|
||
g.fillStyle(0x4a2d16, 1).fillRoundedRect(x, y, w, h, 14);
|
||
g.lineStyle(2, 0xc9a24a, 0.9).strokeRoundedRect(x + 4, y + 4, w - 8, h - 8, 11);
|
||
g.fillStyle(0xf3ead4, 1).fillRoundedRect(x + 10, y + 10, w - 20, h - 20, 8);
|
||
g.lineStyle(2, 0x1d4f8f, 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: COBALT, align: 'center' })
|
||
.setOrigin(0.5).setDepth(depth);
|
||
}
|
||
|
||
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_LABEL = { relaxed: 'Relaxed', normal: 'Normal', fast: 'Fast' };
|
||
|
||
// ── pause / settings ──────────────────────────────────────────────────────────────
|
||
export function openPauseMenu(scene, { settings, variantNow, depth, onChange, onRules, onNewGame, onLeave, onClose }) {
|
||
const objs = [blocker(scene, depth - 1, 0.5)];
|
||
const w = 500, h = 720;
|
||
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 Workshop', depth + 1, 28));
|
||
const cx = x + w / 2;
|
||
let hRef = null;
|
||
const variantLabel = () => {
|
||
const v = settings.variant === 'free' ? 'Free (grey) wall' : 'Printed wall';
|
||
return `Wall: ${v}${settings.variant !== variantNow ? ' · next game' : ''}`;
|
||
};
|
||
const rows = [
|
||
['Resume', () => hRef.close(), 0x1d4f8f],
|
||
[() => `Opponent speed: ${PACE_LABEL[settings.pace]}`, () => {
|
||
const order = ['relaxed', 'normal', 'fast'];
|
||
onChange('pace', order[(order.indexOf(settings.pace) + 1) % order.length]);
|
||
}],
|
||
[() => `Move preview: ${onOff(settings.preview)}`, () => onChange('preview', !settings.preview)],
|
||
[() => `Undo last move: ${onOff(settings.undo)}`, () => onChange('undo', !settings.undo)],
|
||
[() => `Tile tracker: ${onOff(settings.tracker)}`, () => onChange('tracker', !settings.tracker)],
|
||
[() => `Bonus hints on boards: ${onOff(settings.bonusHints)}`, () => onChange('bonusHints', !settings.bonusHints)],
|
||
[() => `Colour-blind symbols: ${onOff(settings.glyphs)}`, () => onChange('glyphs', !settings.glyphs)],
|
||
[variantLabel, () => onChange('variant', settings.variant === 'free' ? 'standard' : 'free')],
|
||
['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 + 106 + i * 52, text, () => {
|
||
fn();
|
||
if (typeof label === 'function') btn.setLabel(label());
|
||
}, { width: 400, height: 44, fontSize: 17, bg: bg ?? 0x5a3820 }).setDepth(depth + 2);
|
||
objs.push(btn);
|
||
});
|
||
objs.push(scene.add.text(cx, y + h - 34, 'Keys: 1–9 plates · C centre · ←/→ colour · ↑/↓ line · Enter place · F floor · Z undo · L log', {
|
||
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;
|
||
}
|
||
|
||
// ── log ────────────────────────────────────────────────────────────────────────────
|
||
export function openLog(scene, { log, depth, onClose }) {
|
||
const objs = [blocker(scene, depth - 1, 0.5)];
|
||
const w = 760, h = 700;
|
||
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, 'Order Book', depth + 1, 28));
|
||
const viewY = y + 84, viewH = h - 160;
|
||
const lines = log.slice().reverse();
|
||
const body = scene.add.text(x + 44, viewY, lines.join('\n'), {
|
||
fontFamily: SERIF, fontSize: '16px', color: '#1d3f6e', lineSpacing: 8, wordWrap: { width: w - 88 },
|
||
}).setDepth(depth + 1);
|
||
const maskG = scene.make.graphics({ x: 0, y: 0, add: false });
|
||
maskG.fillStyle(0xffffff).fillRect(x + 20, viewY, w - 40, viewH);
|
||
body.setMask(maskG.createGeometryMask());
|
||
objs.push(body, { destroy: () => maskG.destroy() });
|
||
const maxScroll = Math.max(0, body.height - viewH);
|
||
let off = 0;
|
||
const onWheel = (_p, _o, _dx, dy) => { off = Math.max(0, Math.min(maxScroll, off + dy * 0.6)); body.y = viewY - off; };
|
||
scene.input.on('wheel', onWheel);
|
||
objs.push({ destroy: () => scene.input.off('wheel', onWheel) });
|
||
if (maxScroll > 0) {
|
||
objs.push(scene.add.text(x + w - 44, viewY + viewH + 8, 'newest first · scroll for more ↓', {
|
||
fontFamily: SERIF, fontSize: '12px', fontStyle: 'italic', color: '#5a4428',
|
||
}).setOrigin(1, 0).setDepth(depth + 1));
|
||
}
|
||
let hRef = null;
|
||
objs.push(new Button(scene, x + w / 2, y + h - 42, 'Close', () => hRef.close(), { width: 200, height: 44, fontSize: 18, bg: 0x5a3820 }).setDepth(depth + 2));
|
||
objs[0].on('pointerdown', () => hRef.close());
|
||
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 = 500, h = 240;
|
||
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 + 104, 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 - 112, y + h - 52, yes, () => { hRef.close(); onYes?.(); }, { width: 196, height: 46, fontSize: 18, bg: 0x1d4f8f }).setDepth(depth + 2));
|
||
objs.push(new Button(scene, x + w / 2 + 112, y + h - 52, no, () => { hRef.close(); onNo?.(); }, { width: 196, height: 46, fontSize: 18, bg: 0x5a3820 }).setDepth(depth + 2));
|
||
hRef = handle(objs);
|
||
return hRef;
|
||
}
|