Esempio n. 1
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 drawLaunchsites()
        {
            displayingTooltip = false;
            int           iPulseRate = 180;
            CelestialBody body       = PlanetariumCamera.fetch.target.GetReferenceBody();

            iRadarCounter = iRadarCounter + 1;
            if (iRadarCounter > iPulseRate)
            {
                iRadarCounter = 0;
            }

            // Then do launchsites
            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            for (int index = 0; index < sites.Count; index++)
            {
                LaunchSite site = sites[index];

                // don't spam the logfile for the KSC. doesn't work roght now.
                if (site.name == "Runway" || site.name == "LaunchPad")
                {
                    continue;
                }

                // check if we should display the site or not this is the fastst check, so it shoud be first
                string openclosed = site.openclosestate;
                string category   = site.category;

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

                if (MiscUtils.isCareerGame())
                {
                    if (!KerbalKonstructs.instance.mapShowOpen && openclosed == "Open")
                    {
                        continue;
                    }
                    if (!KerbalKonstructs.instance.mapShowClosed && openclosed == "Closed")
                    {
                        continue;
                    }
                    if (KerbalKonstructs.instance.disableDisplayClosed && openclosed == "Closed")
                    {
                        continue;
                    }
                    if (openclosed == "OpenLocked" || openclosed == "ClosedLocked")
                    {
                        continue;
                    }
                }


                PSystemSetup.SpaceCenterFacility facility = PSystemSetup.Instance.GetSpaceCenterFacility(site.name);
                if (facility == null)
                {
                    continue;
                }

                PSystemSetup.SpaceCenterFacility.SpawnPoint sp = facility.GetSpawnPoint(site.name);
                if (sp == null)
                {
                    Log.Error("No Spawn Point found for: " + site.name);
                    continue;
                }

                if (facility.facilityPQS != body.pqsController)
                {
                    Log.Error("No PQS found for: " + site.name);
                    continue;
                }
                ;

                Transform spawnPointTransform = sp.GetSpawnPointTransform();
                if (spawnPointTransform == null)
                {
                    Log.Error("No Spawn PointTransform found for: " + site.name);
                    continue;
                }

                if (isOccluded((spawnPointTransform.position), body))
                {
                    if (KerbalKonstructs.instance.mapHideIconsBehindBody)
                    {
                        continue;
                    }
                }

                Vector3 pos = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(spawnPointTransform.position));

                Rect screenRect = 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;
                //      Log.Warning("fRadarRadius = " + Math.Round(fRadarRadius,2));
                float fRadarOffset = fRadarRadius / 2;



                if (KerbalKonstructs.instance.mapShowRadar)
                {
                    drawRadar(pos, category, openclosed);
                }

                if (openclosed == "Open" && KerbalKonstructs.instance.mapShowGroundComms)
                {
                    drawGroundComms(null, site);
                }

                if (site.icon != null)
                {
                    if (fRadarRadius > 15)
                    {
                        GUI.DrawTexture(screenRect, site.icon, ScaleMode.ScaleToFit, true);
                    }
                }
                else
                {
                    if (fRadarRadius > 15)
                    {
                        switch (site.type)
                        {
                        case SiteType.VAB:
                            GUI.DrawTexture(screenRect, UIMain.VABIcon, ScaleMode.ScaleToFit, true);
                            break;

                        case SiteType.SPH:
                            GUI.DrawTexture(screenRect, UIMain.SPHIcon, ScaleMode.ScaleToFit, true);
                            break;

                        default:
                            GUI.DrawTexture(screenRect, UIMain.ANYIcon, ScaleMode.ScaleToFit, true);
                            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);
                        WindowManager.instance.OpenWindow(KerbalKonstructs.instance.GUI_BaseManager.drawBaseManager);
                    }
                }
            }
        }
Esempio n. 3
0
        public void drawSelectorWindow(int id)
        {
            ButtonKK = new GUIStyle(GUI.skin.button);
            ButtonKK.padding.left  = 0;
            ButtonKK.padding.right = 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;

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

            KKToolTip = new GUIStyle(GUI.skin.box);
            KKToolTip.normal.textColor = Color.white;
            KKToolTip.fontSize         = 11;
            KKToolTip.fontStyle        = FontStyle.Normal;

            string smessage = "";

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

                GUILayout.FlexibleSpace();

                GUILayout.Button("Launchsite Selector", DeadButton, GUILayout.Height(21));

                GUILayout.FlexibleSpace();

                GUI.enabled = true;

                if (GUILayout.Button("X", DeadButtonRed, GUILayout.Height(21)))
                {
                    InputLockManager.RemoveControlLock("KKEditorLock");
                    InputLockManager.RemoveControlLock("KKEditorLock2");
                    this.Close();
                    return;
                }
            }
            GUILayout.EndHorizontal();

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

            GUILayout.Space(2);

            GUILayout.BeginHorizontal();
            {
                GUILayout.Space(5);

                if (MiscUtils.isCareerGame())
                {
                    if (bOpenOn)
                    {
                        tHolder = UIMain.tOpenBasesOn;
                    }
                    else
                    {
                        tHolder = UIMain.tOpenBasesOff;
                    }

                    if (GUILayout.Button(new GUIContent(tHolder, "Open"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        if (bOpenOn)
                        {
                            bOpenOn   = false;
                            bClosedOn = true;
                        }
                        else
                        {
                            bOpenOn = true;
                        }
                    }

                    if (bClosedOn)
                    {
                        tHolder = UIMain.tClosedBasesOn;
                    }
                    else
                    {
                        tHolder = UIMain.tClosedBasesOff;
                    }

                    if (GUILayout.Button(new GUIContent(tHolder, "Closed"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        if (bClosedOn)
                        {
                            bClosedOn = false;
                            bOpenOn   = true;
                        }
                        else
                        {
                            bClosedOn = true;
                        }
                    }

                    GUILayout.FlexibleSpace();
                }

                if (bFavesOnly)
                {
                    tHolder = tFavesOn;
                }
                else
                {
                    tHolder = tFavesOff;
                }

                if (GUILayout.Button(new GUIContent(tHolder, "Only Favourites"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    if (bFavesOnly)
                    {
                        bFavesOnly = false;
                    }
                    else
                    {
                        bFavesOnly = true;
                    }
                }

                GUILayout.FlexibleSpace();

                if (editorType == SiteType.SPH)
                {
                    GUI.enabled = false;
                }

                if (bRocketpadsOn)
                {
                    tHolder = UIMain.tLaunchpadsOn;
                }
                else
                {
                    tHolder = UIMain.tLaunchpadsOff;
                }

                if (GUILayout.Button(new GUIContent(tHolder, "Rocketpads"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    bRocketpadsOn = true;
                    bHelipadsOn   = false;
                    bRunwaysOn    = false;
                    bOtherOn      = false;
                    waterLaunchOn = false;

                    sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() :
                            LaunchSiteManager.getLaunchSites(editorType, true, "RocketPad");
                }

                GUI.enabled = true;
                GUILayout.Space(2);

                if (editorType == SiteType.VAB)
                {
                    GUI.enabled = false;
                }

                if (bRunwaysOn)
                {
                    tHolder = UIMain.tRunwaysOn;
                }
                else
                {
                    tHolder = UIMain.tRunwaysOff;
                }

                if (GUILayout.Button(new GUIContent(tHolder, "Runways"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    bRunwaysOn    = true;
                    bHelipadsOn   = false;
                    bRocketpadsOn = false;
                    bOtherOn      = false;
                    waterLaunchOn = false;

                    sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() :
                            LaunchSiteManager.getLaunchSites(editorType, true, "Runway");
                }

                GUI.enabled = true;
                GUILayout.Space(2);

                if (editorType == SiteType.VAB)
                {
                    GUI.enabled = false;
                }

                if (bHelipadsOn)
                {
                    tHolder = UIMain.tHelipadsOn;
                }
                else
                {
                    tHolder = UIMain.tHelipadsOff;
                }

                if (GUILayout.Button(new GUIContent(tHolder, "Helipads"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    bRocketpadsOn = false;
                    bHelipadsOn   = true;
                    bRunwaysOn    = false;
                    bOtherOn      = false;
                    waterLaunchOn = false;

                    sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() :
                            LaunchSiteManager.getLaunchSites(editorType, true, "Helipad");
                }

                GUI.enabled = true;
                GUILayout.Space(2);

                if (editorType == SiteType.VAB)
                {
                    GUI.enabled = false;
                }

                if (waterLaunchOn)
                {
                    tHolder = UIMain.tWaterOn;
                }
                else
                {
                    tHolder = UIMain.tWaterOff;
                }

                if (GUILayout.Button(new GUIContent(tHolder, "WalterLaunch"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    bRocketpadsOn = false;
                    bHelipadsOn   = false;
                    bRunwaysOn    = false;
                    bOtherOn      = false;
                    waterLaunchOn = true;

                    sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() :
                            LaunchSiteManager.getLaunchSites(editorType, true, "Waterlaunch");
                }

                GUI.enabled = true;
                GUILayout.Space(2);

                if (bOtherOn)
                {
                    tHolder = UIMain.tOtherOn;
                }
                else
                {
                    tHolder = UIMain.tOtherOff;
                }

                if (GUILayout.Button(new GUIContent(tHolder, "Other"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    bRocketpadsOn = false;
                    bHelipadsOn   = false;
                    bRunwaysOn    = false;
                    bOtherOn      = true;
                    waterLaunchOn = false;

                    sites = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() :
                            LaunchSiteManager.getLaunchSites(editorType, true, "Other");
                }

                GUILayout.FlexibleSpace();

                if (GUILayout.Button("ALL", GUILayout.Width(32), GUILayout.Height(32)))
                {
                    bRocketpadsOn = true;
                    bHelipadsOn   = true;
                    bRunwaysOn    = true;
                    bOtherOn      = true;
                    waterLaunchOn = true;
                    sites         = (editorType == SiteType.Any) ? LaunchSiteManager.getLaunchSites() :
                                    LaunchSiteManager.getLaunchSites(editorType, true, "ALL");
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(10);

            sitesScrollPosition = GUILayout.BeginScrollView(sitesScrollPosition);
            {
                if (sites == null)
                {
                    sites = (editorType == SiteType.Any) ?
                            LaunchSiteManager.getLaunchSites() : LaunchSiteManager.getLaunchSites(editorType, true, "ALL");
                }

                sites.Sort(delegate(LaunchSite a, LaunchSite b)
                {
                    return((a.LaunchSiteName).CompareTo(b.LaunchSiteName));
                });

                foreach (LaunchSite site in sites)
                {
                    if (bFavesOnly)
                    {
                        if (site.favouriteSite != "Yes")
                        {
                            continue;
                        }
                    }

                    if (MiscUtils.isCareerGame())
                    {
                        if (!bOpenOn)
                        {
                            if (site.isOpen)
                            {
                                continue;
                            }
                        }

                        if (!bClosedOn)
                        {
                            if (!site.isOpen)
                            {
                                continue;
                            }
                        }

                        // Don't show hidden closed Bases
                        if (site.LaunchSiteIsHidden && (!site.isOpen))
                        {
                            continue;
                        }

                        GUILayout.BeginHorizontal();
                        if (site.isOpen)
                        {
                            GUILayout.Label(UIMain.tIconOpen, GUILayout.Height(30), GUILayout.Width(30));
                        }
                        else
                        {
                            GUILayout.Label(UIMain.tIconClosed, GUILayout.Height(30), GUILayout.Width(30));
                        }
                    }

                    GUI.enabled = !(selectedSite == site);

                    string sButtonName = "";
                    sButtonName = site.LaunchSiteName;
                    if (site.LaunchSiteName == "Runway")
                    {
                        sButtonName = "KSC Runway";
                    }
                    if (site.LaunchSiteName == "LaunchPad")
                    {
                        sButtonName = "KSC LaunchPad";
                    }

                    if (GUILayout.Button(sButtonName, GUILayout.Height(30)))
                    {
                        selectedSite = site;

                        if (!MiscUtils.isCareerGame())
                        {
                            LaunchSiteManager.setLaunchSite(site);
                            smessage = "Launchsite set to " + sButtonName;
                            MiscUtils.HUDMessage(smessage, 10, 2);
                        }
                    }
                    GUI.enabled = true;

                    if (MiscUtils.isCareerGame())
                    {
                        if (site.isOpen)
                        {
                            GUILayout.Label(UIMain.tIconOpen, GUILayout.Height(30), GUILayout.Width(30));
                        }
                        else
                        {
                            GUILayout.Label(UIMain.tIconClosed, GUILayout.Height(30), GUILayout.Width(30));
                        }

                        GUILayout.EndHorizontal();
                    }
                }
            }
            GUILayout.EndScrollView();

            GUILayout.Space(5);

            sCurrentSite = LaunchSiteManager.getCurrentLaunchSite();

            if (sCurrentSite != null)
            {
                if (sCurrentSite == "Runway")
                {
                    GUILayout.Box("Current Launchsite: KSC Runway");
                }
                else
                if (sCurrentSite == "LaunchPad")
                {
                    GUILayout.Box("Current Launchsite: KSC LaunchPad");
                }
                else
                {
                    GUILayout.Box("Current Launchsite: " + sCurrentSite);
                }
            }

            GUI.enabled = (selectedSite != null && !(selectedSite.LaunchSiteName == sCurrentSite) && LaunchSiteManager.getIsSiteOpen(selectedSite.LaunchSiteName));
            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Set as Launchsite", GUILayout.Height(46)))
            {
                LaunchSiteManager.setLaunchSite(selectedSite);
                MiscUtils.HUDMessage(selectedSite.LaunchSiteName + " has been set as the launchsite", 10, 0);
            }

            GUILayout.EndHorizontal();
            GUI.enabled = true;

            GUILayout.BeginHorizontal();
            {
                if (editorType == SiteType.SPH)
                {
                    GUI.enabled = (KerbalKonstructs.instance.defaultSPHlaunchsite != sCurrentSite);
                }

                if (editorType == SiteType.VAB)
                {
                    GUI.enabled = (KerbalKonstructs.instance.defaultVABlaunchsite != sCurrentSite);
                }

                if (GUILayout.Button("Set as Default", GUILayout.Height(23)))
                {
                    if (sCurrentSite != null)
                    {
                        if (editorType == SiteType.SPH)
                        {
                            KerbalKonstructs.instance.defaultSPHlaunchsite = sCurrentSite;
                        }

                        if (editorType == SiteType.VAB)
                        {
                            KerbalKonstructs.instance.defaultVABlaunchsite = sCurrentSite;
                        }
                    }
                }
                GUI.enabled = true;

                LaunchSite DefaultSite = null;

                if (GUILayout.Button("Use Default", GUILayout.Height(23)))
                {
                    if (editorType == SiteType.SPH)
                    {
                        foreach (LaunchSite site in sites)
                        {
                            if (site.LaunchSiteName == KerbalKonstructs.instance.defaultSPHlaunchsite)
                            {
                                DefaultSite = site;
                            }
                        }

                        if (DefaultSite != null)
                        {
                            if (MiscUtils.isCareerGame())
                            {
                                if (!DefaultSite.isOpen)
                                {
                                    smessage = "Default site is closed.";
                                    MiscUtils.HUDMessage(smessage, 10, 0);
                                }
                                else
                                {
                                    LaunchSiteManager.setLaunchSite(DefaultSite);
                                }
                            }
                            else
                            {
                                LaunchSiteManager.setLaunchSite(DefaultSite);
                            }
                        }
                    }

                    if (editorType == SiteType.VAB)
                    {
                        foreach (LaunchSite site in sites)
                        {
                            if (site.LaunchSiteName == KerbalKonstructs.instance.defaultVABlaunchsite)
                            {
                                DefaultSite = site;
                            }
                        }

                        if (DefaultSite != null)
                        {
                            if (MiscUtils.isCareerGame())
                            {
                                if (!DefaultSite.isOpen)
                                {
                                    smessage = "Default site is closed.";
                                    MiscUtils.HUDMessage(smessage, 10, 0);
                                }
                                else
                                {
                                    LaunchSiteManager.setLaunchSite(DefaultSite);
                                }
                            }
                            else
                            {
                                LaunchSiteManager.setLaunchSite(DefaultSite);
                            }
                        }
                    }

                    if (DefaultSite != null)
                    {
                        smessage = DefaultSite.LaunchSiteName + " has been set as the launchsite";
                        MiscUtils.HUDMessage(smessage, 10, 0);
                    }
                    else
                    {
                        smessage = "KK could not determine the default launchsite.";
                        MiscUtils.HUDMessage(smessage, 10, 0);
                    }
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.FlexibleSpace();
            GUILayout.Box(UIMain.tHorizontalSep, BoxNoBorder, GUILayout.Height(4));

            GUILayout.Space(2);

            GUI.enabled = true;

            if (selectedSite != null)
            {
                BaseManager.setSelectedSite(selectedSite);
                BaseManager.instance.Open();
            }
            else
            {
                if (LaunchSiteManager.getLaunchSites().Count > 0)
                {
                    selectedSite = LaunchSiteManager.getLaunchSites(editorType)[0];
                    LaunchSiteManager.setLaunchSite(selectedSite);
                    BaseManager.setSelectedSite(selectedSite);
                    BaseManager.instance.Open();
                }
                else
                {
                    Log.UserError("ERROR Launch Selector cannot find KSC Runway or Launch Pad! PANIC! Runaway! Hide!");
                }
            }

            if (GUI.tooltip != "")
            {
                var labelSize = GUI.skin.GetStyle("Label").CalcSize(new GUIContent(GUI.tooltip));
                GUI.Box(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y + 20, labelSize.x + 5, labelSize.y + 6), GUI.tooltip, KKToolTip);
            }

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
Esempio n. 4
0
        public void drawLaunchsites(MapObject target)
        {
            displayingTooltip = false;
            int iPulseRate = 180;

            iRadarCounter = iRadarCounter + 1;
            if (iRadarCounter > iPulseRate)
            {
                iRadarCounter = 0;
            }

            // Then do launchsites
            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            for (int index = 0; index < sites.Count; index++)
            {
                LaunchSite site = sites[index];

                PSystemSetup.SpaceCenterFacility facility = PSystemSetup.Instance.GetSpaceCenterFacility(site.name);

                if (facility == null)
                {
                    continue;
                }

                PSystemSetup.SpaceCenterFacility.SpawnPoint sp = facility.GetSpawnPoint(site.name);

                if (sp == null)
                {
                    continue;
                }

                if (facility.facilityPQS != target.celestialBody.pqsController)
                {
                    continue;
                }

                Transform spawnPointTransform = sp.GetSpawnPointTransform();
                if (spawnPointTransform == null)
                {
                    continue;
                }

                if (isOccluded(spawnPointTransform.position, target.celestialBody))
                {
                    if (KerbalKonstructs.instance.mapHideIconsBehindBody)
                    {
                        continue;
                    }
                }

                Vector3 pos        = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(spawnPointTransform.position));
                Rect    screenRect = 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;
                float fRadarOffset = fRadarRadius / 2;

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

                bool display = true;

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

                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 (openclosed == "OpenLocked" || openclosed == "ClosedLocked")
                    {
                        display = false;
                    }
                }

                if (!display)
                {
                    continue;
                }

                if (KerbalKonstructs.instance.mapShowRadar)
                {
                    drawRadar(pos, category, openclosed);
                }

                if (openclosed == "Open" && KerbalKonstructs.instance.mapShowGroundComms)
                {
                    drawGroundComms(null, site);
                }

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

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

                        default:
                            Graphics.DrawTexture(screenRect, UIMain.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;
                    }
                }
            }
        }