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 = 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 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 = 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(sender); // tells everyone who cares a new target was set if (msgboxtext != null && prompt) { ExtendedControls.MessageBoxTheme.Show(senderForm, msgboxtext, "Create a target", MessageBoxButtons.OK); } }
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 = BookmarkClass.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"; } else { dataGridViewRouteSystems.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.FindBookmarkOnSystem(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 = BookmarkClass.AddOrUpdateBookmark(bkmark, !regionmarker, frm.StarHeading, double.Parse(frm.x), double.Parse(frm.y), double.Parse(frm.z), tme, frm.Notes); 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); }
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; } HistoryEntry last = hl.GetLast; if (last == null) { return; } ISystem currentSystem = last.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 = 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 = 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 == 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 = BookmarkClass.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"; } else { dataGridViewExplore.Rows[rowindex].ErrorText = ""; } } }