game/lib/screens/main_menu_screen.dart

142 lines
4.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'character_selection_screen.dart';
import 'main_wrapper.dart';
import '../widgets/responsive_container.dart';
import '../game/save_manager.dart';
import '../providers/battle_provider.dart';
class MainMenuScreen extends StatefulWidget {
const MainMenuScreen({super.key});
@override
State<MainMenuScreen> createState() => _MainMenuScreenState();
}
class _MainMenuScreenState extends State<MainMenuScreen> {
bool _hasSave = false;
bool _isLoading = true;
@override
void initState() {
super.initState();
_checkSaveData();
}
Future<void> _checkSaveData() async {
final hasSave = await SaveManager.hasSaveData();
if (mounted) {
setState(() {
_hasSave = hasSave;
_isLoading = false;
});
}
}
Future<void> _continueGame() async {
final data = await SaveManager.loadGame();
if (data != null && mounted) {
context.read<BattleProvider>().loadFromSave(data);
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => const MainWrapper()),
);
} else {
// Handle load error
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Failed to load save data.')),
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.black, Colors.blueGrey[900]!],
),
),
child: ResponsiveContainer(
child: _isLoading
? const Center(child: CircularProgressIndicator())
: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.gavel, size: 100, color: Colors.amber),
const SizedBox(height: 20),
const Text(
"COLOSSEUM'S CHOICE",
style: TextStyle(
fontSize: 32,
fontWeight: FontWeight.bold,
letterSpacing: 2.0,
color: Colors.white,
),
),
const SizedBox(height: 10),
const Text(
"Rise as a Legend",
style: TextStyle(
fontSize: 16,
color: Colors.grey,
fontStyle: FontStyle.italic,
),
),
const SizedBox(height: 60),
if (_hasSave) ...[
ElevatedButton(
onPressed: _continueGame,
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 50,
vertical: 15,
),
backgroundColor: Colors.blueAccent,
foregroundColor: Colors.white,
textStyle: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
child: const Text("CONTINUE"),
),
const SizedBox(height: 20),
],
ElevatedButton(
onPressed: () {
// Warn if save exists? Or just overwrite on save.
// For now, simpler flow.
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const CharacterSelectionScreen(),
),
);
},
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 50,
vertical: 15,
),
backgroundColor: Colors.amber[700],
foregroundColor: Colors.black,
textStyle: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
child: const Text("NEW GAME"),
),
],
),
),
),
);
}
}