Feat: Add SettingsProvider and Toggle for Enemy Animations
This commit is contained in:
@@ -61,4 +61,5 @@ class AppStrings {
|
||||
|
||||
// Settings
|
||||
static const String settings = "Settings";
|
||||
static const String enemyAnimations = "Enemy Animations";
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'game/data/enemy_table.dart';
|
||||
import 'game/data/player_table.dart';
|
||||
import 'providers/battle_provider.dart';
|
||||
import 'providers/shop_provider.dart'; // Import ShopProvider
|
||||
import 'providers/settings_provider.dart'; // Import SettingsProvider
|
||||
import 'screens/main_menu_screen.dart';
|
||||
|
||||
void main() async {
|
||||
@@ -22,6 +23,7 @@ class MyApp extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider(create: (_) => SettingsProvider()), // Register SettingsProvider
|
||||
ChangeNotifierProvider(create: (_) => ShopProvider()),
|
||||
ChangeNotifierProxyProvider<ShopProvider, BattleProvider>(
|
||||
create: (context) => BattleProvider(
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class SettingsProvider with ChangeNotifier {
|
||||
static const String _keyEnemyAnim = 'settings_enemy_anim';
|
||||
|
||||
bool _enableEnemyAnimations = false; // Default: Disabled
|
||||
|
||||
bool get enableEnemyAnimations => _enableEnemyAnimations;
|
||||
|
||||
SettingsProvider() {
|
||||
_loadSettings();
|
||||
}
|
||||
|
||||
Future<void> _loadSettings() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_enableEnemyAnimations = prefs.getBool(_keyEnemyAnim) ?? false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> toggleEnemyAnimations(bool value) async {
|
||||
_enableEnemyAnimations = value;
|
||||
notifyListeners();
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(_keyEnemyAnim, value);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import 'main_menu_screen.dart';
|
||||
import '../game/config/battle_config.dart';
|
||||
import '../game/config/theme_config.dart';
|
||||
import '../game/config/app_strings.dart';
|
||||
import '../providers/settings_provider.dart'; // Import SettingsProvider
|
||||
|
||||
class BattleScreen extends StatefulWidget {
|
||||
const BattleScreen({super.key});
|
||||
@@ -293,6 +294,15 @@ class _BattleScreenState extends State<BattleScreen> {
|
||||
} else if (event.type == ActionType.attack &&
|
||||
event.target == EffectTarget.player &&
|
||||
event.feedbackType == null) {
|
||||
|
||||
// Check Settings
|
||||
bool enableAnim = context.read<SettingsProvider>().enableEnemyAnimations;
|
||||
|
||||
if (!enableAnim) {
|
||||
showEffect(); // Just show effect if anim disabled
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Enemy Attack Animation Trigger
|
||||
final RenderBox? playerBox =
|
||||
_playerKey.currentContext?.findRenderObject() as RenderBox?;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../providers/battle_provider.dart';
|
||||
import '../providers/settings_provider.dart'; // Import SettingsProvider
|
||||
import 'main_menu_screen.dart';
|
||||
import '../game/config/theme_config.dart';
|
||||
import '../game/config/app_strings.dart';
|
||||
@@ -23,11 +24,27 @@ class SettingsScreen extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
// Placeholder for future settings
|
||||
const Text(
|
||||
'Effect Intensity: Normal',
|
||||
style: TextStyle(color: ThemeConfig.textColorWhite),
|
||||
|
||||
// Enemy Animation Toggle
|
||||
Consumer<SettingsProvider>(
|
||||
builder: (context, settings, child) {
|
||||
return SizedBox(
|
||||
width: 300,
|
||||
child: SwitchListTile(
|
||||
title: const Text(
|
||||
AppStrings.enemyAnimations,
|
||||
style: TextStyle(color: ThemeConfig.textColorWhite),
|
||||
),
|
||||
value: settings.enableEnemyAnimations,
|
||||
onChanged: (value) {
|
||||
settings.toggleEnemyAnimations(value);
|
||||
},
|
||||
activeColor: ThemeConfig.btnActionActive,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
const Text(
|
||||
'Volume: 100%',
|
||||
|
||||
Reference in New Issue
Block a user