Ejemplo n.º 1
0
        private void UpdateFrom(bool updatename)
        {
            changesilence = true;

            if (textBox_From.ReadOnly == false)                // if entering system name..
            {
                ISystem ds1 = discoveryform.history.FindSystem(SystemNameOnly(textBox_From.Text), discoveryform.galacticMapping);

                if (ds1 != null)
                {
                    if (updatename)                          // can't fix it as you type.. so leave alone
                    {
                        if (ds1 is GalacticMapSystem)
                        {
                            GalacticMapSystem gms = (GalacticMapSystem)ds1;
                            textBox_From.Text = gms.GalMapObject.name;
                        }
                        else
                        {
                            textBox_From.Text = ds1.Name;
                        }
                    }

                    textBox_FromName.Text = ds1.Name;
                    textBox_FromX.Text    = ds1.X.ToString("0.00");
                    textBox_FromY.Text    = ds1.Y.ToString("0.00");
                    textBox_FromZ.Text    = ds1.Z.ToString("0.00");
                }
                else
                {
                    textBox_FromX.Text = textBox_FromY.Text = textBox_FromZ.Text = "";
                }
            }
            else
            {
                string  res = "";
                Point3D curpos;
                if (GetCoordsFrom(out curpos))
                {
                    ISystem nearest = SystemCache.FindNearestSystemTo(curpos.X, curpos.Y, curpos.Z, 100);

                    if (nearest != null)
                    {
                        double distance = Point3D.DistanceBetween(curpos, new Point3D(nearest.X, nearest.Y, nearest.Z));
                        if (distance < 0.1)
                        {
                            res = nearest.Name;
                        }
                        else
                        {
                            res = nearest.Name + " @ " + distance.ToString("0.00") + "ly";
                        }
                    }
                }

                textBox_From.Text     = res;
                textBox_FromName.Text = res;
            }

            UpdateDistance();

            changesilence        = false;
            button_Route.Enabled = IsValid();
        }
Ejemplo n.º 2
0
        private void UpdateTo(object sender, string optupdateto = null)
        {
            changesilence = true;

            if (optupdateto != null)
            {
                textBox_To.Text = optupdateto;
            }

            if (sender == textBox_To)
            {
                ISystem ds1 = SystemCache.FindSystem(SystemNameOnly(textBox_To.Text), discoveryform.galacticMapping, true);
                if (ds1 != null)
                {
                    textBox_ToName.Text = ds1.Name;
                    textBox_ToX.Text    = ds1.X.ToString("0.00");
                    textBox_ToY.Text    = ds1.Y.ToString("0.00");
                    textBox_ToZ.Text    = ds1.Z.ToString("0.00");
                }
                else
                {
                    textBox_ToX.Text = textBox_ToY.Text = textBox_ToZ.Text = "";
                }
            }
            else
            {
                string res = "", resname = "";

                if (GetCoordsTo(out Point3D curpos))
                {
                    ISystem           nearest    = SystemCache.FindNearestSystemTo(curpos.X, curpos.Y, curpos.Z, 100);
                    GalacticMapObject nearestgmo = discoveryform.galacticMapping.FindNearest(curpos.X, curpos.Y, curpos.Z);

                    if (nearest != null)
                    {
                        if (nearestgmo != null && nearest.Distance(curpos.X, curpos.Y, curpos.Z) > nearestgmo.GetSystem().Distance(curpos.X, curpos.Y, curpos.Z))
                        {
                            nearest = nearestgmo.GetSystem();
                        }
                    }
                    else
                    {
                        nearest = nearestgmo?.GetSystem();
                    }

                    if (nearest != null)
                    {
                        res = resname = nearest.Name;

                        double distance = Point3D.DistanceBetween(curpos, new Point3D(nearest.X, nearest.Y, nearest.Z));
                        if (distance > 0.1)
                        {
                            resname = nearest.Name + " @ " + distance.ToString("0.00") + "ly";
                        }
                    }
                }

                textBox_To.Text     = res;
                textBox_ToName.Text = resname;
            }

            UpdateDistance();
            button_Route.Enabled = IsValid();
            changesilence        = false;
        }