public static void AddLocation(EDLocation location) { if (_locations == null) { LoadLocations(); } if (String.IsNullOrEmpty(location.Name)) { int count = 1; bool nameIsUnique = true; string locationName; do { nameIsUnique = true; locationName = $"Location {count}"; foreach (EDLocation l in _locations) { if (l.Name.Equals(locationName)) { nameIsUnique = false; break; } } count++; } while (!nameIsUnique); location.Name = locationName; } _locations.Add(location); SaveLocationsToFile(); LocationAdded?.Invoke(null, location); }
public static void AddLocation(EDLocation location) { if (_locations == null) { LoadLocations(); } if (String.IsNullOrEmpty(location.Name)) { // This is grossly inefficient, and is a hopefully temporary way to ensure names are present and unique int count = 1; bool nameIsUnique = true; string locationName; do { nameIsUnique = true; locationName = $"Location {count}"; foreach (EDLocation l in _locations) { if (l.Name.Equals(locationName)) { nameIsUnique = false; break; } } count++; } while (!nameIsUnique); location.Name = locationName; } _locations.Add(location); SaveLocationsToFile(); LocationAdded?.Invoke(null, location); }
private static void LoadLocations() { _locations = new List <EDLocation>(); if (String.IsNullOrEmpty(_saveFilename) || !File.Exists(_saveFilename)) { return; } try { Stream statusStream = File.OpenRead(_saveFilename); using (StreamReader reader = new StreamReader(statusStream)) { while (!reader.EndOfStream) { try { _locations.Add(EDLocation.FromString(reader.ReadLine())); } catch { } } reader.Close(); } } catch { } }
public EDLocation GetDisplayedLocation(EDLocation updateLocation = null) { // Return EDLocation with given data try { if (updateLocation == null) { EDLocation newLocation = new EDLocation(textBoxLocationName.Text, textBoxSystem.Text, textBoxPlanet.Text, Convert.ToDouble(textBoxLatitude.Text), Convert.ToDouble(textBoxLongitude.Text), Convert.ToDouble(textBoxAltitude.Text), Convert.ToDouble(textBoxPlanetaryRadius.Text)); return(newLocation); } updateLocation.Name = textBoxLocationName.Text; updateLocation.SystemName = textBoxSystem.Text; updateLocation.PlanetName = textBoxPlanet.Text; updateLocation.Latitude = Convert.ToDouble(textBoxLatitude.Text); updateLocation.Longitude = Convert.ToDouble(textBoxLongitude.Text); updateLocation.Altitude = Convert.ToDouble(textBoxAltitude.Text); updateLocation.PlanetaryRadius = Convert.ToDouble(textBoxPlanetaryRadius.Text); return(updateLocation); } catch { } return(null); }
private double DistanceBetween(EDLocation location1, EDLocation location2) { if (checkBoxIncludeAltitudeInDistanceCalculations.Checked) { return(EDLocation.DistanceBetweenIncludingAltitude(location1, location2)); } return(EDLocation.DistanceBetween(location1, location2)); }
private void buttonCurrentLocation_Click(object sender, EventArgs e) { if (FormTracker.CurrentLocation == null) { return; } _location = FormTracker.CurrentLocation.Copy(); DisplayLocation(); }
private void buttonAddLocation_Click(object sender, EventArgs e) { FormAddLocation formAddLocation = new FormAddLocation(); EDLocation newLocation = formAddLocation.AddLocation(listBoxLocations, this); if (newLocation == null) { return; } _locations.Add(newLocation); }
public void SetTarget(EDLocation targetLocation, string additionalInfo = "", string targetName = "") { // Sets the tracking target _targetPosition = targetLocation; if (String.IsNullOrEmpty(targetName)) { targetName = targetLocation.Name; } UpdateTrackingTarget(targetName); locatorHUD1.SetAdditionalInfo(additionalInfo); DisplayTarget(); UpdateTracking(); }
public void EditLocation(EDLocation location, IWin32Window owner = null, bool asDialog = false) { _location = location; DisplayLocation(); buttonAdd.Text = "Update"; if (asDialog) { this.ShowDialog(); } else { this.Show(owner); } }
private void buttonUseCurrentLocation_Click(object sender, EventArgs e) { if (FormTracker.CurrentLocation == null) { return; } try { _targetPosition = FormTracker.CurrentLocation.Copy(); UpdateTrackingTarget($"{_targetPosition.Longitude.ToString()} , {_targetPosition.Latitude.ToString()}"); DisplayTarget(); } catch { } }
private void LocationManager_LocationAdded(object sender, EDLocation location) { Action action = new Action(() => { listBoxLocations.Items.Add(location); }); if (listBoxLocations.InvokeRequired) { listBoxLocations.Invoke(action); } else { action(); } }
public FormAddLocation(EDLocation location = null) { InitializeComponent(); _location = location; if (_location == null) { _location = new EDLocation(); if (FormTracker.CurrentLocation.PlanetaryRadius > 0) { _location.PlanetaryRadius = FormTracker.CurrentLocation.PlanetaryRadius; } _location.PlanetName = FormTracker.CurrentLocation.PlanetName; _location.SystemName = FormTracker.CurrentLocation.SystemName; } DisplayLocation(); }
private void buttonEditLocation_Click(object sender, EventArgs e) { if (listBoxLocations.SelectedIndex < 0) { return; } try { FormAddLocation formAddLocation = new FormAddLocation(); EDLocation location = _locations[listBoxLocations.SelectedIndex]; formAddLocation.EditLocation(location, this); if (!((string)listBoxLocations.SelectedItem).Equals(location.Name)) { listBoxLocations.Items[listBoxLocations.SelectedIndex] = location.Name; } } catch { } }
private void CommanderWatcher_UpdateReceived(object sender, EDEvent edEvent) { if (!edEvent.HasCoordinates() || edEvent.Commander.Equals(FormTracker.CommanderName)) { return; } if (checkBoxTrackClosest.Checked && FormTracker.CurrentLocation != null) { // If we are tracking the closest commander to us, we need to check all updates and change our tracking target as necessary // We just check if the distance from this commander is closer than our currently tracked target double distanceToCommander = DistanceBetween(FormTracker.CurrentLocation, edEvent.Location()); if (distanceToCommander == 0) // This is impossible, and just means we haven't got data on the tracked target { distanceToCommander = double.MaxValue; } if (distanceToCommander < _closestCommanderDistance) { _closestCommander = edEvent; _closestCommanderDistance = distanceToCommander; } else if (edEvent.Commander == _closestCommander.Commander) { _closestCommanderDistance = distanceToCommander; } // Switch tracking to this target _targetPosition = edEvent.Location(); SetTarget(edEvent.Commander); return; } if (!TrackingTarget.Equals(edEvent.Commander)) { return; } _targetPosition = edEvent.Location(); DisplayTarget(); UpdateTracking(); }
private void comboBoxLocation_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxLocation.SelectedIndex < 0) { return; } if (comboBoxLocation.SelectedIndex == 0) { // Show the location editor comboBoxLocation.SelectedIndex = -1; FormAddLocation formAddLocation = new FormAddLocation(); EDLocation newLocation = formAddLocation.GetLocation(this); if (newLocation != null) { LocationManager.AddLocation(newLocation); comboBoxLocation.Items.Add(newLocation.Name); comboBoxLocation.SelectedIndex = comboBoxLocation.Items.Count - 1; } formAddLocation.Dispose(); return; } LocationManager locationManager = new LocationManager(); if (locationManager.Locations.Count > 0) { foreach (EDLocation location in locationManager.Locations) { if (location.Name.Equals(comboBoxLocation.SelectedItem.ToString())) { _targetPosition = location; UpdateTrackingTarget(location.Name); DisplayTarget(); break; } } } locationManager.Dispose(); }
private void UpdateTrackingTarget(string target) { Action action; TrackingTarget = target; if (_targetPosition == null) { EDEvent commanderEvent = CommanderWatcher.GetCommanderMostRecentEvent(target); if (commanderEvent != null) { _targetPosition = commanderEvent.Location(); } } locatorHUD1.SetTarget(target); string bearingInfo = $"Bearing (tracking {target})"; if (String.IsNullOrEmpty(target)) { bearingInfo = "Bearing (target not set)"; } if (String.IsNullOrEmpty(TrackingTarget)) { if (buttonTrackCommander.Text.Equals("Stop")) { action = new Action(() => { buttonTrackCommander.Text = "Track"; }); if (buttonTrackCommander.InvokeRequired) { buttonTrackCommander.Invoke(action); } else { action(); } } } }
private void buttonAdd_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(textBoxLocationName.Text)) { textBoxLocationName.Focus(); return; } EDLocation location = GetDisplayedLocation(_location); if (location == null) { return; } if (_locationListBox != null) { // We're adding this location _locationListBox.Items.Add(location); } this.Close(); }
public void UpdateTracking() { // Update our position if (FormTracker.CurrentLocation == null) { return; } Action action; if (!buttonUseCurrentLocation.Enabled) { action = new Action(() => { buttonUseCurrentLocation.Enabled = true; }); if (buttonUseCurrentLocation.InvokeRequired) { buttonUseCurrentLocation.Invoke(action); } else { action(); } } locatorHUD1.SetSpeed(FormTracker.Tracker.SpeedInMS); if (_targetPosition == null) { return; } bool displayChanged = false; try { _distanceToTarget = DistanceBetween(FormTracker.CurrentLocation, _targetPosition); string d = locatorHUD1.SetDistance(_distanceToTarget); _bearingToTarget = EDLocation.BearingToLocation(FormTracker.CurrentLocation, _targetPosition); if (locatorHUD1.SetBearing((int)_bearingToTarget, FormTracker.CurrentHeading)) { displayChanged = true; } string b = $"{Convert.ToInt32(_bearingToTarget).ToString()}°"; if (!labelDistance.Text.Equals(d)) { displayChanged = true; action = new Action(() => { labelDistance.Text = d; }); if (labelDistance.InvokeRequired) { labelDistance.Invoke(action); } else { action(); } } if (!labelHeading.Text.Equals(b)) { displayChanged = true; action = new Action(() => { labelHeading.Text = b; }); if (labelHeading.InvokeRequired) { labelHeading.Invoke(action); } else { action(); } } if (checkBoxTrackClosest.Checked) { _trackedTargetDistance = _distanceToTarget; } } catch { } if (displayChanged && checkBoxEnableVRLocator.Checked) { try { UpdateVRLocatorImage(); } catch (Exception ex) { MessageBox.Show($"{ex}", "Error updating VR image", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void UpdateLocation(EDLocation location, int heading = -1) { Action action; if (labelLongitude.Text != location.Longitude.ToString()) { action = new Action(() => { labelLongitude.Text = location.Longitude.ToString(); }); if (labelLongitude.InvokeRequired) { labelLongitude.Invoke(action); } else { action(); } } if (labelLatitude.Text != location.Latitude.ToString()) { action = new Action(() => { labelLatitude.Text = location.Latitude.ToString(); }); if (labelLatitude.InvokeRequired) { labelLatitude.Invoke(action); } else { action(); } } if (labelAltitude.Text != location.Altitude.ToString("F1")) { action = new Action(() => { labelAltitude.Text = location.Altitude.ToString("F1"); }); if (labelAltitude.InvokeRequired) { labelAltitude.Invoke(action); } else { action(); } } string sHeading = heading.ToString(); if (heading < 0) { sHeading = "NA"; } if (!labelHeading.Text.Equals(sHeading)) { action = new Action(() => { labelHeading.Text = sHeading; }); if (labelHeading.InvokeRequired) { labelHeading.Invoke(action); } else { action(); } } }