This commit is contained in:
2025-12-04 01:21:37 +09:00
parent a29dc50c4c
commit 0a7c50e6c9
10 changed files with 300 additions and 38 deletions
+195 -21
View File
@@ -21,6 +21,7 @@ class _BattleScreenState extends State<BattleScreen> {
final ScrollController _scrollController = ScrollController();
final List<_DamageTextData> _floatingDamageTexts = [];
final List<_FloatingEffectData> _floatingEffects = [];
final List<_FeedbackTextData> _floatingFeedbackTexts = [];
StreamSubscription<DamageEvent>? _damageSubscription;
StreamSubscription<EffectEvent>? _effectSubscription;
final GlobalKey _playerKey = GlobalKey();
@@ -131,6 +132,51 @@ class _BattleScreenState extends State<BattleScreen> {
position +
Offset(renderBox.size.width / 2 - 30, renderBox.size.height / 2 - 30);
// feedbackType이 존재하면 해당 텍스트를 표시하고 기존 이펙트 아이콘은 건너뜜
if (event.feedbackType != null) {
String feedbackText;
Color feedbackColor;
switch (event.feedbackType) {
case BattleFeedbackType.miss:
feedbackText = "MISS";
feedbackColor = Colors.grey;
break;
case BattleFeedbackType.failed:
feedbackText = "FAILED";
feedbackColor = Colors.redAccent;
break;
default:
feedbackText = ""; // Should not happen with current enums
feedbackColor = Colors.white;
}
final String id = UniqueKey().toString();
setState(() {
_floatingFeedbackTexts.add(
_FeedbackTextData(
id: id,
widget: Positioned(
left: position.dx,
top: position.dy,
child: _FloatingFeedbackText(
key: ValueKey(id),
feedback: feedbackText,
color: feedbackColor,
onRemove: () {
if (mounted) {
setState(() {
_floatingFeedbackTexts.removeWhere((e) => e.id == id);
});
}
},
),
),
),
);
});
return; // feedbackType이 있으면 아이콘 이펙트는 표시하지 않음
}
IconData icon;
Color color;
double size;
@@ -321,29 +367,34 @@ class _BattleScreenState extends State<BattleScreen> {
// Battle Area
Expanded(
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
child: Padding(
// padding: const EdgeInsets.symmetric(horizontal: 40.0),
padding: const EdgeInsets.all(70.0),
child: Column(
children: [
_buildCharacterStatus(
battleProvider.player,
isPlayer: true,
isTurn: battleProvider.isPlayerTurn,
key: _playerKey,
// 적 영역 (우측 상단)
Expanded(
child: Align(
alignment: Alignment.topRight,
child: _buildCharacterStatus(
battleProvider.enemy,
isPlayer: false,
isTurn: !battleProvider.isPlayerTurn,
key: _enemyKey,
),
),
),
// const Text(
// "VS",
// style: TextStyle(
// color: Colors.red,
// fontSize: 24,
// fontWeight: FontWeight.bold,
// ),
// ),
_buildCharacterStatus(
battleProvider.enemy,
isPlayer: false,
isTurn: !battleProvider.isPlayerTurn,
key: _enemyKey,
// 플레이어 영역 (좌측 하단)
Expanded(
child: Align(
alignment: Alignment.bottomLeft,
child: _buildCharacterStatus(
battleProvider.player,
isPlayer: true,
isTurn: battleProvider.isPlayerTurn,
key: _playerKey,
),
),
),
],
),
@@ -470,6 +521,7 @@ class _BattleScreenState extends State<BattleScreen> {
),
..._floatingDamageTexts.map((e) => e.widget),
..._floatingEffects.map((e) => e.widget),
..._floatingFeedbackTexts.map((e) => e.widget), // 새로운 피드백 텍스트 추가
],
);
},
@@ -609,6 +661,31 @@ class _BattleScreenState extends State<BattleScreen> {
),
Text("ATK: ${character.totalAtk}"),
Text("DEF: ${character.totalDefense}"),
// 캐릭터 아이콘/이미지 영역 추가
Container(
width: 100, // 임시 크기
height: 100, // 임시 크기
decoration: BoxDecoration(
color: isPlayer
? Colors.lightBlue
: Colors.deepOrange, // 플레이어/적 구분 색상
borderRadius: BorderRadius.circular(8),
),
child: Center(
child: isPlayer
? const Icon(
Icons.person,
size: 60,
color: Colors.white,
) // 플레이어 아이콘
: const Icon(
Icons.psychology,
size: 60,
color: Colors.white,
), // 적 아이콘 (몬스터 대신)
),
),
const SizedBox(height: 8), // 아이콘과 정보 사이 간격
if (!isPlayer)
Consumer<BattleProvider>(
@@ -863,3 +940,100 @@ class _FloatingEffectData {
_FloatingEffectData({required this.id, required this.widget});
}
// 새로운 _FloatingFeedbackText 위젯
class _FloatingFeedbackText extends StatefulWidget {
final String feedback;
final Color color;
final VoidCallback onRemove;
const _FloatingFeedbackText({
Key? key,
required this.feedback,
required this.color,
required this.onRemove,
}) : super(key: key);
@override
__FloatingFeedbackTextState createState() => __FloatingFeedbackTextState();
}
class __FloatingFeedbackTextState extends State<_FloatingFeedbackText>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<Offset> _offsetAnimation;
late Animation<double> _opacityAnimation;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(milliseconds: 1000),
vsync: this,
);
_offsetAnimation = Tween<Offset>(
begin: const Offset(0.0, 0.0),
end: const Offset(0.0, -1.5),
).animate(CurvedAnimation(parent: _controller, curve: Curves.easeOut));
_opacityAnimation = Tween<double>(begin: 1.0, end: 0.0).animate(
CurvedAnimation(
parent: _controller,
curve: const Interval(0.5, 1.0, curve: Curves.easeOut),
),
);
_controller.forward().then((_) {
if (mounted) {
widget.onRemove();
}
});
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _controller,
builder: (context, child) {
return FractionalTranslation(
translation: _offsetAnimation.value,
child: Opacity(
opacity: _opacityAnimation.value,
child: Material(
color: Colors.transparent,
child: Text(
widget.feedback,
style: TextStyle(
color: widget.color,
fontSize: 20,
fontWeight: FontWeight.bold,
shadows: const [
Shadow(
blurRadius: 2.0,
color: Colors.black,
offset: Offset(1.0, 1.0),
),
],
),
),
),
),
);
},
);
}
}
class _FeedbackTextData {
final String id;
final Widget widget;
_FeedbackTextData({required this.id, required this.widget});
}