bullet movement navigatior
This commit is contained in:
+235
-62
@@ -3,7 +3,7 @@ import 'dart:typed_data';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../utils/target_colors.dart';
|
import '../utils/target_colors.dart';
|
||||||
import '../theme/app_theme.dart';
|
import '../theme/app_theme.dart';
|
||||||
import 'package:flutter/services.dart' show rootBundle;
|
import 'package:flutter/services.dart' show rootBundle, HapticFeedback;
|
||||||
import 'package:image/image.dart' as img;
|
import 'package:image/image.dart' as img;
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'yolo_detector.dart';
|
import 'yolo_detector.dart';
|
||||||
@@ -63,6 +63,15 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
bool _isEditMode = false;
|
bool _isEditMode = false;
|
||||||
int? _selectedBulletIndexInEdit;
|
int? _selectedBulletIndexInEdit;
|
||||||
|
|
||||||
|
// Hold-and-drag on the edit controller: moves the selected bullet with the
|
||||||
|
// finger while a magnifier shows the area around it.
|
||||||
|
bool _isDragMovingBullet = false;
|
||||||
|
Offset _lastDragOffset = Offset.zero;
|
||||||
|
double _displayScaleX = 1;
|
||||||
|
double _displayScaleY = 1;
|
||||||
|
static const double _loupeSize = 130;
|
||||||
|
static const double _loupeZoom = 2.5;
|
||||||
|
|
||||||
Color get _editColor => Colors.deepOrangeAccent;
|
Color get _editColor => Colors.deepOrangeAccent;
|
||||||
Color get _activeColor => _isEditMode ? _editColor : _bulletColor;
|
Color get _activeColor => _isEditMode ? _editColor : _bulletColor;
|
||||||
Color get _activeColorWithOpacity =>
|
Color get _activeColorWithOpacity =>
|
||||||
@@ -625,7 +634,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
final targetData = {
|
final targetData = {
|
||||||
'date': dateString,
|
'date': dateString,
|
||||||
'totalScore': _totalScore,
|
'totalScore': _totalScore,
|
||||||
'bulletCount': widget.bulletCount, // shots fired; missed ones are absent from 'bullets'
|
'bulletCount': widget
|
||||||
|
.bulletCount, // shots fired; missed ones are absent from 'bullets'
|
||||||
'bullets': bulletsInDefaultCoordinates,
|
'bullets': bulletsInDefaultCoordinates,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -641,76 +651,219 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Score of the bullet at [index], live for manual and detected bullets.
|
||||||
|
int _scoreAt(int index) {
|
||||||
|
final manualStart = _mappedBullets.length - _manualBulletScores.length;
|
||||||
|
if (index >= manualStart) {
|
||||||
|
return _manualBulletScores[index - manualStart];
|
||||||
|
}
|
||||||
|
final b = _mappedBullets[index];
|
||||||
|
return _scoreForBullet(
|
||||||
|
Offset(b.dx / _scaleFactorX, b.dy / _scaleFactorY),
|
||||||
|
fixedRingTargetCenter,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildEditController() {
|
Widget _buildEditController() {
|
||||||
if (!_isEditMode || _selectedBulletIndexInEdit == null) {
|
final index = _selectedBulletIndexInEdit;
|
||||||
|
if (!_isEditMode || index == null || index >= _mappedBullets.length) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final s = Surfaces.current;
|
||||||
|
final accent = _bulletColor;
|
||||||
|
final dragging = _isDragMovingBullet;
|
||||||
|
const padSize = 156.0;
|
||||||
|
const step = 3.0;
|
||||||
|
|
||||||
|
Widget arrow(IconData icon, Offset delta, Alignment align) {
|
||||||
|
return Align(
|
||||||
|
alignment: align,
|
||||||
|
child: Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
shape: const CircleBorder(),
|
||||||
|
clipBehavior: Clip.antiAlias,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () => _moveBullet(delta),
|
||||||
|
child: SizedBox(
|
||||||
|
width: 52,
|
||||||
|
height: 52,
|
||||||
|
child: Icon(icon, size: 34, color: s.textPrimary),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return Positioned(
|
return Positioned(
|
||||||
bottom: 20,
|
bottom: 20,
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Container(
|
child: GestureDetector(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 20),
|
// Hold anywhere on the controller, then drag to move the bullet fast
|
||||||
decoration: BoxDecoration(
|
onLongPressStart: (_) {
|
||||||
color: Colors.black.withValues(alpha: 0.75),
|
HapticFeedback.mediumImpact();
|
||||||
borderRadius: BorderRadius.circular(16),
|
setState(() {
|
||||||
),
|
_isDragMovingBullet = true;
|
||||||
child: Column(
|
_lastDragOffset = Offset.zero;
|
||||||
mainAxisSize: MainAxisSize.min,
|
});
|
||||||
children: [
|
},
|
||||||
// Up
|
onLongPressMoveUpdate: (details) {
|
||||||
IconButton(
|
final delta = details.offsetFromOrigin - _lastDragOffset;
|
||||||
icon: const Icon(Icons.keyboard_arrow_up,
|
_lastDragOffset = details.offsetFromOrigin;
|
||||||
size: 36, color: Colors.white),
|
// Finger movement on screen = bullet movement on screen
|
||||||
onPressed: () => _moveBullet(const Offset(0, -3)),
|
_moveBullet(Offset(
|
||||||
splashRadius: 24,
|
delta.dx / _displayScaleX,
|
||||||
|
delta.dy / _displayScaleY,
|
||||||
|
));
|
||||||
|
},
|
||||||
|
onLongPressEnd: (_) => setState(() => _isDragMovingBullet = false),
|
||||||
|
onLongPressCancel: () => setState(() => _isDragMovingBullet = false),
|
||||||
|
child: AnimatedContainer(
|
||||||
|
duration: const Duration(milliseconds: 150),
|
||||||
|
width: 200,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: s.card,
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
border: Border.all(
|
||||||
|
color: dragging ? accent : Colors.transparent,
|
||||||
|
width: 2,
|
||||||
),
|
),
|
||||||
|
boxShadow: const [
|
||||||
// Left - Check - Right
|
BoxShadow(
|
||||||
Row(
|
color: Colors.black38,
|
||||||
mainAxisSize: MainAxisSize.min,
|
offset: Offset(0, 4),
|
||||||
children: [
|
blurRadius: 12,
|
||||||
IconButton(
|
),
|
||||||
icon: const Icon(Icons.keyboard_arrow_left,
|
],
|
||||||
size: 36, color: Colors.white),
|
),
|
||||||
onPressed: () => _moveBullet(const Offset(-3, 0)),
|
child: Column(
|
||||||
splashRadius: 24,
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
// Header: which bullet, and its live score
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 12, 12, 4),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'${_t('Bullet')} ${index + 1}'.toUpperCase(),
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
letterSpacing: 1.4,
|
||||||
|
color: s.textSecondary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Spacer(),
|
||||||
|
Container(
|
||||||
|
constraints: const BoxConstraints(minWidth: 36),
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 10, vertical: 4),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: accent,
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
),
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: Text(
|
||||||
|
'${_scoreAt(index)}',
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
),
|
||||||
Container(
|
// Round d-pad with "done" in the middle
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||||
|
child: Container(
|
||||||
|
width: padSize,
|
||||||
|
height: padSize,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
color: Colors.greenAccent.withValues(alpha: 0.2),
|
color: s.textPrimary.withValues(alpha: 0.06),
|
||||||
border: Border.all(color: Colors.greenAccent, width: 2),
|
border: Border.all(color: s.divider),
|
||||||
),
|
),
|
||||||
child: IconButton(
|
child: Stack(
|
||||||
icon: const Icon(Icons.check,
|
children: [
|
||||||
color: Colors.greenAccent, size: 28),
|
arrow(Icons.keyboard_arrow_up_rounded,
|
||||||
onPressed: () =>
|
const Offset(0, -step), Alignment.topCenter),
|
||||||
setState(() => _selectedBulletIndexInEdit = null),
|
arrow(Icons.keyboard_arrow_down_rounded,
|
||||||
splashRadius: 22,
|
const Offset(0, step), Alignment.bottomCenter),
|
||||||
|
arrow(Icons.keyboard_arrow_left_rounded,
|
||||||
|
const Offset(-step, 0), Alignment.centerLeft),
|
||||||
|
arrow(Icons.keyboard_arrow_right_rounded,
|
||||||
|
const Offset(step, 0), Alignment.centerRight),
|
||||||
|
Center(
|
||||||
|
child: Material(
|
||||||
|
color: accent,
|
||||||
|
shape: const CircleBorder(),
|
||||||
|
elevation: 2,
|
||||||
|
child: InkWell(
|
||||||
|
customBorder: const CircleBorder(),
|
||||||
|
onTap: () => setState(
|
||||||
|
() => _selectedBulletIndexInEdit = null),
|
||||||
|
child: SizedBox(
|
||||||
|
width: 52,
|
||||||
|
height: 52,
|
||||||
|
child: Icon(
|
||||||
|
dragging
|
||||||
|
? Icons.open_with_rounded
|
||||||
|
: Icons.check_rounded,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 28,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
),
|
||||||
IconButton(
|
Padding(
|
||||||
icon: const Icon(Icons.keyboard_arrow_right,
|
padding: const EdgeInsets.only(bottom: 12),
|
||||||
size: 36, color: Colors.white),
|
child: Text(
|
||||||
onPressed: () => _moveBullet(const Offset(3, 0)),
|
_t('Hold and drag to move'),
|
||||||
splashRadius: 24,
|
style: TextStyle(fontSize: 11, color: s.textSecondary),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Down
|
/// Magnifier shown above the selected bullet while it is being dragged.
|
||||||
IconButton(
|
Widget _buildBulletLoupe(Offset bullet, double scaleX, double scaleY,
|
||||||
icon: const Icon(Icons.keyboard_arrow_down,
|
double offsetX, double offsetY) {
|
||||||
size: 36, color: Colors.white),
|
final bx = bullet.dx * scaleX + offsetX;
|
||||||
onPressed: () => _moveBullet(const Offset(0, 3)),
|
final by = bullet.dy * scaleY + offsetY;
|
||||||
splashRadius: 24,
|
const gap = _loupeSize / 2 + 40;
|
||||||
),
|
// Put the loupe above the bullet, or below it when there is no room.
|
||||||
],
|
final cy = by - gap - _loupeSize / 2 >= 0 ? by - gap : by + gap;
|
||||||
|
return Positioned(
|
||||||
|
left: bx - _loupeSize / 2,
|
||||||
|
top: cy - _loupeSize / 2,
|
||||||
|
child: IgnorePointer(
|
||||||
|
child: RawMagnifier(
|
||||||
|
size: const Size(_loupeSize, _loupeSize),
|
||||||
|
magnificationScale: _loupeZoom,
|
||||||
|
focalPointOffset: Offset(0, by - cy),
|
||||||
|
decoration: const MagnifierDecoration(
|
||||||
|
shape: CircleBorder(
|
||||||
|
side: BorderSide(color: Colors.white, width: 3),
|
||||||
|
),
|
||||||
|
shadows: [BoxShadow(color: Colors.black54, blurRadius: 8)],
|
||||||
|
),
|
||||||
|
child: const Center(
|
||||||
|
child: Icon(Icons.add, color: Colors.red, size: 24),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -773,8 +926,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
final num = int.parse(training.group(1)!);
|
final num = int.parse(training.group(1)!);
|
||||||
if (num >= trainingCount) trainingCount = num + 1;
|
if (num >= trainingCount) trainingCount = num + 1;
|
||||||
}
|
}
|
||||||
final tournament =
|
final tournament = RegExp(r'^(?:Tournament|Tekmovanje|Wettkampf) (\d+)$')
|
||||||
RegExp(r'^(?:Tournament|Tekmovanje|Wettkampf) (\d+)$').firstMatch(name);
|
.firstMatch(name);
|
||||||
if (tournament != null) {
|
if (tournament != null) {
|
||||||
final num = int.parse(tournament.group(1)!);
|
final num = int.parse(tournament.group(1)!);
|
||||||
if (num >= tournamentCount) tournamentCount = num + 1;
|
if (num >= tournamentCount) tournamentCount = num + 1;
|
||||||
@@ -1112,6 +1265,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
|
|
||||||
final scaleX = displayWidth / imgWidth;
|
final scaleX = displayWidth / imgWidth;
|
||||||
final scaleY = displayHeight / imgHeight;
|
final scaleY = displayHeight / imgHeight;
|
||||||
|
_displayScaleX = scaleX;
|
||||||
|
_displayScaleY = scaleY;
|
||||||
|
|
||||||
final imageWidget =
|
final imageWidget =
|
||||||
Image.memory(displayImage, fit: BoxFit.fill);
|
Image.memory(displayImage, fit: BoxFit.fill);
|
||||||
@@ -1220,6 +1375,18 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
if (_mode == PreviewMode.mappedTarget &&
|
||||||
|
_isDragMovingBullet &&
|
||||||
|
_selectedBulletIndexInEdit != null &&
|
||||||
|
_selectedBulletIndexInEdit! <
|
||||||
|
_mappedBullets.length)
|
||||||
|
_buildBulletLoupe(
|
||||||
|
_mappedBullets[_selectedBulletIndexInEdit!],
|
||||||
|
scaleX,
|
||||||
|
scaleY,
|
||||||
|
offsetX,
|
||||||
|
offsetY,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -1313,7 +1480,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
Container(
|
Container(
|
||||||
height: 30,
|
height: 30,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Surfaces.current.card,
|
color:
|
||||||
|
Surfaces.current.card,
|
||||||
borderRadius:
|
borderRadius:
|
||||||
const BorderRadius
|
const BorderRadius
|
||||||
.only(
|
.only(
|
||||||
@@ -1330,7 +1498,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
fontWeight:
|
fontWeight:
|
||||||
FontWeight.bold,
|
FontWeight.bold,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: Surfaces.current.textPrimary,
|
color: Surfaces.current
|
||||||
|
.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -1405,7 +1574,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
Container(
|
Container(
|
||||||
height: 30,
|
height: 30,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Surfaces.current.card,
|
color:
|
||||||
|
Surfaces.current.card,
|
||||||
borderRadius:
|
borderRadius:
|
||||||
const BorderRadius
|
const BorderRadius
|
||||||
.only(
|
.only(
|
||||||
@@ -1422,7 +1592,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
fontWeight:
|
fontWeight:
|
||||||
FontWeight.bold,
|
FontWeight.bold,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: Surfaces.current.textPrimary,
|
color: Surfaces.current
|
||||||
|
.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -1530,7 +1701,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.create_new_folder_outlined, color: Colors.white, size: 24),
|
icon: const Icon(Icons.create_new_folder_outlined,
|
||||||
|
color: Colors.white, size: 24),
|
||||||
onPressed: _saveTargetDataWithDialog,
|
onPressed: _saveTargetDataWithDialog,
|
||||||
tooltip: _t("Save to folder"),
|
tooltip: _t("Save to folder"),
|
||||||
),
|
),
|
||||||
@@ -1546,7 +1718,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
|
|||||||
_selectedBulletIndexInEdit = null;
|
_selectedBulletIndexInEdit = null;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
tooltip: _isEditMode ? _t("Done Editing") : _t("Edit Mode"),
|
tooltip:
|
||||||
|
_isEditMode ? _t("Done Editing") : _t("Edit Mode"),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -192,6 +192,11 @@ class AppTranslations {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Camera settings
|
// Camera settings
|
||||||
|
'Hold and drag to move': {
|
||||||
|
'English': 'Hold and drag to move',
|
||||||
|
'Slovenian': 'Pridrži in povleci za premik',
|
||||||
|
'German': 'Halten und ziehen zum Verschieben',
|
||||||
|
},
|
||||||
'About': {
|
'About': {
|
||||||
'English': 'About',
|
'English': 'About',
|
||||||
'Slovenian': 'O aplikaciji',
|
'Slovenian': 'O aplikaciji',
|
||||||
|
|||||||
Reference in New Issue
Block a user