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 = BookmarkClass.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); } }
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); }