/** * FamilyTreeUI.js * =============== * KRVAVA Ε½ETEV - Family Tree UI (P12.5) * * Features: * - Visual family tree display * - Generational view * - Heirloom tracking * - Legacy stats * * @author NovaFarma Team * @date 2025-12-23 */ export default class FamilyTreeUI { constructor(scene) { this.scene = scene; // UI elements this.container = null; this.isVisible = false; // Heirloom system this.heirlooms = new Map(); // itemId -> heirloom data console.log('🌳 FamilyTreeUI initialized'); } /** * Create Family Tree UI */ createFamilyTreeUI() { const width = this.scene.cameras.main.width; const height = this.scene.cameras.main.height; // Main container this.container = this.scene.add.container(width / 2, height / 2); this.container.setScrollFactor(0); this.container.setDepth(10000); this.container.setVisible(false); // Background const bg = this.scene.add.rectangle(0, 0, 800, 600, 0x1a1a1a, 0.95); bg.setStrokeStyle(3, 0xDAA520); this.container.add(bg); // Title const title = this.scene.add.text(0, -280, '🌳 FAMILY TREE', { fontSize: '32px', fontFamily: 'Arial', color: '#DAA520', fontStyle: 'bold' }); title.setOrigin(0.5); this.container.add(title); // Close button const closeBtn = this.scene.add.text(380, -280, '❌', { fontSize: '24px', cursor: 'pointer' }); closeBtn.setInteractive(); closeBtn.on('pointerdown', () => this.hide()); this.container.add(closeBtn); // Stats panel this.createStatsPanel(); // Family tree visualization this.createTreeVisualization(); // Heirloom panel this.createHeirloomPanel(); console.log('βœ… Family Tree UI created'); } /** * Create stats panel */ createStatsPanel() { const generationalSystem = this.scene.generationalGameplaySystem; if (!generationalSystem) return; const stats = generationalSystem.getFamilyTree(); const currentGen = generationalSystem.currentGeneration; const totalGens = generationalSystem.generations.length; const statsText = [ `Current Generation: ${currentGen}`, `Total Generations: ${totalGens}`, `Family Members: ${stats.size}`, `Legacy Points: ${generationalSystem.legacyPoints}` ].join('\n'); const text = this.scene.add.text(-350, -220, statsText, { fontSize: '16px', fontFamily: 'Arial', color: '#ffffff', lineSpacing: 8 }); this.container.add(text); } /** * Create tree visualization */ createTreeVisualization() { const generationalSystem = this.scene.generationalGameplaySystem; if (!generationalSystem) return; const generations = generationalSystem.generations; const startY = -150; const genSpacing = 100; generations.forEach((generation, genIndex) => { // Generation label const genLabel = this.scene.add.text(-350, startY + (genIndex * genSpacing), `Gen ${genIndex + 1}:`, { fontSize: '18px', fontFamily: 'Arial', color: '#DAA520', fontStyle: 'bold' }); this.container.add(genLabel); // Members of this generation const memberSpacing = 80; const startX = -250; generation.forEach((member, memberIndex) => { const x = startX + (memberIndex * memberSpacing); const y = startY + (genIndex * genSpacing); // Member box const box = this.scene.add.rectangle(x, y, 70, 70, member.isAlive ? 0x2d5016 : 0x4a4a4a, 1); box.setStrokeStyle(2, member.isProtagonist ? 0xFFD700 : 0x888888); this.container.add(box); // Name const nameText = this.scene.add.text(x, y - 10, member.name, { fontSize: '12px', fontFamily: 'Arial', color: '#ffffff' }); nameText.setOrigin(0.5); this.container.add(nameText); // Age/status const statusText = this.scene.add.text(x, y + 10, member.isAlive ? `Age: ${Math.floor(member.age / 365)}` : '⚰️', { fontSize: '10px', fontFamily: 'Arial', color: member.isAlive ? '#00ff00' : '#ff0000' }); statusText.setOrigin(0.5); this.container.add(statusText); // Protagonist indicator if (member.isProtagonist) { const star = this.scene.add.text(x, y - 45, 'πŸ‘‘', { fontSize: '16px' }); star.setOrigin(0.5); this.container.add(star); } // Connection lines to children if (member.children && member.children.length > 0) { member.children.forEach(childId => { const child = generationalSystem.familyTree.get(childId); if (child) { const childGen = child.generation - 1; const childIndex = generations[childGen]?.indexOf(child) || 0; const childX = startX + (childIndex * memberSpacing); const childY = startY + (childGen * genSpacing); // Draw line const line = this.scene.add.line(0, 0, x, y + 35, childX, childY - 35, 0xDAA520, 0.5); this.container.add(line); } }); } }); }); } /** * Create heirloom panel */ createHeirloomPanel() { // Heirloom title const heirloomTitle = this.scene.add.text(-350, 200, 'πŸ‘‘ HEIRLOOMS:', { fontSize: '20px', fontFamily: 'Arial', color: '#DAA520', fontStyle: 'bold' }); this.container.add(heirloomTitle); // List heirlooms let y = 230; this.heirlooms.forEach((heirloom, itemId) => { const text = this.scene.add.text(-340, y, `${heirloom.icon} ${heirloom.name} (Gen ${heirloom.originalGeneration})`, { fontSize: '14px', fontFamily: 'Arial', color: '#ffffff' }); this.container.add(text); y += 25; }); if (this.heirlooms.size === 0) { const noHeirlooms = this.scene.add.text(-340, 230, 'No heirlooms yet. Create legacy items!', { fontSize: '14px', fontFamily: 'Arial', color: '#888888', fontStyle: 'italic' }); this.container.add(noHeirlooms); } } /** * Add heirloom item */ addHeirloom(itemId, itemName, icon = 'πŸ’Ž') { const generationalSystem = this.scene.generationalGameplaySystem; if (!generationalSystem) return; const heirloom = { itemId: itemId, name: itemName, icon: icon, originalGeneration: generationalSystem.currentGeneration, originalOwner: generationalSystem.currentProtagonist?.name || 'Unknown', createdDate: new Date(), timesPassedDown: 0 }; this.heirlooms.set(itemId, heirloom); console.log(`πŸ‘‘ "${itemName}" is now an heirloom! (Generation ${heirloom.originalGeneration})`); this.showNotification({ title: 'Heirloom Created!', text: `πŸ‘‘ ${itemName} will be passed down through generations!`, icon: 'πŸ’Ž' }); } /** * Pass down heirlooms to next generation */ passDownHeirlooms() { this.heirlooms.forEach(heirloom => { heirloom.timesPassedDown++; console.log(`πŸ‘‘ ${heirloom.name} passed to next generation (${heirloom.timesPassedDown} times)`); }); if (this.heirlooms.size > 0) { this.showNotification({ title: 'Heirlooms Inherited', text: `πŸ‘‘ ${this.heirlooms.size} family treasure(s) passed down!`, icon: 'πŸ’Ž' }); } } /** * Get heirloom bonus */ getHeirloomBonus(itemId) { const heirloom = this.heirlooms.get(itemId); if (!heirloom) return 1.0; // Bonus increases with each generation return 1.0 + (heirloom.timesPassedDown * 0.05); // +5% per generation } /** * Show/hide UI */ show() { if (!this.container) { this.createFamilyTreeUI(); } this.isVisible = true; this.container.setVisible(true); // Refresh display this.refresh(); } hide() { if (!this.container) return; this.isVisible = false; this.container.setVisible(false); } toggle() { if (this.isVisible) { this.hide(); } else { this.show(); } } /** * Refresh UI */ refresh() { if (!this.container) return; // Clear and rebuild this.container.removeAll(true); this.createFamilyTreeUI(); } /** * Helper: Show notification */ showNotification(notification) { console.log(`πŸ“’ ${notification.icon} ${notification.title}: ${notification.text}`); const ui = this.scene.scene.get('UIScene'); if (ui && ui.showNotification) { ui.showNotification(notification); } } /** * Get all heirlooms */ getHeirlooms() { return Array.from(this.heirlooms.values()); } /** * Check if item is heirloom */ isHeirloom(itemId) { return this.heirlooms.has(itemId); } }