Example #1
0
        /// <summary>
        /// Spawns an Instance of an defined StaticModel
        /// </summary>
        /// <param name="model"></param>
        /// <param name="fOffset"></param>
        /// <param name="vPosition"></param>
        /// <param name="fAngle"></param>
        /// <returns></returns>
        public string SpawnInstance(StaticModel model, float fOffset, Vector3 vPosition)
        {
            StaticInstance instance = new StaticInstance();

            instance.Orientation     = Vector3.up;
            instance.heighReference  = HeightReference.Terrain;
            instance.VisibilityRange = (PhysicsGlobals.Instance.VesselRangesDefault.flying.unload + 3000);

            instance.Group          = "SaveGame";
            instance.RadialPosition = vPosition;

            instance.model = model;

            if (instance.model == null)
            {
                Log.UserError("LoadFromSave: Canot find model named: " + model.name);
                instance = null;
            }
            //instance.mesh = UnityEngine.Object.Instantiate(instance.model.prefab);


            instance.CelestialBody = KerbalKonstructs.instance.GetCurrentBody();

            instance.RadiusOffset  = fOffset;
            instance.RotationAngle = 0;

            instance.RefLatitude  = KKMath.GetLatitudeInDeg(instance.RadialPosition);
            instance.RefLongitude = KKMath.GetLongitudeInDeg(instance.RadialPosition);

            InstanceUtil.CreateGroupCenterIfMissing(instance);


            bool oldLegacySpawn = KerbalKonstructs.convertLegacyConfigs;

            instance.Orientate();
            instance.Activate();

            KerbalKonstructs.convertLegacyConfigs = oldLegacySpawn;

            KerbalKonstructs.SelectInstance(instance, true);

            selectedInstance = instance;
            startPosition    = selectedInstance.position;

            instance.Update();
            instance.isInSavegame = true;

            instance.HighlightObject(XKCDColors.FreshGreen);

            this.Open();

            return(instance.UUID);
        }
Example #2
0
        /// <summary>
        /// Attaches A CommNet or RemoteTech Groundstation to a Static Object instance
        /// </summary>
        /// <param name="instance"></param>
        internal static void AttachGroundStation(StaticInstance instance)
        {
            GroundStation myfacility = instance.myFacilities[0] as GroundStation;
            // we use a messure of 1000km from the settings.
            float antennaPower = myfacility.TrackingShort * 1000000;

            if (antennaPower == 0f || instance.Group == "KSCUpgrades")
            {
                return;
            }

            // add CommNet Groundstations
            if (KerbalKonstructs.instance.enableCommNet)
            {
                Log.Normal("Adding Groundstation: " + instance.Group);
                if (openCNStations.Contains(instance) == false)
                {
                    KKCommNetHome commNetGroudStation = instance.gameObject.AddComponent <KKCommNetHome>();

                    commNetGroudStation.nodeName = instance.CelestialBody.name + " " + instance.Group;
                    commNetGroudStation.comm     = new CommNode();
                    var commNode = commNetGroudStation.comm;
                    commNode.antennaTransmit.power = antennaPower;
                    //commNetGroudStation.enabled = true;
                    openCNStations.Add(instance);
                    CommNet.CommNetNetwork.Reset();
                }
                else
                {
                    Log.UserError("Adding GroundStations should never be here: (instance allready added when open was called)");
                }
            }
            // Add RemoteTech Groundstation
            if (KerbalKonstructs.instance.enableRT)
            {
                Guid stationID = RemoteTechAddon.GetGroundStationGuid((instance.CelestialBody.name) + " " + instance.Group);
                if (stationID == Guid.Empty)
                {
                    double lng, lat, alt;
                    alt = instance.CelestialBody.pqsController.GetSurfaceHeight(instance.RadialPosition) - instance.CelestialBody.pqsController.radius + 15;

                    var objectPos = instance.CelestialBody.transform.InverseTransformPoint(instance.gameObject.transform.position);
                    lng       = KKMath.GetLongitudeInDeg(objectPos);
                    lat       = KKMath.GetLatitudeInDeg(objectPos);
                    stationID = RemoteTechAddon.AddGroundstation((instance.CelestialBody.name) + " " + instance.Group, lat, lng, alt, instance.CelestialBody);
                    Log.Normal("Got RTStationID: " + stationID);
                }
                openRTStations.Add(instance, stationID);
                RemoteTechAddon.ChangeGroundStationRange(stationID, antennaPower);
            }
        }
Example #3
0
        public static void LoadBuilding(ConfigNode cfgNode)
        {
            StaticInstance instance = new StaticInstance();

            instance.isInSavegame = true;

            instance.Orientation     = Vector3.up;
            instance.heighReference  = HeightReference.Terrain;
            instance.VisibilityRange = (PhysicsGlobals.Instance.VesselRangesDefault.flying.unload + 3000);

            instance.Group = "SaveGame";

            instance.RadialPosition = ConfigNode.ParseVector3(cfgNode.GetValue("Position"));

            instance.model = StaticDatabase.GetModelByName(cfgNode.GetValue("ModelName"));

            if (instance.model == null)
            {
                Log.UserError("LoadFromSave: Canot find model named: " + cfgNode.GetValue("ModelName"));
                instance = null;
                return;
            }
            //instance.mesh = UnityEngine.Object.Instantiate(instance.model.prefab);

            instance.UUID = cfgNode.GetValue("UUID");

            instance.CelestialBody = ConfigUtil.GetCelestialBody(cfgNode.GetValue("Body"));

            instance.RadiusOffset  = float.Parse(cfgNode.GetValue("Altitude"));
            instance.RotationAngle = float.Parse(cfgNode.GetValue("Rotation"));

            instance.RefLatitude  = KKMath.GetLatitudeInDeg(instance.RadialPosition);
            instance.RefLongitude = KKMath.GetLongitudeInDeg(instance.RadialPosition);

            InstanceUtil.CreateGroupCenterIfMissing(instance);

            if (cfgNode.HasValue("IsScanable"))
            {
                bool.TryParse(cfgNode.GetValue("IsScanable"), out instance.isScanable);
            }

            bool oldLegacySpawn = KerbalKonstructs.convertLegacyConfigs;

            instance.Orientate();

            KerbalKonstructs.convertLegacyConfigs = oldLegacySpawn;
        }
        /// <summary>
        /// Spawns an Instance of an defined StaticModel
        /// </summary>
        /// <param name="model"></param>
        /// <param name="fOffset"></param>
        /// <param name="vPosition"></param>
        /// <param name="fAngle"></param>
        /// <returns></returns>
        public string SpawnInstance(StaticModel model, float fOffset, Vector3 vPosition)
        {
            StaticInstance instance = new StaticInstance();

            instance.isInSavegame = true;

            instance.heighReference = HeightReference.Terrain;

            instance.gameObject      = UnityEngine.Object.Instantiate(model.prefab);
            instance.RadiusOffset    = fOffset;
            instance.CelestialBody   = KerbalKonstructs.instance.getCurrentBody();
            instance.Group           = "Ungrouped";
            instance.RadialPosition  = vPosition;
            instance.RotationAngle   = 0;
            instance.Orientation     = Vector3.up;
            instance.VisibilityRange = (PhysicsGlobals.Instance.VesselRangesDefault.flying.unload + 3000);
            instance.RefLatitude     = KKMath.GetLatitudeInDeg(instance.RadialPosition);
            instance.RefLongitude    = KKMath.GetLongitudeInDeg(instance.RadialPosition);

            instance.model      = model;
            instance.configPath = null;
            instance.configUrl  = null;

            instance.SpawnObject(true);

            KerbalKonstructs.instance.selectedObject = instance;

            selectedObject = instance;
            startPosition  = selectedObject.gameObject.transform.position;

            instance.HighlightObject(XKCDColors.FreshGreen);

            this.Open();

            return(instance.UUID);
        }
Example #5
0
        void prepNGS()
        {
            if (lTargetSite != null)
            {
                sTargetSiteName = lTargetSite.LaunchSiteName;

                fRangeToTarget = LaunchSiteManager.getDistanceToBase(FlightGlobals.ActiveVessel.GetTransform().position, lTargetSite);
                if (fRangeToTarget > fOldRange)
                {
                    bClosing = false;
                }
                if (fRangeToTarget < fOldRange)
                {
                    bClosing = true;
                }

                var basepos = KerbalKonstructs.instance.GetCurrentBody().transform.InverseTransformPoint(lTargetSite.staticInstance.gameObject.transform.position);

                //disBaseLat = dBaseLat * 180 / Math.PI;
                //disBaseLon = dBaseLon * 180 / Math.PI;
                disBaseLat = KKMath.GetLatitudeInDeg(basepos);
                disBaseLon = KKMath.GetLongitudeInDeg(basepos);
                var dBaseLat = disBaseLat * KKMath.deg2rad;
                var dBaseLon = disBaseLon * KKMath.deg2rad;

                fOldRange = fRangeToTarget;

                if (bClosing)
                {
                    tTextureMiddle = UIMain.tIconOpen;
                }
                else
                {
                    tTextureMiddle = UIMain.tIconClosed;
                }

                Vector3 vcraftpos = FlightGlobals.ActiveVessel.GetTransform().position;
                vCrft = vcraftpos;
                Vector3 vsitepos = lTargetSite.staticInstance.transform.position;
                vSPos = vsitepos;
                Vector3 vHeading = FlightGlobals.ActiveVessel.transform.up;
                vHead = vHeading;

                disLat = FlightGlobals.ActiveVessel.latitude;
                var dLat = disLat / 180 * Math.PI;
                disLon = FlightGlobals.ActiveVessel.longitude;
                var dLon = disLon / 180 * Math.PI;

                var y = Math.Sin(dBaseLon - dLon) * Math.Cos(dBaseLat);
                var x = (Math.Cos(dLat) * Math.Sin(dBaseLat)) - (Math.Sin(dLat) * Math.Cos(dBaseLat) * Math.Cos(dBaseLon - dLon));
                var requiredHeading = Math.Atan2(y, x) * 180 / Math.PI;
                dreqheading = (requiredHeading + 360) % 360;

                var diff = (360 + 180 + requiredHeading - FlightGlobals.ship_heading) % 360 - 180;
                dshipheading = (FlightGlobals.ship_heading + 360) % 360;

                if (diff > 5)
                {
                    iCorrection = 2;
                }
                else if (diff < -5)
                {
                    iCorrection = 1;
                }
                else
                {
                    iCorrection = 0;
                }

                if (bClosing)
                {
                    tTextureLeft  = UIMain.tLeftOff;
                    tTextureRight = UIMain.tRightOff;
                }
                else
                {
                    tTextureLeft  = UIMain.tLeftOn;
                    tTextureRight = UIMain.tRightOn;
                }

                if (iCorrection == 1)
                {
                    tTextureLeft  = UIMain.tLeftOn;
                    tTextureRight = UIMain.tRightOff;
                }
                if (iCorrection == 2)
                {
                    tTextureLeft  = UIMain.tLeftOff;
                    tTextureRight = UIMain.tRightOn;
                }
            }
            else
            {
                tTextureMiddle = UIMain.tIconClosed;
                tTextureLeft   = UIMain.tLeftOff;
                tTextureRight  = UIMain.tRightOff;
            }
        }
Example #6
0
        void drawFacilityManagerWindow(int windowID)
        {
            if (selectedInstance.hasFacilities == false || selectedInstance.myFacilities.Count == 0)
            {
                selectedInstance = null;
                this.Close();
            }


            if (!layoutInitialized)
            {
                InitializeLayout();
                layoutInitialized = true;
            }

            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)))
                {
                    selectedInstance = null;
                    this.Close();
                    return;
                }
            }
            GUILayout.EndHorizontal();

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

            GUILayout.Space(2);

            if (selectedInstance != null)
            {
                sFacilityType = selectedInstance.FacilityType;

                if (sFacilityType == "GroundStation")
                {
                    sFacilityName = "Ground Station";
                    bHalfwindow   = true;
                }
                else
                {
                    if (selectedInstance.facilityType != KKFacilityType.None)
                    {
                        sFacilityName = selectedInstance.GetFacility(selectedInstance.facilityType).FacilityName;
                    }
                    else
                    {
                        sFacilityName = selectedInstance.model.title;
                    }
                }

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

                fAlt = selectedInstance.RadiusOffset;

                objectPos    = KerbalKonstructs.instance.GetCurrentBody().transform.InverseTransformPoint(selectedInstance.position);
                disObjectLat = KKMath.GetLatitudeInDeg(objectPos);
                disObjectLon = KKMath.GetLongitudeInDeg(objectPos);

                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);

                sPurpose = "";

                switch (selectedInstance.facilityType)
                {
                case KKFacilityType.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;
                    break;
                }

                case KKFacilityType.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;
                    break;
                }

                case KKFacilityType.Research:
                {
                    sPurpose    = "This facility carries out research and generates Science.";
                    bHalfwindow = true;
                    break;
                }

                case KKFacilityType.Business:
                {
                    sPurpose    = "This facility carries out business related to the space program in order to generate Funds.";
                    bHalfwindow = true;
                    break;
                }

                case KKFacilityType.GroundStation:
                {
                    sPurpose    = "This facility can be a GroundStation for RemoteTech/CommNet";
                    bHalfwindow = true;
                    break;
                }

                case KKFacilityType.Merchant:
                {
                    sPurpose    = "You can buy and sell Resources here";
                    bHalfwindow = false;
                    break;
                }

                case KKFacilityType.Storage:
                {
                    sPurpose    = "You can store Resources here";
                    bHalfwindow = false;
                    break;
                }
                }

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

                SharedInterfaces.OpenCloseFacility(selectedInstance);

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

                if (selectedInstance.myFacilities[0].isOpen)
                {
                    switch (selectedInstance.facilityType)
                    {
                    case KKFacilityType.GroundStation:
                        TrackingStationGUI.TrackingInterface(selectedInstance);
                        break;

                    case KKFacilityType.Hangar:
                        HangarGUI.HangarInterface(selectedInstance);
                        break;

                    case KKFacilityType.Research:
                    case KKFacilityType.Business:
                        ProductionGUI.ProductionInterface(selectedInstance, sFacilityType);
                        break;

                    case KKFacilityType.Merchant:
                        MerchantGUI.MerchantInterface(selectedInstance);
                        break;

                    case KKFacilityType.Storage:
                        StorageGUI.StorageInerface(selectedInstance);
                        break;
                    }
                    GUILayout.Space(2);
                    GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
                    GUILayout.Space(2);
                    StaffGUI.StaffingInterface(selectedInstance);
                }
            }

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

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
Example #7
0
        private void DrawSpaceCenters()
        {
            if (!KerbalKonstructs.instance.mapShowRecovery)
            {
                return;
            }

            body = PlanetariumCamera.fetch.target.GetReferenceBody();

            displayingTooltip2 = false;

            // Do tracking stations first
            foreach (CustomSpaceCenter customSpaceCenter in spaceCenters)
            {
                if ((mapHideIconsBehindBody) && (IsOccluded(customSpaceCenter.gameObject.transform.position, body)))
                {
                    continue;
                }

                cscIsOpen = customSpaceCenter.isOpen;



                if (KerbalKonstructs.instance.mapShowRecovery)
                {
                    cscDisplay = true;
                }
                if (!KerbalKonstructs.instance.mapShowClosed && !cscIsOpen)
                {
                    cscDisplay = false;
                }
                if (!KerbalKonstructs.instance.mapShowOpen && cscIsOpen)
                {
                    cscDisplay = false;
                }

                if (!cscDisplay)
                {
                    continue;
                }

                Vector3 pos = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(customSpaceCenter.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.iconRecoveryBase, ScaleMode.ScaleToFit, true);
                }

                if (screenRect6.Contains(Event.current.mousePosition) && !displayingTooltip2)
                {
                    var objectpos2 = customSpaceCenter.staticInstance.CelestialBody.transform.InverseTransformPoint(customSpaceCenter.gameObject.transform.position);

                    var disObjectLat2 = KKMath.GetLatitudeInDeg(objectpos2);
                    var disObjectLon2 = KKMath.GetLongitudeInDeg(objectpos2);

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

                    //Only display one tooltip at a time
                    if (customSpaceCenter.isFromFacility)
                    {
                        DisplayMapIconToolTip(customSpaceCenter.staticInstance.GetFacility(KKFacilityType.RecoveryBase).FacilityName + "\n(Lat." + disObjectLat2.ToString("#0.00") + "/ Lon." + disObjectLon2.ToString("#0.00") + ")", pos);
                    }
                    else
                    {
                        DisplayMapIconToolTip(customSpaceCenter.staticInstance.launchSite.LaunchSiteName + "\n(Lat." + disObjectLat2.ToString("#0.00") + "/ Lon." + disObjectLon2.ToString("#0.00") + ")", pos);
                    }

                    if (Event.current.type == EventType.mouseDown && Event.current.button == 0)
                    {
                        if (customSpaceCenter.isFromFacility)
                        {
                            //# = customSpaceCenter.staticInstance;
                            FacilityManager.selectedInstance = customSpaceCenter.staticInstance;
                            FacilityManager.instance.Open();
                        }
                        else
                        {
                            BaseManager.setSelectedSite(customSpaceCenter.staticInstance.launchSite);
                            BaseManager.instance.Open();
                        }
                    }
                }
            }
        }
Example #8
0
        /// <summary>
        /// Draws the groundStation icons on the map
        /// </summary>
        public void drawTrackingStations()
        {
            if (CareerUtils.isSandboxGame)
            {
                KerbalKonstructs.instance.mapShowClosed = true;
                KerbalKonstructs.instance.mapShowOpen   = true;
            }

            if (!KerbalKonstructs.instance.mapShowOpenT)
            {
                return;
            }

            body = PlanetariumCamera.fetch.target.GetReferenceBody();

            displayingTooltip2 = false;

            // Do tracking stations first
            for (int i = 0; i < groundStations.Count; i++)
            {
                groundStation = groundStations[i];
                if ((mapHideIconsBehindBody) && (IsOccluded(groundStation.gameObject.transform.position, body)))
                {
                    continue;
                }

                isOpen = ((GroundStation)groundStation.myFacilities[0]).isOpen;



                if (KerbalKonstructs.instance.mapShowOpenT)
                {
                    display2 = true;
                }
                if (!KerbalKonstructs.instance.mapShowClosed && !isOpen)
                {
                    display2 = false;
                }
                if (!KerbalKonstructs.instance.mapShowOpen && isOpen)
                {
                    display2 = false;
                }

                if (!display2)
                {
                    continue;
                }

                Vector3 pos = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(groundStation.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);
                }


                if (screenRect6.Contains(Event.current.mousePosition) && !displayingTooltip2)
                {
                    var objectpos2 = groundStation.CelestialBody.transform.InverseTransformPoint(groundStation.gameObject.transform.position);

                    var disObjectLat2 = KKMath.GetLatitudeInDeg(objectpos2);
                    var disObjectLon2 = KKMath.GetLongitudeInDeg(objectpos2);

                    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)
                    {
                        selectedFacility = groundStation;
                        FacilityManager.selectedInstance = groundStation;
                        FacilityManager.instance.Open();
                    }
                }
            }
        }
        void UpdateUI()
        {
            if (selectedInstance.hasFacilities == false || selectedInstance.myFacilities.Count == 0)
            {
                selectedInstance = null;
                this.Close();
            }

            string facilityType = selectedInstance.FacilityType;

            if (facilityType == "GroundStation")
            {
                facilityName.Text(KKLocalization.GroundStation);
            }
            else
            {
                if (selectedInstance.facilityType != KKFacilityType.None)
                {
                    facilityName.Text(selectedInstance.GetFacility(selectedInstance.facilityType).FacilityName);
                }
                else
                {
                    facilityName.Text(selectedInstance.model.title);
                }
            }

            Vector3 pos = KerbalKonstructs.instance.GetCurrentBody().transform.InverseTransformPoint(selectedInstance.position);

            facilityPosition.Altitude(selectedInstance.RadiusOffset).Latitude(KKMath.GetLatitudeInDeg(pos)).Longitude(KKMath.GetLongitudeInDeg(pos));

            UpdateOpenClose();

            bool enableTrackingStation = false;
            bool enableHangar          = false;
            bool enableProduction      = false;
            bool enableMerchant        = false;
            bool enableStorage         = false;

            switch (selectedInstance.facilityType)
            {
            case KKFacilityType.Hangar:
                facilityPurpose.Text(KKLocalization.FacilityPurposeHangar);
                enableHangar = true;
                break;

            case KKFacilityType.Barracks:
                facilityPurpose.Text(KKLocalization.FacilityPurposeBarracks);
                break;

            case KKFacilityType.Research:
                facilityPurpose.Text(KKLocalization.FacilityPurposeResearch);
                enableProduction = true;
                break;

            case KKFacilityType.Business:
                facilityPurpose.Text(KKLocalization.FacilityPurposeBusiness);
                enableProduction = true;
                break;

            case KKFacilityType.GroundStation:
                facilityPurpose.Text(KKLocalization.FacilityPurposeGroundStation);
                enableTrackingStation = true;
                break;

            case KKFacilityType.Merchant:
                facilityPurpose.Text(KKLocalization.FacilityPurposeMerchant);
                enableMerchant = true;
                break;

            case KKFacilityType.Storage:
                facilityPurpose.Text(KKLocalization.FacilityPurposeStorage);
                enableStorage = true;
                break;
            }
            bool isOpen = selectedInstance.myFacilities[0].isOpen;

            tractingStation.SetActive(isOpen && enableTrackingStation);
            hangar.SetActive(isOpen && enableHangar);
            production.SetActive(isOpen && enableProduction);
            merchant.SetActive(isOpen && enableMerchant);
            storage.SetActive(isOpen && enableStorage);
            staff.SetActive(isOpen);

            if (isOpen)
            {
                switch (selectedInstance.facilityType)
                {
                case KKFacilityType.GroundStation:
                    tractingStation.UpdateUI(selectedInstance);
                    break;

                case KKFacilityType.Hangar:
                    hangar.UpdateUI(selectedInstance);
                    break;

                case KKFacilityType.Research:
                case KKFacilityType.Business:
                    production.UpdateUI(selectedInstance);
                    break;

                case KKFacilityType.Merchant:
                    merchant.UpdateUI(selectedInstance);
                    break;

                case KKFacilityType.Storage:
                    storage.UpdateUI(selectedInstance);
                    break;
                }
                staff.UpdateUI(selectedInstance);
            }
        }
Example #10
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)))
                {
                    selectedFacility = null;
                    this.Close();
                    return;
                }
            }
            GUILayout.EndHorizontal();

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

            GUILayout.Space(2);

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

                if (sFacilityType == "GroundStation")
                {
                    sFacilityName = "Ground Station";
                    bHalfwindow   = true;
                }
                else
                {
                    sFacilityName = selectedFacility.model.title;
                }

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

                fAlt = selectedFacility.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;
                disObjectLat = KKMath.GetLatitudeInDeg(objectPos);
                disObjectLon = KKMath.GetLongitudeInDeg(objectPos);

                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 == "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 == "Business")
                {
                    sPurpose    = "This facility carries out business related to the space program in order to generate Funds.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "TrackingStation")
                {
                    sPurpose    = "Thís Facility can be a GroundStation for RemoteTech/CommNet";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "FuelTanks")
                {
                    sPurpose    = "This facility stores fuel for craft.";
                    bHalfwindow = false;
                }


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

                SharedInterfaces.OpenCloseFacility(selectedFacility);

                isOpen2 = selectedFacility.myFacilities[0].isOpen;


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

                GUI.enabled = isOpen2;

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

                if (sFacilityType == "Hangar")
                {
                    HangarGUI.HangarInterface(selectedFacility);
                }

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

                fLqFMax = selectedFacility.model.LqFMax;
                fOxFMax = selectedFacility.model.OxFMax;
                fMoFMax = selectedFacility.model.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));
        }