import 'package:flame_audio/flame_audio.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:match_magic/db/main_db.dart'; import 'package:match_magic/game/board.dart'; import 'package:match_magic/screens/main_menu_screen.dart'; import 'package:match_magic/styles/styles.dart'; import 'package:match_magic/widgets/icon_widgets/volume_icon.dart'; import 'package:match_magic/widgets/overlays/game_overlay/hint_button.dart'; import 'package:match_magic/widgets/overlays/game_overlay/pause_button.dart'; import 'package:match_magic/widgets/overlays/game_overlay/restart_button.dart'; import 'package:match_magic/widgets/toggle_switch.dart'; class PauseMenu extends StatefulWidget { static const String id = 'PauseMenu'; final Board gameRef; const PauseMenu({super.key, required this.gameRef}); @override State createState() => _PauseMenuState(); } class _PauseMenuState extends State { bool isMusic = true; bool isSound = Board.isSoundPlaying; @override Widget build(BuildContext context) { return Container( padding: const EdgeInsets.symmetric(vertical: 70, horizontal: 16), decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [ Color(0xFFEBEBEB).withOpacity(0.6), Color(0xFFBFBEC0).withOpacity(0.6), ], ), ), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const SizedBox( height: 122, ), // Pause menu title. Padding( padding: const EdgeInsets.symmetric(vertical: 50.0), child: Text('Game Paused', style: AppStyles.titleTextStyle.copyWith( fontSize: 32, color: AppStyles.accentColorTopBar)), ), // Sound settings Card( child: Container( height: 56, padding: const EdgeInsets.all(12), child: Row( children: [ const VolumeIcon(), const SizedBox( width: 6, ), const Text( 'Sound settings', style: TextStyle(), ), const Expanded(child: SizedBox()), ToggleSwitch( value: isSound, onChanged: (value) async { setState(() { isSound = value; Board.isSoundPlaying = !Board.isSoundPlaying; }); await MainDB.instance.saveSoundEnabled(value); }) ], ), ), ), const SizedBox( height: 6, ), // Music // Card( // child: Container( // height: 56, // padding: const EdgeInsets.all(12), // child: Row( // children: [ // const MusicIcon(), // const SizedBox( // width: 6, // ), // const Text( // 'Music', // style: TextStyle(), // ), // const Expanded(child: SizedBox()), // ToggleSwitch( // value: isMusic, // onChanged: (value) async { // setState(() { // isMusic = value; // if (Board.isMusicPlaying) { // FlameAudio.bgm.stop(); // } else { // FlameAudio.bgm.play('.ogg'); // } // Board.isMusicPlaying = !Board.isMusicPlaying; // }); // await MainDB.instance.saveMusicEnabled(value); // }) // ], // ), // ), // ), const Expanded(child: SizedBox()), Row( children: [ // Exit button Expanded( child: ElevatedButton( onPressed: () { showDialog( context: context, barrierDismissible: false, builder: (context) => AlertDialog( backgroundColor: AppStyles.mainBackground, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16), ), title: const Text( 'Quit', style: AppStyles.titleTextStyle, ), content: const Text( 'Are you sure you want to leave the game? You progress will be lost.', style: AppStyles.subtitleTextStyle, ), actions: [ TextButton( onPressed: () { Navigator.of(context).pop(); }, child: Text( 'CANCEL', style: AppStyles.subtitleTextStyle.copyWith( fontSize: 14, color: AppStyles.accentColor), ), ), TextButton( onPressed: () { FlameAudio.bgm.stop(); widget.gameRef.overlays.remove(PauseMenu.id); widget.gameRef.removed; widget.gameRef.resumeEngine(); Navigator.of(context).pushReplacement( MaterialPageRoute( builder: (context) => MainMenuScreen(), ), ); }, child: Text( 'EXIT', style: AppStyles.subtitleTextStyle.copyWith( fontSize: 14, color: AppStyles.accentColor), ), ), ], ), ); }, child: const Text('Exit'), ), ), const SizedBox( width: 16, ), // Continue button Expanded( child: ElevatedButton( onPressed: () async { widget.gameRef.overlays.remove(PauseMenu.id); widget.gameRef.overlays.add(PauseButton.id); widget.gameRef.overlays.add(RestartButton.id); widget.gameRef.overlays.add(HintButton.id); widget.gameRef.resumeEngine(); print('${Board.isSoundPlaying}'); }, child: const Text('Continue'), )), ], ), ], ), ); } }