public List <IData3DCollection> AddNotedBookmarks(Bitmap map, Bitmap maptarget, float widthly, float heightly, Vector3 rotation, List <HistoryEntry> syslists) { var datasetbks = Data3DCollection <TexturedQuadData> .Create("bkmrs", Color.White, 1f); long bookmarknoted = TargetClass.GetTargetNotedSystem(); if (syslists != null) { foreach (HistoryEntry vs in syslists.Where(s => s.IsLocOrJump)) { SystemNoteClass notecs = SystemNoteClass.GetNoteOnSystem(vs.System.Name); if (notecs != null) // if we have a note.. { string note = notecs.Note.Trim(); if (note.Length > 0) { PointData pd = new PointData(vs.System.X, vs.System.Y, vs.System.Z); Bitmap touse = (notecs.id == bookmarknoted) ? maptarget : map; TexturedQuadData newtexture = TexturedQuadData.FromBitmap(touse, pd, rotation, widthly, heightly, 0, heightly / 2); newtexture.Tag = vs; newtexture.Tag2 = 1; // note mark datasetbks.Add(newtexture); } } } } _datasets.Add(datasetbks); return(_datasets); }
public void Bookmark(BookmarkClass bk) // from multiple places, update this bookmark, region or system.. { string note = ""; string name; long? edsmid = null; if (!bk.isRegion) { ISystem s = SystemCache.FindSystem(bk.StarName); if (s != null) // paranoia { InitialisePos(s); edsmid = s.EDSMID; } else { InitialisePos(bk.x, bk.y, bk.z); } SystemNoteClass sn = SystemNoteClass.GetNoteOnSystem(bk.StarName); note = (sn != null) ? sn.Note : ""; name = bk.StarName; } else { // region, set position, set name InitialisePos(bk.x, bk.y, bk.z); name = bk.Heading; } this.Text = "Update Bookmark".T(EDTx.BookmarkForm_UB); buttonOK.Text = "Update".T(EDTx.BookmarkForm_Update); textBoxName.Text = name; textBoxName.ReadOnly = !bk.isRegion; textBoxName.ReturnPressed += (ctrl) => { return(true); }; textBoxBookmarkNotes.Text = bk.Note; textBoxBookmarkNotes.CursorToEnd(); textBoxBookmarkNotes.ScrollToCaret(); textBoxTravelNote.Text = note; textBoxTime.Text = EDDConfig.Instance.ConvertTimeToSelectedFromUTC(bk.TimeUTC).ToString(); checkBoxTarget.Checked = bk.id == TargetClass.GetTargetBookmark(); // who is the target of a bookmark (0=none) //foreach (Control c in panelOuter.Controls) System.Diagnostics.Debug.WriteLine("All Control {0} at {1}", c.Name, c.Top); if (bk.isRegion) { HideEDSM(); HideTravelNote(); // in order note HideSurfaceBookmarks(); } else { var edsm = new EDSMClass(); edsmurl = edsm.GetUrlToEDSMSystem(name, edsmid); SurfaceBookmarks.Init(bk.StarName, bk.PlanetaryMarks); } buttonOK.Enabled = true; }
private void textBoxName_Validated(object sender, EventArgs e) { if (!freeSystemEntry) { return; } string t = textBoxName.Text.Trim(); ISystem s = SystemClassDB.GetSystem(t); if (s != null) { var edsm = new EDSMClass(); edsmurl = edsm.GetUrlToEDSMSystem(t); userControlSurfaceBookmarks1.NewForSystem(t); SystemNoteClass sn = SystemNoteClass.GetNoteOnSystem(t); textBoxNotes.Text = (sn != null) ? sn.Note : ""; InitialisePos(s); buttonOK.Enabled = true; labelBadSystem.Text = ""; } else { buttonOK.Enabled = false; textBoxName.SelectAll(); labelBadSystem.Text = "System name not recognised"; } }
private void AddNewHistoryRow(bool insert, HistoryEntry item) // second part of add history row, adds item to view. { SystemNoteClass snc = SystemNoteClass.GetNoteOnJournalEntry(item.Journalid); if (snc == null && item.IsFSDJump) { snc = SystemNoteClass.GetNoteOnSystem(item.System.name, item.System.id_edsm); } // Try to fill EDSM ID where a system note is set but journal item EDSM ID is not set if (snc != null && snc.Name != null && snc.EdsmId > 0 && item.System.id_edsm <= 0) { item.System.id_edsm = 0; discoveryform.history.FillEDSM(item); if (snc.Journalid != item.Journalid && item.System.id_edsm > 0 && snc.EdsmId != item.System.id_edsm) { snc = null; } } if (snc != null && snc.Name != null && snc.Journalid == item.Journalid && item.System.id_edsm > 0 && snc.EdsmId != item.System.id_edsm) { snc.EdsmId = item.System.id_edsm; snc.Update(); } //string debugt = item.Journalid + " " + item.System.id_edsm + " " + item.System.GetHashCode() + " "; // add on for debug purposes to a field below object[] rowobj = { EDDiscoveryForm.EDDConfig.DisplayUTC?item.EventTimeUTC : item.EventTimeLocal, "", item.EventSummary, item.EventDescription, (snc != null) ? snc.Note : "" }; int rownr; if (insert) { dataGridViewTravel.Rows.Insert(0, rowobj); rownr = 0; } else { dataGridViewTravel.Rows.Add(rowobj); rownr = dataGridViewTravel.Rows.Count - 1; } dataGridViewTravel.Rows[rownr].Cells[TravelHistoryColumns.HistoryTag].Tag = item; dataGridViewTravel.Rows[rownr].Cells[TravelHistoryColumns.NoteTag].Tag = snc; dataGridViewTravel.Rows[rownr].DefaultCellStyle.ForeColor = (item.System.HasCoordinate || item.EntryType != JournalTypeEnum.FSDJump) ? discoveryform.theme.VisitedSystemColor : discoveryform.theme.NonVisitedSystemColor; string tip = item.EventSummary + Environment.NewLine + item.EventDescription + Environment.NewLine + item.EventDetailedInfo; dataGridViewTravel.Rows[rownr].Cells[0].ToolTipText = tip; dataGridViewTravel.Rows[rownr].Cells[1].ToolTipText = tip; dataGridViewTravel.Rows[rownr].Cells[2].ToolTipText = tip; dataGridViewTravel.Rows[rownr].Cells[3].ToolTipText = tip; dataGridViewTravel.Rows[rownr].Cells[4].ToolTipText = tip; }
public void GetComments(Action <string> logout = null) // Protected against bad JSON { var json = GetComments(new DateTime(2011, 1, 1)); if (json != null) { try { JObject msg = JObject.Parse(json); // protect against bad json - seen in the wild int msgnr = msg["msgnum"].Value <int>(); JArray comments = (JArray)msg["comments"]; if (comments != null) { int commentsadded = 0; foreach (JObject jo in comments) { string name = jo["system"].Value <string>(); string note = jo["comment"].Value <string>(); string utctime = jo["lastUpdate"].Value <string>(); int edsmid = 0; if (!Int32.TryParse(jo["systemId"].Str("0"), out edsmid)) { edsmid = 0; } DateTime localtime = DateTime.ParseExact(utctime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime(); SystemNoteClass curnote = SystemNoteClass.GetNoteOnSystem(name, edsmid); if (curnote != null) // curnote uses local time to store { if (localtime.Ticks > curnote.Time.Ticks) // if newer, add on (verified with EDSM 29/9/2016) { curnote.UpdateNote(curnote.Note + ". EDSM: " + note, true, localtime, edsmid, true); commentsadded++; } } else { SystemNoteClass.MakeSystemNote(note, localtime, name, 0, edsmid, true); // new one! its an FSD one as well commentsadded++; } } logout?.Invoke(string.Format("EDSM Comments downloaded/updated {0}", commentsadded)); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Failed due to " + e.ToString()); } } }
public void Update(BookmarkClass bk) // from multiple places, update this bookmark, region or system.. { string note = ""; string name; long? edsmid = null; if (!bk.isRegion) { ISystem s = SystemCache.FindSystem(bk.StarName); if (s != null) // paranoia { InitialisePos(s); edsmid = s.EDSMID; } else { InitialisePos(bk.x, bk.y, bk.z); } SystemNoteClass sn = SystemNoteClass.GetNoteOnSystem(bk.StarName); note = (sn != null) ? sn.Note : ""; name = bk.StarName; } else { // region, set position, set name InitialisePos(bk.x, bk.y, bk.z); name = bk.Heading; } this.Text = "Update Bookmark".Tx(this, "UB"); buttonOK.Text = "Update".Tx(this); textBoxName.Text = name; textBoxName.ReadOnly = !bk.isRegion; textBoxName.ReturnPressed += (ctrl) => { return(true); }; textBoxBookmarkNotes.Text = bk.Note; textBoxBookmarkNotes.CursorToEnd(); textBoxBookmarkNotes.ScrollToCaret(); textBoxTravelNote.Text = note; textBoxTime.Text = bk.Time.ToString(); checkBoxTarget.Checked = bk.id == TargetClass.GetTargetBookmark(); // who is the target of a bookmark (0=none) if (bk.isRegion) { HideEDSM(); HideTravelNote(); HideSurfaceBookmarks(); } else { var edsm = new EDSMClass(); edsmurl = edsm.GetUrlToEDSMSystem(name, edsmid); SurfaceBookmarks.Init(bk.StarName, bk.PlanetaryMarks); } buttonOK.Enabled = true; }
private void UpdateSystemRow(int rowindex) { if (rowindex < dataGridViewRouteSystems.Rows.Count && dataGridViewRouteSystems[0, rowindex].Value != null) { string sysname = dataGridViewRouteSystems[0, rowindex].Value.ToString(); var sys = GetSystem(sysname); dataGridViewRouteSystems[1, rowindex].Value = ""; if (rowindex > 0 && rowindex < dataGridViewRouteSystems.Rows.Count && dataGridViewRouteSystems[0, rowindex - 1].Value != null && dataGridViewRouteSystems[0, rowindex].Value != null) { string prevsysname = dataGridViewRouteSystems[0, rowindex - 1].Value.ToString(); var prevsys = GetSystem(prevsysname); if (sys != null && prevsys != null) { double dist = SystemClass.Distance(sys, prevsys); string strdist = dist >= 0 ? ((double)dist).ToString("0.00") : ""; dataGridViewRouteSystems[1, rowindex].Value = strdist; } } dataGridViewRouteSystems[0, rowindex].Tag = sys; dataGridViewRouteSystems.Rows[rowindex].DefaultCellStyle.ForeColor = (sys != null && sys.HasCoordinate) ? _discoveryForm.theme.VisitedSystemColor : _discoveryForm.theme.NonVisitedSystemColor; if (sys != null) { SystemNoteClass sn = SystemNoteClass.GetNoteOnSystem(sys.name, sys.id_edsm); dataGridViewRouteSystems[2, rowindex].Value = sn != null ? sn.Note : ""; } if (sys == null && sysname != "") { dataGridViewRouteSystems.Rows[rowindex].ErrorText = "System not known to EDSM"; } else { dataGridViewRouteSystems.Rows[rowindex].ErrorText = ""; } } }
public void Update(BookmarkClass bk) { string note = ""; string name; if (!bk.isRegion) { SystemNoteClass sn = SystemNoteClass.GetNoteOnSystem(bk.StarName); ISystem s = SystemClassDB.GetSystem(bk.StarName); InitialisePos(s); note = (sn != null) ? sn.Note : ""; name = bk.StarName; } else { name = bk.Heading; } Update(name, note, bk.Note, bk.Time.ToString(), bk.isRegion, false, bk.PlanetaryMarks); userControlSurfaceBookmarks1.DisplayPlanetMarks(bk); buttonOK.Enabled = true; }
private void UpdateSystemRow(int rowindex) { const int idxVisits = 5; const int idxScans = 6; const int idxPriStar = 7; const int idxInfo = 8; const int idxNote = 9; ISystem currentSystem = discoveryform.history.CurrentSystem; // may be null if (rowindex < dataGridViewExplore.Rows.Count && dataGridViewExplore[0, rowindex].Value != null) { string sysname = dataGridViewExplore[0, rowindex].Value.ToString(); ISystem sys = (ISystem)dataGridViewExplore[0, rowindex].Tag; if (sys == null) { sys = SystemCache.FindSystem(sysname); } if (sys != null && currentSystem != null) { double dist = sys.Distance(currentSystem); string strdist = dist >= 0 ? ((double)dist).ToString("0.00") : ""; dataGridViewExplore[1, rowindex].Value = strdist; } dataGridViewExplore[0, rowindex].Tag = sys; dataGridViewExplore.Rows[rowindex].DefaultCellStyle.ForeColor = (sys != null && sys.HasCoordinate) ? discoveryform.theme.VisitedSystemColor : discoveryform.theme.NonVisitedSystemColor; if (sys != null) { if (sys.HasCoordinate) { dataGridViewExplore[2, rowindex].Value = sys.X.ToString("0.00"); dataGridViewExplore[3, rowindex].Value = sys.Y.ToString("0.00"); dataGridViewExplore[4, rowindex].Value = sys.Z.ToString("0.00"); } dataGridViewExplore[idxVisits, rowindex].Value = discoveryform.history.GetVisitsCount(sysname).ToString(); List <JournalScan> scans = discoveryform.history.GetScans(sysname); dataGridViewExplore[idxScans, rowindex].Value = scans.Count.ToString(); string pristar = ""; // Search for primary star foreach (var scan in scans) { if (scan.IsStar && scan.DistanceFromArrivalLS == 0.0) { pristar = scan.StarType; break; } } dataGridViewExplore[idxPriStar, rowindex].Value = pristar; string info = ""; foreach (var scan in scans) { if (scan.IsStar) { if (scan.StarTypeID == EDStar.AeBe) { info = info + " " + "AeBe"; } if (scan.StarTypeID == EDStar.N) { info = info + " " + "NS"; } if (scan.StarTypeID == EDStar.H) { info = info + " " + "BH"; } } else { if (scan.PlanetTypeID == EDPlanet.Earthlike_body) { info = info + " " + "ELW"; } if (scan.PlanetTypeID == EDPlanet.Water_world) { info = info + " " + "WW"; } } } dataGridViewExplore[idxInfo, rowindex].Value = info.Trim(); string note = ""; SystemNoteClass sn = SystemNoteClass.GetNoteOnSystem(sys.Name, sys.EDSMID); if (sn != null && !string.IsNullOrWhiteSpace(sn.Note)) { note = sn.Note; } else { BookmarkClass bkmark = GlobalBookMarkList.Instance.FindBookmarkOnSystem(sys.Name); if (bkmark != null && !string.IsNullOrWhiteSpace(bkmark.Note)) { note = bkmark.Note; } else { var gmo = discoveryform.galacticMapping.Find(sys.Name); if (gmo != null && !string.IsNullOrWhiteSpace(gmo.description)) { note = gmo.description; } } } dataGridViewExplore[idxNote, rowindex].Value = note.WordWrap(60); } if (sys == null && sysname != "") { dataGridViewExplore.Rows[rowindex].ErrorText = "System not known".Tx(); } else { dataGridViewExplore.Rows[rowindex].ErrorText = ""; } } }
private void UpdateSystemRow(int rowindex) { const int idxVisits = 5; const int idxScans = 6; const int idxBodies = 7; const int idxstars = 8; const int idxInfo = 9; const int idxNote = 10; ISystem currentSystem = discoveryform.history.CurrentSystem; // may be null if (rowindex < dataGridViewExplore.Rows.Count && dataGridViewExplore[0, rowindex].Value != null) { string sysname = dataGridViewExplore[0, rowindex].Value.ToString(); ISystem sys = (ISystem)dataGridViewExplore[0, rowindex].Tag; if (sys == null) { sys = discoveryform.history.FindSystem(sysname); } if (sys != null && currentSystem != null) { double dist = sys.Distance(currentSystem); string strdist = dist >= 0 ? ((double)dist).ToString("0.00") : ""; dataGridViewExplore[1, rowindex].Value = strdist; } dataGridViewExplore[0, rowindex].Tag = sys; dataGridViewExplore.Rows[rowindex].DefaultCellStyle.ForeColor = (sys != null && sys.HasCoordinate) ? discoveryform.theme.VisitedSystemColor : discoveryform.theme.NonVisitedSystemColor; if (sys != null) { if (sys.HasCoordinate) { dataGridViewExplore[2, rowindex].Value = sys.X.ToString("0.00"); dataGridViewExplore[3, rowindex].Value = sys.Y.ToString("0.00"); dataGridViewExplore[4, rowindex].Value = sys.Z.ToString("0.00"); } dataGridViewExplore[idxVisits, rowindex].Value = discoveryform.history.GetVisitsCount(sysname).ToString(); StarScan.SystemNode sysnode = discoveryform.history.starscan.FindSystemSynchronous(sys, false); if (sysnode != null) { dataGridViewExplore[idxScans, rowindex].Value = sysnode.StarPlanetsScanned().ToString(); if (sysnode.FSSTotalBodies.HasValue) { dataGridViewExplore[idxBodies, rowindex].Value = sysnode.FSSTotalBodies.Value.ToString(); } dataGridViewExplore[idxstars, rowindex].Value = sysnode.StarTypesFound(false); string info = ""; foreach (var scan in sysnode.Bodies) { JournalScan sd = scan.ScanData; if (sd != null) { if (sd.IsStar) { if (sd.StarTypeID == EDStar.AeBe) { info = info + " " + "AeBe"; } if (sd.StarTypeID == EDStar.N) { info = info + " " + "NS"; } if (sd.StarTypeID == EDStar.H) { info = info + " " + "BH"; } } else { if (sd.PlanetTypeID == EDPlanet.Earthlike_body) { info = info + " " + (sd.Terraformable ? "T-ELW" : "ELW"); } else if (sd.PlanetTypeID == EDPlanet.Water_world) { info = info + " " + (sd.Terraformable ? "T-WW" : "WW"); } else if (sd.PlanetTypeID == EDPlanet.High_metal_content_body && sd.Terraformable) { info = info + " " + "T-HMC"; } } } } dataGridViewExplore[idxInfo, rowindex].Value = info.Trim(); } string note = ""; SystemNoteClass sn = SystemNoteClass.GetNoteOnSystem(sys.Name, sys.EDSMID); if (sn != null && !string.IsNullOrWhiteSpace(sn.Note)) { note = sn.Note; } else { BookmarkClass bkmark = GlobalBookMarkList.Instance.FindBookmarkOnSystem(sys.Name); if (bkmark != null && !string.IsNullOrWhiteSpace(bkmark.Note)) { note = bkmark.Note; } else { var gmo = discoveryform.galacticMapping.Find(sys.Name); if (gmo != null && !string.IsNullOrWhiteSpace(gmo.description)) { note = gmo.description; } } } dataGridViewExplore[idxNote, rowindex].Value = note.WordWrap(60); } if (sys == null && sysname != "") { dataGridViewExplore.Rows[rowindex].ErrorText = "System not known".T(EDTx.Systemnotknown); } else { dataGridViewExplore.Rows[rowindex].ErrorText = ""; } } }
public static void setTargetSystem(Object sender, EDDiscoveryForm _discoveryForm, String sn, Boolean prompt) { Form senderForm = ((Control)sender)?.FindForm() ?? _discoveryForm; if (string.IsNullOrWhiteSpace(sn)) { if (prompt && TargetClass.IsTargetSet()) // if prompting, and target is set, ask for delete { if (ExtendedControls.MessageBoxTheme.Show(senderForm, "Confirm deletion of target", "Delete a target", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { TargetClass.ClearTarget(); _discoveryForm.NewTargetSet(sender); // tells everyone who cares a new target was set } } return; } ISystem sc = _discoveryForm.history.FindSystem(sn); string msgboxtext = null; if (sc != null && sc.HasCoordinate) { SystemNoteClass nc = SystemNoteClass.GetNoteOnSystem(sc.Name, sc.EDSMID); // has it got a note? if (nc != null) { TargetClass.SetTargetNotedSystem(sc.Name, nc.id, sc.X, sc.Y, sc.Z); msgboxtext = "Target set on system with note " + sc.Name; } else { BookmarkClass bk = GlobalBookMarkList.Instance.FindBookmarkOnSystem(sn); // has it been bookmarked? if (bk != null) { TargetClass.SetTargetBookmark(sc.Name, bk.id, bk.x, bk.y, bk.z); msgboxtext = "Target set on bookmarked system " + sc.Name; } else { bool createbookmark = false; if ((prompt && ExtendedControls.MessageBoxTheme.Show(senderForm, "Make a bookmark on " + sc.Name + " and set as target?", "Make Bookmark", MessageBoxButtons.OKCancel) == DialogResult.OK) || !prompt) { createbookmark = true; } if (createbookmark) { BookmarkClass newbk = GlobalBookMarkList.Instance.AddOrUpdateBookmark(null, true, sn, sc.X, sc.Y, sc.Z, DateTime.Now, ""); TargetClass.SetTargetBookmark(sc.Name, newbk.id, newbk.x, newbk.y, newbk.z); } } } } else { if (sn.Length > 2 && sn.Substring(0, 2).Equals("G:")) { sn = sn.Substring(2, sn.Length - 2); } GalacticMapObject gmo = _discoveryForm.galacticMapping.Find(sn, true, true); // ignore if its off, find any part of string, find if disabled if (gmo != null) { TargetClass.SetTargetGMO("G:" + gmo.name, gmo.id, gmo.points[0].X, gmo.points[0].Y, gmo.points[0].Z); msgboxtext = "Target set on galaxy object " + gmo.name; } else { msgboxtext = "Unknown system, system is without co-ordinates or galaxy object not found"; } } _discoveryForm.NewTargetSet(sender); // tells everyone who cares a new target was set if (msgboxtext != null && prompt) { ExtendedControls.MessageBoxTheme.Show(senderForm, msgboxtext, "Create a target", MessageBoxButtons.OK); } }
// cursystem = null, curbookmark = null, new system free entry bookmark // cursystem != null, curbookmark = null, system bookmark found, update // cursystem != null, curbookmark = null, no system bookmark found, new bookmark on system // curbookmark != null, edit current bookmark public static void showBookmarkForm(Object sender, EDDiscoveryForm discoveryForm, ISystem cursystem, BookmarkClass curbookmark, bool notedsystem) { Form senderForm = ((Control)sender)?.FindForm() ?? discoveryForm; // try and find the associated bookmark.. BookmarkClass bkmark = (curbookmark != null) ? curbookmark : (cursystem != null ? GlobalBookMarkList.Instance.FindBookmarkOnSystem(cursystem.Name) : null); SystemNoteClass sn = (cursystem != null) ? SystemNoteClass.GetNoteOnSystem(cursystem.Name, cursystem.EDSMID) : null; string note = (sn != null) ? sn.Note : ""; BookmarkForm frm = new BookmarkForm(); if (notedsystem && bkmark == null) // note on a system { long targetid = TargetClass.GetTargetNotedSystem(); // who is the target of a noted system (0=none) long noteid = sn.id; frm.InitialisePos(cursystem); frm.NotedSystem(cursystem.Name, note, noteid == targetid); // note may be passed in null frm.ShowDialog(senderForm); if ((frm.IsTarget && targetid != noteid) || (!frm.IsTarget && targetid == noteid)) // changed.. { if (frm.IsTarget) { TargetClass.SetTargetNotedSystem(cursystem.Name, noteid, cursystem.X, cursystem.Y, cursystem.Z); } else { TargetClass.ClearTarget(); } } } else { bool regionmarker = false; DateTime tme; if (bkmark == null) // new bookmark { tme = DateTime.Now; if (cursystem == null) { frm.NewFreeEntrySystemBookmark(tme); } else { frm.NewSystemBookmark(cursystem, note, tme); } } else // update bookmark { regionmarker = bkmark.isRegion; tme = bkmark.Time; frm.Update(bkmark); } DialogResult res = frm.ShowDialog(senderForm); long curtargetid = TargetClass.GetTargetBookmark(); // who is the target of a bookmark (0=none) if (res == DialogResult.OK) { BookmarkClass newcls = GlobalBookMarkList.Instance.AddOrUpdateBookmark(bkmark, !regionmarker, frm.StarHeading, double.Parse(frm.x), double.Parse(frm.y), double.Parse(frm.z), tme, frm.Notes, frm.SurfaceLocations); if ((frm.IsTarget && curtargetid != newcls.id) || (!frm.IsTarget && curtargetid == newcls.id)) // changed.. { if (frm.IsTarget) { TargetClass.SetTargetBookmark(regionmarker ? ("RM:" + newcls.Heading) : newcls.StarName, newcls.id, newcls.x, newcls.y, newcls.z); } else { TargetClass.ClearTarget(); } } } else if (res == DialogResult.Abort && bkmark != null) { if (curtargetid == bkmark.id) { TargetClass.ClearTarget(); } GlobalBookMarkList.Instance.Delete(bkmark); } } discoveryForm.NewTargetSet(sender); }
private void Sync(EDSMClass edsm) { try { mainForm.LogLine("EDSM sync begin"); List <HistoryEntry> hlfsdunsyncedlist = mainForm.history.FilterByNotEDSMSyncedAndFSD; // first entry is oldest if (_syncTo && hlfsdunsyncedlist.Count > 0) // send systems to edsm (verified with dates, 29/9/2016, utc throughout) { DateTime logstarttime = DateTime.MinValue; DateTime logendtime = DateTime.MinValue; mainForm.LogLine("EDSM: Sending " + hlfsdunsyncedlist.Count.ToString() + " flightlog entries"); List <HistoryEntry> edsmsystemlog = null; int edsmsystemssent = 0; foreach (var he in hlfsdunsyncedlist) { if (Exit) { running = false; return; } if (edsmsystemlog == null || he.EventTimeUTC >= logendtime.AddDays(-1)) { edsm.GetLogs(he.EventTimeUTC.AddDays(-1), null, out edsmsystemlog, out logstarttime, out logendtime); // always returns a log, time is in UTC as per HistoryEntry and JournalEntry } if (logendtime < logstarttime) { running = false; return; } if (edsmsystemlog == null) { running = false; return; } HistoryEntry ps2 = (from c in edsmsystemlog where c.System.name == he.System.name && c.EventTimeUTC.Ticks == he.EventTimeUTC.Ticks select c).FirstOrDefault(); if (ps2 != null) // it did, just make sure EDSM sync flag is set.. { he.SetEdsmSync(); } else { string errmsg; // (verified with EDSM 29/9/2016) bool firstdiscover; int edsmid; if (edsm.SendTravelLog(he.System.name, he.EventTimeUTC, he.System.HasCoordinate && !he.IsStarPosFromEDSM, he.System.x, he.System.y, he.System.z, out errmsg, out firstdiscover, out edsmid)) { if (edsmid != 0 && he.System.id_edsm <= 0) { he.System.id_edsm = edsmid; EDDiscovery.EliteDangerous.JournalEntry.UpdateEDSMIDPosJump(he.Journalid, he.System, false, -1); } if (firstdiscover) { he.SetFirstDiscover(); } he.SetEdsmSync(); edsmsystemssent++; } if (errmsg.Length > 0) { mainForm.LogLine(errmsg); break; } } } mainForm.LogLine(string.Format("EDSM Systems sent {0}", edsmsystemssent)); } // TBD Comments to edsm? if (_syncFrom) // Verified ok with time 29/9/2016 { var json = edsm.GetComments(new DateTime(2011, 1, 1)); if (json != null) { JObject msg = JObject.Parse(json); int msgnr = msg["msgnum"].Value <int>(); JArray comments = (JArray)msg["comments"]; if (comments != null) { int commentsadded = 0; foreach (JObject jo in comments) { string name = jo["system"].Value <string>(); string note = jo["comment"].Value <string>(); string utctime = jo["lastUpdate"].Value <string>(); int edsmid = 0; if (!Int32.TryParse(JSONHelper.GetStringDef(jo["systemId"], "0"), out edsmid)) { edsmid = 0; } DateTime localtime = DateTime.ParseExact(utctime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime(); SystemNoteClass curnote = SystemNoteClass.GetNoteOnSystem(name, edsmid); if (curnote != null) { // curnote uses local time to store if (localtime.Ticks > curnote.Time.Ticks) // if newer, add on (verified with EDSM 29/9/2016) { curnote.Note += ". EDSM: " + note; curnote.Time = localtime; curnote.EdsmId = edsmid; curnote.Update(); commentsadded++; } } else { curnote = new SystemNoteClass(); curnote.Note = note; curnote.Time = localtime; curnote.Name = name; curnote.Journalid = 0; curnote.EdsmId = edsmid; curnote.Add(); commentsadded++; } } mainForm.LogLine(string.Format("EDSM Comments downloaded/updated {0}", commentsadded)); } } } mainForm.LogLine("EDSM sync Done"); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message); mainForm.LogLineHighlight("EDSM sync Exception " + ex.Message); } }
private void UpdateSystemRow(int rowindex) { if (rowindex < dataGridViewRouteSystems.Rows.Count && dataGridViewRouteSystems[0, rowindex].Value != null) { string sysname = dataGridViewRouteSystems[0, rowindex].Value.ToString(); var sys = GetSystem(sysname); dataGridViewRouteSystems[1, rowindex].Value = ""; if (rowindex > 0 && rowindex < dataGridViewRouteSystems.Rows.Count && dataGridViewRouteSystems[0, rowindex - 1].Value != null && dataGridViewRouteSystems[0, rowindex].Value != null) { string prevsysname = dataGridViewRouteSystems[0, rowindex - 1].Value.ToString(); var prevsys = GetSystem(prevsysname); if (sys != null && prevsys != null) { double dist = sys.Distance(prevsys); string strdist = dist >= 0 ? ((double)dist).ToString("0.00") : ""; dataGridViewRouteSystems[1, rowindex].Value = strdist; } } dataGridViewRouteSystems[0, rowindex].Tag = sys; dataGridViewRouteSystems.Rows[rowindex].DefaultCellStyle.ForeColor = (sys != null && sys.HasCoordinate) ? discoveryform.theme.VisitedSystemColor : discoveryform.theme.NonVisitedSystemColor; if (sys != null) { string note = ""; SystemNoteClass sn = SystemNoteClass.GetNoteOnSystem(sys.Name, sys.EDSMID); if (sn != null && !string.IsNullOrWhiteSpace(sn.Note)) { note = sn.Note; } else { BookmarkClass bkmark = GlobalBookMarkList.Instance.FindBookmarkOnSystem(sys.Name); if (bkmark != null && !string.IsNullOrWhiteSpace(bkmark.Note)) { note = bkmark.Note; } else { var gmo = discoveryform.galacticMapping.Find(sys.Name); if (gmo != null && !string.IsNullOrWhiteSpace(gmo.description)) { note = gmo.description; } } } dataGridViewRouteSystems[2, rowindex].Value = note.WordWrap(60); dataGridViewRouteSystems.Rows[rowindex].Cells[0].ToolTipText = string.Format("{0:0.#},{1:0.#},{2:0.#}", sys.X, sys.Y, sys.Z); } if (sys == null && sysname != "") { dataGridViewRouteSystems.Rows[rowindex].ErrorText = "System not known to EDSM".T(EDTx.UserControlExpedition_EDSMUnk); } else { dataGridViewRouteSystems.Rows[rowindex].ErrorText = ""; } } }
private void Sync(EDSMClass edsm) { try { mainForm.LogLine("EDSM sync begin"); List <HistoryEntry> hlfsdunsyncedlist = mainForm.history.FilterByNotEDSMSyncedAndFSD; // first entry is oldest if (_syncTo && hlfsdunsyncedlist.Count > 0) // send systems to edsm (verified with dates, 29/9/2016, utc throughout) { DateTime utcmin = hlfsdunsyncedlist[0].EventTimeUTC.AddDays(-1); // 1 days for margin ;-) only get them back to this date for speed.. mainForm.LogLine("EDSM: Sending " + hlfsdunsyncedlist.Count.ToString() + " flightlog entries"); List <HistoryEntry> edsmsystemlog = null; edsm.GetLogs(utcmin, out edsmsystemlog); // always returns a log, time is in UTC as per HistoryEntry and JournalEntry int edsmsystemssent = 0; foreach (var he in hlfsdunsyncedlist) { if (Exit) { running = false; return; } HistoryEntry ps2 = (from c in edsmsystemlog where c.System.name == he.System.name && c.EventTimeUTC.Ticks == he.EventTimeUTC.Ticks select c).FirstOrDefault(); if (ps2 != null) // it did, just make sure EDSM sync flag is set.. { he.SetEdsmSync(); } else { string errmsg; // (verified with EDSM 29/9/2016) // it converts to UTC inside the function, supply local for now if (edsm.SendTravelLog(he.System.name, he.EventTimeUTC, he.System.HasCoordinate && !he.IsStarPosFromEDSM, he.System.x, he.System.y, he.System.z, out errmsg)) { he.SetEdsmSync(); } if (errmsg.Length > 0) { mainForm.LogLine(errmsg); } edsmsystemssent++; } } mainForm.LogLine(string.Format("EDSM Systems sent {0}", edsmsystemssent)); } // TBD Comments to edsm? if (_syncFrom) // Verified ok with time 29/9/2016 { var json = edsm.GetComments(new DateTime(2011, 1, 1)); if (json != null) { JObject msg = JObject.Parse(json); int msgnr = msg["msgnum"].Value <int>(); JArray comments = (JArray)msg["comments"]; if (comments != null) { int commentsadded = 0; foreach (JObject jo in comments) { string name = jo["system"].Value <string>(); string note = jo["comment"].Value <string>(); string utctime = jo["lastUpdate"].Value <string>(); int edsmid = 0; if (!Int32.TryParse(JSONHelper.GetStringDef(jo["systemId"], "0"), out edsmid)) { edsmid = 0; } DateTime localtime = DateTime.ParseExact(utctime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime(); SystemNoteClass curnote = SystemNoteClass.GetNoteOnSystem(name, edsmid); if (curnote != null) { // curnote uses local time to store if (localtime.Ticks > curnote.Time.Ticks) // if newer, add on (verified with EDSM 29/9/2016) { curnote.Note += ". EDSM: " + note; curnote.Time = localtime; curnote.EdsmId = edsmid; curnote.Update(); commentsadded++; } } else { curnote = new SystemNoteClass(); curnote.Note = note; curnote.Time = localtime; curnote.Name = name; curnote.Journalid = 0; curnote.EdsmId = edsmid; curnote.Add(); commentsadded++; } } mainForm.LogLine(string.Format("EDSM Comments downloaded/updated {0}", commentsadded)); } } } if (_syncFrom) // verified after struggle 29/9/2016 { List <HistoryEntry> edsmsystemlog = null; edsm.GetLogs(new DateTime(2011, 1, 1), out edsmsystemlog); // get the full list of systems edsmsystemlog = edsmsystemlog.OrderBy(s => s.EventTimeUTC).ToList(); List <HistoryEntry> hlfsdlist = mainForm.history.FilterByFSD.OrderBy(h => h.EventTimeUTC).ToList(); // FSD jumps only List <HistoryEntry> toadd = new List <HistoryEntry>(); int previdx = -1; foreach (HistoryEntry he in edsmsystemlog) // find out list of ones not present { int index = hlfsdlist.FindIndex(x => x.System.name.Equals(he.System.name, StringComparison.InvariantCultureIgnoreCase) && x.EventTimeUTC.Ticks == he.EventTimeUTC.Ticks); if (index < 0) { // Look for any entries where DST may have thrown off the time foreach (var vi in hlfsdlist.Select((v, i) => new { v = v, i = i }).Where(vi => vi.v.System.name.Equals(he.System.name, StringComparison.InvariantCultureIgnoreCase))) { if (vi.i > previdx) { double hdiff = vi.v.EventTimeUTC.Subtract(he.EventTimeUTC).TotalHours; if (hdiff >= -2 && hdiff <= 2 && hdiff == Math.Floor(hdiff)) { if (vi.v.System.id_edsm <= 0) { vi.v.System.id_edsm = 0; mainForm.history.FillEDSM(vi.v); } if (vi.v.System.id_edsm <= 0 || vi.v.System.id_edsm == he.System.id_edsm) { index = vi.i; break; } } } } } if (index < 0) { toadd.Add(he); } else { previdx = index; } } if (toadd.Count > 0) // if we have any, we can add { TravelLogUnit tlu = new TravelLogUnit(); // need a tlu for it tlu.type = 2; // EDSM tlu.Name = "EDSM-" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); tlu.Size = 0; tlu.Path = "EDSM"; tlu.CommanderId = EDDiscoveryForm.EDDConfig.CurrentCommander.Nr; tlu.Add(); // Add to Database using (SQLiteConnectionUser cn = new SQLiteConnectionUser(utc: true)) { foreach (HistoryEntry he in toadd) { EDDiscovery.EliteDangerous.JournalEntry je = EDDiscovery.EliteDangerous.JournalEntry.CreateFSDJournalEntry(tlu.id, tlu.CommanderId.Value, he.EventTimeUTC, he.System.name, he.System.x, he.System.y, he.System.z, _defmapcolour, (int)EDDiscovery.EliteDangerous.SyncFlags.EDSM); System.Diagnostics.Trace.WriteLine(string.Format("Add {0} {1}", je.EventTimeUTC, he.System.name)); je.Add(cn); } } if (OnDownloadedSystems != null) { OnDownloadedSystems(); } mainForm.LogLine(string.Format("EDSM downloaded {0} systems", toadd.Count)); } } mainForm.LogLine("EDSM sync Done"); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message); mainForm.LogLineHighlight("EDSM sync Exception " + ex.Message); } }
private void UpdateSystemRow(int rowindex) { if (rowindex < dataGridViewRouteSystems.Rows.Count && dataGridViewRouteSystems[0, rowindex].Value != null) { string sysname = dataGridViewRouteSystems[0, rowindex].Value.ToString(); var sys = GetSystem(sysname); dataGridViewRouteSystems[1, rowindex].Value = ""; if (rowindex > 0 && rowindex < dataGridViewRouteSystems.Rows.Count && dataGridViewRouteSystems[0, rowindex - 1].Value != null && dataGridViewRouteSystems[0, rowindex].Value != null) { string prevsysname = dataGridViewRouteSystems[0, rowindex - 1].Value.ToString(); var prevsys = GetSystem(prevsysname); if (sys != null && prevsys != null) { double dist = SystemClass.Distance(sys, prevsys); string strdist = dist >= 0 ? ((double)dist).ToString("0.00") : ""; dataGridViewRouteSystems[1, rowindex].Value = strdist; } } dataGridViewRouteSystems[0, rowindex].Tag = sys; dataGridViewRouteSystems.Rows[rowindex].DefaultCellStyle.ForeColor = (sys != null && sys.HasCoordinate) ? _discoveryForm.theme.VisitedSystemColor : _discoveryForm.theme.NonVisitedSystemColor; if (sys != null) { string note = ""; SystemNoteClass sn = SystemNoteClass.GetNoteOnSystem(sys.name, sys.id_edsm); if (sn != null && !string.IsNullOrWhiteSpace(sn.Note)) { note = sn.Note; } else { BookmarkClass bkmark = BookmarkClass.bookmarks.Find(x => x.StarName != null && x.StarName.Equals(sys.name)); if (bkmark != null && !string.IsNullOrWhiteSpace(bkmark.Note)) { note = bkmark.Note; } else { var gmo = _discoveryForm.galacticMapping.Find(sys.name); if (gmo != null && !string.IsNullOrWhiteSpace(gmo.description)) { note = gmo.description; } } } dataGridViewRouteSystems[2, rowindex].Value = Tools.WordWrap(note, 60); } if (sys == null && sysname != "") { dataGridViewRouteSystems.Rows[rowindex].ErrorText = "System not known to EDSM"; } else { dataGridViewRouteSystems.Rows[rowindex].ErrorText = ""; } } }
private void UpdateSystemRow(int rowindex) { const int idxVisits = 5; const int idxScans = 6; const int idxPriStar = 7; const int idxInfo = 8; const int idxNote = 9; if (hl == null) { hl = _discoveryForm.history; } if (hl.GetLast == null) { return; } ISystem currentSystem = hl.GetLast.System; if (rowindex < dataGridViewExplore.Rows.Count && dataGridViewExplore[0, rowindex].Value != null) { string sysname = dataGridViewExplore[0, rowindex].Value.ToString(); ISystem sys = (ISystem)dataGridViewExplore[0, rowindex].Tag; if (sys == null) { sys = GetSystem(sysname); } if (sys != null && currentSystem != null) { double dist = SystemClass.Distance(sys, currentSystem); string strdist = dist >= 0 ? ((double)dist).ToString("0.00") : ""; dataGridViewExplore[1, rowindex].Value = strdist; } dataGridViewExplore[0, rowindex].Tag = sys; dataGridViewExplore.Rows[rowindex].DefaultCellStyle.ForeColor = (sys != null && sys.HasCoordinate) ? _discoveryForm.theme.VisitedSystemColor : _discoveryForm.theme.NonVisitedSystemColor; if (sys != null) { if (sys.HasCoordinate) { dataGridViewExplore[2, rowindex].Value = sys.x.ToString("0.00"); dataGridViewExplore[3, rowindex].Value = sys.y.ToString("0.00"); dataGridViewExplore[4, rowindex].Value = sys.z.ToString("0.00"); } dataGridViewExplore[idxVisits, rowindex].Value = hl.GetVisitsCount(sysname).ToString(); List <JournalScan> scans = hl.GetScans(sysname); dataGridViewExplore[idxScans, rowindex].Value = scans.Count.ToString(); string pristar = ""; // Search for primary star foreach (var scan in scans) { if (scan.IsStar && scan.DistanceFromArrivalLS == 0.0) { pristar = scan.StarType; break; } } dataGridViewExplore[idxPriStar, rowindex].Value = pristar; string info = ""; foreach (var scan in scans) { if (scan.IsStar) { if (scan.StarTypeID == EliteDangerous.EDStar.AeBe) { info = info + " " + "AeBe"; } if (scan.StarTypeID == EliteDangerous.EDStar.N) { info = info + " " + "NS"; } if (scan.StarTypeID == EliteDangerous.EDStar.H) { info = info + " " + "BH"; } } else { if (scan.PlanetTypeID == EliteDangerous.EDPlanet.Earthlike_body) { info = info + " " + "ELW"; } if (scan.PlanetTypeID == EliteDangerous.EDPlanet.Water_world) { info = info + " " + "WW"; } } } dataGridViewExplore[idxInfo, rowindex].Value = info.Trim(); string note = ""; SystemNoteClass sn = SystemNoteClass.GetNoteOnSystem(sys.name, sys.id_edsm); if (sn != null && !string.IsNullOrWhiteSpace(sn.Note)) { note = sn.Note; } else { BookmarkClass bkmark = BookmarkClass.bookmarks.Find(x => x.StarName != null && x.StarName.Equals(sys.name)); if (bkmark != null && !string.IsNullOrWhiteSpace(bkmark.Note)) { note = bkmark.Note; } else { var gmo = _discoveryForm.galacticMapping.Find(sys.name); if (gmo != null && !string.IsNullOrWhiteSpace(gmo.description)) { note = gmo.description; } } } dataGridViewExplore[idxNote, rowindex].Value = Tools.WordWrap(note, 60); } if (sys == null && sysname != "") { dataGridViewExplore.Rows[rowindex].ErrorText = "System not known"; } else { dataGridViewExplore.Rows[rowindex].ErrorText = ""; } } }
public static void showBookmarkForm(Object sender, EDDiscoveryForm discoveryForm, ISystem cursystem, BookmarkClass curbookmark, bool notedsystem) { Form senderForm = ((Control)sender)?.FindForm() ?? discoveryForm; // try and find the associated bookmark.. BookmarkClass bkmark = (curbookmark != null) ? curbookmark : BookmarkClass.bookmarks.Find(x => x.StarName != null && x.StarName.Equals(cursystem.Name)); SystemNoteClass sn = (cursystem != null) ? SystemNoteClass.GetNoteOnSystem(cursystem.Name, cursystem.EDSMID) : null; string note = (sn != null) ? sn.Note : ""; BookmarkForm frm = new BookmarkForm(); if (notedsystem && bkmark == null) // note on a system { long targetid = TargetClass.GetTargetNotedSystem(); // who is the target of a noted system (0=none) long noteid = sn.id; frm.InitialisePos(cursystem.X, cursystem.Y, cursystem.Z); frm.NotedSystem(cursystem.Name, note, noteid == targetid); // note may be passed in null frm.ShowDialog(senderForm); if ((frm.IsTarget && targetid != noteid) || (!frm.IsTarget && targetid == noteid)) // changed.. { if (frm.IsTarget) { TargetClass.SetTargetNotedSystem(cursystem.Name, noteid, cursystem.X, cursystem.Y, cursystem.Z); } else { TargetClass.ClearTarget(); } } } else { bool regionmarker = false; DateTime tme; long targetid = TargetClass.GetTargetBookmark(); // who is the target of a bookmark (0=none) if (bkmark == null) // new bookmark { frm.InitialisePos(cursystem.X, cursystem.Y, cursystem.Z); tme = DateTime.Now; frm.NewSystemBookmark(cursystem.Name, note, tme.ToString()); } else // update bookmark { frm.InitialisePos(bkmark.x, bkmark.y, bkmark.z); regionmarker = bkmark.isRegion; tme = bkmark.Time; frm.Update(regionmarker ? bkmark.Heading : bkmark.StarName, note, bkmark.Note, tme.ToString(), regionmarker, targetid == bkmark.id); } DialogResult res = frm.ShowDialog(senderForm); if (res == DialogResult.OK) { BookmarkClass newcls = new BookmarkClass(); if (regionmarker) { newcls.Heading = frm.StarHeading; } else { newcls.StarName = frm.StarHeading; } newcls.x = double.Parse(frm.x); newcls.y = double.Parse(frm.y); newcls.z = double.Parse(frm.z); newcls.Time = tme; newcls.Note = frm.Notes; if (bkmark != null) { newcls.id = bkmark.id; newcls.Update(); } else { newcls.Add(); } if ((frm.IsTarget && targetid != newcls.id) || (!frm.IsTarget && targetid == newcls.id)) // changed.. { if (frm.IsTarget) { TargetClass.SetTargetBookmark(regionmarker ? ("RM:" + newcls.Heading) : newcls.StarName, newcls.id, newcls.x, newcls.y, newcls.z); } else { TargetClass.ClearTarget(); } } } else if (res == DialogResult.Abort && bkmark != null) { if (targetid == bkmark.id) { TargetClass.ClearTarget(); } bkmark.Delete(); } } discoveryForm.NewTargetSet(sender); }
public override bool ExecuteAction(ActionProgramRun ap) { string res; if (ap.functions.ExpandString(UserData, out res) != BaseUtils.Functions.ExpandResult.Failed) { StringParser sp = new StringParser(res); string prefix = "T_"; string cmdname = sp.NextWord(); if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase)) { prefix = sp.NextWord(); if (prefix == null) { ap.ReportError("Missing name after Prefix in Target"); return(true); } cmdname = sp.NextWord(); } if (cmdname != null) { if (cmdname.Equals("GET", StringComparison.InvariantCultureIgnoreCase)) { bool tset = EliteDangerousCore.DB.TargetClass.IsTargetSet(); ap[prefix + "TargetSet"] = tset.ToStringIntValue(); if (tset) { EliteDangerousCore.DB.TargetClass.GetTargetPosition(out string name, out double x, out double y, out double z); ap[prefix + "TargetType"] = EliteDangerousCore.DB.TargetClass.GetTargetType().ToString(); ap[prefix + "TargetPositionFullName"] = name; ap[prefix + "TargetPositionName"] = EliteDangerousCore.DB.TargetClass.GetNameWithoutPrefix(name); if (!double.IsNaN(x) && !double.IsNaN(y) && !double.IsNaN(z)) { ap[prefix + "TargetPositionX"] = x.ToStringInvariant("0.##"); ap[prefix + "TargetPositionY"] = y.ToStringInvariant("0.##"); ap[prefix + "TargetPositionZ"] = z.ToStringInvariant("0.##"); } } } else if (cmdname.Equals("CLEAR", StringComparison.InvariantCultureIgnoreCase)) { bool tset = EliteDangerousCore.DB.TargetClass.IsTargetSet(); ap[prefix + "TargetClear"] = tset.ToStringIntValue(); if (tset) { TargetClass.ClearTarget(); } } else { string name = sp.NextQuotedWord(); if (name != null) { EDDiscoveryForm discoveryform = (ap.actioncontroller as ActionController).DiscoveryForm; if (cmdname.Equals("BOOKMARK", StringComparison.InvariantCultureIgnoreCase)) { BookmarkClass bk = GlobalBookMarkList.Instance.FindBookmarkOnSystem(name); // has it been bookmarked? if (bk != null) { TargetClass.SetTargetBookmark(name, bk.id, bk.x, bk.y, bk.z); discoveryform.NewTargetSet(this); } else { ap.ReportError("Bookmark '" + name + "' not found"); } } else if (cmdname.Equals("GMO", StringComparison.InvariantCultureIgnoreCase)) { EliteDangerousCore.EDSM.GalacticMapObject gmo = discoveryform.galacticMapping.Find(name, true, true); if (gmo != null) { TargetClass.SetTargetGMO("G:" + gmo.name, gmo.id, gmo.points[0].X, gmo.points[0].Y, gmo.points[0].Z); discoveryform.NewTargetSet(this); } else { ap.ReportError("GMO '" + name + "' not found"); } } else if (cmdname.Equals("NOTE", StringComparison.InvariantCultureIgnoreCase)) { SystemNoteClass nc = SystemNoteClass.GetNoteOnSystem(name); // has it got a note? ISystem sc = discoveryform.history.FindSystem(name); if (sc != null && sc.HasCoordinate && nc != null) { TargetClass.SetTargetNotedSystem(name, nc.id, sc.X, sc.Y, sc.Z); discoveryform.NewTargetSet(this); } else { ap.ReportError("No Note found on entries in system '" + name + "'"); } } else { ap.ReportError("Unknown TARGET command"); } } else { ap.ReportError("Missing name in command"); } } } else { ap.ReportError("Missing TARGET command"); } } else { ap.ReportError(res); } return(true); }
private void UpdateSystemRows() { for (int rowindex = 0; rowindex < dataGridView.Rows.Count; rowindex++) { dataGridView[1, rowindex].ReadOnly = true; dataGridView[2, rowindex].ReadOnly = true; dataGridView[3, rowindex].ReadOnly = true; dataGridView[4, rowindex].ReadOnly = true; dataGridView[5, rowindex].ReadOnly = true; string sysname = dataGridView[0, rowindex].Value.ToString(); if (sysname.HasChars()) { var sys = discoveryform.history.FindSystem(sysname); dataGridView[1, rowindex].Value = ""; if (rowindex > 0 && dataGridView[0, rowindex - 1].Value != null && dataGridView[0, rowindex].Value != null) { string prevsysname = dataGridView[0, rowindex - 1].Value.ToString(); var prevsys = discoveryform.history.FindSystem(prevsysname); if ((sys?.HasCoordinate ?? false) && (prevsys?.HasCoordinate ?? false)) { double dist = sys.Distance(prevsys); string strdist = dist >= 0 ? ((double)dist).ToString("0.00") : ""; dataGridView[1, rowindex].Value = strdist; } } dataGridView[0, rowindex].Tag = sys; dataGridView.Rows[rowindex].Cells[0].Style.ForeColor = (sys != null && sys.HasCoordinate) ? Color.Empty : discoveryform.theme.UnknownSystemColor; string note = ""; SystemNoteClass sn = SystemNoteClass.GetNoteOnSystem(sysname); if (sn != null && !string.IsNullOrWhiteSpace(sn.Note)) { note = sn.Note; } BookmarkClass bkmark = GlobalBookMarkList.Instance.FindBookmarkOnSystem(sysname); if (bkmark != null && !string.IsNullOrWhiteSpace(bkmark.Note)) { note = note.AppendPrePad(bkmark.Note, "; "); } var gmo = discoveryform.galacticMapping.Find(sysname); if (gmo != null && !string.IsNullOrWhiteSpace(gmo.description)) { note = note.AppendPrePad(gmo.description, "; "); } dataGridView[2, rowindex].Value = note; if (sys != null && sys.HasCoordinate) { dataGridView[3, rowindex].Value = sys.X.ToString("0.0.#"); dataGridView[4, rowindex].Value = sys.Y.ToString("0.0.#"); dataGridView[5, rowindex].Value = sys.Z.ToString("0.0.#"); dataGridView.Rows[rowindex].ErrorText = ""; } else { dataGridView.Rows[rowindex].ErrorText = "System not known location".T(EDTx.UserControlExpedition_EDSMUnk); } } } txtCmlDistance.Text = txtP2PDIstance.Text = ""; if (dataGridView.Rows.Count > 1) { double distance = 0; ISystem firstSC = null; ISystem lastSC = null; for (int i = 0; i < dataGridView.Rows.Count; i++) { if (firstSC == null && dataGridView[0, i].Tag != null) { firstSC = (ISystem)dataGridView[0, i].Tag; } if (dataGridView[0, i].Tag != null) { lastSC = (ISystem)dataGridView[0, i].Tag; } String value = dataGridView[1, i].Value as string; if (!String.IsNullOrWhiteSpace(value)) { distance += Double.Parse(value); } } txtCmlDistance.Text = distance.ToString("0.00") + "LY"; if (firstSC != null && lastSC != null) { distance = firstSC.Distance(lastSC); txtP2PDIstance.Text = distance.ToString("0.00") + "LY"; } } }
public static void setTargetSystem(EDDiscoveryForm _discoveryForm, String sn, Boolean prompt) { if (string.IsNullOrWhiteSpace(sn)) { return; } ISystem sc = _discoveryForm.history.FindSystem(sn); string msgboxtext = null; if (sc != null && sc.HasCoordinate) { SystemNoteClass nc = SystemNoteClass.GetNoteOnSystem(sc.name, sc.id_edsm); // has it got a note? if (nc != null) { TargetClass.SetTargetNotedSystem(sc.name, nc.id, sc.x, sc.y, sc.z); msgboxtext = "Target set on system with note " + sc.name; } else { BookmarkClass bk = BookmarkClass.FindBookmarkOnSystem(sn); // has it been bookmarked? if (bk != null) { TargetClass.SetTargetBookmark(sc.name, bk.id, bk.x, bk.y, bk.z); msgboxtext = "Target set on booked marked system " + sc.name; } else { bool createbookmark = false; if ((prompt && ExtendedControls.MessageBoxTheme.Show("Make a bookmark on " + sc.name + " and set as target?", "Make Bookmark", MessageBoxButtons.OKCancel) == DialogResult.OK) || !prompt) { createbookmark = true; } if (createbookmark) { BookmarkClass newbk = new BookmarkClass(); newbk.StarName = sn; newbk.x = sc.x; newbk.y = sc.y; newbk.z = sc.z; newbk.Time = DateTime.Now; newbk.Note = ""; newbk.Add(); TargetClass.SetTargetBookmark(sc.name, newbk.id, newbk.x, newbk.y, newbk.z); } } } } else { if (sn.Length > 2 && sn.Substring(0, 2).Equals("G:")) { sn = sn.Substring(2, sn.Length - 2); } GalacticMapObject gmo = _discoveryForm.galacticMapping.Find(sn, true, true); // ignore if its off, find any part of string, find if disabled if (gmo != null) { TargetClass.SetTargetGMO("G:" + gmo.name, gmo.id, gmo.points[0].X, gmo.points[0].Y, gmo.points[0].Z); msgboxtext = "Target set on galaxy object " + gmo.name; } else { msgboxtext = "Unknown system, system is without co-ordinates or galaxy object not found"; } } _discoveryForm.NewTargetSet(); // tells everyone who cares a new target was set if (msgboxtext != null && prompt) { ExtendedControls.MessageBoxTheme.Show(msgboxtext, "Create a target", MessageBoxButtons.OK); } }