added new tragets... fixed some issues.
This commit is contained in:
+243
-288
@@ -6,6 +6,7 @@ import 'dart:convert';
|
||||
import 'package:image/image.dart' as img;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../utils/translations.dart';
|
||||
import '../utils/target_colors.dart';
|
||||
|
||||
class TargetViewScreen extends StatefulWidget {
|
||||
final List<File> jsonFiles;
|
||||
@@ -37,7 +38,6 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
late String _targetFilePath;
|
||||
late String targetAssetPath;
|
||||
late String _selectedTargetPath; // For display
|
||||
final double bulletSize = 19;
|
||||
double _scaleFactorX = 1.0; // Scale factor for X coordinate
|
||||
double _scaleFactorY = 1.0; // Scale factor for Y coordinate
|
||||
|
||||
@@ -45,7 +45,6 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
String _selectedLanguage = 'English';
|
||||
Color _backgroundColor = Colors.white;
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -75,7 +74,8 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
|
||||
Future<void> _loadSelectedTarget() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final selectedTarget = prefs.getString('selectedTarget') ?? 'assets/target.png';
|
||||
final selectedTarget =
|
||||
prefs.getString('selectedTarget') ?? 'assets/target.png';
|
||||
// Always use default target for bullet positioning
|
||||
targetAssetPath = 'assets/target.png';
|
||||
// Store selected target for display
|
||||
@@ -84,110 +84,54 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
}
|
||||
|
||||
Color _getBackgroundColorForTarget(String targetPath) {
|
||||
// Map each target to its background color (extracted from first pixel of each image)
|
||||
switch (targetPath) {
|
||||
case 'assets/target.png':
|
||||
return const Color(0xFFFFFFFF); // White
|
||||
case 'assets/targets/Target1.jpg':
|
||||
return const Color(0xFFE8ECD5); // Light beige
|
||||
case 'assets/targets/Target2.jpg':
|
||||
return const Color(0xFFC1DF87); // Light green
|
||||
case 'assets/targets/Target3.jpg':
|
||||
return const Color(0xFFFEFEFE); // Off-white
|
||||
case 'assets/targets/Target4.jpg':
|
||||
return const Color(0xFFD42931); // Red
|
||||
case 'assets/targets/Target5.jpg':
|
||||
return const Color(0xFF02050A); // Very dark blue/black
|
||||
case 'assets/targets/Target6.jpg':
|
||||
return const Color(0xFFF3E7D1); // Light beige
|
||||
case 'assets/targets/Target7.jpg':
|
||||
return const Color(0xFFFFD454); // Bright yellow
|
||||
case 'assets/targets/Target8.jpg':
|
||||
return const Color(0xFF1E5E81); // Dark teal blue
|
||||
case 'assets/targets/Target9.jpg':
|
||||
return const Color(0xFFFEFEFC); // Off-white
|
||||
case 'assets/targets/Target10.jpg':
|
||||
return const Color(0xFF98926E); // Olive green
|
||||
case 'assets/targets/Target11.jpg':
|
||||
return const Color(0xFF13132B); // Dark blue
|
||||
case 'assets/targets/Target12.jpg':
|
||||
return const Color(0xFFF5F4EF); // Off-white
|
||||
case 'assets/targets/Target13.jpg':
|
||||
return const Color(0xFF174AA5); // Blue
|
||||
case 'assets/targets/Target14.jpg':
|
||||
return const Color(0xFFFEE05E); // Light yellow
|
||||
case 'assets/targets/Target15.jpg':
|
||||
return const Color(0xFFFFFFFF); // White
|
||||
case 'assets/targets/Target16.jpg':
|
||||
return const Color(0xFF000000); // Black
|
||||
case 'assets/targets/Target17.jpg':
|
||||
return const Color(0xFF13132B); // Dark blue
|
||||
case 'assets/targets/Target18.jpg':
|
||||
return const Color(0xFF050608); // Very dark gray
|
||||
case 'assets/targets/Target19.jpg':
|
||||
return const Color(0xFFC32534); // Dark red
|
||||
case 'assets/targets/Target20.jpg':
|
||||
return const Color(0xFFFCF3EE); // Light beige
|
||||
case 'assets/targets/Target21.jpg':
|
||||
return const Color(0xFFDA6868); // Muted red
|
||||
case 'assets/targets/Target22.jpg':
|
||||
return const Color(0xFFFDFAF3); // Off-white
|
||||
case 'assets/targets/Target23.jpg':
|
||||
return const Color(0xFFFFFFFD); // White
|
||||
case 'assets/targets/Target24.jpg':
|
||||
return const Color(0xFFFFC4C6); // Light pink
|
||||
default:
|
||||
return Colors.white; // Fallback to white
|
||||
}
|
||||
return TargetColors.getBackgroundColor(targetPath);
|
||||
}
|
||||
|
||||
Future<void> _loadBulletColor() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final selectedColor = prefs.getString('bulletColor') ?? 'Blue';
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final selectedColor = prefs.getString('bulletColor') ?? 'Blue';
|
||||
|
||||
setState(() {
|
||||
_bulletColor = _getColorFromName(selectedColor);
|
||||
});
|
||||
}
|
||||
setState(() {
|
||||
_bulletColor = _getColorFromName(selectedColor);
|
||||
});
|
||||
}
|
||||
|
||||
Color _getColorFromName(String colorName) {
|
||||
switch (colorName.toLowerCase()) {
|
||||
case 'blue':
|
||||
return Colors.blue;
|
||||
case 'green':
|
||||
return Colors.green;
|
||||
case 'yellow':
|
||||
return Colors.yellow;
|
||||
case 'purple':
|
||||
return Colors.purple;
|
||||
case 'cyan':
|
||||
return Colors.cyan;
|
||||
case 'teal':
|
||||
return Colors.teal;
|
||||
case 'indigo':
|
||||
return Colors.indigo;
|
||||
case 'pink':
|
||||
return Colors.pink;
|
||||
case 'lime':
|
||||
return Colors.lime;
|
||||
case 'mint':
|
||||
return Colors.greenAccent;
|
||||
case 'orange':
|
||||
return Colors.orange;
|
||||
case 'violet':
|
||||
return Colors.deepPurpleAccent;
|
||||
case 'amber':
|
||||
return Colors.amber;
|
||||
case 'brown':
|
||||
return Colors.brown;
|
||||
case 'grey':
|
||||
return Colors.grey;
|
||||
default:
|
||||
return Colors.blue; // fallback
|
||||
switch (colorName.toLowerCase()) {
|
||||
case 'blue':
|
||||
return Colors.blue;
|
||||
case 'green':
|
||||
return Colors.green;
|
||||
case 'yellow':
|
||||
return Colors.yellow;
|
||||
case 'purple':
|
||||
return Colors.purple;
|
||||
case 'cyan':
|
||||
return Colors.cyan;
|
||||
case 'teal':
|
||||
return Colors.teal;
|
||||
case 'indigo':
|
||||
return Colors.indigo;
|
||||
case 'pink':
|
||||
return Colors.pink;
|
||||
case 'lime':
|
||||
return Colors.lime;
|
||||
case 'mint':
|
||||
return Colors.greenAccent;
|
||||
case 'orange':
|
||||
return Colors.orange;
|
||||
case 'violet':
|
||||
return Colors.deepPurpleAccent;
|
||||
case 'amber':
|
||||
return Colors.amber;
|
||||
case 'brown':
|
||||
return Colors.brown;
|
||||
case 'grey':
|
||||
return Colors.grey;
|
||||
default:
|
||||
return Colors.blue; // fallback
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Future<void> _loadJsonAndImage() async {
|
||||
try {
|
||||
@@ -217,7 +161,8 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
return;
|
||||
}
|
||||
|
||||
_targetImageBytes = Uint8List.fromList(img.encodePng(_targetImageDecoded!));
|
||||
_targetImageBytes =
|
||||
Uint8List.fromList(img.encodePng(_targetImageDecoded!));
|
||||
|
||||
final currentFile = widget.jsonFiles[_currentIndex];
|
||||
final jsonString = await currentFile.readAsString();
|
||||
@@ -322,7 +267,8 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
backgroundColor: Colors.grey[900],
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
@@ -341,7 +287,8 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_t("Are you sure you want to delete this target?"),
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 16),
|
||||
style: const TextStyle(
|
||||
color: Colors.white70, fontSize: 16),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
@@ -357,7 +304,8 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.redAccent,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
@@ -375,7 +323,8 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.grey[800],
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
@@ -389,7 +338,6 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -425,6 +373,10 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
|
||||
final scaleX = displayWidth / imgWidth;
|
||||
final scaleY = displayHeight / imgHeight;
|
||||
// Scale bullet size by target scale factors and display scale factors
|
||||
final dynamicBulletSize =
|
||||
(((_scaleFactorX + _scaleFactorY) / 2) * 53) *
|
||||
((scaleX + scaleY) / 2);
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
@@ -433,39 +385,42 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
top: offsetY,
|
||||
width: displayWidth,
|
||||
height: displayHeight,
|
||||
child: Image.memory(_targetImageBytes!, fit: BoxFit.fill),
|
||||
child: Image.memory(_targetImageBytes!,
|
||||
fit: BoxFit.fill),
|
||||
),
|
||||
..._scaledBullets.asMap().entries.map((entry) {
|
||||
final i = entry.key;
|
||||
final scaledBullet = entry.value;
|
||||
// Scaled bullets are already scaled to display target dimensions
|
||||
final dx = scaledBullet.dx * scaleX + offsetX;
|
||||
final dy = scaledBullet.dy * scaleY + offsetY;
|
||||
// Score is calculated using original bullet position and default target center
|
||||
final originalBullet = _bullets[i];
|
||||
final score = _scoreForBullet(originalBullet, _targetCenter ?? Offset.zero);
|
||||
final isHighlighted = widget.isCombinedView
|
||||
? (_pressedScoreGroup == score)
|
||||
: (i == _highlightedBulletIndex);
|
||||
final i = entry.key;
|
||||
final scaledBullet = entry.value;
|
||||
// Scaled bullets are already scaled to display target dimensions
|
||||
final dx = scaledBullet.dx * scaleX + offsetX;
|
||||
final dy = scaledBullet.dy * scaleY + offsetY;
|
||||
// Score is calculated using original bullet position and default target center
|
||||
final originalBullet = _bullets[i];
|
||||
final score = _scoreForBullet(
|
||||
originalBullet, _targetCenter ?? Offset.zero);
|
||||
final isHighlighted = widget.isCombinedView
|
||||
? (_pressedScoreGroup == score)
|
||||
: (i == _highlightedBulletIndex);
|
||||
|
||||
return Positioned(
|
||||
left: dx - bulletSize / 2,
|
||||
top: dy - bulletSize / 2,
|
||||
child: Container(
|
||||
width: bulletSize,
|
||||
height: bulletSize,
|
||||
decoration: BoxDecoration(
|
||||
color: _bulletColor.withOpacity(0.8),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: isHighlighted ? Colors.red : Colors.black,
|
||||
width: isHighlighted ? 3 : 1,
|
||||
return Positioned(
|
||||
left: dx - dynamicBulletSize / 2,
|
||||
top: dy - dynamicBulletSize / 2,
|
||||
child: Container(
|
||||
width: dynamicBulletSize,
|
||||
height: dynamicBulletSize,
|
||||
decoration: BoxDecoration(
|
||||
color: _bulletColor.withValues(alpha: 0.8),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: isHighlighted
|
||||
? Colors.red
|
||||
: Colors.black,
|
||||
width: isHighlighted ? 3 : 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
})
|
||||
.toList(),
|
||||
);
|
||||
}).toList(),
|
||||
],
|
||||
);
|
||||
},
|
||||
@@ -474,7 +429,8 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
color: _backgroundColor,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
child: Row(
|
||||
children: widget.isCombinedView
|
||||
? _buildGroupedScoreButtons()
|
||||
@@ -497,7 +453,8 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.track_changes, size: 28, color: Colors.white),
|
||||
const Icon(Icons.track_changes,
|
||||
size: 28, color: Colors.white),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
"${_t('Total score')} $_totalScore",
|
||||
@@ -518,55 +475,146 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
}
|
||||
|
||||
List<Widget> _buildGroupedScoreButtons() {
|
||||
final Map<int, int> scoreGroups = {};
|
||||
for (final bullet in _bullets) {
|
||||
final score = _scoreForBullet(bullet, _targetCenter!);
|
||||
scoreGroups[score] = (scoreGroups[score] ?? 0) + 1;
|
||||
}
|
||||
final Map<int, int> scoreGroups = {};
|
||||
for (final bullet in _bullets) {
|
||||
final score = _scoreForBullet(bullet, _targetCenter!);
|
||||
scoreGroups[score] = (scoreGroups[score] ?? 0) + 1;
|
||||
}
|
||||
|
||||
// Sort scores descending (10 → 0)
|
||||
final sortedEntries = scoreGroups.entries.toList()
|
||||
..sort((a, b) => b.key.compareTo(a.key));
|
||||
// Sort scores descending (10 → 0)
|
||||
final sortedEntries = scoreGroups.entries.toList()
|
||||
..sort((a, b) => b.key.compareTo(a.key));
|
||||
|
||||
return sortedEntries.map((entry) {
|
||||
final score = entry.key;
|
||||
final count = entry.value;
|
||||
return sortedEntries.map((entry) {
|
||||
final score = entry.key;
|
||||
final count = entry.value;
|
||||
|
||||
return Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
child: GestureDetector(
|
||||
onTapDown: (_) => setState(() => _pressedScoreGroup = score),
|
||||
onTapUp: (_) => setState(() => _pressedScoreGroup = null),
|
||||
onTapCancel: () => setState(() => _pressedScoreGroup = null),
|
||||
child: Container(
|
||||
height: 100,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: Colors.black26,
|
||||
offset: Offset(0, 2),
|
||||
blurRadius: 6,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 30,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[300],
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(16),
|
||||
topRight: Radius.circular(16),
|
||||
return Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
child: GestureDetector(
|
||||
onTapDown: (_) => setState(() => _pressedScoreGroup = score),
|
||||
onTapUp: (_) => setState(() => _pressedScoreGroup = null),
|
||||
onTapCancel: () => setState(() => _pressedScoreGroup = null),
|
||||
child: Container(
|
||||
height: 100,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: Colors.black26,
|
||||
offset: Offset(0, 2),
|
||||
blurRadius: 6,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 30,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[300],
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(16),
|
||||
topRight: Radius.circular(16),
|
||||
),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
'${count}x',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: _pressedScoreGroup == score
|
||||
? Colors.red[400]
|
||||
: _bulletColor.withValues(alpha: 0.85),
|
||||
borderRadius: const BorderRadius.only(
|
||||
bottomLeft: Radius.circular(16),
|
||||
bottomRight: Radius.circular(16),
|
||||
),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
'$score',
|
||||
style: const TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<Widget> _buildIndividualScoreButtons() {
|
||||
final scoredBullets = _bullets.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final bullet = entry.value;
|
||||
final score = _scoreForBullet(bullet, _targetCenter ?? Offset.zero);
|
||||
return {'index': index, 'score': score, 'bullet': bullet};
|
||||
}).toList();
|
||||
|
||||
// Sort descending by score
|
||||
scoredBullets
|
||||
.sort((a, b) => (b['score'] as int).compareTo(a['score'] as int));
|
||||
|
||||
return scoredBullets.map((entry) {
|
||||
final int index = entry['index'] as int;
|
||||
final int score = entry['score'] as int;
|
||||
|
||||
return Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
child: GestureDetector(
|
||||
onTapDown: (_) => setState(() => _highlightedBulletIndex = index),
|
||||
onTapUp: (_) => setState(() => _highlightedBulletIndex = null),
|
||||
onTapCancel: () => setState(() => _highlightedBulletIndex = null),
|
||||
child: Container(
|
||||
height: 100,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: Colors.black26,
|
||||
offset: Offset(0, 2),
|
||||
blurRadius: 6,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 30,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[300],
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(16),
|
||||
topRight: Radius.circular(16),
|
||||
),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'${count}x',
|
||||
'${index + 1}',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
@@ -574,21 +622,18 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: _pressedScoreGroup == score
|
||||
? Colors.red[400]
|
||||
: _bulletColor.withOpacity(0.85),
|
||||
borderRadius: const BorderRadius.only(
|
||||
bottomLeft: Radius.circular(16),
|
||||
bottomRight: Radius.circular(16),
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: _highlightedBulletIndex == index
|
||||
? Colors.red[400]
|
||||
: _bulletColor.withValues(alpha: 0.85),
|
||||
borderRadius: const BorderRadius.only(
|
||||
bottomLeft: Radius.circular(16),
|
||||
bottomRight: Radius.circular(16),
|
||||
),
|
||||
),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'$score',
|
||||
style: const TextStyle(
|
||||
@@ -599,102 +644,12 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<Widget> _buildIndividualScoreButtons() {
|
||||
final scoredBullets = _bullets.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final bullet = entry.value;
|
||||
final score = _scoreForBullet(bullet, _targetCenter ?? Offset.zero);
|
||||
return {'index': index, 'score': score, 'bullet': bullet};
|
||||
}).toList();
|
||||
|
||||
// Sort descending by score
|
||||
scoredBullets.sort((a, b) => (b['score'] as int).compareTo(a['score'] as int));
|
||||
|
||||
return scoredBullets.map((entry) {
|
||||
final int index = entry['index'] as int;
|
||||
final int score = entry['score'] as int;
|
||||
|
||||
return Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
child: GestureDetector(
|
||||
onTapDown: (_) => setState(() => _highlightedBulletIndex = index),
|
||||
onTapUp: (_) => setState(() => _highlightedBulletIndex = null),
|
||||
onTapCancel: () => setState(() => _highlightedBulletIndex = null),
|
||||
child: Container(
|
||||
height: 100,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
color: Colors.black26,
|
||||
offset: Offset(0, 2),
|
||||
blurRadius: 6,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 30,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[300],
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(16),
|
||||
topRight: Radius.circular(16),
|
||||
),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'${index + 1}',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: _highlightedBulletIndex == index
|
||||
? Colors.red[400]
|
||||
: _bulletColor.withOpacity(0.85),
|
||||
borderRadius: const BorderRadius.only(
|
||||
bottomLeft: Radius.circular(16),
|
||||
bottomRight: Radius.circular(16),
|
||||
),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'$score',
|
||||
style: const TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user