void drawBaseManagerWindow(int windowID)
        {
            string     Base;
            string     Base2;
            float      Range;
            LaunchSite lNearest;
            LaunchSite lBase;
            LaunchSite lBase2;
            string     smessage = "";

            BoxNoBorder = new GUIStyle(GUI.skin.box);
            BoxNoBorder.normal.background = null;
            BoxNoBorder.normal.textColor  = Color.white;

            LabelInfo = new GUIStyle(GUI.skin.label);
            LabelInfo.normal.background = null;
            LabelInfo.normal.textColor  = Color.white;
            LabelInfo.fontSize          = 13;
            LabelInfo.fontStyle         = FontStyle.Bold;
            LabelInfo.padding.left      = 3;
            LabelInfo.padding.top       = 0;
            LabelInfo.padding.bottom    = 0;

            DeadButton = new GUIStyle(GUI.skin.button);
            DeadButton.normal.background  = null;
            DeadButton.hover.background   = null;
            DeadButton.active.background  = null;
            DeadButton.focused.background = null;
            DeadButton.normal.textColor   = Color.white;
            DeadButton.hover.textColor    = Color.white;
            DeadButton.active.textColor   = Color.white;
            DeadButton.focused.textColor  = Color.white;
            DeadButton.fontSize           = 14;
            DeadButton.fontStyle          = FontStyle.Bold;

            DeadButtonRed = new GUIStyle(GUI.skin.button);
            DeadButtonRed.normal.background  = null;
            DeadButtonRed.hover.background   = null;
            DeadButtonRed.active.background  = null;
            DeadButtonRed.focused.background = null;
            DeadButtonRed.normal.textColor   = Color.red;
            DeadButtonRed.hover.textColor    = Color.yellow;
            DeadButtonRed.active.textColor   = Color.red;
            DeadButtonRed.focused.textColor  = Color.red;
            DeadButtonRed.fontSize           = 12;
            DeadButtonRed.fontStyle          = FontStyle.Bold;

            GUILayout.BeginHorizontal();
            {
                GUI.enabled = false;
                GUILayout.Button("-KK-", DeadButton, GUILayout.Height(16));

                GUILayout.FlexibleSpace();

                GUILayout.Button("Inflight Base Boss", DeadButton, GUILayout.Height(16));

                GUILayout.FlexibleSpace();

                GUI.enabled = true;

                if (GUILayout.Button("X", DeadButtonRed, GUILayout.Height(16)))
                {
                    bShowFacilities = false;
                    KerbalKonstructs.instance.showFlightManager = false;
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));

            GUILayout.Space(5);
            GUILayout.Box("Flight Tools", BoxNoBorder);

            GUILayout.BeginHorizontal();
            {
                GUILayout.Space(2);
                GUILayout.Label("ATC ", LabelInfo);

                if (KerbalKonstructs.instance.enableATC)
                {
                    tToggle = tIconOpen;
                }
                else
                {
                    tToggle = tIconClosed;
                }

                if (GUILayout.Button(tToggle, GUILayout.Height(18), GUILayout.Width(18)))
                {
                    KerbalKonstructs.instance.updateCache();

                    if (KerbalKonstructs.instance.enableATC)
                    {
                        KerbalKonstructs.instance.enableATC = false;
                    }
                    else
                    {
                        KerbalKonstructs.instance.enableATC = true;
                    }
                }

                KerbalKonstructs.instance.showATC = (KerbalKonstructs.instance.enableATC);

                GUILayout.FlexibleSpace();
                GUILayout.Label("NGS ", LabelInfo);

                if (KerbalKonstructs.instance.enableNGS)
                {
                    tToggle2 = tIconOpen;
                }
                else
                {
                    tToggle2 = tIconClosed;
                }

                if (GUILayout.Button(tToggle2, GUILayout.Height(18), GUILayout.Width(18)))
                {
                    if (KerbalKonstructs.instance.enableNGS)
                    {
                        KerbalKonstructs.instance.enableNGS = false;
                    }
                    else
                    {
                        KerbalKonstructs.instance.enableNGS = true;
                    }
                }

                KerbalKonstructs.instance.showNGS = (KerbalKonstructs.instance.enableNGS);

                GUILayout.FlexibleSpace();
                GUILayout.Label("Downlink ", LabelInfo);

                if (KerbalKonstructs.instance.enableDownlink)
                {
                    tToggle2 = tIconOpen;
                }
                else
                {
                    tToggle2 = tIconClosed;
                }

                if (GUILayout.Button(tToggle2, GUILayout.Height(18), GUILayout.Width(18)))
                {
                    if (KerbalKonstructs.instance.enableDownlink)
                    {
                        KerbalKonstructs.instance.enableDownlink = false;
                    }
                    else
                    {
                        KerbalKonstructs.instance.enableDownlink = true;
                    }
                }

                KerbalKonstructs.instance.showDownlink = (KerbalKonstructs.instance.enableDownlink);

                GUILayout.Space(2);
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(2);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(2);

            GUILayout.Box("Active Beacons", BoxNoBorder);

            if (MiscUtils.isCareerGame())
            {
                GUILayout.BeginHorizontal();
                {
                    string snearestopen = "";
                    LaunchSiteManager.getNearestOpenBase(FlightGlobals.ActiveVessel.GetTransform().position, out Base, out Range, out lNearest);
                    if (FlightGlobals.ActiveVessel.altitude > 75000)
                    {
                        GUILayout.Label("No base's beacon in range at this altitude.", LabelInfo);
                    }
                    else
                    if (Base == "")
                    {
                        GUILayout.Label("No open base found.", LabelInfo);
                    }
                    else
                    {
                        if (Range < 10000)
                        {
                            snearestopen = Base + " at " + Range.ToString("#0.0") + " m";
                        }
                        else
                        {
                            snearestopen = Base + " at " + (Range / 1000).ToString("#0.0") + " km";
                        }

                        GUILayout.Space(5);
                        GUILayout.Label("Nearest Open: ", LabelInfo);
                        GUILayout.Label(snearestopen, LabelInfo, GUILayout.Width(150));

                        if (KerbalKonstructs.instance.enableNGS)
                        {
                            GUILayout.FlexibleSpace();
                            if (GUILayout.Button("NGS", GUILayout.Height(21)))
                            {
                                NavGuidanceSystem.setTargetSite(lNearest);
                                smessage = "NGS set to " + Base;
                                MiscUtils.HUDMessage(smessage, 10, 2);
                            }
                        }
                    }
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(2);
            }

            GUILayout.BeginHorizontal();
            {
                string sNearestbase = "";
                LaunchSiteManager.getNearestBase(FlightGlobals.ActiveVessel.GetTransform().position, out Base, out Base2, out Range, out lBase, out lBase2);

                if (FlightGlobals.ActiveVessel.altitude > 75000)
                {
                    GUILayout.Label("No base's beacon in range at this altitude.", LabelInfo);
                }
                else
                if (Base == "")
                {
                    GUILayout.Label("No nearest base found.", LabelInfo);
                }
                else
                {
                    if (Range < 10000)
                    {
                        sNearestbase = Base + " at " + Range.ToString("#0.0") + " m";
                    }
                    else
                    {
                        sNearestbase = Base + " at " + (Range / 1000).ToString("#0.0") + " km";
                    }

                    GUILayout.Space(5);
                    GUILayout.Label("Nearest Base: ", LabelInfo);
                    GUILayout.Label(sNearestbase, LabelInfo, GUILayout.Width(150));

                    if (KerbalKonstructs.instance.enableNGS)
                    {
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("NGS", GUILayout.Height(21)))
                        {
                            NavGuidanceSystem.setTargetSite(lBase);

                            smessage = "NGS set to " + Base;
                            MiscUtils.HUDMessage(smessage, 10, 2);
                        }
                    }
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(2);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(2);
            GUILayout.Box("Base Status", BoxNoBorder);

            if (MiscUtils.isCareerGame())
            {
                bool bLanded = (FlightGlobals.ActiveVessel.Landed);

                if (Range < 2000)
                {
                    string sClosed;
                    float  fOpenCost;
                    LaunchSiteManager.getSiteOpenCloseState(Base, out sClosed, out fOpenCost);
                    fOpenCost = fOpenCost / 2f;

                    if (bLanded && sClosed == "Closed")
                    {
                        GUILayout.Space(2);
                        GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
                        GUILayout.Space(2);
                        if (GUILayout.Button("Open Base for " + fOpenCost + " funds", GUILayout.Height(23)))
                        {
                            double currentfunds = Funding.Instance.Funds;

                            if (fOpenCost > currentfunds)
                            {
                                MiscUtils.HUDMessage("Insufficient funds to open this site!", 10, 0);
                            }
                            else
                            {
                                Funding.Instance.AddFunds(-fOpenCost, TransactionReasons.Cheating);

                                LaunchSiteManager.setSiteOpenCloseState(Base, "Open");
                                smessage = Base + " opened";
                                MiscUtils.HUDMessage(smessage, 10, 2);
                            }
                        }
                    }

                    if (bLanded && sClosed == "Open")
                    {
                        GUI.enabled = false;
                        GUILayout.Button("Base is Open", GUILayout.Height(23));
                        GUI.enabled = true;
                    }

                    if (bLanded && (sClosed == "OpenLocked" || sClosed == "ClosedLocked"))
                    {
                        GUI.enabled = false;
                        GUILayout.Button("Base cannot be opened or closed", GUILayout.Height(23));
                        GUI.enabled = true;
                    }

                    GUILayout.Space(2);
                    GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
                    GUILayout.Space(2);
                }
                else
                {
                    GUILayout.Label("Bases can only be opened or closed at the base when within 2km of the base.", LabelInfo);
                }

                if (Range > 100000)
                {
                    if (bLanded)
                    {
                        GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
                        GUILayout.Space(2);
                        GUILayout.Label("This feature is WIP.", LabelInfo);
                        GUI.enabled = false;
                        if (GUILayout.Button("Found a New Base", GUILayout.Height(23)))
                        {
                            foundingBase = true;
                        }
                        GUI.enabled = true;
                        GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
                        GUILayout.Space(2);
                    }
                }
                else
                {
                    GUILayout.Label("This feature is WIP.", LabelInfo);
                    GUILayout.Label("New bases cannot be built within 100 km of an existing base.", LabelInfo);
                }
            }

            GUILayout.Space(2);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(2);
            GUILayout.Box("Operational Facilities", BoxNoBorder);

            bool bAreFacilities = false;

            if (FlightGlobals.ActiveVessel.Landed)
            {
                if (GUILayout.Button("Show/Hide", GUILayout.Height(23)))
                {
                    if (bShowFacilities)
                    {
                        bShowFacilities = false;
                    }
                    else
                    {
                        foreach (StaticObject soStaticobj in KerbalKonstructs.instance.getStaticDB().getAllStatics())
                        {
                            if ((string)soStaticobj.model.getSetting("DefaultFacilityType") == "None")
                            {
                                continue;
                            }

                            if (soStaticobj.pqsCity.sphere == FlightGlobals.currentMainBody.pqsController)
                            {
                                var dist2 = Vector3.Distance(FlightGlobals.ActiveVessel.GetTransform().position, soStaticobj.gameObject.transform.position);
                                if (dist2 > 5000f)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                continue;
                            }

                            PersistenceUtils.loadStaticPersistence(soStaticobj);
                        }

                        bShowFacilities = true;
                    }
                }

                if (bShowFacilities)
                {
                    scrollPos = GUILayout.BeginScrollView(scrollPos);
                    foreach (StaticObject obj in KerbalKonstructs.instance.getStaticDB().getAllStatics())
                    {
                        bool isLocal = true;
                        if (obj.pqsCity.sphere == FlightGlobals.currentMainBody.pqsController)
                        {
                            var dist = Vector3.Distance(FlightGlobals.ActiveVessel.GetTransform().position, obj.gameObject.transform.position);
                            isLocal = dist < 5000f;
                        }
                        else
                        {
                            isLocal = false;
                        }

                        if ((string)obj.model.getSetting("DefaultFacilityType") == "None")
                        {
                            isLocal = false;
                        }

                        if (isLocal)
                        {
                            bAreFacilities = true;
                            GUILayout.BeginHorizontal();
                            {
                                bIsOpen = ((string)obj.getSetting("OpenCloseState") == "Open");

                                if (!bIsOpen)
                                {
                                    iFundsOpen2 = (float)obj.model.getSetting("cost");
                                    if (iFundsOpen2 == 0)
                                    {
                                        bIsOpen = true;
                                    }
                                }

                                if (GUILayout.Button((string)obj.model.getSetting("title"), GUILayout.Height(23)))
                                {
                                    selectedObject = obj;
                                    KerbalKonstructs.instance.selectObject(obj, false, true, false);
                                    PersistenceUtils.loadStaticPersistence(obj);
                                    FacilityManager.setSelectedFacility(obj);
                                    KerbalKonstructs.instance.showFacilityManager = true;
                                }

                                if (bIsOpen)
                                {
                                    GUILayout.Label(tIconOpen, GUILayout.Height(23), GUILayout.Width(23));
                                }

                                if (!bIsOpen)
                                {
                                    GUILayout.Label(tIconClosed, GUILayout.Height(23), GUILayout.Width(23));
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                    }
                    GUILayout.EndScrollView();
                }
                else
                {
                    GUILayout.Label("Click the button above to display a list of nearby operational facilities.", LabelInfo);

                    if (KerbalKonstructs.instance.DebugMode)
                    {
                        GUILayout.Box("Debug Mode ActiveVessel Report");
                        GUILayout.Label("Name " + FlightGlobals.ActiveVessel.vesselName);
                        GUILayout.Label("Acceleration " + FlightGlobals.ActiveVessel.acceleration.ToString());
                        GUILayout.Label("Angular Momentum " + FlightGlobals.ActiveVessel.angularMomentum.ToString("#0.000"));
                        GUILayout.Label("Angular Velocity " + FlightGlobals.ActiveVessel.angularVelocity.ToString("#0.000"));
                        //GUILayout.Label("Centrifugal Acc " + FlightGlobals.ActiveVessel.CentrifugalAcc.ToString());
                        GUILayout.Label("Horiz Srf Speed " + FlightGlobals.ActiveVessel.horizontalSrfSpeed.ToString("#0.00"));
                        GUILayout.Label("Indicated Air Speed " + FlightGlobals.ActiveVessel.indicatedAirSpeed.ToString("#0.00"));
                        GUILayout.Label("Mach " + FlightGlobals.ActiveVessel.mach.ToString("#0.00"));
                        GUILayout.Label("Orbit Speed " + FlightGlobals.ActiveVessel.obt_speed.ToString("#0.00"));
                        GUILayout.Label("Orbit Velocity " + FlightGlobals.ActiveVessel.obt_velocity.ToString());
                        GUILayout.Label("Perturbation " + FlightGlobals.ActiveVessel.perturbation.ToString());
                        GUILayout.Label("rb_velocity " + FlightGlobals.ActiveVessel.rb_velocity.ToString("#0.000"));
                        GUILayout.Label("Specific Acc " + FlightGlobals.ActiveVessel.specificAcceleration.ToString("#0.00"));
                        GUILayout.Label("speed " + FlightGlobals.ActiveVessel.speed.ToString("#0.00"));
                        GUILayout.Label("srf_velocity " + FlightGlobals.ActiveVessel.srf_velocity.ToString());
                        GUILayout.Label("srfspeed " + FlightGlobals.ActiveVessel.srfSpeed.ToString("#0.00"));
                    }
                }
            }
            else
            {
                GUILayout.Label("Nearby facilities can only be shown when landed.", LabelInfo);
                bShowFacilities = false;
            }

            if (bAreFacilities == false)
            {
                //GUILayout.Label("There are no nearby operational facilities.", LabelInfo);
            }

            GUILayout.FlexibleSpace();
            GUILayout.Space(2);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(2);
            GUILayout.Box("Other Features", BoxNoBorder);
            if (GUILayout.Button("Start Air Racing!", GUILayout.Height(23)))
            {
                KerbalKonstructs.instance.showRacingApp = true;
                AirRacing.runningRace                       = true;
                KerbalKonstructs.instance.showNGS           = false;
                KerbalKonstructs.instance.showFlightManager = false;
            }
            if (GUILayout.Button("Basic Orbital Data", GUILayout.Height(23)))
            {
                KerbalKonstructs.instance.showRacingApp = true;
                AirRacing.runningRace                       = false;
                AirRacing.basicorbitalhud                   = true;
                KerbalKonstructs.instance.showNGS           = false;
                KerbalKonstructs.instance.showFlightManager = false;
            }
            GUILayout.Space(5);

            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(2);

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
Beispiel #2
0
        public void drawIcons()
        {
            displayingTooltip = false;
            MapObject target = PlanetariumCamera.fetch.target;

            if (target.type == MapObject.MapObjectType.CELESTIALBODY)
            {
                // Do tracking stations first
                foreach (StaticObject obj in KerbalKonstructs.instance.getStaticDB().getAllStatics())
                {
                    bool display2 = false;
                    if ((string)obj.getSetting("FacilityType") == "TrackingStation")
                    {
                        if (!isOccluded(obj.gameObject.transform.position, target.celestialBody))
                        {
                            if (MiscUtils.isCareerGame())
                            {
                                //PersistenceUtils.loadStaticPersistence(obj);
                                string openclosed2 = (string)obj.getSetting("OpenCloseState");
                                // To do manage open and close state of tracking stations
                                if (KerbalKonstructs.instance.mapShowOpenT)                                 // && openclosed == "Open")
                                {
                                    display2 = true;
                                }
                                if (!KerbalKonstructs.instance.mapShowClosed && openclosed2 == "Closed")
                                {
                                    display2 = false;
                                }
                                if (!KerbalKonstructs.instance.mapShowOpen && openclosed2 == "Open")
                                {
                                    display2 = false;
                                }
                            }
                            else
                            {                             // Not a career game
                            }

                            if (display2)
                            {
                                Vector3 pos         = MapView.MapCamera.camera.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(obj.gameObject.transform.position));
                                Rect    screenRect2 = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16);
                                Graphics.DrawTexture(screenRect2, TrackingStationIcon);

                                if (screenRect2.Contains(Event.current.mousePosition) && !displayingTooltip)
                                {
                                    CelestialBody cPlanetoid = (CelestialBody)obj.getSetting("CelestialBody");

                                    var objectpos2    = cPlanetoid.transform.InverseTransformPoint(obj.gameObject.transform.position);
                                    var dObjectLat2   = NavUtils.GetLatitude(objectpos2);
                                    var dObjectLon2   = NavUtils.GetLongitude(objectpos2);
                                    var disObjectLat2 = dObjectLat2 * 180 / Math.PI;
                                    var disObjectLon2 = dObjectLon2 * 180 / Math.PI;

                                    if (disObjectLon2 < 0)
                                    {
                                        disObjectLon2 = disObjectLon2 + 360;
                                    }

                                    //Only display one tooltip at a time
                                    displayMapIconToolTip("Tracking Station " + "\n(Lat." + disObjectLat2.ToString("#0.00") + "/ Lon." + disObjectLon2.ToString("#0.00") + ")", pos);
                                    // TO DO Display Lat and Lon in tooltip too

                                    if (Event.current.type == EventType.mouseDown && Event.current.button == 0)
                                    {
                                        //MiscUtils.HUDMessage("Selected base is " + sToolTip + ".", 5f, 3);
                                        Debug.Log("KK: Selected station in map");
                                        float sTrackAngle = (float)obj.getSetting("TrackingAngle");
                                        Debug.Log("KK: Before save load " + sTrackAngle.ToString());
                                        float sTrackRange = (float)obj.getSetting("TrackingShort");
                                        Debug.Log("KK: Before save load " + sTrackRange.ToString());

                                        //PersistenceUtils.saveStaticPersistence(obj);
                                        PersistenceUtils.loadStaticPersistence(obj);

                                        float sTrackAngle2 = (float)obj.getSetting("TrackingAngle");
                                        Debug.Log("KK: After save load " + sTrackAngle2.ToString());
                                        float sTrackRange2 = (float)obj.getSetting("TrackingShort");
                                        Debug.Log("KK: After save load " + sTrackRange2.ToString());

                                        selectedFacility = obj;
                                        FacilityManager.setSelectedFacility(obj);
                                        KerbalKonstructs.instance.showFacilityManager = true;
                                        //EditorGUI.setTargetSite(selectedSite);
                                    }
                                }
                                else
                                {                                 // Mouse is not over tooltip
                                }
                            }
                            else
                            {                             // Filter set to not display
                            }
                        }
                        else
                        {                         // is occluded
                        }
                    }
                    else
                    {             // Not a tracking station
                    }
                }                 //end foreach

                // Then do launchsites
                List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();
                foreach (LaunchSite site in sites)
                {
                    bool display = false;
                    PSystemSetup.SpaceCenterFacility facility = PSystemSetup.Instance.GetSpaceCenterFacility(site.name);
                    if (facility != null)
                    {
                        PSystemSetup.SpaceCenterFacility.SpawnPoint sp = facility.GetSpawnPoint(site.name);
                        if (sp != null)
                        {
                            if (facility.facilityPQS == target.celestialBody.pqsController)
                            {
                                if (!isOccluded(sp.GetSpawnPointTransform().position, target.celestialBody))
                                {
                                    Vector3 pos        = MapView.MapCamera.camera.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(sp.GetSpawnPointTransform().position));
                                    Rect    screenRect = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16);

                                    string openclosed = site.openclosestate;
                                    string category   = site.category;

                                    if (KerbalKonstructs.instance.mapShowHelipads && category == "Helipad")
                                    {
                                        display = true;
                                    }
                                    if (KerbalKonstructs.instance.mapShowOther && category == "Other")
                                    {
                                        display = true;
                                    }
                                    if (KerbalKonstructs.instance.mapShowRocketbases && category == "RocketPad")
                                    {
                                        display = true;
                                    }
                                    if (KerbalKonstructs.instance.mapShowRunways && category == "Runway")
                                    {
                                        display = true;
                                    }

                                    if (display && MiscUtils.isCareerGame())
                                    {
                                        if (!KerbalKonstructs.instance.mapShowOpen && openclosed == "Open")
                                        {
                                            display = false;
                                        }
                                        if (!KerbalKonstructs.instance.mapShowClosed && openclosed == "Closed")
                                        {
                                            display = false;
                                        }
                                        if (KerbalKonstructs.instance.disableDisplayClosed && openclosed == "Closed")
                                        {
                                            display = false;
                                        }
                                    }

                                    if (display)
                                    {
                                        if (site.icon != null)
                                        {
                                            Graphics.DrawTexture(screenRect, site.icon);
                                        }
                                        else
                                        {
                                            switch (site.type)
                                            {
                                            case SiteType.VAB:
                                                Graphics.DrawTexture(screenRect, VABIcon);
                                                break;

                                            case SiteType.SPH:
                                                Graphics.DrawTexture(screenRect, SPHIcon);
                                                break;

                                            default:
                                                Graphics.DrawTexture(screenRect, ANYIcon);
                                                break;
                                            }
                                        }

                                        // Tooltip
                                        if (screenRect.Contains(Event.current.mousePosition) && !displayingTooltip)
                                        {
                                            //Only display one tooltip at a time
                                            string sToolTip = "";
                                            sToolTip = site.name;
                                            if (site.name == "Runway")
                                            {
                                                sToolTip = "KSC Runway";
                                            }
                                            if (site.name == "LaunchPad")
                                            {
                                                sToolTip = "KSC LaunchPad";
                                            }
                                            displayMapIconToolTip(sToolTip, pos);

                                            // Select a base by clicking on the icon
                                            if (Event.current.type == EventType.mouseDown && Event.current.button == 0)
                                            {
                                                MiscUtils.HUDMessage("Selected base is " + sToolTip + ".", 5f, 3);
                                                BaseManager.setSelectedSite(site);
                                                selectedSite = site;
                                                NavGuidanceSystem.setTargetSite(selectedSite);
                                                KerbalKonstructs.instance.showBaseManager = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        public void drawTrackingStations()
        {
            displayingTooltip2 = false;
            CelestialBody body = PlanetariumCamera.fetch.target.GetReferenceBody();

            // Do tracking stations first
            foreach (StaticObject obj in KerbalKonstructs.instance.getStaticDB().getAllStatics())
            {
                if (!MiscUtils.isCareerGame())
                {
                    break;
                }

                bool   display2    = false;
                string openclosed3 = "Closed";

                if ((string)obj.getSetting("FacilityType") != "TrackingStation")
                {
                    continue;
                }

                if (isOccluded(obj.gameObject.transform.position, body))
                {
                    if (KerbalKonstructs.instance.mapHideIconsBehindBody)
                    {
                        continue;
                    }
                }

                openclosed3 = (string)obj.getSetting("OpenCloseState");

                if ((float)obj.getSetting("OpenCost") == 0)
                {
                    openclosed3 = "Open";
                }

                if (KerbalKonstructs.instance.mapShowOpenT)
                {
                    display2 = true;
                }
                if (!KerbalKonstructs.instance.mapShowClosed && openclosed3 == "Closed")
                {
                    display2 = false;
                }
                if (!KerbalKonstructs.instance.mapShowOpen && openclosed3 == "Open")
                {
                    display2 = false;
                }

                if (!display2)
                {
                    continue;
                }

                Vector3 pos         = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(obj.gameObject.transform.position));
                Rect    screenRect6 = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16);
                // Distance between camera and spawnpoint sort of
                float fPosZ        = pos.z;
                float fRadarRadius = 12800 / fPosZ;

                if (fRadarRadius > 15)
                {
                    GUI.DrawTexture(screenRect6, UIMain.TrackingStationIcon, ScaleMode.ScaleToFit, true);
                }

                string sTarget  = (string)obj.getSetting("TargetID");
                float  fStRange = (float)obj.getSetting("TrackingShort");
                float  fStAngle = (float)obj.getSetting("TrackingAngle");

                if (openclosed3 == "Open" && KerbalKonstructs.instance.mapShowGroundComms)
                {
                    drawGroundComms(obj);
                }

                if ((string)obj.getSetting("TargetType") == "Craft" && sTarget != "None")
                {
                    Vessel vTargetVessel = TrackingStationGUI.GetTargetVessel(sTarget);
                    if (vTargetVessel == null)
                    {
                    }
                    else
                    {
                        if (vTargetVessel.state == Vessel.State.DEAD)
                        {
                        }
                        else
                        {
                            CelestialBody cbTStation = (CelestialBody)obj.getSetting("CelestialBody");
                            CelestialBody cbTCraft   = vTargetVessel.mainBody;

                            if (cbTStation == cbTCraft && openclosed3 == "Open" && KerbalKonstructs.instance.mapShowUplinks)
                            {
                                Vector3 vCraftPos = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(vTargetVessel.gameObject.transform.position));

                                float fRangeToTarget = TrackingStationGUI.GetRangeToCraft(obj, vTargetVessel);
                                int   iUplink        = TrackingStationGUI.GetUplinkQuality(fStRange, fRangeToTarget);
                                float fUplink        = (float)iUplink / 100;

                                float fRed   = 1f;
                                float fGreen = 0f;
                                float fBlue  = fUplink;
                                float fAlpha = 1f;

                                if (iUplink > 45)
                                {
                                    fRed   = 1f;
                                    fGreen = 0.65f + (fUplink / 10);
                                    fBlue  = 0f;
                                }

                                if (iUplink > 85)
                                {
                                    fRed   = 0f;
                                    fGreen = fUplink;
                                    fBlue  = 0f;
                                }

                                float fStationLOS = TrackingStationGUI.StationHasLOS(obj, vTargetVessel);

                                if (fStationLOS > fStAngle)
                                {
                                    fRed   = 1f;
                                    fGreen = 0f;
                                    fBlue  = 0f;
                                    fAlpha = 0.5f;
                                }

                                NavUtils.CreateLineMaterial(3);

                                GL.Begin(GL.LINES);
                                NavUtils.lineMaterial3.SetPass(0);
                                GL.Color(new Color(fRed, fGreen, fBlue, fAlpha));
                                GL.Vertex3(pos.x - Screen.width / 2, pos.y - Screen.height / 2, pos.z);
                                GL.Vertex3(vCraftPos.x - Screen.width / 2, vCraftPos.y - Screen.height / 2, vCraftPos.z);
                                GL.End();
                            }
                        }
                    }
                }

                if (screenRect6.Contains(Event.current.mousePosition) && !displayingTooltip2)
                {
                    CelestialBody cPlanetoid = (CelestialBody)obj.getSetting("CelestialBody");

                    var objectpos2    = cPlanetoid.transform.InverseTransformPoint(obj.gameObject.transform.position);
                    var dObjectLat2   = NavUtils.GetLatitude(objectpos2);
                    var dObjectLon2   = NavUtils.GetLongitude(objectpos2);
                    var disObjectLat2 = dObjectLat2 * 180 / Math.PI;
                    var disObjectLon2 = dObjectLon2 * 180 / Math.PI;

                    if (disObjectLon2 < 0)
                    {
                        disObjectLon2 = disObjectLon2 + 360;
                    }

                    //Only display one tooltip at a time
                    displayMapIconToolTip("Tracking Station " + "\n(Lat." + disObjectLat2.ToString("#0.00") + "/ Lon." + disObjectLon2.ToString("#0.00") + ")", pos);

                    if (Event.current.type == EventType.mouseDown && Event.current.button == 0)
                    {
                        float sTrackAngle = (float)obj.getSetting("TrackingAngle");
                        float sTrackRange = (float)obj.getSetting("TrackingShort");

                        PersistenceUtils.loadStaticPersistence(obj);

                        float sTrackAngle2 = (float)obj.getSetting("TrackingAngle");
                        float sTrackRange2 = (float)obj.getSetting("TrackingShort");

                        selectedFacility = obj;
                        FacilityManager.setSelectedFacility(obj);
                        WindowManager.instance.OpenWindow(KerbalKonstructs.instance.GUI_FacilityManager.drawFacilityManager);
                    }
                }
            }
        }