- Extract createButton/pixelText helpers to src/utils/ui.js with sensible defaults and per-call option overrides - MenuScene now shows BADGES button opening the achievement panel (10 entries, count of unlocked, star icons for completed) - GameOverScene buttons migrated to shared utility, removing duplicate hover/click handlers - Smaller LEADERBOARD button to make room for BADGES alongside
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
import { sound } from '../managers/SoundManager.js';
|
|
|
|
const DEFAULTS = {
|
|
width: 260,
|
|
height: 48,
|
|
fontSize: '13px',
|
|
bgColor: 0x581c87,
|
|
hoverColor: 0x7e22ce,
|
|
strokeColor: 0xa855f7,
|
|
strokeWidth: 2,
|
|
textColor: '#ffffff',
|
|
hoverScale: 1.04,
|
|
playClick: true,
|
|
};
|
|
|
|
export function createButton(scene, x, y, text, callback, options = {}) {
|
|
const opt = { ...DEFAULTS, ...options };
|
|
|
|
const bg = scene.add.rectangle(x, y, opt.width, opt.height, opt.bgColor)
|
|
.setStrokeStyle(opt.strokeWidth, opt.strokeColor)
|
|
.setInteractive({ useHandCursor: true });
|
|
|
|
const label = scene.add.text(x, y, text, {
|
|
fontFamily: '"Press Start 2P", monospace',
|
|
fontSize: opt.fontSize,
|
|
color: opt.textColor,
|
|
}).setOrigin(0.5);
|
|
|
|
bg.on('pointerover', () => {
|
|
bg.setFillStyle(opt.hoverColor);
|
|
scene.tweens.add({ targets: [bg, label], scaleX: opt.hoverScale, scaleY: opt.hoverScale, duration: 100 });
|
|
});
|
|
bg.on('pointerout', () => {
|
|
bg.setFillStyle(opt.bgColor);
|
|
scene.tweens.add({ targets: [bg, label], scaleX: 1, scaleY: 1, duration: 100 });
|
|
});
|
|
bg.on('pointerdown', () => {
|
|
if (opt.playClick) sound.click();
|
|
callback();
|
|
});
|
|
|
|
return { bg, label, destroy: () => { bg.destroy(); label.destroy(); } };
|
|
}
|
|
|
|
export function pixelText(scene, x, y, text, size = '14px', color = '#ffffff') {
|
|
return scene.add.text(x, y, text, {
|
|
fontFamily: '"Press Start 2P", monospace',
|
|
fontSize: size,
|
|
color,
|
|
}).setOrigin(0.5);
|
|
}
|