Пример #1
0
        // 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);
        }
Пример #2
0
        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);
        }