private void RenderTargetSelectUI(GUIStyle sty, GUIStyle but)
        {
            GUILayout.Label("Select Target", sty);
            TargetMode = (TgtMode)GUILayout.SelectionGrid((int)TargetMode, sel_texts, 3, but);
            _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, GUILayout.Width(300), GUILayout.Height(300));
            List<Vessel> vesselList = new List<Vessel>(FlightGlobals.Vessels);
            List<CelestialBody> bodyList = new List<CelestialBody>(FlightGlobals.Bodies);

            switch (TargetMode)
            {
                case TgtMode.BODIES:
                    for (int i = 1; i < bodyList.Count; i++)
                    {
                        if (bodyList[i].orbit.referenceBody != this.part.vessel.orbit.referenceBody)
                            continue;
                        if (GUILayout.Button(bodyList[i].name, but, GUILayout.ExpandWidth(true)))
                        {
                            Mode = UIMode.SELECTED;
                            core.setTarget(bodyList[i]);
                        }

                    }

                    break;

                case TgtMode.DEBRIS:
                    for (int i = 0; i < vesselList.Count; i++)
                    {
                        // skip real vessels
                        if (vesselList[i].isCommandable == true)
                            continue;

                        // Skip stuff around other worlds.
                        if (part.vessel.orbit.referenceBody != vesselList[i].orbit.referenceBody)
                            continue;

                        if (GUILayout.Button(vesselList[i].vesselName, but, GUILayout.ExpandWidth(true)))
                        {
                            Mode = UIMode.SELECTED;
                            _selectedVesselInstanceId = vesselList[i].GetInstanceID();
                            _selectedVesselIndex = FlightGlobals.Vessels.IndexOf(vesselList[i]);
                            core.setTarget(vesselList[i]);
                        }
                    }

                    break;
                case TgtMode.VESSELS:
                    var vdc = new VesselDistanceComparer();

                    vdc.OriginVessel = part.vessel;

                    vesselList.Sort(vdc);

                    for (int i = 0; i < vesselList.Count; i++)
                    {
                        // Skip ourselves.
                        if (vesselList[i] == part.vessel)
                            continue;

                        if (vesselList[i].LandedOrSplashed)
                            continue;

                        // Skip stuff around other worlds.
                        if (part.vessel.orbit.referenceBody != vesselList[i].orbit.referenceBody)
                            continue;
                        //Skip Debris
                        if (vesselList[i].isCommandable == false)
                            continue;

                        // Calculate the distance.
                        float d = Vector3.Distance(vesselList[i].transform.position, part.vessel.transform.position);

                        if (GUILayout.Button((d / 1000).ToString("F1") + "km " + vesselList[i].vesselName, but,
                                             GUILayout.ExpandWidth(true)))
                        {
                            Mode = UIMode.SELECTED;
                            _selectedVesselInstanceId = vesselList[i].GetInstanceID();
                            _selectedVesselIndex = FlightGlobals.Vessels.IndexOf(vesselList[i]);
                            core.setTarget(vesselList[i]);
                        }
                    }
                    break;
            }
            GUILayout.EndScrollView();
        }
        private void RenderTargetSelectUI(GUIStyle sty, GUIStyle but)
        {
            GUILayout.Label("Select Target", sty);
            TargetMode      = (TgtMode)GUILayout.SelectionGrid((int)TargetMode, sel_texts, 3, but);
            _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, GUILayout.Width(300), GUILayout.Height(300));
            List <Vessel>        vesselList = new List <Vessel>(FlightGlobals.Vessels);
            List <CelestialBody> bodyList   = new List <CelestialBody>(FlightGlobals.Bodies);

            switch (TargetMode)
            {
            case TgtMode.BODIES:
                for (int i = 1; i < bodyList.Count; i++)
                {
                    if (bodyList[i].orbit.referenceBody != this.part.vessel.orbit.referenceBody)
                    {
                        continue;
                    }
                    if (GUILayout.Button(bodyList[i].name, but, GUILayout.ExpandWidth(true)))
                    {
                        Mode = UIMode.SELECTED;
                        core.setTarget(bodyList[i]);
                    }
                }

                break;

            case TgtMode.DEBRIS:
                for (int i = 0; i < vesselList.Count; i++)
                {
                    // skip real vessels
                    if (vesselList[i].isCommandable == true)
                    {
                        continue;
                    }

                    // Skip stuff around other worlds.
                    if (part.vessel.orbit.referenceBody != vesselList[i].orbit.referenceBody)
                    {
                        continue;
                    }

                    if (GUILayout.Button(vesselList[i].vesselName, but, GUILayout.ExpandWidth(true)))
                    {
                        Mode = UIMode.SELECTED;
                        _selectedVesselInstanceId = vesselList[i].GetInstanceID();
                        _selectedVesselIndex      = FlightGlobals.Vessels.IndexOf(vesselList[i]);
                        core.setTarget(vesselList[i]);
                    }
                }

                break;

            case TgtMode.VESSELS:
                var vdc = new VesselDistanceComparer();

                vdc.OriginVessel = part.vessel;

                vesselList.Sort(vdc);

                for (int i = 0; i < vesselList.Count; i++)
                {
                    // Skip ourselves.
                    if (vesselList[i] == part.vessel)
                    {
                        continue;
                    }

                    if (vesselList[i].LandedOrSplashed)
                    {
                        continue;
                    }

                    // Skip stuff around other worlds.
                    if (part.vessel.orbit.referenceBody != vesselList[i].orbit.referenceBody)
                    {
                        continue;
                    }
                    //Skip Debris
                    if (vesselList[i].isCommandable == false)
                    {
                        continue;
                    }

                    // Calculate the distance.
                    float d = Vector3.Distance(vesselList[i].transform.position, part.vessel.transform.position);

                    if (GUILayout.Button((d / 1000).ToString("F1") + "km " + vesselList[i].vesselName, but,
                                         GUILayout.ExpandWidth(true)))
                    {
                        Mode = UIMode.SELECTED;
                        _selectedVesselInstanceId = vesselList[i].GetInstanceID();
                        _selectedVesselIndex      = FlightGlobals.Vessels.IndexOf(vesselList[i]);
                        core.setTarget(vesselList[i]);
                    }
                }
                break;
            }
            GUILayout.EndScrollView();
        }