diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 3067147..45a00d9 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1407,6 +1407,8 @@ PODS: - shared_preferences_foundation (0.0.1): - Flutter - FlutterMacOS + - url_launcher_ios (0.0.1): + - Flutter DEPENDENCIES: - app_links (from `.symlinks/plugins/app_links/ios`) @@ -1420,6 +1422,7 @@ DEPENDENCIES: - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - share_plus (from `.symlinks/plugins/share_plus/ios`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) + - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) SPEC REPOS: trunk: @@ -1469,6 +1472,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/share_plus/ios" shared_preferences_foundation: :path: ".symlinks/plugins/shared_preferences_foundation/darwin" + url_launcher_ios: + :path: ".symlinks/plugins/url_launcher_ios/ios" SPEC CHECKSUMS: abseil: a05cc83bf02079535e17169a73c5be5ba47f714b @@ -1504,6 +1509,7 @@ SPEC CHECKSUMS: RecaptchaInterop: 11e0b637842dfb48308d242afc3f448062325aba share_plus: 50da8cb520a8f0f65671c6c6a99b3617ed10a58a shared_preferences_foundation: 7036424c3d8ec98dfe75ff1667cb0cd531ec82bb + url_launcher_ios: 7a95fa5b60cc718a708b8f2966718e93db0cef1b PODFILE CHECKSUM: 3d68f7cb47d5f2fb7765407f663653c9b51100f3 diff --git a/lib/logic/game_controller.dart b/lib/logic/game_controller.dart index fd5d8b9..d4daec4 100644 --- a/lib/logic/game_controller.dart +++ b/lib/logic/game_controller.dart @@ -56,9 +56,32 @@ class GameController extends ChangeNotifier { bool opponentWantsRematch = false; int lastMatchXP = 0; + // --- NUOVA ROADMAP DINAMICA DEGLI SBLOCCHI --- + // Aggiungi qui le tue future meccaniche! Il popup le leggerà in automatico. + static const Map>> rewardsRoadmap = { + 2: [{'title': 'Bomba & Oro', 'desc': 'Appaiono le caselle speciali: Oro (+2) e Bomba (-1)!', 'icon': Icons.stars, 'color': Colors.amber}], + 3: [ + {'title': 'Tema Cyberpunk', 'desc': 'Sbloccato un nuovo tema visivo nelle impostazioni.', 'icon': Icons.palette, 'color': Colors.tealAccent}, + {'title': 'Arena a Croce', 'desc': 'Sbloccata una nuova forma arena più complessa.', 'icon': Icons.add_box, 'color': Colors.blueAccent} + ], + 5: [{'title': 'Scambio', 'desc': 'Nuova casella! Inverte istantaneamente i punteggi.', 'icon': Icons.swap_horiz, 'color': Colors.purpleAccent}], + 7: [ + {'title': 'Tema 8-Bit', 'desc': 'Sbloccato il nostalgico tema sala giochi.', 'icon': Icons.videogame_asset, 'color': Colors.greenAccent}, + {'title': 'Arene Caos', 'desc': 'Generazione procedurale sbloccata. Nessuna partita sarà uguale!', 'icon': Icons.all_inclusive, 'color': Colors.redAccent} + ], + 10: [ + {'title': 'Tema Grimorio', 'desc': 'Sbloccato il tema della magia antica.', 'icon': Icons.auto_stories, 'color': Colors.deepPurpleAccent}, + {'title': 'Blocco di Ghiaccio', 'desc': 'Nuova meccanica! Il ghiaccio richiede due colpi per rompersi.', 'icon': Icons.ac_unit, 'color': Colors.cyanAccent} + ], + 15: [ + {'title': 'Tema Musica', 'desc': 'Sbloccato il tema a tempo di beat.', 'icon': Icons.headphones, 'color': Colors.pinkAccent}, + {'title': 'Moltiplicatore x2', 'desc': 'Nuova casella! Raddoppia i punti della tua prossima conquista.', 'icon': Icons.bolt, 'color': Colors.yellowAccent} + ], + }; + bool hasLeveledUp = false; int newlyReachedLevel = 1; - List unlockedFeatures = []; + List> unlockedRewards = []; // Ora è una lista di mappe dinamiche bool isSetupPhase = true; bool myJokerPlaced = false; @@ -111,7 +134,7 @@ class GameController extends ChangeNotifier { lastMatchXP = 0; hasLeveledUp = false; - unlockedFeatures.clear(); + unlockedRewards.clear(); myReaction = null; opponentReaction = null; @@ -543,17 +566,13 @@ class GameController extends ChangeNotifier { } } - // --- NUOVI LIVELLI DI SBLOCCO --- - List _getUnlocks(int oldLevel, int newLevel) { - List unlocks = []; + // --- LOGICA DI ESTRAZIONE SBLOCCHI DINAMICA --- + List> _getUnlocks(int oldLevel, int newLevel) { + List> unlocks = []; for(int i = oldLevel + 1; i <= newLevel; i++) { - if (i == 3) unlocks.add("Tema: Cyberpunk"); - if (i == 7) { - unlocks.add("Tema: 8-Bit Arcade"); - unlocks.add("Forma Arena: Caos"); + if (rewardsRoadmap.containsKey(i)) { + unlocks.addAll(rewardsRoadmap[i]!); } - if (i == 10) unlocks.add("Tema: Grimorio"); - if (i == 15) unlocks.add("Tema: Musica"); } return unlocks; } @@ -607,7 +626,7 @@ class GameController extends ChangeNotifier { if (newLevel > oldLevel) { hasLeveledUp = true; newlyReachedLevel = newLevel; - unlockedFeatures = _getUnlocks(oldLevel, newLevel); + unlockedRewards = _getUnlocks(oldLevel, newLevel); } notifyListeners(); diff --git a/lib/ui/home/home_modals.dart b/lib/ui/home/home_modals.dart new file mode 100644 index 0000000..c8fa311 --- /dev/null +++ b/lib/ui/home/home_modals.dart @@ -0,0 +1,702 @@ +// =========================================================================== +// FILE: lib/ui/home/home_modals.dart +// =========================================================================== + +import 'dart:ui'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:firebase_auth/firebase_auth.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +import '../../core/theme_manager.dart'; +import '../../core/app_colors.dart'; +import '../../logic/game_controller.dart'; +import '../../models/game_board.dart'; +import '../../services/storage_service.dart'; +import '../../services/multiplayer_service.dart'; +import '../../l10n/app_localizations.dart'; +import '../../widgets/painters.dart'; +import '../../widgets/cyber_border.dart'; +import '../game/game_screen.dart'; +import '../multiplayer/lobby_screen.dart'; +import '../multiplayer/lobby_widgets.dart'; + +class HomeModals { + + static void showNameDialog(BuildContext context, VoidCallback onSuccess) { + final TextEditingController nameController = TextEditingController(text: StorageService.instance.playerName); + final TextEditingController passController = TextEditingController(); + bool isLoadingAuth = false; + bool obscurePassword = true; + String errorMessage = ""; + + showDialog( + context: context, barrierDismissible: false, barrierColor: Colors.black.withOpacity(0.8), + builder: (dialogContext) { + final themeManager = dialogContext.watch(); + final themeType = themeManager.currentThemeType; + Color inkColor = const Color(0xFF111122); + final loc = AppLocalizations.of(dialogContext)!; + + return StatefulBuilder( + builder: (context, setStateDialog) { + + Future handleAuth(bool isLogin) async { + final name = nameController.text.trim(); + final password = passController.text.trim(); + + setStateDialog(() { errorMessage = ""; isLoadingAuth = true; }); + + if (name.isEmpty || password.isEmpty) { + setStateDialog(() { errorMessage = "Inserisci Nome e Password!"; isLoadingAuth = false; }); + return; + } + if (password.length < 6) { + setStateDialog(() { errorMessage = "La password deve avere almeno 6 caratteri!"; isLoadingAuth = false; }); + return; + } + + final fakeEmail = "${name.toLowerCase().replaceAll(' ', '')}@tetraq.game"; + + try { + if (isLogin) { + await FirebaseAuth.instance.signInWithEmailAndPassword(email: fakeEmail, password: password); + final doc = await FirebaseFirestore.instance.collection('leaderboard').doc(FirebaseAuth.instance.currentUser!.uid).get(); + if (doc.exists) { + final data = doc.data() as Map; + final prefs = await SharedPreferences.getInstance(); + await prefs.setInt('totalXP', data['xp'] ?? 0); + await prefs.setInt('wins', data['wins'] ?? 0); + await prefs.setInt('losses', data['losses'] ?? 0); + } + if (context.mounted) ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Bentornato $name! Dati sincronizzati."), backgroundColor: Colors.green)); + } else { + await FirebaseAuth.instance.createUserWithEmailAndPassword(email: fakeEmail, password: password); + if (context.mounted) ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("Account creato con successo!"), backgroundColor: Colors.green)); + } + + await StorageService.instance.savePlayerName(name); + if (context.mounted) Navigator.of(dialogContext).pop(); + onSuccess(); + + } on FirebaseAuthException catch (e) { + String msg = "Errore di autenticazione."; + if (e.code == 'email-already-in-use') msg = "Nome occupato!\nSe è il tuo account, clicca su ACCEDI."; + else if (e.code == 'user-not-found' || e.code == 'wrong-password' || e.code == 'invalid-credential') msg = "Nome o Password errati!"; + setStateDialog(() { errorMessage = msg; isLoadingAuth = false; }); + } catch (e) { + setStateDialog(() { errorMessage = "Errore imprevisto: $e"; isLoadingAuth = false; }); + } + } + + Widget dialogContent = themeType == AppThemeType.doodle + ? CustomPaint( + painter: DoodleBackgroundPainter(fillColor: Colors.yellow.shade100, strokeColor: inkColor, seed: 100), + child: SingleChildScrollView( + physics: const BouncingScrollPhysics(), + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 20.0, horizontal: 20.0), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text(loc.welcomeTitle, style: getSharedTextStyle(themeType, TextStyle(color: inkColor, fontWeight: FontWeight.w900, fontSize: 24, letterSpacing: 2.0)), textAlign: TextAlign.center), + const SizedBox(height: 10), + Text('Scegli Nome e Password.\nTi serviranno per recuperare gli XP!', style: getSharedTextStyle(themeType, TextStyle(color: inkColor.withOpacity(0.8), fontSize: 13)), textAlign: TextAlign.center), + const SizedBox(height: 15), + TextField( + controller: nameController, textCapitalization: TextCapitalization.characters, textAlign: TextAlign.center, maxLength: 8, + style: getSharedTextStyle(themeType, TextStyle(color: inkColor, fontSize: 24, fontWeight: FontWeight.bold, letterSpacing: 4)), + decoration: InputDecoration( + hintText: loc.nameHint, hintStyle: getSharedTextStyle(themeType, TextStyle(color: inkColor.withOpacity(0.3), letterSpacing: 4)), + filled: false, counterText: "", + enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: inkColor, width: 3)), + focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.red.shade200, width: 5)) + ), + ), + const SizedBox(height: 8), + TextField( + controller: passController, obscureText: obscurePassword, textAlign: TextAlign.center, maxLength: 20, + style: getSharedTextStyle(themeType, TextStyle(color: inkColor, fontSize: 20, fontWeight: FontWeight.bold, letterSpacing: 8)), + decoration: InputDecoration( + hintText: "PASSWORD", hintStyle: getSharedTextStyle(themeType, TextStyle(color: inkColor.withOpacity(0.3), letterSpacing: 4)), + filled: false, counterText: "", + enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: inkColor, width: 3)), + focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.red.shade200, width: 5)), + suffixIcon: IconButton( + icon: Icon(obscurePassword ? Icons.visibility : Icons.visibility_off, color: inkColor.withOpacity(0.6)), + onPressed: () { setStateDialog(() { obscurePassword = !obscurePassword; }); }, + ), + ), + ), + const SizedBox(height: 15), + if (errorMessage.isNotEmpty) + Padding(padding: const EdgeInsets.only(bottom: 10), child: Text(errorMessage, style: getSharedTextStyle(themeType, const TextStyle(color: Colors.red, fontSize: 14, fontWeight: FontWeight.bold)), textAlign: TextAlign.center)), + Text("💡 Nota: Non serve una vera email. Usa una password facile da ricordare!", style: getSharedTextStyle(themeType, TextStyle(color: inkColor.withOpacity(0.6), fontSize: 11, height: 1.3)), textAlign: TextAlign.center), + const SizedBox(height: 15), + isLoadingAuth ? CircularProgressIndicator(color: inkColor) : Row( + children: [ + Expanded(child: GestureDetector(onTap: () => handleAuth(true), child: CustomPaint(painter: DoodleBackgroundPainter(fillColor: Colors.blue.shade200, strokeColor: inkColor, seed: 101), child: Container(height: 45, alignment: Alignment.center, child: Text("ACCEDI", style: getSharedTextStyle(themeType, TextStyle(color: inkColor, fontSize: 14, fontWeight: FontWeight.bold, letterSpacing: 1.5))))))), + const SizedBox(width: 10), + Expanded(child: GestureDetector(onTap: () => handleAuth(false), child: CustomPaint(painter: DoodleBackgroundPainter(fillColor: Colors.green.shade200, strokeColor: inkColor, seed: 102), child: Container(height: 45, alignment: Alignment.center, child: Text("REGISTRATI", style: getSharedTextStyle(themeType, TextStyle(color: inkColor, fontSize: 14, fontWeight: FontWeight.bold, letterSpacing: 1.5))))))), + ], + ), + ], + ), + ), + ), + ) + : Container( + decoration: BoxDecoration(color: themeManager.currentColors.background, borderRadius: BorderRadius.circular(25), border: Border.all(color: themeManager.currentColors.playerBlue.withOpacity(0.5), width: 2), boxShadow: [BoxShadow(color: themeManager.currentColors.playerBlue.withOpacity(0.3), blurRadius: 20, spreadRadius: 5)]), + child: SingleChildScrollView( + physics: const BouncingScrollPhysics(), + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 20.0, horizontal: 20.0), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text(loc.welcomeTitle, style: getSharedTextStyle(themeType, TextStyle(color: themeManager.currentColors.text, fontWeight: FontWeight.w900, fontSize: 20, letterSpacing: 1.5)), textAlign: TextAlign.center), + const SizedBox(height: 10), + Text('Scegli Nome e Password.\nTi serviranno per recuperare gli XP!', style: getSharedTextStyle(themeType, TextStyle(color: themeManager.currentColors.text.withOpacity(0.8), fontSize: 13)), textAlign: TextAlign.center), + const SizedBox(height: 15), + TextField( + controller: nameController, textCapitalization: TextCapitalization.characters, textAlign: TextAlign.center, maxLength: 8, + style: getSharedTextStyle(themeType, TextStyle(color: themeManager.currentColors.text, fontSize: 24, fontWeight: FontWeight.bold, letterSpacing: 4)), + decoration: InputDecoration( + hintText: loc.nameHint, hintStyle: getSharedTextStyle(themeType, TextStyle(color: themeManager.currentColors.text.withOpacity(0.3), letterSpacing: 4)), + filled: true, fillColor: themeManager.currentColors.text.withOpacity(0.05), counterText: "", + enabledBorder: OutlineInputBorder(borderSide: BorderSide(color: themeManager.currentColors.gridLine.withOpacity(0.5), width: 2), borderRadius: BorderRadius.circular(15)), + focusedBorder: OutlineInputBorder(borderSide: BorderSide(color: themeManager.currentColors.playerBlue, width: 3), borderRadius: BorderRadius.circular(15)) + ), + ), + const SizedBox(height: 10), + TextField( + controller: passController, obscureText: obscurePassword, textAlign: TextAlign.center, maxLength: 20, + style: getSharedTextStyle(themeType, TextStyle(color: themeManager.currentColors.text, fontSize: 20, fontWeight: FontWeight.bold, letterSpacing: 8)), + decoration: InputDecoration( + hintText: "PASSWORD", hintStyle: getSharedTextStyle(themeType, TextStyle(color: themeManager.currentColors.text.withOpacity(0.3), letterSpacing: 4)), + filled: true, fillColor: themeManager.currentColors.text.withOpacity(0.05), counterText: "", + enabledBorder: OutlineInputBorder(borderSide: BorderSide(color: themeManager.currentColors.gridLine.withOpacity(0.5), width: 2), borderRadius: BorderRadius.circular(15)), + focusedBorder: OutlineInputBorder(borderSide: BorderSide(color: themeManager.currentColors.playerBlue, width: 3), borderRadius: BorderRadius.circular(15)), + suffixIcon: IconButton( + icon: Icon(obscurePassword ? Icons.visibility : Icons.visibility_off, color: themeManager.currentColors.text.withOpacity(0.6)), + onPressed: () { setStateDialog(() { obscurePassword = !obscurePassword; }); }, + ), + ), + ), + const SizedBox(height: 15), + if (errorMessage.isNotEmpty) + Padding(padding: const EdgeInsets.only(bottom: 10), child: Text(errorMessage, style: getSharedTextStyle(themeType, const TextStyle(color: Colors.redAccent, fontSize: 14, fontWeight: FontWeight.bold)), textAlign: TextAlign.center)), + Text("💡 Nota: Non serve una vera email. Usa una password facile da ricordare!", style: getSharedTextStyle(themeType, TextStyle(color: themeManager.currentColors.text.withOpacity(0.6), fontSize: 11, height: 1.3)), textAlign: TextAlign.center), + const SizedBox(height: 20), + isLoadingAuth ? CircularProgressIndicator(color: themeManager.currentColors.playerBlue) : Row( + children: [ + Expanded(child: SizedBox(height: 45, child: ElevatedButton(style: ElevatedButton.styleFrom(backgroundColor: themeManager.currentColors.text.withOpacity(0.1), foregroundColor: themeManager.currentColors.text, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)), side: BorderSide(color: themeManager.currentColors.playerBlue, width: 1.5)), onPressed: () => handleAuth(true), child: Text("ACCEDI", style: getSharedTextStyle(themeType, const TextStyle(fontSize: 13, fontWeight: FontWeight.bold, letterSpacing: 1.0)))))), + const SizedBox(width: 10), + Expanded(child: SizedBox(height: 45, child: ElevatedButton(style: ElevatedButton.styleFrom(backgroundColor: themeManager.currentColors.playerBlue, foregroundColor: Colors.white, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15))), onPressed: () => handleAuth(false), child: Text("REGISTRATI", style: getSharedTextStyle(themeType, const TextStyle(fontSize: 13, fontWeight: FontWeight.bold, letterSpacing: 1.0)))))), + ], + ), + ], + ), + ), + ), + ); + + if (themeType == AppThemeType.cyberpunk || themeType == AppThemeType.music) dialogContent = AnimatedCyberBorder(child: dialogContent); + return Dialog(backgroundColor: Colors.transparent, insetPadding: const EdgeInsets.all(20), child: dialogContent); + }, + ); + }, + ); + } + + static void showMatchSetupDialog(BuildContext context, bool isVsCPU) { + int localRadius = 4; ArenaShape localShape = ArenaShape.classic; bool localTimeMode = true; + bool isChaosUnlocked = StorageService.instance.playerLevel >= 7; + final loc = AppLocalizations.of(context)!; + + showDialog( + context: context, barrierColor: Colors.black.withOpacity(0.8), + builder: (ctx) { + final themeManager = ctx.watch(); + final theme = themeManager.currentColors; final themeType = themeManager.currentThemeType; + Color inkColor = const Color(0xFF111122); + + return StatefulBuilder( + builder: (context, setStateDialog) { + Widget dialogContent = themeType == AppThemeType.doodle + ? Transform.rotate( + angle: 0.015, + child: CustomPaint( + painter: DoodleBackgroundPainter(fillColor: Colors.white.withOpacity(0.95), strokeColor: inkColor, seed: 200), + child: SingleChildScrollView( + physics: const BouncingScrollPhysics(), + child: Padding( + padding: const EdgeInsets.all(25.0), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Row(children: [ SizedBox(width: 40, child: IconButton(padding: EdgeInsets.zero, alignment: Alignment.centerLeft, icon: Icon(Icons.arrow_back_ios_new, color: inkColor, size: 26), onPressed: () => Navigator.pop(ctx))), Expanded(child: Text(isVsCPU ? loc.cpuTitle : loc.localTitle, textAlign: TextAlign.center, style: getSharedTextStyle(themeType, TextStyle(fontSize: 26, fontWeight: FontWeight.w900, color: inkColor, letterSpacing: 2)))), const SizedBox(width: 40) ]), + const SizedBox(height: 25), + + if (isVsCPU) ...[ + Icon(Icons.smart_toy, size: 50, color: inkColor.withOpacity(0.6)), const SizedBox(height: 10), + Text("MODALITÀ CAMPAGNA", style: getSharedTextStyle(themeType, TextStyle(fontSize: 16, fontWeight: FontWeight.w900, color: inkColor))), const SizedBox(height: 10), + Text("Livello CPU: ${StorageService.instance.cpuLevel}\nForma e dimensioni si adatteranno alla tua bravura!", textAlign: TextAlign.center, style: getSharedTextStyle(themeType, TextStyle(fontSize: 13, color: inkColor.withOpacity(0.8), height: 1.4))), const SizedBox(height: 25), + Divider(color: inkColor.withOpacity(0.3), thickness: 2.5), const SizedBox(height: 20), + ] else ...[ + Text("FORMA ARENA", style: getSharedTextStyle(themeType, TextStyle(fontSize: 14, fontWeight: FontWeight.w900, color: inkColor.withOpacity(0.6), letterSpacing: 1.5))), const SizedBox(height: 15), + Wrap( + spacing: 12, runSpacing: 12, alignment: WrapAlignment.center, + children: [ + NeonShapeButton(icon: Icons.diamond_outlined, label: 'Rombo', isSelected: localShape == ArenaShape.classic, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.classic)), + NeonShapeButton(icon: Icons.add, label: 'Croce', isSelected: localShape == ArenaShape.cross, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.cross)), + NeonShapeButton(icon: Icons.donut_large, label: 'Buco', isSelected: localShape == ArenaShape.donut, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.donut)), + NeonShapeButton(icon: Icons.hourglass_bottom, label: 'Clessidra', isSelected: localShape == ArenaShape.hourglass, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.hourglass)), + NeonShapeButton(icon: Icons.all_inclusive, label: 'Caos', isSelected: localShape == ArenaShape.chaos, theme: theme, themeType: themeType, isSpecial: true, isLocked: !isChaosUnlocked, onTap: () => setStateDialog(() => localShape = ArenaShape.chaos)), + ], + ), + const SizedBox(height: 25), Divider(color: inkColor.withOpacity(0.3), thickness: 2.5), const SizedBox(height: 20), + + Text("GRANDEZZA", style: getSharedTextStyle(themeType, TextStyle(fontSize: 14, fontWeight: FontWeight.w900, color: inkColor.withOpacity(0.6), letterSpacing: 1.5))), const SizedBox(height: 15), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + NeonSizeButton(label: 'S', isSelected: localRadius == 3, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 3)), + NeonSizeButton(label: 'M', isSelected: localRadius == 4, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 4)), + NeonSizeButton(label: 'L', isSelected: localRadius == 5, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 5)), + NeonSizeButton(label: 'MAX', isSelected: localRadius == 6, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 6)), + ], + ), + const SizedBox(height: 25), Divider(color: inkColor.withOpacity(0.3), thickness: 2.5), const SizedBox(height: 20), + ], + + Text("TEMPO", style: getSharedTextStyle(themeType, TextStyle(fontSize: 14, fontWeight: FontWeight.w900, color: inkColor.withOpacity(0.6), letterSpacing: 1.5))), const SizedBox(height: 10), + NeonTimeSwitch(isTimeMode: localTimeMode, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localTimeMode = !localTimeMode)), const SizedBox(height: 35), + + Transform.rotate( + angle: -0.02, + child: GestureDetector( + onTap: () { Navigator.pop(ctx); context.read().startNewGame(localRadius, vsCPU: isVsCPU, shape: localShape, timeMode: localTimeMode); Navigator.push(context, MaterialPageRoute(builder: (_) => GameScreen())); }, + child: CustomPaint(painter: DoodleBackgroundPainter(fillColor: Colors.green.shade200, strokeColor: inkColor, seed: 300), child: Container(height: 65, width: double.infinity, alignment: Alignment.center, child: Text(loc.startGame, style: getSharedTextStyle(themeType, TextStyle(fontSize: 22, fontWeight: FontWeight.w900, letterSpacing: 3.0, color: inkColor))))), + ), + ) + ], + ), + ), + ), + ), + ) + : Container( + decoration: BoxDecoration( + gradient: LinearGradient(begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [theme.background.withOpacity(0.95), theme.background.withOpacity(0.8)]), + borderRadius: BorderRadius.circular(25), border: themeType == AppThemeType.cyberpunk || themeType == AppThemeType.arcade || themeType == AppThemeType.music ? null : Border.all(color: Colors.white.withOpacity(0.15), width: 1.5), + boxShadow: themeType == AppThemeType.cyberpunk || themeType == AppThemeType.arcade || themeType == AppThemeType.music ? [] : [BoxShadow(color: Colors.black.withOpacity(0.5), blurRadius: 20, offset: const Offset(4, 10))], + ), + child: SingleChildScrollView( + physics: const BouncingScrollPhysics(), + child: Padding( + padding: const EdgeInsets.all(20.0), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Row(children: [ SizedBox(width: 40, child: IconButton(padding: EdgeInsets.zero, alignment: Alignment.centerLeft, icon: Icon(Icons.arrow_back_ios_new, color: theme.text, size: 26), onPressed: () => Navigator.pop(ctx))), Expanded(child: Text(isVsCPU ? loc.cpuTitle : loc.localTitle, textAlign: TextAlign.center, style: getSharedTextStyle(themeType, TextStyle(fontSize: 24, fontWeight: FontWeight.w900, color: theme.text, letterSpacing: 2)))), const SizedBox(width: 40) ]), + const SizedBox(height: 20), + + if (isVsCPU) ...[ + Icon(Icons.smart_toy, size: 50, color: theme.playerBlue), const SizedBox(height: 10), + Text("MODALITÀ CAMPAGNA", style: getSharedTextStyle(themeType, TextStyle(fontSize: 16, fontWeight: FontWeight.w900, color: theme.text, letterSpacing: 1.5))), const SizedBox(height: 10), + Text("Livello CPU: ${StorageService.instance.cpuLevel}\nForma e dimensioni si adatteranno alla tua bravura!", textAlign: TextAlign.center, style: getSharedTextStyle(themeType, TextStyle(fontSize: 13, color: theme.text.withOpacity(0.7), height: 1.4))), const SizedBox(height: 20), + Divider(color: Colors.white.withOpacity(0.05), thickness: 2), const SizedBox(height: 20), + ] else ...[ + Text("FORMA ARENA", style: getSharedTextStyle(themeType, TextStyle(fontSize: 12, fontWeight: FontWeight.w900, color: theme.text.withOpacity(0.5), letterSpacing: 1.5))), const SizedBox(height: 10), + Wrap( + spacing: 10, runSpacing: 10, alignment: WrapAlignment.center, + children: [ + NeonShapeButton(icon: Icons.diamond_outlined, label: 'Rombo', isSelected: localShape == ArenaShape.classic, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.classic)), + NeonShapeButton(icon: Icons.add, label: 'Croce', isSelected: localShape == ArenaShape.cross, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.cross)), + NeonShapeButton(icon: Icons.donut_large, label: 'Buco', isSelected: localShape == ArenaShape.donut, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.donut)), + NeonShapeButton(icon: Icons.hourglass_bottom, label: 'Clessidra', isSelected: localShape == ArenaShape.hourglass, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.hourglass)), + NeonShapeButton(icon: Icons.all_inclusive, label: 'Caos', isSelected: localShape == ArenaShape.chaos, theme: theme, themeType: themeType, isSpecial: true, isLocked: !isChaosUnlocked, onTap: () => setStateDialog(() => localShape = ArenaShape.chaos)), + ], + ), + const SizedBox(height: 20), Divider(color: Colors.white.withOpacity(0.05), thickness: 2), const SizedBox(height: 20), + + Text("GRANDEZZA", style: getSharedTextStyle(themeType, TextStyle(fontSize: 12, fontWeight: FontWeight.w900, color: theme.text.withOpacity(0.5), letterSpacing: 1.5))), const SizedBox(height: 10), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + NeonSizeButton(label: 'S', isSelected: localRadius == 3, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 3)), + NeonSizeButton(label: 'M', isSelected: localRadius == 4, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 4)), + NeonSizeButton(label: 'L', isSelected: localRadius == 5, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 5)), + NeonSizeButton(label: 'MAX', isSelected: localRadius == 6, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 6)), + ], + ), + const SizedBox(height: 20), Divider(color: Colors.white.withOpacity(0.05), thickness: 2), const SizedBox(height: 20), + ], + + Text("TEMPO", style: getSharedTextStyle(themeType, TextStyle(fontSize: 12, fontWeight: FontWeight.w900, color: theme.text.withOpacity(0.5), letterSpacing: 1.5))), const SizedBox(height: 10), + NeonTimeSwitch(isTimeMode: localTimeMode, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localTimeMode = !localTimeMode)), const SizedBox(height: 30), + + SizedBox( + width: double.infinity, height: 60, + child: ElevatedButton( + style: ElevatedButton.styleFrom(backgroundColor: isVsCPU ? Colors.purple.shade400 : theme.playerRed, foregroundColor: Colors.white, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))), + onPressed: () { Navigator.pop(ctx); context.read().startNewGame(localRadius, vsCPU: isVsCPU, shape: localShape, timeMode: localTimeMode); Navigator.push(context, MaterialPageRoute(builder: (_) => GameScreen())); }, + child: Text(loc.startGame, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w900, letterSpacing: 2)), + ), + ) + ], + ), + ), + ), + ); + + if (themeType == AppThemeType.cyberpunk || themeType == AppThemeType.music) { + dialogContent = AnimatedCyberBorder(child: dialogContent); + } + + return Dialog(backgroundColor: Colors.transparent, insetPadding: const EdgeInsets.symmetric(horizontal: 15, vertical: 20), child: dialogContent); + }, + ); + } + ); + } + + static void showWaitingDialog({ + required BuildContext context, + required String code, + required bool isPublicRoom, + required int selectedRadius, + required ArenaShape selectedShape, + required bool isTimeMode, + required MultiplayerService multiplayerService, + required VoidCallback onRoomStarted, + required VoidCallback onCleanup, + }) { + showDialog( + context: context, + barrierDismissible: false, + builder: (dialogContext) { + final theme = dialogContext.watch().currentColors; + final themeType = dialogContext.read().currentThemeType; + + Widget dialogContent = Column( + mainAxisSize: MainAxisSize.min, + children: [ + CircularProgressIndicator(color: theme.playerRed), const SizedBox(height: 25), + Text("CODICE STANZA", style: getSharedTextStyle(themeType, TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: theme.text.withOpacity(0.6), letterSpacing: 2))), + Text(code, style: getSharedTextStyle(themeType, TextStyle(fontSize: 40, fontWeight: FontWeight.w900, color: theme.playerRed, letterSpacing: 8, shadows: themeType == AppThemeType.doodle ? [] : [Shadow(color: theme.playerRed.withOpacity(0.5), blurRadius: 10)]))), + const SizedBox(height: 25), + Transform.rotate( + angle: themeType == AppThemeType.doodle ? 0.02 : 0, + child: Container( + padding: const EdgeInsets.all(18), + decoration: BoxDecoration( + color: themeType == AppThemeType.doodle ? Colors.white : theme.text.withOpacity(0.05), + borderRadius: BorderRadius.circular(20), + border: Border.all(color: themeType == AppThemeType.doodle ? theme.text : theme.playerBlue.withOpacity(0.3), width: themeType == AppThemeType.doodle ? 2 : 1.5), + boxShadow: themeType == AppThemeType.doodle + ? [BoxShadow(color: theme.text.withOpacity(0.8), offset: const Offset(4, 4))] + : [BoxShadow(color: theme.playerBlue.withOpacity(0.1), blurRadius: 10)] + ), + child: Column( + children: [ + Icon(isPublicRoom ? Icons.podcasts : Icons.share, color: theme.playerBlue, size: 32), const SizedBox(height: 12), + Text(isPublicRoom ? "Sei in Bacheca!" : "Invita un amico", textAlign: TextAlign.center, style: getSharedTextStyle(themeType, TextStyle(color: theme.text, fontWeight: FontWeight.w900, fontSize: 18))), + const SizedBox(height: 8), + Text(isPublicRoom ? "Aspettiamo che uno sfidante si unisca dalla lobby pubblica." : "Condividi il codice. La partita inizierà appena si unirà.", textAlign: TextAlign.center, style: getSharedTextStyle(themeType, TextStyle(color: themeType == AppThemeType.doodle ? theme.text : theme.text.withOpacity(0.8), fontSize: 14, height: 1.5))), + ], + ), + ), + ), + ], + ); + + if (themeType == AppThemeType.cyberpunk || themeType == AppThemeType.music) { + dialogContent = AnimatedCyberBorder(child: dialogContent); + } else { + dialogContent = Container( + padding: const EdgeInsets.all(20), + decoration: BoxDecoration( + color: themeType == AppThemeType.doodle ? Colors.white.withOpacity(0.95) : theme.background, + borderRadius: BorderRadius.circular(25), + border: Border.all(color: themeType == AppThemeType.doodle ? theme.text : theme.gridLine.withOpacity(0.5), width: 2), + boxShadow: themeType == AppThemeType.doodle ? [BoxShadow(color: theme.text.withOpacity(0.6), offset: const Offset(8, 8))] : [] + ), + child: dialogContent + ); + } + + return StreamBuilder( + stream: multiplayerService.listenToRoom(code), + builder: (ctx, snapshot) { + if (snapshot.hasData && snapshot.data!.exists) { + var data = snapshot.data!.data() as Map; + if (data['status'] == 'playing') { + onRoomStarted(); + WidgetsBinding.instance.addPostFrameCallback((_) { + Navigator.pop(ctx); + context.read().startNewGame(selectedRadius, isOnline: true, roomCode: code, isHost: true, shape: selectedShape, timeMode: isTimeMode); + Navigator.pushReplacement(context, MaterialPageRoute(builder: (_) => GameScreen())); + }); + } + } + + return PopScope( + canPop: false, + onPopInvoked: (didPop) { + if (didPop) return; + onCleanup(); + Navigator.pop(ctx); + }, + child: Dialog( + backgroundColor: Colors.transparent, + insetPadding: const EdgeInsets.all(20), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + dialogContent, + const SizedBox(height: 20), + TextButton( + onPressed: () { + onCleanup(); + Navigator.pop(ctx); + }, + child: Text("ANNULLA", style: getSharedTextStyle(themeType, TextStyle(color: Colors.red, fontWeight: FontWeight.w900, fontSize: 20, letterSpacing: 2.0, shadows: themeType == AppThemeType.doodle ? [] : [const Shadow(color: Colors.black, blurRadius: 2)]))), + ), + ], + ), + ), + ); + }, + ); + } + ); + } + + static void showJoinPromptDialog(BuildContext context, String roomCode, Function(String) onConfirm) { + showDialog( + context: context, + builder: (context) { + final themeManager = context.watch(); + final theme = themeManager.currentColors; + final themeType = themeManager.currentThemeType; + return AlertDialog( + backgroundColor: themeType == AppThemeType.doodle ? Colors.white : theme.background, + shape: themeType == AppThemeType.doodle ? RoundedRectangleBorder(borderRadius: BorderRadius.circular(15), side: BorderSide(color: theme.text, width: 2)) : null, + title: Text("Invito Trovato!", style: getSharedTextStyle(themeType, TextStyle(color: theme.text, fontWeight: FontWeight.bold))), + content: Text("Vuoi unirti alla stanza $roomCode?", style: getSharedTextStyle(themeType, TextStyle(color: theme.text))), + actions: [ + TextButton(onPressed: () => Navigator.pop(context), child: Text("No", style: getSharedTextStyle(themeType, const TextStyle(color: Colors.red)))), + ElevatedButton( + style: ElevatedButton.styleFrom(backgroundColor: themeType == AppThemeType.doodle ? Colors.transparent : theme.playerBlue, elevation: 0, side: themeType == AppThemeType.doodle ? BorderSide(color: theme.text, width: 1.5) : BorderSide.none), + onPressed: () { + Navigator.of(context).pop(); + onConfirm(roomCode); + }, + child: Text(AppLocalizations.of(context)!.joinMatch, style: getSharedTextStyle(themeType, TextStyle(color: themeType == AppThemeType.doodle ? theme.text : Colors.white, fontWeight: FontWeight.bold))), + ), + ], + ); + } + ); + } + + static void showFavoritesDialog(BuildContext context, Function(String, String) onInvite) { + final favs = StorageService.instance.favorites; + + showDialog( + context: context, + builder: (ctx) { + final themeManager = ctx.watch(); + final theme = themeManager.currentColors; + final themeType = themeManager.currentThemeType; + + return AlertDialog( + backgroundColor: theme.background, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20), + ), + title: Text("I TUOI PREFERITI", style: getLobbyTextStyle(themeType, TextStyle(color: theme.text, fontWeight: FontWeight.bold))), + content: Container( + width: double.maxFinite, + height: 300, + decoration: BoxDecoration( + border: Border.all(color: theme.playerRed, width: 2), + borderRadius: BorderRadius.circular(10) + ), + child: favs.isEmpty + ? Center(child: Padding( + padding: const EdgeInsets.all(20.0), + child: Text("Non hai ancora aggiunto nessun preferito dalla Classifica!", textAlign: TextAlign.center, style: getLobbyTextStyle(themeType, TextStyle(color: theme.text.withOpacity(0.6)))), + )) + : ListView.builder( + itemCount: favs.length, + itemBuilder: (c, i) { + return ListTile( + title: Text(favs[i]['name']!, style: getLobbyTextStyle(themeType, TextStyle(color: theme.text, fontSize: 18, fontWeight: FontWeight.bold))), + trailing: ElevatedButton( + style: ElevatedButton.styleFrom(backgroundColor: theme.playerBlue, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10))), + onPressed: () { + Navigator.pop(ctx); + onInvite(favs[i]['uid']!, favs[i]['name']!); + }, + child: Text("SFIDA", style: getLobbyTextStyle(themeType, const TextStyle(color: Colors.white, fontWeight: FontWeight.bold))), + ), + ); + }, + ), + ), + actions: [ + TextButton(onPressed: () => Navigator.pop(ctx), child: Text("CHIUDI", style: getLobbyTextStyle(themeType, TextStyle(color: theme.playerRed)))) + ], + ); + } + ); + } +} + +// --- WIDGET POPUP PER AMICO ONLINE --- +class FavoriteOnlinePopup extends StatefulWidget { + final String name; + final VoidCallback onDismiss; + const FavoriteOnlinePopup({super.key, required this.name, required this.onDismiss}); + + @override + State createState() => _FavoriteOnlinePopupState(); +} + +class _FavoriteOnlinePopupState extends State with SingleTickerProviderStateMixin { + late AnimationController _ctrl; + late Animation _fade; + late Animation _slide; + + @override + void initState() { + super.initState(); + _ctrl = AnimationController(vsync: this, duration: const Duration(milliseconds: 400)); + _fade = Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(parent: _ctrl, curve: Curves.easeOut)); + _slide = Tween(begin: const Offset(0, -0.5), end: Offset.zero).animate(CurvedAnimation(parent: _ctrl, curve: Curves.easeOutBack)); + + _ctrl.forward(); + + Future.delayed(const Duration(seconds: 3), () async { + if (mounted) { + await _ctrl.reverse(); + widget.onDismiss(); + } + }); + } + + @override + void dispose() { + _ctrl.dispose(); + super.dispose(); + } + + void _handleTap() { + final game = context.read(); + final themeManager = context.read(); + final theme = themeManager.currentColors; + final themeType = themeManager.currentThemeType; + + // Se il gioco è attivo (non finito e siamo oltre la fase di setup) + bool isInGame = !game.isGameOver && (!game.isSetupPhase || game.isOnline || game.isVsCPU); + + if (isInGame) { + showDialog( + context: context, + builder: (ctx) => AlertDialog( + backgroundColor: theme.background, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15), side: BorderSide(color: theme.playerRed, width: 2)), + title: Text("Sei in partita!", style: getSharedTextStyle(themeType, TextStyle(color: theme.text, fontWeight: FontWeight.bold))), + content: Text("Vuoi abbandonare la partita attuale per raggiungere la lobby multiplayer?", style: TextStyle(color: theme.text)), + actions: [ + TextButton(onPressed: () => Navigator.pop(ctx), child: Text("Annulla", style: TextStyle(color: theme.text))), + ElevatedButton( + style: ElevatedButton.styleFrom(backgroundColor: theme.playerRed), + onPressed: () { + game.disconnectOnlineGame(); + Navigator.pop(ctx); + widget.onDismiss(); + Navigator.popUntil(context, (route) => route.isFirst); + Navigator.push(context, MaterialPageRoute(builder: (_) => LobbyScreen())); + }, + child: const Text("Abbandona e Vai", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)), + ) + ] + ) + ); + } else { + widget.onDismiss(); + Navigator.popUntil(context, (route) => route.isFirst); + Navigator.push(context, MaterialPageRoute(builder: (_) => LobbyScreen())); + } + } + + @override + Widget build(BuildContext context) { + final themeManager = context.watch(); + final theme = themeManager.currentColors; + final themeType = themeManager.currentThemeType; + + return Material( + color: Colors.transparent, + child: SlideTransition( + position: _slide, + child: FadeTransition( + opacity: _fade, + child: GestureDetector( + onTap: _handleTap, + child: Container( + padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14), + decoration: BoxDecoration( + gradient: LinearGradient( + colors: [theme.playerBlue.withOpacity(0.95), theme.playerBlue.withOpacity(0.8)], + ), + borderRadius: BorderRadius.circular(20), + border: Border.all(color: Colors.white.withOpacity(0.4), width: 1.5), + boxShadow: [ + BoxShadow(color: Colors.black.withOpacity(0.4), blurRadius: 15, offset: const Offset(0, 8)), + BoxShadow(color: theme.playerBlue.withOpacity(0.4), blurRadius: 10, spreadRadius: 1), + ], + ), + child: Row( + children: [ + Container( + padding: const EdgeInsets.all(8), + decoration: BoxDecoration( + color: Colors.white.withOpacity(0.2), + shape: BoxShape.circle, + ), + child: const Icon(Icons.star_rounded, color: Colors.amber, size: 24), + ), + const SizedBox(width: 15), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text("Giocatore Online!", style: getSharedTextStyle(themeType, TextStyle(color: Colors.white.withOpacity(0.8), fontSize: 11, fontWeight: FontWeight.bold, letterSpacing: 1.5))), + const SizedBox(height: 2), + Text("${widget.name} è in partita", style: getSharedTextStyle(themeType, const TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w900))), + ], + ), + ), + GestureDetector( + onTap: () async { + await _ctrl.reverse(); + widget.onDismiss(); + }, + child: Icon(Icons.close, color: Colors.white.withOpacity(0.6), size: 20), + ) + ], + ), + ), + ), + ), + ), + ); + } +} \ No newline at end of file diff --git a/lib/ui/home/home_screen.dart b/lib/ui/home/home_screen.dart index 28c6edf..c6d32b5 100644 --- a/lib/ui/home/home_screen.dart +++ b/lib/ui/home/home_screen.dart @@ -11,28 +11,24 @@ import 'package:cloud_firestore/cloud_firestore.dart'; import 'dart:async'; import 'package:app_links/app_links.dart'; -import 'package:firebase_auth/firebase_auth.dart'; -import 'package:shared_preferences/shared_preferences.dart'; - import '../../logic/game_controller.dart'; import '../../core/theme_manager.dart'; import '../../core/app_colors.dart'; -import '../game/game_screen.dart'; -import '../settings/settings_screen.dart'; import '../../services/storage_service.dart'; import '../../services/audio_service.dart'; import '../../services/multiplayer_service.dart'; import '../multiplayer/lobby_screen.dart'; -import 'history_screen.dart'; import '../admin/admin_screen.dart'; +import '../settings/settings_screen.dart'; +import '../game/game_screen.dart'; import 'package:tetraq/l10n/app_localizations.dart'; import '../../widgets/painters.dart'; import '../../widgets/cyber_border.dart'; import '../../widgets/music_theme_widgets.dart'; import '../../widgets/home_buttons.dart'; -import '../../widgets/custom_settings_button.dart'; import 'dialog.dart'; +import 'home_modals.dart'; class HomeScreen extends StatefulWidget { const HomeScreen({super.key}); @@ -46,30 +42,35 @@ class _HomeScreenState extends State with WidgetsBindingObserver { int _debugTapCount = 0; late AppLinks _appLinks; StreamSubscription? _linkSubscription; - bool _isCreatingRoom = false; + StreamSubscription? _favoritesSubscription; + + Map _lastOnlineNotifications = {}; + + final int _selectedRadius = 4; + final ArenaShape _selectedShape = ArenaShape.classic; + final bool _isTimeMode = true; + final bool _isPublicRoom = true; - int _selectedRadius = 4; - ArenaShape _selectedShape = ArenaShape.classic; - bool _isTimeMode = true; - bool _isPublicRoom = true; bool _isLoading = false; String? _myRoomCode; bool _roomStarted = false; final MultiplayerService _multiplayerService = MultiplayerService(); - final TextEditingController _codeController = TextEditingController(); @override void initState() { super.initState(); WidgetsBinding.instance.addObserver(this); WidgetsBinding.instance.addPostFrameCallback((_) { - _checkPlayerName(); + if (StorageService.instance.playerName.isEmpty) { + HomeModals.showNameDialog(context, () => setState(() {})); + } StorageService.instance.syncLeaderboard(); _checkThemeSafety(); }); _checkClipboardForInvite(); _initDeepLinks(); + _listenToFavoritesOnline(); } void _checkThemeSafety() { @@ -85,7 +86,7 @@ class _HomeScreenState extends State with WidgetsBindingObserver { WidgetsBinding.instance.removeObserver(this); _cleanupGhostRoom(); _linkSubscription?.cancel(); - _codeController.dispose(); + _favoritesSubscription?.cancel(); super.dispose(); } @@ -93,6 +94,7 @@ class _HomeScreenState extends State with WidgetsBindingObserver { void didChangeAppLifecycleState(AppLifecycleState state) { if (state == AppLifecycleState.resumed) { _checkClipboardForInvite(); + _listenToFavoritesOnline(); } else if (state == AppLifecycleState.paused || state == AppLifecycleState.detached) { _cleanupGhostRoom(); } @@ -105,10 +107,6 @@ class _HomeScreenState extends State with WidgetsBindingObserver { } } - void _checkPlayerName() { - if (StorageService.instance.playerName.isEmpty) { _showNameDialog(); } - } - Future _initDeepLinks() async { _appLinks = AppLinks(); try { @@ -123,7 +121,7 @@ class _HomeScreenState extends State with WidgetsBindingObserver { String? code = uri.queryParameters['code']; if (code != null && code.length == 5) { Future.delayed(const Duration(milliseconds: 500), () { - if (mounted) _promptJoinRoom(code.toUpperCase()); + if (mounted) HomeModals.showJoinPromptDialog(context, code.toUpperCase(), _joinRoomByCode); }); } } @@ -139,43 +137,74 @@ class _HomeScreenState extends State with WidgetsBindingObserver { if (match != null) { String roomCode = match.group(1)!.toUpperCase(); await Clipboard.setData(const ClipboardData(text: '')); - if (mounted && ModalRoute.of(context)?.isCurrent == true) { _promptJoinRoom(roomCode); } + if (mounted && ModalRoute.of(context)?.isCurrent == true) { + HomeModals.showJoinPromptDialog(context, roomCode, _joinRoomByCode); + } } } } catch (e) { debugPrint("Errore lettura appunti: $e"); } } - Future _createRoom() async { - if (_isLoading) return; - setState(() => _isLoading = true); + void _listenToFavoritesOnline() { + _favoritesSubscription?.cancel(); + final favs = StorageService.instance.favorites; + if (favs.isEmpty) return; - try { - String playerName = StorageService.instance.playerName; - if (playerName.isEmpty) playerName = "HOST"; + List favUids = favs.map((f) => f['uid']!).toList(); + if (favUids.length > 10) favUids = favUids.sublist(0, 10); - String code = await _multiplayerService.createGameRoom( - _selectedRadius, playerName, _selectedShape.name, _isTimeMode, isPublic: _isPublicRoom - ); - - if (!mounted) return; - setState(() { _myRoomCode = code; _isLoading = false; _roomStarted = false; }); - - if (!_isPublicRoom) { - _multiplayerService.shareInviteLink(code); + _favoritesSubscription = FirebaseFirestore.instance + .collection('leaderboard') + .where(FieldPath.documentId, whereIn: favUids) + .snapshots() + .listen((snapshot) { + for (var change in snapshot.docChanges) { + if (change.type == DocumentChangeType.modified || change.type == DocumentChangeType.added) { + var data = change.doc.data(); + if (data != null && data['lastActive'] != null) { + Timestamp lastActive = data['lastActive']; + if (DateTime.now().difference(lastActive.toDate()).inSeconds < 15) { + String name = data['name'] ?? 'Un amico'; + _showFavoriteOnlinePopup(name); + } + } + } } - _showWaitingDialog(code); - } catch (e) { - if (mounted) { setState(() => _isLoading = false); _showError("Errore durante la creazione della partita."); } + }); + } + + void _showFavoriteOnlinePopup(String name) { + if (_lastOnlineNotifications.containsKey(name)) { + if (DateTime.now().difference(_lastOnlineNotifications[name]!).inMinutes < 5) return; } + _lastOnlineNotifications[name] = DateTime.now(); + + final overlay = Overlay.of(context); + late OverlayEntry entry; + bool removed = false; + + entry = OverlayEntry( + builder: (context) => Positioned( + top: MediaQuery.of(context).padding.top + 15, + left: 20, + right: 20, + child: FavoriteOnlinePopup( + name: name, + onDismiss: () { + if (!removed) { + removed = true; + entry.remove(); + } + }, + ), + ), + ); + overlay.insert(entry); } Future _joinRoomByCode(String code) async { if (_isLoading) return; FocusScope.of(context).unfocus(); - - code = code.trim().toUpperCase(); - if (code.isEmpty || code.length != 5) { _showError("Inserisci un codice valido di 5 caratteri."); return; } - setState(() => _isLoading = true); try { @@ -196,554 +225,18 @@ class _HomeScreenState extends State with WidgetsBindingObserver { bool hostTimeMode = roomData['timeMode'] ?? true; context.read().startNewGame(hostRadius, isOnline: true, roomCode: code, isHost: false, shape: hostShape, timeMode: hostTimeMode); - Navigator.pushReplacement(context, MaterialPageRoute(builder: (_) => const GameScreen())); + Navigator.pushReplacement(context, MaterialPageRoute(builder: (_) => GameScreen())); } else { - _showError("Stanza non trovata, piena o partita già iniziata."); + ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("Stanza non trovata, piena o partita già iniziata.", style: TextStyle(color: Colors.white)), backgroundColor: Colors.red)); } } catch (e) { - if (mounted) { setState(() => _isLoading = false); _showError("Errore di connessione: $e"); } + if (mounted) { + setState(() => _isLoading = false); + ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Errore di connessione: $e", style: const TextStyle(color: Colors.white)), backgroundColor: Colors.red)); + } } } - void _showError(String message) { ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message, style: const TextStyle(color: Colors.white)), backgroundColor: Colors.red)); } - - void _showWaitingDialog(String code) { - showDialog( - context: context, - barrierDismissible: false, - builder: (context) { - final theme = context.watch().currentColors; - final themeType = context.read().currentThemeType; - - Widget dialogContent = Column( - mainAxisSize: MainAxisSize.min, - children: [ - CircularProgressIndicator(color: theme.playerRed), const SizedBox(height: 25), - Text("CODICE STANZA", style: getSharedTextStyle(themeType, TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: theme.text.withOpacity(0.6), letterSpacing: 2))), - Text(code, style: getSharedTextStyle(themeType, TextStyle(fontSize: 40, fontWeight: FontWeight.w900, color: theme.playerRed, letterSpacing: 8, shadows: themeType == AppThemeType.doodle ? [] : [Shadow(color: theme.playerRed.withOpacity(0.5), blurRadius: 10)]))), - const SizedBox(height: 25), - Transform.rotate( - angle: themeType == AppThemeType.doodle ? 0.02 : 0, - child: Container( - padding: const EdgeInsets.all(18), - decoration: BoxDecoration( - color: themeType == AppThemeType.doodle ? Colors.white : theme.text.withOpacity(0.05), - borderRadius: BorderRadius.circular(20), - border: Border.all(color: themeType == AppThemeType.doodle ? theme.text : theme.playerBlue.withOpacity(0.3), width: themeType == AppThemeType.doodle ? 2 : 1.5), - boxShadow: themeType == AppThemeType.doodle - ? [BoxShadow(color: theme.text.withOpacity(0.8), offset: const Offset(4, 4))] - : [BoxShadow(color: theme.playerBlue.withOpacity(0.1), blurRadius: 10)] - ), - child: Column( - children: [ - Icon(_isPublicRoom ? Icons.podcasts : Icons.share, color: theme.playerBlue, size: 32), const SizedBox(height: 12), - Text(_isPublicRoom ? "Sei in Bacheca!" : "Invita un amico", textAlign: TextAlign.center, style: getSharedTextStyle(themeType, TextStyle(color: theme.text, fontWeight: FontWeight.w900, fontSize: 18))), - const SizedBox(height: 8), - Text(_isPublicRoom ? "Aspettiamo che uno sfidante si unisca dalla lobby pubblica." : "Condividi il codice. La partita inizierà appena si unirà.", textAlign: TextAlign.center, style: getSharedTextStyle(themeType, TextStyle(color: themeType == AppThemeType.doodle ? theme.text : theme.text.withOpacity(0.8), fontSize: 14, height: 1.5))), - ], - ), - ), - ), - ], - ); - - if (themeType == AppThemeType.cyberpunk || themeType == AppThemeType.music) { - dialogContent = AnimatedCyberBorder(child: dialogContent); - } else { - dialogContent = Container( - padding: const EdgeInsets.all(20), - decoration: BoxDecoration( - color: themeType == AppThemeType.doodle ? Colors.white.withOpacity(0.95) : theme.background, - borderRadius: BorderRadius.circular(25), - border: Border.all(color: themeType == AppThemeType.doodle ? theme.text : theme.gridLine.withOpacity(0.5), width: 2), - boxShadow: themeType == AppThemeType.doodle ? [BoxShadow(color: theme.text.withOpacity(0.6), offset: const Offset(8, 8))] : [] - ), - child: dialogContent - ); - } - - return StreamBuilder( - stream: _multiplayerService.listenToRoom(code), - builder: (context, snapshot) { - if (snapshot.hasData && snapshot.data!.exists) { - var data = snapshot.data!.data() as Map; - if (data['status'] == 'playing') { - _roomStarted = true; - WidgetsBinding.instance.addPostFrameCallback((_) { - Navigator.pop(context); - context.read().startNewGame(_selectedRadius, isOnline: true, roomCode: code, isHost: true, shape: _selectedShape, timeMode: _isTimeMode); - Navigator.pushReplacement(context, MaterialPageRoute(builder: (_) => const GameScreen())); - }); - } - } - - return PopScope( - canPop: false, - onPopInvoked: (didPop) { - if (didPop) return; - _cleanupGhostRoom(); - Navigator.pop(context); - }, - child: Dialog( - backgroundColor: Colors.transparent, - insetPadding: const EdgeInsets.all(20), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - dialogContent, - const SizedBox(height: 20), - TextButton( - onPressed: () { - _cleanupGhostRoom(); - Navigator.pop(context); - }, - child: Text("ANNULLA", style: getSharedTextStyle(themeType, TextStyle(color: Colors.red, fontWeight: FontWeight.w900, fontSize: 20, letterSpacing: 2.0, shadows: themeType == AppThemeType.doodle ? [] : [const Shadow(color: Colors.black, blurRadius: 2)]))), - ), - ], - ), - ), - ); - }, - ); - } - ); - } - - void _promptJoinRoom(String roomCode) { - showDialog( - context: context, - builder: (context) { - final theme = context.watch().currentColors; - final themeType = context.read().currentThemeType; - return AlertDialog( - backgroundColor: themeType == AppThemeType.doodle ? Colors.white : theme.background, - shape: themeType == AppThemeType.doodle ? RoundedRectangleBorder(borderRadius: BorderRadius.circular(15), side: BorderSide(color: theme.text, width: 2)) : null, - title: Text("Invito Trovato!", style: getSharedTextStyle(themeType, TextStyle(color: theme.text, fontWeight: FontWeight.bold))), - content: Text("Vuoi unirti alla stanza $roomCode?", style: getSharedTextStyle(themeType, TextStyle(color: theme.text))), - actions: [ - TextButton(onPressed: () => Navigator.pop(context), child: Text("No", style: getSharedTextStyle(themeType, const TextStyle(color: Colors.red)))), - ElevatedButton( - style: ElevatedButton.styleFrom(backgroundColor: themeType == AppThemeType.doodle ? Colors.transparent : theme.playerBlue, elevation: 0, side: themeType == AppThemeType.doodle ? BorderSide(color: theme.text, width: 1.5) : BorderSide.none), - onPressed: () { - Navigator.of(context).pop(); - _joinRoomByCode(roomCode); - }, - child: Text(AppLocalizations.of(context)!.joinMatch, style: getSharedTextStyle(themeType, TextStyle(color: themeType == AppThemeType.doodle ? theme.text : Colors.white, fontWeight: FontWeight.bold))), - ), - ], - ); - } - ); - } - - void _showNameDialog() { - final TextEditingController nameController = TextEditingController(text: StorageService.instance.playerName); - final TextEditingController passController = TextEditingController(); - bool isLoadingAuth = false; - bool _obscurePassword = true; - String _errorMessage = ""; - - showDialog( - context: context, barrierDismissible: false, barrierColor: Colors.black.withOpacity(0.8), - builder: (context) { - final themeManager = context.watch(); - final theme = themeManager.currentColors; final themeType = themeManager.currentThemeType; - Color inkColor = const Color(0xFF111122); final loc = AppLocalizations.of(context)!; - - return StatefulBuilder( - builder: (context, setStateDialog) { - - Future handleAuth(bool isLogin) async { - final name = nameController.text.trim(); - final password = passController.text.trim(); - - setStateDialog(() { - _errorMessage = ""; - isLoadingAuth = true; - }); - - if (name.isEmpty || password.isEmpty) { - setStateDialog(() { - _errorMessage = "Inserisci Nome e Password!"; - isLoadingAuth = false; - }); - return; - } - if (password.length < 6) { - setStateDialog(() { - _errorMessage = "La password deve avere almeno 6 caratteri!"; - isLoadingAuth = false; - }); - return; - } - - final fakeEmail = "${name.toLowerCase().replaceAll(' ', '')}@tetraq.game"; - - try { - if (isLogin) { - await FirebaseAuth.instance.signInWithEmailAndPassword(email: fakeEmail, password: password); - final doc = await FirebaseFirestore.instance.collection('leaderboard').doc(FirebaseAuth.instance.currentUser!.uid).get(); - if (doc.exists) { - final data = doc.data() as Map; - final prefs = await SharedPreferences.getInstance(); - await prefs.setInt('totalXP', data['xp'] ?? 0); - await prefs.setInt('wins', data['wins'] ?? 0); - await prefs.setInt('losses', data['losses'] ?? 0); - } - if (mounted) ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Bentornato $name! Dati sincronizzati."), backgroundColor: Colors.green)); - } else { - await FirebaseAuth.instance.createUserWithEmailAndPassword(email: fakeEmail, password: password); - if (mounted) ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("Account creato con successo!"), backgroundColor: Colors.green)); - } - - await StorageService.instance.savePlayerName(name); - if (mounted) Navigator.of(context).pop(); - setState(() {}); - - } on FirebaseAuthException catch (e) { - String msg = "Errore di autenticazione."; - if (e.code == 'email-already-in-use') { - msg = "Nome occupato!\nSe è il tuo account, clicca su ACCEDI."; - } else if (e.code == 'user-not-found' || e.code == 'wrong-password' || e.code == 'invalid-credential') { - msg = "Nome o Password errati!"; - } - setStateDialog(() { - _errorMessage = msg; - isLoadingAuth = false; - }); - } catch (e) { - setStateDialog(() { - _errorMessage = "Errore imprevisto: $e"; - isLoadingAuth = false; - }); - } - } - - Widget dialogContent = themeType == AppThemeType.doodle - ? CustomPaint( - painter: DoodleBackgroundPainter(fillColor: Colors.yellow.shade100, strokeColor: inkColor, seed: 100), - child: SingleChildScrollView( - physics: const BouncingScrollPhysics(), - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 20.0, horizontal: 20.0), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text(loc.welcomeTitle, style: getSharedTextStyle(themeType, TextStyle(color: inkColor, fontWeight: FontWeight.w900, fontSize: 24, letterSpacing: 2.0)), textAlign: TextAlign.center), - const SizedBox(height: 10), - Text('Scegli Nome e Password.\nTi serviranno per recuperare gli XP!', style: getSharedTextStyle(themeType, TextStyle(color: inkColor.withOpacity(0.8), fontSize: 13)), textAlign: TextAlign.center), - const SizedBox(height: 15), - TextField( - controller: nameController, textCapitalization: TextCapitalization.characters, textAlign: TextAlign.center, maxLength: 8, - style: getSharedTextStyle(themeType, TextStyle(color: inkColor, fontSize: 24, fontWeight: FontWeight.bold, letterSpacing: 4)), - decoration: InputDecoration( - hintText: loc.nameHint, - hintStyle: getSharedTextStyle(themeType, TextStyle(color: inkColor.withOpacity(0.3), letterSpacing: 4)), - filled: false, counterText: "", - enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: inkColor, width: 3)), - focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.red.shade200, width: 5)) - ), - ), - const SizedBox(height: 8), - TextField( - controller: passController, obscureText: _obscurePassword, textAlign: TextAlign.center, maxLength: 20, - style: getSharedTextStyle(themeType, TextStyle(color: inkColor, fontSize: 20, fontWeight: FontWeight.bold, letterSpacing: 8)), - decoration: InputDecoration( - hintText: "PASSWORD", - hintStyle: getSharedTextStyle(themeType, TextStyle(color: inkColor.withOpacity(0.3), letterSpacing: 4)), - filled: false, counterText: "", - enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: inkColor, width: 3)), - focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.red.shade200, width: 5)), - suffixIcon: IconButton( - icon: Icon(_obscurePassword ? Icons.visibility : Icons.visibility_off, color: inkColor.withOpacity(0.6)), - onPressed: () { setStateDialog(() { _obscurePassword = !_obscurePassword; }); }, - ), - ), - ), - const SizedBox(height: 15), - - if (_errorMessage.isNotEmpty) - Padding( - padding: const EdgeInsets.only(bottom: 10), - child: Text(_errorMessage, style: getSharedTextStyle(themeType, const TextStyle(color: Colors.red, fontSize: 14, fontWeight: FontWeight.bold)), textAlign: TextAlign.center), - ), - - Text("💡 Nota: Non serve una vera email. Usa una password facile da ricordare!", style: getSharedTextStyle(themeType, TextStyle(color: inkColor.withOpacity(0.6), fontSize: 11, height: 1.3)), textAlign: TextAlign.center), - const SizedBox(height: 15), - isLoadingAuth - ? CircularProgressIndicator(color: inkColor) - : Row( - children: [ - Expanded( - child: GestureDetector( - onTap: () => handleAuth(true), - child: CustomPaint( - painter: DoodleBackgroundPainter(fillColor: Colors.blue.shade200, strokeColor: inkColor, seed: 101), - child: Container(height: 45, alignment: Alignment.center, child: Text("ACCEDI", style: getSharedTextStyle(themeType, TextStyle(color: inkColor, fontSize: 14, fontWeight: FontWeight.bold, letterSpacing: 1.5)))), - ), - ), - ), - const SizedBox(width: 10), - Expanded( - child: GestureDetector( - onTap: () => handleAuth(false), - child: CustomPaint( - painter: DoodleBackgroundPainter(fillColor: Colors.green.shade200, strokeColor: inkColor, seed: 102), - child: Container(height: 45, alignment: Alignment.center, child: Text("REGISTRATI", style: getSharedTextStyle(themeType, TextStyle(color: inkColor, fontSize: 14, fontWeight: FontWeight.bold, letterSpacing: 1.5)))), - ), - ), - ), - ], - ), - ], - ), - ), - ), - ) - : Container( - decoration: BoxDecoration(color: theme.background, borderRadius: BorderRadius.circular(25), border: Border.all(color: theme.playerBlue.withOpacity(0.5), width: 2), boxShadow: [BoxShadow(color: theme.playerBlue.withOpacity(0.3), blurRadius: 20, spreadRadius: 5)]), - child: SingleChildScrollView( - physics: const BouncingScrollPhysics(), - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 20.0, horizontal: 20.0), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text(loc.welcomeTitle, style: getSharedTextStyle(themeType, TextStyle(color: theme.text, fontWeight: FontWeight.w900, fontSize: 20, letterSpacing: 1.5)), textAlign: TextAlign.center), - const SizedBox(height: 10), - Text('Scegli Nome e Password.\nTi serviranno per recuperare gli XP!', style: getSharedTextStyle(themeType, TextStyle(color: theme.text.withOpacity(0.8), fontSize: 13)), textAlign: TextAlign.center), - const SizedBox(height: 15), - TextField( - controller: nameController, textCapitalization: TextCapitalization.characters, textAlign: TextAlign.center, maxLength: 8, - style: getSharedTextStyle(themeType, TextStyle(color: theme.text, fontSize: 24, fontWeight: FontWeight.bold, letterSpacing: 4)), - decoration: InputDecoration( - hintText: loc.nameHint, - hintStyle: getSharedTextStyle(themeType, TextStyle(color: theme.text.withOpacity(0.3), letterSpacing: 4)), - filled: true, fillColor: theme.text.withOpacity(0.05), counterText: "", - enabledBorder: OutlineInputBorder(borderSide: BorderSide(color: theme.gridLine.withOpacity(0.5), width: 2), borderRadius: BorderRadius.circular(15)), - focusedBorder: OutlineInputBorder(borderSide: BorderSide(color: theme.playerBlue, width: 3), borderRadius: BorderRadius.circular(15)) - ), - ), - const SizedBox(height: 10), - TextField( - controller: passController, obscureText: _obscurePassword, textAlign: TextAlign.center, maxLength: 20, - style: getSharedTextStyle(themeType, TextStyle(color: theme.text, fontSize: 20, fontWeight: FontWeight.bold, letterSpacing: 8)), - decoration: InputDecoration( - hintText: "PASSWORD", - hintStyle: getSharedTextStyle(themeType, TextStyle(color: theme.text.withOpacity(0.3), letterSpacing: 4)), - filled: true, fillColor: theme.text.withOpacity(0.05), counterText: "", - enabledBorder: OutlineInputBorder(borderSide: BorderSide(color: theme.gridLine.withOpacity(0.5), width: 2), borderRadius: BorderRadius.circular(15)), - focusedBorder: OutlineInputBorder(borderSide: BorderSide(color: theme.playerBlue, width: 3), borderRadius: BorderRadius.circular(15)), - suffixIcon: IconButton( - icon: Icon(_obscurePassword ? Icons.visibility : Icons.visibility_off, color: theme.text.withOpacity(0.6)), - onPressed: () { setStateDialog(() { _obscurePassword = !_obscurePassword; }); }, - ), - ), - ), - const SizedBox(height: 15), - - if (_errorMessage.isNotEmpty) - Padding( - padding: const EdgeInsets.only(bottom: 10), - child: Text(_errorMessage, style: getSharedTextStyle(themeType, const TextStyle(color: Colors.redAccent, fontSize: 14, fontWeight: FontWeight.bold)), textAlign: TextAlign.center), - ), - - Text("💡 Nota: Non serve una vera email. Usa una password facile da ricordare!", style: getSharedTextStyle(themeType, TextStyle(color: theme.text.withOpacity(0.6), fontSize: 11, height: 1.3)), textAlign: TextAlign.center), - const SizedBox(height: 20), - isLoadingAuth - ? CircularProgressIndicator(color: theme.playerBlue) - : Row( - children: [ - Expanded( - child: SizedBox( - height: 45, - child: ElevatedButton( - style: ElevatedButton.styleFrom(backgroundColor: theme.text.withOpacity(0.1), foregroundColor: theme.text, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)), side: BorderSide(color: theme.playerBlue, width: 1.5)), - onPressed: () => handleAuth(true), - child: Text("ACCEDI", style: getSharedTextStyle(themeType, const TextStyle(fontSize: 13, fontWeight: FontWeight.bold, letterSpacing: 1.0))), - ), - ), - ), - const SizedBox(width: 10), - Expanded( - child: SizedBox( - height: 45, - child: ElevatedButton( - style: ElevatedButton.styleFrom(backgroundColor: theme.playerBlue, foregroundColor: Colors.white, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15))), - onPressed: () => handleAuth(false), - child: Text("REGISTRATI", style: getSharedTextStyle(themeType, const TextStyle(fontSize: 13, fontWeight: FontWeight.bold, letterSpacing: 1.0))), - ), - ), - ), - ], - ), - ], - ), - ), - ), - ); - - if (themeType == AppThemeType.cyberpunk || themeType == AppThemeType.music) dialogContent = AnimatedCyberBorder(child: dialogContent); - return Dialog(backgroundColor: Colors.transparent, insetPadding: const EdgeInsets.all(20), child: dialogContent); - }, - ); - }, - ); - } - - void _showMatchSetupDialog(bool isVsCPU) { - int localRadius = 4; ArenaShape localShape = ArenaShape.classic; bool localTimeMode = true; - bool isChaosUnlocked = StorageService.instance.playerLevel >= 7; - final loc = AppLocalizations.of(context)!; - - showDialog( - context: context, barrierColor: Colors.black.withOpacity(0.8), - builder: (ctx) { - final themeManager = ctx.watch(); - final theme = themeManager.currentColors; final themeType = themeManager.currentThemeType; - Color inkColor = const Color(0xFF111122); - - return StatefulBuilder( - builder: (context, setStateDialog) { - Widget dialogContent = themeType == AppThemeType.doodle - ? Transform.rotate( - angle: 0.015, - child: CustomPaint( - painter: DoodleBackgroundPainter(fillColor: Colors.white.withOpacity(0.95), strokeColor: inkColor, seed: 200), - child: SingleChildScrollView( - physics: const BouncingScrollPhysics(), - child: Padding( - padding: const EdgeInsets.all(25.0), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Row(children: [ SizedBox(width: 40, child: IconButton(padding: EdgeInsets.zero, alignment: Alignment.centerLeft, icon: Icon(Icons.arrow_back_ios_new, color: inkColor, size: 26), onPressed: () => Navigator.pop(ctx))), Expanded(child: Text(isVsCPU ? loc.cpuTitle : loc.localTitle, textAlign: TextAlign.center, style: getSharedTextStyle(themeType, TextStyle(fontSize: 26, fontWeight: FontWeight.w900, color: inkColor, letterSpacing: 2)))), const SizedBox(width: 40) ]), - const SizedBox(height: 25), - - if (isVsCPU) ...[ - Icon(Icons.smart_toy, size: 50, color: inkColor.withOpacity(0.6)), const SizedBox(height: 10), - Text("MODALITÀ CAMPAGNA", style: getSharedTextStyle(themeType, TextStyle(fontSize: 16, fontWeight: FontWeight.w900, color: inkColor))), const SizedBox(height: 10), - Text("Livello CPU: ${StorageService.instance.cpuLevel}\nForma e dimensioni si adatteranno alla tua bravura!", textAlign: TextAlign.center, style: getSharedTextStyle(themeType, TextStyle(fontSize: 13, color: inkColor.withOpacity(0.8), height: 1.4))), const SizedBox(height: 25), - Divider(color: inkColor.withOpacity(0.3), thickness: 2.5), const SizedBox(height: 20), - ] else ...[ - Text("FORMA ARENA", style: getSharedTextStyle(themeType, TextStyle(fontSize: 14, fontWeight: FontWeight.w900, color: inkColor.withOpacity(0.6), letterSpacing: 1.5))), const SizedBox(height: 15), - Wrap( - spacing: 12, runSpacing: 12, alignment: WrapAlignment.center, - children: [ - NeonShapeButton(icon: Icons.diamond_outlined, label: 'Rombo', isSelected: localShape == ArenaShape.classic, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.classic)), - NeonShapeButton(icon: Icons.add, label: 'Croce', isSelected: localShape == ArenaShape.cross, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.cross)), - NeonShapeButton(icon: Icons.donut_large, label: 'Buco', isSelected: localShape == ArenaShape.donut, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.donut)), - NeonShapeButton(icon: Icons.hourglass_bottom, label: 'Clessidra', isSelected: localShape == ArenaShape.hourglass, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.hourglass)), - NeonShapeButton(icon: Icons.all_inclusive, label: 'Caos', isSelected: localShape == ArenaShape.chaos, theme: theme, themeType: themeType, isSpecial: true, isLocked: !isChaosUnlocked, onTap: () => setStateDialog(() => localShape = ArenaShape.chaos)), - ], - ), - const SizedBox(height: 25), Divider(color: inkColor.withOpacity(0.3), thickness: 2.5), const SizedBox(height: 20), - - Text("GRANDEZZA", style: getSharedTextStyle(themeType, TextStyle(fontSize: 14, fontWeight: FontWeight.w900, color: inkColor.withOpacity(0.6), letterSpacing: 1.5))), const SizedBox(height: 15), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - NeonSizeButton(label: 'S', isSelected: localRadius == 3, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 3)), - NeonSizeButton(label: 'M', isSelected: localRadius == 4, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 4)), - NeonSizeButton(label: 'L', isSelected: localRadius == 5, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 5)), - NeonSizeButton(label: 'MAX', isSelected: localRadius == 6, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 6)), - ], - ), - const SizedBox(height: 25), Divider(color: inkColor.withOpacity(0.3), thickness: 2.5), const SizedBox(height: 20), - ], - - Text("TEMPO", style: getSharedTextStyle(themeType, TextStyle(fontSize: 14, fontWeight: FontWeight.w900, color: inkColor.withOpacity(0.6), letterSpacing: 1.5))), const SizedBox(height: 10), - NeonTimeSwitch(isTimeMode: localTimeMode, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localTimeMode = !localTimeMode)), const SizedBox(height: 35), - - Transform.rotate( - angle: -0.02, - child: GestureDetector( - onTap: () { Navigator.pop(ctx); context.read().startNewGame(localRadius, vsCPU: isVsCPU, shape: localShape, timeMode: localTimeMode); Navigator.push(context, MaterialPageRoute(builder: (_) => const GameScreen())); }, - child: CustomPaint(painter: DoodleBackgroundPainter(fillColor: Colors.green.shade200, strokeColor: inkColor, seed: 300), child: Container(height: 65, width: double.infinity, alignment: Alignment.center, child: Text(loc.startGame, style: getSharedTextStyle(themeType, TextStyle(fontSize: 22, fontWeight: FontWeight.w900, letterSpacing: 3.0, color: inkColor))))), - ), - ) - ], - ), - ), - ), - ), - ) - : Container( - decoration: BoxDecoration( - gradient: LinearGradient(begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [theme.background.withOpacity(0.95), theme.background.withOpacity(0.8)]), - borderRadius: BorderRadius.circular(25), border: themeType == AppThemeType.cyberpunk || themeType == AppThemeType.arcade || themeType == AppThemeType.music ? null : Border.all(color: Colors.white.withOpacity(0.15), width: 1.5), - boxShadow: themeType == AppThemeType.cyberpunk || themeType == AppThemeType.arcade || themeType == AppThemeType.music ? [] : [BoxShadow(color: Colors.black.withOpacity(0.5), blurRadius: 20, offset: const Offset(4, 10))], - ), - child: SingleChildScrollView( - physics: const BouncingScrollPhysics(), - child: Padding( - padding: const EdgeInsets.all(20.0), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Row(children: [ SizedBox(width: 40, child: IconButton(padding: EdgeInsets.zero, alignment: Alignment.centerLeft, icon: Icon(Icons.arrow_back_ios_new, color: theme.text, size: 26), onPressed: () => Navigator.pop(ctx))), Expanded(child: Text(isVsCPU ? loc.cpuTitle : loc.localTitle, textAlign: TextAlign.center, style: getSharedTextStyle(themeType, TextStyle(fontSize: 24, fontWeight: FontWeight.w900, color: theme.text, letterSpacing: 2)))), const SizedBox(width: 40) ]), - const SizedBox(height: 20), - - if (isVsCPU) ...[ - Icon(Icons.smart_toy, size: 50, color: theme.playerBlue), const SizedBox(height: 10), - Text("MODALITÀ CAMPAGNA", style: getSharedTextStyle(themeType, TextStyle(fontSize: 16, fontWeight: FontWeight.w900, color: theme.text, letterSpacing: 1.5))), const SizedBox(height: 10), - Text("Livello CPU: ${StorageService.instance.cpuLevel}\nForma e dimensioni si adatteranno alla tua bravura!", textAlign: TextAlign.center, style: getSharedTextStyle(themeType, TextStyle(fontSize: 13, color: theme.text.withOpacity(0.7), height: 1.4))), const SizedBox(height: 20), - Divider(color: Colors.white.withOpacity(0.05), thickness: 2), const SizedBox(height: 20), - ] else ...[ - Text("FORMA ARENA", style: getSharedTextStyle(themeType, TextStyle(fontSize: 12, fontWeight: FontWeight.w900, color: theme.text.withOpacity(0.5), letterSpacing: 1.5))), const SizedBox(height: 10), - Wrap( - spacing: 10, runSpacing: 10, alignment: WrapAlignment.center, - children: [ - NeonShapeButton(icon: Icons.diamond_outlined, label: 'Rombo', isSelected: localShape == ArenaShape.classic, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.classic)), - NeonShapeButton(icon: Icons.add, label: 'Croce', isSelected: localShape == ArenaShape.cross, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.cross)), - NeonShapeButton(icon: Icons.donut_large, label: 'Buco', isSelected: localShape == ArenaShape.donut, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.donut)), - NeonShapeButton(icon: Icons.hourglass_bottom, label: 'Clessidra', isSelected: localShape == ArenaShape.hourglass, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localShape = ArenaShape.hourglass)), - NeonShapeButton(icon: Icons.all_inclusive, label: 'Caos', isSelected: localShape == ArenaShape.chaos, theme: theme, themeType: themeType, isSpecial: true, isLocked: !isChaosUnlocked, onTap: () => setStateDialog(() => localShape = ArenaShape.chaos)), - ], - ), - const SizedBox(height: 20), Divider(color: Colors.white.withOpacity(0.05), thickness: 2), const SizedBox(height: 20), - - Text("GRANDEZZA", style: getSharedTextStyle(themeType, TextStyle(fontSize: 12, fontWeight: FontWeight.w900, color: theme.text.withOpacity(0.5), letterSpacing: 1.5))), const SizedBox(height: 10), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - NeonSizeButton(label: 'S', isSelected: localRadius == 3, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 3)), - NeonSizeButton(label: 'M', isSelected: localRadius == 4, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 4)), - NeonSizeButton(label: 'L', isSelected: localRadius == 5, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 5)), - NeonSizeButton(label: 'MAX', isSelected: localRadius == 6, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localRadius = 6)), - ], - ), - const SizedBox(height: 20), Divider(color: Colors.white.withOpacity(0.05), thickness: 2), const SizedBox(height: 20), - ], - - Text("TEMPO", style: getSharedTextStyle(themeType, TextStyle(fontSize: 12, fontWeight: FontWeight.w900, color: theme.text.withOpacity(0.5), letterSpacing: 1.5))), const SizedBox(height: 10), - NeonTimeSwitch(isTimeMode: localTimeMode, theme: theme, themeType: themeType, onTap: () => setStateDialog(() => localTimeMode = !localTimeMode)), const SizedBox(height: 30), - - SizedBox( - width: double.infinity, height: 60, - child: ElevatedButton( - style: ElevatedButton.styleFrom(backgroundColor: isVsCPU ? Colors.purple.shade400 : theme.playerRed, foregroundColor: Colors.white, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))), - onPressed: () { Navigator.pop(ctx); context.read().startNewGame(localRadius, vsCPU: isVsCPU, shape: localShape, timeMode: localTimeMode); Navigator.push(context, MaterialPageRoute(builder: (_) => const GameScreen())); }, - child: Text(loc.startGame, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w900, letterSpacing: 2)), - ), - ) - ], - ), - ), - ), - ); - - if (themeType == AppThemeType.cyberpunk || themeType == AppThemeType.music) { - dialogContent = AnimatedCyberBorder(child: dialogContent); - } - - return Dialog(backgroundColor: Colors.transparent, insetPadding: const EdgeInsets.symmetric(horizontal: 15, vertical: 20), child: dialogContent); - }, - ); - } - ); - } - BoxDecoration _glassBoxDecoration(ThemeColors theme, AppThemeType themeType) { return BoxDecoration( color: themeType == AppThemeType.doodle ? Colors.white : null, @@ -776,7 +269,7 @@ class _HomeScreenState extends State with WidgetsBindingObserver { crossAxisAlignment: CrossAxisAlignment.start, children: [ GestureDetector( - onTap: _showNameDialog, + onTap: () => HomeModals.showNameDialog(context, () => setState(() {})), child: Container( padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), decoration: _glassBoxDecoration(theme, themeType), @@ -793,8 +286,15 @@ class _HomeScreenState extends State with WidgetsBindingObserver { crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ - Text(playerName.toUpperCase(), style: getSharedTextStyle(themeType, TextStyle(color: themeType == AppThemeType.doodle ? inkColor : theme.text, fontWeight: FontWeight.bold, fontSize: 16))), - Text("LIV. $playerLevel", style: getSharedTextStyle(themeType, TextStyle(color: themeType == AppThemeType.doodle ? inkColor.withOpacity(0.8) : theme.playerBlue, fontWeight: FontWeight.bold, fontSize: 11))), + // Proteggiamo anche nome e livello + Text( + "\u00A0${playerName.toUpperCase()}\u00A0\u00A0", + style: getSharedTextStyle(themeType, TextStyle(color: themeType == AppThemeType.doodle ? inkColor : theme.text, fontWeight: FontWeight.bold, fontSize: 16, letterSpacing: 1.0)), + ), + Text( + "\u00A0LIV. $playerLevel\u00A0\u00A0", + style: getSharedTextStyle(themeType, TextStyle(color: themeType == AppThemeType.doodle ? inkColor.withOpacity(0.8) : theme.playerBlue, fontWeight: FontWeight.bold, fontSize: 11, letterSpacing: 1.0)), + ), ], ), ], @@ -802,23 +302,44 @@ class _HomeScreenState extends State with WidgetsBindingObserver { ), ), + // --- BOX STATISTICHE BLINDATO --- Container( - padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12), + padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10), // Padding compensato decoration: _glassBoxDecoration(theme, themeType), child: Row( mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, children: [ Icon(themeType == AppThemeType.music ? FontAwesomeIcons.microphone : Icons.emoji_events, color: Colors.amber.shade600, size: 16), - const SizedBox(width: 6), - Text("${StorageService.instance.wins}", style: getSharedTextStyle(themeType, TextStyle(color: themeType == AppThemeType.doodle ? inkColor : theme.text, fontWeight: FontWeight.w900))), - const SizedBox(width: 12), - Icon(themeType == AppThemeType.music ? FontAwesomeIcons.compactDisc : Icons.sentiment_very_dissatisfied, color: theme.playerRed.withOpacity(0.8), size: 16), - const SizedBox(width: 6), - Text("${StorageService.instance.losses}", style: getSharedTextStyle(themeType, TextStyle(color: themeType == AppThemeType.doodle ? inkColor : theme.text, fontWeight: FontWeight.w900))), - const SizedBox(width: 12), + // Doppio spazio invisibile \u00A0\u00A0 e letterSpacing per salvare la pancia a destra! + Text( + "\u00A0${StorageService.instance.wins}\u00A0\u00A0", + style: getSharedTextStyle(themeType, TextStyle( + color: themeType == AppThemeType.doodle ? inkColor : theme.text, + fontWeight: FontWeight.w900, + fontSize: 16, + letterSpacing: 2.0, // Forza ulteriore spazio orizzontale + )), + ), + + const SizedBox(width: 4), + Icon(themeType == AppThemeType.music ? FontAwesomeIcons.compactDisc : Icons.sentiment_very_dissatisfied, color: theme.playerRed.withOpacity(0.8), size: 16), + + // Idem per le sconfitte + Text( + "\u00A0${StorageService.instance.losses}\u00A0\u00A0", + style: getSharedTextStyle(themeType, TextStyle( + color: themeType == AppThemeType.doodle ? inkColor : theme.text, + fontWeight: FontWeight.w900, + fontSize: 16, + letterSpacing: 2.0, + )), + ), + + const SizedBox(width: 4), Container(width: 1, height: 20, color: (themeType == AppThemeType.doodle ? inkColor : Colors.white).withOpacity(0.2)), - const SizedBox(width: 12), + const SizedBox(width: 10), AnimatedBuilder( animation: AudioService.instance, @@ -904,14 +425,15 @@ class _HomeScreenState extends State with WidgetsBindingObserver { ); } else if (_debugTapCount >= 7) { _debugTapCount = 0; - Navigator.push(context, MaterialPageRoute(builder: (_) => const AdminScreen())); + Navigator.push(context, MaterialPageRoute(builder: (_) => AdminScreen())); } } }, child: FittedBox( fit: BoxFit.scaleDown, + // IL TRUCCO: Spazio vuoto anche nel titolo principale child: Text( - loc.appTitle.toUpperCase(), + "${loc.appTitle.toUpperCase()} ", style: getSharedTextStyle(themeType, TextStyle( fontSize: 65 * vScale, fontWeight: FontWeight.w900, @@ -929,18 +451,18 @@ class _HomeScreenState extends State with WidgetsBindingObserver { SizedBox(height: 40 * vScale), if (themeType == AppThemeType.music) ...[ - MusicCassetteCard(title: loc.onlineTitle, subtitle: loc.onlineSub, neonColor: Colors.blueAccent, angle: -0.04, leftIcon: FontAwesomeIcons.sliders, rightIcon: FontAwesomeIcons.globe, themeType: themeType, onTap: () { Navigator.push(context, MaterialPageRoute(builder: (_) => const LobbyScreen())); }), + MusicCassetteCard(title: loc.onlineTitle, subtitle: loc.onlineSub, neonColor: Colors.blueAccent, angle: -0.04, leftIcon: FontAwesomeIcons.sliders, rightIcon: FontAwesomeIcons.globe, themeType: themeType, onTap: () { Navigator.push(context, MaterialPageRoute(builder: (_) => LobbyScreen())); }), SizedBox(height: 12 * vScale), - MusicCassetteCard(title: loc.cpuTitle, subtitle: loc.cpuSub, neonColor: Colors.purpleAccent, angle: 0.03, leftIcon: FontAwesomeIcons.desktop, rightIcon: FontAwesomeIcons.music, themeType: themeType, onTap: () => _showMatchSetupDialog(true)), + MusicCassetteCard(title: loc.cpuTitle, subtitle: loc.cpuSub, neonColor: Colors.purpleAccent, angle: 0.03, leftIcon: FontAwesomeIcons.desktop, rightIcon: FontAwesomeIcons.music, themeType: themeType, onTap: () => HomeModals.showMatchSetupDialog(context, true)), SizedBox(height: 12 * vScale), - MusicCassetteCard(title: loc.localTitle, subtitle: loc.localSub, neonColor: Colors.deepPurpleAccent, angle: -0.02, leftIcon: FontAwesomeIcons.headphones, rightIcon: FontAwesomeIcons.headphones, themeType: themeType, onTap: () => _showMatchSetupDialog(false)), + MusicCassetteCard(title: loc.localTitle, subtitle: loc.localSub, neonColor: Colors.deepPurpleAccent, angle: -0.02, leftIcon: FontAwesomeIcons.headphones, rightIcon: FontAwesomeIcons.headphones, themeType: themeType, onTap: () => HomeModals.showMatchSetupDialog(context, false)), SizedBox(height: 30 * vScale), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded(child: MusicKnobCard(title: loc.leaderboardTitle, icon: FontAwesomeIcons.compactDisc, iconColor: Colors.amber, themeType: themeType, onTap: () => showDialog(context: context, builder: (ctx) => const LeaderboardDialog()))), Expanded(child: MusicKnobCard(title: loc.questsTitle, icon: FontAwesomeIcons.microphoneLines, themeType: themeType, onTap: () => showDialog(context: context, builder: (ctx) => const QuestsDialog()))), - Expanded(child: MusicKnobCard(title: loc.themesTitle, icon: FontAwesomeIcons.palette, themeType: themeType, onTap: () => Navigator.push(context, MaterialPageRoute(builder: (_) => const SettingsScreen())))), + Expanded(child: MusicKnobCard(title: loc.themesTitle, icon: FontAwesomeIcons.palette, themeType: themeType, onTap: () => Navigator.push(context, MaterialPageRoute(builder: (_) => SettingsScreen())))), Expanded(child: MusicKnobCard(title: loc.tutorialTitle, icon: FontAwesomeIcons.bookOpen, themeType: themeType, onTap: () => showDialog(context: context, builder: (ctx) => const TutorialDialog()))), ], ), @@ -948,11 +470,11 @@ class _HomeScreenState extends State with WidgetsBindingObserver { Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - _buildCyberCard(FeatureCard(title: loc.onlineTitle, subtitle: loc.onlineSub, icon: Icons.public, color: Colors.lightBlue.shade200, theme: theme, themeType: themeType, isFeatured: true, onTap: () { Navigator.push(context, MaterialPageRoute(builder: (_) => const LobbyScreen())); }), themeType), + _buildCyberCard(FeatureCard(title: loc.onlineTitle, subtitle: loc.onlineSub, icon: Icons.public, color: Colors.lightBlue.shade200, theme: theme, themeType: themeType, isFeatured: true, onTap: () { Navigator.push(context, MaterialPageRoute(builder: (_) => LobbyScreen())); }), themeType), SizedBox(height: 12 * vScale), - _buildCyberCard(FeatureCard(title: loc.cpuTitle, subtitle: loc.cpuSub, icon: Icons.smart_toy, color: Colors.purple.shade200, theme: theme, themeType: themeType, onTap: () => _showMatchSetupDialog(true)), themeType), + _buildCyberCard(FeatureCard(title: loc.cpuTitle, subtitle: loc.cpuSub, icon: Icons.smart_toy, color: Colors.purple.shade200, theme: theme, themeType: themeType, onTap: () => HomeModals.showMatchSetupDialog(context, true)), themeType), SizedBox(height: 12 * vScale), - _buildCyberCard(FeatureCard(title: loc.localTitle, subtitle: loc.localSub, icon: Icons.people_alt, color: Colors.red.shade200, theme: theme, themeType: themeType, onTap: () => _showMatchSetupDialog(false)), themeType), + _buildCyberCard(FeatureCard(title: loc.localTitle, subtitle: loc.localSub, icon: Icons.people_alt, color: Colors.red.shade200, theme: theme, themeType: themeType, onTap: () => HomeModals.showMatchSetupDialog(context, false)), themeType), SizedBox(height: 12 * vScale), Row( @@ -967,7 +489,7 @@ class _HomeScreenState extends State with WidgetsBindingObserver { Row( children: [ - Expanded(child: _buildCyberCard(FeatureCard(title: loc.themesTitle, subtitle: "Personalizza", icon: Icons.palette, color: Colors.teal.shade200, theme: theme, themeType: themeType, onTap: () => Navigator.push(context, MaterialPageRoute(builder: (_) => const SettingsScreen())), compact: true), themeType)), + Expanded(child: _buildCyberCard(FeatureCard(title: loc.themesTitle, subtitle: "Personalizza", icon: Icons.palette, color: Colors.teal.shade200, theme: theme, themeType: themeType, onTap: () => Navigator.push(context, MaterialPageRoute(builder: (_) => SettingsScreen())), compact: true), themeType)), const SizedBox(width: 12), Expanded(child: _buildCyberCard(FeatureCard(title: loc.tutorialTitle, subtitle: "Come giocare", icon: Icons.school, color: Colors.indigo.shade200, theme: theme, themeType: themeType, onTap: () => showDialog(context: context, builder: (ctx) => const TutorialDialog()), compact: true), themeType)), ], @@ -991,6 +513,14 @@ class _HomeScreenState extends State with WidgetsBindingObserver { body: Stack( children: [ Container(color: themeType == AppThemeType.doodle ? Colors.white : theme.background), + + if (themeType == AppThemeType.doodle) + Positioned.fill( + child: CustomPaint( + painter: FullScreenGridPainter(Colors.blue.withOpacity(0.15)), + ), + ), + if (bgImage != null) Positioned.fill( child: Container( @@ -1005,12 +535,7 @@ class _HomeScreenState extends State with WidgetsBindingObserver { ), ), ), - if (themeType == AppThemeType.doodle) - Positioned.fill( - child: CustomPaint( - painter: FullScreenGridPainter(Colors.blue.withOpacity(0.15)), - ), - ), + if (bgImage != null && (themeType == AppThemeType.cyberpunk || themeType == AppThemeType.music || themeType == AppThemeType.arcade || themeType == AppThemeType.grimorio)) Positioned.fill( child: Container( @@ -1022,6 +547,7 @@ class _HomeScreenState extends State with WidgetsBindingObserver { ), ), ), + if (themeType == AppThemeType.music) Positioned.fill( child: IgnorePointer( @@ -1030,9 +556,26 @@ class _HomeScreenState extends State with WidgetsBindingObserver { ), ), ), + Positioned.fill(child: uiContent), ], ), ); } +} + +class FullScreenGridPainter extends CustomPainter { + final Color gridColor; + FullScreenGridPainter(this.gridColor); + + @override + void paint(Canvas canvas, Size size) { + final Paint paperGridPaint = Paint()..color = gridColor..strokeWidth = 1.0..style = PaintingStyle.stroke; + double paperStep = 20.0; + for (double i = 0; i <= size.width; i += paperStep) canvas.drawLine(Offset(i, 0), Offset(i, size.height), paperGridPaint); + for (double i = 0; i <= size.height; i += paperStep) canvas.drawLine(Offset(0, i), Offset(size.width, i), paperGridPaint); + } + + @override + bool shouldRepaint(covariant CustomPainter oldDelegate) => false; } \ No newline at end of file diff --git a/lib/widgets/game_over_dialog.dart b/lib/widgets/game_over_dialog.dart index b480f18..8f3994d 100644 --- a/lib/widgets/game_over_dialog.dart +++ b/lib/widgets/game_over_dialog.dart @@ -61,32 +61,86 @@ class GameOverDialog extends StatelessWidget { side: BorderSide(color: winnerColor.withOpacity(0.5), width: 2), ), title: Text("FINE PARTITA", textAlign: TextAlign.center, style: TextStyle(color: theme.text, fontWeight: FontWeight.bold, fontSize: 22)), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text(winnerText, textAlign: TextAlign.center, style: TextStyle(fontSize: 26, fontWeight: FontWeight.w900, color: winnerColor)), - const SizedBox(height: 20), - Container( - padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10), - decoration: BoxDecoration( - color: theme.text.withOpacity(0.05), - borderRadius: BorderRadius.circular(15), + content: SingleChildScrollView( + physics: const BouncingScrollPhysics(), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text(winnerText, textAlign: TextAlign.center, style: TextStyle(fontSize: 26, fontWeight: FontWeight.w900, color: winnerColor)), + const SizedBox(height: 20), + Container( + padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10), + decoration: BoxDecoration( + color: theme.text.withOpacity(0.05), + borderRadius: BorderRadius.circular(15), + ), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Text("$nameRed: $red", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: theme.playerRed)), + Text(" - ", style: TextStyle(fontSize: 18, color: theme.text)), + Text("$nameBlue: $blue", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: theme.playerBlue)), + ], + ), ), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Text("$nameRed: $red", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: theme.playerRed)), - Text(" - ", style: TextStyle(fontSize: 18, color: theme.text)), - Text("$nameBlue: $blue", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: theme.playerBlue)), - ], - ), - ), - if (game.isVsCPU) ...[ - const SizedBox(height: 15), - Text("Difficoltà CPU: Livello ${game.cpuLevel}", style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: theme.text.withOpacity(0.7))), - ] - ], + if (game.isVsCPU) ...[ + const SizedBox(height: 15), + Text("Difficoltà CPU: Livello ${game.cpuLevel}", style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: theme.text.withOpacity(0.7))), + ], + + // --- SEZIONE LEVEL UP E ROADMAP DINAMICA --- + if (game.hasLeveledUp && game.unlockedRewards.isNotEmpty) ...[ + const SizedBox(height: 30), + const Divider(), + const SizedBox(height: 15), + Container( + padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 20), + decoration: BoxDecoration( + color: Colors.amber.withOpacity(0.2), + borderRadius: BorderRadius.circular(30), + border: Border.all(color: Colors.amber, width: 2) + ), + child: Text("🎉 LIVELLO ${game.newlyReachedLevel}! 🎉", style: const TextStyle(color: Colors.amber, fontWeight: FontWeight.w900, fontSize: 18)), + ), + const SizedBox(height: 15), + + ...game.unlockedRewards.map((reward) => Container( + margin: const EdgeInsets.only(bottom: 10), + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + color: (reward['color'] as Color).withOpacity(0.1), + borderRadius: BorderRadius.circular(12), + border: Border.all(color: (reward['color'] as Color).withOpacity(0.5), width: 1.5), + ), + child: Row( + children: [ + Container( + padding: const EdgeInsets.all(8), + decoration: BoxDecoration( + color: (reward['color'] as Color).withOpacity(0.2), + shape: BoxShape.circle, + ), + child: Icon(reward['icon'], color: reward['color'], size: 28), + ), + const SizedBox(width: 15), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(reward['title'], style: TextStyle(color: reward['color'], fontWeight: FontWeight.w900, fontSize: 16)), + const SizedBox(height: 4), + Text(reward['desc'], style: TextStyle(color: theme.text.withOpacity(0.9), fontSize: 12, height: 1.3)), + ], + ) + ) + ] + ) + )), + ] + // --------------------------------------------- + ], + ), ), actionsPadding: const EdgeInsets.only(left: 20, right: 20, bottom: 20, top: 10), actionsAlignment: MainAxisAlignment.center,