Beispiel #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;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        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 #3
0
        public static void TrackingInterface(StaticObject soStation)
        {
            fRange      = (float)soStation.getSetting("TrackingShort");
            sTargetType = (string)soStation.getSetting("TargetType");
            sTarget     = (string)soStation.getSetting("TargetID");
            fMaxAngle   = (float)soStation.getSetting("TrackingAngle");

            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;

            BoxInfo = new GUIStyle(GUI.skin.box);
            BoxInfo.normal.textColor  = Color.cyan;
            BoxInfo.fontSize          = 13;
            BoxInfo.padding.top       = 2;
            BoxInfo.padding.bottom    = 1;
            BoxInfo.padding.left      = 5;
            BoxInfo.padding.right     = 5;
            BoxInfo.normal.background = null;

            GUILayout.Space(2);

            GUILayout.BeginHorizontal();
            {
                GUILayout.Space(5);
                GUILayout.Label("Short Range: " + (fRange / 1000f).ToString("#0") + "km", LabelInfo, GUILayout.Height(25));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Max Angle: " + fMaxAngle.ToString("#0") + "°", LabelInfo, GUILayout.Height(25));

                if (KerbalKonstructs.instance.DevMode)
                {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("Upgrade", GUILayout.Height(20), GUILayout.Width(70)))
                    {
                        ScreenMessages.PostScreenMessage("Unable to upgrade this facility. Insufficient materials.", 10, ScreenMessageStyle.LOWER_CENTER);
                    }
                }
            }
            GUILayout.EndHorizontal();

            if (KerbalKonstructs.instance.DevMode)
            {
                GUILayout.Space(1);
                GUILayout.Box("To upgrade a kerbonaut Scientist and Engineer must be at the station. Then processed ore can be ordered for delivery to the station.", BoxInfo);
            }

            GUILayout.Space(2);

            GUILayout.BeginHorizontal();
            {
                GUILayout.Space(5);
                GUILayout.Label("Target Type: " + sTargetType, LabelInfo, GUILayout.Height(25));
                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Change", GUILayout.Height(20), GUILayout.Width(70)))
                {
                    bChangeTargetType = true;
                    sTarget           = "None";

                    if (sTargetType == "None")
                    {
                        sTargetType = "Craft";
                    }
                    else
                    if (sTargetType == "Craft")
                    {
                        sTargetType = "Celestial Body";
                    }
                    else
                    if (sTargetType == "Celestial Body")
                    {
                        sTargetType = "Asteroid";
                    }
                    else
                    if (sTargetType == "Asteroid")
                    {
                        sTargetType = "Station's Discretion";
                    }
                    else
                    if (sTargetType == "Station's Discretion")
                    {
                        sTargetType = "None";
                    }

                    FacilityManager.changeTargetType(sTargetType);

                    soStation.setSetting("TargetID", sTarget);
                    soStation.setSetting("TargetType", sTargetType);
                    PersistenceUtils.saveStaticPersistence(soStation);
                }
            }
            GUILayout.EndHorizontal();

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

                int iU = sTarget.IndexOf("(");
                if (iU < 2)
                {
                    iU = sTarget.Length + 1;
                }

                sDisplayTarget = sTarget.Substring(0, iU - 1);

                GUILayout.Label("Tracking: " + sDisplayTarget + " ", LabelInfo, GUILayout.Height(25));
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Change", GUILayout.Height(20), GUILayout.Width(70)))
                {
                    if (sTargetType == "None" || sTargetType == "Station's Discretion")
                    {
                        ScreenMessages.PostScreenMessage("Please select a target type first.", 10, ScreenMessageStyle.LOWER_CENTER);
                    }
                    else
                    {
                        sSelectedTrackingTarget = "None";
                        FacilityManager.changeTarget(true);
                    }
                }
            }
            GUILayout.EndHorizontal();

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

                GUILayout.Label("Status: ", LabelInfo, GUILayout.Height(25));
                string sStationStatus = "Offline";

                if (sTarget != "None")
                {
                    sStationStatus = "Error. Please reset";

                    if (sTargetType == "Craft")
                    {
                        Vessel vTargetVessel = GetTargetVessel(sTarget);

                        if (vTargetVessel == null)
                        {
                            sStationStatus = "Cannot find craft";
                        }
                        else
                        {
                            if (vTargetVessel.state == Vessel.State.DEAD)
                            {
                                sStationStatus = "Cannot find craft";
                            }
                            else
                            {
                                StationLOS = StationHasLOS(soStation, vTargetVessel);

                                if (StationLOS <= fMaxAngle)
                                {
                                    sDisplayRange = "0m";
                                    float fRangeToTarget = GetRangeToCraft(soStation, vTargetVessel);

                                    if (fRangeToTarget > 100000f)
                                    {
                                        sDisplayRange = (fRangeToTarget / 1000f).ToString("#0") + " km";
                                    }
                                    else
                                    {
                                        sDisplayRange = fRangeToTarget.ToString("#0") + "m";
                                    }

                                    if (fRangeToTarget > fRange)
                                    {
                                        sStationStatus = "Lock " + StationLOS.ToString("#0")
                                                         + "° " + sDisplayRange;
                                    }
                                    else
                                    {
                                        sStationStatus = "Lock " + StationLOS.ToString("#0") + "° " + sDisplayRange;
                                    }
                                }
                                else
                                {
                                    sStationStatus = "No lock";
                                }
                            }
                        }
                    }

                    if (sTargetType == "Asteroid")
                    {
                        Vessel vTargetVessel = GetTargetVessel(sTarget);

                        bool bAsteroidDetected = true;
                        if (vTargetVessel == null)
                        {
                            bAsteroidDetected = false;
                        }
                        else
                        {
                            if (vTargetVessel.state == Vessel.State.DEAD)
                            {
                                bAsteroidDetected = false;
                            }
                        }

                        if (!bAsteroidDetected)
                        {
                            sStationStatus = "Cannot find asteroid";
                        }
                        else
                        {
                            StationLOS = StationHasLOS(soStation, vTargetVessel);

                            vTargetVessel.DiscoveryInfo.SetLastObservedTime(Planetarium.GetUniversalTime());
                            vTargetVessel.DiscoveryInfo.SetLevel((DiscoveryLevels)29);

                            if (StationLOS <= fMaxAngle)
                            {
                                sDisplayRange = "0m";
                                float fRangeToTarget = GetRangeToCraft(soStation, vTargetVessel);

                                if (fRangeToTarget > 100000f)
                                {
                                    sDisplayRange = (fRangeToTarget / 1000f).ToString("#0") + " km";
                                }
                                else
                                {
                                    sDisplayRange = fRangeToTarget.ToString("#0") + "m";
                                }

                                if (fRangeToTarget > fRange)
                                {
                                    sStationStatus = "Lock " + StationLOS.ToString("#0") + "° " + sDisplayRange;
                                }
                                else
                                {
                                    sStationStatus = "Lock " + StationLOS.ToString("#0") + "° " + sDisplayRange;
                                }
                            }
                            else
                            {
                                sStationStatus = "No lock";
                            }
                        }
                    }

                    if (sTargetType == "Celestial Body")
                    {
                        CelestialBody cTargetPlanet = GetTargetPlanet(sTarget);

                        if (cTargetPlanet == null)
                        {
                            sStationStatus = "Cannot find body";
                        }
                        else
                        {
                            StationLOS = StationHasLOStoPlanet(soStation, cTargetPlanet);

                            if (StationLOS <= fMaxAngle)
                            {
                                sDisplayRange = "0m";
                                float fRangeToTarget = GetRangeToPlanet(soStation, cTargetPlanet);

                                sDisplayRange  = (fRangeToTarget / 1000f).ToString("#0") + "km";
                                sStationStatus = "Sighted " + StationLOS.ToString("#0") + "° " + sDisplayRange;
                            }
                            else
                            {
                                sStationStatus = "No sighting";
                            }
                        }
                    }
                }

                if (sTargetType == "Station's Discretion")
                {
                    sStationStatus = " Busy ";
                }

                GUILayout.Label(sStationStatus, LabelInfo, GUILayout.Height(30));
                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Stop", GUILayout.Height(20), GUILayout.Width(70)))
                {
                    sTargetType = "None";
                    sTarget     = "None";
                    soStation.setSetting("TargetType", sTargetType);
                    soStation.setSetting("TargetID", sTarget);
                    PersistenceUtils.saveStaticPersistence(soStation);
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(5);
        }
        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);
                    }
                }
            }
        }
Beispiel #5
0
        public static void TargetSelector(string sTargetTypeSelected, StaticObject selectedFacility = null)
        {
            scrollPos = GUILayout.BeginScrollView(scrollPos);
            {
                if (sTargetTypeSelected == "Station")
                {
                    sSelectedTrackingTarget = "None";

                    foreach (StaticObject obj in KerbalKonstructs.instance.getStaticDB().getAllStatics())
                    {
                        if ((string)obj.getSetting("FacilityType") == "TrackingStation")
                        {
                            if ((string)obj.getSetting("OpenCloseState") == "Closed")
                            {
                                continue;
                            }

                            GUILayout.BeginHorizontal();
                            {
                                fAlt = (float)obj.getSetting("RadiusOffset");

                                cPlanetoid = (CelestialBody)obj.getSetting("CelestialBody");

                                ObjectPos    = cPlanetoid.transform.InverseTransformPoint(obj.gameObject.transform.position);
                                dObjectLat   = NavUtils.GetLatitude(ObjectPos);
                                dObjectLon   = NavUtils.GetLongitude(ObjectPos);
                                disObjectLat = dObjectLat * 180 / Math.PI;
                                disObjectLon = dObjectLon * 180 / Math.PI;

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

                                sButtonText = cPlanetoid.name + " Station\nAltitude: " + fAlt.ToString("#0") + "m\nLat. "
                                              + disObjectLat.ToString("#0.000") + " Lon. " + disObjectLon.ToString("#0.000");

                                GUI.enabled = (obj != selectedStation);
                                //GUILayout.Box(sButtonText, GUILayout.Height(50));

                                ButtonSmallText           = new GUIStyle(GUI.skin.button);
                                ButtonSmallText.fontSize  = 12;
                                ButtonSmallText.fontStyle = FontStyle.Normal;

                                if (GUILayout.Button("" + sButtonText, ButtonSmallText, GUILayout.Height(55)))
                                {
                                    selectedStation = obj;
                                }

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

                if (sTargetTypeSelected == "Craft")
                {
                    selectedStation = null;

                    foreach (Vessel vVessel in FlightGlobals.Vessels)
                    {
                        if (vVessel.vesselType == VesselType.SpaceObject)
                        {
                            continue;
                        }
                        if (vVessel.vesselType == VesselType.Debris)
                        {
                            continue;
                        }
                        if (vVessel.vesselType == VesselType.EVA)
                        {
                            continue;
                        }
                        if (vVessel.vesselType == VesselType.Flag)
                        {
                            continue;
                        }
                        if (vVessel.vesselType == VesselType.Unknown)
                        {
                            continue;
                        }
                        if (vVessel == FlightGlobals.ActiveVessel)
                        {
                            continue;
                        }

                        int iU = vVessel.name.IndexOf("(");
                        if (iU < 2)
                        {
                            iU = vVessel.name.Length + 1;
                        }
                        string sDisplayTarget = vVessel.name.Substring(0, iU - 1);

                        GUI.enabled = (sSelectedTrackingTarget != vVessel.name + "_" + vVessel.id.ToString());
                        if (GUILayout.Button(sDisplayTarget, GUILayout.Height(20)))
                        {
                            sSelectedTrackingTarget = vVessel.name + "_" + vVessel.id.ToString();
                        }
                        GUI.enabled = true;
                    }
                }

                if (sTargetTypeSelected == "Celestial Body")
                {
                    foreach (CelestialBody cBody in FlightGlobals.Bodies)
                    {
                        GUI.enabled = (sSelectedTrackingTarget != cBody.name);
                        if (GUILayout.Button(cBody.name, GUILayout.Height(20)))
                        {
                            sSelectedTrackingTarget = cBody.name;
                        }
                        GUI.enabled = true;
                    }
                }

                if (sTargetTypeSelected == "Asteroid")
                {
                    foreach (Vessel vVessel in FlightGlobals.Vessels)
                    {
                        if (vVessel.vesselType != VesselType.SpaceObject && vVessel.vesselType != VesselType.Unknown)
                        {
                            continue;
                        }

                        int iU = vVessel.name.IndexOf("(");
                        if (iU < 2)
                        {
                            iU = vVessel.name.Length + 1;
                        }
                        string sDisplayTarget = vVessel.name.Substring(0, iU - 1);

                        GUI.enabled = (sSelectedTrackingTarget != vVessel.name + "_" + vVessel.id.ToString());
                        if (GUILayout.Button(sDisplayTarget, GUILayout.Height(20)))
                        {
                            sSelectedTrackingTarget = vVessel.name + "_" + vVessel.id.ToString();
                        }
                        GUI.enabled = true;
                    }
                }

                if (sTargetTypeSelected == "Station's Discretion")
                {
                    GUILayout.Box("Target is selected by the station.");
                }

                if (sTargetTypeSelected == "None")
                {
                    GUILayout.Box("Select a target type.");
                }
            }
            GUILayout.EndScrollView();

            GUILayout.FlexibleSpace();

            GUILayout.BeginHorizontal();
            {
                if (sSelectedTrackingTarget != "None")
                {
                    bGUIenabled = true;
                }
                if (selectedStation != null)
                {
                    bGUIenabled = true;
                }

                GUI.enabled = bGUIenabled;
                if (GUILayout.Button("Select", GUILayout.Height(25)))
                {
                    sTarget = sSelectedTrackingTarget;
                    if (selectedFacility != null)
                    {
                        selectedFacility.setSetting("TargetID", sTarget);
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }
                    else
                    {
                        if (selectedStation != null)
                        {
                            DownlinkGUI.soTargetStation = selectedStation;
                            var FacilityKey = selectedStation.getSetting("RadialPosition");
                            DownlinkGUI.sStationRadial = FacilityKey.ToString();
                        }
                        else
                        {
                            DownlinkGUI.sTarget = sTarget;
                        }

                        DownlinkGUI.SaveCommsState();
                    }
                }
                GUI.enabled = true;

                if (GUILayout.Button("Close", GUILayout.Height(25)))
                {
                    if (selectedFacility != null)
                    {
                        FacilityManager.changeTarget(false);
                    }
                    else
                    {
                        DownlinkGUI.changeTarget(false);
                    }
                }
            }
            GUILayout.EndHorizontal();
        }