update
This commit is contained in:
@@ -11,6 +11,8 @@ import '../utils.dart';
|
||||
import 'main_menu_screen.dart';
|
||||
import '../game/config.dart';
|
||||
|
||||
enum AnimationPhase { none, start, middle, end }
|
||||
|
||||
class BattleScreen extends StatefulWidget {
|
||||
const BattleScreen({super.key});
|
||||
|
||||
@@ -42,6 +44,22 @@ class _BattleScreenState extends State<BattleScreen> {
|
||||
// New State for Interactive Defense Animation
|
||||
int _lastTurnCount = -1;
|
||||
bool _hasShownEnemyDefense = false;
|
||||
AnimationPhase _playerAnimPhase = AnimationPhase.none;
|
||||
|
||||
String? _getOverrideImage(bool isPlayer) {
|
||||
if (!isPlayer)
|
||||
return null; // Enemy animation image logic can be added later
|
||||
|
||||
if (_playerAnimPhase == AnimationPhase.start) {
|
||||
return "assets/images/character/warrior_attack_1.png";
|
||||
} else if (_playerAnimPhase == AnimationPhase.middle) {
|
||||
return null; // Middle phase now uses default image or another image
|
||||
} else if (_playerAnimPhase == AnimationPhase.end) {
|
||||
return "assets/images/character/warrior_attack_2.png";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -348,28 +366,50 @@ class _BattleScreenState extends State<BattleScreen> {
|
||||
: event.risk;
|
||||
|
||||
_playerAnimKey.currentState
|
||||
?.animateAttack(offset, () {
|
||||
showEffect();
|
||||
context.read<BattleProvider>().handleImpact(event);
|
||||
?.animateAttack(
|
||||
offset,
|
||||
() {
|
||||
showEffect();
|
||||
context.read<BattleProvider>().handleImpact(event);
|
||||
|
||||
if (event.risk == RiskLevel.risky && event.feedbackType == null) {
|
||||
_shakeKey.currentState?.shake();
|
||||
RenderBox? stackBox =
|
||||
_stackKey.currentContext?.findRenderObject() as RenderBox?;
|
||||
if (stackBox != null) {
|
||||
Offset localEnemyPos = stackBox.globalToLocal(enemyPos);
|
||||
localEnemyPos += Offset(
|
||||
enemyBox.size.width / 2,
|
||||
enemyBox.size.height / 2,
|
||||
);
|
||||
_explosionKey.currentState?.explode(localEnemyPos);
|
||||
if (event.risk == RiskLevel.risky &&
|
||||
event.feedbackType == null) {
|
||||
_shakeKey.currentState?.shake();
|
||||
RenderBox? stackBox =
|
||||
_stackKey.currentContext?.findRenderObject()
|
||||
as RenderBox?;
|
||||
if (stackBox != null) {
|
||||
Offset localEnemyPos = stackBox.globalToLocal(enemyPos);
|
||||
localEnemyPos += Offset(
|
||||
enemyBox.size.width / 2,
|
||||
enemyBox.size.height / 2,
|
||||
);
|
||||
_explosionKey.currentState?.explode(localEnemyPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, animRisk)
|
||||
},
|
||||
animRisk,
|
||||
onAnimationStart: () {
|
||||
if (mounted) {
|
||||
setState(() => _playerAnimPhase = AnimationPhase.start);
|
||||
}
|
||||
},
|
||||
onAnimationMiddle: () {
|
||||
if (mounted) {
|
||||
setState(() => _playerAnimPhase = AnimationPhase.middle);
|
||||
}
|
||||
},
|
||||
onAnimationEnd: () {
|
||||
if (mounted) {
|
||||
setState(() => _playerAnimPhase = AnimationPhase.end);
|
||||
}
|
||||
},
|
||||
)
|
||||
.then((_) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isPlayerAttacking = false;
|
||||
_playerAnimPhase = AnimationPhase.none;
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -685,6 +725,7 @@ class _BattleScreenState extends State<BattleScreen> {
|
||||
key: _playerKey,
|
||||
animationKey: _playerAnimKey,
|
||||
hideStats: _isPlayerAttacking,
|
||||
overrideImage: _getOverrideImage(true),
|
||||
),
|
||||
),
|
||||
// Enemy (Top Right) - Rendered Last (On Top)
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../providers.dart';
|
||||
import '../game/data.dart';
|
||||
import 'main_wrapper.dart';
|
||||
import 'story_screen.dart';
|
||||
import '../widgets.dart';
|
||||
import '../game/config.dart';
|
||||
|
||||
@@ -37,12 +37,12 @@ class CharacterSelectionScreen extends StatelessWidget {
|
||||
// Initialize Game
|
||||
context.read<BattleProvider>().initializeBattle();
|
||||
|
||||
// Navigate to Game Screen (MainWrapper)
|
||||
// Navigate to Story Screen first
|
||||
// Using pushReplacement to prevent going back to selection
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const MainWrapper(),
|
||||
builder: (context) => const StoryScreen(),
|
||||
),
|
||||
(route) => false,
|
||||
);
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'main_wrapper.dart';
|
||||
import '../widgets.dart';
|
||||
import '../game/config.dart';
|
||||
|
||||
class StoryScreen extends StatefulWidget {
|
||||
const StoryScreen({super.key});
|
||||
|
||||
@override
|
||||
State<StoryScreen> createState() => _StoryScreenState();
|
||||
}
|
||||
|
||||
class _StoryScreenState extends State<StoryScreen> {
|
||||
final PageController _pageController = PageController();
|
||||
int _currentPage = 0;
|
||||
final int _totalPages = 3;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pageController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onSkip() {
|
||||
Navigator.of(context).pushAndRemoveUntil(
|
||||
MaterialPageRoute(builder: (context) => const MainWrapper()),
|
||||
(route) => false,
|
||||
);
|
||||
}
|
||||
|
||||
void _onNext() {
|
||||
if (_currentPage < _totalPages - 1) {
|
||||
_pageController.nextPage(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
} else {
|
||||
_onSkip(); // Start Game
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black, // Dark background for story
|
||||
body: Center(
|
||||
child: ResponsiveContainer(
|
||||
child: SafeArea(
|
||||
child: Stack(
|
||||
children: [
|
||||
// 1. PageView for Story Content
|
||||
PageView(
|
||||
controller: _pageController,
|
||||
physics:
|
||||
const NeverScrollableScrollPhysics(), // Disable swipe
|
||||
onPageChanged: (index) {
|
||||
setState(() {
|
||||
_currentPage = index;
|
||||
});
|
||||
},
|
||||
children: [
|
||||
_buildStoryPage(1),
|
||||
_buildStoryPage(2),
|
||||
_buildStoryPage(3),
|
||||
],
|
||||
),
|
||||
|
||||
// 2. Skip Button (Top Right)
|
||||
Positioned(
|
||||
top: 16,
|
||||
right: 16,
|
||||
child: TextButton(
|
||||
onPressed: _onSkip,
|
||||
child: const Text(
|
||||
"SKIP",
|
||||
style: TextStyle(
|
||||
color: ThemeConfig.textColorGrey, // Reverted to Grey
|
||||
fontSize:
|
||||
ThemeConfig.fontSizeMedium, // Reverted to Medium
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 3. Next/Start Button (Bottom Center or Right)
|
||||
Positioned(
|
||||
bottom: 32,
|
||||
left: 16,
|
||||
right: 16,
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 200,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: ThemeConfig.btnActionActive,
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
),
|
||||
onPressed: _onNext,
|
||||
child: Text(
|
||||
_currentPage == _totalPages - 1
|
||||
? "START BATTLE"
|
||||
: "NEXT",
|
||||
style: const TextStyle(
|
||||
color: ThemeConfig.textColorWhite,
|
||||
fontSize: ThemeConfig.fontSizeHeader,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStoryPage(int pageIndex) {
|
||||
return Container(
|
||||
color: Colors.black,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// Placeholder for Image
|
||||
Container(
|
||||
width: 300,
|
||||
height: 300,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[800],
|
||||
border: Border.all(color: ThemeConfig.textColorGrey),
|
||||
),
|
||||
child: Center(
|
||||
child: Icon(Icons.image, size: 64, color: Colors.grey[600]),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Text(
|
||||
"Story Image $pageIndex",
|
||||
style: const TextStyle(
|
||||
color: ThemeConfig.textColorWhite,
|
||||
fontSize: ThemeConfig.fontSizeHeader,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 32.0),
|
||||
child: Text(
|
||||
"This is the placeholder text for the story part $pageIndex. Describe the lore or setting here.",
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
color: ThemeConfig.textColorGrey,
|
||||
fontSize: ThemeConfig.fontSizeMedium,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user