mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-10-11 02:08:43 +02:00
Multiple cameras on one pole
This commit is contained in:
1 parent
1993714752
commit
d9f415c527
9 files changed
+409
-103
No files matched your search
+109
-29
@@ -12,6 +12,112 @@ class AddNodeSheet extends StatelessWidget {
|
||||
|
||||
final AddNodeSession session;
|
||||
|
||||
Widget _buildDirectionControls(BuildContext context, AppState appState, AddNodeSession session, LocalizationService locService) {
|
||||
final requiresDirection = session.profile != null && session.profile!.requiresDirection;
|
||||
|
||||
// Format direction display text with bold for current direction
|
||||
String directionsText = '';
|
||||
if (requiresDirection) {
|
||||
final directionsWithBold = <String>[];
|
||||
for (int i = 0; i < session.directions.length; i++) {
|
||||
final dirStr = session.directions[i].round().toString();
|
||||
if (i == session.currentDirectionIndex) {
|
||||
directionsWithBold.add('**$dirStr**'); // Mark for bold formatting
|
||||
} else {
|
||||
directionsWithBold.add(dirStr);
|
||||
}
|
||||
}
|
||||
directionsText = directionsWithBold.join(', ');
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
title: requiresDirection
|
||||
? RichText(
|
||||
text: TextSpan(
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
children: [
|
||||
const TextSpan(text: 'Directions: '),
|
||||
if (directionsText.isNotEmpty)
|
||||
...directionsText.split('**').asMap().entries.map((entry) {
|
||||
final isEven = entry.key % 2 == 0;
|
||||
return TextSpan(
|
||||
text: entry.value,
|
||||
style: TextStyle(
|
||||
fontWeight: isEven ? FontWeight.normal : FontWeight.bold,
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Text(locService.t('addNode.direction', params: [session.directionDegrees.round().toString()])),
|
||||
subtitle: Row(
|
||||
children: [
|
||||
// Slider takes most of the space
|
||||
Expanded(
|
||||
child: Slider(
|
||||
min: 0,
|
||||
max: 359,
|
||||
divisions: 359,
|
||||
value: session.directionDegrees,
|
||||
label: session.directionDegrees.round().toString(),
|
||||
onChanged: requiresDirection ? (v) => appState.updateSession(directionDeg: v) : null,
|
||||
),
|
||||
),
|
||||
// Buttons on the right (only show if direction is required)
|
||||
if (requiresDirection) ...[
|
||||
const SizedBox(width: 8),
|
||||
// Remove button
|
||||
IconButton(
|
||||
icon: const Icon(Icons.remove, size: 20),
|
||||
onPressed: session.directions.length > 1 ? () => appState.removeDirection() : null,
|
||||
tooltip: 'Remove current direction',
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
|
||||
),
|
||||
// Add button
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add, size: 20),
|
||||
onPressed: () => appState.addDirection(),
|
||||
tooltip: 'Add new direction',
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
|
||||
),
|
||||
// Cycle button
|
||||
IconButton(
|
||||
icon: const Icon(Icons.repeat, size: 20),
|
||||
onPressed: session.directions.length > 1 ? () => appState.cycleDirection() : null,
|
||||
tooltip: 'Cycle through directions',
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
// Show info text when profile doesn't require direction
|
||||
if (!requiresDirection)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.info_outline, color: Colors.grey, size: 16),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
locService.t('addNode.profileNoDirectionInfo'),
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
@@ -78,35 +184,9 @@ class AddNodeSheet extends StatelessWidget {
|
||||
onChanged: (p) => appState.updateSession(profile: p),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text(locService.t('addNode.direction', params: [session.directionDegrees.round().toString()])),
|
||||
subtitle: Slider(
|
||||
min: 0,
|
||||
max: 359,
|
||||
divisions: 359,
|
||||
value: session.directionDegrees,
|
||||
label: session.directionDegrees.round().toString(),
|
||||
onChanged: (session.profile != null && session.profile!.requiresDirection)
|
||||
? (v) => appState.updateSession(directionDeg: v)
|
||||
: null, // Disabled when no profile selected or profile doesn't require direction
|
||||
),
|
||||
),
|
||||
if (session.profile != null && !session.profile!.requiresDirection)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.info_outline, color: Colors.grey, size: 16),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
locService.t('addNode.profileNoDirectionInfo'),
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Direction controls
|
||||
_buildDirectionControls(context, appState, session, locService),
|
||||
|
||||
if (!appState.isLoggedIn)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
||||
|
||||
@@ -13,6 +13,112 @@ class EditNodeSheet extends StatelessWidget {
|
||||
|
||||
final EditNodeSession session;
|
||||
|
||||
Widget _buildDirectionControls(BuildContext context, AppState appState, EditNodeSession session, LocalizationService locService) {
|
||||
final requiresDirection = session.profile != null && session.profile!.requiresDirection;
|
||||
|
||||
// Format direction display text with bold for current direction
|
||||
String directionsText = '';
|
||||
if (requiresDirection) {
|
||||
final directionsWithBold = <String>[];
|
||||
for (int i = 0; i < session.directions.length; i++) {
|
||||
final dirStr = session.directions[i].round().toString();
|
||||
if (i == session.currentDirectionIndex) {
|
||||
directionsWithBold.add('**$dirStr**'); // Mark for bold formatting
|
||||
} else {
|
||||
directionsWithBold.add(dirStr);
|
||||
}
|
||||
}
|
||||
directionsText = directionsWithBold.join(', ');
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
title: requiresDirection
|
||||
? RichText(
|
||||
text: TextSpan(
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
children: [
|
||||
const TextSpan(text: 'Directions: '),
|
||||
if (directionsText.isNotEmpty)
|
||||
...directionsText.split('**').asMap().entries.map((entry) {
|
||||
final isEven = entry.key % 2 == 0;
|
||||
return TextSpan(
|
||||
text: entry.value,
|
||||
style: TextStyle(
|
||||
fontWeight: isEven ? FontWeight.normal : FontWeight.bold,
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Text(locService.t('editNode.direction', params: [session.directionDegrees.round().toString()])),
|
||||
subtitle: Row(
|
||||
children: [
|
||||
// Slider takes most of the space
|
||||
Expanded(
|
||||
child: Slider(
|
||||
min: 0,
|
||||
max: 359,
|
||||
divisions: 359,
|
||||
value: session.directionDegrees,
|
||||
label: session.directionDegrees.round().toString(),
|
||||
onChanged: requiresDirection ? (v) => appState.updateEditSession(directionDeg: v) : null,
|
||||
),
|
||||
),
|
||||
// Buttons on the right (only show if direction is required)
|
||||
if (requiresDirection) ...[
|
||||
const SizedBox(width: 8),
|
||||
// Remove button
|
||||
IconButton(
|
||||
icon: const Icon(Icons.remove, size: 20),
|
||||
onPressed: session.directions.length > 1 ? () => appState.removeDirection() : null,
|
||||
tooltip: 'Remove current direction',
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
|
||||
),
|
||||
// Add button
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add, size: 20),
|
||||
onPressed: () => appState.addDirection(),
|
||||
tooltip: 'Add new direction',
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
|
||||
),
|
||||
// Cycle button
|
||||
IconButton(
|
||||
icon: const Icon(Icons.repeat, size: 20),
|
||||
onPressed: session.directions.length > 1 ? () => appState.cycleDirection() : null,
|
||||
tooltip: 'Cycle through directions',
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
// Show info text when profile doesn't require direction
|
||||
if (!requiresDirection)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.info_outline, color: Colors.grey, size: 16),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'This profile does not require a direction.',
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
@@ -85,35 +191,9 @@ class EditNodeSheet extends StatelessWidget {
|
||||
onChanged: (p) => appState.updateEditSession(profile: p),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text(locService.t('editNode.direction', params: [session.directionDegrees.round().toString()])),
|
||||
subtitle: Slider(
|
||||
min: 0,
|
||||
max: 359,
|
||||
divisions: 359,
|
||||
value: session.directionDegrees,
|
||||
label: session.directionDegrees.round().toString(),
|
||||
onChanged: (session.profile != null && session.profile!.requiresDirection)
|
||||
? (v) => appState.updateEditSession(directionDeg: v)
|
||||
: null, // Disabled when no profile selected or profile doesn't require direction
|
||||
),
|
||||
),
|
||||
if (session.profile != null && !session.profile!.requiresDirection)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.info_outline, color: Colors.grey, size: 16),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
locService.t('editNode.profileNoDirectionInfo'),
|
||||
style: const TextStyle(color: Colors.grey, fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Direction controls
|
||||
_buildDirectionControls(context, appState, session, locService),
|
||||
|
||||
if (!appState.isLoggedIn)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
||||
|
||||
@@ -18,47 +18,81 @@ class DirectionConesBuilder {
|
||||
}) {
|
||||
final overlays = <Polygon>[];
|
||||
|
||||
// Add session cone if in add-camera mode and profile requires direction
|
||||
// Add session cones if in add-camera mode and profile requires direction
|
||||
if (session != null && session.target != null && session.profile?.requiresDirection == true) {
|
||||
// Add current working direction (full opacity)
|
||||
overlays.add(_buildCone(
|
||||
session.target!,
|
||||
session.directionDegrees,
|
||||
zoom,
|
||||
context: context,
|
||||
isSession: true,
|
||||
isActiveDirection: true,
|
||||
));
|
||||
|
||||
// Add other directions (reduced opacity)
|
||||
for (int i = 0; i < session.directions.length; i++) {
|
||||
if (i != session.currentDirectionIndex) {
|
||||
overlays.add(_buildCone(
|
||||
session.target!,
|
||||
session.directions[i],
|
||||
zoom,
|
||||
context: context,
|
||||
isSession: true,
|
||||
isActiveDirection: false,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add edit session cone if in edit-camera mode and profile requires direction
|
||||
// Add edit session cones if in edit-camera mode and profile requires direction
|
||||
if (editSession != null && editSession.profile?.requiresDirection == true) {
|
||||
// Add current working direction (full opacity)
|
||||
overlays.add(_buildCone(
|
||||
editSession.target,
|
||||
editSession.directionDegrees,
|
||||
zoom,
|
||||
context: context,
|
||||
isSession: true,
|
||||
isActiveDirection: true,
|
||||
));
|
||||
|
||||
// Add other directions (reduced opacity)
|
||||
for (int i = 0; i < editSession.directions.length; i++) {
|
||||
if (i != editSession.currentDirectionIndex) {
|
||||
overlays.add(_buildCone(
|
||||
editSession.target,
|
||||
editSession.directions[i],
|
||||
zoom,
|
||||
context: context,
|
||||
isSession: true,
|
||||
isActiveDirection: false,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add cones for cameras with direction (but exclude camera being edited)
|
||||
overlays.addAll(
|
||||
cameras
|
||||
.where((n) => _isValidCameraWithDirection(n) &&
|
||||
(editSession == null || n.id != editSession.originalNode.id))
|
||||
.map((n) => _buildCone(
|
||||
n.coord,
|
||||
n.directionDeg!,
|
||||
zoom,
|
||||
context: context,
|
||||
))
|
||||
);
|
||||
for (final node in cameras) {
|
||||
if (_isValidCameraWithDirection(node) &&
|
||||
(editSession == null || node.id != editSession.originalNode.id)) {
|
||||
// Build a cone for each direction
|
||||
for (final direction in node.directionDeg) {
|
||||
overlays.add(_buildCone(
|
||||
node.coord,
|
||||
direction,
|
||||
zoom,
|
||||
context: context,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return overlays;
|
||||
}
|
||||
|
||||
static bool _isValidCameraWithDirection(OsmNode node) {
|
||||
return node.hasDirection &&
|
||||
node.directionDeg != null &&
|
||||
(node.coord.latitude != 0 || node.coord.longitude != 0) &&
|
||||
node.coord.latitude.abs() <= 90 &&
|
||||
node.coord.longitude.abs() <= 180;
|
||||
@@ -76,6 +110,7 @@ class DirectionConesBuilder {
|
||||
required BuildContext context,
|
||||
bool isPending = false,
|
||||
bool isSession = false,
|
||||
bool isActiveDirection = true,
|
||||
}) {
|
||||
final halfAngle = kDirectionConeHalfAngle;
|
||||
|
||||
@@ -114,9 +149,15 @@ class DirectionConesBuilder {
|
||||
points.add(project(angle, innerRadius));
|
||||
}
|
||||
|
||||
// Adjust opacity based on direction state
|
||||
double opacity = kDirectionConeOpacity;
|
||||
if (isSession && !isActiveDirection) {
|
||||
opacity = kDirectionConeOpacity * 0.4; // Reduced opacity for inactive session directions
|
||||
}
|
||||
|
||||
return Polygon(
|
||||
points: points,
|
||||
color: kDirectionConeColor.withOpacity(kDirectionConeOpacity),
|
||||
color: kDirectionConeColor.withOpacity(opacity),
|
||||
borderColor: kDirectionConeColor,
|
||||
borderStrokeWidth: getDirectionConeBorderWidth(context),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user