- adjust risky animation offset
 - show inventory in shop
This commit is contained in:
2025-12-09 11:47:37 +09:00
parent d544f46766
commit ac4df02654
8 changed files with 726 additions and 649 deletions
+17 -14
View File
@@ -510,6 +510,9 @@ class _BattleScreenState extends State<BattleScreen> {
// Trigger Animation
_enemyAnimKey.currentState
?.animateDefense(() {
// [New] Apply Logic Synced with Animation
battleProvider.applyPendingEnemyDefense();
// Create a local visual-only event to trigger the effect (Icon or FAILED text)
final bool isSuccess = enemyIntent.isSuccess;
final BattleFeedbackType? feedbackType = isSuccess
@@ -701,20 +704,7 @@ class _BattleScreenState extends State<BattleScreen> {
padding: const EdgeInsets.all(16.0),
child: Stack(
children: [
// Enemy (Top Right)
Positioned(
top: 16, // Add some padding from top
right: 16, // Add some padding from right
child: CharacterStatusCard(
character: battleProvider.enemy,
isPlayer: false,
isTurn: !battleProvider.isPlayerTurn,
key: _enemyKey,
animationKey: _enemyAnimKey, // Direct Pass
hideStats: _isEnemyAttacking,
),
),
// Player (Bottom Left)
// Player (Bottom Left) - Rendered First
Positioned(
bottom: 80, // Space for FABs
left: 16, // Add some padding from left
@@ -727,6 +717,19 @@ class _BattleScreenState extends State<BattleScreen> {
hideStats: _isPlayerAttacking,
),
),
// Enemy (Top Right) - Rendered Last (On Top)
Positioned(
top: 16, // Add some padding from top
right: 16, // Add some padding from right
child: CharacterStatusCard(
character: battleProvider.enemy,
isPlayer: false,
isTurn: !battleProvider.isPlayerTurn,
key: _enemyKey,
animationKey: _enemyAnimKey, // Direct Pass
hideStats: _isEnemyAttacking,
),
),
], // Close children list
), // Close Stack
), // Close Padding
+14 -402
View File
@@ -6,6 +6,8 @@ import '../game/enums.dart';
import '../utils/item_utils.dart';
import '../game/config/theme_config.dart';
import '../game/config/app_strings.dart';
import '../widgets/inventory/character_stats_widget.dart';
import '../widgets/inventory/inventory_grid_widget.dart';
class InventoryScreen extends StatelessWidget {
const InventoryScreen({super.key});
@@ -20,57 +22,10 @@ class InventoryScreen extends StatelessWidget {
return Column(
children: [
// Player Stats Header
Card(
margin: const EdgeInsets.all(16.0),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Text(
player.name,
style: Theme.of(context).textTheme.headlineSmall,
),
const SizedBox(height: 8),
Text("Stage: ${battleProvider.stage}"),
const Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_buildStatItem(
AppStrings.hp,
"${player.hp}/${player.totalMaxHp}",
color: ThemeConfig.statHpColor,
),
_buildStatItem(
AppStrings.atk,
"${player.totalAtk}",
color: ThemeConfig.statAtkColor,
),
_buildStatItem(
AppStrings.def,
"${player.totalDefense}",
color: ThemeConfig.statDefColor,
),
_buildStatItem(AppStrings.armor, "${player.armor}"),
_buildStatItem(
AppStrings.luck,
"${player.totalLuck}",
color: ThemeConfig.statLuckColor,
),
_buildStatItem(
AppStrings.gold,
"${player.gold} G",
color: ThemeConfig.statGoldColor,
),
],
),
],
),
),
),
// 1. Modularized Stats Widget
const CharacterStatsWidget(),
// Equipped Items Section (Slot based)
// 2. Equipped Items Section (Kept here for now)
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
@@ -119,7 +74,7 @@ class InventoryScreen extends StatelessWidget {
: null,
child: Stack(
children: [
// Slot Name (Top Right)
// Slot Name
Positioned(
right: 4,
top: 4,
@@ -132,14 +87,12 @@ class InventoryScreen extends StatelessWidget {
),
),
),
// Faded Icon (Top Left)
// Faded Icon
Positioned(
left: 4,
top: 4,
child: Opacity(
opacity: item != null
? 0.5
: 0.2, // Increase opacity slightly for images
opacity: item != null ? 0.5 : 0.2,
child: Image.asset(
ItemUtils.getIconPath(slot),
width: 40,
@@ -157,13 +110,12 @@ class InventoryScreen extends StatelessWidget {
mainAxisAlignment:
MainAxisAlignment.center,
children: [
const SizedBox(
height: 12,
), // Spacing for top elements
const SizedBox(height: 12),
FittedBox(
fit: BoxFit.scaleDown,
child: Text(
item?.name ?? AppStrings.emptySlot,
item?.name ??
AppStrings.emptySlot,
textAlign: TextAlign.center,
style: TextStyle(
fontSize:
@@ -200,125 +152,8 @@ class InventoryScreen extends StatelessWidget {
),
),
// Inventory (Bag) Section
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"${AppStrings.bag} (${player.inventory.length}/${player.maxInventorySize})",
style: const TextStyle(
fontSize: ThemeConfig.fontSizeHeader,
fontWeight: ThemeConfig.fontWeightBold,
),
),
),
),
Expanded(
child: GridView.builder(
padding: const EdgeInsets.all(16.0),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
crossAxisSpacing: 8.0,
mainAxisSpacing: 8.0,
),
itemCount: player.maxInventorySize,
itemBuilder: (context, index) {
if (index < player.inventory.length) {
final item = player.inventory[index];
return InkWell(
onTap: () {
// Show Action Dialog instead of direct Equip
_showItemActionDialog(context, battleProvider, item);
},
child: Card(
color: ThemeConfig.inventoryCardBg,
shape: item.rarity != ItemRarity.magic
? RoundedRectangleBorder(
side: BorderSide(
color: ItemUtils.getRarityColor(
item.rarity,
),
width: 2.0,
),
borderRadius: BorderRadius.circular(4.0),
)
: null,
child: Stack(
children: [
// Faded Icon in Top-Left
Positioned(
left: 4,
top: 4,
child: Opacity(
opacity:
0.5, // Adjusted opacity for image visibility
child: Image.asset(
ItemUtils.getIconPath(item.slot),
width: 40,
height: 40,
fit: BoxFit.contain,
filterQuality: FilterQuality.high,
),
),
),
// Centered Content
Center(
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FittedBox(
fit: BoxFit.scaleDown,
child: Text(
item.name,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: ThemeConfig.fontSizeSmall,
fontWeight:
ThemeConfig.fontWeightBold,
color: ItemUtils.getRarityColor(
item.rarity,
),
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
FittedBox(
fit: BoxFit.scaleDown,
child: _buildItemStatText(item),
),
],
),
),
),
],
),
),
);
} else {
// Empty slot
return Container(
decoration: BoxDecoration(
border: Border.all(color: ThemeConfig.textColorGrey),
color: ThemeConfig.emptySlotBg,
),
child: const Center(
child: Icon(
Icons.add_box,
color: ThemeConfig.textColorGrey,
),
),
);
}
},
),
),
// 3. Modularized Inventory Grid
const Expanded(child: InventoryGridWidget()),
],
);
},
@@ -326,230 +161,7 @@ class InventoryScreen extends StatelessWidget {
);
}
Widget _buildStatItem(String label, String value, {Color? color}) {
return Column(
children: [
Text(
label,
style: const TextStyle(
color: ThemeConfig.textColorGrey,
fontSize: 12,
),
),
Text(
value,
style: TextStyle(
fontWeight: ThemeConfig.fontWeightBold,
fontSize: 16,
color: color,
),
),
],
);
}
/// Shows a menu with actions for the selected item (Equip, Discard, etc.)
void _showItemActionDialog(
BuildContext context,
BattleProvider provider,
Item item,
) {
bool isShop = provider.currentStage.type == StageType.shop;
showDialog(
context: context,
builder: (ctx) => SimpleDialog(
title: Text("${item.name} Actions"),
children: [
SimpleDialogOption(
onPressed: () {
Navigator.pop(ctx);
_showEquipConfirmationDialog(context, provider, item);
},
child: const Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: Row(
children: [
Icon(Icons.shield, color: ThemeConfig.btnDefendActive),
SizedBox(width: 10),
Text(AppStrings.equip),
],
),
),
),
if (isShop)
SimpleDialogOption(
onPressed: () {
Navigator.pop(ctx);
_showSellConfirmationDialog(context, provider, item);
},
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
children: [
const Icon(
Icons.attach_money,
color: ThemeConfig.statGoldColor,
),
const SizedBox(width: 10),
Text("${AppStrings.sell} (${item.price} G)"),
],
),
),
),
SimpleDialogOption(
onPressed: () {
Navigator.pop(ctx);
_showDiscardConfirmationDialog(context, provider, item);
},
child: const Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: Row(
children: [
Icon(Icons.delete, color: ThemeConfig.btnActionActive),
SizedBox(width: 10),
Text(AppStrings.discard),
],
),
),
),
],
),
);
}
void _showSellConfirmationDialog(
BuildContext context,
BattleProvider provider,
Item item,
) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text("Sell Item"),
content: Text("Sell ${item.name} for ${item.price} G?"),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text(AppStrings.cancel),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: ThemeConfig.statGoldColor,
),
onPressed: () {
provider.sellItem(item);
Navigator.pop(ctx);
},
child: const Text(AppStrings.sell, style: TextStyle(color: Colors.black)),
),
],
),
);
}
void _showDiscardConfirmationDialog(
BuildContext context,
BattleProvider provider,
Item item,
) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text("Discard Item"),
content: Text("Are you sure you want to discard ${item.name}?"),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text(AppStrings.cancel),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: ThemeConfig.btnActionActive,
),
onPressed: () {
provider.discardItem(item);
Navigator.pop(ctx);
},
child: const Text(AppStrings.discard),
),
],
),
);
}
void _showEquipConfirmationDialog(
BuildContext context,
BattleProvider provider,
Item newItem,
) {
final player = provider.player;
final oldItem = player.equipment[newItem.slot];
// Calculate predicted stats
final currentMaxHp = player.totalMaxHp;
final currentAtk = player.totalAtk;
final currentDef = player.totalDefense;
final currentHp = player.hp;
// Predict new stats
int newMaxHp = currentMaxHp - (oldItem?.hpBonus ?? 0) + newItem.hpBonus;
int newAtk = currentAtk - (oldItem?.atkBonus ?? 0) + newItem.atkBonus;
int newDef = currentDef - (oldItem?.armorBonus ?? 0) + newItem.armorBonus;
// Predict HP (Percentage Logic)
double ratio = currentMaxHp > 0 ? currentHp / currentMaxHp : 0.0;
int newHp = (newMaxHp * ratio).toInt();
if (newHp < 0) newHp = 0;
if (newHp > newMaxHp) newHp = newMaxHp;
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text("Change Equipment"),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"${AppStrings.equip} ${newItem.name}?",
style: const TextStyle(fontWeight: ThemeConfig.fontWeightBold),
),
if (oldItem != null)
Text(
"Replaces ${oldItem.name}",
style: const TextStyle(
fontSize: 12,
color: ThemeConfig.textColorGrey,
),
),
const SizedBox(height: 16),
_buildStatChangeRow("Max HP", currentMaxHp, newMaxHp),
_buildStatChangeRow("Current HP", currentHp, newHp),
_buildStatChangeRow(AppStrings.atk, currentAtk, newAtk),
_buildStatChangeRow(AppStrings.def, currentDef, newDef),
_buildStatChangeRow(
"LUCK",
player.totalLuck,
player.totalLuck - (oldItem?.luck ?? 0) + newItem.luck,
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text(AppStrings.cancel),
),
ElevatedButton(
onPressed: () {
provider.equipItem(newItem);
Navigator.pop(ctx);
},
child: const Text(AppStrings.confirm),
),
],
),
);
}
// --- Helper Methods for Equipped Items Section ---
void _showUnequipConfirmationDialog(
BuildContext context,