- consumable items
This commit is contained in:
2025-12-10 16:05:42 +09:00
parent 8f72b9a812
commit 09d8fdcfe9
24 changed files with 859 additions and 369 deletions
+70 -2
View File
@@ -250,7 +250,8 @@ class _BattleScreenState extends State<BattleScreen> {
break;
case BattleFeedbackType.dodge:
feedbackText = "DODGE";
feedbackColor = ThemeConfig.statLuckColor; // Use Luck color (Greenish)
feedbackColor =
ThemeConfig.statLuckColor; // Use Luck color (Greenish)
break;
default:
feedbackText = "";
@@ -564,6 +565,70 @@ class _BattleScreenState extends State<BattleScreen> {
return false;
}
void _showInventoryDialog(BuildContext context) {
final battleProvider = context.read<BattleProvider>();
final List<Item> consumables = battleProvider.player.inventory
.where((item) => item.slot == EquipmentSlot.consumable)
.toList();
if (consumables.isEmpty) {
ToastUtils.showTopToast(context, "No consumable items!");
return;
}
showDialog(
context: context,
builder: (context) {
return SimpleDialog(
title: const Text("Use Item"),
children: consumables.map((item) {
return SimpleDialogOption(
onPressed: () {
battleProvider.useConsumable(item);
Navigator.pop(context);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: ThemeConfig.rewardItemBg,
borderRadius: BorderRadius.circular(4),
border: Border.all(
color: ItemUtils.getRarityColor(item.rarity),
),
),
child: Image.asset(
ItemUtils.getIconPath(item.slot),
width: ThemeConfig.itemIconSizeMedium,
height: ThemeConfig.itemIconSizeMedium,
fit: BoxFit.contain,
),
),
const SizedBox(width: 12),
Text(
item.name,
style: TextStyle(
fontWeight: ThemeConfig.fontWeightBold,
fontSize: ThemeConfig.fontSizeLarge,
color: ItemUtils.getRarityColor(item.rarity),
),
),
],
),
_buildItemStatText(item),
],
),
);
}).toList(),
);
},
);
}
@override
Widget build(BuildContext context) {
// Sync animation setting to provider logic
@@ -661,11 +726,14 @@ class _BattleScreenState extends State<BattleScreen> {
!battleProvider.showRewardPopup &&
!_isPlayerAttacking &&
!_isEnemyAttacking &&
!battleProvider.player.hasStatus(StatusEffectType.defenseForbidden), // Disable if defense is forbidden
!battleProvider.player.hasStatus(
StatusEffectType.defenseForbidden,
), // Disable if defense is forbidden
onAttackPressed: () =>
_showRiskLevelSelection(context, ActionType.attack),
onDefendPressed: () =>
_showRiskLevelSelection(context, ActionType.defend),
onItemPressed: () => _showInventoryDialog(context),
),
),
+2 -280
View File
@@ -1,10 +1,6 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers.dart';
import '../game/models.dart';
import '../game/enums.dart';
import '../utils.dart';
import '../game/config.dart';
import '../widgets.dart';
class InventoryScreen extends StatelessWidget {
@@ -16,139 +12,13 @@ class InventoryScreen extends StatelessWidget {
appBar: AppBar(title: const Text("Inventory & Stats")),
body: Consumer<BattleProvider>(
builder: (context, battleProvider, child) {
final player = battleProvider.player;
return Column(
children: [
// 1. Modularized Stats Widget
const CharacterStatsWidget(),
// 2. Equipped Items Section (Kept here for now)
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Equipped Items",
style: TextStyle(
fontSize: ThemeConfig.fontSizeHeader,
fontWeight: ThemeConfig.fontWeightBold,
),
),
const SizedBox(height: 8),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: EquipmentSlot.values.map((slot) {
final item = player.equipment[slot];
return Expanded(
child: InkWell(
onTap: item != null
? () => _showUnequipConfirmationDialog(
context,
battleProvider,
item,
)
: null,
child: Card(
color: item != null
? ThemeConfig.equipmentCardBg
: ThemeConfig.emptySlotBg,
shape:
item != null &&
item.rarity != ItemRarity.magic
? RoundedRectangleBorder(
side: BorderSide(
color: ItemUtils.getRarityColor(
item.rarity,
),
width: 2.0,
),
borderRadius: BorderRadius.circular(4.0),
)
: null,
child: Stack(
children: [
// Slot Name
Positioned(
right: 4,
top: 4,
child: Text(
slot.name.toUpperCase(),
style: const TextStyle(
fontSize: ThemeConfig.fontSizeTiny,
fontWeight: ThemeConfig.fontWeightBold,
color: Colors.white30,
),
),
),
// Faded Icon
Positioned(
left: 4,
top: 4,
child: Opacity(
opacity: item != null ? 0.5 : 0.2,
child: Image.asset(
ItemUtils.getIconPath(slot),
width: 40,
height: 40,
fit: BoxFit.contain,
filterQuality: FilterQuality.high,
),
),
),
// Content
Center(
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
const SizedBox(height: 12),
FittedBox(
fit: BoxFit.scaleDown,
child: Text(
item?.name ??
AppStrings.emptySlot,
textAlign: TextAlign.center,
style: TextStyle(
fontSize:
ThemeConfig.fontSizeSmall,
fontWeight:
ThemeConfig.fontWeightBold,
color: item != null
? ItemUtils.getRarityColor(
item.rarity,
)
: ThemeConfig.textColorGrey,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
if (item != null)
FittedBox(
fit: BoxFit.scaleDown,
child: _buildItemStatText(item),
),
],
),
),
),
],
),
),
),
);
}).toList(),
),
],
),
),
// 2. Modularized Equipped Items Section
const EquippedItemsWidget(),
// 3. Modularized Inventory Grid
const Expanded(child: InventoryGridWidget()),
@@ -158,152 +28,4 @@ class InventoryScreen extends StatelessWidget {
),
);
}
// --- Helper Methods for Equipped Items Section ---
void _showUnequipConfirmationDialog(
BuildContext context,
BattleProvider provider,
Item itemToUnequip,
) {
final player = provider.player;
// Calculate predicted stats
final currentMaxHp = player.totalMaxHp;
final currentAtk = player.totalAtk;
final currentDef = player.totalDefense;
final currentHp = player.hp;
// Predict new stats (Subtract item bonuses)
int newMaxHp = currentMaxHp - itemToUnequip.hpBonus;
int newAtk = currentAtk - itemToUnequip.atkBonus;
int newDef = currentDef - itemToUnequip.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("Unequip Item"),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"${AppStrings.unequip} ${itemToUnequip.name}?",
style: const TextStyle(fontWeight: ThemeConfig.fontWeightBold),
),
const SizedBox(height: 16),
_buildStatChangeRow("Max HP", currentMaxHp, newMaxHp),
_buildStatChangeRow("Current HP", currentHp, newHp),
_buildStatChangeRow(AppStrings.atk, currentAtk, newAtk),
_buildStatChangeRow(AppStrings.def, currentDef, newDef),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text(AppStrings.cancel),
),
ElevatedButton(
onPressed: () {
provider.unequipItem(itemToUnequip);
Navigator.pop(ctx);
},
child: const Text(AppStrings.confirm),
),
],
),
);
}
Widget _buildStatChangeRow(String label, int oldVal, int newVal) {
int diff = newVal - oldVal;
Color color = diff > 0
? ThemeConfig.statDiffPositive
: (diff < 0
? ThemeConfig.statDiffNegative
: ThemeConfig.statDiffNeutral);
String diffText = diff > 0 ? "(+$diff)" : (diff < 0 ? "($diff)" : "");
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(label),
Row(
children: [
Text(
"$oldVal",
style: const TextStyle(color: ThemeConfig.textColorGrey),
),
const Icon(
Icons.arrow_right,
size: 16,
color: ThemeConfig.textColorGrey,
),
Text(
"$newVal",
style: const TextStyle(fontWeight: ThemeConfig.fontWeightBold),
),
const SizedBox(width: 4),
Text(
diffText,
style: TextStyle(
color: color,
fontSize: 12,
fontWeight: ThemeConfig.fontWeightBold,
),
),
],
),
],
),
);
}
Widget _buildItemStatText(Item item) {
List<String> stats = [];
if (item.atkBonus > 0) stats.add("+${item.atkBonus} ${AppStrings.atk}");
if (item.hpBonus > 0) stats.add("+${item.hpBonus} ${AppStrings.hp}");
if (item.armorBonus > 0) stats.add("+${item.armorBonus} ${AppStrings.def}");
if (item.luck > 0) stats.add("+${item.luck} ${AppStrings.luck}");
// Include effects
List<String> effectTexts = item.effects.map((e) => e.description).toList();
if (stats.isEmpty && effectTexts.isEmpty) return const SizedBox.shrink();
return Column(
children: [
if (stats.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 2.0, bottom: 2.0),
child: Text(
stats.join(", "),
style: const TextStyle(
fontSize: ThemeConfig.fontSizeSmall,
color: ThemeConfig.statAtkColor,
),
textAlign: TextAlign.center,
),
),
if (effectTexts.isNotEmpty)
Padding(
padding: const EdgeInsets.only(bottom: 2.0),
child: Text(
effectTexts.join("\n"),
style: const TextStyle(
fontSize: ThemeConfig.fontSizeTiny,
color: ThemeConfig.rarityLegendary,
),
),
),
],
);
}
}
+52 -10
View File
@@ -28,16 +28,58 @@ class SettingsScreen extends StatelessWidget {
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,
child: Column(
children: [
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(
'Attack Animation Scale',
style: TextStyle(color: ThemeConfig.textColorWhite),
),
Row(
children: [
const Text(
'2.0',
style: TextStyle(color: ThemeConfig.textColorGrey),
),
Expanded(
child: Slider(
value: settings.attackAnimScale,
min: 2.0,
max: 9.9,
divisions: 79,
label: settings.attackAnimScale.toStringAsFixed(1),
activeColor: ThemeConfig.btnActionActive,
inactiveColor: ThemeConfig.textColorGrey,
onChanged: (value) {
settings.setAttackAnimScale(value);
},
),
),
const Text(
'9.9',
style: TextStyle(color: ThemeConfig.textColorGrey),
),
],
),
Text(
'Current: ${settings.attackAnimScale.toStringAsFixed(1)}',
style: const TextStyle(
color: ThemeConfig.textColorWhite,
fontSize: 12,
),
),
],
),
);
},