fixed controller and coloring

This commit is contained in:
2025-04-07 20:35:07 +02:00
parent aeda7ddd2e
commit b822fe1ca3
2 changed files with 144 additions and 112 deletions
+105 -88
View File
@@ -43,7 +43,7 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
@override
void initState() {
super.initState();
_loadBulletColor(); // 👈 this will load bullet color
_loadBulletColor();
_loadJsonAndImage();
}
@@ -285,32 +285,33 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
child: Image.memory(_targetImageBytes!, fit: BoxFit.fill),
),
..._bullets.asMap().entries.map((entry) {
final i = entry.key;
final bullet = entry.value;
final dx = bullet.dx * scaleX + offsetX;
final dy = bullet.dy * scaleY + offsetY;
final score = _scoreForBullet(bullet, _targetCenter!);
final isHighlighted = widget.isCombinedView
? (_pressedScoreGroup == score)
: (i == _highlightedBulletIndex);
final i = entry.key;
final bullet = entry.value;
final dx = bullet.dx * scaleX + offsetX;
final dy = bullet.dy * scaleY + offsetY;
final score = _scoreForBullet(bullet, _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 - 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,
),
),
);
}).toList(),
),
);
})
.toList(),
],
);
},
@@ -355,7 +356,11 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
scoreGroups[score] = (scoreGroups[score] ?? 0) + 1;
}
return scoreGroups.entries.map((entry) {
// 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;
@@ -370,10 +375,10 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
height: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
boxShadow: [
boxShadow: const [
BoxShadow(
color: Colors.black26,
offset: const Offset(0, 2),
offset: Offset(0, 2),
blurRadius: 6,
),
],
@@ -406,8 +411,8 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
child: Container(
decoration: BoxDecoration(
color: _pressedScoreGroup == score
? Colors.red[400]
: _bulletColor.withOpacity(0.85),
? Colors.red[400]
: _bulletColor.withOpacity(0.85),
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(16),
bottomRight: Radius.circular(16),
@@ -437,79 +442,91 @@ class _TargetViewScreenState extends State<TargetViewScreen> {
}
List<Widget> _buildIndividualScoreButtons() {
return List.generate(_bullets.length, (index) {
final bullet = _bullets[index];
final score = _scoreForBullet(bullet, _targetCenter!);
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: [
BoxShadow(
color: Colors.black26,
offset: const Offset(0, 2),
blurRadius: 6,
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),
),
),
],
),
child: Column(
children: [
Container(
height: 30,
alignment: Alignment.center,
child: Text(
'${index + 1}',
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14,
color: Colors.black87,
),
),
),
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.grey[300],
color: _highlightedBulletIndex == index
? Colors.red[400]
: _bulletColor.withOpacity(0.85),
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16),
bottomLeft: Radius.circular(16),
bottomRight: Radius.circular(16),
),
),
alignment: Alignment.center,
child: Text(
'${index + 1}',
'$score',
style: const TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
fontSize: 14,
color: Colors.black87,
color: Colors.white,
),
),
),
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();
}
}