diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index d9de399f..98a1974a 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -37,6 +37,7 @@ DD41582A28585C32009B0E59 /* RangeTestConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD41582928585C32009B0E59 /* RangeTestConfig.swift */; }; DD41A61529AB0035003C5A37 /* NodeWeatherForecast.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD41A61429AB0035003C5A37 /* NodeWeatherForecast.swift */; }; DD457188293C7E63000C49FB /* BLESignalStrengthIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD457187293C7E63000C49FB /* BLESignalStrengthIndicator.swift */; }; + DD4640202AFF10F4002A5ECB /* WaypointForm.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD46401F2AFF10F4002A5ECB /* WaypointForm.swift */; }; DD47E3D626F17ED900029299 /* CircleText.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD47E3D526F17ED900029299 /* CircleText.swift */; }; DD4A911E2708C65400501B7E /* AppSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD4A911D2708C65400501B7E /* AppSettings.swift */; }; DD4F23CD28779A3C001D37CB /* EnvironmentMetricsLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD4F23CC28779A3C001D37CB /* EnvironmentMetricsLog.swift */; }; @@ -246,6 +247,7 @@ DD41A61E29AE7E8F003C5A37 /* SwiftUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftUI.framework; path = System/Library/Frameworks/SwiftUI.framework; sourceTree = SDKROOT; }; DD457187293C7E63000C49FB /* BLESignalStrengthIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BLESignalStrengthIndicator.swift; sourceTree = ""; }; DD457BC4295D5E35004BCE4D /* MeshtasticDataModelV5.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MeshtasticDataModelV5.xcdatamodel; sourceTree = ""; }; + DD46401F2AFF10F4002A5ECB /* WaypointForm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WaypointForm.swift; sourceTree = ""; }; DD47E3D526F17ED900029299 /* CircleText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircleText.swift; sourceTree = ""; }; DD4A911D2708C65400501B7E /* AppSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSettings.swift; sourceTree = ""; }; DD4F23CC28779A3C001D37CB /* EnvironmentMetricsLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnvironmentMetricsLog.swift; sourceTree = ""; }; @@ -633,6 +635,7 @@ isa = PBXGroup; children = ( DDB6CCFA2AAF805100945AF6 /* NodeMapSwiftUI.swift */, + DD46401F2AFF10F4002A5ECB /* WaypointForm.swift */, ); path = Map; sourceTree = ""; @@ -1097,6 +1100,7 @@ DD4F23CD28779A3C001D37CB /* EnvironmentMetricsLog.swift in Sources */, DD41A61529AB0035003C5A37 /* NodeWeatherForecast.swift in Sources */, DDB6ABD628AE742000384BA1 /* BluetoothConfig.swift in Sources */, + DD4640202AFF10F4002A5ECB /* WaypointForm.swift in Sources */, DD769E0328D18BF1001A3F05 /* DeviceMetricsLog.swift in Sources */, DDAF8C5326EB1DF10058C060 /* BLEManager.swift in Sources */, DDDB445229F8ACF900EE2349 /* Date.swift in Sources */, diff --git a/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift b/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift new file mode 100644 index 00000000..3ab7fb0a --- /dev/null +++ b/Meshtastic/Views/Nodes/Helpers/Map/WaypointForm.swift @@ -0,0 +1,53 @@ + +// +// WaypointForm.swift +// Meshtastic +// +// Copyright Garth Vander Houwen 1/10/23. +// + +import SwiftUI +import CoreLocation + +struct WaypointForm: View { + + @EnvironmentObject var bleManager: BLEManager + @Environment(\.dismiss) private var dismiss + @State var waypoint: WaypointEntity + + + + @FocusState private var iconIsFocused: Bool + @State private var name: String = "" + @State private var description: String = "" + @State private var icon: String = "📍" + @State private var latitude: Double = 0 + @State private var longitude: Double = 0 + @State private var expires: Bool = false + @State private var expire: Date = Date.now.addingTimeInterval(60 * 480) // 1 minute * 480 = 8 Hours + @State private var locked: Bool = false + @State private var lockedTo: Int64 = 0 + + var body: some View { + + ZStack { + Form { + Section(header: Text("Waypoint Options")) { + + } + } +#if targetEnvironment(macCatalyst) + Spacer() + Button { + dismiss() + } label: { + Label("close", systemImage: "xmark") + } + .buttonStyle(.bordered) + .buttonBorderShape(.capsule) + .controlSize(.large) + .padding(.bottom) +#endif + } + } +} diff --git a/Meshtastic/Views/Nodes/MeshMap.swift b/Meshtastic/Views/Nodes/MeshMap.swift index de21cb0d..99ffa4f5 100644 --- a/Meshtastic/Views/Nodes/MeshMap.swift +++ b/Meshtastic/Views/Nodes/MeshMap.swift @@ -36,8 +36,10 @@ struct MeshMap: View { @State var isEditingSettings = false @State var selectedPosition: PositionEntity? @State var showWaypoints = false + @State var editingWaypoint: WaypointEntity? @State var selectedWaypoint: WaypointEntity? - @State var newWaypointLocation :CLLocationCoordinate2D? = nil + + @State var newWaypoint :CLLocationCoordinate2D? var delay: Double = 0 @State private var scale: CGFloat = 0.5 @@ -151,9 +153,20 @@ struct MeshMap: View { } } } - .onTapGesture(perform: { screenCoord in - newWaypointLocation = reader.convert(screenCoord, from: .local) - print("Tapped at \(newWaypointLocation)") + .gesture(LongPressGesture(minimumDuration: 0.5).sequenced(before: DragGesture(minimumDistance: 0, coordinateSpace: .local)) + .onEnded { value in + switch value { + case .second(true, let drag): + /// Convert the touch point to a Coordinate + newWaypoint = reader.convert(drag?.location ?? .zero, from: .local) + /// Create a new WaypointEntity using the values from the newWaypoint which will trigger the WaypointForm sheet + editingWaypoint = WaypointEntity(context: context) + editingWaypoint!.name = "Waypoint Pin" + editingWaypoint!.latitudeI = Int32(newWaypoint?.latitude ?? 0 * 1e7) + editingWaypoint!.longitudeI = Int32(newWaypoint?.longitude ?? 0 * 1e7) + default: + break + } }) } } @@ -180,6 +193,10 @@ struct MeshMap: View { WaypointPopover(waypoint: selection) .padding() } + .sheet(item: $editingWaypoint) { selection in + WaypointForm(waypoint: selection) + .padding() + } .sheet(isPresented: $isEditingSettings) { MapSettingsForm(nodeHistory: $showNodeHistory, routeLines: $showRouteLines, convexHull: $showConvexHull, traffic: $showTraffic, pointsOfInterest: $showPointsOfInterest, mapLayer: $selectedMapLayer) } @@ -246,14 +263,8 @@ struct MeshMap: View { } } .navigationTitle("Mesh Map") - .navigationBarItems(leading: - MeshtasticLogo(), trailing: - ZStack { - ConnectedDevice( - bluetoothOn: bleManager.isSwitchedOn, - deviceConnected: bleManager.connectedPeripheral != nil, - name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName : - "?") + .navigationBarItems(leading: MeshtasticLogo(), trailing: ZStack { + ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName : "?") }) .onAppear { UIApplication.shared.isIdleTimerDisabled = true