public static void HangarCraft(Vessel vVessel, StaticObject soHangar, int iMax = 2)
        {
            string sSpace = GetHangarSpace(soHangar, iMax);

            if (sSpace == "None")
            {
                MiscUtils.HUDMessage("This facility is full.", 10,
                                     3);
            }
            else
            {
                string sVesselID = vVessel.id.ToString();
                soHangar.setSetting(sSpace, sVesselID);
                PersistenceUtils.saveStaticPersistence(soHangar);

                // Hangar the vessel - hide it
                foreach (Part p in vVessel.Parts)
                {
                    if (p != null && p.gameObject != null)
                    {
                        p.gameObject.SetActive(false);
                    }
                    else
                    {
                        continue;
                    }
                }

                vVessel.MakeInactive();
                vVessel.enabled = false;
                vVessel.Unload();
            }
        }
        public static void RemoveCorrectCraft(Vessel vVessel, StaticObject soHangar)
        {
            string sSpace    = "InStorage";
            string sVesselID = vVessel.id.ToString();

            if (sVesselID == (string)soHangar.getSetting("TargetID"))
            {
                sSpace = "TargetID";
            }
            if (sVesselID == (string)soHangar.getSetting("TargetType"))
            {
                sSpace = "TargetType";
            }

            soHangar.setSetting(sSpace, "None");
            PersistenceUtils.saveStaticPersistence(soHangar);
        }
        public static void ProductionInterface(StaticObject selectedFacility, string sFacilityType)
        {
            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;

            Yellowtext = new GUIStyle(GUI.skin.box);
            Yellowtext.normal.textColor  = Color.yellow;
            Yellowtext.normal.background = null;

            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;

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

            float fStaffing       = 0;
            float fProductionRate = 0;
            float fLastCheck      = 0;

            fStaffing       = (float)selectedFacility.getSetting("StaffCurrent");
            fProductionRate = (float)selectedFacility.getSetting("ProductionRateCurrent") * (fStaffing / 2f);

            if (fProductionRate < 0.01f)
            {
                float fDefaultRate = 0.01f;

                if (sFacilityType == "Business")
                {
                    fDefaultRate = 0.10f;
                }
                if (sFacilityType == "Mining")
                {
                    fDefaultRate = 0.05f;
                }

                selectedFacility.setSetting("ProductionRateCurrent", fDefaultRate);
                PersistenceUtils.saveStaticPersistence(selectedFacility);
                fProductionRate = fDefaultRate * (fStaffing / 2f);
            }

            fLastCheck = (float)selectedFacility.getSetting("LastCheck");

            if (fLastCheck == 0)
            {
                fLastCheck = (float)Planetarium.GetUniversalTime();
                selectedFacility.setSetting("LastCheck", fLastCheck);
                PersistenceUtils.saveStaticPersistence(selectedFacility);
            }

            if (sFacilityType == "Research" || sFacilityType == "Business" || sFacilityType == "Mining")
            {
                string sProduces = "";
                float  fMax      = 0f;
                float  fCurrent  = 0f;

                if (sFacilityType == "Research")
                {
                    sProduces = "Science";
                    fMax      = (float)selectedFacility.getSetting("ScienceOMax");

                    if (fMax < 1)
                    {
                        fMax = (float)selectedFacility.model.getSetting("DefaultScienceOMax");

                        if (fMax < 1)
                        {
                            fMax = 10f;
                        }

                        selectedFacility.setSetting("ScienceOMax", fMax);
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }

                    fCurrent = (float)selectedFacility.getSetting("ScienceOCurrent");
                }
                if (sFacilityType == "Business")
                {
                    sProduces = "Funds";
                    fMax      = (float)selectedFacility.getSetting("FundsOMax");

                    if (fMax < 1)
                    {
                        fMax = (float)selectedFacility.model.getSetting("DefaultFundsOMax");

                        if (fMax < 1)
                        {
                            fMax = 10000f;
                        }

                        selectedFacility.setSetting("FundsOMax", fMax);
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }

                    fCurrent = (float)selectedFacility.getSetting("FundsOCurrent");
                }
                if (sFacilityType == "Mining")
                {
                    sProduces = "Ore";
                    fMax      = (float)selectedFacility.model.getSetting("OreMax");

                    if (fMax < 1)
                    {
                        fMax = 500f;
                    }

                    fCurrent = (float)selectedFacility.getSetting("OreCurrent");
                }

                double dTime = Planetarium.GetUniversalTime();

                // Deal with revert exploits
                if (fLastCheck > (float)dTime)
                {
                    selectedFacility.setSetting("LastCheck", (float)dTime);
                    PersistenceUtils.saveStaticPersistence(selectedFacility);
                }

                if ((float)dTime - fLastCheck > 43200)
                {
                    float fDays = (((float)dTime - fLastCheck) / 43200);

                    float fProduced = fDays * fProductionRate;

                    fCurrent = fCurrent + fProduced;
                    if (fCurrent > fMax)
                    {
                        fCurrent = fMax;
                    }

                    if (sFacilityType == "Research")
                    {
                        selectedFacility.setSetting("ScienceOCurrent", fCurrent);
                    }
                    if (sFacilityType == "Business")
                    {
                        selectedFacility.setSetting("FundsOCurrent", fCurrent);
                    }
                    if (sFacilityType == "Mining")
                    {
                        selectedFacility.setSetting("OreCurrent", fCurrent);
                    }

                    selectedFacility.setSetting("LastCheck", (float)dTime);
                    PersistenceUtils.saveStaticPersistence(selectedFacility);
                }

                GUILayout.BeginHorizontal();
                GUILayout.Label("Produces: " + sProduces, LabelInfo);
                GUILayout.FlexibleSpace();
                GUILayout.Label("Current: " + fCurrent.ToString("#0") + " | Max: " + fMax.ToString("#0"), LabelInfo);
                GUILayout.EndHorizontal();
                //if (GUILayout.Button("Upgrade Max Capacity", ButtonSmallText, GUILayout.Height(20)))
                //{ }

                if (sFacilityType == "Research")
                {
                    if (GUILayout.Button("Transfer Science to KSC R&D", ButtonSmallText, GUILayout.Height(20)))
                    {
                        ResearchAndDevelopment.Instance.AddScience(fCurrent, TransactionReasons.Cheating);
                        selectedFacility.setSetting("ScienceOCurrent", 0f);
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }

                    /* GUILayout.BeginHorizontal();
                     * {
                     *      if (GUILayout.Button("Assign a Special Project", ButtonSmallText, GUILayout.Height(20)))
                     *      { }
                     *      if (GUILayout.Button("Deliver Research Materials", ButtonSmallText, GUILayout.Height(20)))
                     *      { }
                     * }
                     * GUILayout.EndHorizontal();
                     * if (GUILayout.Button("Assign a Kerbonaut Scientist", ButtonSmallText, GUILayout.Height(20)))
                     * { } */
                }
                if (sFacilityType == "Business")
                {
                    if (GUILayout.Button("Transfer Funds to KSC Account", ButtonSmallText, GUILayout.Height(20)))
                    {
                        Funding.Instance.AddFunds((double)fCurrent, TransactionReasons.Cheating);
                        selectedFacility.setSetting("FundsOCurrent", 0f);
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }
                }

                /* if (sFacilityType == "Mining")
                 * {
                 *      if (GUILayout.Button("Transfer Ore to/from Craft", ButtonSmallText, GUILayout.Height(20)))
                 *      {
                 *              if (bTransferOreToC) bTransferOreToC = false;
                 *              else bTransferOreToC = true;
                 *      }
                 *
                 *      if (bTransferOreToC)
                 *      {
                 *              // Ore transfer to craft GUI
                 *              GUILayout.Label("Select Craft & Container", LabelInfo);
                 *              scrollOreTransfer = GUILayout.BeginScrollView(scrollOreTransfer);
                 *              GUILayout.Label("Select Craft & Container", LabelInfo);
                 *              GUILayout.Label("Select Craft & Container", LabelInfo);
                 *              GUILayout.Label("Select Craft & Container", LabelInfo);
                 *              GUILayout.EndScrollView();
                 *              GUILayout.BeginHorizontal();
                 *              if (GUILayout.Button("Into Craft", GUILayout.Height(23)))
                 *              {
                 *
                 *              }
                 *              if (GUILayout.Button("Out of Craft", GUILayout.Height(23)))
                 *              {
                 *
                 *              }
                 *              GUILayout.EndHorizontal();
                 *              GUILayout.BeginHorizontal();
                 *              GUILayout.Label("Amount: ", LabelInfo);
                 *              sOreTransferAmount = GUILayout.TextField(sOreTransferAmount, 7, GUILayout.Width(120));
                 *              if (GUILayout.Button("Max", GUILayout.Height(23)))
                 *              {
                 *
                 *              }
                 *              GUILayout.EndHorizontal();
                 *              if (GUILayout.Button("Proceed", GUILayout.Height(23)))
                 *              {
                 *
                 *              }
                 *
                 *              GUILayout.FlexibleSpace();
                 *      }
                 *
                 *      if (GUILayout.Button("Transfer Ore to Facility", ButtonSmallText, GUILayout.Height(20)))
                 *      {
                 *              if (bTransferOreToF) bTransferOreToF = false;
                 *              else bTransferOreToF = true;
                 *
                 *      }
                 *
                 *      if (bTransferOreToF)
                 *      {
                 *              // Ore transfer to Facility GUI
                 *              GUILayout.Label("Select Destination Facility", LabelInfo);
                 *              scrollOreTransfer2 = GUILayout.BeginScrollView(scrollOreTransfer2);
                 *              GUILayout.Label("Select Destination Facility", LabelInfo);
                 *              GUILayout.Label("Select Destination Facility", LabelInfo);
                 *              GUILayout.Label("Select Destination Facility", LabelInfo);
                 *              GUILayout.EndScrollView();
                 *
                 *              GUILayout.BeginHorizontal();
                 *              GUILayout.Label("Amount: ", LabelInfo);
                 *              sOreTransferAmount = GUILayout.TextField(sOreTransferAmount, 7, GUILayout.Width(120));
                 *              if (GUILayout.Button("Max", GUILayout.Height(23)))
                 *              {
                 *
                 *              }
                 *              GUILayout.EndHorizontal();
                 *              GUILayout.BeginHorizontal();
                 *              GUILayout.Label("Transfer Cost: X Funds");
                 *              if (GUILayout.Button("Proceed", GUILayout.Height(23)))
                 *              {
                 *
                 *              }
                 *              GUILayout.EndHorizontal();
                 *              GUILayout.FlexibleSpace();
                 *      }
                 *
                 *      if (GUILayout.Button("Assign a Kerbonaut Engineer", ButtonSmallText, GUILayout.Height(20)))
                 *      { }
                 * } */

                GUILayout.Space(5);
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label("Production Rate: Up to " + fProductionRate.ToString("#0.00") + " per 12 hrs", LabelInfo);
                    GUILayout.FlexibleSpace();
                    //if (GUILayout.Button(" Upgrade ", ButtonSmallText, GUILayout.Height(20)))
                    //{ }
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(3);
            }
        }
Esempio n. 4
0
        void drawMapManagerWindow(int windowID)
        {
            ButtonRed = new GUIStyle(GUI.skin.button);
            ButtonRed.normal.textColor  = Color.red;
            ButtonRed.active.textColor  = Color.red;
            ButtonRed.focused.textColor = Color.red;
            ButtonRed.hover.textColor   = Color.red;

            ButtonKK = new GUIStyle(GUI.skin.button);
            ButtonKK.padding.left      = 0;
            ButtonKK.padding.right     = 0;
            ButtonKK.normal.background = tNormalButton;
            ButtonKK.hover.background  = tHoverButton;

            Yellowtext = new GUIStyle(GUI.skin.box);
            Yellowtext.normal.textColor  = Color.yellow;
            Yellowtext.normal.background = null;

            TextAreaNoBorder = new GUIStyle(GUI.skin.textArea);
            TextAreaNoBorder.normal.background = null;

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

            if (!loadedPersistence && MiscUtils.isCareerGame())
            {
                PersistenceFile <LaunchSite> .LoadList(LaunchSiteManager.AllLaunchSites, "LAUNCHSITES", "KK");

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

                loadedPersistence = true;
            }

            GUILayout.BeginHorizontal();
            GUILayout.Box(" ", BoxNoBorder, GUILayout.Height(34));

            GUI.enabled = (MiscUtils.isCareerGame());
            if (!MiscUtils.isCareerGame())
            {
                GUILayout.Button(tOpenBasesOff, GUILayout.Width(32), GUILayout.Height(32));
                GUILayout.Button(tClosedBasesOff, GUILayout.Width(32), GUILayout.Height(32));
                GUILayout.Box(" ", BoxNoBorder, GUILayout.Height(34));
                GUILayout.Button(tTrackingOff, GUILayout.Width(32), GUILayout.Height(32));
            }
            else
            {
                if (KerbalKonstructs.instance.mapShowOpen)
                {
                    if (GUILayout.Button(new GUIContent(tOpenBasesOn, "Opened"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowOpen = false;
                    }
                }
                else
                {
                    if (GUILayout.Button(new GUIContent(tOpenBasesOff, "Opened"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowOpen = true;
                    }
                }

                if (!KerbalKonstructs.instance.disableDisplayClosed)
                {
                    if (KerbalKonstructs.instance.mapShowClosed)
                    {
                        if (GUILayout.Button(new GUIContent(tClosedBasesOn, "Closed"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                        {
                            KerbalKonstructs.instance.mapShowClosed = false;
                        }
                    }
                    else
                    {
                        if (GUILayout.Button(new GUIContent(tClosedBasesOff, "Closed"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                        {
                            KerbalKonstructs.instance.mapShowClosed = true;
                        }
                    }
                }

                GUILayout.Box(" ", BoxNoBorder, GUILayout.Height(34));
                if (KerbalKonstructs.instance.mapShowOpenT)
                {
                    if (GUILayout.Button(new GUIContent(tTrackingOn, "Tracking Stations"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowOpenT = false;
                    }
                }
                else
                {
                    if (GUILayout.Button(new GUIContent(tTrackingOff, "Tracking Stations"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowOpenT = true;
                    }
                }
            }
            GUI.enabled = true;

            GUILayout.Box(" ", BoxNoBorder, GUILayout.Height(34));

            if (KerbalKonstructs.instance.mapShowRocketbases)
            {
                if (GUILayout.Button(new GUIContent(tLaunchpadsOn, "Rocketpads"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowRocketbases = false;
                }
            }
            else
            {
                if (GUILayout.Button(new GUIContent(tLaunchpadsOff, "Rocketpads"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowRocketbases = true;
                }
            }

            if (KerbalKonstructs.instance.mapShowHelipads)
            {
                if (GUILayout.Button(new GUIContent(tHelipadsOn, "Helipads"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowHelipads = false;
                }
            }
            else
            {
                if (GUILayout.Button(new GUIContent(tHelipadsOff, "Helipads"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowHelipads = true;
                }
            }

            if (KerbalKonstructs.instance.mapShowRunways)
            {
                if (GUILayout.Button(new GUIContent(tRunwaysOn, "Runways"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowRunways = false;
                }
            }
            else
            {
                if (GUILayout.Button(new GUIContent(tRunwaysOff, "Runways"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowRunways = true;
                }
            }

            if (KerbalKonstructs.instance.mapShowOther)
            {
                if (GUILayout.Button(new GUIContent(tOtherOn, "Other"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowOther = false;
                }
            }
            else
            {
                if (GUILayout.Button(new GUIContent(tOtherOff, "Other"), ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowOther = true;
                }
            }

            GUILayout.Box(" ", BoxNoBorder, GUILayout.Height(34));

            if (GUILayout.Button("X", ButtonRed, GUILayout.Height(20), GUILayout.Width(20)))
            {
                loadedPersistence = false;
                KerbalKonstructs.instance.showMapIconManager = false;
            }

            GUILayout.EndHorizontal();

            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 + 2, labelSize.y + 2), GUI.tooltip, BoxNoBorder);
            }

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
Esempio n. 5
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;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Generate stream directory based on relative scope path. The base directory is
 /// <code>streams</code>, e.g. a scope <code>/application/one/two</code> will
 /// generate a directory <code>/streams/one/two</code> inside the application.
 /// </summary>
 /// <param name="scope">Scope.</param>
 /// <returns>Directory based on relative scope path.</returns>
 private string GetStreamDirectory(IScope scope)
 {
     return(PersistenceUtils.GetPath(scope, "streams"));
 }
        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));
        }
Esempio n. 8
0
        public static void StaffingInterface(StaticObject selectedFacility)
        {
            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;

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

            fStaff    = (float)selectedFacility.getSetting("StaffCurrent");
            fMaxStaff = (float)selectedFacility.getSetting("StaffMax");

            bIsBarracks = false;

            if ((string)selectedFacility.getSetting("FacilityType") == "Barracks")
            {
                bIsBarracks = true;
            }
            else
            if ((string)selectedFacility.model.getSetting("DefaultFacilityType") == "Barracks")
            {
                bIsBarracks = true;
            }

            if (fMaxStaff < 1)
            {
                fMaxStaff = (float)selectedFacility.model.getSetting("DefaultStaffMax");

                if (fMaxStaff < 1)
                {
                    selectedFacility.setSetting("StaffMax", (float)0);
                    //PersistenceUtils.saveStaticPersistence(selectedFacility);
                }
                else
                {
                    selectedFacility.setSetting("StaffMax", (float)fMaxStaff);
                    PersistenceUtils.saveStaticPersistence(selectedFacility);
                }
            }

            if (fMaxStaff > 0)
            {
                float fHireFundCost = 5000;
                float fFireRefund   = 2500;
                float fFireRepCost  = 1;

                bIsOpen = ((string)selectedFacility.getSetting("OpenCloseState") == "Open");

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

                GUILayout.Space(5);

                float CountCurrent = fStaff;
                float CountEmpty   = fMaxStaff - fStaff;
                float funassigned  = (float)selectedFacility.getSetting("ProductionRateCurrent");

                scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(58));
                {
                    GUILayout.BeginHorizontal();
                    {
                        while (CountCurrent > 0)
                        {
                            GUILayout.Box(tKerbal, GUILayout.Width(23));
                            CountCurrent = CountCurrent - 1;
                        }

                        while (CountEmpty > 0)
                        {
                            GUILayout.Box(tNoKerbal, GUILayout.Width(23));
                            CountEmpty = CountEmpty - 1;
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndScrollView();

                GUI.enabled = bIsOpen;

                if (!bIsBarracks)
                {
                    GUILayout.Box("Assigned Staff: " + fStaff.ToString("#0") + "/" + fMaxStaff.ToString("#0"), BoxInfo);
                }

                if (bIsBarracks)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Staff: " + fStaff.ToString("#0") + "/" + fMaxStaff.ToString("#0"), LabelInfo);
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Unassigned: " + funassigned.ToString("#0") + "/" + fStaff.ToString("#0"), LabelInfo);
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    {
                        if (GUILayout.Button("Hire", ButtonSmallText, GUILayout.Height(20)))
                        {
                            if (fStaff == fMaxStaff)
                            {
                                MiscUtils.HUDMessage("Facility is full.", 10,
                                                     3);
                            }
                            else
                            {
                                double currentfunds = Funding.Instance.Funds;

                                if (fHireFundCost > currentfunds)
                                {
                                    MiscUtils.HUDMessage("Insufficient funds to hire staff!", 10,
                                                         3);
                                }
                                else
                                {
                                    selectedFacility.setSetting("StaffCurrent", (float)fStaff + 1);
                                    Funding.Instance.AddFunds(-fHireFundCost, TransactionReasons.Cheating);
                                    selectedFacility.setSetting("ProductionRateCurrent", (float)selectedFacility.getSetting("ProductionRateCurrent") + 1);
                                    PersistenceUtils.saveStaticPersistence(selectedFacility);
                                }
                            }
                        }
                        if (GUILayout.Button("Fire", ButtonSmallText, GUILayout.Height(20)))
                        {
                            if (fStaff < 2)
                            {
                                MiscUtils.HUDMessage("This facility must have at least one caretaker.", 10, 3);
                            }
                            else
                            {
                                if ((float)selectedFacility.getSetting("ProductionRateCurrent") < 1)
                                {
                                    MiscUtils.HUDMessage("All staff are assigned to duties. Staff must be unassigned in order to fire them.", 10, 3);
                                }
                                else
                                {
                                    selectedFacility.setSetting("StaffCurrent", (float)fStaff - 1);
                                    selectedFacility.setSetting("ProductionRateCurrent", (float)selectedFacility.getSetting("ProductionRateCurrent") - 1);
                                    PersistenceUtils.saveStaticPersistence(selectedFacility);
                                    Funding.Instance.AddFunds(fFireRefund, TransactionReasons.Cheating);
                                    Reputation.Instance.AddReputation(-fFireRepCost, TransactionReasons.Cheating);
                                }
                            }
                        }
                    }

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

                    string sHireTip = " Cost to hire next kerbal: " + fHireFundCost.ToString("#0") + " funds.";
                    string sFireTip = " Refund for firing: " + fFireRefund.ToString("#0") + " funds. Rep lost: " + fFireRepCost.ToString("#0") + ".";

                    GUILayout.Space(2);

                    if (fStaff < fMaxStaff)
                    {
                        GUILayout.Box(sHireTip, BoxInfo, GUILayout.Height(16));
                    }

                    if (fStaff > 1)
                    {
                        GUILayout.Box(sFireTip, BoxInfo, GUILayout.Height(16));
                    }
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    {
                        if (GUILayout.Button("Assign", ButtonSmallText, GUILayout.Height(20)))
                        {
                            if (fStaff == fMaxStaff)
                            {
                                MiscUtils.HUDMessage("Facility is fully staffed.", 10,
                                                     3);
                            }
                            else
                            {
                                float fAvailable = TotalBarracksPool(selectedFacility);

                                if (fAvailable < 1)
                                {
                                    MiscUtils.HUDMessage("No unassigned staff available.", 10, 3);
                                }
                                else
                                {
                                    StaticObject soNearestBarracks = NearestBarracks(selectedFacility);

                                    if (soNearestBarracks != null)
                                    {
                                        DrawFromBarracks(soNearestBarracks);

                                        selectedFacility.setSetting("StaffCurrent", (float)fStaff + 1);
                                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                                        PersistenceUtils.saveStaticPersistence(soNearestBarracks);
                                    }
                                    else
                                    {
                                        MiscUtils.HUDMessage("No facility with available staff is nearby.", 10, 3);
                                    }
                                }
                            }
                        }

                        if (GUILayout.Button("Unassign", ButtonSmallText, GUILayout.Height(20)))
                        {
                            if (fStaff < 2)
                            {
                                MiscUtils.HUDMessage("An open facility must have one resident caretaker.", 10, 3);
                            }
                            else
                            {
                                StaticObject soAvailableSpace = NearestBarracks(selectedFacility, false);

                                if (soAvailableSpace != null)
                                {
                                    UnassignToBarracks(soAvailableSpace);
                                    selectedFacility.setSetting("StaffCurrent", (float)fStaff - 1);
                                    PersistenceUtils.saveStaticPersistence(selectedFacility);
                                    PersistenceUtils.saveStaticPersistence(soAvailableSpace);
                                }
                                else
                                {
                                    MiscUtils.HUDMessage("There's no room left in a barracks or apartment for this kerbal to go to.", 10, 3);
                                }
                            }
                        }
                    }

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

                GUILayout.Space(5);

                if (KerbalKonstructs.instance.DevMode)
                {
                    fXP = (float)selectedFacility.getSetting("FacilityXP");
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Space(5);
                        GUILayout.Label("XP: ", LabelInfo, GUILayout.Height(23), GUILayout.Width(55));

                        float CountCurrentXP = fXP;
                        float CountEmptyXP   = 5 - fXP;

                        while (CountCurrentXP > 0)
                        {
                            GUILayout.Button(tXPGained, GUILayout.Height(23), GUILayout.Width(23));
                            CountCurrentXP = CountCurrentXP - 1;
                        }

                        while (CountEmptyXP > 0)
                        {
                            GUILayout.Button(tXPUngained, GUILayout.Height(23), GUILayout.Width(23));
                            CountEmptyXP = CountEmptyXP - 1;
                        }

                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("Spend", ButtonSmallText, GUILayout.Height(23)))
                        {
                            if (fXP < 1)
                            {
                                MiscUtils.HUDMessage("No XP to spend!", 10, 3);
                            }
                        }
                    }
                    GUILayout.EndHorizontal();
                }
            }
            else
            {
                GUILayout.FlexibleSpace();
                GUILayout.Box("This facility does not require staff assigned to it.", BoxInfo, GUILayout.Height(16));
            }
        }
        public static void FuelTanksInterface(StaticObject selectedObject)
        {
            string smessage = "";

            string sFacilityName = (string)selectedObject.model.getSetting("title");
            string sFacilityRole = (string)selectedObject.getSetting("FacilityType");

            fLqFMax     = (float)selectedObject.model.getSetting("LqFMax");
            fLqFCurrent = (float)selectedObject.getSetting("LqFCurrent");
            fOxFMax     = (float)selectedObject.model.getSetting("OxFMax");
            fOxFCurrent = (float)selectedObject.getSetting("OxFCurrent");
            fMoFMax     = (float)selectedObject.model.getSetting("MoFMax");
            fMoFCurrent = (float)selectedObject.getSetting("MoFCurrent");

            float fPurchaseRate = fTransferRate * 100f;

            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;

            if (!FlightGlobals.ActiveVessel.Landed)
            {
                GUILayout.Box("A vessel must be landed to use this facility.", BoxInfo);
                LockFuelTank();
            }

            var vDist = Vector3.Distance(selectedObject.gameObject.transform.position, FlightGlobals.ActiveVessel.transform.position);

            if ((double)vDist < KerbalKonstructs.instance.facilityUseRange)
            {
            }
            else
            {
                GUILayout.Box("A vessel must be in range to use this facility.", BoxInfo);
                LockFuelTank();
            }

            GUILayout.Space(3);
            GUILayout.Label("Fuel Stores", LabelInfo);
            scrollPos4 = GUILayout.BeginScrollView(scrollPos4);
            if (fLqFMax > 0)
            {
                GUILayout.Label("LiquidFuel", LabelInfo);

                GUILayout.BeginHorizontal();
                GUILayout.Label("Max ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(string.Format("{0}", fLqFMax), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.Label("Current ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(fLqFCurrent.ToString("#0.00"), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Order", GUILayout.Height(18)))
                {
                    LockFuelTank();
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedLqF = true;
                }
                GUI.enabled = !bLqFIn;
                if (GUILayout.Button("In", GUILayout.Height(18)))
                {
                    bLqFIn  = true;
                    bLqFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = !bLqFOut;
                if (GUILayout.Button("Out", GUILayout.Height(18)))
                {
                    bLqFOut = true;
                    bLqFIn  = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = bLqFIn || bLqFOut;
                if (GUILayout.Button("Stop", GUILayout.Height(18)))
                {
                    bLqFIn  = false;
                    bLqFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer stopped";
                    MiscUtils.HUDMessage(smessage, 10, 2);
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();
            }

            if (bOrderedLqF)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.RepeatButton("-", GUILayout.Height(18)))
                {
                    fLqFAmount = (float.Parse(fLqFAmount) - fPurchaseRate).ToString();
                    if ((float.Parse(fLqFAmount)) < 0f)
                    {
                        fLqFAmount = "0.00";
                    }
                }
                GUI.enabled = false;
                GUILayout.TextField(fLqFAmount, GUILayout.Height(18));
                GUI.enabled = true;
                if (GUILayout.RepeatButton("+", GUILayout.Height(18)))
                {
                    fLqFAmount = (float.Parse(fLqFAmount) + fPurchaseRate).ToString();
                    if ((float.Parse(fLqFAmount)) > (fLqFMax - fLqFCurrent))
                    {
                        fLqFAmount = (fLqFMax - fLqFCurrent).ToString();
                    }
                }

                if (GUILayout.Button("Max", GUILayout.Height(18)))
                {
                    fLqFAmount = (fLqFMax - fLqFCurrent).ToString();
                    if ((float.Parse(fLqFAmount)) < 0f)
                    {
                        fLqFAmount = "0.00";
                    }
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }

                float flqFPrice = 0.5f;

                float fLqFCost = (float.Parse(fLqFAmount)) * flqFPrice;
                GUILayout.Label("Cost: " + fLqFCost.ToString("#0") + " \\F", LabelInfo);
                if (GUILayout.Button("Buy", GUILayout.Height(18)))
                {
                    if ((float)selectedObject.getSetting("LqFCurrent") + (float.Parse(fLqFAmount)) > fLqFMax)
                    {
                        MiscUtils.HUDMessage("Insufficient fuel capacity!", 10, 0);
                        fLqFAmount = "0.00";
                    }
                    else
                    {
                        if (MiscUtils.isCareerGame())
                        {
                            double currentfunds = Funding.Instance.Funds;

                            if (fLqFCost > currentfunds)
                            {
                                MiscUtils.HUDMessage("Insufficient funds!", 10, 0);
                            }
                            else
                            {
                                Funding.Instance.AddFunds(-fLqFCost, TransactionReasons.Cheating);
                                selectedObject.setSetting("LqFCurrent", (float)selectedObject.getSetting("LqFCurrent") + (float.Parse(fLqFAmount)));
                            }
                        }
                        else
                        {
                            selectedObject.setSetting("LqFCurrent", (float)selectedObject.getSetting("LqFCurrent") + (float.Parse(fLqFAmount)));
                        }
                    }

                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                if (GUILayout.Button("Done", GUILayout.Height(18)))
                {
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedLqF = false;
                }
                GUILayout.EndHorizontal();
            }

            if (fOxFMax > 0)
            {
                GUILayout.Label("Oxidizer", LabelInfo);

                GUILayout.BeginHorizontal();
                GUILayout.Label("Max ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(string.Format("{0}", fOxFMax), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.Label("Current ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(fOxFCurrent.ToString("#0.00"), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Order", GUILayout.Height(18)))
                {
                    LockFuelTank();
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedOxF = true;
                }
                GUI.enabled = !bOxFIn;
                if (GUILayout.Button("In", GUILayout.Height(18)))
                {
                    bOxFIn  = true;
                    bOxFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = !bOxFOut;
                if (GUILayout.Button("Out", GUILayout.Height(18)))
                {
                    bOxFOut = true;
                    bOxFIn  = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = bOxFIn || bOxFOut;
                if (GUILayout.Button("Stop", GUILayout.Height(18)))
                {
                    bOxFIn  = false;
                    bOxFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer stopped";
                    MiscUtils.HUDMessage(smessage, 10, 2);
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();
            }

            if (bOrderedOxF)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.RepeatButton("-", GUILayout.Height(18)))
                {
                    fOxFAmount = (float.Parse(fOxFAmount) - fPurchaseRate).ToString();
                    if ((float.Parse(fOxFAmount)) < 0f)
                    {
                        fOxFAmount = "0.00";
                    }
                }
                GUI.enabled = false;
                GUILayout.TextField(fOxFAmount, GUILayout.Height(18));
                GUI.enabled = true;
                if (GUILayout.RepeatButton("+", GUILayout.Height(18)))
                {
                    fOxFAmount = (float.Parse(fOxFAmount) + fPurchaseRate).ToString();
                    if ((float.Parse(fOxFAmount)) > (fOxFMax - fOxFCurrent))
                    {
                        fOxFAmount = (fOxFMax - fOxFCurrent).ToString();
                    }
                }

                if (GUILayout.Button("Max", GUILayout.Height(18)))
                {
                    fOxFAmount = (fOxFMax - fOxFCurrent).ToString();
                    if ((float.Parse(fOxFAmount)) < 0f)
                    {
                        fOxFAmount = "0.00";
                    }
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }

                float fOxFPrice = 1.5f;

                float fOxFCost = (float.Parse(fOxFAmount)) * fOxFPrice;
                GUILayout.Label("Cost: " + fOxFCost.ToString("#0") + " \\F", LabelInfo);
                if (GUILayout.Button("Buy", GUILayout.Height(18)))
                {
                    if ((float)selectedObject.getSetting("OxFCurrent") + (float.Parse(fOxFAmount)) > fOxFMax)
                    {
                        MiscUtils.HUDMessage("Insufficient fuel capacity!", 10, 0);
                        fOxFAmount = "0.00";
                    }
                    else
                    {
                        if (MiscUtils.isCareerGame())
                        {
                            double currentfunds = Funding.Instance.Funds;

                            if (fOxFCost > currentfunds)
                            {
                                MiscUtils.HUDMessage("Insufficient funds!", 10, 0);
                            }
                            else
                            {
                                Funding.Instance.AddFunds(-fOxFCost, TransactionReasons.Cheating);
                                selectedObject.setSetting("OxFCurrent", (float)selectedObject.getSetting("OxFCurrent") + (float.Parse(fOxFAmount)));
                            }
                        }
                        else
                        {
                            selectedObject.setSetting("OxFCurrent", (float)selectedObject.getSetting("OxFCurrent") + (float.Parse(fOxFAmount)));
                        }
                    }

                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                if (GUILayout.Button("Done", GUILayout.Height(18)))
                {
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedOxF = false;
                }
                GUILayout.EndHorizontal();
            }

            if (fMoFMax > 0)
            {
                GUILayout.Label("Monopropellant", LabelInfo);

                GUILayout.BeginHorizontal();
                GUILayout.Label("Max ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(string.Format("{0}", fMoFMax), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.Label("Current ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(fMoFCurrent.ToString("#0.00"), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Order", GUILayout.Height(18)))
                {
                    LockFuelTank();
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedMoF = true;
                }
                GUI.enabled = !bMoFIn;
                if (GUILayout.Button("In", GUILayout.Height(18)))
                {
                    bMoFIn  = true;
                    bMoFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = !bMoFOut;
                if (GUILayout.Button("Out", GUILayout.Height(18)))
                {
                    bMoFOut = true;
                    bMoFIn  = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = bMoFIn || bMoFOut;
                if (GUILayout.Button("Stop", GUILayout.Height(18)))
                {
                    bMoFIn  = false;
                    bMoFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer stopped";
                    MiscUtils.HUDMessage(smessage, 10, 2);
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();
            }

            if (bOrderedMoF)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.RepeatButton("-", GUILayout.Height(18)))
                {
                    fMoFAmount = (float.Parse(fMoFAmount) - fPurchaseRate).ToString();
                    if ((float.Parse(fMoFAmount)) < 0f)
                    {
                        fMoFAmount = "0.00";
                    }
                }
                GUI.enabled = false;
                GUILayout.TextField(fMoFAmount, GUILayout.Height(18));
                GUI.enabled = true;
                if (GUILayout.RepeatButton("+", GUILayout.Height(18)))
                {
                    fMoFAmount = (float.Parse(fMoFAmount) + fPurchaseRate).ToString();
                    if ((float.Parse(fMoFAmount)) > (fMoFMax - fMoFCurrent))
                    {
                        fMoFAmount = (fMoFMax - fMoFCurrent).ToString();
                    }
                }

                if (GUILayout.Button("Max", GUILayout.Height(18)))
                {
                    fMoFAmount = (fMoFMax - fMoFCurrent).ToString();
                    if ((float.Parse(fMoFAmount)) < 0f)
                    {
                        fMoFAmount = "0.00";
                    }
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }

                float fMoFPrice = 1.2f;

                float fMoFCost = (float.Parse(fMoFAmount)) * fMoFPrice;
                GUILayout.Label("Cost: " + fMoFCost.ToString("#0") + " \\F", LabelInfo);
                if (GUILayout.Button("Buy", GUILayout.Height(18)))
                {
                    if ((float)selectedObject.getSetting("MoFCurrent") + (float.Parse(fMoFAmount)) > fMoFMax)
                    {
                        MiscUtils.HUDMessage("Insufficient fuel capacity!", 10, 0);
                        fMoFAmount = "0.00";
                    }
                    else
                    {
                        if (MiscUtils.isCareerGame())
                        {
                            double currentfunds = Funding.Instance.Funds;

                            if (fMoFCost > currentfunds)
                            {
                                MiscUtils.HUDMessage("Insufficient funds!", 10, 0);
                            }
                            else
                            {
                                Funding.Instance.AddFunds(-fMoFCost, TransactionReasons.Cheating);
                                selectedObject.setSetting("MoFCurrent", (float)selectedObject.getSetting("MoFCurrent") + (float.Parse(fMoFAmount)));
                            }
                        }
                        else
                        {
                            selectedObject.setSetting("MoFCurrent", (float)selectedObject.getSetting("MoFCurrent") + (float.Parse(fMoFAmount)));
                        }
                    }

                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                if (GUILayout.Button("Done", GUILayout.Height(18)))
                {
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedMoF = false;
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();

            if (fOxFMax > 0 || fLqFMax > 0 || fMoFMax > 0)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Transfer Rate", LabelInfo);

                GUI.enabled = (fTransferRate != 0.01f);
                if (GUILayout.Button(" x1", GUILayout.Height(18)))
                {
                    fTransferRate = 0.01f;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer rate set to x1";
                    MiscUtils.HUDMessage(smessage, 10, 2);
                }
                GUI.enabled = (fTransferRate != 0.04f);
                if (GUILayout.Button(" x4", GUILayout.Height(18)))
                {
                    fTransferRate = 0.04f;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer rate set to x4";
                    MiscUtils.HUDMessage(smessage, 10, 2);
                }
                GUI.enabled = (fTransferRate != 0.1f);
                if (GUILayout.Button("x10", GUILayout.Height(18)))
                {
                    fTransferRate = 0.1f;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer rate set to x10";
                    MiscUtils.HUDMessage(smessage, 10, 2);
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                if (!FlightGlobals.ActiveVessel.isEVA && FlightGlobals.ActiveVessel.Landed)
                {
                    GUILayout.Label(FlightGlobals.ActiveVessel.vesselName + "'s Tanks", LabelInfo);

                    scrollPos3 = GUILayout.BeginScrollView(scrollPos3);
                    foreach (Part fTank in FlightGlobals.ActiveVessel.parts)
                    {
                        foreach (PartResource rResource in fTank.Resources)
                        {
                            if (rResource.resourceName == "LiquidFuel" || rResource.resourceName == "Oxidizer" || rResource.resourceName == "MonoPropellant")
                            {
                                if (SelectedTank == fTank && SelectedResource == rResource)
                                {
                                    PartSelected = true;
                                }
                                else
                                {
                                    PartSelected = false;
                                }

                                GUILayout.BeginHorizontal();
                                GUILayout.Box("" + fTank.gameObject.name, GUILayout.Height(18));
                                GUILayout.Box("" + rResource.resourceName, GUILayout.Height(18));
                                GUILayout.EndHorizontal();

                                GUILayout.BeginHorizontal();
                                GUILayout.Label("Fuel", LabelInfo);
                                GUI.enabled = false;
                                GUILayout.TextField("" + rResource.amount.ToString("#0.00"), GUILayout.Height(18));
                                GUI.enabled = true;

                                GUI.enabled = !PartSelected;
                                if (GUILayout.Button(" Select ", GUILayout.Height(18)))
                                {
                                    SelectedResource = rResource;
                                    SelectedTank     = fTank;
                                    PersistenceUtils.saveStaticPersistence(selectedObject);
                                }

                                GUI.enabled = PartSelected;
                                if (GUILayout.Button("Deselect", GUILayout.Height(18)))
                                {
                                    SelectedResource = null;
                                    SelectedTank     = null;
                                    PersistenceUtils.saveStaticPersistence(selectedObject);
                                }
                                GUI.enabled = true;
                                GUILayout.EndHorizontal();
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    GUILayout.EndScrollView();

                    GUI.enabled = true;

                    if (SelectedResource != null && SelectedTank != null)
                    {
                        if (bMoFOut || bOxFOut || bLqFOut)
                        {
                            doFuelOut(selectedObject);
                        }
                        if (bMoFIn || bOxFIn || bLqFIn)
                        {
                            doFuelIn(selectedObject);
                        }
                    }
                }
            }

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
        void drawMapManagerWindow(int windowID)
        {
            if (!loadedPersistence && MiscUtils.isCareerGame())
            {
                PersistenceFile <LaunchSite> .LoadList(LaunchSiteManager.AllLaunchSites, "LAUNCHSITES", "KK");

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

                loadedPersistence = true;
            }

            GUILayout.BeginHorizontal();
            GUILayout.Box(" ", UIMain.BoxNoBorder, GUILayout.Height(34));

            GUI.enabled = (MiscUtils.isCareerGame());
            if (!MiscUtils.isCareerGame())
            {
                GUILayout.Button(UIMain.tOpenBasesOff, GUILayout.Width(32), GUILayout.Height(32));
                GUILayout.Button(UIMain.tClosedBasesOff, GUILayout.Width(32), GUILayout.Height(32));
                GUILayout.Box(" ", UIMain.BoxNoBorder, GUILayout.Height(34));
                GUILayout.Button(UIMain.tTrackingOff, GUILayout.Width(32), GUILayout.Height(32));
            }
            else
            {
                if (KerbalKonstructs.instance.mapShowOpen)
                {
                    if (GUILayout.Button(new GUIContent(UIMain.tOpenBasesOn, "Opened"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowOpen = false;
                    }
                }
                else
                {
                    if (GUILayout.Button(new GUIContent(UIMain.tOpenBasesOff, "Opened"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowOpen = true;
                    }
                }

                if (!KerbalKonstructs.instance.disableDisplayClosed)
                {
                    if (KerbalKonstructs.instance.mapShowClosed)
                    {
                        if (GUILayout.Button(new GUIContent(UIMain.tClosedBasesOn, "Closed"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                        {
                            KerbalKonstructs.instance.mapShowClosed = false;
                        }
                    }
                    else
                    {
                        if (GUILayout.Button(new GUIContent(UIMain.tClosedBasesOff, "Closed"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                        {
                            KerbalKonstructs.instance.mapShowClosed = true;
                        }
                    }
                }

                GUILayout.Box(" ", UIMain.BoxNoBorder, GUILayout.Height(34));
                if (KerbalKonstructs.instance.mapShowOpenT)
                {
                    if (GUILayout.Button(new GUIContent(UIMain.tTrackingOn, "Tracking Stations"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowOpenT = false;
                    }
                }
                else
                {
                    if (GUILayout.Button(new GUIContent(UIMain.tTrackingOff, "Tracking Stations"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowOpenT = true;
                    }
                }
            }
            GUI.enabled = true;

            GUILayout.Box(" ", UIMain.BoxNoBorder, GUILayout.Height(34));

            if (KerbalKonstructs.instance.mapShowRocketbases)
            {
                if (GUILayout.Button(new GUIContent(UIMain.tLaunchpadsOn, "Rocketpads"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowRocketbases = false;
                }
            }
            else
            {
                if (GUILayout.Button(new GUIContent(UIMain.tLaunchpadsOff, "Rocketpads"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowRocketbases = true;
                }
            }

            if (KerbalKonstructs.instance.mapShowHelipads)
            {
                if (GUILayout.Button(new GUIContent(UIMain.tHelipadsOn, "Helipads"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowHelipads = false;
                }
            }
            else
            {
                if (GUILayout.Button(new GUIContent(UIMain.tHelipadsOff, "Helipads"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowHelipads = true;
                }
            }

            if (KerbalKonstructs.instance.mapShowRunways)
            {
                if (GUILayout.Button(new GUIContent(UIMain.tRunwaysOn, "Runways"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowRunways = false;
                }
            }
            else
            {
                if (GUILayout.Button(new GUIContent(UIMain.tRunwaysOff, "Runways"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowRunways = true;
                }
            }

            if (KerbalKonstructs.instance.mapShowOther)
            {
                if (GUILayout.Button(new GUIContent(UIMain.tOtherOn, "Other"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowOther = false;
                }
            }
            else
            {
                if (GUILayout.Button(new GUIContent(UIMain.tOtherOff, "Other"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapShowOther = true;
                }
            }

            GUILayout.Box(" ", UIMain.BoxNoBorder, GUILayout.Height(34));

            GUI.enabled = (MiscUtils.isCareerGame());
            if (!MiscUtils.isCareerGame())
            {
                GUILayout.Button(UIMain.tDownlinksOff, GUILayout.Width(32), GUILayout.Height(32));
                GUILayout.Button(UIMain.tUplinksOff, GUILayout.Width(32), GUILayout.Height(32));
                GUILayout.Button(UIMain.tRadarOff, GUILayout.Width(32), GUILayout.Height(32));
                GUILayout.Button(UIMain.tGroundCommsOff, GUILayout.Width(32), GUILayout.Height(32));
            }
            else
            {
                if (KerbalKonstructs.instance.mapShowDownlinks)
                {
                    if (GUILayout.Button(new GUIContent(UIMain.tDownlinksOn, "Downlinks"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowDownlinks = false;
                    }
                }
                else
                {
                    if (GUILayout.Button(new GUIContent(UIMain.tDownlinksOff, "Downlinks"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowDownlinks = true;
                    }
                }

                if (KerbalKonstructs.instance.mapShowUplinks)
                {
                    if (GUILayout.Button(new GUIContent(UIMain.tUplinksOn, "Uplinks"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowUplinks = false;
                    }
                }
                else
                {
                    if (GUILayout.Button(new GUIContent(UIMain.tUplinksOff, "Uplinks"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowUplinks = true;
                    }
                }

                if (KerbalKonstructs.instance.mapShowRadar)
                {
                    if (GUILayout.Button(new GUIContent(UIMain.tRadarOn, "Radar"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowRadar = false;
                    }
                }
                else
                {
                    if (GUILayout.Button(new GUIContent(UIMain.tRadarOff, "Radar"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowRadar = true;
                    }
                }

                if (KerbalKonstructs.instance.mapShowGroundComms)
                {
                    if (GUILayout.Button(new GUIContent(UIMain.tGroundCommsOn, "Ground Comms"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowGroundComms = false;
                    }
                }
                else
                {
                    if (GUILayout.Button(new GUIContent(UIMain.tGroundCommsOff, "Ground Comms"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                    {
                        KerbalKonstructs.instance.mapShowGroundComms = true;
                    }
                }
            }
            GUI.enabled = true;

            GUILayout.Box(" ", UIMain.BoxNoBorder, GUILayout.Height(34));

            if (KerbalKonstructs.instance.mapHideIconsBehindBody)
            {
                if (GUILayout.Button(new GUIContent(UIMain.tHideOn, "Occlude"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapHideIconsBehindBody = false;
                }
            }
            else
            {
                if (GUILayout.Button(new GUIContent(UIMain.tHideOff, "Occlude"), UIMain.ButtonKK, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    KerbalKonstructs.instance.mapHideIconsBehindBody = true;
                }
            }

            GUILayout.Box(" ", UIMain.BoxNoBorder, GUILayout.Height(34));

            if (GUILayout.Button("X", UIMain.ButtonRed, GUILayout.Height(20), GUILayout.Width(20)))
            {
                loadedPersistence = false;
                WindowManager.instance.CloseWindow(KerbalKonstructs.instance.GUI_MapIconManager.drawManager);
            }

            GUILayout.EndHorizontal();

            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, UIMain.KKToolTip);
            }

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
        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);
                    }
                }
            }
        }
Esempio n. 12
0
        void drawFacilityManagerWindow(int windowID)
        {
            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;

            Yellowtext = new GUIStyle(GUI.skin.box);
            Yellowtext.normal.textColor  = Color.yellow;
            Yellowtext.normal.background = null;

            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;

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

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

                GUILayout.FlexibleSpace();

                GUILayout.Button("Facility Manager", DeadButton, GUILayout.Height(16));

                GUILayout.FlexibleSpace();

                GUI.enabled = true;

                if (GUILayout.Button("X", DeadButtonRed, GUILayout.Height(16)))
                {
                    PersistenceUtils.saveStaticPersistence(selectedFacility);
                    selectedFacility = null;
                    WindowManager.instance.CloseWindow(KerbalKonstructs.instance.GUI_FacilityManager.drawFacilityManager);
                }
            }
            GUILayout.EndHorizontal();

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

            GUILayout.Space(2);

            if (selectedFacility != null)
            {
                sFacilityType = (string)selectedFacility.getSetting("FacilityType");

                if (sFacilityType == "TrackingStation")
                {
                    sFacilityName = "Tracking Station";
                    bHalfwindow   = true;
                }
                else
                {
                    sFacilityName = (string)selectedFacility.model.getSetting("title");
                }

                GUILayout.Box("" + sFacilityName, Yellowtext);
                GUILayout.Space(5);

                fAlt = (float)selectedFacility.getSetting("RadiusOffset");

                ObjectPos    = KerbalKonstructs.instance.getCurrentBody().transform.InverseTransformPoint(selectedFacility.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;
                }

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(5);
                    GUILayout.Label("Alt. " + fAlt.ToString("#0.0") + "m", LabelInfo);
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Lat. " + disObjectLat.ToString("#0.000"), LabelInfo);
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Lon. " + disObjectLon.ToString("#0.000"), LabelInfo);
                    GUILayout.Space(5);
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(5);

                string sPurpose = "";

                if (sFacilityType == "Hangar")
                {
                    sPurpose    = "Craft can be stored in this building for launching from the base at a later date. The building has limited space.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "RocketAssembly")
                {
                    sPurpose    = "This facility can construct craft that have been designed in KSC's VAB and can store a constructed craft for launching from the base at a later date.";
                    bHalfwindow = false;
                }
                else
                if (sFacilityType == "PlaneAssembly")
                {
                    sPurpose    = "This facility can construct craft that have been designed in KSC's SPH and can store a constructed craft for launching from the base at a later date.";
                    bHalfwindow = false;
                }
                else
                if (sFacilityType == "ControlTower")
                {
                    sPurpose = "This facility manages incoming and outgoing air-traffic to and from the base, as well as administrating most other base operations.";
                }
                else
                if (sFacilityType == "Barracks")
                {
                    sPurpose    = "This facility provides a temporary home for base-staff. Other facilities can draw staff from the pool available at this facility.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "RadarStation")
                {
                    sPurpose    = "This facility tracks craft in the planet's atmosphere at a limited range. It provides bonuses for recovery operations by the nearest open base.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "Research")
                {
                    sPurpose    = "This facility carries out research and generates Science.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "Mining")
                {
                    sPurpose = "This facility excavates useful minerals and materials and thus generates Ore.";
                }
                else
                if (sFacilityType == "Refining")
                {
                    sPurpose = "This facility converts Ore into fuels.";
                }
                else
                if (sFacilityType == "Manufacturing")
                {
                    sPurpose = "This facility converts Ore into Processed Ore, for use in manufacturing craft in lieu of Funds, constructing and upgrading facilities.";
                }
                else
                if (sFacilityType == "Business")
                {
                    sPurpose    = "This facility carries out business related to the space program in order to generate Funds.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "Training")
                {
                    sPurpose = "This facility can provide professional skills and experience to rookie Kerbonauts.";
                }
                else
                if (sFacilityType == "Medical")
                {
                    sPurpose = "This facility can aid Kerbonaut recovery after long missions or injury.";
                }
                else
                if (sFacilityType == "TrackingStation")
                {
                    sPurpose    = "This facility can track a variety of off-Kerbin targets, including spacecraft, celestial bodies and asteroids.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "FuelTanks")
                {
                    sPurpose    = "This facility stores fuel for craft.";
                    bHalfwindow = false;
                }
                else
                if (sFacilityType == "Storage")
                {
                    sPurpose = "This facility stores construction materials (Processed Ore).";
                }
                else
                if (sFacilityType == "CraftAssembly")
                {
                    sPurpose    = "This facility can construct craft that have been designed in KSC's VAB or SPH and can store a constructed craft for launching from the base at a later date.";
                    bHalfwindow = false;
                }

                GUILayout.Label(sPurpose, LabelInfo);
                GUILayout.Space(2);
                GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
                GUILayout.Space(3);

                SharedInterfaces.OpenCloseFacility(selectedFacility);

                iFundsOpen2 = (float)selectedFacility.getSetting("OpenCost");
                isOpen2     = ((string)selectedFacility.getSetting("OpenCloseState") == "Open");
                float iFundsDefaultCost = (float)selectedFacility.model.getSetting("cost");
                if (iFundsOpen2 == 0)
                {
                    iFundsOpen2 = iFundsDefaultCost;
                }

                if (iFundsOpen2 == 0)
                {
                    isOpen2 = true;
                }

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

                GUI.enabled = isOpen2;

                if (sFacilityType == "TrackingStation")
                {
                    TrackingStationGUI.TrackingInterface(selectedFacility);
                }

                if (sFacilityType == "Hangar" || sFacilityType == "RocketAssembly" || sFacilityType == "PlaneAssembly" || sFacilityType == "CraftAssembly")
                {
                    HangarGUI.HangarInterface(selectedFacility);
                }

                // WIP

                /* if (sFacilityType == "RocketAssembly" || sFacilityType == "PlaneAssembly" || sFacilityType == "CraftAssembly")
                 * {
                 *      CraftConstructionGUI.CraftConstructionInterface(selectedFacility);
                 * } */

                if (sFacilityType == "Research" || sFacilityType == "Business" || sFacilityType == "Mining" ||
                    sFacilityType == "RocketAssembly" || sFacilityType == "PlaneAssembly" || sFacilityType == "CraftAssembly")
                {
                    ProductionGUI.ProductionInterface(selectedFacility, sFacilityType);
                }

                fLqFMax = (float)selectedFacility.model.getSetting("LqFMax");
                fOxFMax = (float)selectedFacility.model.getSetting("OxFMax");
                fMoFMax = (float)selectedFacility.model.getSetting("MoFMax");

                if (fLqFMax > 0 || fOxFMax > 0 || fMoFMax > 0 || sFacilityType == "FuelTanks")
                {
                    FuelTanksGUI.FuelTanksInterface(selectedFacility);
                }

                GUI.enabled = true;

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

                GUI.enabled = isOpen2;
                StaffGUI.StaffingInterface(selectedFacility);
                GUI.enabled = true;
            }

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

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
Esempio n. 13
0
        public void updateCache(Vector3 playerPos)
        {
            foreach (StaticObject obj in childObjects)
            {
                float dist    = Vector3.Distance(obj.gameObject.transform.position, playerPos);
                bool  visible = (dist < (float)obj.getSetting("VisibilityRange"));

                string sFacType = (string)obj.getSetting("FacilityType");

                if (sFacType == "Hangar")
                {
                    string sInStorage  = (string)obj.getSetting("InStorage");
                    string sInStorage2 = (string)obj.getSetting("TargetID");
                    string sInStorage3 = (string)obj.getSetting("TargetType");

                    foreach (Vessel vVesselStored in FlightGlobals.Vessels)
                    {
                        if (vVesselStored == null)
                        {
                            continue;
                        }
                        if (!vVesselStored.loaded)
                        {
                            continue;
                        }
                        if (vVesselStored.vesselType == VesselType.SpaceObject)
                        {
                            continue;
                        }
                        if (vVesselStored.vesselType == VesselType.Debris)
                        {
                            continue;
                        }
                        if (vVesselStored.vesselType == VesselType.EVA)
                        {
                            continue;
                        }
                        if (vVesselStored.vesselType == VesselType.Flag)
                        {
                            continue;
                        }
                        if (vVesselStored.vesselType == VesselType.Unknown)
                        {
                            continue;
                        }

                        string sHangarSpace = "None";
                        // If a vessel is hangared
                        if (vVesselStored.id.ToString() == sInStorage)
                        {
                            sHangarSpace = "InStorage";
                        }
                        if (vVesselStored.id.ToString() == sInStorage2)
                        {
                            sHangarSpace = "TargetID";
                        }
                        if (vVesselStored.id.ToString() == sInStorage3)
                        {
                            sHangarSpace = "TargetType";
                        }

                        if (sHangarSpace != "None")
                        {
                            if (vVesselStored == FlightGlobals.ActiveVessel)
                            {
                                // Craft has been taken control
                                // Empty the hangar
                                obj.setSetting(sHangarSpace, "None");
                                PersistenceUtils.saveStaticPersistence(obj);
                            }
                            else
                            {
                                // Hide the vessel - it is in the hangar
                                if (vVesselStored != null)
                                {
                                    foreach (Part p in vVesselStored.Parts)
                                    {
                                        if (p != null && p.gameObject != null)
                                        {
                                            p.gameObject.SetActive(false);
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }

                                    vVesselStored.MakeInactive();
                                    vVesselStored.enabled = false;

                                    if (vVesselStored.loaded)
                                    {
                                        vVesselStored.Unload();
                                    }
                                }
                            }
                        }
                    }
                }

                if (sFacType == "CityLights")
                {
                    if (dist < 60000f)
                    {
                        SetActiveRecursively(obj.gameObject, false);
                    }
                    else
                    {
                        if (visible)
                        {
                            SetActiveRecursively(obj.gameObject, true);
                        }
                    }
                }
                else
                {
                    if (visible)
                    {
                        SetActiveRecursively(obj.gameObject, true);
                    }
                }
            }
        }
Esempio n. 14
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);
        }
Esempio n. 15
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();
        }
Esempio n. 16
0
        public static void HangarInterface(StaticObject selectedFacility)
        {
            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;

            Yellowtext = new GUIStyle(GUI.skin.box);
            Yellowtext.normal.textColor  = Color.yellow;
            Yellowtext.normal.background = null;

            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;

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

            sInStorage  = (string)selectedFacility.getSetting("InStorage");
            sInStorage2 = (string)selectedFacility.getSetting("TargetID");
            sInStorage3 = (string)selectedFacility.getSetting("TargetType");

            float fMaxMass = (float)selectedFacility.model.getSetting("DefaultFacilityMassCapacity");

            if (fMaxMass < 1)
            {
                fMaxMass = 25f;
            }
            float fMaxCrafts = (float)selectedFacility.model.getSetting("DefaultFacilityCraftCapacity");

            if (fMaxCrafts < 1 || fMaxCrafts > 3)
            {
                fMaxCrafts = 2;
            }

            GUILayout.Space(2);
            GUILayout.Label("Where necessary craft are disassembled for storage or re-assembled before being rolled out. Please note that for game purposes, this procedure is instantaneous.", LabelInfo);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Max Craft: " + fMaxCrafts.ToString("#0"), LabelInfo);
            GUILayout.FlexibleSpace();
            GUILayout.Label("Max Mass/Craft: " + fMaxMass.ToString("#0") + " T", LabelInfo);
            GUILayout.EndHorizontal();

            if (sInStorage == null || sInStorage == "")
            {
                sInStorage = "None";
                selectedFacility.setSetting("InStorage", "None");
                PersistenceUtils.saveStaticPersistence(selectedFacility);
            }
            if (sInStorage2 == null || sInStorage2 == "")
            {
                sInStorage2 = "None";
                selectedFacility.setSetting("TargetID", "None");
                PersistenceUtils.saveStaticPersistence(selectedFacility);
            }
            if (sInStorage3 == null || sInStorage3 == "")
            {
                sInStorage3 = "None";
                selectedFacility.setSetting("TargetType", "None");
                PersistenceUtils.saveStaticPersistence(selectedFacility);
            }

            if (sInStorage == "None" && sInStorage2 == "None" && sInStorage3 == "None")
            {
                GUILayout.Label("No craft currently held in this facility.", LabelInfo);
            }
            else
            {
                int iNumberCrafts = NumberCraftHangared(selectedFacility);

                GUILayout.Box("Stored Craft (" + iNumberCrafts.ToString() + "/" + fMaxCrafts.ToString("#0") + ")", Yellowtext);

                List <Vessel> lVessels = FlightGlobals.Vessels;

                foreach (Vessel vVesselStored in lVessels)
                {
                    if (vVesselStored.id.ToString() == sInStorage)
                    {
                        if (GUILayout.Button("" + vVesselStored.vesselName, ButtonSmallText, GUILayout.Height(20)))
                        {
                            // Empty the hangar
                            if (HangarwayIsClear(selectedFacility))
                            {
                                sInStorage = "None";
                                UnhangarCraft(vVesselStored, selectedFacility);
                                sInStorage = "None";
                            }
                            else
                            {
                                MiscUtils.HUDMessage("Cannot roll craft out. Clear the way first!", 10,
                                                     3);
                            }
                        }
                        break;
                    }
                }

                foreach (Vessel vVesselStored in lVessels)
                {
                    if (vVesselStored.id.ToString() == sInStorage2)
                    {
                        if (GUILayout.Button("" + vVesselStored.vesselName, ButtonSmallText, GUILayout.Height(20)))
                        {
                            // Empty the hangar
                            if (HangarwayIsClear(selectedFacility))
                            {
                                sInStorage2 = "None";
                                UnhangarCraft(vVesselStored, selectedFacility);
                                sInStorage2 = "None";
                            }
                            else
                            {
                                MiscUtils.HUDMessage("Cannot roll craft out. Clear the way first!", 10,
                                                     3);
                            }
                        }
                        break;
                    }
                }

                foreach (Vessel vVesselStored in lVessels)
                {
                    if (vVesselStored.id.ToString() == sInStorage3)
                    {
                        if (GUILayout.Button("" + vVesselStored.vesselName, ButtonSmallText, GUILayout.Height(20)))
                        {
                            // Empty the hangar
                            if (HangarwayIsClear(selectedFacility))
                            {
                                sInStorage3 = "None";
                                UnhangarCraft(vVesselStored, selectedFacility);
                                sInStorage3 = "None";
                            }
                            else
                            {
                                MiscUtils.HUDMessage("Cannot roll craft out. Clear the way first!", 10,
                                                     3);
                            }
                        }
                        break;
                    }
                }
            }

            GUILayout.Space(5);

            scrollNearbyCraft = GUILayout.BeginScrollView(scrollNearbyCraft);

            GUILayout.Box("Nearby Craft", Yellowtext);

            bool bNearbyCraft = false;

            foreach (Vessel vVessel in FlightGlobals.Vessels)
            {
                if (vVessel == null)
                {
                    continue;
                }
                if (!vVessel.loaded)
                {
                    continue;
                }
                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;
                }
                if (vVessel.situation != Vessel.Situations.LANDED)
                {
                    continue;
                }
                if (vVessel.GetCrewCount() > 0)
                {
                    continue;
                }

                var vDistToCraft = Vector3.Distance(vVessel.gameObject.transform.position, selectedFacility.gameObject.transform.position);
                if (vDistToCraft > 250)
                {
                    continue;
                }

                bNearbyCraft = true;

                if (GUILayout.Button(" " + vVessel.vesselName + " ", ButtonSmallText, GUILayout.Height(20)))
                {
                    float fMass = vVessel.GetTotalMass();

                    if (fMass > fMaxMass)
                    {
                        MiscUtils.HUDMessage("Craft too heavy for this facility. Max " + fMaxMass.ToString("#0") + "T per craft.", 10,
                                             3);
                    }
                    else
                    {
                        float fMaxCraft = (float)selectedFacility.model.getSetting("DefaultFacilityCraftCapacity");
                        if (fMaxCraft < 1 || fMaxCraft > 3)
                        {
                            fMaxCraft = 2;
                        }

                        int iNumberCraft = NumberCraftHangared(selectedFacility);

                        if (iNumberCraft < (int)fMaxCraft)
                        {
                            HangarCraft(vVessel, selectedFacility, (int)fMaxCraft);
                        }
                        else
                        {
                            MiscUtils.HUDMessage("This facility is full. Max craft: " + fMaxCraft.ToString("#0"), 10,
                                                 3);
                        }
                    }
                }
            }

            if (!bNearbyCraft)
            {
                GUILayout.Label("There are no craft close enough to store in this facility.", LabelInfo);
            }

            GUILayout.EndScrollView();

            GUILayout.FlexibleSpace();
        }
Esempio n. 17
0
        public static void CacheHangaredCraft(StaticObject obj)
        {
            string sInStorage  = (string)obj.getSetting("InStorage");
            string sInStorage2 = (string)obj.getSetting("TargetID");
            string sInStorage3 = (string)obj.getSetting("TargetType");

            foreach (Vessel vVesselStored in FlightGlobals.Vessels)
            {
                if (vVesselStored == null)
                {
                    continue;
                }
                if (!vVesselStored.loaded)
                {
                    continue;
                }
                if (vVesselStored.vesselType == VesselType.SpaceObject)
                {
                    continue;
                }
                if (vVesselStored.vesselType == VesselType.Debris)
                {
                    continue;
                }
                if (vVesselStored.vesselType == VesselType.EVA)
                {
                    continue;
                }
                if (vVesselStored.vesselType == VesselType.Flag)
                {
                    continue;
                }
                if (vVesselStored.vesselType == VesselType.Unknown)
                {
                    continue;
                }

                string sHangarSpace = "None";
                // If a vessel is hangared
                if (vVesselStored.id.ToString() == sInStorage)
                {
                    sHangarSpace = "InStorage";
                }
                if (vVesselStored.id.ToString() == sInStorage2)
                {
                    sHangarSpace = "TargetID";
                }
                if (vVesselStored.id.ToString() == sInStorage3)
                {
                    sHangarSpace = "TargetType";
                }

                if (sHangarSpace != "None")
                {
                    if (vVesselStored == FlightGlobals.ActiveVessel)
                    {
                        // Craft has been taken control
                        // Empty the hangar
                        obj.setSetting(sHangarSpace, "None");
                        PersistenceUtils.saveStaticPersistence(obj);
                    }
                    else
                    {
                        // Hide the vessel - it is in the hangar
                        if (vVesselStored != null)
                        {
                            foreach (Part p in vVesselStored.Parts)
                            {
                                if (p != null && p.gameObject != null)
                                {
                                    p.gameObject.SetActive(false);
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            vVesselStored.MakeInactive();
                            vVesselStored.enabled = false;

                            if (vVesselStored.loaded)
                            {
                                vVesselStored.Unload();
                            }
                        }
                    }
                }
            }
        }
        public static void OpenCloseFacility(StaticObject selectedFacility)
        {
            BoxInfo = new GUIStyle(GUI.skin.box);
            BoxInfo.normal.textColor  = Color.white;
            BoxInfo.fontSize          = 12;
            BoxInfo.padding.top       = 2;
            BoxInfo.padding.bottom    = 1;
            BoxInfo.padding.left      = 5;
            BoxInfo.padding.right     = 5;
            BoxInfo.normal.background = null;

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

            float iFundsOpen2       = (float)selectedFacility.getSetting("OpenCost");
            float iFundsClose2      = (float)selectedFacility.getSetting("CloseValue");
            float iFundsDefaultCost = (float)selectedFacility.model.getSetting("cost");

            bool isAlwaysOpen2   = false;
            bool cannotBeClosed2 = false;

            // Career mode
            // If a launchsite is 0 to open it is always open
            if (iFundsOpen2 == 0 && iFundsDefaultCost == 0)
            {
                isAlwaysOpen2 = true;
            }

            // If it is 0 to close you cannot close it
            if (iFundsClose2 == 0 && iFundsDefaultCost == 0)
            {
                cannotBeClosed2 = true;
            }

            if (MiscUtils.isCareerGame())
            {
                bool isOpen2 = ((string)selectedFacility.getSetting("OpenCloseState") == "Open");

                GUILayout.BeginHorizontal();
                {
                    if (!isAlwaysOpen2)
                    {
                        GUI.enabled = !isOpen2;

                        if (iFundsOpen2 == 0)
                        {
                            iFundsOpen2 = iFundsDefaultCost;
                        }

                        if (GUILayout.Button("Open for \n" + iFundsOpen2 + " funds", ButtonSmallText, GUILayout.Height(30)))
                        {
                            double currentfunds2 = Funding.Instance.Funds;

                            if (iFundsOpen2 > currentfunds2)
                            {
                                MiscUtils.HUDMessage("Insufficient funds to open this facility!", 10, 0);
                            }
                            else
                            {
                                // Open the site - save to instance
                                selectedFacility.setSetting("OpenCloseState", "Open");

                                // Charge some funds
                                Funding.Instance.AddFunds(-iFundsOpen2, TransactionReasons.Cheating);

                                // Save new state to persistence
                                PersistenceUtils.saveStaticPersistence(selectedFacility);

                                storedEventso = selectedFacility;
                                if (evFacilityOpened != null)
                                {
                                    evFacilityOpened();
                                }

                                //PersistenceUtils.saveRTCareerBackup();
                            }
                        }
                        GUI.enabled = true;
                    }
                    else
                    {
                        // GUILayout.Box("This facility is always open.", BoxInfo);
                    }

                    if (!cannotBeClosed2)
                    {
                        GUI.enabled = isOpen2;

                        if (iFundsClose2 == 0)
                        {
                            iFundsClose2 = iFundsDefaultCost / 4;
                        }

                        if (GUILayout.Button("Close for \n" + iFundsClose2 + " funds", ButtonSmallText, GUILayout.Height(30)))
                        {
                            // Close the site - save to instance
                            // Pay back some funds
                            Funding.Instance.AddFunds(iFundsClose2, TransactionReasons.Cheating);
                            selectedFacility.setSetting("OpenCloseState", "Closed");

                            // Save new state to persistence
                            PersistenceUtils.saveStaticPersistence(selectedFacility);

                            storedEventso = selectedFacility;
                            if (evFacilityClosed != null)
                            {
                                evFacilityClosed();
                            }
                            //PersistenceUtils.saveRTCareerBackup();
                        }
                        GUI.enabled = true;
                    }
                    else
                    {
                        // GUILayout.Box("This facility cannot be closed.", BoxInfo);
                    }
                }
                GUILayout.EndHorizontal();
            }
        }
        void drawFacilityManagerWindow(int windowID)
        {
            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;

            Yellowtext = new GUIStyle(GUI.skin.box);
            Yellowtext.normal.textColor  = Color.yellow;
            Yellowtext.normal.background = null;

            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;

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

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

                GUILayout.FlexibleSpace();

                GUILayout.Button("Facility Manager", DeadButton, GUILayout.Height(16));

                GUILayout.FlexibleSpace();

                GUI.enabled = true;

                if (GUILayout.Button("X", DeadButtonRed, GUILayout.Height(16)))
                {
                    PersistenceUtils.saveStaticPersistence(selectedFacility);
                    selectedFacility = null;
                    KerbalKonstructs.instance.showFacilityManager = false;
                }
            }
            GUILayout.EndHorizontal();

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

            GUILayout.Space(2);

            if (selectedFacility != null)
            {
                sFacilityType = (string)selectedFacility.getSetting("FacilityType");

                if (sFacilityType == "TrackingStation")
                {
                    sFacilityName = "Tracking Station";
                    bHalfwindow   = true;
                }
                else
                {
                    sFacilityName = (string)selectedFacility.model.getSetting("title");
                }

                GUILayout.Box("" + sFacilityName, Yellowtext);
                GUILayout.Space(5);

                fAlt = (float)selectedFacility.getSetting("RadiusOffset");

                ObjectPos    = KerbalKonstructs.instance.getCurrentBody().transform.InverseTransformPoint(selectedFacility.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;
                }

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(5);
                    GUILayout.Label("Alt. " + fAlt.ToString("#0.0") + "m", LabelInfo);
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Lat. " + disObjectLat.ToString("#0.000"), LabelInfo);
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Lon. " + disObjectLon.ToString("#0.000"), LabelInfo);
                    GUILayout.Space(5);
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(5);

                string sPurpose = "";

                if (sFacilityType == "Hangar")
                {
                    sPurpose    = "Craft can be stored in this building for launching from the base at a later date. The building has limited space.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "RocketAssembly")
                {
                    sPurpose    = "This facility can construct craft that have been designed in KSC's VAB and can store a constructed craft for launching from the base at a later date.";
                    bHalfwindow = false;
                }
                else
                if (sFacilityType == "PlaneAssembly")
                {
                    sPurpose    = "This facility can construct craft that have been designed in KSC's SPH and can store a constructed craft for launching from the base at a later date.";
                    bHalfwindow = false;
                }
                else
                if (sFacilityType == "ControlTower")
                {
                    sPurpose = "This facility manages incoming and outgoing air-traffic to and from the base, as well as administrating most other base operations.";
                }
                else
                if (sFacilityType == "Barracks")
                {
                    sPurpose    = "This facility provides a temporary home for base-staff. Other facilities can draw staff from the pool available at this facility.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "RadarStation")
                {
                    sPurpose    = "This facility tracks craft in the planet's atmosphere at a limited range. It provides bonuses for recovery operations by the nearest open base.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "Research")
                {
                    sPurpose    = "This facility carries out research and generates Science.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "Mining")
                {
                    sPurpose = "This facility excavates useful minerals and materials and thus generates Ore.";
                }
                else
                if (sFacilityType == "Refining")
                {
                    sPurpose = "This facility converts Ore into fuels.";
                }
                else
                if (sFacilityType == "Manufacturing")
                {
                    sPurpose = "This facility converts Ore into Processed Ore, for use in manufacturing craft in lieu of Funds, constructing and upgrading facilities.";
                }
                else
                if (sFacilityType == "Business")
                {
                    sPurpose    = "This facility carries out business related to the space program in order to generate Funds.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "Training")
                {
                    sPurpose = "This facility can provide professional skills and experience to rookie Kerbonauts.";
                }
                else
                if (sFacilityType == "Medical")
                {
                    sPurpose = "This facility can aid Kerbonaut recovery after long missions or injury.";
                }
                else
                if (sFacilityType == "TrackingStation")
                {
                    sPurpose    = "This facility can track a variety of off-Kerbin targets, including spacecraft, celestial bodies and asteroids.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "FuelTanks")
                {
                    sPurpose    = "This facility stores fuel for craft.";
                    bHalfwindow = false;
                }
                else
                if (sFacilityType == "Storage")
                {
                    sPurpose = "This facility stores construction materials (Processed Ore).";
                }
                else
                if (sFacilityType == "CraftAssembly")
                {
                    sPurpose    = "This facility can construct craft that have been designed in KSC's VAB or SPH and can store a constructed craft for launching from the base at a later date.";
                    bHalfwindow = false;
                }

                GUILayout.Label(sPurpose, LabelInfo);
                GUILayout.Space(2);
                GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
                GUILayout.Space(3);

                SharedInterfaces.OpenCloseFacility(selectedFacility);

                iFundsOpen2 = (float)selectedFacility.getSetting("OpenCost");
                isOpen2     = ((string)selectedFacility.getSetting("OpenCloseState") == "Open");
                float iFundsDefaultCost = (float)selectedFacility.model.getSetting("cost");
                if (iFundsOpen2 == 0)
                {
                    iFundsOpen2 = iFundsDefaultCost;
                }

                if (iFundsOpen2 == 0)
                {
                    isOpen2 = true;
                }

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

                GUI.enabled = isOpen2;

                if (sFacilityType == "TrackingStation")
                {
                    TrackingStationGUI.TrackingInterface(selectedFacility);
                }

                if (sFacilityType == "Hangar" || sFacilityType == "RocketAssembly" || sFacilityType == "PlaneAssembly" || sFacilityType == "CraftAssembly")
                {
                    sInStorage  = (string)selectedFacility.getSetting("InStorage");
                    sInStorage2 = (string)selectedFacility.getSetting("TargetID");
                    sInStorage3 = (string)selectedFacility.getSetting("TargetType");

                    float fMaxMass = (float)selectedFacility.model.getSetting("DefaultFacilityMassCapacity");
                    if (fMaxMass < 1)
                    {
                        fMaxMass = 25f;
                    }
                    float fMaxCrafts = (float)selectedFacility.model.getSetting("DefaultFacilityCraftCapacity");
                    if (fMaxCrafts < 1 || fMaxCrafts > 3)
                    {
                        fMaxCrafts = 2;
                    }

                    GUILayout.Space(2);
                    GUILayout.Label("Where necessary craft are disassembled for storage or re-assembled before being rolled out. Please note that for game purposes, this procedure is instantaneous.", LabelInfo);
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Max Craft: " + fMaxCrafts.ToString("#0"), LabelInfo);
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Max Mass/Craft: " + fMaxMass.ToString("#0") + " T", LabelInfo);
                    GUILayout.EndHorizontal();

                    if (sInStorage == null || sInStorage == "")
                    {
                        sInStorage = "None";
                        selectedFacility.setSetting("InStorage", "None");
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }
                    if (sInStorage2 == null || sInStorage2 == "")
                    {
                        sInStorage2 = "None";
                        selectedFacility.setSetting("TargetID", "None");
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }
                    if (sInStorage3 == null || sInStorage3 == "")
                    {
                        sInStorage3 = "None";
                        selectedFacility.setSetting("TargetType", "None");
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }

                    if (sInStorage == "None" && sInStorage2 == "None" && sInStorage3 == "None")
                    {
                        GUILayout.Label("No craft currently held in this facility.", LabelInfo);
                    }
                    else
                    {
                        int iNumberCrafts = NumberCraftHangared(selectedFacility);

                        GUILayout.Box("Stored Craft (" + iNumberCrafts.ToString() + "/" + fMaxCrafts.ToString("#0") + ")", Yellowtext);

                        List <Vessel> lVessels = FlightGlobals.Vessels;

                        foreach (Vessel vVesselStored in lVessels)
                        {
                            if (vVesselStored.id.ToString() == sInStorage)
                            {
                                if (GUILayout.Button("" + vVesselStored.vesselName, ButtonSmallText, GUILayout.Height(20)))
                                {
                                    // Empty the hangar
                                    if (HangarwayIsClear(selectedFacility))
                                    {
                                        sInStorage = "None";
                                        UnhangarCraft(vVesselStored, selectedFacility);
                                        sInStorage = "None";
                                    }
                                    else
                                    {
                                        ScreenMessages.PostScreenMessage("Cannot roll craft out. Clear the way first!", 10,
                                                                         ScreenMessageStyle.LOWER_CENTER);
                                    }
                                }
                                break;
                            }
                        }

                        foreach (Vessel vVesselStored in lVessels)
                        {
                            if (vVesselStored.id.ToString() == sInStorage2)
                            {
                                if (GUILayout.Button("" + vVesselStored.vesselName, ButtonSmallText, GUILayout.Height(20)))
                                {
                                    // Empty the hangar
                                    if (HangarwayIsClear(selectedFacility))
                                    {
                                        sInStorage2 = "None";
                                        UnhangarCraft(vVesselStored, selectedFacility);
                                        sInStorage2 = "None";
                                    }
                                    else
                                    {
                                        ScreenMessages.PostScreenMessage("Cannot roll craft out. Clear the way first!", 10,
                                                                         ScreenMessageStyle.LOWER_CENTER);
                                    }
                                }
                                break;
                            }
                        }

                        foreach (Vessel vVesselStored in lVessels)
                        {
                            if (vVesselStored.id.ToString() == sInStorage3)
                            {
                                if (GUILayout.Button("" + vVesselStored.vesselName, ButtonSmallText, GUILayout.Height(20)))
                                {
                                    // Empty the hangar
                                    if (HangarwayIsClear(selectedFacility))
                                    {
                                        sInStorage3 = "None";
                                        UnhangarCraft(vVesselStored, selectedFacility);
                                        sInStorage3 = "None";
                                    }
                                    else
                                    {
                                        ScreenMessages.PostScreenMessage("Cannot roll craft out. Clear the way first!", 10,
                                                                         ScreenMessageStyle.LOWER_CENTER);
                                    }
                                }
                                break;
                            }
                        }
                    }

                    GUILayout.Space(5);

                    scrollNearbyCraft = GUILayout.BeginScrollView(scrollNearbyCraft);

                    GUILayout.Box("Nearby Craft", Yellowtext);

                    bool bNearbyCraft = false;

                    foreach (Vessel vVessel in FlightGlobals.Vessels)
                    {
                        if (vVessel == null)
                        {
                            continue;
                        }
                        if (!vVessel.loaded)
                        {
                            continue;
                        }
                        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;
                        }
                        if (vVessel.situation != Vessel.Situations.LANDED)
                        {
                            continue;
                        }
                        if (vVessel.GetCrewCount() > 0)
                        {
                            continue;
                        }

                        var vDistToCraft = Vector3.Distance(vVessel.gameObject.transform.position, selectedFacility.gameObject.transform.position);
                        if (vDistToCraft > 250)
                        {
                            continue;
                        }

                        bNearbyCraft = true;

                        if (GUILayout.Button(" " + vVessel.vesselName + " ", ButtonSmallText, GUILayout.Height(20)))
                        {
                            float fMass = vVessel.GetTotalMass();

                            if (fMass > fMaxMass)
                            {
                                ScreenMessages.PostScreenMessage("Craft too heavy for this facility. Max " + fMaxMass.ToString("#0") + "T per craft.", 10,
                                                                 ScreenMessageStyle.LOWER_CENTER);
                            }
                            else
                            {
                                float fMaxCraft = (float)selectedFacility.model.getSetting("DefaultFacilityCraftCapacity");
                                if (fMaxCraft < 1 || fMaxCraft > 3)
                                {
                                    fMaxCraft = 2;
                                }

                                int iNumberCraft = NumberCraftHangared(selectedFacility);

                                if (iNumberCraft < (int)fMaxCraft)
                                {
                                    HangarCraft(vVessel, selectedFacility, (int)fMaxCraft);
                                }
                                else
                                {
                                    ScreenMessages.PostScreenMessage("This facility is full. Max craft: " + fMaxCraft.ToString("#0"), 10,
                                                                     ScreenMessageStyle.LOWER_CENTER);
                                }
                            }
                        }
                    }

                    if (!bNearbyCraft)
                    {
                        GUILayout.Label("There are no craft close enough to store in this facility.", LabelInfo);
                    }

                    GUILayout.EndScrollView();

                    GUILayout.FlexibleSpace();
                }

/*				if (sFacilityType == "RocketAssembly" || sFacilityType == "PlaneAssembly" || sFacilityType == "CraftAssembly")
 *                              {
 *                                      string sProducing = (string)selectedFacility.getSetting("Producing");
 *
 *                                      if (sProducing == null || sProducing == "")
 *                                      {
 *                                              sProducing = "None";
 *                                              selectedFacility.setSetting("Producing", "None");
 *                                              PersistenceUtils.saveStaticPersistence(selectedFacility);
 *                                      }
 *
 *                                      if (GUILayout.Button("Construct a Craft", ButtonSmallText, GUILayout.Height(20)))
 *                                      {
 *                                              if (sProducing != "None")
 *                                                      ScreenMessages.PostScreenMessage("Only one craft can be constructed at a time.", 10,
 *                                                              ScreenMessageStyle.LOWER_CENTER);
 *                                      }
 *
 *                                      GUILayout.Space(3);
 *                                      if (sProducing == "None")
 *                                              GUILayout.Label("No craft currently under construction in this facility.", LabelInfo);
 *                                      else
 *                                      {
 *                                              GUILayout.Label("Craft Under Construction: ", LabelInfo);
 *
 *                                              // TO DO List of craft
 *                                              GUILayout.Label("Cost of Construction: X Funds / X Materials", LabelInfo);
 *                                              GUILayout.Label("Total Construction Time: X hours", LabelInfo);
 *                                              GUILayout.Label("Time to Completion: X hours", LabelInfo);
 *                                              if (GUILayout.Button("Assign a Kerbonaut Engineer", ButtonSmallText, GUILayout.Height(20)))
 *                                              { }
 *                                      }
 *
 *                                      if (GUILayout.Button("Upgrade Production", ButtonSmallText, GUILayout.Height(20)))
 *                                      { }
 *
 *                                      float fAvailableMaterials;
 *
 *                                      fAvailableMaterials = (float)selectedFacility.getSetting("PrOreCurrent");
 *
 *                                      GUILayout.Space(3);
 *                                      GUILayout.Label("Available Materials (Processed Ore): " + fAvailableMaterials.ToString("#0.0"), LabelInfo);
 *                              } */

                float fStaffing       = 0;
                float fProductionRate = 0;
                float fLastCheck      = 0;

                if (sFacilityType == "Research" || sFacilityType == "Business" || sFacilityType == "Mining" ||
                    sFacilityType == "RocketAssembly" || sFacilityType == "PlaneAssembly" || sFacilityType == "CraftAssembly")
                {
                    // Check production since last check
                    fStaffing       = (float)selectedFacility.getSetting("StaffCurrent");
                    fProductionRate = (float)selectedFacility.getSetting("ProductionRateCurrent") * (fStaffing / 2f);

                    if (fProductionRate < 0.01f)
                    {
                        float fDefaultRate = 0.01f;

                        if (sFacilityType == "Business")
                        {
                            fDefaultRate = 0.10f;
                        }
                        if (sFacilityType == "Mining")
                        {
                            fDefaultRate = 0.05f;
                        }

                        selectedFacility.setSetting("ProductionRateCurrent", fDefaultRate);
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                        fProductionRate = fDefaultRate * (fStaffing / 2f);
                    }

                    fLastCheck = (float)selectedFacility.getSetting("LastCheck");

                    if (fLastCheck == 0)
                    {
                        fLastCheck = (float)Planetarium.GetUniversalTime();
                        selectedFacility.setSetting("LastCheck", fLastCheck);
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }
                }

                if (sFacilityType == "Research" || sFacilityType == "Business" || sFacilityType == "Mining")
                {
                    string sProduces = "";
                    float  fMax      = 0f;
                    float  fCurrent  = 0f;

                    if (sFacilityType == "Research")
                    {
                        sProduces = "Science";
                        fMax      = (float)selectedFacility.getSetting("ScienceOMax");

                        if (fMax < 1)
                        {
                            fMax = (float)selectedFacility.model.getSetting("DefaultScienceOMax");

                            if (fMax < 1)
                            {
                                fMax = 10f;
                            }

                            selectedFacility.setSetting("ScienceOMax", fMax);
                            PersistenceUtils.saveStaticPersistence(selectedFacility);
                        }

                        fCurrent = (float)selectedFacility.getSetting("ScienceOCurrent");
                    }
                    if (sFacilityType == "Business")
                    {
                        sProduces = "Funds";
                        fMax      = (float)selectedFacility.getSetting("FundsOMax");

                        if (fMax < 1)
                        {
                            fMax = (float)selectedFacility.model.getSetting("DefaultFundsOMax");

                            if (fMax < 1)
                            {
                                fMax = 10000f;
                            }

                            selectedFacility.setSetting("FundsOMax", fMax);
                            PersistenceUtils.saveStaticPersistence(selectedFacility);
                        }

                        fCurrent = (float)selectedFacility.getSetting("FundsOCurrent");
                    }
                    if (sFacilityType == "Mining")
                    {
                        sProduces = "Ore";
                        fMax      = (float)selectedFacility.model.getSetting("OreMax");

                        if (fMax < 1)
                        {
                            fMax = 500f;
                        }

                        fCurrent = (float)selectedFacility.getSetting("OreCurrent");
                    }

                    double dTime = Planetarium.GetUniversalTime();

                    // Deal with revert exploits
                    if (fLastCheck > (float)dTime)
                    {
                        selectedFacility.setSetting("LastCheck", (float)dTime);
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }

                    if ((float)dTime - fLastCheck > 43200)
                    {
                        float fDays = (((float)dTime - fLastCheck) / 43200);

                        float fProduced = fDays * fProductionRate;

                        fCurrent = fCurrent + fProduced;
                        if (fCurrent > fMax)
                        {
                            fCurrent = fMax;
                        }

                        if (sFacilityType == "Research")
                        {
                            selectedFacility.setSetting("ScienceOCurrent", fCurrent);
                        }
                        if (sFacilityType == "Business")
                        {
                            selectedFacility.setSetting("FundsOCurrent", fCurrent);
                        }
                        if (sFacilityType == "Mining")
                        {
                            selectedFacility.setSetting("OreCurrent", fCurrent);
                        }

                        selectedFacility.setSetting("LastCheck", (float)dTime);
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Produces: " + sProduces, LabelInfo);
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Current: " + fCurrent.ToString("#0") + " | Max: " + fMax.ToString("#0"), LabelInfo);
                    GUILayout.EndHorizontal();
                    //if (GUILayout.Button("Upgrade Max Capacity", ButtonSmallText, GUILayout.Height(20)))
                    //{ }

                    if (sFacilityType == "Research")
                    {
                        if (GUILayout.Button("Transfer Science to KSC R&D", ButtonSmallText, GUILayout.Height(20)))
                        {
                            ResearchAndDevelopment.Instance.AddScience(fCurrent, TransactionReasons.Cheating);
                            selectedFacility.setSetting("ScienceOCurrent", 0f);
                            PersistenceUtils.saveStaticPersistence(selectedFacility);
                        }

                        /* GUILayout.BeginHorizontal();
                         * {
                         *      if (GUILayout.Button("Assign a Special Project", ButtonSmallText, GUILayout.Height(20)))
                         *      { }
                         *      if (GUILayout.Button("Deliver Research Materials", ButtonSmallText, GUILayout.Height(20)))
                         *      { }
                         * }
                         * GUILayout.EndHorizontal();
                         * if (GUILayout.Button("Assign a Kerbonaut Scientist", ButtonSmallText, GUILayout.Height(20)))
                         * { } */
                    }
                    if (sFacilityType == "Business")
                    {
                        if (GUILayout.Button("Transfer Funds to KSC Account", ButtonSmallText, GUILayout.Height(20)))
                        {
                            Funding.Instance.AddFunds((double)fCurrent, TransactionReasons.Cheating);
                            selectedFacility.setSetting("FundsOCurrent", 0f);
                            PersistenceUtils.saveStaticPersistence(selectedFacility);
                        }
                    }

                    /* if (sFacilityType == "Mining")
                     * {
                     *      if (GUILayout.Button("Transfer Ore to/from Craft", ButtonSmallText, GUILayout.Height(20)))
                     *      {
                     *              if (bTransferOreToC) bTransferOreToC = false;
                     *              else bTransferOreToC = true;
                     *      }
                     *
                     *      if (bTransferOreToC)
                     *      {
                     *              // Ore transfer to craft GUI
                     *              GUILayout.Label("Select Craft & Container", LabelInfo);
                     *              scrollOreTransfer = GUILayout.BeginScrollView(scrollOreTransfer);
                     *              GUILayout.Label("Select Craft & Container", LabelInfo);
                     *              GUILayout.Label("Select Craft & Container", LabelInfo);
                     *              GUILayout.Label("Select Craft & Container", LabelInfo);
                     *              GUILayout.EndScrollView();
                     *              GUILayout.BeginHorizontal();
                     *              if (GUILayout.Button("Into Craft", GUILayout.Height(23)))
                     *              {
                     *
                     *              }
                     *              if (GUILayout.Button("Out of Craft", GUILayout.Height(23)))
                     *              {
                     *
                     *              }
                     *              GUILayout.EndHorizontal();
                     *              GUILayout.BeginHorizontal();
                     *              GUILayout.Label("Amount: ", LabelInfo);
                     *              sOreTransferAmount = GUILayout.TextField(sOreTransferAmount, 7, GUILayout.Width(120));
                     *              if (GUILayout.Button("Max", GUILayout.Height(23)))
                     *              {
                     *
                     *              }
                     *              GUILayout.EndHorizontal();
                     *              if (GUILayout.Button("Proceed", GUILayout.Height(23)))
                     *              {
                     *
                     *              }
                     *
                     *              GUILayout.FlexibleSpace();
                     *      }
                     *
                     *      if (GUILayout.Button("Transfer Ore to Facility", ButtonSmallText, GUILayout.Height(20)))
                     *      {
                     *              if (bTransferOreToF) bTransferOreToF = false;
                     *              else bTransferOreToF = true;
                     *
                     *      }
                     *
                     *      if (bTransferOreToF)
                     *      {
                     *              // Ore transfer to Facility GUI
                     *              GUILayout.Label("Select Destination Facility", LabelInfo);
                     *              scrollOreTransfer2 = GUILayout.BeginScrollView(scrollOreTransfer2);
                     *              GUILayout.Label("Select Destination Facility", LabelInfo);
                     *              GUILayout.Label("Select Destination Facility", LabelInfo);
                     *              GUILayout.Label("Select Destination Facility", LabelInfo);
                     *              GUILayout.EndScrollView();
                     *
                     *              GUILayout.BeginHorizontal();
                     *              GUILayout.Label("Amount: ", LabelInfo);
                     *              sOreTransferAmount = GUILayout.TextField(sOreTransferAmount, 7, GUILayout.Width(120));
                     *              if (GUILayout.Button("Max", GUILayout.Height(23)))
                     *              {
                     *
                     *              }
                     *              GUILayout.EndHorizontal();
                     *              GUILayout.BeginHorizontal();
                     *              GUILayout.Label("Transfer Cost: X Funds");
                     *              if (GUILayout.Button("Proceed", GUILayout.Height(23)))
                     *              {
                     *
                     *              }
                     *              GUILayout.EndHorizontal();
                     *              GUILayout.FlexibleSpace();
                     *      }
                     *
                     *      if (GUILayout.Button("Assign a Kerbonaut Engineer", ButtonSmallText, GUILayout.Height(20)))
                     *      { }
                     * } */

                    GUILayout.Space(5);
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Label("Production Rate: Up to " + fProductionRate.ToString("#0.00") + " per 12 hrs", LabelInfo);
                        GUILayout.FlexibleSpace();
                        //if (GUILayout.Button(" Upgrade ", ButtonSmallText, GUILayout.Height(20)))
                        //{ }
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.Space(3);
                }

                fLqFMax = (float)selectedFacility.model.getSetting("LqFMax");
                fOxFMax = (float)selectedFacility.model.getSetting("OxFMax");
                fMoFMax = (float)selectedFacility.model.getSetting("MoFMax");

                if (fLqFMax > 0 || fOxFMax > 0 || fMoFMax > 0)
                {
                    FuelTanksGUI.FuelTanksInterface(selectedFacility);
                }

                GUI.enabled = true;

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

                GUI.enabled = isOpen2;
                StaffGUI.StaffingInterface(selectedFacility);
                GUI.enabled = true;
            }

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

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
        public static void CraftConstructionInterface(StaticObject selectedFacility)
        {
            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;

            Yellowtext = new GUIStyle(GUI.skin.box);
            Yellowtext.normal.textColor  = Color.yellow;
            Yellowtext.normal.background = null;

            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;

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

            string sProducing = (string)selectedFacility.getSetting("Producing");

            if (sProducing == null || sProducing == "")
            {
                sProducing = "None";
                selectedFacility.setSetting("Producing", "None");
                PersistenceUtils.saveStaticPersistence(selectedFacility);
            }

            if (GUILayout.Button("Construct a Craft", ButtonSmallText, GUILayout.Height(20)))
            {
                if (sProducing != "None")
                {
                    MiscUtils.HUDMessage("Only one craft can be constructed at a time.", 10,
                                         3);
                }
            }

            GUILayout.Space(3);
            if (sProducing == "None")
            {
                GUILayout.Label("No craft currently under construction in this facility.", LabelInfo);
            }
            else
            {
                GUILayout.Label("Craft Under Construction: ", LabelInfo);

                // TO DO List of craft
                GUILayout.Label("Cost of Construction: X Funds / X Materials", LabelInfo);
                GUILayout.Label("Total Construction Time: X hours", LabelInfo);
                GUILayout.Label("Time to Completion: X hours", LabelInfo);
                if (GUILayout.Button("Assign a Kerbonaut Engineer", ButtonSmallText, GUILayout.Height(20)))
                {
                }
            }

            if (GUILayout.Button("Upgrade Production", ButtonSmallText, GUILayout.Height(20)))
            {
            }

            float fAvailableMaterials;

            fAvailableMaterials = (float)selectedFacility.getSetting("PrOreCurrent");

            GUILayout.Space(3);
            GUILayout.Label("Available Materials (Processed Ore): " + fAvailableMaterials.ToString("#0.0"), LabelInfo);
        }